mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
code cleanup
This commit is contained in:
parent
260e7935b9
commit
c4d577ec06
@ -272,4 +272,4 @@
|
|||||||
6.20462 5.25418
|
6.20462 5.25418
|
||||||
5.72617 4.80159
|
5.72617 4.80159
|
||||||
5.13134 4.41366
|
5.13134 4.41366
|
||||||
4.87271 4.16797
|
4.87271 4.16797
|
@ -123,43 +123,43 @@ class Triangle(val points: Array[Point]) {
|
|||||||
|
|
||||||
// Locate first triangle crossed by constrained edge
|
// Locate first triangle crossed by constrained edge
|
||||||
def locateFirst(edge: Segment): Triangle = {
|
def locateFirst(edge: Segment): Triangle = {
|
||||||
val p = edge.p
|
|
||||||
val q = edge.q
|
if(edge.q == points(0))
|
||||||
val e = p - q
|
search(points(1), points(2), edge, neighbors(2))
|
||||||
|
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))
|
||||||
|
else
|
||||||
|
throw new Exception("Point not found")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def search(p1: Point, p2: Point, edge: Segment, neighbor: Triangle): Triangle = {
|
||||||
|
|
||||||
val ik = points(2) - points(0)
|
val o1 = Util.orient2d(edge.q, p1, edge.p)
|
||||||
val ij = points(1) - points(0)
|
val o2 = Util.orient2d(edge.q, p2, edge.p)
|
||||||
val jk = points(2) - points(1)
|
val sameSign = Math.signum(o1) == Math.signum(o2)
|
||||||
val ji = points(0) - points(1)
|
|
||||||
val kj = points(1) - points(2)
|
// Edge crosses this triangle
|
||||||
val ki = points(0) - points(2)
|
if(!sameSign)
|
||||||
|
return this
|
||||||
if(q == points(0)) {
|
|
||||||
val sameSign = Math.signum(ik cross e) == Math.signum(ij cross e)
|
// Look at neighbor
|
||||||
if(!sameSign) return this
|
if(neighbor == null)
|
||||||
if(neighbors(2) == null) return null
|
null
|
||||||
return neighbors(2).locateFirst(edge)
|
else
|
||||||
} else if(q == points(1)) {
|
neighbor.locateFirst(edge)
|
||||||
val sameSign = Math.signum(jk cross e) == Math.signum(ji cross e)
|
|
||||||
if(!sameSign) return this
|
|
||||||
if(neighbors(0) == null) return null
|
|
||||||
return neighbors(0).locateFirst(edge)
|
|
||||||
} else if(q == points(2)) {
|
|
||||||
val sameSign = Math.signum(kj cross e) == Math.signum(ki cross e)
|
|
||||||
if(!sameSign) return this
|
|
||||||
if(neighbors(1) == null) return null
|
|
||||||
return neighbors(1).locateFirst(edge)
|
|
||||||
}
|
|
||||||
throw new Exception("Point not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locate next triangle crossed by edge
|
// Locate next triangle crossed by edge
|
||||||
def findNeighbor(e: Point): Triangle = {
|
def findNeighbor(e: Point): Triangle = {
|
||||||
if(Util.orient2d(points(0), points(1), e) > 0)
|
if(Util.orient2d(points(0), points(1), e) < 0)
|
||||||
return neighbors(2)
|
return neighbors(2)
|
||||||
else if(Util.orient2d(points(1), points(2), e) > 0)
|
else if(Util.orient2d(points(1), points(2), e) < 0)
|
||||||
return neighbors(0)
|
return neighbors(0)
|
||||||
else if(Util.orient2d(points(2), points(0), e) > 0)
|
else if(Util.orient2d(points(2), points(0), e) < 0)
|
||||||
return neighbors(1)
|
return neighbors(1)
|
||||||
else
|
else
|
||||||
// Point must reside inside this triangle
|
// Point must reside inside this triangle
|
||||||
@ -249,10 +249,10 @@ class Triangle(val points: Array[Point]) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make legalized triangle will not be collinear
|
// Check if legalized triangle will be collinear
|
||||||
def collinear(oPoint: Point): Boolean = Util.collinear(points(1), points(0), oPoint)
|
def collinear(oPoint: Point): Boolean = Util.collinear(points(1), points(0), oPoint)
|
||||||
|
|
||||||
// Make sure legalized triangle will not be collinear
|
// Check if legalized triangle will be collinear
|
||||||
def collinear(oPoint: Point, nPoint: Point): Boolean = {
|
def collinear(oPoint: Point, nPoint: Point): Boolean = {
|
||||||
if(oPoint == points(0)) {
|
if(oPoint == points(0)) {
|
||||||
Util.collinear(points(0), points(2), nPoint)
|
Util.collinear(points(0), points(2), nPoint)
|
||||||
|
@ -43,7 +43,7 @@ object Util {
|
|||||||
// Tests if the given points are collinear
|
// Tests if the given points are collinear
|
||||||
def collinear(p1: Point, p2: Point, p3: Point): Boolean = {
|
def collinear(p1: Point, p2: Point, p3: Point): Boolean = {
|
||||||
|
|
||||||
val d = (p2 - p1) cross (p1 - p3)
|
val d = orient2d(p1, p2, p3)
|
||||||
|
|
||||||
if(Math.abs(d) <= COLLINEAR_SLOP)
|
if(Math.abs(d) <= COLLINEAR_SLOP)
|
||||||
true
|
true
|
||||||
@ -93,7 +93,7 @@ object Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adaptive exact 2D orientation test. Robust. By Jonathan Shewchuk
|
// Adaptive exact 2D orientation test. Robust. By Jonathan Shewchuk
|
||||||
// Return: positive if point a, b, and c are counterclockwise
|
// Return: positive if point a, b, and c are counterclockwise
|
||||||
// negative if point a, b, and c are clockwise
|
// negative if point a, b, and c are clockwise
|
||||||
// zero if points are collinear
|
// zero if points are collinear
|
||||||
// See: http://www-2.cs.cmu.edu/~quake/robust.html
|
// See: http://www-2.cs.cmu.edu/~quake/robust.html
|
||||||
@ -124,15 +124,13 @@ object Util {
|
|||||||
if ((det >= errbound) || (-det >= errbound)) {
|
if ((det >= errbound) || (-det >= errbound)) {
|
||||||
return det
|
return det
|
||||||
} else {
|
} else {
|
||||||
println(pa + "," + pb + "," + pc)
|
|
||||||
println(detleft + "," + detright)
|
// Cheat a little bit.... we have a degenerate triangle
|
||||||
println("Det = " + det + " , errbound = " + errbound)
|
val c = pc * 1.00001f
|
||||||
throw new Exception("Degenerate triangle")
|
return orient2d(pa, pb, c)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not implemented;
|
|
||||||
// http://www.cs.cmu.edu/afs/cs/project/quake/public/code/predicates.c
|
|
||||||
// return orient2dadapt(pa, pb, pc, detsum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user