@woosh/meep-engine 2.49.9 → 2.50.1

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 (170) hide show
  1. package/editor/actions/concrete/ArrayCopyAction.js +1 -1
  2. package/package.json +1 -1
  3. package/src/core/binary/BinaryBuffer.js +1 -1
  4. package/src/core/binary/BinaryBuffer.spec.js +128 -0
  5. package/src/core/binary/int32_to_binary_string.js +4 -1
  6. package/src/core/binary/int32_to_binary_string.spec.js +9 -0
  7. package/src/core/bvh2/BinaryNode.js +0 -30
  8. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
  9. package/src/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
  10. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
  11. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +1 -1
  12. package/src/core/cache/Cache.js +31 -29
  13. package/src/core/cache/Cache.spec.js +4 -1
  14. package/src/core/collection/HashMap.js +1 -1
  15. package/src/core/collection/array/{copyArray.js → array_copy.js} +1 -24
  16. package/src/core/collection/array/array_copy_entire.js +21 -0
  17. package/src/core/collection/array/typed/typed_array_copy.js +1 -1
  18. package/src/core/collection/queue/Deque.d.ts +4 -0
  19. package/src/core/collection/queue/Deque.js +5 -7
  20. package/src/core/collection/queue/Deque.spec.js +107 -0
  21. package/src/core/collection/table/RowFirstTable.js +1 -1
  22. package/src/core/geom/2d/aabb/AABB2.d.ts +14 -0
  23. package/src/core/geom/2d/aabb/AABB2.js +9 -7
  24. package/src/core/geom/2d/aabb/AABB2.spec.js +100 -0
  25. package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.spec.js +11 -0
  26. package/src/core/geom/2d/aabb/aabb2_compute_overlap.spec.js +56 -0
  27. package/src/core/geom/2d/aabb/aabb2_contains.spec.js +40 -0
  28. package/src/core/geom/2d/bvh/Node2.js +1 -1
  29. package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +1 -1
  30. package/src/core/geom/2d/convex-hull/fixed_convex_hull_relaxation.js +1 -1
  31. package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_2d.js +35 -0
  32. package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_array_2d.js +51 -0
  33. package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_vectors_2d.js +15 -0
  34. package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_vectors_array_2d.js +30 -0
  35. package/src/core/geom/2d/line/line_segment_line_segment_intersection_exists_2d.js +29 -0
  36. package/src/core/geom/3d/aabb/AABB3.d.ts +4 -0
  37. package/src/core/geom/3d/aabb/AABB3.spec.js +30 -0
  38. package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +4 -4
  39. package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +5 -5
  40. package/src/core/geom/3d/matrix/m4_make_translation.js +1 -1
  41. package/src/core/geom/3d/plane/is_point_within_planes.js +1 -1
  42. package/src/core/geom/3d/plane/lerp_planes_to_array.js +2 -0
  43. package/src/core/geom/3d/plane/{plane_computeConvex3PlaneIntersection.js → plane3_compute_convex_3_plane_intersection.js} +1 -1
  44. package/src/core/geom/3d/plane/{plane3_computeLineSegmentIntersection.js → plane3_compute_line_segment_intersection.js} +1 -1
  45. package/src/core/geom/3d/plane/{computePlanePlaneIntersection.js → plane3_compute_plane_intersection.js} +15 -11
  46. package/src/core/geom/3d/plane/{computePlaneLineIntersection.js → plane3_compute_ray_intersection.js} +5 -1
  47. package/src/core/geom/3d/plane/plane3_intersect_plane.js +14 -0
  48. package/src/core/geom/3d/plane/{plane_three_compute_convex3_plane_intersection.js → plane3_three_compute_convex_3_plane_intersection.js} +7 -4
  49. package/src/core/geom/3d/plane/planeRayIntersection.js +2 -2
  50. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +1 -1
  51. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +1 -1
  52. package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +5 -5
  53. package/src/core/geom/3d/tetrahedra/compute_circumsphere.js +1 -1
  54. package/src/core/geom/3d/tetrahedra/delaunay/fill_in_a_cavity.js +1 -1
  55. package/src/core/geom/3d/topology/bounds/computeTriangleClusterNormalBoundingCone.js +1 -1
  56. package/src/core/geom/3d/topology/expandConnectivityByLocality.js +1 -1
  57. package/src/core/geom/3d/topology/struct/binary/BinaryTopology.js +1 -1
  58. package/src/core/geom/Quaternion.d.ts +11 -0
  59. package/src/core/geom/Quaternion.js +36 -27
  60. package/src/core/geom/Quaternion.spec.js +141 -0
  61. package/src/core/geom/Vector2.d.ts +5 -1
  62. package/src/core/geom/Vector2.js +24 -0
  63. package/src/core/geom/Vector3.d.ts +6 -0
  64. package/src/core/geom/Vector3.spec.js +60 -0
  65. package/src/core/graph/GraphUtils.js +4 -2
  66. package/src/core/graph/layout/CircleLayout.js +4 -2
  67. package/src/core/math/vector_nd_dot.js +16 -0
  68. package/src/core/math/{normalizeArrayVector.js → vector_nd_normalize.js} +3 -3
  69. package/src/core/math/{normalizeArrayVector.spec.js → vector_nd_normalize.spec.js} +3 -3
  70. package/src/core/process/PromiseWatcher.spec.js +1 -1
  71. package/src/engine/animation/curve/compression/downsample_float_array_curve_by_error.js +1 -1
  72. package/src/engine/ecs/EntityBlueprint.d.ts +14 -0
  73. package/src/engine/ecs/EntityBlueprint.js +2 -2
  74. package/src/engine/ecs/EntityBlueprint.spec.js +52 -0
  75. package/src/engine/ecs/EntityBuilder.js +8 -0
  76. package/src/engine/ecs/EntityManager.d.ts +1 -0
  77. package/src/engine/ecs/EntityManager.js +17 -213
  78. package/src/engine/ecs/EntityManager.spec.js +62 -1
  79. package/src/engine/ecs/System.js +8 -2
  80. package/src/engine/ecs/fow/FogOfWar.js +1 -1
  81. package/src/engine/ecs/guid/GUID.js +1 -1
  82. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +1 -1
  83. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +1 -1
  84. package/src/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
  85. package/src/engine/ecs/transform/Transform.d.ts +2 -0
  86. package/src/engine/ecs/transform/Transform.spec.js +63 -0
  87. package/src/engine/ecs/transform-attachment/TransformAttachment.d.ts +17 -1
  88. package/src/engine/ecs/transform-attachment/TransformAttachment.js +12 -2
  89. package/src/engine/ecs/transform-attachment/TransformAttachment.spec.js +103 -0
  90. package/src/engine/graphics/ecs/camera/Camera.js +2 -2
  91. package/src/engine/graphics/ecs/path/entity/EntityPath.js +1 -1
  92. package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +1 -1
  93. package/src/engine/graphics/geometry/MikkT/GenerateTSpaces.js +1 -1
  94. package/src/engine/graphics/geometry/MikkT/m_getNormal.js +1 -1
  95. package/src/engine/graphics/geometry/MikkT/m_getTexCoord.js +1 -1
  96. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
  97. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +1 -1
  98. package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +1 -1
  99. package/src/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.js +1 -1
  100. package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +1 -1
  101. package/src/engine/graphics/render/Lines.js +1 -1
  102. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
  103. package/src/engine/graphics/render/forward_plus/LightManager.js +1 -1
  104. package/src/engine/graphics/render/forward_plus/computeFrustumCorners.js +10 -10
  105. package/src/engine/graphics/render/forward_plus/model/Decal.js +1 -1
  106. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +1 -1
  107. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +1 -1
  108. package/src/engine/graphics/render/layers/RenderLayerUtils.js +3 -3
  109. package/src/engine/graphics/render/view/CameraView.js +1 -1
  110. package/src/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +1 -1
  111. package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +1 -1
  112. package/src/engine/graphics/sh3/LightProbeVolume.js +1 -1
  113. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +1 -1
  114. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +1 -1
  115. package/src/engine/graphics/sh3/path_tracer/make_sky_hosek.js +1 -1
  116. package/src/engine/graphics/sh3/prototypeSH3Probe.js +1 -1
  117. package/src/engine/graphics/texture/3d/scs3d_read_2d_slice.js +1 -1
  118. package/src/engine/graphics/texture/CanvasClone.js +5 -1
  119. package/src/engine/graphics/texture/sampler/Sampler2D.js +14 -75
  120. package/src/engine/graphics/texture/sampler/bicubic.js +19 -19
  121. package/src/engine/graphics/texture/sampler/convertSampler2D2DataURL.spec.js +10 -0
  122. package/src/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.spec.js +90 -0
  123. package/src/engine/graphics/texture/sampler/differenceSampler.js +13 -8
  124. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_Chamfer.js +140 -0
  125. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +130 -0
  126. package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField.js +10 -0
  127. package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField.spec.js +183 -0
  128. package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField_Chamfer.js +133 -0
  129. package/src/engine/graphics/texture/sampler/filter/mitchell.js +4 -0
  130. package/src/engine/graphics/texture/sampler/loadSampler2D.js +5 -2
  131. package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +8 -3
  132. package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.spec.js +13 -0
  133. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +58 -0
  134. package/src/engine/graphics/trail/TemporalPath.js +0 -36
  135. package/src/engine/intelligence/behavior/composite/ParallelBehavior.spec.js +12 -12
  136. package/src/engine/intelligence/behavior/composite/SequenceBehavior.spec.js +17 -0
  137. package/src/engine/intelligence/behavior/primitive/SucceedingBehavior.js +3 -1
  138. package/src/engine/knowledge/database/StaticKnowledgeDataTable.d.ts +7 -1
  139. package/src/engine/knowledge/database/StaticKnowledgeDataTable.spec.js +21 -0
  140. package/src/engine/knowledge/database/StaticKnowledgeDataTableDescriptor.d.ts +2 -2
  141. package/src/engine/logging/ConsoleLoggerBackend.js +4 -0
  142. package/src/engine/logging/VoidLoggerBackend.js +12 -0
  143. package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +1 -1
  144. package/src/engine/navigation/ecs/components/computeCatmullRomSplineUniformDistance.js +1 -1
  145. package/src/engine/physics/cannon/CannonJSPhysicsSystem.js +1 -1
  146. package/src/engine/save/GameStateLoader.js +1 -1
  147. package/src/engine/scene/Scene.d.ts +2 -0
  148. package/src/engine/scene/Scene.js +2 -2
  149. package/src/engine/scene/Scene.spec.js +20 -0
  150. package/src/engine/scene/SceneManager.d.ts +4 -0
  151. package/src/engine/scene/SceneManager.js +46 -23
  152. package/src/engine/scene/SceneManager.spec.js +131 -0
  153. package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +2 -2
  154. package/src/engine/ui/GUIEngine.js +1 -1
  155. package/src/generation/grid/GridData.js +8 -2
  156. package/src/generation/grid/GridData.spec.js +5 -0
  157. package/src/generation/grid/generation/util/buildUnsignedDistanceField.js +3 -1
  158. package/src/generation/markers/MarkerNode.js +2 -2
  159. package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
  160. package/src/generation/theme/AreaMask.js +3 -1
  161. package/src/view/elements/progress/RectangularPieProgressView.js +8 -6
  162. package/src/view/minimap/dom/MinimapCameraView.js +3 -3
  163. package/src/core/geom/2d/LineSegment2.js +0 -175
  164. package/src/core/geom/3d/plane/computePlaneRayIntersection.js +0 -55
  165. package/src/core/geom/Matrix4.js +0 -275
  166. package/src/engine/graphics/texture/sampler/distanceField.js +0 -411
  167. package/src/engine/graphics/texture/sampler/distanceField.spec.js +0 -184
  168. package/src/engine/physics/cannon/cannon.min.js +0 -27
  169. package/src/generation/grid/MarkerMatchCounter.js +0 -25
  170. /package/src/engine/physics/spring/{Spring.js → computeHookeForce.js} +0 -0
@@ -8,10 +8,12 @@ import { assert } from "../../../assert.js";
8
8
  import { clamp } from "../../../math/clamp.js";
9
9
  import { max2 } from "../../../math/max2.js";
10
10
  import { min2 } from "../../../math/min2.js";
11
- import LineSegment2 from "../LineSegment2.js";
12
11
  import Vector2 from "../../Vector2.js";
13
12
  import { aabb2_compute_overlap } from "./aabb2_compute_overlap.js";
14
13
  import { aabb2_overlap_exists } from "./aabb2_overlap_exists.js";
14
+ import {
15
+ line_segment_compute_line_segment_intersection_2d
16
+ } from "../line/line_segment_compute_line_segment_intersection_2d.js";
15
17
 
16
18
  /**
17
19
  *
@@ -215,7 +217,7 @@ class AABB2 {
215
217
  }
216
218
 
217
219
  /**
218
- *
220
+ * NOTE: only 1 intersection point is produced
219
221
  * @param {Vector2} p0
220
222
  * @param {Vector2} p1
221
223
  * @param {Vector2} result
@@ -227,19 +229,19 @@ class AABB2 {
227
229
  const x1 = this.x1;
228
230
  const y1 = this.y1;
229
231
 
230
- if (LineSegment2.intersectionPointRaw(p0.x, p0.y, p1.x, p1.y, x0, y0, x1, y0, result)) {
232
+ if (line_segment_compute_line_segment_intersection_2d(p0.x, p0.y, p1.x, p1.y, x0, y0, x1, y0, result)) {
231
233
  //top
232
234
  return true;
233
235
  }
234
- if (LineSegment2.intersectionPointRaw(p0.x, p0.y, p1.x, p1.y, x0, y1, x1, y1, result)) {
236
+ if (line_segment_compute_line_segment_intersection_2d(p0.x, p0.y, p1.x, p1.y, x0, y1, x1, y1, result)) {
235
237
  //bottom
236
238
  return true;
237
239
  }
238
- if (LineSegment2.intersectionPointRaw(p0.x, p0.y, p1.x, p1.y, x0, y0, x0, y1, result)) {
240
+ if (line_segment_compute_line_segment_intersection_2d(p0.x, p0.y, p1.x, p1.y, x0, y0, x0, y1, result)) {
239
241
  //left
240
242
  return true;
241
243
  }
242
- if (LineSegment2.intersectionPointRaw(p0.x, p0.y, p1.x, p1.y, x1, y0, x1, y1, result)) {
244
+ if (line_segment_compute_line_segment_intersection_2d(p0.x, p0.y, p1.x, p1.y, x1, y0, x1, y1, result)) {
243
245
  //right
244
246
  return true;
245
247
  }
@@ -486,7 +488,7 @@ class AABB2 {
486
488
  }
487
489
 
488
490
  /**
489
- *
491
+ * Set bounds without having to maintain constraint that x0 >= x1 and y0 >= y1
490
492
  * @param {number} x0
491
493
  * @param {number} y0
492
494
  * @param {number} x1
@@ -1,4 +1,5 @@
1
1
  import AABB2 from "./AABB2.js";
2
+ import Vector2 from "../../Vector2.js";
2
3
 
3
4
  test('copy', () => {
4
5
  const a = new AABB2(1, 2, 5, 11);
@@ -51,3 +52,102 @@ test('equals', () => {
51
52
  expect(a.equals(e)).toBe(false);
52
53
  expect(a.equals(f)).toBe(false);
53
54
  });
55
+
56
+ test("lineIntersectionPoint", () => {
57
+ const aabb = new AABB2(1, 1, 2, 2);
58
+
59
+ const result = new Vector2();
60
+
61
+ expect(aabb.lineIntersectionPoint(new Vector2(0, 0), new Vector2(-1, -1), result)).toBe(false);
62
+
63
+ expect(aabb.lineIntersectionPoint(new Vector2(0, 1.5), new Vector2(3, 1.5), result)).toBe(true);
64
+ });
65
+
66
+ /**
67
+ *
68
+ * @param {AABB2} aabb
69
+ * @param {number} x0
70
+ * @param {number} y0
71
+ * @param {number} x1
72
+ * @param {number} y1
73
+ */
74
+ function expect_aabb_equals(aabb, x0, y0, x1, y1) {
75
+ expect(aabb.x0).toEqual(x0);
76
+ expect(aabb.y0).toEqual(y0);
77
+ expect(aabb.x1).toEqual(x1);
78
+ expect(aabb.y1).toEqual(y1);
79
+ }
80
+
81
+ test("setBoundsUnordered", () => {
82
+
83
+ const aabb = new AABB2();
84
+
85
+ aabb.setBoundsUnordered(2, 3, -5, -7);
86
+
87
+ expect_aabb_equals(aabb, -5, -7, 2, 3);
88
+
89
+ aabb.setBoundsUnordered(-5, -7, 2, 3);
90
+
91
+ expect_aabb_equals(aabb, -5, -7, 2, 3);
92
+
93
+ aabb.setBoundsUnordered(-5, 3, 2, -7);
94
+
95
+ expect_aabb_equals(aabb, -5, -7, 2, 3);
96
+
97
+ aabb.setBoundsUnordered(2, -7, -5, 3);
98
+
99
+ expect_aabb_equals(aabb, -5, -7, 2, 3);
100
+ });
101
+
102
+ test("toJSON", () => {
103
+
104
+ const aabb = new AABB2(1, 3, 5, 7);
105
+
106
+ expect(aabb.toJSON()).toEqual({
107
+ x0: 1,
108
+ y0: 3,
109
+ x1: 5,
110
+ y1: 7
111
+ });
112
+
113
+ });
114
+
115
+ test("fromJSON", () => {
116
+
117
+ const aabb = new AABB2();
118
+
119
+ aabb.fromJSON({
120
+ x0: 1,
121
+ y0: 3,
122
+ x1: 5,
123
+ y1: 7
124
+ });
125
+
126
+ expect_aabb_equals(aabb, 1, 3, 5, 7);
127
+ });
128
+
129
+ test("_expandToFitPoint", () => {
130
+
131
+ const aabb = new AABB2();
132
+
133
+ aabb._expandToFitPoint(0, 0);
134
+
135
+ expect_aabb_equals(aabb, 0, 0, 0, 0);
136
+
137
+ aabb._expandToFitPoint(-1, 0);
138
+
139
+ expect_aabb_equals(aabb, -1, 0, 0, 0);
140
+
141
+ aabb._expandToFitPoint(0, -1);
142
+
143
+ expect_aabb_equals(aabb, -1, -1, 0, 0);
144
+
145
+ aabb._expandToFitPoint(3, 5);
146
+
147
+ expect_aabb_equals(aabb, -1, -1, 3, 5);
148
+
149
+ aabb._expandToFitPoint(7, 0);
150
+
151
+ expect_aabb_equals(aabb, -1, -1, 7, 5);
152
+
153
+ });
@@ -0,0 +1,11 @@
1
+ import { aabb2_compute_center_from_multiple } from "./aabb2_compute_center_from_multiple.js";
2
+ import AABB2 from "./AABB2.js";
3
+ import Vector2 from "../../Vector2.js";
4
+
5
+ test("single box", () => {
6
+ const center = aabb2_compute_center_from_multiple([
7
+ new AABB2(-1, -3, 0, -2)
8
+ ]);
9
+
10
+ expect(center.roughlyEquals(new Vector2(-0.5, -2.5))).toBe(true);
11
+ });
@@ -0,0 +1,56 @@
1
+ import { aabb2_compute_overlap } from "./aabb2_compute_overlap.js";
2
+ import AABB2 from "./AABB2.js";
3
+
4
+ test("no overlap", () => {
5
+
6
+ const aabb = new AABB2();
7
+
8
+ expect(aabb2_compute_overlap(
9
+ -1, -1, -1, -1,
10
+ 1, 1, 1, 1,
11
+ aabb
12
+ )).toBe(false);
13
+
14
+ expect(aabb2_compute_overlap(
15
+ 0, 0, 0, 0,
16
+ -1, 1, 1, 1,
17
+ aabb
18
+ )).toBe(false);
19
+
20
+ expect(aabb2_compute_overlap(
21
+ 0, 0, 0, 0,
22
+ 1, -1, 1, 1,
23
+ aabb
24
+ )).toBe(false);
25
+
26
+ expect(aabb2_compute_overlap(
27
+ -1, 1, 1, 1,
28
+ 0, 0, 0, 0,
29
+ aabb
30
+ )).toBe(false);
31
+
32
+ expect(aabb2_compute_overlap(
33
+ 1, -1, 1, 1,
34
+ 0, 0, 0, 0,
35
+ aabb
36
+ )).toBe(false);
37
+
38
+ });
39
+
40
+ test("partial complex overlap", () => {
41
+
42
+ const aabb = new AABB2();
43
+
44
+ expect(aabb2_compute_overlap(
45
+ 0, 0, 7, 3,
46
+ 5, 1, 11, 2,
47
+ aabb
48
+ )).toBe(true);
49
+
50
+ expect(aabb.toJSON()).toEqual({
51
+ x0: 5,
52
+ y0: 1,
53
+ x1: 7,
54
+ y1: 2
55
+ });
56
+ });
@@ -0,0 +1,40 @@
1
+ import { aabb2_contains } from "./aabb2_contains.js";
2
+
3
+ test("test", () => {
4
+
5
+ expect(aabb2_contains(
6
+ 0, 0, 0, 0,
7
+ -1, -1, 1, 1
8
+ )).toBe(false);
9
+
10
+ expect(aabb2_contains(
11
+ 0, 0, 0, 0,
12
+ 0, 0, 0, 0
13
+ )).toBe(true);
14
+
15
+ expect(aabb2_contains(
16
+ -1, -1, 1, 1,
17
+ 0, 0, 0, 0
18
+ )).toBe(true);
19
+
20
+ expect(aabb2_contains(
21
+ -1, -1, 1, 1,
22
+ -2, 0, 0, 0
23
+ )).toBe(false);
24
+
25
+ expect(aabb2_contains(
26
+ -1, -1, 1, 1,
27
+ 0, -2, 0, 0
28
+ )).toBe(false);
29
+
30
+ expect(aabb2_contains(
31
+ -1, -1, 1, 1,
32
+ 0, 0, 2, 0
33
+ )).toBe(false);
34
+
35
+ expect(aabb2_contains(
36
+ -1, -1, 1, 1,
37
+ 0, 0, 0, 2
38
+ )).toBe(false);
39
+
40
+ });
@@ -1,4 +1,4 @@
1
- import AABB2 from "../../AABB2.js";
1
+ import AABB2 from "../aabb/AABB2.js";
2
2
 
3
3
  export class Node2 extends AABB2 {
4
4
  constructor(x0, y0, x1, y1) {
@@ -1,6 +1,6 @@
1
1
  //
2
2
 
3
- import { array_copy } from "../../../collection/array/copyArray.js";
3
+ import { array_copy } from "../../../collection/array/array_copy.js";
4
4
  import { compute_polygon_area_2d } from "../compute_polygon_area_2d.js";
5
5
  import { intersect_ray_2d } from "../intersect_ray_2d.js";
6
6
  import { UintArrayForCount } from "../../../collection/array/typed/uint_array_for_count.js";
@@ -1,4 +1,4 @@
1
- import { array_copy } from "../../../collection/array/copyArray.js";
1
+ import { array_copy } from "../../../collection/array/array_copy.js";
2
2
  import { Uint32Heap } from "../../../collection/heap/Uint32Heap.js";
3
3
  import { intersect_ray_2d } from "../intersect_ray_2d.js";
4
4
  import { compute_triangle_area_2d } from "../compute_triangle_area_2d.js";
@@ -0,0 +1,35 @@
1
+ import {
2
+ line_segment_compute_line_segment_intersection_array_2d
3
+ } from "./line_segment_compute_line_segment_intersection_array_2d.js";
4
+
5
+ const scratch_array = new Float32Array(2);
6
+
7
+ /**
8
+ * @param {number} a0_x
9
+ * @param {number} a0_y
10
+ * @param {number} a1_x
11
+ * @param {number} a1_y
12
+ * @param {number} b0_x
13
+ * @param {number} b0_y
14
+ * @param {number} b1_x
15
+ * @param {number} b1_y
16
+ * @param {Vector2} result resulting intersection point will be stored here if intersection exists
17
+ * @returns {boolean} True if segments intersect, False otherwise
18
+ */
19
+ export function line_segment_compute_line_segment_intersection_2d(
20
+ a0_x, a0_y, a1_x, a1_y,
21
+ b0_x, b0_y, b1_x, b1_y,
22
+ result
23
+ ) {
24
+ const collision = line_segment_compute_line_segment_intersection_array_2d(
25
+ scratch_array, 0,
26
+ a0_x, a0_y, a1_x, a1_y,
27
+ b0_x, b0_y, b1_x, b1_y,
28
+ );
29
+
30
+ if (collision) {
31
+ result.readFromArray(scratch_array);
32
+ }
33
+
34
+ return collision;
35
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ *
3
+ * Find intersection point between two line segments if they intersect at all
4
+ * Adapted from answer by iMalc from stackoverflow.com "how do you detect where two line segments intersect"
5
+ * @link https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
6
+ *
7
+ * @param {number[]|Float32Array|Float64Array} result resulting intersection point will be stored here if intersection exists
8
+ * @param {number} result_offset
9
+ * @param {number} a0_x
10
+ * @param {number} a0_y
11
+ * @param {number} a1_x
12
+ * @param {number} a1_y
13
+ * @param {number} b0_x
14
+ * @param {number} b0_y
15
+ * @param {number} b1_x
16
+ * @param {number} b1_y
17
+ * @return {boolean} True if segments intersect, False otherwise
18
+ */
19
+ export function line_segment_compute_line_segment_intersection_array_2d(
20
+ result, result_offset,
21
+ a0_x, a0_y, a1_x, a1_y,
22
+ b0_x, b0_y, b1_x, b1_y
23
+ ) {
24
+
25
+ const s1_x = a1_x - a0_x;
26
+ const s1_y = a1_y - a0_y;
27
+ const s2_x = b1_x - b0_x;
28
+ const s2_y = b1_y - b0_y;
29
+
30
+ const dy_02 = a0_y - b0_y;
31
+ const dx_02 = a0_x - b0_x;
32
+
33
+ const inv_denom = 1 / (-s2_x * s1_y + s1_x * s2_y);
34
+
35
+ const s = (-s1_y * dx_02 + s1_x * dy_02) * inv_denom;
36
+ const t = (s2_x * dy_02 - s2_y * dx_02) * inv_denom;
37
+
38
+ if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
39
+ // Collision detected
40
+
41
+ const intercept_x = a0_x + (t * s1_x);
42
+ const intercept_y = a0_y + (t * s1_y);
43
+
44
+ result[result_offset] = intercept_x;
45
+ result[result_offset + 1] = intercept_y;
46
+
47
+ return true;
48
+ }
49
+
50
+ return false; // No collision
51
+ }
@@ -0,0 +1,15 @@
1
+ import {
2
+ line_segment_compute_line_segment_intersection_2d
3
+ } from "./line_segment_compute_line_segment_intersection_2d.js";
4
+
5
+ /**
6
+ * @param {Vector2} a0 start of first segment
7
+ * @param {Vector2} a1 end of first segment
8
+ * @param {Vector2} b0 start of second segment
9
+ * @param {Vector2} b1 end of second segment
10
+ * @param {Vector2} result resulting intersection point will be stored here if intersection exists
11
+ * @returns {boolean} True if segments intersect, False otherwise
12
+ */
13
+ export function line_segment_compute_line_segment_intersection_vectors_2d(a0, a1, b0, b1, result) {
14
+ return line_segment_compute_line_segment_intersection_2d(a0.x, a0.y, a1.x, a1.y, b0.x, b0.y, b1.x, b1.y, result);
15
+ }
@@ -0,0 +1,30 @@
1
+ import {
2
+ line_segment_compute_line_segment_intersection_array_2d
3
+ } from "./line_segment_compute_line_segment_intersection_array_2d.js";
4
+
5
+ /**
6
+ * @param {Vector2} p0
7
+ * @param {Vector2} p1
8
+ * @param {Vector2} p2
9
+ * @param {Vector2} p3
10
+ * @returns {[number,number]}
11
+ */
12
+ export function line_segment_compute_line_segment_intersection_vectors_array_2d(p0, p1, p2, p3) {
13
+ const p0_x = p0.x;
14
+ const p0_y = p0.y;
15
+ const p1_x = p1.x;
16
+ const p1_y = p1.y;
17
+ const p2_x = p2.x;
18
+ const p2_y = p2.y;
19
+ const p3_x = p3.x;
20
+ const p3_y = p3.y;
21
+
22
+ const result = [];
23
+
24
+ if (line_segment_compute_line_segment_intersection_array_2d(result, 0, p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y)) {
25
+ return result;
26
+ } else {
27
+ return null; // No collision
28
+ }
29
+
30
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ *
3
+ * @param {number} a0_x
4
+ * @param {number} a0_y
5
+ * @param {number} a1_x
6
+ * @param {number} a1_y
7
+ * @param {number} b0_x
8
+ * @param {number} b0_y
9
+ * @param {number} b1_x
10
+ * @param {number} b1_y
11
+ * @returns {boolean} True if segments intersect, False otherwise
12
+ * @public
13
+ */
14
+ export function line_segment_line_segment_intersection_exists_2d(a0_x, a0_y, a1_x, a1_y, b0_x, b0_y, b1_x, b1_y) {
15
+ const s1_x = a1_x - a0_x;
16
+ const s1_y = a1_y - a0_y;
17
+ const s2_x = b1_x - b0_x;
18
+ const s2_y = b1_y - b0_y;
19
+
20
+ const dy_02 = a0_y - b0_y;
21
+ const dx_02 = a0_x - b0_x;
22
+
23
+ const inv_denom = 1 / (-s2_x * s1_y + s1_x * s2_y);
24
+
25
+ const s = (-s1_y * dx_02 + s1_x * dy_02) * inv_denom;
26
+ const t = (s2_x * dy_02 - s2_y * dx_02) * inv_denom;
27
+
28
+ return s >= 0 && s <= 1 && t >= 0 && t <= 1;
29
+ }
@@ -12,6 +12,8 @@ export class AABB3 {
12
12
 
13
13
  setBounds(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void
14
14
 
15
+ setBoundsUnordered(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void
16
+
15
17
  getCenter(target: Vector3): void
16
18
 
17
19
  getCenterX(): number
@@ -43,4 +45,6 @@ export class AABB3 {
43
45
  equals(other: AABB3): boolean
44
46
 
45
47
  copy(other: AABB3): void
48
+
49
+ _isBelowPlane(nx: number, ny: number, nz: number, constant: number): boolean
46
50
  }
@@ -6,6 +6,12 @@ import { serializeAABB3 } from "./serializeAABB3.js";
6
6
  import { deserializeAABB3 } from "./deserializeAABB3.js";
7
7
 
8
8
 
9
+ /**
10
+ *
11
+ * @param {AABB3} expected
12
+ * @param {AABB3} actual
13
+ * @param {number} [numDigits]
14
+ */
9
15
  function compareBounds(expected, actual, numDigits = 10) {
10
16
  expect(actual.x0).toBeCloseTo(expected.x0, numDigits);
11
17
  expect(actual.y0).toBeCloseTo(expected.y0, numDigits);
@@ -225,3 +231,27 @@ test("getExtentsZ", () => {
225
231
  expect(new AABB3(0, 0, 0, 0, 0, 1).getExtentsZ()).toBeCloseTo(1);
226
232
  expect(new AABB3(0, 0, -1, 0, 0, 1).getExtentsZ()).toBeCloseTo(2);
227
233
  });
234
+
235
+ test("setBoundsUnordered", () => {
236
+ const aabb = new AABB3();
237
+
238
+ aabb.setBoundsUnordered(1, 2, 3, -5, -7, -11);
239
+
240
+ compareBounds(aabb, new AABB3(-5, -7, -11, 1,2,3));
241
+
242
+ aabb.setBoundsUnordered(-5, -7, -11, 1, 2, 3);
243
+
244
+ compareBounds(aabb, new AABB3(-5, -7, -11, 1,2,3));
245
+
246
+ aabb.setBoundsUnordered(1, -7, -11, -5, 2, 3);
247
+
248
+ compareBounds(aabb, new AABB3(-5, -7, -11, 1,2,3));
249
+
250
+ aabb.setBoundsUnordered(-5, 2, -11, 1, -7, 3);
251
+
252
+ compareBounds(aabb, new AABB3(-5, -7, -11, 1,2,3));
253
+
254
+ aabb.setBoundsUnordered(-5, -7, 3, 1, 2, -11);
255
+
256
+ compareBounds(aabb, new AABB3(-5, -7, -11, 1,2,3));
257
+ });
@@ -2,11 +2,11 @@ import { aabb3_build_corners } from "./aabb3_build_corners.js";
2
2
  import { aabb_build_frustum } from "./aabb3_build_frustum.js";
3
3
  import { aabb3_corner_edge_mapping } from "./aabb3_corner_edge_mapping.js";
4
4
  import { aabb3_edge_corner_mapping } from "./aabb3_edge_corner_mapping.js";
5
- import { plane_computeConvex3PlaneIntersection } from "../plane/plane_computeConvex3PlaneIntersection.js";
5
+ import { plane3_compute_convex_3_plane_intersection } from "../plane/plane3_compute_convex_3_plane_intersection.js";
6
6
  import { is_point_within_planes } from "../plane/is_point_within_planes.js";
7
7
  import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
8
8
  import { EPSILON } from "../../../math/EPSILON.js";
9
- import { plane3_computeLineSegmentIntersection } from "../plane/plane3_computeLineSegmentIntersection.js";
9
+ import { plane3_compute_line_segment_intersection } from "../plane/plane3_compute_line_segment_intersection.js";
10
10
 
11
11
  /**
12
12
  * Common piece of continuous memory for better cache coherence
@@ -205,7 +205,7 @@ export function aabb3_detailed_volume_intersection(
205
205
  const nz = planes[plane_address + 2];
206
206
  const c = planes[plane_address + 3];
207
207
 
208
- const edge_intersects = plane3_computeLineSegmentIntersection(
208
+ const edge_intersects = plane3_compute_line_segment_intersection(
209
209
  scratch_v3_array, 0,
210
210
  corner_0_x, corner_0_y, corner_0_z,
211
211
  corner_1_x, corner_1_y, corner_1_z,
@@ -256,7 +256,7 @@ export function aabb3_detailed_volume_intersection(
256
256
  const next_orthogonal_plane_index = (frustum_plane_index + 2) % 4;
257
257
  const cp_1 = next_orthogonal_plane_index * 4;
258
258
 
259
- const intersection_exists = plane_computeConvex3PlaneIntersection(
259
+ const intersection_exists = plane3_compute_convex_3_plane_intersection(
260
260
  scratch_v3_array, 0,
261
261
  aabb_plane_nx, aabb_plane_ny, aabb_plane_nz, aabb_plane_constant,
262
262
  planes[cp_0], planes[cp_0 + 1], planes[cp_0 + 2], planes[cp_0 + 3],
@@ -3,9 +3,9 @@ import { plane3_projectPoint } from "../plane/plane3_projectPoint.js";
3
3
  import { ray_computeNearestPointToPoint } from "../ray/ray_computeNearestPointToPoint.js";
4
4
  import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
5
5
  import {
6
- plane_three_computeConvex3PlaneIntersection
7
- } from "../plane/plane_three_compute_convex3_plane_intersection.js";
8
- import { computePlanePlaneIntersection } from "../plane/computePlanePlaneIntersection.js";
6
+ plane3_three_compute_convex_3_plane_intersection
7
+ } from "../plane/plane3_three_compute_convex_3_plane_intersection.js";
8
+ import { plane3_compute_plane_intersection } from "../plane/plane3_compute_plane_intersection.js";
9
9
 
10
10
  /**
11
11
  *
@@ -82,7 +82,7 @@ export function frustum3_computeNearestPointToPoint(result, planes, target_x, ta
82
82
  const plane_0 = planes[plane_0_index];
83
83
  const plane_1 = planes[plane_1_index];
84
84
 
85
- const intersection_exists = computePlanePlaneIntersection(plane_0, plane_1, scratch_v3_0, scratch_v3_1);
85
+ const intersection_exists = plane3_compute_plane_intersection(plane_0, plane_1, scratch_v3_0, scratch_v3_1);
86
86
 
87
87
  if (!intersection_exists) {
88
88
  throw new Error('Planes are parallel and do not intersect, likely an invalid frustum');
@@ -103,7 +103,7 @@ export function frustum3_computeNearestPointToPoint(result, planes, target_x, ta
103
103
  const plane_1 = planes[plane_1_index];
104
104
  const plane_2 = planes[plane_2_index];
105
105
 
106
- plane_three_computeConvex3PlaneIntersection(scratch_v3_array, 0, plane_0, plane_1, plane_2);
106
+ plane3_three_compute_convex_3_plane_intersection(scratch_v3_array, 0, plane_0, plane_1, plane_2);
107
107
 
108
108
  result.readFromArray(scratch_v3_array, 0)
109
109
  }
@@ -1,4 +1,4 @@
1
- import { array_copy } from "../../../collection/array/copyArray.js";
1
+ import { array_copy } from "../../../collection/array/array_copy.js";
2
2
  import { MATRIX_4_IDENTITY } from "./MATRIX_4_IDENTITY.js";
3
3
 
4
4
  /**
@@ -2,7 +2,7 @@ import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
2
2
  import { EPSILON } from "../../../math/EPSILON.js";
3
3
 
4
4
  /**
5
- *
5
+ * Checks if point lies in a volume bound by a number of planes, such a camera frustum
6
6
  * @param {number} x
7
7
  * @param {number} y
8
8
  * @param {number} z
@@ -48,4 +48,6 @@ function lerp_planes_to_array(
48
48
  const n_z = a_normal_z * scale_0 + b_normal_z * scale_1;
49
49
 
50
50
  //compute R
51
+
52
+ throw new Error("Not Implemented");
51
53
  }
@@ -23,7 +23,7 @@ import { v3_dot } from "../../v3_dot.js";
23
23
  * @param {number} c_constant
24
24
  * @returns {boolean} true if planes intersect, false otherwise
25
25
  */
26
- export function plane_computeConvex3PlaneIntersection(
26
+ export function plane3_compute_convex_3_plane_intersection(
27
27
  result, result_offset,
28
28
  a_normal_x, a_normal_y, a_normal_z, a_constant,
29
29
  b_normal_x, b_normal_y, b_normal_z, b_constant,
@@ -16,7 +16,7 @@ import { v3_dot } from "../../v3_dot.js";
16
16
  * @param {number} dist
17
17
  * @returns {boolean}
18
18
  */
19
- export function plane3_computeLineSegmentIntersection(
19
+ export function plane3_compute_line_segment_intersection(
20
20
  result, result_offset,
21
21
  x0, y0, z0,
22
22
  x1, y1, z1,