mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-05 22:09:52 +01:00
code cleanup
This commit is contained in:
parent
316ab15839
commit
e827825e47
@ -305,8 +305,8 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
CDT.clearPoint = 7
|
||||
loadModel(i18, 20f, Point(600f, 500f), 20)
|
||||
case "data/nazca_heron.dat" =>
|
||||
doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||
CDT.clearPoint = 7
|
||||
//doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||
CDT.clearPoint = 100
|
||||
loadModel(nazcaHeron, 4.2f, Point(400f, 300f), 1500)
|
||||
case "data/tank.dat" =>
|
||||
//doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||
|
@ -61,7 +61,7 @@ class AFront(iTriangle: Triangle) {
|
||||
// Locate node containing given point
|
||||
def locatePoint(point: Point): Node = {
|
||||
var node = head
|
||||
while(node != tail) {
|
||||
while(node != null) {
|
||||
if(point == node.point)
|
||||
return node
|
||||
node = node.next
|
||||
@ -90,72 +90,33 @@ class AFront(iTriangle: Triangle) {
|
||||
}
|
||||
|
||||
// Update advancing front with constrained edge triangles
|
||||
def constrainedEdge(sNode: Node, eNode: Node, T1: ArrayBuffer[Triangle],
|
||||
T2: ArrayBuffer[Triangle], edge: Segment): Triangle = {
|
||||
def constrainedEdge(sNode: Node, eNode: Node, T2: ArrayBuffer[Triangle], edge: Segment): Triangle = {
|
||||
|
||||
var node = sNode
|
||||
var t1r, t2r = false
|
||||
|
||||
// Scan the advancing front and update Node triangle pointers
|
||||
// Either T1 OR T2
|
||||
while(node != eNode) {
|
||||
|
||||
T2.foreach(t => {
|
||||
if(t.contains(node.point, node.next.point)) {
|
||||
node.triangle = t
|
||||
t2r = true
|
||||
}
|
||||
})
|
||||
|
||||
if(!t2r)
|
||||
T1.foreach(t => {
|
||||
if(t.contains(node.point, node.next.point)) {
|
||||
node.triangle = t
|
||||
t1r = true
|
||||
}
|
||||
})
|
||||
|
||||
node = node.next
|
||||
}
|
||||
|
||||
val point1 = edge.q
|
||||
val point2 = edge.p
|
||||
|
||||
// Select edge triangles
|
||||
var edgeTri: Triangle = null
|
||||
var marked = false
|
||||
|
||||
var edgeTri1: Triangle = null
|
||||
var i = 0
|
||||
while(edgeTri1 == null) {
|
||||
if(T1(i).contains(point1, point2))
|
||||
edgeTri1 = T1(i)
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Mark constrained edge
|
||||
edgeTri1 markEdge(point1, point2)
|
||||
|
||||
var edgeTri2: Triangle = null
|
||||
i = 0
|
||||
while(edgeTri2 == null) {
|
||||
if(T2(i).contains(point1, point2))
|
||||
edgeTri2 = T2(i)
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Mark constrained edge
|
||||
edgeTri2 markEdge(point1, point2)
|
||||
|
||||
// Update neighbor pointer
|
||||
edgeTri1.markNeighbor(edgeTri2)
|
||||
|
||||
if(t1r && !t2r)
|
||||
edgeTri1
|
||||
else if(t2r && !t1r) {
|
||||
edgeTri2
|
||||
} else {
|
||||
throw new Exception("edge insertion error")
|
||||
// Scan the advancing front and update Node triangle pointers
|
||||
while(node != eNode) {
|
||||
|
||||
T2.foreach(t => {
|
||||
if(t.contains(node.point, node.next.point))
|
||||
node.triangle = t
|
||||
if(!marked && t.contains(point1, point2)) {
|
||||
edgeTri = t
|
||||
edgeTri markEdge(point1, point2)
|
||||
marked = true
|
||||
}
|
||||
})
|
||||
|
||||
node = node.next
|
||||
}
|
||||
|
||||
edgeTri
|
||||
}
|
||||
|
||||
def -=(tuple: Tuple3[Node, Node, Triangle]) {
|
||||
|
@ -240,13 +240,11 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
val sNode = aFront.locate(point1)
|
||||
val eNode = aFront.locate(point2)
|
||||
|
||||
val first = aFront.constrainedEdge(sNode, eNode, T1, T2, edge)
|
||||
|
||||
// Update neighbors
|
||||
edgeNeighbors(nTriangles, T1)
|
||||
edgeNeighbors(nTriangles, T2)
|
||||
|
||||
first
|
||||
aFront.constrainedEdge(sNode, eNode, T2, edge)
|
||||
|
||||
} else if(firstTriangle == null) {
|
||||
|
||||
@ -257,7 +255,7 @@ 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.locate(point1)
|
||||
var node = aFront.locatePoint(point1)
|
||||
val first = node
|
||||
|
||||
val points = new ArrayBuffer[Point]
|
||||
@ -277,8 +275,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
val T = new ArrayBuffer[Triangle]
|
||||
triangulate(points.toArray, List(edge.q, edge.p), T)
|
||||
|
||||
// Update advancing front
|
||||
|
||||
// Select edge triangle
|
||||
var edgeTri: Triangle = null
|
||||
var i = 0
|
||||
@ -288,6 +284,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Update advancing front
|
||||
aFront link (first, node, edgeTri)
|
||||
|
||||
// Update neighbors
|
||||
@ -299,9 +296,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
// Return original triangle
|
||||
triangle
|
||||
|
||||
} else if(firstTriangle.contains(edge.p, edge.q)) {
|
||||
} else if(firstTriangle.contains(edge.q, edge.p)) {
|
||||
// Mark constrained edge
|
||||
firstTriangle markEdge(edge.p, edge.q)
|
||||
firstTriangle markEdge(edge.q, edge.p)
|
||||
triangle
|
||||
} else {
|
||||
throw new Exception("Triangulation error")
|
||||
@ -347,10 +344,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
}
|
||||
|
||||
if(!P.isEmpty) {
|
||||
val ccw = Util.orient2d(a, b, P(i)) > 0
|
||||
val pB = if(ccw) P(i) else b
|
||||
val pC = if(ccw) b else P(i)
|
||||
val points = Array(a, pB, pC)
|
||||
//val ccw = Util.orient2d(a, b, P(i)) > 0
|
||||
//val pB = if(ccw) P(i) else b
|
||||
//val pC = if(ccw) b else P(i)
|
||||
val points = Array(a, P(i), b)
|
||||
T += new Triangle(points)
|
||||
mesh.map += T.last
|
||||
}
|
||||
@ -447,8 +444,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
// Update new neighbors
|
||||
for(n <- neighbors) {
|
||||
if(n != null) {
|
||||
t2.markNeighbor(n)
|
||||
t1.markNeighbor(n)
|
||||
t1.markNeighbor(n)
|
||||
t2.markNeighbor(n)
|
||||
}
|
||||
}
|
||||
t2.markNeighbor(t1)
|
||||
|
@ -132,7 +132,7 @@ class Triangle(val points: Array[Point]) {
|
||||
else if(edge.q == points(1))
|
||||
search(points(0), points(2), edge, neighbors(0))
|
||||
else if(edge.q == points(2))
|
||||
search(points(1), points(0), edge, neighbors(1))
|
||||
search(points(0), points(1), edge, neighbors(1))
|
||||
else
|
||||
throw new Exception("Point not found")
|
||||
|
||||
|
@ -125,7 +125,7 @@ object Util {
|
||||
return det
|
||||
} else {
|
||||
// Cheat a little bit.... we have a degenerate triangle
|
||||
val c = pc * 1.0001f
|
||||
val c = pc * 0.1e-5f
|
||||
return orient2d(pa, pb, c)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user