python work

This commit is contained in:
zzzzrrr 2009-11-11 20:22:27 -05:00
parent dede764bb7
commit 8635340839

View File

@ -99,18 +99,15 @@ class Triangulator(object) {
trapezoidalMap.clear trapezoidalMap.clear
i += 1 i += 1
// Mark outside trapezoids
for t in trapezoidalMap.map for t in trapezoidalMap.map
markOutside(t) markOutside(t)
// Collect interior trapezoids
for t in trapezoidalMap.map for t in trapezoidalMap.map
if t.inside: if t.inside:
trapezoids.append(t) trapezoids.append(t)
t.addPoints() t.addPoints()
// Generate the triangles createMountains()
createMountains
} }
@ -132,29 +129,20 @@ class Triangulator(object) {
if(s.mPoints.size > 0) { if(s.mPoints.size > 0) {
val mountain = new MonotoneMountain mountain = MonotoneMountain()
var k: List[Point] = None
// Sorting is a perfromance hit. Literature says this can be accomplised in if len(s.mPoints) < 10:
// linear time, although I don't see a way around using traditional methods k = insertSort((p1: Point, p2: Point) => p1 < p2)(s.mPoints).toList
// when using a randomized incremental algorithm
if(s.mPoints.size < 10)
// Insertion sort is one of the fastest algorithms for sorting arrays containing
// fewer than ten elements, or for lists that are already mostly sorted.
k = Util.insertSort((p1: Point, p2: Point) => p1 < p2)(s.mPoints).toList
else else
k = Util.msort((p1: Point, p2: Point) => p1 < p2)(s.mPoints.toList) k = msort((p1: Point, p2: Point) => p1 < p2)(s.mPoints.toList)
val points = s.p :: k ::: List(s.q) points = s.p :: k ::: List(s.q)
var j = 0 for p in points:
while(j < points.size) { mountain.add(p)
mountain += points(j)
j += 1
}
// Triangulate monotone mountain mountain.process()
mountain process
// Extract the triangles into a single list // Extract the triangles into a single list
j = 0 j = 0