mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-05 22:09:52 +01:00
fixed floating point rounding bug
This commit is contained in:
parent
08264e50d0
commit
6100a498ab
@ -171,13 +171,14 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
||||
val p16 = Point(300,312)
|
||||
|
||||
segments = new ArrayBuffer[Segment]
|
||||
segments += new Segment(p1, p2)
|
||||
segments += new Segment(p2, p3)
|
||||
segments += new Segment(p3, p4)
|
||||
segments += new Segment(p1, p2)
|
||||
segments += new Segment(p7, p1)
|
||||
segments += new Segment(p4, p5)
|
||||
segments += new Segment(p3, p4)
|
||||
segments += new Segment(p5, p6)
|
||||
segments += new Segment(p6, p7)
|
||||
segments += new Segment(p7, p8)
|
||||
segments += new Segment(p3, p4)
|
||||
segments += new Segment(p8, p9)
|
||||
segments += new Segment(p9, p10)
|
||||
segments += new Segment(p10, p11)
|
||||
|
@ -49,7 +49,7 @@ class Segment(var p: Point, var q: Point) {
|
||||
val b = p.y - (p.x * slope)
|
||||
|
||||
// Determines if this segment lies above the given point
|
||||
def > (point: Point) = (point.y < slope * point.x + b)
|
||||
def > (point: Point) = (point.y < Math.floor(slope * point.x + b))
|
||||
// Determines if this segment lies below the given point
|
||||
def < (point: Point) = (point.y > slope * point.x + b)
|
||||
|
||||
|
@ -144,11 +144,11 @@ class Triangulator(segments: ArrayBuffer[Segment]) {
|
||||
if(s.p.x > s.q.x) {
|
||||
segs += new Segment(s.q.clone, s.p.clone)
|
||||
} else if(s.p.x < s.q.x)
|
||||
segs += new Segment(s.p.clone, s.q.clone)
|
||||
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)
|
||||
Random.shuffle(segs)
|
||||
segs
|
||||
}
|
||||
}
|
||||
|
@ -35,10 +35,11 @@ class YNode(segment: Segment, lChild: Node, rChild: Node) extends Node(lChild, r
|
||||
override def locate(s: Segment): Sink = {
|
||||
if (segment > s.p) {
|
||||
// Move down the graph
|
||||
right.locate(s)
|
||||
return right.locate(s)
|
||||
} else if (segment < s.p){
|
||||
// Move up the graph
|
||||
left.locate(s)
|
||||
return left.locate(s)
|
||||
|
||||
} else {
|
||||
// s and segment share the same endpoint, p
|
||||
if (s.slope < segment.slope) {
|
||||
|
Loading…
Reference in New Issue
Block a user