@woosh/meep-engine 2.87.6 → 2.88.0
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 +9 -3
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +9 -3
- package/editor/view/ecs/HierarchicalEntityListView.js +1 -1
- package/editor/view/v2/prototypeEditor.js +1 -1
- package/package.json +1 -1
- package/src/core/bvh2/bvh3/BVH.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/BVH.js +4 -2
- package/src/core/bvh2/bvh3/BVH.spec.js +15 -3
- package/src/core/geom/2d/aabb/aabb2_clip_line_cohen_sutherland.d.ts +16 -0
- package/src/core/geom/2d/aabb/aabb2_clip_line_cohen_sutherland.d.ts.map +1 -0
- package/src/core/geom/2d/aabb/aabb2_clip_line_cohen_sutherland.js +149 -0
- package/src/core/geom/2d/aabb/aabb2_intersects_circle.d.ts +13 -0
- package/src/core/geom/2d/aabb/aabb2_intersects_circle.d.ts.map +1 -0
- package/src/core/geom/2d/aabb/aabb2_intersects_circle.js +27 -0
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.d.ts +41 -6
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.d.ts.map +1 -1
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.js +92 -22
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.spec.js +98 -2
- package/src/core/geom/2d/hash-grid/prototypeGridQueries.d.ts +2 -0
- package/src/core/geom/2d/hash-grid/prototypeGridQueries.d.ts.map +1 -0
- package/src/core/geom/2d/hash-grid/prototypeGridQueries.js +387 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.d.ts +12 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.d.ts.map +1 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.js +160 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.spec.d.ts +2 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.spec.d.ts.map +1 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.spec.js +85 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.d.ts +14 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.d.ts.map +1 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.js +132 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.spec.d.ts +2 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.spec.d.ts.map +1 -0
- package/src/core/geom/2d/hash-grid/shg_query_elements_line.spec.js +102 -0
- package/src/core/geom/2d/line/line2_distance_to_point_sqr.d.ts +11 -0
- package/src/core/geom/2d/line/line2_distance_to_point_sqr.d.ts.map +1 -0
- package/src/core/geom/2d/line/line2_distance_to_point_sqr.js +39 -0
- package/src/core/geom/2d/quad-tree/QuadTreeNode.spec.js +53 -0
- package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.spec.d.ts +2 -0
- package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.spec.d.ts.map +1 -0
- package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.spec.js +86 -0
- package/src/core/model/ObservedString.d.ts.map +1 -1
- package/src/core/model/ObservedString.js +1 -1
- package/src/engine/animation/curve/ecd_bind_animation_curve.js +1 -1
- package/src/engine/ecs/name/Name.d.ts +25 -0
- package/src/engine/ecs/name/Name.d.ts.map +1 -0
- package/src/engine/ecs/name/Name.js +42 -0
- package/src/engine/ecs/name/NameSerializationAdapter.d.ts +18 -0
- package/src/engine/ecs/name/NameSerializationAdapter.d.ts.map +1 -0
- package/src/engine/ecs/name/NameSerializationAdapter.js +29 -0
- package/src/engine/ecs/transform/Transform.d.ts +2 -2
- package/src/engine/graphics/canvas/canvas2d_draw_grid.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +1 -1
- package/src/core/geom/2d/hash-grid/shg_query_raycast.d.ts +0 -14
- package/src/core/geom/2d/hash-grid/shg_query_raycast.d.ts.map +0 -1
- package/src/core/geom/2d/hash-grid/shg_query_raycast.js +0 -21
package/build/meep.module.js
CHANGED
|
@@ -50994,7 +50994,7 @@ function computeStringHash(string) {
|
|
|
50994
50994
|
class ObservedString extends String {
|
|
50995
50995
|
/**
|
|
50996
50996
|
*
|
|
50997
|
-
* @param {
|
|
50997
|
+
* @param {string} [value]
|
|
50998
50998
|
* @constructor
|
|
50999
50999
|
*/
|
|
51000
51000
|
constructor(value = "") {
|
|
@@ -52622,8 +52622,10 @@ class BVH {
|
|
|
52622
52622
|
let index = this.__root;
|
|
52623
52623
|
|
|
52624
52624
|
while (this.node_is_leaf(index) === false) {
|
|
52625
|
-
const
|
|
52626
|
-
|
|
52625
|
+
const node_address = index * ELEMENT_WORD_COUNT;
|
|
52626
|
+
|
|
52627
|
+
const child1 = uint32[node_address + COLUMN_CHILD_1];
|
|
52628
|
+
const child2 = uint32[node_address + COLUMN_CHILD_2];
|
|
52627
52629
|
|
|
52628
52630
|
const area = this.node_get_surface_area(index);
|
|
52629
52631
|
|
|
@@ -73701,6 +73703,10 @@ function assetTypeByPath(url) {
|
|
|
73701
73703
|
}
|
|
73702
73704
|
|
|
73703
73705
|
class Name extends ObservedString {
|
|
73706
|
+
/**
|
|
73707
|
+
*
|
|
73708
|
+
* @param {string} [value]
|
|
73709
|
+
*/
|
|
73704
73710
|
constructor(value = "") {
|
|
73705
73711
|
super(value);
|
|
73706
73712
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Name from "../../../../model/game/ecs/component/Name.js";
|
|
2
1
|
import { arraySetSortingDiff } from "../../../src/core/collection/array/arraySetSortingDiff.js";
|
|
3
2
|
import List from "../../../src/core/collection/list/List.js";
|
|
4
3
|
import Signal from "../../../src/core/events/signal/Signal.js";
|
|
5
4
|
import { number_compare_ascending } from "../../../src/core/primitives/numbers/number_compare_ascending.js";
|
|
5
|
+
import Name from "../../../src/engine/ecs/name/Name.js";
|
|
6
6
|
import { ParentEntity } from "../../../src/engine/ecs/parent/ParentEntity.js";
|
|
7
7
|
import { MouseEvents } from "../../../src/engine/input/devices/events/MouseEvents.js";
|
|
8
8
|
import LabelView from "../../../src/view/common/LabelView.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Name from "../../../../model/game/ecs/component/Name.js";
|
|
2
1
|
import { initializeEditor } from "../../../../model/game/initializeEditor.js";
|
|
3
2
|
import { randomFromArray } from "../../../src/core/math/random/randomFromArray.js";
|
|
4
3
|
import { randomIntegerBetween } from "../../../src/core/math/random/randomIntegerBetween.js";
|
|
5
4
|
import { seededRandom } from "../../../src/core/math/random/seededRandom.js";
|
|
6
5
|
import { TextureAssetLoader } from "../../../src/engine/asset/loaders/texture/TextureAssetLoader.js";
|
|
6
|
+
import Name from "../../../src/engine/ecs/name/Name.js";
|
|
7
7
|
import { EntityNode } from "../../../src/engine/ecs/parent/EntityNode.js";
|
|
8
8
|
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
9
9
|
import { EngineHarness } from "../../../src/engine/EngineHarness.js";
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BVH.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/BVH.js"],"names":[],"mappings":"AAQA,8BAA+B;AAC/B,+BAAgC;AAChC,+BAAgC;AAChC,8BAA+B;AAU/B;;;GAGG;AACH,wBAFU,MAAM,CAEoB;AAcpC;;;;;GAKG;AACH,iCAFU,MAAM,CAEqB;AAgBrC;;;;;;GAMG;AACH;IAEI;;;;OAIG;IACH,sBAA2E;IAE3E;;;;OAIG;IACH,uBAAsD;IAEtD;;;;OAIG;IACH,sBAAoD;IAEpD;;;;OAIG;IACH,mBAA8B;IAE9B;;;;OAIG;IACH,eAAW;IAEX;;;;OAIG;IACH,eAAY;IAEZ;;;;OAIG;IACH,uBAAmB;IAEnB;;;;OAIG;IACH,eAAmB;IAEnB;;;OAGG;IACH,mBAEC;IAUD;;;OAGG;IACH,+BAMC;IAlBD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OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,oBAHW,MAAM,UACN,MAAM,QAKhB;IAED;;;;OAIG;IACH,kBAHW,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,QAe/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,QACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,QAsBpC;IAED;;;;OAIG;IACH,mBAHW,MAAM,QACN,MAAM,EAAE,QAWlB;IAED;;;;;;;;;OASG;IACH,4BARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAmBhB;IAED;;;;OAIG;IACH,0BAHW,MAAM,GACJ,MAAM,CAoBlB;IAED;;;;;OAKG;IACH,wCAJW,MAAM,WACN,MAAM,GACJ,MAAM,CAoClB;IAED;;;;;OAKG;IACH,oCAJW,MAAM,WACN,MAAM,WACN,MAAM,QAyChB;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,IAAI,CA0GhB;IAED;;;;;OAKG;IACH,wBAuBC;IAED;;;;OAIG;IACH,yBA4BC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,IAAI,CA6ChB;IAED;;;;;;OAMG;IACH,gBAoMC;IAED;;;OAGG;IACH,oBAIC;IAED;;;;OAIG;IACH,yCA8BC;IAED;;;;;OAKG;IACH,+BAJW,MAAM,EAAE,sBACR,MAAM,GACJ,MAAM,CAWlB;IAED;;;;;OAKG;IACH,0BA6BC;IAED;;;;;OAKG;IACH,cAJW,MAAM,KACN,MAAM,GACJ,OAAO,CAsCnB;CACJ"}
|
|
@@ -617,8 +617,10 @@ export class BVH {
|
|
|
617
617
|
let index = this.__root;
|
|
618
618
|
|
|
619
619
|
while (this.node_is_leaf(index) === false) {
|
|
620
|
-
const
|
|
621
|
-
|
|
620
|
+
const node_address = index * ELEMENT_WORD_COUNT;
|
|
621
|
+
|
|
622
|
+
const child1 = uint32[node_address + COLUMN_CHILD_1];
|
|
623
|
+
const child2 = uint32[node_address + COLUMN_CHILD_2];
|
|
622
624
|
|
|
623
625
|
const area = this.node_get_surface_area(index);
|
|
624
626
|
|
|
@@ -305,7 +305,7 @@ test("move leaf node", () => {
|
|
|
305
305
|
expect(actual_bounds).toEqual(a_new_bounds);
|
|
306
306
|
});
|
|
307
307
|
|
|
308
|
-
test.skip("performance, insert
|
|
308
|
+
test.skip("performance, insert 100k random nodes", () => {
|
|
309
309
|
|
|
310
310
|
const random = seededRandom(1);
|
|
311
311
|
|
|
@@ -314,9 +314,9 @@ test.skip("performance, insert 10k random nodes", () => {
|
|
|
314
314
|
const min_bound = -1000;
|
|
315
315
|
const max_bound = 1000;
|
|
316
316
|
|
|
317
|
-
const OBJECT_COUNT =
|
|
318
|
-
|
|
317
|
+
const OBJECT_COUNT = 100000;
|
|
319
318
|
|
|
319
|
+
const leaves = new Uint32Array(OBJECT_COUNT);
|
|
320
320
|
for (let i = 0; i < OBJECT_COUNT; i++) {
|
|
321
321
|
const node = bvh.allocate_node();
|
|
322
322
|
|
|
@@ -343,7 +343,19 @@ test.skip("performance, insert 10k random nodes", () => {
|
|
|
343
343
|
x0, y0, z0,
|
|
344
344
|
x1, y1, z1
|
|
345
345
|
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const t0 = performance.now();
|
|
349
|
+
for (let i = 0; i < OBJECT_COUNT; i++) {
|
|
350
|
+
const node = leaves[i];
|
|
346
351
|
|
|
347
352
|
bvh.insert_leaf(node);
|
|
348
353
|
}
|
|
354
|
+
|
|
355
|
+
const duration = performance.now() - t0;
|
|
356
|
+
|
|
357
|
+
const duration_seconds = duration * 1e-3;
|
|
358
|
+
|
|
359
|
+
console.log(`Duration ${duration_seconds}s, ${(OBJECT_COUNT / duration_seconds).toFixed(2)} records per second`);
|
|
360
|
+
|
|
349
361
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements Cohen–Sutherland algorithm
|
|
3
|
+
* @param {number[]|Float32Array|Float64Array} result
|
|
4
|
+
* @param {number} result_offset
|
|
5
|
+
* @param {number} box_x0
|
|
6
|
+
* @param {number} box_y0
|
|
7
|
+
* @param {number} box_x1
|
|
8
|
+
* @param {number} box_y1
|
|
9
|
+
* @param {number} line_x0
|
|
10
|
+
* @param {number} line_y0
|
|
11
|
+
* @param {number} line_x1
|
|
12
|
+
* @param {number} line_y1
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export function aabb2_clip_line_cohen_sutherland(result: number[] | Float32Array | Float64Array, result_offset: number, box_x0: number, box_y0: number, box_x1: number, box_y1: number, line_x0: number, line_y0: number, line_x1: number, line_y1: number): boolean;
|
|
16
|
+
//# sourceMappingURL=aabb2_clip_line_cohen_sutherland.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aabb2_clip_line_cohen_sutherland.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/aabb/aabb2_clip_line_cohen_sutherland.js"],"names":[],"mappings":"AA0CA;;;;;;;;;;;;;GAaG;AACH,yDAZW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,UACN,MAAM,UACN,MAAM,UACN,MAAM,UACN,MAAM,WACN,MAAM,WACN,MAAM,WACN,MAAM,WACN,MAAM,GACJ,OAAO,CA8FnB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const INSIDE = 0; // 0000
|
|
2
|
+
const LEFT = 1; // 0001
|
|
3
|
+
const RIGHT = 2; // 0010
|
|
4
|
+
const BOTTOM = 4; // 0100
|
|
5
|
+
const TOP = 8; // 1000
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compute the bit code for a point (x, y) using the clip rectangle
|
|
9
|
+
* @param {number} box_x0
|
|
10
|
+
* @param {number} box_y0
|
|
11
|
+
* @param {number} box_x1
|
|
12
|
+
* @param {number} box_y1
|
|
13
|
+
* @param {number} x
|
|
14
|
+
* @param {number} y
|
|
15
|
+
* @return {number}
|
|
16
|
+
*/
|
|
17
|
+
function compute_out_code(
|
|
18
|
+
box_x0, box_y0,
|
|
19
|
+
box_x1, box_y1,
|
|
20
|
+
x, y
|
|
21
|
+
) {
|
|
22
|
+
let code = INSIDE; // initialised as being inside of clip window
|
|
23
|
+
|
|
24
|
+
if (x < box_x0) {
|
|
25
|
+
// to the left of clip window
|
|
26
|
+
code |= LEFT;
|
|
27
|
+
} else if (x > box_x1) {
|
|
28
|
+
// to the right of clip window
|
|
29
|
+
code |= RIGHT;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (y < box_y0) {
|
|
33
|
+
// below the clip window
|
|
34
|
+
code |= BOTTOM;
|
|
35
|
+
} else if (y > box_y1) {
|
|
36
|
+
// above the clip window
|
|
37
|
+
code |= TOP;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return code;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Implements Cohen–Sutherland algorithm
|
|
45
|
+
* @param {number[]|Float32Array|Float64Array} result
|
|
46
|
+
* @param {number} result_offset
|
|
47
|
+
* @param {number} box_x0
|
|
48
|
+
* @param {number} box_y0
|
|
49
|
+
* @param {number} box_x1
|
|
50
|
+
* @param {number} box_y1
|
|
51
|
+
* @param {number} line_x0
|
|
52
|
+
* @param {number} line_y0
|
|
53
|
+
* @param {number} line_x1
|
|
54
|
+
* @param {number} line_y1
|
|
55
|
+
* @returns {boolean}
|
|
56
|
+
*/
|
|
57
|
+
export function aabb2_clip_line_cohen_sutherland(
|
|
58
|
+
result, result_offset,
|
|
59
|
+
box_x0, box_y0,
|
|
60
|
+
box_x1, box_y1,
|
|
61
|
+
line_x0, line_y0,
|
|
62
|
+
line_x1, line_y1
|
|
63
|
+
) {
|
|
64
|
+
let x0 = line_x0;
|
|
65
|
+
let y0 = line_y0;
|
|
66
|
+
let x1 = line_x1;
|
|
67
|
+
let y1 = line_y1;
|
|
68
|
+
|
|
69
|
+
// compute out codes for P0, P1, and whatever point lies outside the clip rectangle
|
|
70
|
+
let out_code_0 = compute_out_code(
|
|
71
|
+
box_x0, box_y0,
|
|
72
|
+
box_x1, box_y1,
|
|
73
|
+
x0, y0
|
|
74
|
+
);
|
|
75
|
+
let out_code_1 = compute_out_code(
|
|
76
|
+
box_x0, box_y0,
|
|
77
|
+
box_x1, box_y1,
|
|
78
|
+
x1, y1
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
let x, y;
|
|
82
|
+
|
|
83
|
+
while (true) {
|
|
84
|
+
if ((out_code_0 | out_code_1) === 0) {
|
|
85
|
+
// bitwise OR is 0: both points inside window; trivially accept and exit loop
|
|
86
|
+
|
|
87
|
+
result[result_offset] = x0;
|
|
88
|
+
result[result_offset + 1] = y0;
|
|
89
|
+
result[result_offset + 2] = x1;
|
|
90
|
+
result[result_offset + 3] = y1;
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
} else if ((out_code_0 & out_code_1) !== 0) {
|
|
94
|
+
// bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,
|
|
95
|
+
// or BOTTOM), so both must be outside window; exit loop (accept is false)
|
|
96
|
+
return false;
|
|
97
|
+
} else {
|
|
98
|
+
// failed both tests, so calculate the line segment to clip
|
|
99
|
+
// from an outside point to an intersection with clip edge
|
|
100
|
+
|
|
101
|
+
// At least one endpoint is outside the clip rectangle; pick it.
|
|
102
|
+
const outcodeOut = out_code_1 > out_code_0 ? out_code_1 : out_code_0;
|
|
103
|
+
|
|
104
|
+
// Now find the intersection point;
|
|
105
|
+
// use formulas:
|
|
106
|
+
// slope = (y1 - y0) / (x1 - x0)
|
|
107
|
+
// x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax
|
|
108
|
+
// y = y0 + slope * (xm - x0), where xm is xmin or xmax
|
|
109
|
+
// No need to worry about divide-by-zero because, in each case, the
|
|
110
|
+
// outcode bit being tested guarantees the denominator is non-zero
|
|
111
|
+
if (outcodeOut & TOP) {
|
|
112
|
+
// point is above the clip window
|
|
113
|
+
x = x0 + (x1 - x0) * (box_y1 - y0) / (y1 - y0);
|
|
114
|
+
y = box_y1;
|
|
115
|
+
} else if (outcodeOut & BOTTOM) {
|
|
116
|
+
// point is below the clip window
|
|
117
|
+
x = x0 + (x1 - x0) * (box_y0 - y0) / (y1 - y0);
|
|
118
|
+
y = box_y0;
|
|
119
|
+
} else if (outcodeOut & RIGHT) {
|
|
120
|
+
// point is to the right of clip window
|
|
121
|
+
y = y0 + (y1 - y0) * (box_x1 - x0) / (x1 - x0);
|
|
122
|
+
x = box_x1;
|
|
123
|
+
} else if (outcodeOut & LEFT) {
|
|
124
|
+
// point is to the left of clip window
|
|
125
|
+
y = y0 + (y1 - y0) * (box_x0 - x0) / (x1 - x0);
|
|
126
|
+
x = box_x0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Now we move outside point to intersection point to clip
|
|
130
|
+
// and get ready for next pass.
|
|
131
|
+
if (outcodeOut === out_code_0) {
|
|
132
|
+
x0 = x;
|
|
133
|
+
y0 = y;
|
|
134
|
+
out_code_0 = compute_out_code(
|
|
135
|
+
box_x0, box_y0,
|
|
136
|
+
box_x1, box_y1, x0, y0
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
x1 = x;
|
|
140
|
+
y1 = y;
|
|
141
|
+
out_code_1 = compute_out_code(
|
|
142
|
+
box_x0, box_y0,
|
|
143
|
+
box_x1, box_y1,
|
|
144
|
+
x1, y1
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} x0
|
|
4
|
+
* @param {number} y0
|
|
5
|
+
* @param {number} x1
|
|
6
|
+
* @param {number} y1
|
|
7
|
+
* @param {number} center_x
|
|
8
|
+
* @param {number} center_y
|
|
9
|
+
* @param {number} radius
|
|
10
|
+
* @return {boolean}
|
|
11
|
+
*/
|
|
12
|
+
export function aabb2_intersects_circle(x0: number, y0: number, x1: number, y1: number, center_x: number, center_y: number, radius: number): boolean;
|
|
13
|
+
//# sourceMappingURL=aabb2_intersects_circle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aabb2_intersects_circle.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/aabb/aabb2_intersects_circle.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,4CATW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,YACN,MAAM,YACN,MAAM,UACN,MAAM,GACL,OAAO,CAelB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { aabb2_distance_sqr_to_point } from "./aabb2_distance_sqr_to_point.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} x0
|
|
6
|
+
* @param {number} y0
|
|
7
|
+
* @param {number} x1
|
|
8
|
+
* @param {number} y1
|
|
9
|
+
* @param {number} center_x
|
|
10
|
+
* @param {number} center_y
|
|
11
|
+
* @param {number} radius
|
|
12
|
+
* @return {boolean}
|
|
13
|
+
*/
|
|
14
|
+
export function aabb2_intersects_circle(
|
|
15
|
+
x0, y0,
|
|
16
|
+
x1, y1,
|
|
17
|
+
center_x, center_y, radius
|
|
18
|
+
) {
|
|
19
|
+
|
|
20
|
+
const distance_to_center = aabb2_distance_sqr_to_point(
|
|
21
|
+
x0, y0,
|
|
22
|
+
x1, y1,
|
|
23
|
+
center_x, center_y
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return distance_to_center < radius * radius;
|
|
27
|
+
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
export const NULL_POINTER: number;
|
|
2
|
+
export const COLUMN_ELEMENT_X0: 2;
|
|
3
|
+
export const COLUMN_ELEMENT_Y0: 3;
|
|
4
|
+
export const COLUMN_ELEMENT_X1: 4;
|
|
5
|
+
export const COLUMN_ELEMENT_Y1: 5;
|
|
1
6
|
export class SpatialHashGrid {
|
|
2
7
|
constructor(size_x?: number, size_y?: number, scale?: number);
|
|
8
|
+
get size_x(): number;
|
|
9
|
+
get size_y(): number;
|
|
10
|
+
get node_pool(): BinaryElementPool;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @return {BinaryElementPool}
|
|
14
|
+
*/
|
|
15
|
+
get element_pool(): BinaryElementPool;
|
|
16
|
+
get scale(): number;
|
|
17
|
+
get scale_inverse(): number;
|
|
3
18
|
element_allocate(): number;
|
|
4
19
|
element_set_user_data(element: any, user_data: any): void;
|
|
20
|
+
element_get_user_data(element: any): number;
|
|
5
21
|
/**
|
|
6
22
|
* You have to remove the element from the grid before changing its bounds
|
|
7
23
|
* @param {number} element
|
|
@@ -21,20 +37,38 @@ export class SpatialHashGrid {
|
|
|
21
37
|
* @param {number} element
|
|
22
38
|
*/
|
|
23
39
|
element_insert(element: number): void;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {number} node
|
|
43
|
+
* @return {number}
|
|
44
|
+
*/
|
|
45
|
+
node_get_element(node: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Next element in the linked list of cell's nodes
|
|
48
|
+
* @param {number} node
|
|
49
|
+
* @return {number}
|
|
50
|
+
*/
|
|
51
|
+
node_get_same_cell_next_node(node: number): number;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {number} cell_index
|
|
55
|
+
* @return {number}
|
|
56
|
+
*/
|
|
57
|
+
cell_get_first_node(cell_index: number): number;
|
|
24
58
|
/**
|
|
25
59
|
*
|
|
26
60
|
* @param {number} x
|
|
27
61
|
* @param {number} y
|
|
28
|
-
* @
|
|
62
|
+
* @return {number}
|
|
29
63
|
*/
|
|
30
|
-
|
|
64
|
+
world_position_to_cell_index(x: number, y: number): number;
|
|
31
65
|
/**
|
|
32
66
|
*
|
|
33
|
-
* @param {number
|
|
34
|
-
* @param {number}
|
|
35
|
-
* @
|
|
67
|
+
* @param {number} x
|
|
68
|
+
* @param {number} y
|
|
69
|
+
* @returns {number}
|
|
36
70
|
*/
|
|
37
|
-
|
|
71
|
+
cell_position_to_index(x: number, y: number): number;
|
|
38
72
|
/**
|
|
39
73
|
*
|
|
40
74
|
* @param {number} cell_x
|
|
@@ -49,4 +83,5 @@ export class SpatialHashGrid {
|
|
|
49
83
|
element_remove(element: number): void;
|
|
50
84
|
#private;
|
|
51
85
|
}
|
|
86
|
+
import { BinaryElementPool } from "../../3d/topology/struct/binary/BinaryElementPool.js";
|
|
52
87
|
//# sourceMappingURL=SpatialHashGrid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpatialHashGrid.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/hash-grid/SpatialHashGrid.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpatialHashGrid.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/hash-grid/SpatialHashGrid.js"],"names":[],"mappings":"AAMA,kCAAuC;AA2BvC,kCAAmC;AACnC,kCAAmC;AACnC,kCAAmC;AACnC,kCAAmC;AAEnC;IAuCI,8DAYC;IAxCD,qBAEC;IAED,qBAEC;IAED,mCAEC;IAED;;;OAGG;IACH,sCAEC;IAED,oBAEC;IAED,4BAEC;IAsBD,2BAIC;IAED,0DAKC;IAED,4CAKC;IAED;;;;;;;OAOG;IACH,sCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAYhB;IAED;;;OAGG;IACH,yBAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,wBAFW,MAAM,QA8BhB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACL,MAAM,CAKjB;IAED;;;;OAIG;IACH,mCAHW,MAAM,GACL,MAAM,CAMjB;IAED;;;;OAIG;IACH,gCAHW,MAAM,GACL,MAAM,CAMjB;IAED;;;;;OAKG;IACH,gCAJW,MAAM,KACN,MAAM,GACL,MAAM,CAOjB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAgBlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,UACN,MAAM,GACL,OAAO,CAclB;IA0FD;;;OAGG;IACH,wBAFW,MAAM,QA6BhB;;CACJ;kCA/XiC,sDAAsD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { assert } from "../../../assert.js";
|
|
2
2
|
import { UINT32_MAX } from "../../../binary/UINT32_MAX.js";
|
|
3
|
-
import {
|
|
3
|
+
import { clamp } from "../../../math/clamp.js";
|
|
4
4
|
import { BinaryElementPool } from "../../3d/topology/struct/binary/BinaryElementPool.js";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const NULL_POINTER = UINT32_MAX;
|
|
7
|
+
export const NULL_POINTER = UINT32_MAX;
|
|
8
8
|
/**
|
|
9
9
|
* Single-linked list
|
|
10
10
|
* Pointer to next NODE in the same grid cell
|
|
@@ -31,10 +31,10 @@ const COLUMN_NODE_GRID_INDEX = 3;
|
|
|
31
31
|
|
|
32
32
|
const COLUMN_ELEMENT_DATA = 0;
|
|
33
33
|
const COLUMN_ELEMENT_NODE_FIRST = 1;
|
|
34
|
-
const COLUMN_ELEMENT_X0 = 2;
|
|
35
|
-
const COLUMN_ELEMENT_Y0 = 3;
|
|
36
|
-
const COLUMN_ELEMENT_X1 = 4;
|
|
37
|
-
const COLUMN_ELEMENT_Y1 = 5;
|
|
34
|
+
export const COLUMN_ELEMENT_X0 = 2;
|
|
35
|
+
export const COLUMN_ELEMENT_Y0 = 3;
|
|
36
|
+
export const COLUMN_ELEMENT_X1 = 4;
|
|
37
|
+
export const COLUMN_ELEMENT_Y1 = 5;
|
|
38
38
|
|
|
39
39
|
export class SpatialHashGrid {
|
|
40
40
|
#element_pool = new BinaryElementPool(24)
|
|
@@ -47,6 +47,34 @@ export class SpatialHashGrid {
|
|
|
47
47
|
#scale = 1;
|
|
48
48
|
#scale_inverse = 1;
|
|
49
49
|
|
|
50
|
+
get size_x() {
|
|
51
|
+
return this.#size_x;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get size_y() {
|
|
55
|
+
return this.#size_y;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get node_pool() {
|
|
59
|
+
return this.#node_pool;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @return {BinaryElementPool}
|
|
65
|
+
*/
|
|
66
|
+
get element_pool() {
|
|
67
|
+
return this.#element_pool;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get scale() {
|
|
71
|
+
return this.#scale;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get scale_inverse() {
|
|
75
|
+
return this.#scale_inverse;
|
|
76
|
+
}
|
|
77
|
+
|
|
50
78
|
constructor(size_x = 1, size_y = 1, scale = 8) {
|
|
51
79
|
|
|
52
80
|
assert.notNaN(scale, "scale");
|
|
@@ -80,6 +108,13 @@ export class SpatialHashGrid {
|
|
|
80
108
|
pool.data_uint32[address + COLUMN_ELEMENT_DATA] = user_data;
|
|
81
109
|
}
|
|
82
110
|
|
|
111
|
+
element_get_user_data(element) {
|
|
112
|
+
const pool = this.#element_pool;
|
|
113
|
+
const address = pool.element_word(element);
|
|
114
|
+
|
|
115
|
+
return pool.data_uint32[address + COLUMN_ELEMENT_DATA];
|
|
116
|
+
}
|
|
117
|
+
|
|
83
118
|
/**
|
|
84
119
|
* You have to remove the element from the grid before changing its bounds
|
|
85
120
|
* @param {number} element
|
|
@@ -142,6 +177,51 @@ export class SpatialHashGrid {
|
|
|
142
177
|
}
|
|
143
178
|
}
|
|
144
179
|
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @param {number} node
|
|
183
|
+
* @return {number}
|
|
184
|
+
*/
|
|
185
|
+
node_get_element(node) {
|
|
186
|
+
const address = this.#node_pool.element_word(node);
|
|
187
|
+
return this.#node_pool.data_uint32[address + COLUMN_NODE_ELEMENT];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Next element in the linked list of cell's nodes
|
|
192
|
+
* @param {number} node
|
|
193
|
+
* @return {number}
|
|
194
|
+
*/
|
|
195
|
+
node_get_same_cell_next_node(node) {
|
|
196
|
+
const address = this.#node_pool.element_word(node);
|
|
197
|
+
|
|
198
|
+
return this.#node_pool.data_uint32[address + COLUMN_NODE_SAME_NODE_NEXT];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param {number} cell_index
|
|
204
|
+
* @return {number}
|
|
205
|
+
*/
|
|
206
|
+
cell_get_first_node(cell_index) {
|
|
207
|
+
assert.lessThan(cell_index, this.#size_x * this.#size_y);
|
|
208
|
+
|
|
209
|
+
return this.#grid_data[cell_index]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param {number} x
|
|
215
|
+
* @param {number} y
|
|
216
|
+
* @return {number}
|
|
217
|
+
*/
|
|
218
|
+
world_position_to_cell_index(x, y) {
|
|
219
|
+
const grid_x = clamp(Math.floor(x * this.#scale_inverse), 0, this.#size_x - 1);
|
|
220
|
+
const grid_y = clamp(Math.floor(y * this.#scale_inverse), 0, this.#size_y - 1);
|
|
221
|
+
|
|
222
|
+
return this.cell_position_to_index(grid_x, grid_y);
|
|
223
|
+
}
|
|
224
|
+
|
|
145
225
|
/**
|
|
146
226
|
*
|
|
147
227
|
* @param {number} x
|
|
@@ -152,26 +232,16 @@ export class SpatialHashGrid {
|
|
|
152
232
|
assert.isNonNegativeInteger(x, 'x');
|
|
153
233
|
assert.isNonNegativeInteger(y, 'y');
|
|
154
234
|
|
|
155
|
-
return
|
|
156
|
-
|
|
235
|
+
return y * this.#size_x + x;
|
|
157
236
|
|
|
237
|
+
// const cell_count = this.#size_x * this.#size_y;
|
|
238
|
+
//
|
|
158
239
|
// const _x = split_by_2(x);
|
|
159
240
|
// const _y = split_by_2(y);
|
|
160
241
|
//
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {number[]} out
|
|
167
|
-
* @param {number} out_offset
|
|
168
|
-
* @param {number} index
|
|
169
|
-
*/
|
|
170
|
-
cell_index_to_position(out, out_offset, index) {
|
|
171
|
-
|
|
172
|
-
out[out_offset] = de_interleave_2_bits(index)
|
|
173
|
-
out[out_offset + 1] = de_interleave_2_bits(index >> 1)
|
|
174
|
-
|
|
242
|
+
// const hash = _x | (_y << 1);
|
|
243
|
+
//
|
|
244
|
+
// return hash % cell_count;
|
|
175
245
|
}
|
|
176
246
|
|
|
177
247
|
/**
|