mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
bug fixes
This commit is contained in:
parent
50848ab60c
commit
5fa8c4501e
@ -139,7 +139,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
// Process Point event
|
||||
var triangle = pointEvent(point)
|
||||
// Process edge events
|
||||
if(triangle != null)
|
||||
point.edges.foreach(e => triangle = edgeEvent(e, triangle))
|
||||
if(i == CDT.clearPoint) {cleanTri = triangle; mesh.debug += cleanTri}
|
||||
|
||||
@ -256,9 +255,29 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
edgeNeighbors(nTriangles, T1)
|
||||
edgeNeighbors(nTriangles, T2)
|
||||
|
||||
// Mark constrained edges
|
||||
T1.first.mark(point1, point2)
|
||||
T2.first.mark(point1, point2)
|
||||
// Select edge triangle
|
||||
var edgeTri1: Triangle = null
|
||||
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
|
||||
first
|
||||
@ -298,29 +317,30 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
|
||||
// Select edge triangle
|
||||
var edgeTri: Triangle = null
|
||||
T.foreach(t =>
|
||||
if(t.contains(first.point, node.point))
|
||||
edgeTri = t
|
||||
)
|
||||
assert(edgeTri != null)
|
||||
var i = 0
|
||||
while(edgeTri == null) {
|
||||
if(T(i).contains(first.point, node.point))
|
||||
edgeTri = T(i)
|
||||
i += 1
|
||||
}
|
||||
|
||||
aFront link (first, node, edgeTri)
|
||||
|
||||
// Mark constrained edge
|
||||
edgeTri mark(edge.p, edge.q)
|
||||
|
||||
// Update neighbors
|
||||
edgeNeighbors(nTriangles, T)
|
||||
|
||||
// Mark constrained edge
|
||||
edgeTri mark(edge.p, edge.q)
|
||||
|
||||
// Return original triangle
|
||||
triangle
|
||||
|
||||
} else {
|
||||
|
||||
} else if(firstTriangle.contains(edge.p, edge.q)) {
|
||||
// Mark constrained edge
|
||||
if(firstTriangle != null)
|
||||
firstTriangle mark(edge.p, edge.q)
|
||||
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 point = t1.points(0)
|
||||
|
||||
val oPoint = t2 oppositePoint t1
|
||||
|
||||
// Try to avoid creating degenerate triangles
|
||||
val collinear = t1.collinear(oPoint) || t2.collinear(oPoint, point)
|
||||
|
||||
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)) && !t2.finalized) {
|
||||
|
||||
// Flip edge and rotate everything clockwise
|
||||
t1.legalize(oPoint)
|
||||
|
@ -48,9 +48,11 @@ class Triangle(val points: Array[Point]) {
|
||||
// Finalization flag
|
||||
var clean = false
|
||||
|
||||
var finalized = false
|
||||
|
||||
// Update neighbor pointers
|
||||
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)))
|
||||
neighbors(0) = t
|
||||
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 */
|
||||
def markNeighbor(t: Triangle) {
|
||||
assert(t != this, "self-pointer error")
|
||||
|
||||
if (t.contains(points(1), points(2))) {
|
||||
neighbors(0) = t
|
||||
t.markNeighbor(points(1), points(2), this)
|
||||
@ -93,7 +95,6 @@ class Triangle(val points: Array[Point]) {
|
||||
t.printDebug
|
||||
printDebug
|
||||
println(area + " | " + t.area)
|
||||
|
||||
throw new Exception("Point location error, please report")
|
||||
}
|
||||
|
||||
@ -308,10 +309,13 @@ class Triangle(val points: Array[Point]) {
|
||||
// Mark edge as constrained
|
||||
private def markEdge(p: Point, q: Point) {
|
||||
if((q == points(0) && p == points(1)) || (q == points(1) && p == points(0))) {
|
||||
finalized = true
|
||||
edges(2) = true
|
||||
} else if ((q == points(0) && p == points(2)) || (q == points(2) && p == points(0))) {
|
||||
finalized = true
|
||||
edges(1) = true
|
||||
} else if ((q == points(1) && p == points(2)) || (q == points(2) && p == points(1))){
|
||||
finalized = true
|
||||
edges(0) = true
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ object Util {
|
||||
return det
|
||||
} else {
|
||||
// Cheat a little bit.... we have a degenerate triangle
|
||||
val c = pc * 1.00001f
|
||||
val c = pc * 1.0001f
|
||||
return orient2d(pa, pb, c)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user