@woosh/meep-engine 2.48.22 → 2.49.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 (230) hide show
  1. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +1 -1
  2. package/editor/ecs/component/editors/three/MeshEditor.js +1 -1
  3. package/editor/tools/GridPaintTool.js +1 -1
  4. package/editor/tools/SelectionTool.js +1 -1
  5. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  6. package/editor/view/GridPickCoordinateView.js +1 -1
  7. package/editor/view/library/MeshLibraryView.js +1 -1
  8. package/package.json +1 -1
  9. package/src/core/UUID.js +2 -0
  10. package/src/core/assert.js +4 -1
  11. package/src/core/binary/32BitEncoder.js +1 -1
  12. package/src/core/binary/ctz32.js +1 -1
  13. package/src/core/binary/operations/bitCount.spec.js +19 -0
  14. package/src/core/binary/uint82float.spec.js +7 -0
  15. package/src/core/bvh2/LeafNode.js +2 -2
  16. package/src/core/bvh2/Node.d.ts +1 -1
  17. package/src/core/bvh2/Node.js +1 -1
  18. package/src/core/bvh2/NodeValidator.js +1 -1
  19. package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +3 -0
  20. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +5 -4
  21. package/src/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
  22. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -2
  23. package/src/core/bvh2/serialization/serializeBinaryNode.js +1 -1
  24. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -2
  25. package/src/core/bvh2/transform/RotationOptimizer.spec.js +161 -155
  26. package/src/core/cache/Cache.js +4 -2
  27. package/src/core/codegen/LineBuilder.js +15 -3
  28. package/src/core/codegen/LineBuilder.spec.js +7 -0
  29. package/src/core/collection/HashMap.js +491 -236
  30. package/src/core/collection/HashMap.spec.js +110 -1
  31. package/src/core/collection/array/{typedArrayToDataType.js → typed/typedArrayToDataType.js} +1 -1
  32. package/src/core/collection/array/weightedRandomFromArray.spec.js +20 -0
  33. package/src/core/collection/heap/Uint32Heap.js +1 -0
  34. package/src/core/debug/matchers/AnyOf.js +1 -2
  35. package/src/core/events/signal/Signal.js +7 -5
  36. package/src/core/events/signal/SignalBinding.js +56 -54
  37. package/src/core/events/signal/SignalFlags.js +7 -0
  38. package/src/core/function/Functions.js +1 -1
  39. package/src/core/geom/{Rectangle.js → 2d/Rectangle.js} +5 -5
  40. package/src/core/geom/{AABB2.js → 2d/aabb/AABB2.js} +10 -78
  41. package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.js +19 -0
  42. package/src/core/geom/2d/aabb/aabb2_compute_overlap.js +42 -0
  43. package/src/core/geom/2d/aabb/aabb2_contains.js +23 -0
  44. package/src/core/geom/2d/aabb/aabb2_distance_sqr_to_point.js +25 -0
  45. package/src/core/geom/2d/aabb/aabb2_distance_to_point.js +17 -0
  46. package/src/core/geom/2d/aabb/aabb2_distance_to_point.spec.js +17 -0
  47. package/src/core/geom/2d/aabb/aabb2_overlap_exists.js +18 -0
  48. package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.js +45 -0
  49. package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.spec.js +40 -0
  50. package/src/core/geom/2d/aabb/aabb2_signed_distance_to_point.js +27 -0
  51. package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +4 -0
  52. package/src/core/geom/2d/quad-tree/PointQuadTree.js +3 -0
  53. package/src/core/geom/2d/quad-tree/QuadTreeDatum.js +1 -1
  54. package/src/core/geom/2d/quad-tree/QuadTreeNode.js +3 -3
  55. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +6 -8
  56. package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.js +3 -3
  57. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +8 -10
  58. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.d.ts +1 -1
  59. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.js +13 -13
  60. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.spec.js +1 -1
  61. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +17 -15
  62. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.spec.js +25 -0
  63. package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
  64. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +3 -0
  65. package/src/core/geom/3d/aabb/aabb3_from_v3_array.spec.js +32 -0
  66. package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.spec.js +115 -0
  67. package/src/core/geom/3d/aabb/aabb3_raycast.js +6 -1
  68. package/src/core/geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js +13 -9
  69. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Encoded_v0.js +6 -6
  70. package/src/core/geom/3d/{CircleMath.js → compute_circle_bounding_box.js} +1 -1
  71. package/src/core/geom/3d/decompose_matrix_4_array.js +18 -19
  72. package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
  73. package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/matrix}/allocate_transform_m4.js +1 -1
  74. package/src/core/geom/3d/normal/hemioct/decode_hemioct_to_unit.js +26 -0
  75. package/src/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +0 -26
  76. package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +2 -1
  77. package/src/core/geom/3d/plane/computePlaneLineIntersection.js +51 -0
  78. package/src/core/geom/3d/plane/computePlanePlaneIntersection.js +77 -0
  79. package/src/core/geom/3d/plane/computePlaneRayIntersection.js +55 -0
  80. package/src/core/geom/3d/plane/plane3_computeLineSegmentIntersection.js +50 -0
  81. package/src/core/geom/3d/plane/planeRayIntersection.js +14 -0
  82. package/src/core/geom/3d/{tetrahedra/in_sphere_fast.js → sphere/in_sphere3d_fast.js} +1 -1
  83. package/src/core/geom/3d/{tetrahedra/in_sphere_robust.js → sphere/in_sphere3d_robust.js} +1 -1
  84. package/src/core/geom/3d/sphere/sphere_array_intersects_point.js +2 -2
  85. package/src/core/geom/3d/sphere/{sphereIntersectsPoint.js → sphere_intersects_point.js} +7 -4
  86. package/src/core/geom/3d/sphere/sphere_intersects_point.spec.js +134 -0
  87. package/src/core/geom/3d/sphere/sphere_intersects_ray.spec.js +49 -0
  88. package/src/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +11 -7
  89. package/src/core/geom/3d/tetrahedra/delaunay/{debug_validate_mesh.js → debug/debug_validate_mesh.js} +1 -1
  90. package/src/core/geom/3d/tetrahedra/delaunay/{push_boundary_with_validation.js → debug/push_boundary_with_validation.js} +1 -1
  91. package/src/core/geom/3d/tetrahedra/delaunay/{validate_cavity_boundary.js → debug/validate_cavity_boundary.js} +2 -2
  92. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +2 -2
  93. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +0 -164
  94. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +87 -0
  95. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +81 -0
  96. package/src/core/geom/{GeometryMath.js → 3d/triangle/rayTriangleIntersection.js} +7 -3
  97. package/src/core/geom/ConicRay.js +160 -152
  98. package/src/core/geom/Matrix4.js +2 -0
  99. package/src/core/geom/Quaternion.js +19 -1
  100. package/src/core/geom/packing/max-rect/MaxRectangles.js +5 -215
  101. package/src/core/geom/packing/max-rect/cost/costByBestShortSide.js +11 -0
  102. package/src/core/geom/packing/max-rect/cost/costByRemainingArea.js +14 -0
  103. package/src/core/geom/packing/max-rect/cutArea.js +79 -0
  104. package/src/core/geom/packing/max-rect/findBestContainer.js +58 -0
  105. package/src/core/geom/packing/max-rect/packOneBox.js +49 -0
  106. package/src/core/geom/v3_dot.js +1 -1
  107. package/src/core/graph/GraphUtils.js +1 -1
  108. package/src/core/graph/build_face_graph_from_mesh.js +1 -3
  109. package/src/core/graph/layout/CircleLayout.js +3 -3
  110. package/src/core/graph/layout/{BoxLayouter.js → box/BoxLayouter.js} +6 -50
  111. package/src/core/graph/layout/box/applyCentralGravityAABB2.js +29 -0
  112. package/src/core/json/resolvePath.spec.js +14 -0
  113. package/src/core/land/reactive/{compiler/ReactiveCompiler.spec.js → compileReactiveExpression.spec.js} +17 -17
  114. package/src/core/math/random/MersenneTwister.spec.js +19 -0
  115. package/src/core/math/random/randomGaussian.spec.js +9 -0
  116. package/src/core/math/statistics/computeStatisticalMean.js +2 -2
  117. package/src/core/model/node-graph/visual/NodeVisualData.js +1 -1
  118. package/src/core/model/reactive/model/arithmetic/ReactiveAdd.js +1 -1
  119. package/src/core/model/reactive/model/arithmetic/ReactiveDivide.js +3 -1
  120. package/src/core/model/reactive/model/arithmetic/ReactiveMultiply.js +1 -1
  121. package/src/core/model/reactive/model/arithmetic/ReactiveNegate.js +3 -1
  122. package/src/core/model/reactive/model/arithmetic/ReactiveSubtract.js +1 -1
  123. package/src/core/model/reactive/model/comparative/ReactiveEquals.js +1 -1
  124. package/src/core/model/reactive/model/comparative/ReactiveGreaterThan.js +3 -1
  125. package/src/core/model/reactive/model/comparative/ReactiveGreaterThanOrEqual.js +3 -1
  126. package/src/core/model/reactive/model/comparative/ReactiveLessThan.js +3 -1
  127. package/src/core/model/reactive/model/comparative/ReactiveLessThanOrEqual.js +3 -1
  128. package/src/core/model/reactive/model/comparative/ReactiveNotEquals.js +1 -1
  129. package/src/core/model/reactive/model/logic/ReactiveAnd.js +1 -1
  130. package/src/core/model/reactive/model/logic/ReactiveNot.js +3 -1
  131. package/src/core/model/reactive/model/logic/ReactiveOr.js +1 -1
  132. package/src/core/primitives/numbers/computeHashFloat.spec.js +7 -0
  133. package/src/core/process/task/util/iteratorTask.js +3 -1
  134. package/src/engine/animation/curve/AnimationCurve.js +34 -5
  135. package/src/engine/animation/curve/AnimationCurve.spec.js +100 -0
  136. package/src/engine/asset/AssetTransformer.js +1 -0
  137. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  138. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +2 -2
  139. package/src/engine/asset/preloader/Preloader.js +3 -3
  140. package/src/engine/computeStridedIntegerArrayHash.js +4 -2
  141. package/src/engine/ecs/components/Renderable.d.ts +2 -2
  142. package/src/engine/ecs/components/Renderable.js +1 -1
  143. package/src/{ecs → engine/ecs}/grid/pick.js +4 -4
  144. package/src/engine/ecs/gui/position/ViewportPositionSystem.js +1 -1
  145. package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
  146. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -18
  147. package/src/engine/ecs/systems/MotionSystem.js +7 -1
  148. package/src/engine/ecs/systems/SynchronizePositionSystem.js +8 -2
  149. package/src/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
  150. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +2 -2
  151. package/src/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
  152. package/src/engine/ecs/transform/Transform.js +1 -1
  153. package/src/engine/graphics/camera/makeScreenScissorFrustum.d.ts +1 -1
  154. package/src/engine/graphics/camera/makeScreenScissorFrustum.js +3 -3
  155. package/src/engine/graphics/camera/testClippingPlaneComputation.js +13 -13
  156. package/src/engine/graphics/ecs/camera/Camera.js +1 -1
  157. package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
  158. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +1 -1
  159. package/src/engine/graphics/ecs/mesh/Mesh.js +1 -1
  160. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +1 -1
  161. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +1 -1
  162. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.d.ts +1 -1
  163. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +1 -1
  164. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +9 -0
  165. package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.d.ts +1 -1
  166. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +1 -1
  167. package/src/engine/graphics/geometry/MikkT/STSpace.js +1 -1
  168. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
  169. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +1 -1
  170. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
  171. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +1 -1
  172. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
  173. package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +1 -1
  174. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +1 -0
  175. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  176. package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +2 -2
  177. package/src/engine/graphics/render/forward_plus/debug/createScreenGrid.js +1 -1
  178. package/src/engine/graphics/render/view/CameraView.js +1 -1
  179. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -2
  180. package/src/engine/graphics/texture/atlas/AtlasPatch.js +2 -2
  181. package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +2 -2
  182. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  183. package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +1 -1
  184. package/src/engine/graphics/util/makeMeshPreviewScene.js +1 -1
  185. package/src/engine/graphics/util/renderObjectToSampler2D.js +1 -1
  186. package/src/engine/intelligence/behavior/Behavior.spec.js +15 -0
  187. package/src/engine/intelligence/mcts/MoveEdge.js +1 -1
  188. package/src/engine/reference/v1/ReferenceManager.js +3 -0
  189. package/src/engine/reference/v2/Reference.js +33 -37
  190. package/src/engine/sound/sopra/README.md +6 -0
  191. package/src/engine/ui/tiles2d/computeTileGridMove.js +3 -2
  192. package/src/engine/ui/tiles2d/computeTileGridMove.spec.js +1 -1
  193. package/src/generation/automata/CaveGeneratorCellularAutomata.js +10 -7
  194. package/src/generation/automata/CaveGeneratorCellularAutomata.spec.js +12 -0
  195. package/src/generation/automata/CellularAutomata.js +5 -4
  196. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +25 -9
  197. package/src/generation/theme/AreaMask.js +1 -1
  198. package/src/view/View.js +1 -1
  199. package/src/view/elements/progress/RectangularPieProgressView.js +1 -1
  200. package/src/view/minimap/Minimap.js +1 -1
  201. package/src/view/minimap/dom/MinimapCameraView.js +1 -1
  202. package/src/view/minimap/gl/MinimapFogOfWar.js +1 -1
  203. package/src/view/tooltip/DomTooltipObserver.js +1 -1
  204. package/src/view/tooltip/TooltipManager.js +1 -1
  205. package/src/view/tooltip/TooltipView.js +1 -1
  206. package/src/view/util/DomSizeObserver.js +2 -2
  207. package/src/core/geom/2d/AABB2Math.js +0 -40
  208. package/src/core/geom/2d/AABB2Math.spec.js +0 -17
  209. package/src/core/geom/Plane.js +0 -250
  210. package/src/core/land/reactive/ReactiveLexer.js +0 -158
  211. package/src/core/land/reactive/ReactiveLexer.ts +0 -181
  212. package/src/core/land/reactive/ReactiveListener.ts +0 -323
  213. package/src/core/land/reactive/ReactiveParser.js +0 -1573
  214. package/src/core/land/reactive/ReactiveParser.ts +0 -1776
  215. package/src/core/land/reactive/ReactiveVisitor.js +0 -1
  216. package/src/core/land/reactive/ReactiveVisitor.ts +0 -218
  217. package/src/core/land/reactive/compiler/ReactiveCompiler.js +0 -350
  218. package/src/core/land/reactive/compiler/ReactiveNearlyCompiler.js +0 -166
  219. package/src/core/land/reactive/compiler/ReactiveParser.js +0 -34
  220. package/src/core/land/reactive/nearley/ReactiveNearley.js +0 -187
  221. /package/src/core/geom/{LineSegment2.js → 2d/LineSegment2.js} +0 -0
  222. /package/src/core/geom/{Rectangle.spec.js → 2d/Rectangle.spec.js} +0 -0
  223. /package/src/core/geom/{AABB2.d.ts → 2d/aabb/AABB2.d.ts} +0 -0
  224. /package/src/core/geom/{AABB2.spec.js → 2d/aabb/AABB2.spec.js} +0 -0
  225. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3.js +0 -0
  226. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Encoded_v0.js +0 -0
  227. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Quantized16Uint.js +0 -0
  228. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3.js +0 -0
  229. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Quantized16Uint.js +0 -0
  230. /package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/vector}/allocate_v3.js +0 -0
@@ -1,4 +1,4 @@
1
- import { HashMap } from "./HashMap.js";
1
+ import { generate_next_linear_congruential_index, HashMap } from "./HashMap.js";
2
2
  import { passThrough, returnOne, strictEquals } from "../function/Functions.js";
3
3
 
4
4
  /**
@@ -16,6 +16,7 @@ function makeSample() {
16
16
  });
17
17
  }
18
18
 
19
+
19
20
  test('put and get same value', () => {
20
21
  const m = makeSample();
21
22
 
@@ -107,6 +108,44 @@ test("retrieval works as intended after hash map grows", () => {
107
108
 
108
109
  });
109
110
 
111
+ test("after deletion element is not found", () => {
112
+ const map = new HashMap({
113
+ keyHashFunction: passThrough,
114
+ keyEqualityFunction: strictEquals,
115
+ });
116
+
117
+ map.set(1, "a");
118
+
119
+ map.delete(1);
120
+
121
+ expect(map.size).toBe(0);
122
+ expect(map.get(1)).toBeUndefined();
123
+ });
124
+
125
+ test("deleting an element then inserting another one all with hash collisions", () => {
126
+ const map = new HashMap({
127
+ keyHashFunction: returnOne,
128
+ keyEqualityFunction: strictEquals,
129
+ });
130
+
131
+ map.set(1, "a");
132
+ map.set(7, "b");
133
+
134
+ map.delete(1);
135
+
136
+ expect(map.get(7)).toBe("b");
137
+ expect(map.get(1)).toBeUndefined();
138
+
139
+ map.set(13, "c");
140
+
141
+ expect(map.get(13)).toBe("c");
142
+
143
+ map.delete(13);
144
+
145
+ expect(map.get(7)).toBe("b");
146
+ expect(map.get(13)).toBeUndefined();
147
+ });
148
+
110
149
 
111
150
  test("key iterator", () => {
112
151
  const map = new HashMap({
@@ -129,3 +168,73 @@ test("value iterator", () => {
129
168
 
130
169
  expect(map.values().next().value).toBe("hello");
131
170
  });
171
+
172
+
173
+ test("clear works as expected", () => {
174
+ const map = new HashMap({
175
+ keyHashFunction: passThrough,
176
+ keyEqualityFunction: strictEquals
177
+ });
178
+
179
+ map.set(7, "hello");
180
+
181
+ map.clear();
182
+
183
+ expect(map.get(7)).toBe(undefined);
184
+ expect(map.size).toBe(0);
185
+ });
186
+
187
+ test("lcg 32", () => {
188
+ const generated = new Uint32Array(32);
189
+
190
+ let next = 0;
191
+ for (let i = 0; i < 32; i++) {
192
+
193
+ generated[i] = next;
194
+
195
+ next = generate_next_linear_congruential_index(next, 31);
196
+
197
+ }
198
+
199
+ generated.sort();
200
+
201
+ for (let i = 0; i < 32; i++) {
202
+ expect(generated[i]).toBe(i);
203
+ }
204
+ });
205
+
206
+
207
+ test.skip("performance - random fill 100,000", () => {
208
+ const map = new HashMap({
209
+ keyHashFunction: passThrough,
210
+ keyEqualityFunction: strictEquals
211
+ });
212
+
213
+ const map_warmup = new HashMap({
214
+ keyHashFunction: passThrough,
215
+ keyEqualityFunction: strictEquals
216
+ });
217
+
218
+ // warm up
219
+ for (let i = 0; i < 10000; i++) {
220
+ map_warmup.set(i, i);
221
+ map_warmup.get(i);
222
+ }
223
+
224
+ const t0 = performance.now();
225
+
226
+ for (let i = 0; i < 100000; i++) {
227
+ map.set(i, i);
228
+ }
229
+
230
+ const t1 = performance.now();
231
+
232
+ for (let i = 0; i < 100000; i++) {
233
+ map.get(i);
234
+ }
235
+
236
+ const t2 = performance.now();
237
+
238
+ console.log(`Fill: ${t1 - t0}ms`)
239
+ console.log(`Drain: ${t2 - t1}ms`)
240
+ });
@@ -1,4 +1,4 @@
1
- import { BinaryDataType } from "../../binary/type/BinaryDataType.js";
1
+ import { BinaryDataType } from "../../../binary/type/BinaryDataType.js";
2
2
 
3
3
  /**
4
4
  *
@@ -0,0 +1,20 @@
1
+ import { weightedRandomFromArray } from "./weightedRandomFromArray.js";
2
+ import { passThrough, returnOne, returnZero } from "../../function/Functions.js";
3
+
4
+ test("empty array", () => {
5
+ expect(weightedRandomFromArray([], returnZero, passThrough, null, 0))
6
+ .toBeUndefined();
7
+ });
8
+
9
+ test("single element array", () => {
10
+ expect(weightedRandomFromArray([1], returnZero, passThrough, null, 1))
11
+ .toBe(1);
12
+ });
13
+
14
+ test("two elements", () => {
15
+ expect(weightedRandomFromArray([1,3], returnZero, passThrough, null, 2))
16
+ .toBe(1);
17
+
18
+ expect(weightedRandomFromArray([1,3], returnOne, passThrough, null, 2))
19
+ .toBe(3);
20
+ });
@@ -49,6 +49,7 @@ function HEAP_RIGHT(i) {
49
49
 
50
50
  /**
51
51
  * Binary Heap implementation that stores uin32 ID along with a floating point score value
52
+ * Very fast and compact
52
53
  * Inspired by Blender's heap implementation found here: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/BLI_heap.c
53
54
  */
54
55
  export class Uint32Heap {
@@ -20,8 +20,7 @@ export class AnyOf extends BaseMatcher {
20
20
 
21
21
  matches(item, mismatch_description) {
22
22
  for (const matcher of this.#matchers) {
23
- if (!matcher.matches(item, NullDescription.INSTANCE)) {
24
-
23
+ if (matcher.matches(item, NullDescription.INSTANCE)) {
25
24
  return true;
26
25
  }
27
26
  }
@@ -41,6 +41,7 @@ export class Signal {
41
41
  * @returns {boolean}
42
42
  */
43
43
  get dispatching() {
44
+ console.warn('deprecated, use .isDispatching instead');
44
45
  return this.getFlag(SignalFlags.Dispatching);
45
46
  }
46
47
 
@@ -49,6 +50,7 @@ export class Signal {
49
50
  * @param {boolean} v
50
51
  */
51
52
  set dispatching(v) {
53
+ console.warn('deprecated, flag should not be written to from outside of the signal');
52
54
  this.writeFlag(SignalFlags.Dispatching, v);
53
55
  }
54
56
 
@@ -147,7 +149,7 @@ export class Signal {
147
149
  * @param {*} [context]
148
150
  */
149
151
  addOne(h, context) {
150
- assert.isFunction( h, "handler");
152
+ assert.isFunction(h, "handler");
151
153
 
152
154
  const handler = new SignalHandler(h, context);
153
155
 
@@ -209,12 +211,12 @@ export class Signal {
209
211
  }
210
212
 
211
213
  //mark dispatch process
212
- this.dispatching = true;
214
+ this.setFlag(SignalFlags.Dispatching);
213
215
 
214
216
  dispatchViaProxy(this.handlers, args);
215
217
 
216
218
  //mark end of dispatch process
217
- this.dispatching = false;
219
+ this.clearFlag(SignalFlags.Dispatching);
218
220
  }
219
221
 
220
222
  /**
@@ -588,11 +590,11 @@ export class Signal {
588
590
  }
589
591
 
590
592
  /**
591
- *
593
+ * @deprecated do not use
592
594
  * @returns {boolean}
593
595
  */
594
596
  isDispatching() {
595
- return this.dispatching;
597
+ return this.getFlag(SignalFlags.Dispatching);
596
598
  }
597
599
 
598
600
  /**
@@ -4,73 +4,75 @@
4
4
  */
5
5
 
6
6
 
7
- /**
8
- *
9
- * @param {Signal} signal
10
- * @param {function} handler
11
- * @param {*} [context]
12
- * @constructor
13
- */
14
- function SignalBinding(signal, handler, context) {
15
- if (typeof handler !== "function") {
16
- throw new TypeError(`handler must be a function, instead was ${handler}`);
17
- }
7
+ export class SignalBinding {
8
+ /**
9
+ *
10
+ * @param {Signal} signal
11
+ * @param {function} handler
12
+ * @param {*} [context]
13
+ * @constructor
14
+ */
15
+ constructor(signal, handler, context) {
16
+ if (typeof handler !== "function") {
17
+ throw new TypeError(`handler must be a function, instead was ${handler}`);
18
+ }
18
19
 
19
- if (typeof signal !== "object") {
20
- throw new TypeError(`signal must be of an object, instead was ${signal}`)
21
- }
20
+ if (typeof signal !== "object") {
21
+ throw new TypeError(`signal must be of an object, instead was ${signal}`)
22
+ }
22
23
 
23
- if (typeof signal.add !== "function") {
24
- throw new TypeError(`signal.add must be a function, instead was ${signal.add}`);
25
- }
24
+ if (typeof signal.add !== "function") {
25
+ throw new TypeError(`signal.add must be a function, instead was ${signal.add}`);
26
+ }
26
27
 
27
- /**
28
- * Binding signal
29
- * @type {Signal}
30
- */
31
- this.signal = signal;
28
+ /**
29
+ * Binding signal
30
+ * @type {Signal}
31
+ */
32
+ this.signal = signal;
32
33
 
33
- /**
34
- * Signal handler to be attached to the signal
35
- * @type {Function}
36
- */
37
- this.handler = handler;
34
+ /**
35
+ * Signal handler to be attached to the signal
36
+ * @type {Function}
37
+ */
38
+ this.handler = handler;
38
39
 
39
- /**
40
- *
41
- * @type {*}
42
- */
43
- this.context = context;
40
+ /**
41
+ *
42
+ * @type {*}
43
+ */
44
+ this.context = context;
45
+
46
+ /**
47
+ * State flag
48
+ * @type {boolean}
49
+ */
50
+ this.linked = false;
51
+ }
44
52
 
45
53
  /**
46
- * State flag
47
- * @type {boolean}
54
+ * Attaches handler to the signal
55
+ * Idempotent
48
56
  */
49
- this.linked = false;
50
- }
57
+ link() {
58
+ if (this.linked) {
59
+ return;
60
+ }
51
61
 
52
- /**
53
- * Attaches handler to the signal
54
- * Idempotent
55
- */
56
- SignalBinding.prototype.link = function () {
57
- if (!this.linked) {
58
62
  this.linked = true;
59
63
  this.signal.add(this.handler, this.context);
60
64
  }
61
- };
62
65
 
63
- /**
64
- * Detaches handler from the signal
65
- * Idempotent
66
- */
67
- SignalBinding.prototype.unlink = function () {
68
- if (this.linked) {
66
+ /**
67
+ * Detaches handler from the signal
68
+ * Idempotent
69
+ */
70
+ unlink() {
71
+ if (!this.linked) {
72
+ return;
73
+ }
74
+
69
75
  this.linked = false;
70
76
  this.signal.remove(this.handler, this.context);
71
77
  }
72
- };
73
-
74
- export {
75
- SignalBinding
76
- };
78
+ }
@@ -1,4 +1,11 @@
1
1
  export const SignalFlags = {
2
+ /**
3
+ * If set - signal will not invoke handlers when dispatched
4
+ */
2
5
  Silent: 1,
6
+ /**
7
+ * Is set at the start of the dispatch and cleared at the end
8
+ * @deprecated
9
+ */
3
10
  Dispatching: 2
4
11
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  /**
8
8
  * No-operation function. Does nothing. Useful when a callback is required to avoid checks for a missing function.
9
- * @param {*..} arguments
9
+ * @param {*} arguments
10
10
  */
11
11
  export function noop() {
12
12
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Created by Alex on 14/03/2016.
3
3
  */
4
- import { max2 } from "../math/max2.js";
5
- import { min2 } from "../math/min2.js";
6
- import Vector2 from "./Vector2.js";
7
- import { intersects1D } from "../math/interval/intersects1D.js";
8
- import { overlap1D } from "../math/interval/overlap1D.js";
4
+ import { max2 } from "../../math/max2.js";
5
+ import { min2 } from "../../math/min2.js";
6
+ import Vector2 from "../Vector2.js";
7
+ import { intersects1D } from "../../math/interval/intersects1D.js";
8
+ import { overlap1D } from "../../math/interval/overlap1D.js";
9
9
 
10
10
 
11
11
  class Rectangle {
@@ -4,13 +4,14 @@
4
4
  */
5
5
 
6
6
 
7
- import { assert } from "../assert.js";
8
- import { clamp } from "../math/clamp.js";
9
- import { max2 } from "../math/max2.js";
10
- import { min2 } from "../math/min2.js";
11
- import LineSegment2 from "./LineSegment2.js";
12
- import Vector2 from "./Vector2.js";
13
- import { overlap1D } from "../math/interval/overlap1D.js";
7
+ import { assert } from "../../../assert.js";
8
+ import { clamp } from "../../../math/clamp.js";
9
+ import { max2 } from "../../../math/max2.js";
10
+ import { min2 } from "../../../math/min2.js";
11
+ import LineSegment2 from "../LineSegment2.js";
12
+ import Vector2 from "../../Vector2.js";
13
+ import { aabb2_compute_overlap } from "./aabb2_compute_overlap.js";
14
+ import { aabb2_overlap_exists } from "./aabb2_overlap_exists.js";
14
15
 
15
16
  /**
16
17
  *
@@ -137,7 +138,7 @@ class AABB2 {
137
138
  const bx1 = other.x1;
138
139
  const by1 = other.y1;
139
140
 
140
- return computeOverlap(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, result);
141
+ return aabb2_compute_overlap(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, result);
141
142
  }
142
143
 
143
144
  /**
@@ -156,7 +157,7 @@ class AABB2 {
156
157
  const bx1 = other.x1;
157
158
  const by1 = other.y1;
158
159
 
159
- return aabb2_overlapExists(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1);
160
+ return aabb2_overlap_exists(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1);
160
161
  }
161
162
 
162
163
  /**
@@ -583,74 +584,5 @@ AABB2.zero = Object.freeze(new AABB2(0, 0, 0, 0));
583
584
  */
584
585
  AABB2.unit = Object.freeze(new AABB2(0, 0, 1, 1));
585
586
 
586
- /**
587
- *
588
- * @param {number} ax0
589
- * @param {number} ay0
590
- * @param {number} ax1
591
- * @param {number} ay1
592
- * @param {number} bx0
593
- * @param {number} by0
594
- * @param {number} bx1
595
- * @param {number} by1
596
- * @returns {boolean} true if overlap exists, false if no overlap
597
- */
598
- export function aabb2_overlapExists(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1) {
599
- return overlap1D(ax0, ax1, bx0, bx1)
600
- && overlap1D(ay0, ay1, by0, by1);
601
- }
602
-
603
- /**
604
- *
605
- * @param {number} bounds_x0
606
- * @param {number} bounds_y0
607
- * @param {number} bounds_x1
608
- * @param {number} bounds_y1
609
- * @param {number} x0
610
- * @param {number} y0
611
- * @param {number} x1
612
- * @param {number} y1
613
- * @return {boolean}
614
- */
615
- export function aabb2_contains(bounds_x0, bounds_y0, bounds_x1, bounds_y1, x0, y0, x1, y1) {
616
-
617
- return x0 >= bounds_x0 && x1 <= bounds_x1 && y0 >= bounds_y0 && y1 <= bounds_y1;
618
- }
619
-
620
- /**
621
- *
622
- * @param {number} ax0
623
- * @param {number} ay0
624
- * @param {number} ax1
625
- * @param {number} ay1
626
- * @param {number} bx0
627
- * @param {number} by0
628
- * @param {number} bx1
629
- * @param {number} by1
630
- * @param {AABB2} result
631
- * @returns {boolean} true if overlap exists, false if no overlap
632
- */
633
- function computeOverlap(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, result) {
634
- const x0 = max2(ax0, bx0);
635
- const x1 = min2(ax1, bx1);
636
-
637
- if (x0 >= x1) {
638
- //no overlap
639
- return false;
640
- }
641
-
642
- const y0 = max2(ay0, by0);
643
- const y1 = min2(ay1, by1);
644
-
645
- if (y0 >= y1) {
646
- //no overlap
647
- return false;
648
- }
649
-
650
- result.set(x0, y0, x1, y1);
651
-
652
- return true;
653
- }
654
-
655
587
 
656
588
  export default AABB2;
@@ -0,0 +1,19 @@
1
+ import Vector2 from "../../Vector2.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Array.<AABB2>} boxes
6
+ * @returns {Vector2}
7
+ */
8
+ export function aabb2_compute_center_from_multiple(boxes) {
9
+ const numBoxes = boxes.length;
10
+
11
+ const center = new Vector2();
12
+ for (let i = 0; i < numBoxes; i++) {
13
+ const box = boxes[i];
14
+ center._add(box.midX(), box.midY());
15
+ }
16
+ center.multiplyScalar(1 / numBoxes);
17
+
18
+ return center;
19
+ }
@@ -0,0 +1,42 @@
1
+ import { max2 } from "../../../math/max2.js";
2
+ import { min2 } from "../../../math/min2.js";
3
+
4
+ /**
5
+ *
6
+ * @param {number} ax0
7
+ * @param {number} ay0
8
+ * @param {number} ax1
9
+ * @param {number} ay1
10
+ * @param {number} bx0
11
+ * @param {number} by0
12
+ * @param {number} bx1
13
+ * @param {number} by1
14
+ * @param {AABB2} result
15
+ * @returns {boolean} true if overlap exists, false if no overlap
16
+ */
17
+ export function aabb2_compute_overlap(
18
+ ax0, ay0, ax1, ay1,
19
+ bx0, by0, bx1, by1,
20
+ result
21
+ ) {
22
+
23
+ const x0 = max2(ax0, bx0);
24
+ const x1 = min2(ax1, bx1);
25
+
26
+ if (x0 >= x1) {
27
+ //no overlap
28
+ return false;
29
+ }
30
+
31
+ const y0 = max2(ay0, by0);
32
+ const y1 = min2(ay1, by1);
33
+
34
+ if (y0 >= y1) {
35
+ //no overlap
36
+ return false;
37
+ }
38
+
39
+ result.set(x0, y0, x1, y1);
40
+
41
+ return true;
42
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * @param {number} bounds_x0
4
+ * @param {number} bounds_y0
5
+ * @param {number} bounds_x1
6
+ * @param {number} bounds_y1
7
+ * @param {number} x0
8
+ * @param {number} y0
9
+ * @param {number} x1
10
+ * @param {number} y1
11
+ * @return {boolean}
12
+ */
13
+ export function aabb2_contains(
14
+ bounds_x0, bounds_y0, bounds_x1, bounds_y1,
15
+ x0, y0, x1, y1
16
+ ) {
17
+
18
+ return x0 >= bounds_x0
19
+ && x1 <= bounds_x1
20
+ && y0 >= bounds_y0
21
+ && y1 <= bounds_y1
22
+ ;
23
+ }
@@ -0,0 +1,25 @@
1
+ import { max3 } from "../../../math/max3.js";
2
+
3
+ /**
4
+ * NOTE: The result is not a signed distance, any degree of penetration will produce 0 distance as a result
5
+ * @param {number} x0
6
+ * @param {number} y0
7
+ * @param {number} x1
8
+ * @param {number} y1
9
+ * @param {number} px
10
+ * @param {number} py
11
+ * @returns {number}
12
+ */
13
+ export function aabb2_distance_sqr_to_point(x0, y0, x1, y1, px, py) {
14
+
15
+ const dx0 = x0 - px;
16
+ const dx1 = px - x1;
17
+
18
+ const dy0 = y0 - py;
19
+ const dy1 = py - y1;
20
+
21
+ const dx = max3(0, dx0, dx1);
22
+ const dy = max3(0, dy0, dy1);
23
+
24
+ return dx * dx + dy * dy;
25
+ }
@@ -0,0 +1,17 @@
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} px
10
+ * @param {number} py
11
+ * @returns {number}
12
+ */
13
+ export function aabb2_distance_to_point(x0, y0, x1, y1, px, py) {
14
+ const sqrD = aabb2_distance_sqr_to_point(x0, y0, x1, y1, px, py);
15
+ return Math.sqrt(sqrD);
16
+ }
17
+
@@ -0,0 +1,17 @@
1
+ import { aabb2_distance_to_point } from "./aabb2_distance_to_point.js";
2
+
3
+ test('aabb2_distance_to_point', () => {
4
+ expect(aabb2_distance_to_point(0, 0, 0, 0, 0, 0)).toBeCloseTo(0);
5
+
6
+ expect(aabb2_distance_to_point(0, 0, 0, 0, 1, 0)).toBeCloseTo(1);
7
+ expect(aabb2_distance_to_point(0, 0, 0, 0, 0, 1)).toBeCloseTo(1);
8
+
9
+ expect(aabb2_distance_to_point(0, 0, 0, 0, 1, 1)).toBeCloseTo(1.41421356237);
10
+
11
+
12
+ expect(aabb2_distance_to_point(0, 0, 1, 1, 2, 0.5)).toBeCloseTo(1);
13
+ expect(aabb2_distance_to_point(0, 0, 1, 1, 0.5, 2)).toBeCloseTo(1);
14
+
15
+ expect(aabb2_distance_to_point(0, 0, 1, 1, -1, 0.5)).toBeCloseTo(1);
16
+ expect(aabb2_distance_to_point(0, 0, 1, 1, 0.5, -1)).toBeCloseTo(1);
17
+ });
@@ -0,0 +1,18 @@
1
+ import { overlap1D } from "../../../math/interval/overlap1D.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number} ax0
6
+ * @param {number} ay0
7
+ * @param {number} ax1
8
+ * @param {number} ay1
9
+ * @param {number} bx0
10
+ * @param {number} by0
11
+ * @param {number} bx1
12
+ * @param {number} by1
13
+ * @returns {boolean} true if overlap exists, false if no overlap
14
+ */
15
+ export function aabb2_overlap_exists(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1) {
16
+ return overlap1D(ax0, ax1, bx0, bx1)
17
+ && overlap1D(ay0, ay1, by0, by1);
18
+ }