You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like earcut filters out points along colinear segments of the polygon as these are not required to cover the polygon with triangles. However, I would like to have triangles with a vertex at these filtered out points since the same set of points is used for something else (the sides of a 3d extrusion of the polygon). which does not need the filtering.
Is there a way to avoid the filtering ? It looks the algorithm may rely on not having colinear segments ? Eg. this is done not just for performance reasons ?
Yeah, filtering fixes some really nasty degenerate cases for the algorithm. You can check this yourself by adding return start in the filterPoints function so that it does nothing and then running the tests — a lot of them will break hard.
Can you describe in more detail why you can't use triangles on filtered points? Even if unfiltered points set is used for something else, the fact the triangles don't use the colinear vertices won't make a visual difference, right?
I think about adopting earcut for https://github.com/x3dom/x3dom which currently uses very basic earclipping to triangulate polygons. The main use case I see is extrusions where earclipping is used to fill end caps but the sides are triangulated/connected independently. Also it is just good practice to preserve as much as possible of the input and to have no surprises.
Here is a current PR x3dom/x3dom#577 which provides some context.
Ah, I see — makes sense. I pushed a branch (less-filtering) where filtering colinear/duplicate points doesn't happen unless we can't find a valid ear to clip. Please try it in x3dom and see if it works correctly.
This improves performance and fixes this issue but may (or may not) lead to some unhandled edge cases, although we can assume it won't cause any trouble until we find a test case that does.
BTW, what do you think about adjacent duplicate (not just colinear) points? Can we remove them safely by default?
Thanks ! It may be a while since in x3dom earclip function consumers provide their own linked list but I will give adopting earcut.js a try. Also, the x3dom developers have a policy to not include or rely on external libraries but for a small one perhaps after some streamlining (hole support not really required, perhaps not even the cool hashing) it would be a case of absorbing it which is probably acceptable. The copyright notice would be always retained.
Having adjacent duplicate points would generally indicate some issue during generation of the polygon but it may happen for some automated procedures. Since zero area triangles are accepted for the sides of an extrusion, again filtering out these out would lead to a mesh with zero area holes and rendering artefacts. But in this case, it may be beneficial as an indicator that the polygon has a problem. So, if possible it would be better to not filter but if necessary it should be done, similar to the colinear cases.
BTW, these Hilbert curves may make good test polygons since they have a lot of reflexes and may hit numerical corner cases. They also have colinear segments.
Here are the vertices of a level 5 one:
Activity
mourner commentedon Nov 13, 2015
Yeah, filtering fixes some really nasty degenerate cases for the algorithm. You can check this yourself by adding
return startin thefilterPointsfunction so that it does nothing and then running the tests — a lot of them will break hard.Can you describe in more detail why you can't use triangles on filtered points? Even if unfiltered points set is used for something else, the fact the triangles don't use the colinear vertices won't make a visual difference, right?
andreasplesch commentedon Nov 13, 2015
I think about adopting earcut for https://github.com/x3dom/x3dom which currently uses very basic earclipping to triangulate polygons. The main use case I see is extrusions where earclipping is used to fill end caps but the sides are triangulated/connected independently. Also it is just good practice to preserve as much as possible of the input and to have no surprises.
Here is a current PR x3dom/x3dom#577 which provides some context.
only filter colinear/duplicate points if we're in trouble
mourner commentedon Nov 13, 2015
Ah, I see — makes sense. I pushed a branch (
less-filtering) where filtering colinear/duplicate points doesn't happen unless we can't find a valid ear to clip. Please try it in x3dom and see if it works correctly.This improves performance and fixes this issue but may (or may not) lead to some unhandled edge cases, although we can assume it won't cause any trouble until we find a test case that does.
BTW, what do you think about adjacent duplicate (not just colinear) points? Can we remove them safely by default?
andreasplesch commentedon Nov 13, 2015
Thanks ! It may be a while since in x3dom earclip function consumers provide their own linked list but I will give adopting earcut.js a try. Also, the x3dom developers have a policy to not include or rely on external libraries but for a small one perhaps after some streamlining (hole support not really required, perhaps not even the cool hashing) it would be a case of absorbing it which is probably acceptable. The copyright notice would be always retained.
Having adjacent duplicate points would generally indicate some issue during generation of the polygon but it may happen for some automated procedures. Since zero area triangles are accepted for the sides of an extrusion, again filtering out these out would lead to a mesh with zero area holes and rendering artefacts. But in this case, it may be beneficial as an indicator that the polygon has a problem. So, if possible it would be better to not filter but if necessary it should be done, similar to the colinear cases.
BTW, these Hilbert curves may make good test polygons since they have a lot of reflexes and may hit numerical corner cases. They also have colinear segments.
Here are the vertices of a level 5 one:
mourner commentedon Nov 13, 2015
@andreasplesch great, thanks! I'll think about merging that branch and making a release then (including your test case too).