mirror of
https://github.com/jhasse/poly2tri.git
synced 2025-01-31 12:43:31 +01:00
fixed updateEdge
This commit is contained in:
parent
44f9fbe572
commit
be0112a0a3
@ -192,7 +192,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
|
|||||||
hiLighter = seidel.polygons.size-1
|
hiLighter = seidel.polygons.size-1
|
||||||
}
|
}
|
||||||
if(c == 'm') drawMap = !drawMap
|
if(c == 'm') drawMap = !drawMap
|
||||||
if(c == 'c') drawCDT = !drawCDT
|
if(c == 'd') drawCDT = !drawCDT
|
||||||
if(c == '1') selectModel(nazcaMonkey)
|
if(c == '1') selectModel(nazcaMonkey)
|
||||||
if(c == '2') selectModel(bird)
|
if(c == '2') selectModel(bird)
|
||||||
if(c == '3') selectModel(strange)
|
if(c == '3') selectModel(strange)
|
||||||
|
@ -78,17 +78,19 @@ 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)
|
||||||
val segment = new Segment(points(i), points(i+1))
|
segments = segment(points(i), points(i+1)) :: segments
|
||||||
points(i+1).eEvent = segment
|
segments = segment(points.first, points.last) :: segments
|
||||||
segments = segment :: segments
|
|
||||||
}
|
|
||||||
val segment = new Segment(points.first, points.last)
|
|
||||||
points.first.eEvent = segment
|
|
||||||
segments = segment :: segments
|
|
||||||
segments
|
segments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new segment and updates edge pointer
|
||||||
|
private def segment(p1: Point, p2: Point): Segment = {
|
||||||
|
val seg = new Segment(p1, p2)
|
||||||
|
p1.updateEdges(p2, seg)
|
||||||
|
seg
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
@ -145,9 +147,11 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
val triangle = new Triangle(pts, neighbors)
|
val triangle = new Triangle(pts, neighbors)
|
||||||
mesh.map += triangle
|
mesh.map += triangle
|
||||||
|
|
||||||
|
// Check if edges need to be swapped to preserve CDT
|
||||||
|
// TODO: Make sure AFront pointers are updated correctly
|
||||||
val oPoint = nTri oppositePoint triangle
|
val oPoint = nTri oppositePoint triangle
|
||||||
if(illegal(ccwPoint, oPoint, cwPoint, point)) {
|
if(illegal(ccwPoint, oPoint, cwPoint, point)) {
|
||||||
swapEdges(triangle, nTri, oPoint)
|
legalization(triangle, nTri, oPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
nTri.updateNeighbors(ccwPoint, cwPoint, triangle)
|
nTri.updateNeighbors(ccwPoint, cwPoint, triangle)
|
||||||
@ -215,9 +219,8 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate everything clockwise
|
// Flip edges and rotate everything clockwise
|
||||||
private def swapEdges(t1: Triangle, t2: Triangle, oPoint: Point) {
|
private def legalization(t1: Triangle, t2: Triangle, oPoint: Point) {
|
||||||
println("swap")
|
|
||||||
// Rotate points
|
// Rotate points
|
||||||
val point = t1.points(0)
|
val point = t1.points(0)
|
||||||
t1.points(1) = t1.points(0)
|
t1.points(1) = t1.points(0)
|
||||||
|
@ -40,10 +40,11 @@ class Mesh(initialTriangle: Triangle) {
|
|||||||
val map = HashSet(initialTriangle)
|
val map = HashSet(initialTriangle)
|
||||||
|
|
||||||
def addEdge(point:Point, triangle: Triangle) {
|
def addEdge(point:Point, triangle: Triangle) {
|
||||||
|
/*
|
||||||
val p = point.eEvent.p
|
val p = point.eEvent.p
|
||||||
if(!triangle.contains(p)) {
|
if(!triangle.contains(p)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.poly2tri.shapes
|
package org.poly2tri.shapes
|
||||||
|
|
||||||
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
|
||||||
case class Point(val x: Float, val y: Float) {
|
case class Point(val x: Float, val y: Float) {
|
||||||
|
|
||||||
// Pointers to next and previous points in Monontone Mountain
|
// Pointers to next and previous points in Monontone Mountain
|
||||||
var next, prev: Point = null
|
var next, prev: Point = null
|
||||||
// The setment this point belongs to
|
// The setment this point belongs to
|
||||||
var segment: Segment = null
|
var segment: Segment = null
|
||||||
// Edge event pointer for CDT
|
// List of edges this point constitutes an upper ending point (CDT)
|
||||||
var eEvent: Segment = null
|
var edges = new ArrayBuffer[Segment]
|
||||||
|
|
||||||
@inline def -(p: Point) = Point(x - p.x, y - p.y)
|
@inline def -(p: Point) = Point(x - p.x, y - p.y)
|
||||||
@inline def +(p: Point) = Point(x + p.x, y + p.y)
|
@inline def +(p: Point) = Point(x + p.x, y + p.y)
|
||||||
@ -55,4 +57,12 @@ case class Point(val x: Float, val y: Float) {
|
|||||||
@inline def >(p: Point) = (y < p.y)
|
@inline def >(p: Point) = (y < p.y)
|
||||||
@inline def !(p: Point) = !(p.x == x && p.y == y)
|
@inline def !(p: Point) = !(p.x == x && p.y == y)
|
||||||
@inline override def clone = Point(x, y)
|
@inline override def clone = Point(x, y)
|
||||||
|
|
||||||
|
def updateEdges(point: Point, segment: Segment) {
|
||||||
|
if(point.y > y)
|
||||||
|
point.edges += segment
|
||||||
|
else
|
||||||
|
edges += segment
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ package org.poly2tri.shapes
|
|||||||
import scala.collection.mutable.{ArrayBuffer}
|
import scala.collection.mutable.{ArrayBuffer}
|
||||||
|
|
||||||
// Represents a simple polygon's edge
|
// Represents a simple polygon's edge
|
||||||
|
// TODO: Rename this class to Edge?
|
||||||
class Segment(var p: Point, var q: Point) {
|
class Segment(var p: Point, var q: Point) {
|
||||||
|
|
||||||
// Pointers used for building trapezoidal map
|
// Pointers used for building trapezoidal map
|
||||||
|
Loading…
Reference in New Issue
Block a user