From f8db8a3faa30b71dca33ced38be16d3f93f43e8a Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Sun, 19 Mar 2017 00:36:26 +0100 Subject: Bring that Whole New World to the Old Continent too Applies the clang-format style to the 2.1 branch as done for master in 5dbf1809c6e3e905b94b8764e99491e608122261. --- core/math/triangulate.cpp | 192 ++++++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 93 deletions(-) (limited to 'core/math/triangulate.cpp') diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 5112077bc..8dadf9c63 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -28,133 +28,139 @@ /*************************************************************************/ #include "triangulate.h" -float Triangulate::get_area(const Vector &contour) -{ +float Triangulate::get_area(const Vector &contour) { - int n = contour.size(); - const Vector2 *c=&contour[0]; + int n = contour.size(); + const Vector2 *c = &contour[0]; - float A=0.0f; + float A = 0.0f; - for(int p=n-1,q=0; q= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); + float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; + float cCROSSap, bCROSScp, aCROSSbp; + + ax = Cx - Bx; + ay = Cy - By; + bx = Ax - Cx; + by = Ay - Cy; + cx = Bx - Ax; + cy = By - Ay; + apx = Px - Ax; + apy = Py - Ay; + bpx = Px - Bx; + bpy = Py - By; + cpx = Px - Cx; + cpy = Py - Cy; + + aCROSSbp = ax * bpy - ay * bpx; + cCROSSap = cx * apy - cy * apx; + bCROSScp = bx * cpy - by * cpx; + + return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); }; -bool Triangulate::snip(const Vector &p_contour,int u,int v,int w,int n,const Vector& V) -{ - int p; - float Ax, Ay, Bx, By, Cx, Cy, Px, Py; - const Vector2 *contour=&p_contour[0]; +bool Triangulate::snip(const Vector &p_contour, int u, int v, int w, int n, const Vector &V) { + int p; + float Ax, Ay, Bx, By, Cx, Cy, Px, Py; + const Vector2 *contour = &p_contour[0]; - Ax = contour[V[u]].x; - Ay = contour[V[u]].y; + Ax = contour[V[u]].x; + Ay = contour[V[u]].y; - Bx = contour[V[v]].x; - By = contour[V[v]].y; + Bx = contour[V[v]].x; + By = contour[V[v]].y; - Cx = contour[V[w]].x; - Cy = contour[V[w]].y; + Cx = contour[V[w]].x; + Cy = contour[V[w]].y; - if ( CMP_EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) ) return false; + if (CMP_EPSILON > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) return false; - for (p=0;p &contour,Vector &result) -{ - /* allocate and initialize list of Vertices in polygon */ - - int n = contour.size(); - if ( n < 3 ) return false; +bool Triangulate::triangulate(const Vector &contour, Vector &result) { + /* allocate and initialize list of Vertices in polygon */ + int n = contour.size(); + if (n < 3) return false; - Vector V; - V.resize(n); + Vector V; + V.resize(n); - /* we want a counter-clockwise polygon in V */ + /* we want a counter-clockwise polygon in V */ - if ( 0.0f < get_area(contour) ) - for (int v=0; v2; ) - { - /* if we loop, it is probably a non-simple polygon */ - if (0 >= (count--)) - { - //** Triangulate: ERROR - probable bad polygon! - return false; - } + for (int v = nv - 1; nv > 2;) { + /* 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 */ + /* 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; + 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]; + /* true names of the vertices */ + a = V[u]; + b = V[v]; + c = V[w]; - /* output Triangle */ - result.push_back( a ); - result.push_back( b ); - result.push_back( c ); + /* output Triangle */ + result.push_back(a); + result.push_back(b); + result.push_back(c); - /* remove v from remaining polygon */ - for(s=v,t=v+1;t