From 2cf811d63537492b04d8240e1f6935a3fa8b8f74 Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Wed, 29 Jul 2009 21:24:11 -0400 Subject: [PATCH] point event pointers --- src/org/poly2tri/Poly2Tri.scala | 2 +- src/org/poly2tri/cdt/AFront.scala | 4 +-- src/org/poly2tri/cdt/CDT.scala | 42 +++++++++++++++++++++++++++---- src/org/poly2tri/cdt/Mesh.scala | 3 ++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index e9ddcd5..41c6fe9 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -91,7 +91,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { def render(container: GameContainer, g: Graphics) { - g.drawString("'1-5' to cycle models", 10, 540) + g.drawString("'1-6' to cycle models", 10, 540) g.drawString("'SPACE' to turn on debug info", 10, 552) g.drawString("'m' to show trapezoidal map (debug mode)", 10, 564) g.drawString("'e' to switch Seidel / EarClip", 10, 576) diff --git a/src/org/poly2tri/cdt/AFront.scala b/src/org/poly2tri/cdt/AFront.scala index f8fe122..b976490 100644 --- a/src/org/poly2tri/cdt/AFront.scala +++ b/src/org/poly2tri/cdt/AFront.scala @@ -36,10 +36,10 @@ import shapes.{Point, Triangle} class AFront(iTriangle: Triangle) { // Doubly linked list - var head = new Node(iTriangle.points(0), iTriangle) + var head = new Node(iTriangle.points(1), iTriangle) var tail = new Node(iTriangle.points(2), iTriangle) - head.next = new Node(iTriangle.points(1), iTriangle) + head.next = new Node(iTriangle.points(0), iTriangle) head.next.next = tail tail.prev = head.next diff --git a/src/org/poly2tri/cdt/CDT.scala b/src/org/poly2tri/cdt/CDT.scala index 8b6f43e..0dfdc5a 100644 --- a/src/org/poly2tri/cdt/CDT.scala +++ b/src/org/poly2tri/cdt/CDT.scala @@ -68,7 +68,7 @@ object CDT { val segments = initSegments(points) val sortedPoints = pointSort(points) - val initialTriangle = new Triangle(Array(p1, sortedPoints(0), p2), null) + val initialTriangle = new Triangle(Array(sortedPoints(0), p1, p2), null) new CDT(sortedPoints, segments, initialTriangle) } @@ -120,13 +120,45 @@ class CDT(val points: List[Point], val segments: List[Segment], initialTriangle: for(i <- 1 until points.size) { val point = points(i) - val triangle = aFront.locate(point) - val (nPoints, nTriangle) = triangle - println(nPoints) + pointEvent(point) + legalization + edgeEvent(point) } - } + // Point event + private def pointEvent(point: Point) { + + // Neightbor points (ccw & cw) and triangle(i) + val (nPts, nTri) = aFront.locate(point) + val pts = Array(point, nPts(0), nPts(1)) + val neighbors = Array(nTri, null, null) + val triangle = new Triangle(pts, neighbors) + mesh.map += triangle + + // Update neighbor's pointers + if(nPts(0) == nTri.points(1) && nPts(1) == nTri.points(2)) + nTri.neighbors(2) = triangle + else if(nPts(0) == nTri.points(2) && nPts(1) == nTri.points(1)) + nTri.neighbors(1) = triangle + else + throw new Exception("CDT Error!") + + } + + private def legalization { + + } + + private def legalizeEdge { + + } + + // EdgeEvent + private def edgeEvent(point: Point) { + + } + private def finalization { } diff --git a/src/org/poly2tri/cdt/Mesh.scala b/src/org/poly2tri/cdt/Mesh.scala index 826e58b..6a65aa3 100644 --- a/src/org/poly2tri/cdt/Mesh.scala +++ b/src/org/poly2tri/cdt/Mesh.scala @@ -35,7 +35,8 @@ import scala.collection.mutable.HashSet import shapes.{Point, Triangle} class Mesh(initialTriangle: Triangle) { - + + // Triangles that constitute the mesh val map = HashSet(initialTriangle) }