bug fixes

This commit is contained in:
Mason 2009-08-07 14:42:23 -04:00
parent f4bacf8cf6
commit 709d8b17ca
5 changed files with 10 additions and 9 deletions

View File

@ -84,7 +84,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
val strange = "data/strange.dat" val strange = "data/strange.dat"
val i18 = "data/i.18" val i18 = "data/i.18"
var currentModel = nazcaMonkey var currentModel = star
var mouseButton = 0 var mouseButton = 0
var mousePressed = false var mousePressed = false

View File

@ -108,6 +108,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Triangle list // Triangle list
def triangles = mesh.map def triangles = mesh.map
def triangleMesh = mesh.map
def debugTriangles = mesh.debug def debugTriangles = mesh.debug
// The triangle mesh // The triangle mesh
@ -139,7 +140,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
} }
// Process edge events // Process edge events
point.edges.foreach(e => edgeEvent(e, triangle)) point.edges.foreach(e => edgeEvent(e, triangle))
//if(i == 10) {cTri = triangle; mesh.debug += cTri} //if(i == 5) {cTri = triangle; mesh.debug += cTri}
} }
//mesh clean cTri //mesh clean cTri
} }
@ -424,7 +425,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val c2 = Util.collinear(t2.points(0), t2.points(1), oPoint) val c2 = Util.collinear(t2.points(0), t2.points(1), oPoint)
val c3 = Util.collinear(t2.points(1), t2.points(2), oPoint) val c3 = Util.collinear(t2.points(1), t2.points(2), oPoint)
val c4 = Util.collinear(t2.points(0), t2.points(2), oPoint) val c4 = Util.collinear(t2.points(0), t2.points(2), oPoint)
val collinear = !(c1 && c2 && c3 && c4) val collinear = (c1 || c2 || c3 || c4)
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) { if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) {
@ -433,8 +434,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val ccwNeighbor = t2.neighborCCW(oPoint) val ccwNeighbor = t2.neighborCCW(oPoint)
if(ccwNeighbor != null) { if(ccwNeighbor != null) {
//val point = if(t1.points(0).x > oPoint.x) t1.points(1) else t1.points(2) val point = if(t1.points(0).x > oPoint.x) t1.points(1) else t1.points(2)
ccwNeighbor.updateNeighbors(oPoint, t1.points(2), t1, mesh.debug) ccwNeighbor.updateNeighbors(oPoint, point, t1, mesh.debug)
t1.neighbors(1) = ccwNeighbor t1.neighbors(1) = ccwNeighbor
} }

View File

@ -46,13 +46,13 @@ class Mesh(initialTriangle: Triangle) {
def clean(triangle: Triangle) { def clean(triangle: Triangle) {
if(triangle != null && triangle.clean == false) { if(triangle != null && triangle.clean == false) {
triangle.clean = true triangle.clean = true
triangles += triangle
if(triangle.edges(0) == false) if(triangle.edges(0) == false)
clean(triangle.neighbors(0)) clean(triangle.neighbors(0))
if(triangle.edges(1) == false) if(triangle.edges(1) == false)
clean(triangle.neighbors(1)) clean(triangle.neighbors(1))
if(triangle.edges(2) == false) if(triangle.edges(2) == false)
clean(triangle.neighbors(2)) clean(triangle.neighbors(2))
triangles += triangle
} }
} }

View File

@ -54,6 +54,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
neighbors(2) = triangle neighbors(2) = triangle
else { else {
debug += triangle debug += triangle
debug += this
throw new Exception("Neighbor pointer error, please report!") throw new Exception("Neighbor pointer error, please report!")
} }
} }

View File

@ -51,11 +51,10 @@ object Util {
// Determinant // Determinant
val d = a11*(a22-a32) - a12*(a21-a31) + (a21*a32-a31*a22) val d = a11*(a22-a32) - a12*(a21-a31) + (a21*a32-a31*a22)
if(Math.abs(d) <= COLLINEAR_SLOP) { if(Math.abs(d) <= COLLINEAR_SLOP)
true true
} else { else
false false
}
} }