@woosh/meep-engine 2.76.0 → 2.76.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +757 -2299
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +757 -2300
- package/package.json +1 -1
- package/src/core/binary/BitSet.js +4 -2
- package/src/core/collection/heap/Uin32Heap.spec.js +14 -1
- package/src/core/collection/heap/Uint32Heap.js +31 -16
- package/src/engine/__module.js +1 -0
- package/src/engine/navigation/__module.js +1 -0
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +193 -124
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +75 -15
|
@@ -1,32 +1,92 @@
|
|
|
1
|
+
import { randomIntegerBetween } from "../../../core/math/random/randomIntegerBetween.js";
|
|
2
|
+
import { seededRandom } from "../../../core/math/random/seededRandom.js";
|
|
3
|
+
import { number_pretty_print } from "../../../core/primitives/numbers/number_pretty_print.js";
|
|
1
4
|
import { find_path_on_grid_astar } from "./find_path_on_grid_astar.js";
|
|
2
5
|
|
|
3
6
|
test("sanity check on 1x1 grid", () => {
|
|
4
|
-
const path = find_path_on_grid_astar([0], 1, 1, 0, 0, 0,
|
|
7
|
+
const path = find_path_on_grid_astar([0], 1, 1, 0, 0, 0, 1);
|
|
5
8
|
|
|
6
9
|
expect(path).toEqual([0]);
|
|
7
10
|
});
|
|
8
11
|
|
|
9
12
|
test("sanity check on 2x1 grid", () => {
|
|
10
|
-
const path = find_path_on_grid_astar(
|
|
11
|
-
[0, 0], 2, 1,
|
|
12
|
-
0, 1,
|
|
13
|
-
0, 0, 1
|
|
14
|
-
);
|
|
13
|
+
const path = find_path_on_grid_astar([0, 0], 2, 1, 0, 1, 0, 1);
|
|
15
14
|
|
|
16
15
|
expect(path).toEqual([0, 1]);
|
|
17
16
|
});
|
|
18
17
|
|
|
19
18
|
test("sanity check on 2x2 grid", () => {
|
|
20
19
|
|
|
21
|
-
const path = find_path_on_grid_astar(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
],
|
|
26
|
-
2, 2,
|
|
27
|
-
0, 3,
|
|
28
|
-
0, 0, 1
|
|
29
|
-
);
|
|
20
|
+
const path = find_path_on_grid_astar([
|
|
21
|
+
0, 0,
|
|
22
|
+
1, 0
|
|
23
|
+
], 2, 2, 0, 3, 0, 1);
|
|
30
24
|
|
|
31
25
|
expect(path).toEqual([0, 1, 3]);
|
|
32
26
|
});
|
|
27
|
+
|
|
28
|
+
test("path on open 3x3 grid", () => {
|
|
29
|
+
|
|
30
|
+
const path = find_path_on_grid_astar([
|
|
31
|
+
0, 0, 0,
|
|
32
|
+
0, 0, 0,
|
|
33
|
+
0, 0, 0
|
|
34
|
+
], 3, 3, 0, 8, 0, 1);
|
|
35
|
+
|
|
36
|
+
expect(path).toEqual([0, 6, 8]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("performance, 256x256 random", () => {
|
|
40
|
+
const FIELD_SIZE = 256;
|
|
41
|
+
|
|
42
|
+
const field = new Uint8Array(FIELD_SIZE * FIELD_SIZE);
|
|
43
|
+
|
|
44
|
+
const random = seededRandom(42);
|
|
45
|
+
|
|
46
|
+
const last_field_index = field.length - 1;
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < field.length * 0.05; i++) {
|
|
49
|
+
const index = randomIntegerBetween(random, 0, last_field_index);
|
|
50
|
+
|
|
51
|
+
field[index] = 255;
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const SAMPLE_COUNT = 10000;
|
|
56
|
+
|
|
57
|
+
const coordinates = new Uint32Array(SAMPLE_COUNT * 2);
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < SAMPLE_COUNT * 2; i++) {
|
|
60
|
+
//build non-blocking point pairs for rout endpoints
|
|
61
|
+
const index = randomIntegerBetween(random, 0, last_field_index);
|
|
62
|
+
|
|
63
|
+
if (field[index] !== 0) {
|
|
64
|
+
i--;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
coordinates[i] = index;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const t0 = performance.now();
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < SAMPLE_COUNT; i++) {
|
|
74
|
+
|
|
75
|
+
const i2 = i * 2;
|
|
76
|
+
const start = coordinates[i2];
|
|
77
|
+
const goal = coordinates[i2 + 1];
|
|
78
|
+
|
|
79
|
+
find_path_on_grid_astar(
|
|
80
|
+
field,
|
|
81
|
+
FIELD_SIZE, FIELD_SIZE,
|
|
82
|
+
start,
|
|
83
|
+
goal, 1, 255
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const t1 = performance.now();
|
|
88
|
+
|
|
89
|
+
const duration = t1 - t0;
|
|
90
|
+
|
|
91
|
+
console.log(`${number_pretty_print(SAMPLE_COUNT)} paths, ${number_pretty_print(duration / SAMPLE_COUNT)}ms per path`);
|
|
92
|
+
});
|