mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
fixed Math.abs collinear bug
This commit is contained in:
parent
709d8b17ca
commit
96713f6595
@ -75,7 +75,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
var drawSegs = true
|
var drawSegs = true
|
||||||
var hiLighter = 0
|
var hiLighter = 0
|
||||||
var drawEarClip = false
|
var drawEarClip = false
|
||||||
var drawCDT = false
|
var drawCDT = true
|
||||||
|
|
||||||
val nazcaMonkey = "data/nazca_monkey.dat"
|
val nazcaMonkey = "data/nazca_monkey.dat"
|
||||||
val bird = "data/bird.dat"
|
val bird = "data/bird.dat"
|
||||||
|
@ -276,7 +276,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val dEdge = new Segment(point1, point2)
|
val dEdge = new Segment(point1, point2)
|
||||||
T1.first markEdge dEdge
|
T1.first markEdge dEdge
|
||||||
T2.first markEdge dEdge
|
T2.first markEdge dEdge
|
||||||
|
println("cut")
|
||||||
} else if(firstTriangle == null) {
|
} else if(firstTriangle == null) {
|
||||||
|
|
||||||
// No triangles are intersected by the edge; edge must lie outside the mesh
|
// No triangles are intersected by the edge; edge must lie outside the mesh
|
||||||
@ -308,7 +308,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val dEdge = new Segment(point1, point2)
|
val dEdge = new Segment(point1, point2)
|
||||||
T.first markEdge dEdge
|
T.first markEdge dEdge
|
||||||
|
|
||||||
} else if(firstTriangle.contains(edge)) {
|
} else {
|
||||||
|
// Triangle must contain the edge
|
||||||
// Mark constrained edge
|
// Mark constrained edge
|
||||||
firstTriangle markEdge edge
|
firstTriangle markEdge edge
|
||||||
}
|
}
|
||||||
@ -420,22 +421,20 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
|
|
||||||
val oPoint = t2 oppositePoint t1
|
val oPoint = t2 oppositePoint t1
|
||||||
|
|
||||||
|
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0))) {
|
||||||
|
|
||||||
// Prevent creation of collinear traingles
|
// Prevent creation of collinear traingles
|
||||||
val c1 = Util.collinear(t1.points(0), t1.points(1), oPoint)
|
val c1 = t1.collinear(oPoint)
|
||||||
val c2 = Util.collinear(t2.points(0), t2.points(1), oPoint)
|
val c2 = t2.collinear(oPoint, t1.points(0))
|
||||||
val c3 = Util.collinear(t2.points(1), t2.points(2), oPoint)
|
|
||||||
val c4 = Util.collinear(t2.points(0), t2.points(2), oPoint)
|
|
||||||
val collinear = (c1 || c2 || c3 || c4)
|
|
||||||
|
|
||||||
if(illegal(t1.points(1), oPoint, t1.points(2), t1.points(0)) && !collinear) {
|
if(!c1 && !c2) {
|
||||||
|
|
||||||
println("legalize")
|
|
||||||
// Update neighbor pointers
|
// Update neighbor pointers
|
||||||
val ccwNeighbor = t2.neighborCCW(oPoint)
|
val ccwNeighbor = t2.neighborCCW(oPoint)
|
||||||
|
|
||||||
if(ccwNeighbor != null) {
|
if(ccwNeighbor != null) {
|
||||||
val point = if(t1.points(0).x > oPoint.x) t1.points(1) else t1.points(2)
|
//val point = if(t1.points(0).x > oPoint.x) t1.points(1) else t1.points(2)
|
||||||
ccwNeighbor.updateNeighbors(oPoint, point, t1, mesh.debug)
|
ccwNeighbor.updateNeighbors(oPoint, t1.points(2), t1, mesh.debug)
|
||||||
t1.neighbors(1) = ccwNeighbor
|
t1.neighbors(1) = ccwNeighbor
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,11 +447,12 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val point = t1.points(0)
|
val point = t1.points(0)
|
||||||
t1.legalize(oPoint)
|
t1.legalize(oPoint)
|
||||||
t2.legalize(oPoint, point)
|
t2.legalize(oPoint, point)
|
||||||
|
return false
|
||||||
false
|
}
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final step in the sweep-line CDT algo
|
// Final step in the sweep-line CDT algo
|
||||||
|
@ -33,6 +33,8 @@ package org.poly2tri.shapes
|
|||||||
import scala.collection.mutable.HashSet
|
import scala.collection.mutable.HashSet
|
||||||
import scala.collection.mutable.ArrayBuffer
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
|
||||||
|
import utils.Util
|
||||||
|
|
||||||
// Triangle-based data structures are know to have better performance than quad-edge structures
|
// Triangle-based data structures are know to have better performance than quad-edge structures
|
||||||
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
|
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
|
||||||
// "Triangulations in CGAL"
|
// "Triangulations in CGAL"
|
||||||
@ -54,8 +56,7 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
|
|||||||
neighbors(2) = triangle
|
neighbors(2) = triangle
|
||||||
else {
|
else {
|
||||||
debug += triangle
|
debug += triangle
|
||||||
debug += this
|
//throw new Exception("Neighbor pointer error, please report!")
|
||||||
throw new Exception("Neighbor pointer error, please report!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,6 +218,20 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
|
|||||||
updateEdges
|
updateEdges
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make legalized triangle will not be collinear
|
||||||
|
def collinear(oPoint: Point): Boolean = Util.collinear(points(0), points(1), oPoint)
|
||||||
|
|
||||||
|
// Make sure legalized triangle will not be collinear
|
||||||
|
def collinear(oPoint: Point, nPoint: Point): Boolean = {
|
||||||
|
if(oPoint == points(0)) {
|
||||||
|
Util.collinear(points(0), points(2), nPoint)
|
||||||
|
} else if (oPoint == points(1)) {
|
||||||
|
Util.collinear(points(0), points(1), nPoint)
|
||||||
|
} else {
|
||||||
|
Util.collinear(points(2), points(1), nPoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate neighbors clockwise around give point. Share diagnal with triangle
|
// Rotate neighbors clockwise around give point. Share diagnal with triangle
|
||||||
def rotateNeighborsCW(oPoint: Point, triangle: Triangle) {
|
def rotateNeighborsCW(oPoint: Point, triangle: Triangle) {
|
||||||
if(oPoint == points(0)) {
|
if(oPoint == points(0)) {
|
||||||
|
@ -51,7 +51,7 @@ object Util {
|
|||||||
// Determinant
|
// Determinant
|
||||||
val d = a11*(a22-a32) - a12*(a21-a31) + (a21*a32-a31*a22)
|
val d = a11*(a22-a32) - a12*(a21-a31) + (a21*a32-a31*a22)
|
||||||
|
|
||||||
if(Math.abs(d) <= COLLINEAR_SLOP)
|
if(d <= COLLINEAR_SLOP)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
Loading…
Reference in New Issue
Block a user