mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-26 15:26:12 +01:00
code cleanup
This commit is contained in:
parent
2abca79e6e
commit
18f8f17cc3
@ -86,6 +86,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
val i18 = "data/i.18"
|
||||
|
||||
var currentModel = strange
|
||||
var doCDT = true
|
||||
|
||||
var mouseButton = 0
|
||||
var mousePressed = false
|
||||
@ -278,21 +279,27 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
def selectModel(model: String) {
|
||||
model match {
|
||||
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)
|
||||
case "data/bird.dat" =>
|
||||
CDT.clearPoint = 80
|
||||
doCDT = false; drawCDT = false; drawcdtMesh = false
|
||||
//CDT.clearPoint = 80
|
||||
loadModel(bird, 25f, Point(400, 300), 350)
|
||||
case "data/i.snake" =>
|
||||
doCDT = true; drawCDT = true
|
||||
CDT.clearPoint = 6
|
||||
loadModel(snake, 10f, Point(600, 300), 10)
|
||||
case "data/star.dat" =>
|
||||
doCDT = true; drawCDT = true
|
||||
CDT.clearPoint = 6
|
||||
loadModel(star, -1f, Point(0f, 0f), 10)
|
||||
case "data/strange.dat" =>
|
||||
doCDT = true; drawCDT = true
|
||||
CDT.clearPoint = 13
|
||||
loadModel(strange, -1f, Point(0f, 0f), 15)
|
||||
case "data/i.18" =>
|
||||
doCDT = true; drawCDT = true
|
||||
CDT.clearPoint = 7
|
||||
loadModel(i18, 20f, Point(600f, 500f), 20)
|
||||
case _ =>
|
||||
@ -334,12 +341,14 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
println("Number of points = " + polyX.size)
|
||||
println
|
||||
|
||||
val t1 = System.nanoTime
|
||||
slCDT = CDT.init(points)
|
||||
val runTime = System.nanoTime - t1
|
||||
println("CDT average (ms) = " + runTime*1e-6)
|
||||
println("Number of triangles = " + slCDT.triangles.size)
|
||||
println
|
||||
if(doCDT) {
|
||||
val t1 = System.nanoTime
|
||||
slCDT = CDT.init(points)
|
||||
val runTime = System.nanoTime - t1
|
||||
println("CDT average (ms) = " + runTime*1e-6)
|
||||
println("Number of triangles = " + slCDT.triangles.size)
|
||||
println
|
||||
}
|
||||
|
||||
if(!drawEarClip) {
|
||||
|
||||
|
@ -180,7 +180,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
|
||||
// Remove intersected triangles
|
||||
if(firstTriangle != null && !firstTriangle.contains(edge)) {
|
||||
println("collect")
|
||||
|
||||
// Collect intersected triangles
|
||||
val tList = new ArrayBuffer[Triangle]
|
||||
tList += firstTriangle
|
||||
@ -257,7 +257,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
first
|
||||
|
||||
} else if(firstTriangle == null) {
|
||||
println("intersect")
|
||||
|
||||
// No triangles are intersected by the edge; edge must lie outside the mesh
|
||||
// Apply constraint; traverse the AFront, and build triangles
|
||||
|
||||
@ -302,7 +302,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
triangle
|
||||
|
||||
} else {
|
||||
println("contains")
|
||||
|
||||
// Mark constrained edge
|
||||
firstTriangle mark(edge.p, edge.q)
|
||||
triangle
|
||||
@ -434,9 +434,10 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
val point = t1.points(0)
|
||||
val oPoint = t2 oppositePoint t1
|
||||
|
||||
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0))) {
|
||||
val collinear = t1.collinear(oPoint) || t2.collinear(oPoint, point)
|
||||
|
||||
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) {
|
||||
|
||||
println("legalize")
|
||||
// Flip edge and rotate everything clockwise
|
||||
t1.legalize(oPoint)
|
||||
t2.legalize(oPoint, point)
|
||||
|
Loading…
Reference in New Issue
Block a user