mapbox / earcut.hpp

Fast, header-only polygon triangulation
ISC License
858 stars 133 forks source link

Builds wrong indices array for concave polygon #110

Closed xahon closed 1 year ago

xahon commented 1 year ago

I have a arrow-like polygon image

Positions are [(-1, -1, 0), (-0.45, 0.45, 0), (1, 1, 0), (-1, 1, 0)] in that order image

When I pass these points (in that order) to earcut it returns me 6 indices which match these triangles (circle is starting point, red first, yellow second) image

Indices are [2, 0, 1, 1, 3, 2]

And I get this shape in the end

image

mrgreywater commented 1 year ago

I'm unable to reproduce the issue. Using x and y of your input i get the following result:

image

xahon commented 1 year ago

Sorry, my bad. I was indexing into wrong array with earcut's indices