bug fixes

This commit is contained in:
zzzzrrr 2009-08-11 17:25:57 -04:00
parent 50848ab60c
commit 5fa8c4501e
3 changed files with 47 additions and 27 deletions

View File

@ -139,8 +139,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Process Point event // Process Point event
var triangle = pointEvent(point) var triangle = pointEvent(point)
// Process edge events // Process edge events
if(triangle != null) point.edges.foreach(e => triangle = edgeEvent(e, triangle))
point.edges.foreach(e => triangle = edgeEvent(e, triangle))
if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri} if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri}
} catch { } catch {
@ -256,9 +255,29 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
edgeNeighbors(nTriangles, T1) edgeNeighbors(nTriangles, T1)
edgeNeighbors(nTriangles, T2) edgeNeighbors(nTriangles, T2)
// Mark constrained edges // Select edge triangle
T1.first.mark(point1, point2) var edgeTri1: Triangle = null
T2.first.mark(point1, point2) var i = 0
while(edgeTri1 == null) {
if(T1(i).contains(point1, point2))
edgeTri1 = T1(i)
i += 1
}
// Select edge triangle
var edgeTri2: Triangle = null
i = 0
while(edgeTri2 == null) {
if(T2(i).contains(point1, point2))
edgeTri2 = T2(i)
i += 1
}
edgeTri1.markNeighbor(edgeTri2)
// Mark constrained edge
edgeTri1 mark(point1, point2)
edgeTri2 mark(point1, point2)
// Double check returning T2.first vs T1.first // Double check returning T2.first vs T1.first
first first
@ -298,29 +317,30 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Select edge triangle // Select edge triangle
var edgeTri: Triangle = null var edgeTri: Triangle = null
T.foreach(t => var i = 0
if(t.contains(first.point, node.point)) while(edgeTri == null) {
edgeTri = t if(T(i).contains(first.point, node.point))
) edgeTri = T(i)
assert(edgeTri != null) i += 1
}
aFront link (first, node, edgeTri) aFront link (first, node, edgeTri)
// Mark constrained edge
edgeTri mark(edge.p, edge.q)
// Update neighbors // Update neighbors
edgeNeighbors(nTriangles, T) edgeNeighbors(nTriangles, T)
// Mark constrained edge
edgeTri mark(edge.p, edge.q)
// Return original triangle // Return original triangle
triangle triangle
} else { } else if(firstTriangle.contains(edge.p, edge.q)) {
// Mark constrained edge // Mark constrained edge
if(firstTriangle != null) firstTriangle mark(edge.p, edge.q)
firstTriangle mark(edge.p, edge.q)
triangle triangle
} else {
throw new Exception("Triangulation error")
} }
} }
@ -447,13 +467,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val t2 = node.triangle val t2 = node.triangle
val point = t1.points(0) val point = t1.points(0)
val oPoint = t2 oppositePoint t1 val oPoint = t2 oppositePoint t1
// Try to avoid creating degenerate triangles if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !t2.finalized) {
val collinear = t1.collinear(oPoint) || t2.collinear(oPoint, point)
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) {
// Flip edge and rotate everything clockwise // Flip edge and rotate everything clockwise
t1.legalize(oPoint) t1.legalize(oPoint)

View File

@ -48,9 +48,11 @@ class Triangle(val points: Array[Point]) {
// Finalization flag // Finalization flag
var clean = false var clean = false
var finalized = false
// Update neighbor pointers // Update neighbor pointers
private def markNeighbor(p1: Point, p2: Point, t: Triangle) { private def markNeighbor(p1: Point, p2: Point, t: Triangle) {
assert(t != this, "self-pointer error")
if((p1 == points(2) && p2 == points(1)) || (p1 == points(1) && p2 == points(2))) if((p1 == points(2) && p2 == points(1)) || (p1 == points(1) && p2 == points(2)))
neighbors(0) = t neighbors(0) = t
else if((p1 == points(0) && p2 == points(2)) || (p1 == points(2) && p2 == points(0))) else if((p1 == points(0) && p2 == points(2)) || (p1 == points(2) && p2 == points(0)))
@ -64,7 +66,7 @@ class Triangle(val points: Array[Point]) {
/* Exhaustive search to update neighbor pointers */ /* Exhaustive search to update neighbor pointers */
def markNeighbor(t: Triangle) { def markNeighbor(t: Triangle) {
assert(t != this, "self-pointer error")
if (t.contains(points(1), points(2))) { if (t.contains(points(1), points(2))) {
neighbors(0) = t neighbors(0) = t
t.markNeighbor(points(1), points(2), this) t.markNeighbor(points(1), points(2), this)
@ -93,7 +95,6 @@ class Triangle(val points: Array[Point]) {
t.printDebug t.printDebug
printDebug printDebug
println(area + " | " + t.area) println(area + " | " + t.area)
throw new Exception("Point location error, please report") throw new Exception("Point location error, please report")
} }
@ -308,10 +309,13 @@ class Triangle(val points: Array[Point]) {
// Mark edge as constrained // Mark edge as constrained
private def markEdge(p: Point, q: Point) { private def markEdge(p: Point, q: Point) {
if((q == points(0) && p == points(1)) || (q == points(1) && p == points(0))) { if((q == points(0) && p == points(1)) || (q == points(1) && p == points(0))) {
finalized = true
edges(2) = true edges(2) = true
} else if ((q == points(0) && p == points(2)) || (q == points(2) && p == points(0))) { } else if ((q == points(0) && p == points(2)) || (q == points(2) && p == points(0))) {
finalized = true
edges(1) = true edges(1) = true
} else if ((q == points(1) && p == points(2)) || (q == points(2) && p == points(1))){ } else if ((q == points(1) && p == points(2)) || (q == points(2) && p == points(1))){
finalized = true
edges(0) = true edges(0) = true
} }
} }

View File

@ -125,7 +125,7 @@ object Util {
return det return det
} else { } else {
// Cheat a little bit.... we have a degenerate triangle // Cheat a little bit.... we have a degenerate triangle
val c = pc * 1.00001f val c = pc * 1.0001f
return orient2d(pa, pb, c) return orient2d(pa, pb, c)
} }