mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
changed edge initialization
This commit is contained in:
parent
629b1f5164
commit
251e8ed8ff
@ -81,16 +81,41 @@ object CDT {
|
|||||||
|
|
||||||
// Create segments and connect end points; update edge event pointer
|
// Create segments and connect end points; update edge event pointer
|
||||||
private def initSegments(points: ArrayBuffer[Point]): List[Segment] = {
|
private def initSegments(points: ArrayBuffer[Point]): List[Segment] = {
|
||||||
|
|
||||||
var segments = List[Segment]()
|
var segments = List[Segment]()
|
||||||
for(i <- 0 until points.size-1) {
|
for(i <- 0 until points.size-1) {
|
||||||
segments = new Segment(points(i), points(i+1)) :: segments
|
|
||||||
segments.first.updateEdge
|
val endPoints = validatePoints(points(i), points(i+1))
|
||||||
|
segments = new Segment(endPoints(0), endPoints(1)) :: segments
|
||||||
|
endPoints(1).edges += segments.first
|
||||||
|
|
||||||
}
|
}
|
||||||
segments = new Segment(points.first, points.last) :: segments
|
|
||||||
segments.first.updateEdge
|
val endPoints = validatePoints(points.first, points.last)
|
||||||
|
segments = new Segment(endPoints(0), endPoints(1)) :: segments
|
||||||
|
endPoints(1).edges += segments.first
|
||||||
|
|
||||||
segments
|
segments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def validatePoints(p1: Point, p2: Point): List[Point] = {
|
||||||
|
|
||||||
|
if(p1.y > p2.y) {
|
||||||
|
// For CDT we want q to be the point with > y
|
||||||
|
return List(p2, p1)
|
||||||
|
} else if(p1.y == p2.y) {
|
||||||
|
// If y values are equal, make sure point with smaller x value
|
||||||
|
// is the the left
|
||||||
|
if(p1.x > p2.x) {
|
||||||
|
return List(p2, p1)
|
||||||
|
} else if(p1.x == p2.x) {
|
||||||
|
throw new Exception("Duplicate point")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List(p1, p2)
|
||||||
|
}
|
||||||
|
|
||||||
// Insertion sort is one of the fastest algorithms for sorting arrays containing
|
// Insertion sort is one of the fastest algorithms for sorting arrays containing
|
||||||
// fewer than ten elements, or for lists that are already mostly sorted.
|
// fewer than ten elements, or for lists that are already mostly sorted.
|
||||||
// Merge sort: O(n log n)
|
// Merge sort: O(n log n)
|
||||||
@ -259,6 +284,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val first = pNode
|
val first = pNode
|
||||||
|
|
||||||
val points = new ArrayBuffer[Point]
|
val points = new ArrayBuffer[Point]
|
||||||
|
|
||||||
// Neighbor triangles
|
// Neighbor triangles
|
||||||
val nTriangles = new ArrayBuffer[Triangle]
|
val nTriangles = new ArrayBuffer[Triangle]
|
||||||
nTriangles += pNode.triangle
|
nTriangles += pNode.triangle
|
||||||
|
@ -51,25 +51,4 @@ class Segment(var p: Point, var q: Point) {
|
|||||||
// Determines if this segment lies below the given point
|
// Determines if this segment lies below the given point
|
||||||
def < (point: Point) = (Math.floor(point.y) > Math.floor(slope * point.x + b))
|
def < (point: Point) = (Math.floor(point.y) > Math.floor(slope * point.x + b))
|
||||||
|
|
||||||
// Update point edge list for CDT
|
|
||||||
def updateEdge {
|
|
||||||
if(p.y > q.y) {
|
|
||||||
// For CDT we want q to be the point with > y
|
|
||||||
val tmp = p
|
|
||||||
p = q
|
|
||||||
q = tmp
|
|
||||||
} else if(p.y == q.y) {
|
|
||||||
// If y values are equal, make sure point with smaller x value
|
|
||||||
// is the the left
|
|
||||||
if(p.x > q.x) {
|
|
||||||
val tmp = p
|
|
||||||
p = q
|
|
||||||
q = tmp
|
|
||||||
} else if(p.x == q.x) {
|
|
||||||
throw new Exception("Duplicate point")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
q.edges += this
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user