@woosh/meep-engine 2.67.0 → 2.69.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.
Files changed (87) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +698 -1270
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +698 -1270
  5. package/package.json +1 -1
  6. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +55 -28
  7. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +3 -3
  8. package/src/core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js +94 -0
  9. package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +17 -18
  10. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +4 -2
  11. package/src/core/geom/3d/aabb/AABB3.js +14 -14
  12. package/src/core/geom/3d/aabb/aabb3_array_intersects_clipping_volume_array.js +30 -0
  13. package/src/core/geom/3d/aabb/aabb3_intersects_clipping_volume_array.js +51 -0
  14. package/src/core/geom/3d/frustum/{read_frustum_planes_to_array.js → read_three_planes_to_array.js} +5 -3
  15. package/src/core/geom/3d/triangle/triangle_intersects_clipping_volume.js +51 -0
  16. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
  17. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +1 -1
  18. package/src/engine/ecs/terrain/tiles/TerrainTile.js +9 -46
  19. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
  20. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
  21. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
  22. package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts +2 -2
  23. package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +79 -36
  24. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +88 -0
  25. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +108 -0
  26. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +4 -30
  27. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_unindexed_geometry.js +30 -0
  28. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +41 -0
  29. package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
  30. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  31. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
  32. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
  33. package/src/engine/graphics/render/view/CameraView.js +8 -8
  34. package/src/core/bvh2/BVHTasks.js +0 -65
  35. package/src/core/bvh2/BinaryNode.d.ts +0 -13
  36. package/src/core/bvh2/BinaryNode.js +0 -1188
  37. package/src/core/bvh2/BinaryNode.spec.js +0 -309
  38. package/src/core/bvh2/LeafNode.d.ts +0 -7
  39. package/src/core/bvh2/LeafNode.js +0 -147
  40. package/src/core/bvh2/Node.d.ts +0 -9
  41. package/src/core/bvh2/Node.js +0 -196
  42. package/src/core/bvh2/NodeValidator.js +0 -197
  43. package/src/core/bvh2/StacklessTraverser.js +0 -154
  44. package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
  45. package/src/core/bvh2/binary/BinaryBVH.js +0 -281
  46. package/src/core/bvh2/binary/IndexedBinaryBVH.js +0 -407
  47. package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +0 -27
  48. package/src/core/bvh2/binary/IndexedBinaryBVHVisitor.js +0 -11
  49. package/src/core/bvh2/binary/NodeType.js +0 -8
  50. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +0 -59
  51. package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
  52. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
  53. package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
  54. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
  55. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
  56. package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
  57. package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
  58. package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
  59. package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
  60. package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
  61. package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
  62. package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
  63. package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
  64. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
  65. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
  66. package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
  67. package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
  68. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
  69. package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
  70. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
  71. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
  72. package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
  73. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
  74. package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
  75. package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
  76. package/src/core/geom/2d/bvh/Node2.js +0 -51
  77. package/src/core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js +0 -20
  78. package/src/core/geom/3d/aabb/aabb3_intersects_frustum_array.js +0 -35
  79. package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
  80. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +0 -195
  81. package/src/engine/graphics/geometry/buffered/query/GeometryVisitor.js +0 -87
  82. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +0 -206
  83. package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
  84. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
  85. package/src/engine/graphics/geometry/bvh/buffered/BinaryBVHFromBufferGeometry.js +0 -123
  86. package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
  87. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +0 -133
@@ -1,384 +0,0 @@
1
- import { BVHVisitor } from "./BVHVisitor.js";
2
- import { read_frustum_planes_to_array } from "../../geom/3d/frustum/read_frustum_planes_to_array.js";
3
- import {
4
- aabb3_detailed_volume_intersection_callback_based
5
- } from "./aabb3_detailed_volume_intersection_callback_based.js";
6
- import { v3_distance_above_plane } from "../../geom/vec3/v3_distance_above_plane.js";
7
-
8
- export class ThreeClippingPlaneComputingBVHVisitor extends BVHVisitor {
9
- constructor() {
10
- super();
11
-
12
- /**
13
- * @private
14
- * @type {Frustum}
15
- */
16
- this.frustum = null;
17
-
18
- /**
19
- *
20
- * @type {Plane[]}
21
- * @private
22
- */
23
- this.__planes = [];
24
-
25
- /**
26
- *
27
- * @type {number}
28
- * @private
29
- */
30
- this.__planeCount = 0;
31
-
32
- /**
33
- *
34
- * @type {Vector3}
35
- * @private
36
- */
37
- this.__nearPlaneNormal = null;
38
- /**
39
- *
40
- * @type {number}
41
- * @private
42
- */
43
- this.__nearPlaneConstant = 0;
44
-
45
- /**
46
- *
47
- * @type {Float32Array}
48
- * @private
49
- */
50
- this.__planes_f32 = new Float32Array(24);
51
-
52
- this.near = 0;
53
- this.far = 0;
54
- }
55
-
56
- /**
57
- *
58
- * @param {Frustum} frustum
59
- */
60
- setFrustum(frustum) {
61
- this.frustum = frustum;
62
- const planes = frustum.planes;
63
-
64
- this.__planes[0] = planes[0];
65
- this.__planes[1] = planes[1];
66
- this.__planes[2] = planes[2];
67
- this.__planes[3] = planes[3];
68
- this.__planes[4] = planes[5];
69
-
70
- const nearPlane = planes[5];
71
-
72
-
73
- this.__nearPlaneNormal = nearPlane.normal;
74
- this.__nearPlaneConstant = nearPlane.constant;
75
-
76
- this.__planeCount = 5;
77
-
78
- read_frustum_planes_to_array(planes, this.__planes_f32);
79
- }
80
-
81
- /**
82
- *
83
- * @param {number} x
84
- * @param {number} y
85
- * @param {number} z
86
- * @private
87
- */
88
- __process_point(x, y, z) {
89
-
90
- // project onto "near" plane
91
- const d = this.__distanceToNearPlane(x, y, z);
92
-
93
- if (d < this.near) {
94
- this.near = d;
95
- }
96
-
97
- if (d > this.far) {
98
- this.far = d;
99
- }
100
-
101
- // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_0.send3(x, y, z);
102
- }
103
-
104
- /**
105
- *
106
- * @param {number} x
107
- * @param {number} y
108
- * @param {number} z
109
- * @return {number}
110
- * @private
111
- */
112
- __distanceToNearPlane(x, y, z) {
113
-
114
- const n = this.__nearPlaneNormal;
115
-
116
- return v3_distance_above_plane(x, y, z, n.x, n.y, n.z, this.__nearPlaneConstant);
117
- }
118
-
119
- /**
120
- * The algorithm has 3 phases:
121
- * 1 ) test corners and record which corners are outside of which planes
122
- * 2 ) test edges attached to outside corners
123
- * 3 ) test planes attached to outside edges
124
- *
125
- * Progressive nature of the algorithm provides good efficiency, as additional phases are only invoked as needed. The algorithm also requires very little memory and is entirely recursion-free
126
- * @param {AABB3} box
127
- * @param {number} plane_mask
128
- * @private
129
- */
130
- __traverseBox_Detailed(box, plane_mask) {
131
-
132
- // make sure to include nearest corner
133
- this.__traverseBoxNearCorner(box);
134
-
135
-
136
- aabb3_detailed_volume_intersection_callback_based(
137
- box.x0, box.y0, box.z0, box.x1, box.y1, box.z1,
138
- plane_mask,
139
- this.__planes_f32,
140
- this.__planeCount,
141
- this.__process_point,
142
- this
143
- );
144
- }
145
-
146
- /**
147
- *
148
- * @param {AABB3} box
149
- * @private
150
- */
151
- __traverseBoxNearCorner(box) {
152
-
153
- const normal = this.__nearPlaneNormal;
154
-
155
- const plane_normal_x = normal.x;
156
- const plane_normal_y = normal.y;
157
- const plane_normal_z = normal.z;
158
-
159
- const _x0 = box.x0;
160
- const _y0 = box.y0;
161
- const _z0 = box.z0;
162
- const _x1 = box.x1;
163
- const _y1 = box.y1;
164
- const _z1 = box.z1;
165
-
166
- let x0,
167
- y0,
168
- z0;
169
-
170
- // construct nearest and farthest corners along the plane normal
171
- if (plane_normal_x > 0) {
172
- x0 = _x0;
173
- } else {
174
- x0 = _x1;
175
- }
176
-
177
- if (plane_normal_y > 0) {
178
- y0 = _y0;
179
- } else {
180
- y0 = _y1;
181
- }
182
-
183
- if (plane_normal_z > 0) {
184
- z0 = _z0;
185
- } else {
186
- z0 = _z1;
187
- }
188
-
189
- this.__process_point(x0, y0, z0);
190
- }
191
-
192
- /**
193
- *
194
- * @param {AABB3} box
195
- * @private
196
- */
197
- __traverseBoxNearAndFarCorners(box) {
198
- const normal = this.__nearPlaneNormal;
199
-
200
- const plane_normal_x = normal.x;
201
- const plane_normal_y = normal.y;
202
- const plane_normal_z = normal.z;
203
-
204
- const _x0 = box.x0;
205
- const _y0 = box.y0;
206
- const _z0 = box.z0;
207
- const _x1 = box.x1;
208
- const _y1 = box.y1;
209
- const _z1 = box.z1;
210
-
211
- let x0,
212
- y0,
213
- z0,
214
- x1,
215
- y1,
216
- z1;
217
-
218
- // construct nearest and farthest corners along the plane normal
219
- if (plane_normal_x > 0) {
220
- x0 = _x0;
221
- x1 = _x1;
222
- } else {
223
- x0 = _x1;
224
- x1 = _x0;
225
- }
226
-
227
- if (plane_normal_y > 0) {
228
- y0 = _y0;
229
- y1 = _y1;
230
- } else {
231
- y0 = _y1;
232
- y1 = _y0;
233
- }
234
-
235
- if (plane_normal_z > 0) {
236
- z0 = _z0;
237
- z1 = _z1;
238
- } else {
239
- z0 = _z1;
240
- z1 = _z0;
241
- }
242
-
243
- this.__process_point(x0, y0, z0);
244
- this.__process_point(x1, y1, z1);
245
- }
246
-
247
-
248
- visitLeaf(node) {
249
- // ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF++;
250
-
251
- let intersection_mask = 0;
252
-
253
- const planeCount = this.__planeCount;
254
- const planes = this.__planes;
255
-
256
- //check planes first
257
- for (let i = 0; i < planeCount; i++) {
258
- const clipPlane = planes[i];
259
-
260
- const planeSide = node.computePlaneSide(clipPlane);
261
- if (planeSide < 0) {
262
- return false;
263
- } else if (planeSide === 0) {
264
- intersection_mask |= 1 << i;
265
- }
266
-
267
- }
268
-
269
- if (intersection_mask !== 0) {
270
- // special case, box intersects one or more planes, compute clipping points
271
- this.__traverseBox_Detailed(node, intersection_mask);
272
- } else {
273
- // box is fully within the frustum
274
- this.__traverseBoxNearAndFarCorners(node);
275
- }
276
-
277
- }
278
-
279
- visitBinary(node) {
280
- const _x0 = node.x0;
281
- const _y0 = node.y0;
282
- const _z0 = node.z0;
283
- const _x1 = node.x1;
284
- const _y1 = node.y1;
285
- const _z1 = node.z1;
286
-
287
-
288
- const normal = this.__nearPlaneNormal;
289
-
290
- const plane_normal_x = normal.x;
291
- const plane_normal_y = normal.y;
292
- const plane_normal_z = normal.z;
293
-
294
- let x0,
295
- y0,
296
- z0,
297
- x1,
298
- y1,
299
- z1;
300
-
301
- // construct nearest and farthest corners along the plane normal
302
- if (plane_normal_x > 0) {
303
- x0 = _x0;
304
- x1 = _x1;
305
- } else {
306
- x0 = _x1;
307
- x1 = _x0;
308
- }
309
-
310
- if (plane_normal_y > 0) {
311
- y0 = _y0;
312
- y1 = _y1;
313
- } else {
314
- y0 = _y1;
315
- y1 = _y0;
316
- }
317
-
318
- if (plane_normal_z > 0) {
319
- z0 = _z0;
320
- z1 = _z1;
321
- } else {
322
- z0 = _z1;
323
- z1 = _z0;
324
- }
325
-
326
- const d_far = this.__distanceToNearPlane(x1, y1, z1);
327
-
328
- if (d_far < 0) {
329
- //behind near plane
330
- return false;
331
- }
332
-
333
- const d_near = this.__distanceToNearPlane(x0, y0, z0);
334
-
335
- //if all corners lie between already set clipping planes - we don't need to check children
336
- if (!(d_near < this.near || d_far > this.far)) {
337
- return false;
338
- }
339
-
340
- /**
341
- *
342
- * @type {Plane[]}
343
- */
344
- const planes = this.__planes;
345
-
346
- let intersects = false;
347
- //check planes
348
- for (let i = 0; i < 4; i++) {
349
- const clipPlane = planes[i];
350
-
351
- const planeSide = node.computePlaneSide(clipPlane);
352
-
353
- if (planeSide < 0) {
354
- return false;
355
- } else if (planeSide === 0) {
356
- intersects = true;
357
- }
358
- }
359
-
360
- if (intersects) {
361
- // node intersects the frustum, continue traversal
362
- return true;
363
- } else {
364
- // node is fully inside the frustum. No need to traverse further
365
-
366
- if (d_near < this.near) {
367
- this.near = d_near;
368
- }
369
-
370
- if (d_far > this.far) {
371
- this.far = d_far;
372
- }
373
-
374
- return false;
375
- }
376
-
377
- }
378
- }
379
-
380
- // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_0 = new Signal(); // DEBUG
381
- // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_1 = new Signal(); // DEBUG
382
- // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_2 = new Signal(); // DEBUG
383
- //
384
- // ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF = 0; // DEBUG
@@ -1,52 +0,0 @@
1
- import { BVHVisitor } from "./BVHVisitor.js";
2
- import { traverseBinaryNodeUsingVisitor } from "./traverseBinaryNodeUsingVisitor.js";
3
-
4
- export class ThreeFrustumsIntersectionBVHVisitor extends BVHVisitor {
5
- constructor() {
6
- super();
7
-
8
- /**
9
- * [plane_x, plane_y, plane_z, constant] collection, defining a frustum
10
- * @private
11
- * @type {ArrayLike<number>|number[]}
12
- */
13
- this.frustum = [];
14
-
15
- /**
16
- *
17
- * @type {BVHVisitor}
18
- */
19
- this.collector = null;
20
- }
21
-
22
- /**
23
- *
24
- * @param {ArrayLike<number>|number[]|Float32Array} frustum
25
- */
26
- setFrustum(frustum) {
27
- this.frustum = frustum;
28
- }
29
-
30
- visitLeaf(node) {
31
-
32
- const degree = node.intersectFrustumDegree_array(this.frustum);
33
-
34
- if (degree !== 0) {
35
- // at least partially visible
36
- this.collector.visitLeaf(node);
37
- }
38
- }
39
-
40
- visitBinary(node) {
41
-
42
- const degree = node.intersectFrustumDegree_array(this.frustum);
43
-
44
- if (degree === 2) {
45
- //completely inside, do fast traversal
46
- traverseBinaryNodeUsingVisitor(node, this.collector);
47
- return false;
48
- }
49
-
50
- return degree === 1;
51
- }
52
- }
@@ -1,43 +0,0 @@
1
- const stack = [];
2
- let stackPointer = 0;
3
-
4
- /**
5
- *
6
- * @param {BinaryNode} root
7
- * @param {function(BinaryNode|LeafNode):*} visitor
8
- * @param {*} [thisArg]
9
- * @return {number}
10
- */
11
- export function bvh_traverse_pre_order_using_stack(root, visitor, thisArg) {
12
- let visitCount = 0;
13
-
14
- const stackOffset = stackPointer;
15
-
16
- stack[stackPointer++] = root;
17
-
18
- let n;
19
-
20
- while (stackPointer-- > stackOffset) {
21
-
22
- visitCount++;
23
-
24
- n = stack[stackPointer];
25
-
26
- visitor.call(thisArg, n);
27
-
28
- if (!n.isLeafNode) {
29
- //a binary node
30
- if (n.right !== null) {
31
- stack[stackPointer++] = n.right;
32
- }
33
- if (n.left !== null) {
34
- stack[stackPointer++] = n.left;
35
- }
36
- }
37
- }
38
-
39
- // drop stack frame
40
- stackPointer = stackOffset;
41
-
42
- return visitCount;
43
- }
@@ -1,5 +0,0 @@
1
- import {BinaryNode} from "../BinaryNode";
2
- import {Plane} from "three";
3
- import {LeafNode} from "../LeafNode";
4
-
5
- export function queryBinaryNode_ClippingPlanes(destination: LeafNode[], destinationOffset: number, root: BinaryNode, planes: Plane[]): number
@@ -1,66 +0,0 @@
1
- /**
2
- *
3
- * @type {(BinaryNode|LeafNode)[]}
4
- */
5
-
6
- const stack = [];
7
- let stackPointer = 0;
8
-
9
- /**
10
- * @template T
11
- * @param {LeafNode<T>[]} destination
12
- * @param {number} destinationOffset
13
- * @param {BinaryNode<T>} root
14
- * @param {Plane[]} planes
15
- */
16
- export function queryBinaryNode_ClippingPlanes(destination, destinationOffset, root, planes) {
17
-
18
- let n;
19
-
20
- const plane_count = planes.length;
21
-
22
- const stackOffset = stackPointer;
23
-
24
- stack[stackPointer++] = root;
25
-
26
- let i = 0;
27
-
28
- stack_loop:while (stackPointer-- > stackOffset) {
29
-
30
- n = stack[stackPointer];
31
-
32
- for (let j = 0; j < plane_count; j++) {
33
- const plane = planes[j];
34
-
35
- const planeSide = n.computePlaneSide(plane);
36
-
37
- if (planeSide < 0) {
38
-
39
- continue stack_loop;
40
- }
41
- }
42
-
43
- if (n.isBinaryNode) {
44
-
45
- if (n.right !== null) {
46
- stack[stackPointer++] = n.right;
47
- }
48
-
49
- if (n.left !== null) {
50
- stack[stackPointer++] = n.left;
51
- }
52
- } else {
53
-
54
- destination[destinationOffset + i] = n;
55
-
56
- i++;
57
- }
58
-
59
- }
60
-
61
- //drop the stack frame
62
- stackPointer = stackOffset;
63
-
64
- return i;
65
-
66
- }
@@ -1,49 +0,0 @@
1
- /**
2
- *
3
- * @type {(BinaryNode|LeafNode)[]}
4
- */
5
- const stack = [];
6
- let stackPointer = 0;
7
-
8
- /**
9
- * @template T
10
- * @param {T[]} destination
11
- * @param {number} destinationOffset
12
- * @param {BinaryNode<T>} root
13
- */
14
- export function queryBinaryNode_CollectData(destination, destinationOffset, root) {
15
- let n;
16
- let i = 0;
17
-
18
- const stackOffset = stackPointer;
19
-
20
- stack[stackPointer++] = root;
21
-
22
- while (stackPointer-- > stackOffset) {
23
-
24
- n = stack[stackPointer];
25
-
26
- if (n.isBinaryNode) {
27
-
28
- if (n.right !== null) {
29
- stack[stackPointer++] = n.right;
30
- }
31
-
32
- if (n.left !== null) {
33
- stack[stackPointer++] = n.left;
34
- }
35
-
36
- } else {
37
-
38
- destination[destinationOffset + i] = n.object;
39
-
40
- i++;
41
- }
42
-
43
- }
44
-
45
- //drop the stack frame
46
- stackPointer = stackOffset;
47
-
48
- return i;
49
- }
@@ -1,51 +0,0 @@
1
-
2
- /**
3
- *
4
- * @type {(BinaryNode|LeafNode)[]}
5
- */
6
- const stack = [];
7
- let stackPointer = 0;
8
-
9
- /**
10
- * @template T
11
- * @param {LeafNode<T>[]} destination
12
- * @param {number} destinationOffset
13
- * @param {BinaryNode<T>} root
14
- */
15
- export function queryBinaryNode_CollectLeaves(destination, destinationOffset, root){
16
- let n;
17
-
18
- const stackOffset = stackPointer;
19
-
20
- stack[stackPointer++] = root;
21
-
22
- let i = 0;
23
-
24
- while (stackPointer-- > stackOffset) {
25
-
26
- n = stack[stackPointer];
27
-
28
- if (n.isBinaryNode) {
29
-
30
- if (n.right !== null) {
31
- stack[stackPointer++] = n.right;
32
- }
33
-
34
- if (n.left !== null) {
35
- stack[stackPointer++] = n.left;
36
- }
37
-
38
- } else {
39
-
40
- destination[destinationOffset + i] = n;
41
-
42
- i++;
43
- }
44
-
45
- }
46
-
47
- //drop the stack frame
48
- stackPointer = stackOffset;
49
-
50
- return i;
51
- }