From 3fcf75c49ace6da08279791dff3a7e4a7cc77d85 Mon Sep 17 00:00:00 2001 From: masongreen Date: Sun, 19 Jul 2009 01:30:50 -0400 Subject: [PATCH] bug hunting --- src/org/poly2tri/Poly2Tri.scala | 9 +++++---- src/org/poly2tri/Segment.scala | 8 ++++---- src/org/poly2tri/Sink.scala | 1 + src/org/poly2tri/Trapezoid.scala | 2 +- src/org/poly2tri/Triangulator.scala | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index dd981af..d7edd12 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -65,6 +65,8 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { def init(container: GameContainer) { poly + val foo = 1.4 + println(Math.round(foo.toDouble)) } def update(gc: GameContainer, delta: Int) { @@ -171,14 +173,13 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { val p16 = Point(300,312) segments = new ArrayBuffer[Segment] - segments += new Segment(p2, p3) segments += new Segment(p1, p2) - segments += new Segment(p7, p1) - segments += new Segment(p4, p5) + segments += new Segment(p2, p3) segments += new Segment(p3, p4) + segments += new Segment(p4, p5) segments += new Segment(p5, p6) segments += new Segment(p6, p7) - segments += new Segment(p3, p4) + segments += new Segment(p7, p8) segments += new Segment(p8, p9) segments += new Segment(p9, p10) segments += new Segment(p10, p11) diff --git a/src/org/poly2tri/Segment.scala b/src/org/poly2tri/Segment.scala index 462133a..d34d395 100644 --- a/src/org/poly2tri/Segment.scala +++ b/src/org/poly2tri/Segment.scala @@ -44,13 +44,13 @@ class Segment(var p: Point, var q: Point) { // Equation of a line: y = m*x + b // Slope of the line (m) - val slope = (q.y - p.y)/(q.x - p.x) + val slope = ((q.y - p.y)/(q.x - p.x)).toDouble // Y intercept - val b = p.y - (p.x * slope) + val b = (p.y - (p.x * slope)).toDouble // Determines if this segment lies above the given point - def > (point: Point) = (point.y < Math.floor(slope * point.x + b)) + def > (point: Point) = (point.y.toFloat < Math.round(slope * point.x.toDouble + b)) // Determines if this segment lies below the given point - def < (point: Point) = (point.y > slope * point.x + b) + def < (point: Point) = (point.y.toFloat > Math.round(slope * point.x.toDouble + b)) } diff --git a/src/org/poly2tri/Sink.scala b/src/org/poly2tri/Sink.scala index fa6e677..a2c921f 100644 --- a/src/org/poly2tri/Sink.scala +++ b/src/org/poly2tri/Sink.scala @@ -34,6 +34,7 @@ object Sink { def init(trapezoid: Trapezoid) = { if(trapezoid.sink != null) + // What about adding to the parent list? trapezoid.sink else new Sink(trapezoid) diff --git a/src/org/poly2tri/Trapezoid.scala b/src/org/poly2tri/Trapezoid.scala index 1851ad1..835f056 100644 --- a/src/org/poly2tri/Trapezoid.scala +++ b/src/org/poly2tri/Trapezoid.scala @@ -74,7 +74,7 @@ class Trapezoid(val leftPoint: Point, var rightPoint: Point, val top: Segment, v } def lineIntersect(s: Segment, x: Float) = { - val y = s.slope * x + s.b + val y = (s.slope * x + s.b).toFloat Point(x, y) } diff --git a/src/org/poly2tri/Triangulator.scala b/src/org/poly2tri/Triangulator.scala index 0539a75..4b0900e 100644 --- a/src/org/poly2tri/Triangulator.scala +++ b/src/org/poly2tri/Triangulator.scala @@ -147,8 +147,8 @@ class Triangulator(segments: ArrayBuffer[Segment]) { segs += new Segment(s.p.clone, s.q.clone) // Randomized triangulation improves performance // See Seidel's paper, or O'Rourke's book, p. 57 - // Turn this off for now because of pointer bug somewhere in DAG / trapezoidal map - Random.shuffle(segs) + // Turn this off for while bug hunting math robustness issues + //Random.shuffle(segs) segs } }