removed sheer transform

This commit is contained in:
Mason 2009-08-13 08:20:21 -04:00
parent 6a08aca82f
commit 4fd96b6535
3 changed files with 22 additions and 17 deletions

View File

@ -44,19 +44,16 @@ object CDT {
// Inital triangle factor
val ALPHA = 0.3f
val SHEER = 0.0001
var clearPoint = 0
// Triangulate simple polygon
def init(points: ArrayBuffer[Point]): CDT = {
var xmax, xmin = shearTransform(points.first).x
var ymax, ymin = shearTransform(points.first).y
var xmax, xmin = points.first.x
var ymax, ymin = points.first.y
// Calculate bounds
for(i <- 0 until points.size) {
points(i) = shearTransform(points(i))
val p = points(i)
if(p.x > xmax) xmax = p.x
if(p.x < xmin) xmin = p.x
@ -98,11 +95,7 @@ object CDT {
else
Util.msort((p1: Point, p2: Point) => p1 > p2)(points.toList)
}
// Prevents any two distinct endpoints from lying on a common horizontal line, and avoiding
// the degenerate case. See Mark de Berg et al, Chapter 6.3
private def shearTransform(point: Point) = Point(point.x, point.y + point.x * 0.001f)
}
class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Triangle) {
@ -351,9 +344,6 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
}
if(!P.isEmpty) {
//val ccw = Util.orient2d(a, b, P(i)) > 0
//val pB = if(ccw) P(i) else b
//val pC = if(ccw) b else P(i)
val points = Array(a, P(i), b)
T += new Triangle(points)
T.last.finalized = true
@ -439,6 +429,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val point = t1.points(0)
val oPoint = t2 oppositePoint t1
val collinear = t1.collinear(oPoint) || t2.collinear(oPoint, point)
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !t2.finalized) {
// Flip edge and rotate everything clockwise

View File

@ -53,8 +53,21 @@ case class Point(val x: Float, val y: Float) {
@inline def normalize = this / length
// Sort along x axis
@inline def <(p: Point) = (x < p.x)
// Sort along y axis
@inline def >(p: Point) = (y < p.y)
@inline def >(p: Point) = {
if(y < p.y)
true
else if(y > p.y)
false
else {
if(x < p.x)
true
else
false
}
}
@inline def !(p: Point) = !(p.x == x && p.y == y)
@inline override def clone = Point(x, y)

View File

@ -43,7 +43,7 @@ object Util {
// Tests if the given points are collinear
def collinear(p1: Point, p2: Point, p3: Point): Boolean = {
val d = orient2d(p1, p2, p3)
val d = Math.abs((p2-p1) cross (p1-p3))
if(Math.abs(d) <= COLLINEAR_SLOP)
true
@ -123,9 +123,9 @@ object Util {
val errbound = Util.ccwerrboundA * detsum
if ((det >= errbound) || (-det >= errbound)) {
return det
} else {
} else {
// Cheat a little bit.... we have a degenerate triangle
val c = pc * 0.1e-5f
val c = pc * 0.1e-6f
return orient2d(pa, pb, c)
}