-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.js
85 lines (68 loc) · 1.57 KB
/
debug.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
console.info('Start');
// import { QuadTree } from './capacity_quadtree.js';
import { QuadTree } from './level_quadtree.js';
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class Boundary {
constructor(x, y, w, h) {
this.x1 = x;
this.y1 = y;
this.x2 = w;
this.y2 = h;
}
}
const size = 100;
const tree = new QuadTree;
tree.initialize(size);
const count = 1000;
const objects = [];
const ratio = size / count;
let wx = 0;
let wy = 0;
for (let i = 0; i < count; i++) {
const point = new Point(wx, wy);
objects.push(point);
tree.insert(point);
wx = wx < size ? wx + 1 : 0;
wy = wy < size ? wy + 1 : 0;
}
const point = new Point(50, 50);
const radius = 13;
function test() {
const result = tree.findByRadius(point, radius);
if (result.length == 0) {
console.error(result);
}
for (const target of result) {
target.__hit = true;
}
for (const object of objects) {
const lengthTo = tree.lengthTo(object, point);
const inner = lengthTo <= radius;
const hit = object.__hit;
if ((inner && !hit) || (!inner && hit)) {
console.error('Failed', object, lengthTo, radius);
console.groupEnd();
return;
}
}
console.info('Successful');
let time = Infinity;
for (let i = 0; i < 1000; i++) {
const start = performance.now();
tree.clear();
for (const object of objects) {
tree.insert(object);
}
for (const object of objects) {
tree.findByRadius(object, radius);
}
time = Math.min(time, performance.now() - start);
}
console.info(time);
}
test();