-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.html
66 lines (49 loc) · 1.76 KB
/
tree.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
<html>
<head>
<title>KD Tree Test</title>
</head>
<body>
<script src="http://my.eatcumtd.com/js/kdtree.js"></script>
<script src="http://my.eatcumtd.com/js/point.js"></script>
<script type="text/javascript">
// This is testing for the KD Tree
var points = new Array();
points.push([0,0]);
points.push([5,3]);
points.push([1,5]);
points.push([-17,36]);
points.push([-7,3]);
points.push([4, -9]);
points.push([50, 25]);
var tree = new KDTree(2, points);
var target = [5, 1];
// 5,3
console.log(tree.findNearestNeighbor(target));
console.log(tree);
var log = '{';
for (var a = 0; a < tree.points.length; a++) {
var point = tree.points[tree.pointIndex[a]];
log += '(' + point.get(0) + ', ' + point.get(1) + ')';
}
log += '}';
console.log(log);
// console.log(tree.remove([5, 3]));
tree
console.log(tree);
var log = '{';
for (var a = 0; a < tree.points.length; a++) {
var point = tree.points[tree.pointIndex[a]];
log += '(' + point.get(0) + ', ' + point.get(1) + ')';
}
log += '}';
console.log(log);
// 0,0
console.log(tree.findNearestNeighbor(target));
// console.log(tree.remove([0,0]));
// // 1,5
// console.log(tree.findNearestNeighbor(target));
// console.log(tree.remove([1,5]));
// console.log(tree.findNearestNeighbor(target));
</script>
</body>
</html>