mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-05 22:09:52 +01:00
bug hunting
This commit is contained in:
parent
ea65046b07
commit
8c7b86d715
@ -84,7 +84,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
val strange = "data/strange.dat"
|
||||
val i18 = "data/i.18"
|
||||
|
||||
var currentModel = strange
|
||||
var currentModel = nazcaMonkey
|
||||
|
||||
var mouseButton = 0
|
||||
var mousePressed = false
|
||||
@ -264,7 +264,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
if(c == '5') selectModel(star)
|
||||
if(c == '6') selectModel(i18)
|
||||
if(c == 's') drawSegs = !drawSegs
|
||||
if(c == 'e') {drawEarClip = !drawEarClip; selectModel(currentModel)}
|
||||
//if(c == 'e') {drawEarClip = !drawEarClip; selectModel(currentModel)}
|
||||
}
|
||||
|
||||
def selectModel(model: String) {
|
||||
|
@ -126,14 +126,16 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
// Implement sweep-line
|
||||
private def sweep {
|
||||
//var cTri: Triangle = null
|
||||
for(i <- 1 until points.size) {
|
||||
for(i <- 1 until 15 /*points.size*/) {
|
||||
val point = points(i)
|
||||
// Process Point event
|
||||
var triangle: Triangle = null
|
||||
try {
|
||||
triangle = pointEvent(point)
|
||||
} catch {
|
||||
case e: Exception => println("Offending triangle = " + i)
|
||||
case e: Exception =>
|
||||
println("Offending triangle = " + i)
|
||||
//System exit 0
|
||||
}
|
||||
// Process edge events
|
||||
//point.edges.foreach(e => edgeEvent(e, triangle))
|
||||
@ -147,6 +149,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
|
||||
val node = aFront.locate(point)
|
||||
|
||||
// Avoid triangles that are almost collinear
|
||||
if(!Util.collinear(point, node.point, node.next.point)) {
|
||||
|
||||
// Projected point coincides with existing point; create two triangles
|
||||
if(point.x == node.point.x && node.prev != null) {
|
||||
|
||||
@ -198,9 +203,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
if(legal) {
|
||||
newNode = aFront.insert(point, triangle, node)
|
||||
// Update neighbors
|
||||
println(1)
|
||||
nTri.updateNeighbors(cwPoint, ccwPoint, triangle, mesh.debug)
|
||||
println(2)
|
||||
} else {
|
||||
newNode = new Node(triangle.points(1), triangle)
|
||||
val rNode = node.next
|
||||
@ -214,6 +217,11 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
scanAFront(newNode)
|
||||
newNode.triangle
|
||||
}
|
||||
|
||||
} else {
|
||||
println("bad triangle")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// EdgeEvent
|
||||
@ -404,9 +412,9 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
||||
|
||||
val sinA = v1 cross v2
|
||||
val sinB = v3 cross v4
|
||||
|
||||
//println((cosA*sinB + sinA*cosB))
|
||||
// Some small number
|
||||
if((cosA*sinB + sinA*cosB) < -0.1)
|
||||
if((cosA*sinB + sinA*cosB) < -10f)
|
||||
true
|
||||
else
|
||||
false
|
||||
|
@ -56,7 +56,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
|
||||
mesh += triangle
|
||||
println(ccwPoint + "," + cwPoint)
|
||||
printDebug
|
||||
//throw new Exception("Neighbor update error")
|
||||
throw new Exception("Neighbor update error")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ import shapes.Point
|
||||
|
||||
object Util {
|
||||
|
||||
val COLLINEAR_SLOP = 10f
|
||||
|
||||
// From "Scala By Example," by Martin Odersky
|
||||
def msort[A](less: (A, A) => Boolean)(xs: List[A]): List[A] = {
|
||||
def merge(xs1: List[A], xs2: List[A]): List[A] =
|
||||
@ -33,6 +35,34 @@ object Util {
|
||||
}
|
||||
xs
|
||||
}
|
||||
|
||||
// Tests if the given points are collinear
|
||||
def collinear(p1: Point, p2: Point, p3: Point): Boolean = {
|
||||
|
||||
// 3x3 matrix
|
||||
val a11 = p1.x
|
||||
val a12 = p1.y
|
||||
val a13 = 1f
|
||||
val a21 = p2.x
|
||||
val a22 = p2.y
|
||||
val a23 = 1f
|
||||
val a31 = p3.x
|
||||
val a32 = p3.y
|
||||
val a33 = 1f
|
||||
|
||||
// Determinant
|
||||
val d = a11*(a22*a33 - a32*a23) - a12*(a21*a33-a31*a23) + a13*(a21*a32-a31*a22)
|
||||
|
||||
println("Determinant = " + d)
|
||||
|
||||
if(d <= COLLINEAR_SLOP) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** The object <code>Random</code> offers a default implementation
|
||||
|
Loading…
Reference in New Issue
Block a user