diff --git a/Include/tesselator.h b/Include/tesselator.h index 38e05f1..3d43155 100755 --- a/Include/tesselator.h +++ b/Include/tesselator.h @@ -118,10 +118,15 @@ enum TessElementType // TESS_CONSTRAINED_DELAUNAY_TRIANGULATION // If enabled, the initial triagulation is improved with non-robust Constrained Delayney triangulation. // Disable by default. +// +// TESS_REVERSE_CONTOURS +// If enabled, tessAddContour() will treat CW contours as CCW and vice versa +// Disabled by default. enum TessOption { TESS_CONSTRAINED_DELAUNAY_TRIANGULATION, + TESS_REVERSE_CONTOURS }; typedef float TESSreal; diff --git a/Source/tess.c b/Source/tess.c index 8059bf4..a2f5e14 100755 --- a/Source/tess.c +++ b/Source/tess.c @@ -629,6 +629,8 @@ TESStesselator* tessNewTess( TESSalloc* alloc ) tess->bmax[0] = 0; tess->bmax[1] = 0; + tess->reverseContours = 0; + tess->windingRule = TESS_WINDING_ODD; if (tess->alloc.regionBucketSize < 16) @@ -973,8 +975,8 @@ void tessAddContour( TESStesselator *tess, int size, const void* vertices, * vertices in such an order that a CCW contour will add +1 to * the winding number of the region inside the contour. */ - e->winding = 1; - e->Sym->winding = -1; + e->winding = tess->reverseContours ? -1 : 1; + e->Sym->winding = tess->reverseContours ? 1 : -1; } } @@ -985,6 +987,9 @@ void tessSetOption( TESStesselator *tess, int option, int value ) case TESS_CONSTRAINED_DELAUNAY_TRIANGULATION: tess->processCDT = value > 0 ? 1 : 0; break; + case TESS_REVERSE_CONTOURS: + tess->reverseContours = value > 0 ? 1 : 0; + break; } } diff --git a/Source/tess.h b/Source/tess.h index c1f981f..30fda27 100755 --- a/Source/tess.h +++ b/Source/tess.h @@ -62,7 +62,8 @@ struct TESStesselator { TESSreal bmax[2]; int processCDT; /* option to run Constrained Delayney pass. */ - + int reverseContours; /* tessAddContour() will treat CCW contours as CW and vice versa */ + /*** state needed for the line sweep ***/ int windingRule; /* rule for determining polygon interior */