-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpdtest.html
95 lines (79 loc) · 2.63 KB
/
cpdtest.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script type="text/javascript" src="d3-master/d3.js"></script>
<script type="text/javascript" src="ConvexHull.js"></script>
<script type="text/javascript" src="PowerDiagram.js"></script>
<script src="jquery-1.11.0.min.js"></script>
</head>
<body>
<style>
body{ background-color:#EEF; } .name{ cursor: pointer; cursor:
hand; } div.first{ width:650px;
}
</style>
<div>
<h1> VORONOI TESTING </h1>
<p id="chart"></p>
<script>
function printFacets(facets){
for (var i = 0; i < facets.length; i++){
console.log("Face: " + i);
for (var j = 0; j < 3; j++){
console.log("\t" + j + ": " + facets[i].verts[j].x + " : "
+ facets[i].verts[j].y + " : " + facets[i].verts[j].z + " : ");
}
}
}
var w = 1000;
var h = 1000;
var num = 100;
boundingPoly = d3.geom.polygon([[-w,-h],[-w,2 *h],[2*w,2*h],[2*w,-h]]);
var sites = d3.range(num).map(function(d, i) {
var r =[Math.random() * w, Math.random()*h, 1E-10]; //Math.random()*w];
return(r);
});
var weights = d3.range(num).map(function() {
var r =Math.random()*10;
return(r);
});
for (var i = 0; i < sites.length; i++){
for (var j = 0; j < sites.length; j++){
if (i !== j && sites[i][0] === sites[j][0] && sites[i][1] === sites[j][1]
&& sites[i][2] === sites[j][2]){
alert("Discarding: " + sites[i] + " : " + sites[j]);
sites.splice(i,1);
}
}
}
// TEST CASE
// var bases = d3.geom.polygon([[-1000, -1000],
// [-1000, 2000],
// [2000, 2000],
// [2000, -1000]]);
// var v = [[310.36066450178623, 132.2060590609908],
// [949.4439263362437, 205.37377358414233],
// [969.2442803643644, 157.36665902659297],
// [672.1746395342052, 687.1926516760141],
// [480.2673126105219, 707.4100147001445],
// [91.76220558583736, 681.5083522815257],
// [521.1214008741081, 429.9340557772666],
// [182.41018848493695, 140.12173330411315],
// [207.10045960731804, 334.0354263782501],
// [466.34850301779807, 635.0483456626534]];
// var w = [1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10,1E-10];
// var x = computePowerDiagram(v, w, bases);
var x = computePowerDiagram(sites, weights, boundingPoly);
for (var i = 0; i < x.length; i++){
console.log(i + ": ");
for (var j =0; j < x[i].length; j++){
console.log("\t" + x[i][j][0] + ", " + x[i][j][1]);
}
}
alert(x.length);
</script>
</div>
</body>
</html>