@woosh/meep-engine 2.48.23 → 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 (142) hide show
  1. package/editor/tools/GridPaintTool.js +1 -1
  2. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  3. package/editor/view/GridPickCoordinateView.js +1 -1
  4. package/package.json +1 -1
  5. package/src/core/UUID.js +2 -0
  6. package/src/core/assert.js +4 -1
  7. package/src/core/binary/ctz32.js +1 -1
  8. package/src/core/binary/operations/bitCount.spec.js +19 -0
  9. package/src/core/binary/uint82float.spec.js +7 -0
  10. package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +3 -0
  11. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +5 -4
  12. package/src/core/bvh2/transform/RotationOptimizer.spec.js +161 -155
  13. package/src/core/codegen/LineBuilder.js +12 -3
  14. package/src/core/codegen/LineBuilder.spec.js +7 -0
  15. package/src/core/collection/HashMap.js +486 -237
  16. package/src/core/collection/HashMap.spec.js +110 -1
  17. package/src/core/collection/array/{typedArrayToDataType.js → typed/typedArrayToDataType.js} +1 -1
  18. package/src/core/collection/array/weightedRandomFromArray.spec.js +20 -0
  19. package/src/core/debug/matchers/AnyOf.js +1 -2
  20. package/src/core/geom/2d/aabb/AABB2.spec.js +1 -1
  21. package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.js +19 -0
  22. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +3 -3
  23. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +7 -9
  24. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +17 -15
  25. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.spec.js +25 -0
  26. package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
  27. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +3 -0
  28. package/src/core/geom/3d/aabb/aabb3_from_v3_array.spec.js +32 -0
  29. package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.spec.js +115 -0
  30. package/src/core/geom/3d/aabb/aabb3_raycast.js +6 -1
  31. package/src/core/geom/3d/aabb/serializeAABB3Encoded_v0.js +6 -6
  32. package/src/core/geom/3d/{CircleMath.js → compute_circle_bounding_box.js} +1 -1
  33. package/src/core/geom/3d/decompose_matrix_4_array.js +18 -19
  34. package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
  35. package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/matrix}/allocate_transform_m4.js +1 -1
  36. package/src/core/geom/3d/normal/hemioct/decode_hemioct_to_unit.js +26 -0
  37. package/src/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +0 -26
  38. package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +2 -1
  39. package/src/core/geom/3d/plane/computePlaneLineIntersection.js +51 -0
  40. package/src/core/geom/3d/plane/computePlanePlaneIntersection.js +77 -0
  41. package/src/core/geom/3d/plane/computePlaneRayIntersection.js +55 -0
  42. package/src/core/geom/3d/plane/plane3_computeLineSegmentIntersection.js +50 -0
  43. package/src/core/geom/3d/plane/planeRayIntersection.js +14 -0
  44. package/src/core/geom/3d/{tetrahedra/in_sphere_fast.js → sphere/in_sphere3d_fast.js} +1 -1
  45. package/src/core/geom/3d/{tetrahedra/in_sphere_robust.js → sphere/in_sphere3d_robust.js} +1 -1
  46. package/src/core/geom/3d/sphere/sphere_array_intersects_point.js +2 -2
  47. package/src/core/geom/3d/sphere/{sphereIntersectsPoint.js → sphere_intersects_point.js} +7 -4
  48. package/src/core/geom/3d/sphere/sphere_intersects_point.spec.js +134 -0
  49. package/src/core/geom/3d/sphere/sphere_intersects_ray.spec.js +49 -0
  50. package/src/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +11 -7
  51. package/src/core/geom/3d/tetrahedra/delaunay/{debug_validate_mesh.js → debug/debug_validate_mesh.js} +1 -1
  52. package/src/core/geom/3d/tetrahedra/delaunay/{push_boundary_with_validation.js → debug/push_boundary_with_validation.js} +1 -1
  53. package/src/core/geom/3d/tetrahedra/delaunay/{validate_cavity_boundary.js → debug/validate_cavity_boundary.js} +2 -2
  54. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +2 -2
  55. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +0 -164
  56. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +87 -0
  57. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +81 -0
  58. package/src/core/geom/{rayTriangleIntersection.js → 3d/triangle/rayTriangleIntersection.js} +2 -2
  59. package/src/core/geom/ConicRay.js +160 -152
  60. package/src/core/geom/Matrix4.js +2 -0
  61. package/src/core/geom/Quaternion.js +19 -1
  62. package/src/core/geom/packing/max-rect/MaxRectangles.js +4 -214
  63. package/src/core/geom/packing/max-rect/cost/costByBestShortSide.js +11 -0
  64. package/src/core/geom/packing/max-rect/cost/costByRemainingArea.js +14 -0
  65. package/src/core/geom/packing/max-rect/cutArea.js +79 -0
  66. package/src/core/geom/packing/max-rect/findBestContainer.js +58 -0
  67. package/src/core/geom/packing/max-rect/packOneBox.js +49 -0
  68. package/src/core/geom/v3_dot.js +1 -1
  69. package/src/core/graph/layout/CircleLayout.js +1 -1
  70. package/src/core/graph/layout/{BoxLayouter.js → box/BoxLayouter.js} +6 -50
  71. package/src/core/graph/layout/box/applyCentralGravityAABB2.js +29 -0
  72. package/src/core/json/resolvePath.spec.js +14 -0
  73. package/src/core/land/reactive/{compiler/ReactiveCompiler.spec.js → compileReactiveExpression.spec.js} +17 -17
  74. package/src/core/math/random/MersenneTwister.spec.js +19 -0
  75. package/src/core/math/random/randomGaussian.spec.js +9 -0
  76. package/src/core/math/statistics/computeStatisticalMean.js +2 -2
  77. package/src/core/model/reactive/model/arithmetic/ReactiveAdd.js +1 -1
  78. package/src/core/model/reactive/model/arithmetic/ReactiveDivide.js +3 -1
  79. package/src/core/model/reactive/model/arithmetic/ReactiveMultiply.js +1 -1
  80. package/src/core/model/reactive/model/arithmetic/ReactiveNegate.js +3 -1
  81. package/src/core/model/reactive/model/arithmetic/ReactiveSubtract.js +1 -1
  82. package/src/core/model/reactive/model/comparative/ReactiveEquals.js +1 -1
  83. package/src/core/model/reactive/model/comparative/ReactiveGreaterThan.js +3 -1
  84. package/src/core/model/reactive/model/comparative/ReactiveGreaterThanOrEqual.js +3 -1
  85. package/src/core/model/reactive/model/comparative/ReactiveLessThan.js +3 -1
  86. package/src/core/model/reactive/model/comparative/ReactiveLessThanOrEqual.js +3 -1
  87. package/src/core/model/reactive/model/comparative/ReactiveNotEquals.js +1 -1
  88. package/src/core/model/reactive/model/logic/ReactiveAnd.js +1 -1
  89. package/src/core/model/reactive/model/logic/ReactiveNot.js +3 -1
  90. package/src/core/model/reactive/model/logic/ReactiveOr.js +1 -1
  91. package/src/core/primitives/numbers/computeHashFloat.spec.js +7 -0
  92. package/src/core/process/task/util/iteratorTask.js +3 -1
  93. package/src/engine/animation/curve/AnimationCurve.js +34 -5
  94. package/src/engine/animation/curve/AnimationCurve.spec.js +100 -0
  95. package/src/engine/asset/AssetTransformer.js +1 -0
  96. package/src/engine/computeStridedIntegerArrayHash.js +4 -2
  97. package/src/engine/ecs/components/Renderable.d.ts +1 -1
  98. package/src/{ecs → engine/ecs}/grid/pick.js +4 -4
  99. package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
  100. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -18
  101. package/src/engine/ecs/systems/MotionSystem.js +7 -1
  102. package/src/engine/ecs/systems/SynchronizePositionSystem.js +8 -2
  103. package/src/engine/ecs/transform/Transform.js +1 -1
  104. package/src/engine/graphics/camera/makeScreenScissorFrustum.js +3 -3
  105. package/src/engine/graphics/camera/testClippingPlaneComputation.js +13 -13
  106. package/src/engine/graphics/ecs/camera/Camera.js +1 -1
  107. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +1 -1
  108. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +9 -0
  109. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +1 -1
  110. package/src/engine/graphics/geometry/MikkT/STSpace.js +1 -1
  111. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
  112. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
  113. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +1 -1
  114. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +1 -0
  115. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  116. package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +2 -2
  117. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -2
  118. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  119. package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +1 -1
  120. package/src/engine/intelligence/behavior/Behavior.spec.js +15 -0
  121. package/src/engine/intelligence/mcts/MoveEdge.js +1 -1
  122. package/src/engine/reference/v1/ReferenceManager.js +3 -0
  123. package/src/engine/reference/v2/Reference.js +33 -37
  124. package/src/engine/sound/sopra/README.md +6 -0
  125. package/src/generation/automata/CaveGeneratorCellularAutomata.js +10 -7
  126. package/src/generation/automata/CaveGeneratorCellularAutomata.spec.js +12 -0
  127. package/src/generation/automata/CellularAutomata.js +5 -4
  128. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +25 -9
  129. package/src/view/minimap/dom/MinimapCameraView.js +1 -1
  130. package/src/core/geom/Plane.js +0 -250
  131. package/src/core/land/reactive/ReactiveLexer.js +0 -158
  132. package/src/core/land/reactive/ReactiveLexer.ts +0 -181
  133. package/src/core/land/reactive/ReactiveListener.ts +0 -323
  134. package/src/core/land/reactive/ReactiveParser.js +0 -1573
  135. package/src/core/land/reactive/ReactiveParser.ts +0 -1776
  136. package/src/core/land/reactive/ReactiveVisitor.js +0 -1
  137. package/src/core/land/reactive/ReactiveVisitor.ts +0 -218
  138. package/src/core/land/reactive/compiler/ReactiveCompiler.js +0 -350
  139. package/src/core/land/reactive/compiler/ReactiveNearlyCompiler.js +0 -166
  140. package/src/core/land/reactive/compiler/ReactiveParser.js +0 -34
  141. package/src/core/land/reactive/nearley/ReactiveNearley.js +0 -187
  142. /package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/vector}/allocate_v3.js +0 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @see A Survey of Efficient Representations for Independent Unit Vectors (Journal of Computer Graphics Techniques Vol. 3, No. 2, 2014)
3
+ *
4
+ * Uses hemi-octahedron for sphere approximation
5
+ *
6
+ * @param {number[]} output
7
+ * @param {number} output_offset
8
+ * @param {number} x range [-1,1]
9
+ * @param {number} y range [-1,1]
10
+ */
11
+ export function decode_hemioct_to_unit(output, output_offset, x, y) {
12
+ // Rotate and scale the unit square back to the center diamond
13
+ const t_x = (x + y) * 0.5;
14
+ const t_y = (x - y) * 0.5;
15
+
16
+ //
17
+ const v_z = 1.0 - Math.abs(t_x) - Math.abs(t_y);
18
+
19
+ // normalize
20
+ const l2 = (t_x * t_x + t_y * t_y + v_z * v_z);
21
+ const m = 1 / Math.sqrt(l2);
22
+
23
+ output[output_offset] = t_x * m;
24
+ output[output_offset + 1] = t_y * m;
25
+ output[output_offset + 2] = v_z * m;
26
+ }
@@ -27,29 +27,3 @@ export function encode_unit_to_hemioct(output, output_offset, x, y, z) {
27
27
  output[output_offset + 1] = _y;
28
28
  }
29
29
 
30
- /**
31
- * @see A Survey of Efficient Representations for Independent Unit Vectors (Journal of Computer Graphics Techniques Vol. 3, No. 2, 2014)
32
- *
33
- * Uses hemi-octahedron for sphere approximation
34
- *
35
- * @param {number[]} output
36
- * @param {number} output_offset
37
- * @param {number} x range [-1,1]
38
- * @param {number} y range [-1,1]
39
- */
40
- export function decode_hemioct_to_unit(output, output_offset, x, y) {
41
- // Rotate and scale the unit square back to the center diamond
42
- const t_x = (x + y) * 0.5;
43
- const t_y = (x - y) * 0.5;
44
-
45
- //
46
- const v_z = 1.0 - Math.abs(t_x) - Math.abs(t_y);
47
-
48
- // normalize
49
- const l2 = (t_x * t_x + t_y * t_y + v_z * v_z);
50
- const m = 1 / Math.sqrt(l2);
51
-
52
- output[output_offset] = t_x * m;
53
- output[output_offset + 1] = t_y * m;
54
- output[output_offset + 2] = v_z * m;
55
- }
@@ -1,5 +1,6 @@
1
- import { decode_hemioct_to_unit, encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
1
+ import { encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
2
2
  import { v3_length } from "../../../v3_length.js";
3
+ import { decode_hemioct_to_unit } from "./decode_hemioct_to_unit.js";
3
4
 
4
5
  test('encode-decode', () => {
5
6
  const v0 = [];
@@ -0,0 +1,51 @@
1
+ import { v3_dot } from "../../v3_dot.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Vector3} out Result will be written here
6
+ * @param {number} originX Ray origin
7
+ * @param {number} originY Ray origin
8
+ * @param {number} originZ Ray origin
9
+ * @param {number} directionX Ray direction
10
+ * @param {number} directionY Ray direction
11
+ * @param {number} directionZ Ray direction
12
+ * @param {number} normalX Plane normal
13
+ * @param {number} normalY Plane normal
14
+ * @param {number} normalZ Plane normal
15
+ * @param {number} dist Plane distance
16
+ * @returns {boolean} true if intersection is found, false otherwise
17
+ */
18
+ export function computePlaneLineIntersection(out, originX, originY, originZ, directionX, directionY, directionZ, normalX, normalY, normalZ, dist) {
19
+ const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
20
+
21
+ const p = v3_dot(normalX, normalY, normalZ, originX, originY, originZ) + dist;
22
+
23
+ if (denom !== 0) {
24
+
25
+ const t = -p / denom;
26
+
27
+ out.set(
28
+ directionX * t + originX,
29
+ directionY * t + originY,
30
+ directionZ * t + originZ
31
+ );
32
+
33
+ return true;
34
+
35
+ } else {
36
+
37
+ if (p === 0) {
38
+
39
+ out.set(originX, originY, originZ);
40
+
41
+ return true;
42
+
43
+ } else {
44
+
45
+ //no intersection
46
+ return false;
47
+
48
+ }
49
+
50
+ }
51
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+
3
+ Algorithm taken from http://geomalgorithms.com/a05-_intersect-1.html. See the
4
+ section 'Intersection of 2 Planes' and specifically the subsection
5
+ (A) Direct Linear Equation
6
+ @param {Plane} p1
7
+ @param {Plane} p2
8
+ @param {Vector3} point
9
+ @param {Vector3} direction
10
+ @returns {boolean}
11
+ */
12
+ export function computePlanePlaneIntersection(p1, p2, point, direction) {
13
+
14
+ // the cross product gives us the direction of the line at the intersection
15
+ // of the two planes, and gives us an easy way to check if the two planes
16
+ // are parallel - the cross product will have zero magnitude
17
+
18
+ direction.crossVectors(p1.normal, p2.normal);
19
+
20
+ const magnitude = direction.lengthSqr();
21
+
22
+ if (magnitude === 0) {
23
+ return false;
24
+ }
25
+
26
+ // now find a point on the intersection. We use the 'Direct Linear Equation'
27
+ // method described in the linked page, and we choose which coordinate
28
+ // to set as zero by seeing which has the largest absolute value in the
29
+ // directional vector
30
+
31
+ const X = Math.abs(direction.x);
32
+ const Y = Math.abs(direction.y);
33
+ const Z = Math.abs(direction.z);
34
+
35
+ if (Z >= X && Z >= Y) {
36
+ solveIntersectingPoint('z', 'x', 'y', p1, p2, point);
37
+ } else if (Y >= Z && Y >= X) {
38
+ solveIntersectingPoint('y', 'z', 'x', p1, p2, point);
39
+ } else {
40
+ solveIntersectingPoint('x', 'y', 'z', p1, p2, point);
41
+ }
42
+
43
+ return true;
44
+ }
45
+
46
+ /**
47
+
48
+ This method helps finding a point on the intersection between two planes.
49
+ Depending on the orientation of the planes, the problem could solve for the
50
+ zero point on either the x, y or z axis
51
+ * @param {string} zeroCoord
52
+ * @param {string} A
53
+ * @param {string} B
54
+ * @param {THREE.Plane} p1
55
+ * @param {THREE.Plane} p2
56
+ * @param {Vector3} result
57
+ */
58
+ function solveIntersectingPoint(zeroCoord, A, B, p1, p2, result) {
59
+ const nP1 = p1.normal;
60
+
61
+ const a1 = nP1[A];
62
+ const b1 = nP1[B];
63
+ const d1 = p1.constant;
64
+
65
+ const nP2 = p2.normal;
66
+
67
+ const a2 = nP2[A];
68
+ const b2 = nP2[B];
69
+ const d2 = p2.constant;
70
+
71
+ const A0 = ((b2 * d1) - (b1 * d2)) / ((a1 * b2 - a2 * b1));
72
+ const B0 = ((a1 * d2) - (a2 * d1)) / ((a1 * b2 - a2 * b1));
73
+
74
+ result[zeroCoord] = 0;
75
+ result[A] = A0;
76
+ result[B] = B0;
77
+ }
@@ -0,0 +1,55 @@
1
+ import { v3_dot } from "../../v3_dot.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Vector3} out Result will be written here
6
+ * @param {number} originX Ray origin
7
+ * @param {number} originY Ray origin
8
+ * @param {number} originZ Ray origin
9
+ * @param {number} directionX Ray direction
10
+ * @param {number} directionY Ray direction
11
+ * @param {number} directionZ Ray direction
12
+ * @param {number} normalX Plane normal
13
+ * @param {number} normalY Plane normal
14
+ * @param {number} normalZ Plane normal
15
+ * @param {number} dist Plane distance
16
+ * @returns {boolean} true if intersection is found, false otherwise
17
+ */
18
+ export function computePlaneRayIntersection(out, originX, originY, originZ, directionX, directionY, directionZ, normalX, normalY, normalZ, dist) {
19
+ const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
20
+
21
+ const p = v3_dot(normalX, normalY, normalZ, originX, originY, originZ) + dist;
22
+
23
+ if (denom !== 0) {
24
+
25
+ const t = -p / denom;
26
+
27
+ if (t < 0) {
28
+ return false;
29
+ }
30
+
31
+ out.set(
32
+ directionX * t + originX,
33
+ directionY * t + originY,
34
+ directionZ * t + originZ
35
+ );
36
+
37
+ return true;
38
+
39
+ } else {
40
+
41
+ if (p === 0) {
42
+
43
+ out.set(originX, originY, originZ);
44
+
45
+ return true;
46
+
47
+ } else {
48
+
49
+ //no intersection
50
+ return false;
51
+
52
+ }
53
+
54
+ }
55
+ }
@@ -0,0 +1,50 @@
1
+ import { v3_dot } from "../../v3_dot.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Float32Array|number[]|vec3} result
6
+ * @param {number} result_offset
7
+ * @param {number} x0
8
+ * @param {number} y0
9
+ * @param {number} z0
10
+ * @param {number} x1
11
+ * @param {number} y1
12
+ * @param {number} z1
13
+ * @param {number} normalX
14
+ * @param {number} normalY
15
+ * @param {number} normalZ
16
+ * @param {number} dist
17
+ * @returns {boolean}
18
+ */
19
+ export function plane3_computeLineSegmentIntersection(
20
+ result, result_offset,
21
+ x0, y0, z0,
22
+ x1, y1, z1,
23
+ normalX, normalY, normalZ, dist
24
+ ) {
25
+
26
+ const directionX = x1 - x0;
27
+ const directionY = y1 - y0;
28
+ const directionZ = z1 - z0;
29
+
30
+ const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
31
+
32
+ if (denom === 0) {
33
+ return false;
34
+ }
35
+
36
+ const p = v3_dot(normalX, normalY, normalZ, x0, y0, z0) + dist;
37
+
38
+ const t = -p / denom;
39
+
40
+ if (t < 0 || t > 1) {
41
+ return false;
42
+ }
43
+
44
+ result[result_offset] = directionX * t + x0;
45
+ result[result_offset + 1] = directionY * t + y0;
46
+ result[result_offset + 2] = directionZ * t + z0;
47
+
48
+ return true;
49
+
50
+ }
@@ -0,0 +1,14 @@
1
+ import { computePlaneRayIntersection } from "./computePlaneRayIntersection.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Vector3} out Result will be written here
6
+ * @param {Vector3} origin Ray origin
7
+ * @param {Vector3} direction Ray direction
8
+ * @param {Vector3} normal Plane normal
9
+ * @param {number} dist Plane distance
10
+ * @returns {boolean} true if intersection is found, false otherwise
11
+ */
12
+ export function planeRayIntersection(out, origin, direction, normal, dist) {
13
+ return computePlaneRayIntersection(out, origin.x, origin.y, origin.z, direction.x, direction.y, direction.z, normal.x, normal.y, normal.z, dist)
14
+ }
@@ -19,7 +19,7 @@
19
19
  * @param {number} e reference point index that we are testing against the tetrahedron
20
20
  * @returns {number}
21
21
  */
22
- export function in_sphere_fast(
22
+ export function in_sphere3d_fast(
23
23
  points,
24
24
  a, b, c, d, e
25
25
  ) {
@@ -12,7 +12,7 @@ import { insphere } from "robust-predicates";
12
12
  * @param {number} e reference point index that we are testing against the tetrahedron
13
13
  * @returns {number}
14
14
  */
15
- export function in_sphere_robust(
15
+ export function in_sphere3d_robust(
16
16
  points,
17
17
  a, b, c, d, e
18
18
  ) {
@@ -1,4 +1,4 @@
1
- import { sphereIntersectsPoint } from "./sphereIntersectsPoint.js";
1
+ import { sphere_intersects_point } from "./sphere_intersects_point.js";
2
2
 
3
3
  //
4
4
 
@@ -11,5 +11,5 @@ import { sphereIntersectsPoint } from "./sphereIntersectsPoint.js";
11
11
  * @return {boolean}
12
12
  */
13
13
  export function sphere_array_intersects_point(sphere, x, y, z) {
14
- return sphereIntersectsPoint(sphere[0], sphere[1], sphere[2], sphere[3], x, y, z);
14
+ return sphere_intersects_point(sphere[0], sphere[1], sphere[2], sphere[3], x, y, z);
15
15
  }
@@ -4,12 +4,15 @@
4
4
  * @param {number} center_y
5
5
  * @param {number} center_z
6
6
  * @param {number} radius
7
- * @param {number} p_x
8
- * @param {number} p_y
9
- * @param {number} p_z
7
+ * @param {number} p_x reference point X coordinate
8
+ * @param {number} p_y reference point Y coordinate
9
+ * @param {number} p_z reference point Z coordinate
10
10
  * @returns {boolean}
11
11
  */
12
- export function sphereIntersectsPoint(center_x, center_y, center_z, radius, p_x, p_y, p_z) {
12
+ export function sphere_intersects_point(
13
+ center_x, center_y, center_z, radius,
14
+ p_x, p_y, p_z
15
+ ) {
13
16
 
14
17
  //compute offset vector
15
18
  const dx = center_x - p_x;
@@ -0,0 +1,134 @@
1
+ import { sphere_intersects_point } from "./sphere_intersects_point.js";
2
+
3
+ test("zero volume sphere", () => {
4
+
5
+ expect(sphere_intersects_point(
6
+ 0, 0, 0, 0,
7
+ 0, 0, 0
8
+ )).toBe(false)
9
+
10
+ expect(sphere_intersects_point(
11
+ 0, 0, 0, 0,
12
+ -1, 0, 0
13
+ )).toBe(false)
14
+
15
+ expect(sphere_intersects_point(
16
+ 0, 0, 0, 0,
17
+ 1, 0, 0
18
+ )).toBe(false)
19
+
20
+ expect(sphere_intersects_point(
21
+ 0, 0, 0, 0,
22
+ 0, -1, 0
23
+ )).toBe(false)
24
+
25
+ expect(sphere_intersects_point(
26
+ 0, 0, 0, 0,
27
+ 0, 1, 0
28
+ )).toBe(false)
29
+
30
+ expect(sphere_intersects_point(
31
+ 0, 0, 0, 0,
32
+ 0, 0, -1
33
+ )).toBe(false)
34
+
35
+ expect(sphere_intersects_point(
36
+ 0, 0, 0, 0,
37
+ 0, 0, 1
38
+ )).toBe(false)
39
+
40
+ });
41
+
42
+ test("out of bounds, centered on origin", () => {
43
+
44
+ // X
45
+ expect(sphere_intersects_point(
46
+ 0, 0, 0, 1,
47
+ -2, 0, 0
48
+ )).toBe(false)
49
+
50
+ expect(sphere_intersects_point(
51
+ 0, 0, 0, 1,
52
+ 2, 0, 0
53
+ )).toBe(false)
54
+
55
+
56
+ // Y
57
+ expect(sphere_intersects_point(
58
+ 0, 0, 0, 1,
59
+ 0, -2, 0
60
+ )).toBe(false)
61
+
62
+ expect(sphere_intersects_point(
63
+ 0, 0, 0, 1,
64
+ 0, 2, 0
65
+ )).toBe(false)
66
+
67
+ // Z
68
+ expect(sphere_intersects_point(
69
+ 0, 0, 0, 1,
70
+ 0, 0, -2
71
+ )).toBe(false)
72
+
73
+ expect(sphere_intersects_point(
74
+ 0, 0, 0, 1,
75
+ 0, 0, 2
76
+ )).toBe(false)
77
+
78
+ });
79
+
80
+ test("out of bounds with offset origin", () => {
81
+
82
+ expect(sphere_intersects_point(
83
+ 3, -5, 7, 1,
84
+ 1, -5, 7
85
+ )).toBe(false)
86
+
87
+ expect(sphere_intersects_point(
88
+ 3, -5, 7, 1,
89
+ 5, -5, 7
90
+ )).toBe(false)
91
+
92
+ });
93
+
94
+ test("in bounds", () => {
95
+
96
+ expect(sphere_intersects_point(
97
+ 0, 0, 0, 2,
98
+ 0, 0, 0
99
+ )).toBe(true)
100
+
101
+ // X
102
+ expect(sphere_intersects_point(
103
+ 0, 0, 0, 2,
104
+ -1, 0, 0
105
+ )).toBe(true)
106
+
107
+ expect(sphere_intersects_point(
108
+ 5, 5, 5, 2,
109
+ 4, 5, 5
110
+ )).toBe(true)
111
+
112
+ // Y
113
+ expect(sphere_intersects_point(
114
+ 0, 0, 0, 2,
115
+ 0, -1, 0
116
+ )).toBe(true)
117
+
118
+ expect(sphere_intersects_point(
119
+ 5, 5, 5, 2,
120
+ 5, 4, 5
121
+ )).toBe(true)
122
+
123
+ // Z
124
+ expect(sphere_intersects_point(
125
+ 0, 0, 0, 2,
126
+ 0, 0, -1
127
+ )).toBe(true)
128
+
129
+ expect(sphere_intersects_point(
130
+ 5, 5, 5, 2,
131
+ 5, 5, 4
132
+ )).toBe(true)
133
+
134
+ });
@@ -0,0 +1,49 @@
1
+ import { sphere_intersects_ray } from "./sphere_intersects_ray.js";
2
+
3
+ test("ray from -X to +X intersects sphere", () => {
4
+ expect(sphere_intersects_ray(
5
+ 0, 0, 0, 1,
6
+ -2, 0, 0,
7
+ 1, 0, 0
8
+ )).toBe(true);
9
+ });
10
+
11
+ test("ray from +X to -X intersects sphere", () => {
12
+ expect(sphere_intersects_ray(
13
+ 0, 0, 0, 1,
14
+ 2, 0, 0,
15
+ -1, 0, 0
16
+ )).toBe(true);
17
+ });
18
+
19
+ test("ray from -Y to +Y intersects sphere", () => {
20
+ expect(sphere_intersects_ray(
21
+ 0, 0, 0, 1,
22
+ 0, -2, 0,
23
+ 0, 1, 0
24
+ )).toBe(true);
25
+ });
26
+
27
+ test("ray from +Y to -Y intersects sphere", () => {
28
+ expect(sphere_intersects_ray(
29
+ 0, 0, 0, 1,
30
+ 0, 2, 0,
31
+ 0, -1, 0
32
+ )).toBe(true);
33
+ });
34
+
35
+ test("ray from -Z to +Z intersects sphere", () => {
36
+ expect(sphere_intersects_ray(
37
+ 0, 0, 0, 1,
38
+ 0, 0, -2,
39
+ 0, 0, 1
40
+ )).toBe(true);
41
+ });
42
+
43
+ test("ray from +Z to -Z intersects sphere", () => {
44
+ expect(sphere_intersects_ray(
45
+ 0, 0, 0, 1,
46
+ 0, 0, 2,
47
+ 0, 0, -1
48
+ )).toBe(true);
49
+ });
@@ -1,11 +1,15 @@
1
1
  /**
2
- *
2
+ * Compute squared radius of bonding sphere centered on 0,0,0 from a set of points and a transform matrix that is to be applied to the points prior to calculation of bounds
3
3
  * @param {number[]|ArrayLike<number>} input
4
- * @param {number} input_length
5
- * @param {ArrayLike<number>|number[]|Float32Array} e 4x4 transformation matrix
4
+ * @param {number} input_length length of the input array, foe example if there is just 1 vector in the input, length will be 3
5
+ * @param {ArrayLike<number>|number[]|Float32Array} mat4 4x4 transformation matrix
6
6
  * @returns {number}
7
7
  */
8
- export function sphere_radius_sqr_from_v3_array_transformed(input, input_length, e) {
8
+ export function sphere_radius_sqr_from_v3_array_transformed(
9
+ input,
10
+ input_length,
11
+ mat4
12
+ ) {
9
13
  let result = 0;
10
14
 
11
15
  for (let i = 0; i < input_length; i += 3) {
@@ -13,9 +17,9 @@ export function sphere_radius_sqr_from_v3_array_transformed(input, input_length,
13
17
  const y = input[i + 1];
14
18
  const z = input[i + 2];
15
19
 
16
- const _x = e[0] * x + e[4] * y + e[8] * z + e[12];
17
- const _y = e[1] * x + e[5] * y + e[9] * z + e[13];
18
- const _z = e[2] * x + e[6] * y + e[10] * z + e[14];
20
+ const _x = mat4[0] * x + mat4[4] * y + mat4[8] * z + mat4[12];
21
+ const _y = mat4[1] * x + mat4[5] * y + mat4[9] * z + mat4[13];
22
+ const _z = mat4[2] * x + mat4[6] * y + mat4[10] * z + mat4[14];
19
23
 
20
24
  const l2 = _x * _x + _y * _y + _z * _z;
21
25
 
@@ -1,4 +1,4 @@
1
- import { validate_tetrahedral_mesh } from "../validate_tetrahedral_mesh.js";
1
+ import { validate_tetrahedral_mesh } from "../../validate_tetrahedral_mesh.js";
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import { tetrahedron_compute_signed_volume } from "../tetrahedron_compute_signed_volume.js";
1
+ import { tetrahedron_compute_signed_volume } from "../../tetrahedron_compute_signed_volume.js";
2
2
 
3
3
  /**
4
4
  * Debug method that validates cavity tet before pushing it
@@ -1,5 +1,5 @@
1
- import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
2
- import { array_range_equal_strict } from "../../../../collection/array/array_range_equal_strict.js";
1
+ import { INVALID_NEIGHBOUR } from "../../TetrahedralMesh.js";
2
+ import { array_range_equal_strict } from "../../../../../collection/array/array_range_equal_strict.js";
3
3
 
4
4
  export function debug_validate_cavity_boundary(mesh, cavity) {
5
5
  let valid = true;
@@ -1,6 +1,6 @@
1
1
  import { assert } from "../../../../assert.js";
2
2
  import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
3
- import { in_sphere_robust } from "../in_sphere_robust.js";
3
+ import { in_sphere3d_robust } from "../../sphere/in_sphere3d_robust.js";
4
4
 
5
5
  /**
6
6
  *
@@ -56,7 +56,7 @@ export function tetrahedral_mesh_compute_cavity(
56
56
  continue;
57
57
  }
58
58
 
59
- if (in_sphere_robust(
59
+ if (in_sphere3d_robust(
60
60
  points,
61
61
  mesh.getVertexIndex(neighbour_index, 0),
62
62
  mesh.getVertexIndex(neighbour_index, 1),