@woosh/meep-engine 2.121.0 → 2.121.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/README.md +1 -1
- package/package.json +1 -1
- package/src/core/collection/map/HashMap.d.ts.map +1 -1
- package/src/core/collection/map/HashMap.js +29 -2
- package/src/core/geom/2d/aabb/aabb2_intersects_point.d.ts +12 -0
- package/src/core/geom/2d/aabb/aabb2_intersects_point.d.ts.map +1 -0
- package/src/core/geom/2d/aabb/aabb2_intersects_point.js +17 -0
- package/src/core/geom/2d/quad-tree/QuadTreeNode.d.ts +17 -6
- package/src/core/geom/2d/quad-tree/QuadTreeNode.d.ts.map +1 -1
- package/src/core/geom/2d/quad-tree/QuadTreeNode.js +59 -98
- package/src/core/geom/2d/quad-tree/qt_collect_by_box.d.ts +14 -0
- package/src/core/geom/2d/quad-tree/qt_collect_by_box.d.ts.map +1 -0
- package/src/core/geom/2d/quad-tree/qt_collect_by_box.js +90 -0
- package/src/core/geom/2d/quad-tree/qt_collect_by_point.d.ts +11 -0
- package/src/core/geom/2d/quad-tree/qt_collect_by_point.d.ts.map +1 -0
- package/src/core/geom/2d/quad-tree/qt_collect_by_point.js +85 -0
- package/src/core/geom/3d/ray/ray3_distance_to_point.d.ts +14 -1
- package/src/core/geom/3d/ray/ray3_distance_to_point.d.ts.map +1 -1
- package/src/core/geom/3d/ray/ray3_distance_to_point.js +18 -1
- package/src/core/geom/3d/shape/UnionShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnionShape3D.js +4 -0
- package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitCubeShape3D.js +4 -0
- package/src/core/geom/ConicRay.d.ts +5 -1
- package/src/core/geom/ConicRay.d.ts.map +1 -1
- package/src/core/geom/ConicRay.js +5 -1
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +67 -49
- package/src/core/geom/packing/max-rect/MaxRectanglesPacker.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +3 -0
- package/src/core/geom/packing/max-rect/cutArea.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/cutArea.js +8 -1
- package/src/core/geom/packing/max-rect/findBestContainer.d.ts +4 -4
- package/src/core/geom/packing/max-rect/findBestContainer.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/findBestContainer.js +30 -8
- package/src/core/geom/packing/max-rect/packOneBox.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/packOneBox.js +7 -2
- package/src/core/geom/packing/max-rect/removeRedundantBoxesArray.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/removeRedundantBoxesArray.js +13 -7
- package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/Miniball.js +27 -1
- package/src/core/geom/packing/miniball/PointSet.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/PointSet.js +25 -4
- package/src/core/geom/packing/miniball/Quality.js +1 -3
- package/src/core/geom/vec3/v3_lerp.d.ts +2 -2
- package/src/core/geom/vec3/v3_lerp.d.ts.map +1 -1
- package/src/core/geom/vec3/v3_lerp.js +3 -1
- package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
- package/src/core/geom/vec3/v3_slerp.js +5 -0
- package/src/core/graph/layout/box/position_box_next_to_box.d.ts.map +1 -1
- package/src/core/graph/layout/box/position_box_next_to_box.js +15 -8
- package/src/core/math/lerp.d.ts +1 -1
- package/src/core/math/lerp.d.ts.map +1 -1
- package/src/core/math/lerp.js +3 -2
- package/src/view/View.d.ts.map +1 -1
- package/src/view/View.js +14 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ To help get you started, various samples are provided under `/samples` folder. F
|
|
|
15
15
|
|
|
16
16
|
Meep is covered by 2,508 unit tests
|
|
17
17
|
|
|
18
|
-
The aim is
|
|
18
|
+
The aim is to [ensure quality](https://about.codecov.io/blog/the-case-against-100-code-coverage/). As a result, the tests are written to cover complex code first and to exhaustively validate critical algorithms.
|
|
19
19
|
Most of the test code is significantly larger than the code that is being tested.
|
|
20
20
|
|
|
21
21
|
## Features
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AAgGD;;;;;;;GAOG;AACH,qBAHa,CAAC,EAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AAgGD;;;;;;;GAOG;AACH,qBAHa,CAAC,EAAC,CAAC;IAyFZ;;;;;;OAMG;IACH,6EALW,CAAS,IAAC,EAAD,GAAC,KAAE,MAAM,EAsC5B;IA7HD;;;;;OAKG;IACH,eAAoB;IAEpB;;;;OAIG;IACH,kBAAyB;IAEzB;;;;OAIG;IACH,wBAAoB;IAEpB;;;;OAIG;IACH,wBAAoB;IAEpB;;;;OAIG;IACH,eAAW;IAEX;;;;OAIG;IACH,oBAAgB;IAEhB;;;;OAIG;IACH,kCAA8B;IAE9B;;;;OAIG;IACH,iCAA6B;IAE7B;;;;OAIG;IACH,qCAAiC;IAEjC;;;;OAIG;IACH,yBAAqB;IAErB;;;;OAIG;IACH,sBAAoC;IAEpC;;;;OAIG;IACH,kBAAc;IAwBV;;;;;OAKG;IACH,iCAAsC;IACtC;;;;;OAKG;IACH,qCAA8C;IAOlD;;;OAGG;IACH,YAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IA2CD;;;;;OAKG;IACH,0BAUC;IAuGD;;;;OAIG;IACH,SAHW,CAAC,SACD,CAAC,QA0EX;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CA+BvB;IAED;;;;;;;;OAQG;IACH,kBALW,CAAC,WACD,CAAS,IAAC,EAAD,CAAC,KAAE,CAAC,oBACb,GAAC,GACA,CAAC,CAgBZ;IAED;;;;;OAKG;IACH,cAJW,CAAC,SACD,CAAC,GACA,CAAC,CAaZ;IAwBD;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CA+CnB;IAED;;;;;OAKG;IACH,sCAHW,GAAC,GACC,OAAO,CA+BnB;IAOD;;OAEG;IACH,gBA0DC;IAmBD,2CA0BC;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,OAAO,CAInB;IAED;;OAEG;IACH,cA6BC;IA+BD;;;OAGG;IACH,WAFa,QAAQ,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAM3B;IAED;;;OAGG;IACH,UAFa,QAAQ,CAAC,CAAC,CAAC,CAOvB;IAED;;;OAGG;IACH,QAFa,QAAQ,CAAC,CAAC,CAAC,CAMvB;IA1DD,yDA2BC;;CAgCJ"}
|
|
@@ -140,48 +140,70 @@ export class HashMap {
|
|
|
140
140
|
* Index pointers to entries array,
|
|
141
141
|
* number of bins is always power or two
|
|
142
142
|
* @type {Uint32Array}
|
|
143
|
+
* @private
|
|
143
144
|
*/
|
|
144
145
|
__bins = EMPTY_BINS;
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
148
|
* Note that dead entries are marked as such with a special reserved hash values, so records can be reused for new entries
|
|
148
149
|
* @type {Array<HashMapEntry<K,V>>}
|
|
150
|
+
* @private
|
|
149
151
|
*/
|
|
150
152
|
__entries = new Array(0);
|
|
151
153
|
|
|
152
154
|
/**
|
|
153
155
|
* Pointer to the end of allocated entries segment
|
|
154
156
|
* @type {number}
|
|
157
|
+
* @private
|
|
155
158
|
*/
|
|
156
159
|
__entries_bound = 0;
|
|
157
160
|
|
|
158
161
|
/**
|
|
159
162
|
*
|
|
160
163
|
* @type {number}
|
|
164
|
+
* @private
|
|
161
165
|
*/
|
|
162
166
|
__entries_start = 0;
|
|
163
167
|
|
|
164
168
|
/**
|
|
165
169
|
* number of records in the map
|
|
166
170
|
* @type {number}
|
|
171
|
+
* @private
|
|
167
172
|
*/
|
|
168
173
|
__size = 0;
|
|
169
174
|
|
|
175
|
+
/**
|
|
176
|
+
*
|
|
177
|
+
* @type {number}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
170
180
|
__bin_count = 0;
|
|
171
181
|
|
|
172
182
|
/**
|
|
173
183
|
* Always exactly half of the number of bins
|
|
174
184
|
* @type {number}
|
|
185
|
+
* @private
|
|
175
186
|
*/
|
|
176
187
|
__entries_allocated_count = 0;
|
|
177
188
|
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* @type {number}
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
178
194
|
__bin_count_power_of_two = 0;
|
|
179
195
|
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @type {number}
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
180
201
|
__entries_count_power_of_two = 0;
|
|
181
202
|
|
|
182
203
|
/**
|
|
183
204
|
* Mask used to map from hash to a bin index
|
|
184
205
|
* @type {number}
|
|
206
|
+
* @private
|
|
185
207
|
*/
|
|
186
208
|
__bin_count_mask = 0;
|
|
187
209
|
|
|
@@ -194,14 +216,15 @@ export class HashMap {
|
|
|
194
216
|
|
|
195
217
|
/**
|
|
196
218
|
* Used to track modifications to prevent concurrent changes during iteration
|
|
219
|
+
* @private
|
|
197
220
|
* @type {number}
|
|
198
221
|
*/
|
|
199
222
|
__version = 0;
|
|
200
223
|
|
|
201
224
|
/**
|
|
202
225
|
* @template K, V
|
|
203
|
-
* @param {function(K):number} [keyHashFunction]
|
|
204
|
-
* @param {function(K,K):boolean} [keyEqualityFunction]
|
|
226
|
+
* @param {function(K):number} [keyHashFunction] function to compute hash of a given key
|
|
227
|
+
* @param {function(K,K):boolean} [keyEqualityFunction] function to compute equality between two keys
|
|
205
228
|
* @param {number} [capacity] initial number of buckets in the hash table
|
|
206
229
|
* @param {number} [loadFactor] a measure of how full the hash table is allowed to get before its capacity is automatically increased
|
|
207
230
|
*/
|
|
@@ -240,6 +263,10 @@ export class HashMap {
|
|
|
240
263
|
this.#setBinCount(ceilPowerOfTwo(capacity));
|
|
241
264
|
}
|
|
242
265
|
|
|
266
|
+
/**
|
|
267
|
+
*
|
|
268
|
+
* @return {number}
|
|
269
|
+
*/
|
|
243
270
|
get size() {
|
|
244
271
|
return this.__size;
|
|
245
272
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} x0
|
|
4
|
+
* @param {number} y0
|
|
5
|
+
* @param {number} x1
|
|
6
|
+
* @param {number} y1
|
|
7
|
+
* @param {number} px
|
|
8
|
+
* @param {number} py
|
|
9
|
+
* @return {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function aabb2_intersects_point(x0: number, y0: number, x1: number, y1: number, px: number, py: number): boolean;
|
|
12
|
+
//# sourceMappingURL=aabb2_intersects_point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aabb2_intersects_point.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/aabb/aabb2_intersects_point.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,2CARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,OAAO,CAQlB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} x0
|
|
4
|
+
* @param {number} y0
|
|
5
|
+
* @param {number} x1
|
|
6
|
+
* @param {number} y1
|
|
7
|
+
* @param {number} px
|
|
8
|
+
* @param {number} py
|
|
9
|
+
* @return {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function aabb2_intersects_point(
|
|
12
|
+
x0, y0,
|
|
13
|
+
x1, y1,
|
|
14
|
+
px, py
|
|
15
|
+
) {
|
|
16
|
+
return x0 <= px && x1 >= px && y0 <= py && y1 >= py;
|
|
17
|
+
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @extends AABB2
|
|
4
4
|
*/
|
|
5
5
|
export class QuadTreeNode<D> extends AABB2 {
|
|
6
|
-
constructor(x0
|
|
6
|
+
constructor(x0: number, y0: number, x1: number, y1: number);
|
|
7
|
+
constructor();
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
10
|
* @type {QuadTreeNode|null}
|
|
@@ -29,6 +30,10 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
29
30
|
* @type {QuadTreeNode|null}
|
|
30
31
|
*/
|
|
31
32
|
parentNode: QuadTreeNode<any> | null;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
32
37
|
treeDataCount: number;
|
|
33
38
|
/**
|
|
34
39
|
*
|
|
@@ -98,12 +103,12 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
98
103
|
traverseData(visitor: (arg0: QuadTreeDatum<D>) => any, thisArg?: any): void;
|
|
99
104
|
/**
|
|
100
105
|
*
|
|
101
|
-
* @param {function(QuadTreeNode):boolean} visitor
|
|
106
|
+
* @param {function(QuadTreeNode<D>):boolean} visitor
|
|
102
107
|
* @param {*} [thisArg]
|
|
103
108
|
*/
|
|
104
|
-
traversePreOrder(visitor: (arg0: QuadTreeNode<
|
|
109
|
+
traversePreOrder(visitor: (arg0: QuadTreeNode<D>) => boolean, thisArg?: any): void;
|
|
105
110
|
/**
|
|
106
|
-
*
|
|
111
|
+
* @deprecated use {@link qt_collect_by_point}
|
|
107
112
|
* @param {number} x
|
|
108
113
|
* @param {number} y
|
|
109
114
|
* @param {function(QuadTreeDatum<D>, x:number,y:number):boolean?} visitor
|
|
@@ -111,7 +116,7 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
111
116
|
*/
|
|
112
117
|
traversePointIntersections(x: number, y: number, visitor: any, thisArg?: any): void;
|
|
113
118
|
/**
|
|
114
|
-
*
|
|
119
|
+
* @deprecated use {@link qt_collect_by_point} directly
|
|
115
120
|
* @param {Array<QuadTreeDatum<D>>} result
|
|
116
121
|
* @param {number} x
|
|
117
122
|
* @param {number} y
|
|
@@ -119,7 +124,7 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
119
124
|
*/
|
|
120
125
|
requestDatumIntersectionsPoint(result: Array<QuadTreeDatum<D>>, x: number, y: number): number;
|
|
121
126
|
/**
|
|
122
|
-
*
|
|
127
|
+
* @deprecated use {@link qt_collect_by_box} instead
|
|
123
128
|
* @param {Array<QuadTreeDatum<D>>} result
|
|
124
129
|
* @param {number} x0
|
|
125
130
|
* @param {number} y0
|
|
@@ -130,6 +135,7 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
130
135
|
requestDatumIntersectionsRectangle(result: Array<QuadTreeDatum<D>>, x0: number, y0: number, x1: number, y1: number): number;
|
|
131
136
|
/**
|
|
132
137
|
* NOTE: touching is not counted as intersection
|
|
138
|
+
* @deprecated use {@link qt_collect_by_box} instead
|
|
133
139
|
* @param {number} x0
|
|
134
140
|
* @param {number} y0
|
|
135
141
|
* @param {number} x1
|
|
@@ -138,6 +144,11 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
138
144
|
* @param {*} [thisArg]
|
|
139
145
|
*/
|
|
140
146
|
traverseRectangleIntersections(x0: number, y0: number, x1: number, y1: number, visitor: (arg0: QuadTreeDatum<D>) => any, thisArg?: any): void;
|
|
147
|
+
/**
|
|
148
|
+
* @readonly
|
|
149
|
+
* @type {boolean}
|
|
150
|
+
*/
|
|
151
|
+
readonly isQuadTreeNode: boolean;
|
|
141
152
|
}
|
|
142
153
|
import AABB2 from "../../2d/aabb/AABB2.js";
|
|
143
154
|
import { QuadTreeDatum } from "./QuadTreeDatum.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuadTreeNode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/QuadTreeNode.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QuadTreeNode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/QuadTreeNode.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH,0BAHa,CAAC;;;IAIV;;;OAGG;IACH,SAFU,oBAAa,IAAI,CAEZ;IACf;;;OAGG;IACH,UAFU,oBAAa,IAAI,CAEX;IAChB;;;OAGG;IACH,YAFU,oBAAa,IAAI,CAET;IAClB;;;OAGG;IACH,aAFU,oBAAa,IAAI,CAER;IAEnB;;;OAGG;IACH,YAFU,oBAAa,IAAI,CAET;IAElB;;;OAGG;IACH,eAFU,MAAM,CAEE;IAGlB;;;OAGG;IACH,MAFU,aAAa,CAAC,CAAC,CAAC,EAAE,CAElB;IAEV,qBAeC;IAED,wBAYC;IAED;;;;;;OAMG;IACH,WALW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAkBhB;IAED;;;;;;;;OAQG;IACH,IARa,CAAC,QACH,CAAC,MACD,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,sBAWhB;IAED;;;OAGG;IACH,6CAuEC;IAED;;;OAGG;IACH,iBAaC;IAED;;;OAGG;IACH,WAFY,OAAO,CAIlB;IAED,cA8BC;IAED;;OAEG;IACH,mBAKC;IAED;;;OAGG;IACH,8CAiBC;IAED;;OAEG;IACH,qBA2DC;IAED,cASC;IAED,cAQC;IAED;;OAEG;IACH,mBAFW,CAAC,EAAE,QAUb;IAED;;;;OAIG;IACH,sBAHW,CAAS,IAAgB,EAAhB,aAAa,CAAC,CAAC,CAAC,QAAC,YAC1B,GAAC,QAeX;IAED;;;;OAIG;IACH,0BAHW,CAAS,IAAe,EAAf,YAAY,CAAC,CAAC,CAAC,KAAE,OAAO,YACjC,GAAC,QAgBX;IAED;;;;;;OAMG;IACH,8BALW,MAAM,KACN,MAAM,0BAEN,GAAC,QASX;IAED;;;;;;OAMG;IACH,uCALW,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KACvB,MAAM,KACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;OAQG;IACH,2CAPW,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MACvB,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;OASG;IACH,mCAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,WACN,CAAS,IAAgB,EAAhB,aAAa,CAAC,CAAC,CAAC,QAAC,YAC1B,GAAC,QA0CX;IAIL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;CANpC;kBAjhBiB,wBAAwB;8BAGZ,oBAAoB"}
|
|
@@ -2,6 +2,8 @@ import { assert } from "../../../assert.js";
|
|
|
2
2
|
import { max2 } from "../../../math/max2.js";
|
|
3
3
|
import { min2 } from "../../../math/min2.js";
|
|
4
4
|
import AABB2 from "../../2d/aabb/AABB2.js";
|
|
5
|
+
import { qt_collect_by_box } from "./qt_collect_by_box.js";
|
|
6
|
+
import { qt_collect_by_point } from "./qt_collect_by_point.js";
|
|
5
7
|
import { QuadTreeDatum } from "./QuadTreeDatum.js";
|
|
6
8
|
|
|
7
9
|
|
|
@@ -13,45 +15,45 @@ const THRESHOLD_MERGE = 8;
|
|
|
13
15
|
* @extends AABB2
|
|
14
16
|
*/
|
|
15
17
|
export class QuadTreeNode extends AABB2 {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @type {QuadTreeNode|null}
|
|
37
|
-
*/
|
|
38
|
-
this.bottomRight = null;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @type {QuadTreeNode|null}
|
|
21
|
+
*/
|
|
22
|
+
topLeft = null;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @type {QuadTreeNode|null}
|
|
26
|
+
*/
|
|
27
|
+
topRight = null;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @type {QuadTreeNode|null}
|
|
31
|
+
*/
|
|
32
|
+
bottomLeft = null;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {QuadTreeNode|null}
|
|
36
|
+
*/
|
|
37
|
+
bottomRight = null;
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @type {QuadTreeNode|null}
|
|
42
|
+
*/
|
|
43
|
+
parentNode = null;
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
treeDataCount = 0;
|
|
47
50
|
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @type {QuadTreeDatum<D>[]}
|
|
55
|
+
*/
|
|
56
|
+
data = [];
|
|
55
57
|
|
|
56
58
|
balance() {
|
|
57
59
|
const dataLength = this.data.length;
|
|
@@ -174,8 +176,8 @@ export class QuadTreeNode extends AABB2 {
|
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
|
|
177
|
-
const xm = (x0 + x1) *0.5;
|
|
178
|
-
const ym = (y0 + y1) *0.5;
|
|
179
|
+
const xm = (x0 + x1) * 0.5;
|
|
180
|
+
const ym = (y0 + y1) * 0.5;
|
|
179
181
|
|
|
180
182
|
if (datum.y1 < ym) {
|
|
181
183
|
//top
|
|
@@ -417,7 +419,7 @@ export class QuadTreeNode extends AABB2 {
|
|
|
417
419
|
|
|
418
420
|
/**
|
|
419
421
|
*
|
|
420
|
-
* @param {function(QuadTreeNode):boolean} visitor
|
|
422
|
+
* @param {function(QuadTreeNode<D>):boolean} visitor
|
|
421
423
|
* @param {*} [thisArg]
|
|
422
424
|
*/
|
|
423
425
|
traversePreOrder(visitor, thisArg) {
|
|
@@ -437,75 +439,34 @@ export class QuadTreeNode extends AABB2 {
|
|
|
437
439
|
}
|
|
438
440
|
|
|
439
441
|
/**
|
|
440
|
-
*
|
|
442
|
+
* @deprecated use {@link qt_collect_by_point}
|
|
441
443
|
* @param {number} x
|
|
442
444
|
* @param {number} y
|
|
443
445
|
* @param {function(QuadTreeDatum<D>, x:number,y:number):boolean?} visitor
|
|
444
446
|
* @param {*} [thisArg]
|
|
445
447
|
*/
|
|
446
|
-
traversePointIntersections(
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
if (datum.x0 <= x && datum.x1 >= x && datum.y0 <= y && datum.y1 >= y) {
|
|
454
|
-
const continueTraversal = visitor.call(thisArg, datum, x, y);
|
|
455
|
-
|
|
456
|
-
if (continueTraversal === false) {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
if (this.isSplit()) {
|
|
463
|
-
|
|
464
|
-
const hx = (this.x0 + this.x1) / 2;
|
|
465
|
-
const hy = (this.y0 + this.y1) / 2;
|
|
466
|
-
|
|
467
|
-
if (hx >= x) {
|
|
468
|
-
if (hy >= y) {
|
|
469
|
-
this.topLeft.traversePointIntersections(x, y, visitor, thisArg);
|
|
470
|
-
}
|
|
471
|
-
if (hy <= y) {
|
|
472
|
-
this.bottomLeft.traversePointIntersections(x, y, visitor, thisArg);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (hx <= x) {
|
|
477
|
-
if (hy >= y) {
|
|
478
|
-
this.topRight.traversePointIntersections(x, y, visitor, thisArg);
|
|
479
|
-
}
|
|
480
|
-
if (hy <= y) {
|
|
481
|
-
this.bottomRight.traversePointIntersections(x, y, visitor, thisArg);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
}
|
|
448
|
+
traversePointIntersections(
|
|
449
|
+
x,
|
|
450
|
+
y,
|
|
451
|
+
visitor,
|
|
452
|
+
thisArg
|
|
453
|
+
) {
|
|
454
|
+
throw new Error('Deprecated, use `qt_collect_by_point` instead')
|
|
486
455
|
}
|
|
487
456
|
|
|
488
457
|
/**
|
|
489
|
-
*
|
|
458
|
+
* @deprecated use {@link qt_collect_by_point} directly
|
|
490
459
|
* @param {Array<QuadTreeDatum<D>>} result
|
|
491
460
|
* @param {number} x
|
|
492
461
|
* @param {number} y
|
|
493
462
|
* @returns {number} number of intersecting objects added to the result
|
|
494
463
|
*/
|
|
495
464
|
requestDatumIntersectionsPoint(result, x, y) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
let count = 0;
|
|
499
|
-
|
|
500
|
-
this.traversePointIntersections(x, y, (d) => {
|
|
501
|
-
result[count++] = d;
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
return count;
|
|
465
|
+
return qt_collect_by_point(result, 0, this, x, y);
|
|
505
466
|
}
|
|
506
467
|
|
|
507
468
|
/**
|
|
508
|
-
*
|
|
469
|
+
* @deprecated use {@link qt_collect_by_box} instead
|
|
509
470
|
* @param {Array<QuadTreeDatum<D>>} result
|
|
510
471
|
* @param {number} x0
|
|
511
472
|
* @param {number} y0
|
|
@@ -514,18 +475,12 @@ export class QuadTreeNode extends AABB2 {
|
|
|
514
475
|
* @returns {number} number of intersecting objects added to the result
|
|
515
476
|
*/
|
|
516
477
|
requestDatumIntersectionsRectangle(result, x0, y0, x1, y1) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
//TODO optimize closures out, to avoid GC
|
|
520
|
-
this.traverseRectangleIntersections(x0, y0, x1, y1, (d) => {
|
|
521
|
-
result[count++] = d;
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
return count;
|
|
478
|
+
return qt_collect_by_box(result, 0, this, x0, y0, x1, y1);
|
|
525
479
|
}
|
|
526
480
|
|
|
527
481
|
/**
|
|
528
482
|
* NOTE: touching is not counted as intersection
|
|
483
|
+
* @deprecated use {@link qt_collect_by_box} instead
|
|
529
484
|
* @param {number} x0
|
|
530
485
|
* @param {number} y0
|
|
531
486
|
* @param {number} x1
|
|
@@ -576,3 +531,9 @@ export class QuadTreeNode extends AABB2 {
|
|
|
576
531
|
}
|
|
577
532
|
|
|
578
533
|
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @readonly
|
|
537
|
+
* @type {boolean}
|
|
538
|
+
*/
|
|
539
|
+
QuadTreeNode.prototype.isQuadTreeNode = true;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {Array<QuadTreeDatum<T>>} result
|
|
5
|
+
* @param {number} result_offset
|
|
6
|
+
* @param {QuadTreeNode<T>} tree
|
|
7
|
+
* @param {number} x0
|
|
8
|
+
* @param {number} y0
|
|
9
|
+
* @param {number} x1
|
|
10
|
+
* @param {number} y1
|
|
11
|
+
* @returns {number}
|
|
12
|
+
*/
|
|
13
|
+
export function qt_collect_by_box<T>(result: Array<QuadTreeDatum<T>>, result_offset: number, tree: QuadTreeNode<T>, x0: number, y0: number, x1: number, y1: number): number;
|
|
14
|
+
//# sourceMappingURL=qt_collect_by_box.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qt_collect_by_box.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/qt_collect_by_box.js"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,kCAVa,CAAC,UACH,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,iBACvB,MAAM,QACN,YAAY,CAAC,CAAC,CAAC,MACf,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAsElB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
2
|
+
import { aabb2_overlap_exists } from "../aabb/aabb2_overlap_exists.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @type {QuadTreeNode[]}
|
|
7
|
+
*/
|
|
8
|
+
const node_stack = [];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @template T
|
|
13
|
+
* @param {Array<QuadTreeDatum<T>>} result
|
|
14
|
+
* @param {number} result_offset
|
|
15
|
+
* @param {QuadTreeNode<T>} tree
|
|
16
|
+
* @param {number} x0
|
|
17
|
+
* @param {number} y0
|
|
18
|
+
* @param {number} x1
|
|
19
|
+
* @param {number} y1
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
export function qt_collect_by_box(
|
|
23
|
+
result, result_offset,
|
|
24
|
+
tree,
|
|
25
|
+
x0, y0,x1, y1
|
|
26
|
+
){
|
|
27
|
+
assert.isArray(result, 'result');
|
|
28
|
+
assert.isNonNegativeInteger(result_offset, 'result_offset');
|
|
29
|
+
assert.defined(tree, 'tree');
|
|
30
|
+
assert.notNull(tree, 'tree');
|
|
31
|
+
assert.equal(tree.isQuadTreeNode, true, 'tree.isQuadTreeNode !== true');
|
|
32
|
+
assert.isNumber(x0, 'x0');
|
|
33
|
+
assert.isNumber(y0, 'y0');
|
|
34
|
+
assert.isNumber(x1, 'x1');
|
|
35
|
+
assert.isNumber(y1, 'y1');
|
|
36
|
+
|
|
37
|
+
let result_cursor = result_offset;
|
|
38
|
+
|
|
39
|
+
let stack_pointer = 1;
|
|
40
|
+
|
|
41
|
+
node_stack[0] = tree;
|
|
42
|
+
|
|
43
|
+
while (stack_pointer-- > 0) {
|
|
44
|
+
|
|
45
|
+
const node = node_stack[stack_pointer];
|
|
46
|
+
|
|
47
|
+
if (!aabb2_overlap_exists(node.x0, node.y0, node.x1, node.y1, x0, y0, x1,y1)) {
|
|
48
|
+
// not a match
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const data = node.data;
|
|
53
|
+
const data_count = data.length;
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < data_count; i++) {
|
|
56
|
+
const datum = data[i];
|
|
57
|
+
|
|
58
|
+
if (aabb2_overlap_exists(datum.x0, datum.y0, datum.x1, datum.y1, x0, y0, x1,y1)) {
|
|
59
|
+
result[result_cursor++] = datum;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (node.isSplit()) {
|
|
64
|
+
const hx = (node.x0 + node.x1) * 0.5;
|
|
65
|
+
const hy = (node.y0 + node.y1) * 0.5;
|
|
66
|
+
|
|
67
|
+
if (hx >= x0) {
|
|
68
|
+
if (hy >= y0) {
|
|
69
|
+
node_stack[stack_pointer++] = node.topLeft;
|
|
70
|
+
}
|
|
71
|
+
if (hy <= y1) {
|
|
72
|
+
node_stack[stack_pointer++] = node.bottomLeft;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (hx <= x1) {
|
|
77
|
+
if (hy >= y0) {
|
|
78
|
+
node_stack[stack_pointer++] = node.topRight;
|
|
79
|
+
}
|
|
80
|
+
if (hy <= y1) {
|
|
81
|
+
node_stack[stack_pointer++] = node.bottomRight;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result_cursor - result_offset;
|
|
90
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @param {Array<QuadTreeDatum<T>>} result
|
|
4
|
+
* @param {number} result_offset
|
|
5
|
+
* @param {QuadTreeNode<T>} tree
|
|
6
|
+
* @param {number} x
|
|
7
|
+
* @param {number} y
|
|
8
|
+
* @returns {number}
|
|
9
|
+
*/
|
|
10
|
+
export function qt_collect_by_point<T>(result: Array<QuadTreeDatum<T>>, result_offset: number, tree: QuadTreeNode<T>, x: number, y: number): number;
|
|
11
|
+
//# sourceMappingURL=qt_collect_by_point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qt_collect_by_point.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/qt_collect_by_point.js"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,oCARa,CAAC,UACH,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,iBACvB,MAAM,QACN,YAAY,CAAC,CAAC,CAAC,KACf,MAAM,KACN,MAAM,GACJ,MAAM,CAoElB"}
|