aboutsummaryrefslogtreecommitdiff
path: root/core/math/triangulate.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez2016-11-04 12:55:08 +0100
committerRémi Verschelde2016-11-15 08:30:09 +0100
commitfada9d7a8e96e916a96e5e50f3f03ba74cbd5817 (patch)
tree3672c10acded8df452a87fe3cb20fe4530bfab39 /core/math/triangulate.cpp
parent82b458f160e4627f25c34cb16370bb26f18f6c74 (diff)
downloadgodot-fada9d7a8e96e916a96e5e50f3f03ba74cbd5817.tar.gz
godot-fada9d7a8e96e916a96e5e50f3f03ba74cbd5817.tar.zst
godot-fada9d7a8e96e916a96e5e50f3f03ba74cbd5817.zip
Clean/fix triangulation internals
Drop unused variable Remove commented-out code Fix leak by using Vector instead of raw memory (cherry picked from commit 0e1972aa5165722e677850bbf799af8ab6751a8d)
Diffstat (limited to 'core/math/triangulate.cpp')
-rw-r--r--core/math/triangulate.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 27b7c8667..5d1d3c793 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -71,7 +71,7 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay,
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
};
-bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,int *V)
+bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V)
{
int p;
float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
@@ -107,8 +107,8 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
if ( n < 3 ) return false;
-
- int *V = (int*)alloca(sizeof(int)*n);
+ Vector<int> V;
+ V.resize(n);
/* we want a counter-clockwise polygon in V */
@@ -122,7 +122,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
/* remove nv-2 Vertices, creating 1 triangle every time */
int count = 2*nv; /* error detection */
- for(int m=0, v=nv-1; nv>2; )
+ for(int v=nv-1; nv>2; )
{
/* if we loop, it is probably a non-simple polygon */
if (0 >= (count--))
@@ -144,18 +144,10 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
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] );
-*/
-
result.push_back( a );
result.push_back( b );
result.push_back( c );
- m++;
-
/* remove v from remaining polygon */
for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--;