From bd128eb4e3446ff84e9d1af5d93c1f98569df6a2 Mon Sep 17 00:00:00 2001 From: Mason Date: Sun, 16 Aug 2009 17:08:08 -0400 Subject: [PATCH] updated earClip init --- src/org/poly2tri/Poly2Tri.scala | 5 ----- src/org/poly2tri/cdt/AFront.scala | 3 --- src/org/poly2tri/cdt/CDT.scala | 1 + src/org/poly2tri/earClip/EarClip.scala | 13 ++++++++++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index a4c6bbb..00a271c 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -395,11 +395,6 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { var xVerts = polyX.toArray var yVerts = polyY.toArray - - if(currentModel != strange) { - xVerts = xVerts.reverse - yVerts = yVerts.reverse - } val t1 = System.nanoTime earClip.triangulatePolygon(xVerts, yVerts, xVerts.size, earClipResults) diff --git a/src/org/poly2tri/cdt/AFront.scala b/src/org/poly2tri/cdt/AFront.scala index 6709096..5c1744a 100644 --- a/src/org/poly2tri/cdt/AFront.scala +++ b/src/org/poly2tri/cdt/AFront.scala @@ -117,9 +117,6 @@ class AFront(iTriangle: Triangle) { node = node.next } - - T1.last.markNeighbor(T2.last) - } def -=(tuple: Tuple3[Node, Node, Triangle]) { diff --git a/src/org/poly2tri/cdt/CDT.scala b/src/org/poly2tri/cdt/CDT.scala index 16cc29d..e26f0d7 100644 --- a/src/org/poly2tri/cdt/CDT.scala +++ b/src/org/poly2tri/cdt/CDT.scala @@ -229,6 +229,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian // Update neighbors edgeNeighbors(nTriangles, T1) edgeNeighbors(nTriangles, T2) + T1.last.markNeighbor(T2.last) // Update advancing front diff --git a/src/org/poly2tri/earClip/EarClip.scala b/src/org/poly2tri/earClip/EarClip.scala index 86f19fc..cd9864c 100644 --- a/src/org/poly2tri/earClip/EarClip.scala +++ b/src/org/poly2tri/earClip/EarClip.scala @@ -26,6 +26,7 @@ package org.poly2tri.earClip import shapes.Point +import utils.Util class EarClip { @@ -37,10 +38,20 @@ class EarClip { var numTriangles = 0 - def triangulatePolygon(xv: Array[Float], yv: Array[Float], vn: Int, results: Array[Triangle]): Int = { + def triangulatePolygon(x: Array[Float], y: Array[Float], vn: Int, results: Array[Triangle]): Int = { + val p1 = Point(x(0), y(0)) + val p2 = Point(x(1), y(1)) + val p3 = Point(x(2), y(2)) + + val ccw = Util.orient2d(p1, p2, p3) > 0 + + val xv = if(ccw) x else x.reverse.toArray + val yv = if(ccw) y else y.reverse.toArray + if (vn < 3) return 0 var vNum = vn + //Recurse and split on pinch points val pA = new Poly val pB = new Poly