Hi Brendan,
Thanks so much for creating this awesome library! I've learned a lot from using it. I've tried other JS libraries like earcut, poly2tri, and several point-in-polygon libraries, but libtess.js gives the best results across many different inputs.
This is a long shot and I'm not sure where to post this but maybe you might have some insights (or alternatively this could be rubber duck debugging for me). Anyway, I'm using a mapping library called CesiumJS to render arbitrary polygons on a globe. However, I want to exclude certain polygons from being rendered, so this is where libtess.js comes in.
Using libtess.js, I've implemented code very similarly to the simple triangulation example you've provided, so initially I created a single contour of 2 triangles, as seen here (the blue and brown triangles):
Next, I added another contour for an arbitrary polygon I want to not render (it's actually a "circle" polygon with 100 points that are radius-distanced from a center point). This produced the following results, where I render every triangle returned from the array passed into gluTessBeginPolygon:
This worked better than every other library/algorithm I've tried (many others had issues triangulating the contours) but my goal is to exclude the center circle.
I tried setting the winding rule to every possible rule to no avail. However, the "GLU_TESS_WINDING_ABS_GEQ_TWO" rule seems to produce the interior contour/polygon that I'm trying to exclude, so that seemed interesting:
Here are the other rules I tried
tessy.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE, libtess.windingRule.GLU_TESS_WINDING_NEGATIVE);
tessy.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE, libtess.windingRule.GLU_TESS_WINDING_ODD);
tessy.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE, libtess.windingRule.GLU_TESS_WINDING_NONZERO);
GLU_TESS_WINDING_NEGATIVE:
GLU_TESS_WINDING_POSITIVE:
GLU_TESS_WINDING_NONZERO:
So overall, my question is: when I run gluTessBeginPolygon and pass in an array, how can I make it so the array I get back excludes the triangles generated for a particular contour?