-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelaunay_gs.js
71 lines (64 loc) · 1.7 KB
/
delaunay_gs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function HEdge() {
this.point;
this.next;
this.prev;
this.pair;
this.face;
}
function QEdge() {
this.rightmostHe; /* right most halfedge */
this.leftmostHe; /* left most halfedge */
this.points; /* pointer to points */
this.faces; /* faces of delaunay */
this.facesCount; /* face count */
this.startPoint; /* start point index */
this.endPoint; /* end point index */
}
function Face() {
}
workingSet = {
edges: [],
faces: [],
freeEdge: NaN,
freeFace: NaN,
}
function delaunay(points,edges, invEdges) {
alert(points);
if (points.length == 3) {
var line1 = [points[0],points[1]];
var line2 = [points[1],points[2]];
var line3 = [points[2],points[0]];
if (ccw(points[0], points[1], points[2])) {
addEdge(line1, edges, invEdges);
addEdge(line2, edges, invEdges);
addEdge(line3, edges, invEdges);
return [line1.splice(), line2.reverse()];
} else if (ccw(points[0], points[2], points[1])) {
line3.reverse()
addEdge(line1, edges, invEdges);
addEdge(line2, edges, invEdges);
addEdge(line3, edges, invEdges);
return [line3.slice().reverse(), line3.slice()];
} else {
addEdge(line1, edges, invEdges);
addEdge(line2, edges, invEdges);
return [line1.splice(), line2.reverse()];
}
} else if (points.length == 2) {
var line = [points[0],points[1]];
edges.push(line);
return [line.slice(), line.reverse()];
} else {
var half = Math.floor(points.length/2);
return delaunayMerge(delaunay(points.slice(0,half)),
delaunay(points.slice(half, points.length)),
edges);
}
}
function delaunayMerge(delRes1, delRes2, edges) {
var ldo = delRes1[0];
var ldi = delRes1[1];
var rdi = delRes2[0];
var rdo = delRes2[0];
if (leftOf(rdi[0], ldi) //what?????
};