Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong output of specific polygon #37

Open
september1st opened this issue Dec 14, 2019 · 3 comments
Open

Wrong output of specific polygon #37

september1st opened this issue Dec 14, 2019 · 3 comments

Comments

@september1st
Copy link

september1st commented Dec 14, 2019

Hi Mikko
I'm a C++ developer from China. Thank you for contributing this great library.
However, I find something wrong when I draw a rectangle with a hole which has 2 coincident edges. The version is v1.0.2.
As shown below, When I draw a rectangle(0->1->2->3) with a hole(4->5->6->7). Line 56 coincides with Line 32, and Line 01 coincides with Line 47.
Forgive me that I can't attach my source code for some reason. My code like this:

tessAddContour(tess, 2, polyPoints[0], 2 * sizeof(float), 4);
tessAddContour(tess, 2, polyPoints[1], 2 * sizeof(float), 4);

tessTesselate(tess, TessWindingRule::TESS_WINDING_ODD, TessElementType::TESS_POLYGONS, 3, 2, 0);

triangleVerts = tessGetVertices(tess);
elemCount = tessGetElementCount(tess);
triangleElems = tessGetElements(tess);

After that, I find that elemCount is 3, and I calculate the output triangles by triangleVerts and triangleElems in TESS_POLYGONS way. I get only 3 triangles:
(0,5,3)(5,0,4)(2,7,1). After renderring, my output picture shown like this below. One triangle (2,7,6) is missing.
image
I'm confused and I've done many experiments. I find that this commit will cause my problem. I am sure about this. I would be very greatful if you can point the connection between this "<=" and my problem, Or maybe my code is wrong?

@taburet
Copy link

taburet commented Feb 18, 2023

Same problem with the mentioned commit:

Screenshot 2023-02-18 at 13 01 20

Screenshot 2023-02-18 at 13 03 12

@EvanBalster
Copy link

EvanBalster commented Feb 21, 2024

I noticed an error like this when moving to the current version of the library from an older version I've been using for years. I may or may not have "fixed" this version of the library at one point so as not to exhibit the bug.

Here's my source code for a version of the library that doesn't create these diagonal artifacts. Note that this version does not support orientation reversal or the Delaunay feature. libtess2_source_without_triangle_bug.zip

@EvanBalster
Copy link

EvanBalster commented Feb 21, 2024

It appears my source code matches this commit: d7c34ac So the regression was introduced sometime afterwards.

I'm particularly suspicious of a specific line change to sweep.c that changed a comparison from < to <=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants