#include #include #include #include #include "triangulate.h" static const float EPSILON=0.0000000001f; float Triangulate::Area(const Vector2dVector &contour) { int n = contour.size(); float A=0.0f; for(int p=n-1,q=0; q= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); }; bool Triangulate::Snip(const Vector2dVector &contour,int u,int v,int w,int n,int *V) { int p; float Ax, Ay, Bx, By, Cx, Cy, Px, Py; Ax = contour[V[u]].GetX(); Ay = contour[V[u]].GetY(); Bx = contour[V[v]].GetX(); By = contour[V[v]].GetY(); Cx = contour[V[w]].GetX(); Cy = contour[V[w]].GetY(); if ( EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) ) return false; for (p=0;p2; ) { /* if we loop, it is probably a non-simple polygon */ if (0 >= (count--)) { //** Triangulate: ERROR - probable bad polygon! return false; } /* three consecutive vertices in current polygon, */ int u = v ; if (nv <= u) u = 0; /* previous */ v = u+1; if (nv <= v) v = 0; /* new v */ int w = v+1; if (nv <= w) w = 0; /* next */ if ( Snip(contour,u,v,w,nv,V) ) { int a,b,c,s,t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ result.push_back( contour[a] ); result.push_back( contour[b] ); result.push_back( contour[c] ); m++; /* remove v from remaining polygon */ for(s=v,t=v+1;t