From 690f0e138cd1b9c4c26777b262f66aeec9ae7520 Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Wed, 19 Aug 2009 19:42:42 -0400 Subject: [PATCH] fixed advanding front, constrained edge bug --- src/org/poly2tri/Poly2Tri.scala | 2 +- src/org/poly2tri/cdt/AFront.scala | 20 +++++++------------- src/org/poly2tri/cdt/CDT.scala | 21 +++++---------------- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index 7d49dd0..6389b25 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -180,7 +180,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { val draw = if(drawcdtMesh) slCDT.triangleMesh else slCDT.triangles draw.foreach( t => { - if(true) { + if(false) { for(i <- 0 to 2) { val s = t.points(i) val e = if(i == 2) t.points(0) else t.points(i + 1) diff --git a/src/org/poly2tri/cdt/AFront.scala b/src/org/poly2tri/cdt/AFront.scala index 2648db0..a67e45a 100644 --- a/src/org/poly2tri/cdt/AFront.scala +++ b/src/org/poly2tri/cdt/AFront.scala @@ -93,30 +93,24 @@ class AFront(iTriangle: Triangle) { def constrainedEdge(sNode: Node, eNode: Node, T1: ArrayBuffer[Triangle], T2: ArrayBuffer[Triangle], edge: Segment) { - var node = sNode + var node = sNode.prev val point1 = edge.q val point2 = edge.p - var marked = false - // Scan the advancing front and update Node triangle pointers - while(node != null && node != eNode) { - + while(node != null && node != eNode.next) { T2.foreach(t => { if(t.contains(node.point, node.next.point)) node.triangle = t - marked = true }) - - if(!marked) - T1.foreach(t => { - if(t.contains(node.point, node.next.point)) - node.triangle = t - }) - + T1.foreach(t => { + if(t.contains(node.point, node.next.point)) + node.triangle = t + }) node = node.next } + } def -=(tuple: Tuple3[Node, Node, Triangle]) { diff --git a/src/org/poly2tri/cdt/CDT.scala b/src/org/poly2tri/cdt/CDT.scala index 134c450..695e7ed 100644 --- a/src/org/poly2tri/cdt/CDT.scala +++ b/src/org/poly2tri/cdt/CDT.scala @@ -139,7 +139,7 @@ class CDT(polyLine: Array[Point], clearPoint: Point) { // Implement sweep-line private def sweep { - for(i <- 1 until 36 /*points.size*/) { + for(i <- 1 until points.size) { val point = points(i) // Process Point event val node = pointEvent(point) @@ -208,9 +208,7 @@ class CDT(polyLine: Array[Point], clearPoint: Point) { tList.foreach(t => { t.neighbors.foreach(n => if(n != null && !tList.contains(n)) nTriangles += n) mesh.map -= t - //mesh.debug += t }) - //nTriangles.foreach(n => mesh.debug += n) val lPoints = new ArrayBuffer[Point] val rPoints = new ArrayBuffer[Point] @@ -250,11 +248,8 @@ class CDT(polyLine: Array[Point], clearPoint: Point) { val point1 = if(ahead) edge.q else edge.p val point2 = if(ahead) edge.p else edge.q - val sNode = if(ahead) node else aFront.locate(point1).prev - val eNode = aFront.locate(point2).next - - //mesh.debug += sNode.triangle - //mesh.debug += eNode.triangle + val sNode = if(ahead) node else aFront.locate(point1) + val eNode = aFront.locate(point2) aFront.constrainedEdge(sNode, eNode, T1, T2, edge) @@ -262,15 +257,9 @@ class CDT(polyLine: Array[Point], clearPoint: Point) { T1.last markEdge(point1, point2) T2.last markEdge(point1, point2) // Copy constraied edges from old triangles - T1.foreach(t => {t.markEdge(tList)/*;mesh.debug += t*/}) - T2.foreach(t => {t.markEdge(tList)/*;mesh.debug += t*/}) + T1.foreach(t => t.markEdge(tList)) + T2.foreach(t => t.markEdge(tList)) - var n = sNode - while(n != eNode) { - mesh.debug += n.triangle - n = n.next - } - } else if(firstTriangle == null) { // No triangles are intersected by the edge; edge must lie outside the mesh