diff --git a/src/meshlabplugins/filter_texture/filter_texture.cpp b/src/meshlabplugins/filter_texture/filter_texture.cpp index 04745b37c2..a6c4e76258 100644 --- a/src/meshlabplugins/filter_texture/filter_texture.cpp +++ b/src/meshlabplugins/filter_texture/filter_texture.cpp @@ -504,12 +504,17 @@ std::map FilterTexturePlugin::applyFilter( } // Creates buckets containing each halfening level triangles (a histogram) - int buckSize = (int)ceil(log_2(maxArea/minArea) + DBL_EPSILON); + // Using the logarithm law + // log_2(maxArea / minArea) + // = log_2(maxArea) - log_2(minArea) + // but the latter does not overflow the division if `minArea = DBL_MIN` + // as set above for `area == 0`. + int buckSize = (int)ceil(log_2(maxArea) - log_2(minArea) + DBL_EPSILON); std::vector > buckets(buckSize); for (uint i=0; i=0) { - int slot = (int)ceil(log_2(maxArea/areas[i]) + DBL_EPSILON) - 1; + int slot = (int)ceil(log_2(maxArea) - log_2(areas[i]) + DBL_EPSILON) - 1; assert(slot < buckSize && slot >= 0); buckets[slot].push_back(i); }