mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-12-02 10:13:29 +01:00
fixed pointer bug
This commit is contained in:
parent
8ce22caf63
commit
50848ab60c
@ -283,11 +283,9 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
def selectModel(model: String) {
|
def selectModel(model: String) {
|
||||||
model match {
|
model match {
|
||||||
case "data/nazca_monkey.dat" =>
|
case "data/nazca_monkey.dat" =>
|
||||||
//CDT.clearPoint = 50
|
CDT.clearPoint = 50
|
||||||
doCDT = false; drawCDT = false; drawcdtMesh = false
|
|
||||||
loadModel(nazcaMonkey, 4.5f, Point(400, 300), 1500)
|
loadModel(nazcaMonkey, 4.5f, Point(400, 300), 1500)
|
||||||
case "data/bird.dat" =>
|
case "data/bird.dat" =>
|
||||||
doCDT = false; drawCDT = false; drawcdtMesh = false
|
|
||||||
CDT.clearPoint = 80
|
CDT.clearPoint = 80
|
||||||
loadModel(bird, 25f, Point(400, 300), 350)
|
loadModel(bird, 25f, Point(400, 300), 350)
|
||||||
case "data/i.snake" =>
|
case "data/i.snake" =>
|
||||||
@ -307,8 +305,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
CDT.clearPoint = 7
|
CDT.clearPoint = 7
|
||||||
loadModel(i18, 20f, Point(600f, 500f), 20)
|
loadModel(i18, 20f, Point(600f, 500f), 20)
|
||||||
case "data/nazca_heron.dat" =>
|
case "data/nazca_heron.dat" =>
|
||||||
doCDT = false; drawCDT = false; drawcdtMesh = false
|
CDT.clearPoint = 7
|
||||||
//CDT.clearPoint = 7
|
|
||||||
loadModel(nazcaHeron, 4.5f, Point(400f, 300f), 1500)
|
loadModel(nazcaHeron, 4.5f, Point(400f, 300f), 1500)
|
||||||
case "data/tank.dat" =>
|
case "data/tank.dat" =>
|
||||||
//doCDT = false; drawCDT = false; drawcdtMesh = false
|
//doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||||
|
@ -269,17 +269,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
// Apply constraint; traverse the AFront, and build triangles
|
// Apply constraint; traverse the AFront, and build triangles
|
||||||
|
|
||||||
val ahead = (edge.p.x > edge.q.x)
|
val ahead = (edge.p.x > edge.q.x)
|
||||||
|
|
||||||
val point1 = if(ahead) edge.q else edge.p
|
val point1 = if(ahead) edge.q else edge.p
|
||||||
val point2 = if(ahead) edge.p else edge.q
|
val point2 = if(ahead) edge.p else edge.q
|
||||||
|
|
||||||
|
var node = aFront.locate(point1)
|
||||||
|
val first = node
|
||||||
|
|
||||||
val points = new ArrayBuffer[Point]
|
val points = new ArrayBuffer[Point]
|
||||||
// Neighbor triangles
|
// Neighbor triangles
|
||||||
val nTriangles = new ArrayBuffer[Triangle]
|
val nTriangles = new ArrayBuffer[Triangle]
|
||||||
|
|
||||||
var node = aFront.locate(point1)
|
|
||||||
|
|
||||||
val first = node
|
|
||||||
nTriangles += node.triangle
|
nTriangles += node.triangle
|
||||||
|
|
||||||
node = node.next
|
node = node.next
|
||||||
@ -297,20 +295,30 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
triangulate(points.toArray, endPoints, T)
|
triangulate(points.toArray, endPoints, T)
|
||||||
|
|
||||||
// Update advancing front
|
// Update advancing front
|
||||||
aFront link (first, node, T.first)
|
|
||||||
|
// Select edge triangle
|
||||||
|
var edgeTri: Triangle = null
|
||||||
|
T.foreach(t =>
|
||||||
|
if(t.contains(first.point, node.point))
|
||||||
|
edgeTri = t
|
||||||
|
)
|
||||||
|
assert(edgeTri != null)
|
||||||
|
|
||||||
|
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
|
|
||||||
T.first mark(edge.p, edge.q)
|
|
||||||
|
|
||||||
// Return original triangle
|
// Return original triangle
|
||||||
triangle
|
triangle
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Mark constrained edge
|
// Mark constrained edge
|
||||||
|
if(firstTriangle != null)
|
||||||
firstTriangle mark(edge.p, edge.q)
|
firstTriangle mark(edge.p, edge.q)
|
||||||
triangle
|
triangle
|
||||||
}
|
}
|
||||||
@ -439,7 +447,7 @@ 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
|
// Try to avoid creating degenerate triangles
|
||||||
@ -468,13 +476,13 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
aFront.insertLegalized(t1.points(1), t1, node)
|
aFront.insertLegalized(t1.points(1), t1, node)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*/
|
|
||||||
// Update neighbor
|
// Update neighbor
|
||||||
t2.markNeighbor(t1)
|
t2.markNeighbor(t1)
|
||||||
// Update advancing front
|
// Update advancing front
|
||||||
aFront.insert(point, t1, node)
|
aFront.insert(point, t1, node)
|
||||||
|
|
||||||
//}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,11 +286,9 @@ class Triangle(val points: Array[Point]) {
|
|||||||
|
|
||||||
// Initial mark edges sweep
|
// Initial mark edges sweep
|
||||||
def mark(p: Point, q: Point) {
|
def mark(p: Point, q: Point) {
|
||||||
if(contains(p) && contains(q)) {
|
|
||||||
markEdge(p, q)
|
markEdge(p, q)
|
||||||
markNeighborEdge(p, q)
|
markNeighborEdge(p, q)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Finalize edge marking
|
// Finalize edge marking
|
||||||
def markEdges {
|
def markEdges {
|
||||||
|
@ -8,7 +8,7 @@ import shapes.Point
|
|||||||
object Util {
|
object Util {
|
||||||
|
|
||||||
// Almost zero
|
// Almost zero
|
||||||
val COLLINEAR_SLOP = 0.25f
|
val COLLINEAR_SLOP = 0.01f
|
||||||
|
|
||||||
val epsilon = exactinit
|
val epsilon = exactinit
|
||||||
val ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon
|
val ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon
|
||||||
@ -124,11 +124,9 @@ object Util {
|
|||||||
if ((det >= errbound) || (-det >= errbound)) {
|
if ((det >= errbound) || (-det >= errbound)) {
|
||||||
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.00001f
|
||||||
return orient2d(pa, pb, c)
|
return orient2d(pa, pb, c)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user