Incorrect decomposition result
Closed this issue · 3 comments
skyostil commented
I noticed the library seems to lose some points in the result with some inputs such as this one:
#include "ConcavePolygon.h"
int main() {
std::vector<cxd::Vertex> verts({
cxd::Vec2({5.729166, 0.000002}),
cxd::Vec2({2.604166, 0.000002}),
cxd::Vec2({-0.520836, 3.125002}),
cxd::Vec2({-6.770838, 3.125002}),
cxd::Vec2({-6.770838, -3.124998}),
cxd::Vec2({5.729166, -3.124998}),
});
cxd::ConcavePolygon poly(std::move(verts));
poly.convexDecomp();
std::vector<cxd::ConcavePolygon> result;
poly.returnLowestLevelPolys(result);
int i = 0;
for (const auto& p : result) {
printf("--- polygon %d:\n", ++i);
for (const auto& v : p.getVertices())
printf("%f, %f\n", v.position.x, v.position.y);
}
}
In this case the point (-0.520836, 3.125002) is missing from the output.
mjjq commented
Thanks for your post, I can confirm that I get the same behaviour.
The cause seems to be due to the polygon slicing algorithm, specifically in slicePolygon(LineSegment segment)
in ConcavePolygon.h
. I'll attempt a fix and let you know when I've pushed it
mjjq commented
skyostil commented
Seems to work. Thanks for the quick fix!