mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-26 15:26:12 +01:00
fixed triangulation bug
This commit is contained in:
parent
00b91269b1
commit
cd7d09ee8a
@ -87,7 +87,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
val i18 = "data/i.18"
|
||||
val tank = "data/tank.dat"
|
||||
|
||||
var currentModel = strange
|
||||
var currentModel = nazcaMonkey
|
||||
var doCDT = true
|
||||
|
||||
var mouseButton = 0
|
||||
|
@ -251,20 +251,20 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
val point1 = if(ahead) edge.q else edge.p
|
||||
val point2 = if(ahead) edge.p else edge.q
|
||||
|
||||
var node = aFront.locatePoint(point1)
|
||||
val first = node
|
||||
var pNode = aFront.locatePoint(point1)
|
||||
val first = pNode
|
||||
|
||||
val points = new ArrayBuffer[Point]
|
||||
// Neighbor triangles
|
||||
val nTriangles = new ArrayBuffer[Triangle]
|
||||
nTriangles += node.triangle
|
||||
nTriangles += pNode.triangle
|
||||
|
||||
node = node.next
|
||||
pNode = pNode.next
|
||||
|
||||
while(node.point != point2) {
|
||||
points += node.point
|
||||
nTriangles += node.triangle
|
||||
node = node.next
|
||||
while(pNode.point != point2) {
|
||||
points += pNode.point
|
||||
nTriangles += pNode.triangle
|
||||
pNode = pNode.next
|
||||
}
|
||||
|
||||
// Triangulate empty areas.
|
||||
@ -283,7 +283,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
}
|
||||
|
||||
// Update advancing front
|
||||
aFront link (first, node, edgeTri)
|
||||
aFront link (first, pNode, edgeTri)
|
||||
|
||||
// Update neighbors
|
||||
edgeNeighbors(nTriangles, T)
|
||||
@ -294,6 +294,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
} else if(firstTriangle.contains(edge.q, edge.p)) {
|
||||
// Mark constrained edge
|
||||
firstTriangle markEdge(edge.q, edge.p)
|
||||
firstTriangle.finalized = true
|
||||
} else {
|
||||
throw new Exception("Triangulation error")
|
||||
//null
|
||||
@ -326,7 +327,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
if(P.size > 1) {
|
||||
var c = P.first
|
||||
for(j <- 1 until P.size) {
|
||||
if(illegal(a, P(j), b, c)) {
|
||||
if(illegal(a, c, b, P(j))) {
|
||||
c = P(j)
|
||||
i = j
|
||||
}
|
||||
@ -445,6 +446,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
}
|
||||
t2.markNeighbor(t1)
|
||||
|
||||
// Don't legalize these triangles again
|
||||
t2.finalized = true
|
||||
t1.finalized = true
|
||||
|
||||
// Update advancing front
|
||||
aFront.insertLegalized(t1.points(1), t1, node)
|
||||
|
||||
|
@ -126,7 +126,7 @@ class Triangle(val points: Array[Point]) {
|
||||
|
||||
// Locate first triangle crossed by constrained edge
|
||||
def locateFirst(edge: Segment): Triangle = {
|
||||
|
||||
if(contains(edge)) this
|
||||
if(edge.q == points(0))
|
||||
search(points(1), points(2), edge, neighbors(2))
|
||||
else if(edge.q == points(1))
|
||||
|
Loading…
Reference in New Issue
Block a user