Skip to content

Commit

Permalink
Fix division overflow in "Trivial per triangle" for 0-area faces. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nh2 committed Dec 14, 2024
1 parent ad55b47 commit 694483c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/meshlabplugins/filter_texture/filter_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,17 @@ std::map<std::string, QVariant> 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<std::vector<uint> > buckets(buckSize);
for (uint i=0; i<areas.size(); ++i)
if (areas[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);
}
Expand Down

0 comments on commit 694483c

Please sign in to comment.