@codexo/exojs-physics 0.19.0 → 0.20.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 (207) hide show
  1. package/README.md +8 -73
  2. package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
  3. package/debug.js +1 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +1 -0
  6. package/package.json +17 -23
  7. package/dist/esm/Aabb.d.ts +0 -10
  8. package/dist/esm/Aabb.d.ts.map +0 -1
  9. package/dist/esm/Aabb.js +0 -16
  10. package/dist/esm/Aabb.js.map +0 -1
  11. package/dist/esm/Collider.d.ts +0 -107
  12. package/dist/esm/Collider.d.ts.map +0 -1
  13. package/dist/esm/Collider.js +0 -284
  14. package/dist/esm/Collider.js.map +0 -1
  15. package/dist/esm/ContactGraph.d.ts +0 -154
  16. package/dist/esm/ContactGraph.d.ts.map +0 -1
  17. package/dist/esm/ContactGraph.js +0 -383
  18. package/dist/esm/ContactGraph.js.map +0 -1
  19. package/dist/esm/ContactModifier.d.ts +0 -62
  20. package/dist/esm/ContactModifier.d.ts.map +0 -1
  21. package/dist/esm/ContactModifier.js +0 -49
  22. package/dist/esm/ContactModifier.js.map +0 -1
  23. package/dist/esm/PhysicsBody.d.ts +0 -186
  24. package/dist/esm/PhysicsBody.d.ts.map +0 -1
  25. package/dist/esm/PhysicsBody.js +0 -526
  26. package/dist/esm/PhysicsBody.js.map +0 -1
  27. package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
  28. package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
  29. package/dist/esm/PhysicsBodyComponent.js +0 -77
  30. package/dist/esm/PhysicsBodyComponent.js.map +0 -1
  31. package/dist/esm/PhysicsWorld.d.ts +0 -567
  32. package/dist/esm/PhysicsWorld.d.ts.map +0 -1
  33. package/dist/esm/PhysicsWorld.js +0 -1096
  34. package/dist/esm/PhysicsWorld.js.map +0 -1
  35. package/dist/esm/TimeStepper.d.ts +0 -40
  36. package/dist/esm/TimeStepper.d.ts.map +0 -1
  37. package/dist/esm/TimeStepper.js +0 -59
  38. package/dist/esm/TimeStepper.js.map +0 -1
  39. package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
  40. package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
  41. package/dist/esm/backend/NativePhysicsBackend.js +0 -52
  42. package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
  43. package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
  44. package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
  45. package/dist/esm/binding/BindingRegistry.d.ts +0 -48
  46. package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
  47. package/dist/esm/binding/BindingRegistry.js +0 -81
  48. package/dist/esm/binding/BindingRegistry.js.map +0 -1
  49. package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
  50. package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
  51. package/dist/esm/binding/PhysicsBinding.js +0 -54
  52. package/dist/esm/binding/PhysicsBinding.js.map +0 -1
  53. package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
  54. package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
  55. package/dist/esm/binding/nodeWorldTransform.js +0 -41
  56. package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
  57. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
  58. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
  59. package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
  60. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
  61. package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
  62. package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
  63. package/dist/esm/broadphase/index.d.ts +0 -3
  64. package/dist/esm/broadphase/index.d.ts.map +0 -1
  65. package/dist/esm/collision/CollisionProxy.d.ts +0 -15
  66. package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
  67. package/dist/esm/collision/Manifold.d.ts +0 -34
  68. package/dist/esm/collision/Manifold.d.ts.map +0 -1
  69. package/dist/esm/collision/Manifold.js +0 -37
  70. package/dist/esm/collision/Manifold.js.map +0 -1
  71. package/dist/esm/collision/chainAdjacency.d.ts +0 -2
  72. package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
  73. package/dist/esm/collision/chainAdjacency.js +0 -44
  74. package/dist/esm/collision/chainAdjacency.js.map +0 -1
  75. package/dist/esm/collision/dispatch.d.ts +0 -35
  76. package/dist/esm/collision/dispatch.d.ts.map +0 -1
  77. package/dist/esm/collision/dispatch.js +0 -58
  78. package/dist/esm/collision/dispatch.js.map +0 -1
  79. package/dist/esm/collision/index.d.ts +0 -5
  80. package/dist/esm/collision/index.d.ts.map +0 -1
  81. package/dist/esm/collision/narrowphase.d.ts +0 -17
  82. package/dist/esm/collision/narrowphase.d.ts.map +0 -1
  83. package/dist/esm/collision/narrowphase.js +0 -555
  84. package/dist/esm/collision/narrowphase.js.map +0 -1
  85. package/dist/esm/collision/segments.d.ts +0 -19
  86. package/dist/esm/collision/segments.d.ts.map +0 -1
  87. package/dist/esm/collision/segments.js +0 -36
  88. package/dist/esm/collision/segments.js.map +0 -1
  89. package/dist/esm/collision/sweep.d.ts +0 -35
  90. package/dist/esm/collision/sweep.d.ts.map +0 -1
  91. package/dist/esm/collision/sweep.js +0 -437
  92. package/dist/esm/collision/sweep.js.map +0 -1
  93. package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
  94. package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
  95. package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
  96. package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
  97. package/dist/esm/debug/index.d.ts.map +0 -1
  98. package/dist/esm/debug/index.js +0 -3
  99. package/dist/esm/events.d.ts +0 -36
  100. package/dist/esm/events.d.ts.map +0 -1
  101. package/dist/esm/index.d.ts +0 -2
  102. package/dist/esm/index.d.ts.map +0 -1
  103. package/dist/esm/index.js +0 -25
  104. package/dist/esm/joints/DistanceJoint.d.ts +0 -70
  105. package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
  106. package/dist/esm/joints/DistanceJoint.js +0 -167
  107. package/dist/esm/joints/DistanceJoint.js.map +0 -1
  108. package/dist/esm/joints/Joint.d.ts +0 -76
  109. package/dist/esm/joints/Joint.d.ts.map +0 -1
  110. package/dist/esm/joints/Joint.js +0 -62
  111. package/dist/esm/joints/Joint.js.map +0 -1
  112. package/dist/esm/joints/MouseJoint.d.ts +0 -55
  113. package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
  114. package/dist/esm/joints/MouseJoint.js +0 -139
  115. package/dist/esm/joints/MouseJoint.js.map +0 -1
  116. package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
  117. package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
  118. package/dist/esm/joints/PrismaticJoint.js +0 -218
  119. package/dist/esm/joints/PrismaticJoint.js.map +0 -1
  120. package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
  121. package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
  122. package/dist/esm/joints/RevoluteJoint.js +0 -204
  123. package/dist/esm/joints/RevoluteJoint.js.map +0 -1
  124. package/dist/esm/joints/WeldJoint.d.ts +0 -60
  125. package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
  126. package/dist/esm/joints/WeldJoint.js +0 -166
  127. package/dist/esm/joints/WeldJoint.js.map +0 -1
  128. package/dist/esm/joints/WheelJoint.d.ts +0 -91
  129. package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
  130. package/dist/esm/joints/WheelJoint.js +0 -235
  131. package/dist/esm/joints/WheelJoint.js.map +0 -1
  132. package/dist/esm/math.d.ts +0 -29
  133. package/dist/esm/math.d.ts.map +0 -1
  134. package/dist/esm/math.js +0 -60
  135. package/dist/esm/math.js.map +0 -1
  136. package/dist/esm/physicsBuildInfo.d.ts +0 -16
  137. package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
  138. package/dist/esm/physicsBuildInfo.js +0 -10
  139. package/dist/esm/physicsBuildInfo.js.map +0 -1
  140. package/dist/esm/public.d.ts +0 -34
  141. package/dist/esm/public.d.ts.map +0 -1
  142. package/dist/esm/query/QueryEngine.d.ts +0 -95
  143. package/dist/esm/query/QueryEngine.d.ts.map +0 -1
  144. package/dist/esm/query/QueryEngine.js +0 -512
  145. package/dist/esm/query/QueryEngine.js.map +0 -1
  146. package/dist/esm/query/SpatialIndex.d.ts +0 -34
  147. package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
  148. package/dist/esm/shapes/AnyShape.d.ts +0 -14
  149. package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
  150. package/dist/esm/shapes/BoxShape.d.ts +0 -12
  151. package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
  152. package/dist/esm/shapes/BoxShape.js +0 -41
  153. package/dist/esm/shapes/BoxShape.js.map +0 -1
  154. package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
  155. package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
  156. package/dist/esm/shapes/CapsuleShape.js +0 -88
  157. package/dist/esm/shapes/CapsuleShape.js.map +0 -1
  158. package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
  159. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
  160. package/dist/esm/shapes/ChainEdgeShape.js +0 -66
  161. package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
  162. package/dist/esm/shapes/ChainShape.d.ts +0 -46
  163. package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
  164. package/dist/esm/shapes/ChainShape.js +0 -85
  165. package/dist/esm/shapes/ChainShape.js.map +0 -1
  166. package/dist/esm/shapes/CircleShape.d.ts +0 -14
  167. package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
  168. package/dist/esm/shapes/CircleShape.js +0 -31
  169. package/dist/esm/shapes/CircleShape.js.map +0 -1
  170. package/dist/esm/shapes/PolygonShape.d.ts +0 -24
  171. package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
  172. package/dist/esm/shapes/PolygonShape.js +0 -153
  173. package/dist/esm/shapes/PolygonShape.js.map +0 -1
  174. package/dist/esm/shapes/SegmentShape.d.ts +0 -31
  175. package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
  176. package/dist/esm/shapes/SegmentShape.js +0 -62
  177. package/dist/esm/shapes/SegmentShape.js.map +0 -1
  178. package/dist/esm/shapes/Shape.d.ts +0 -37
  179. package/dist/esm/shapes/Shape.d.ts.map +0 -1
  180. package/dist/esm/shapes/Shape.js +0 -15
  181. package/dist/esm/shapes/Shape.js.map +0 -1
  182. package/dist/esm/shapes/convexParts.d.ts +0 -21
  183. package/dist/esm/shapes/convexParts.d.ts.map +0 -1
  184. package/dist/esm/shapes/convexParts.js +0 -26
  185. package/dist/esm/shapes/convexParts.js.map +0 -1
  186. package/dist/esm/shapes/decompose.d.ts +0 -2
  187. package/dist/esm/shapes/decompose.d.ts.map +0 -1
  188. package/dist/esm/shapes/decompose.js +0 -272
  189. package/dist/esm/shapes/decompose.js.map +0 -1
  190. package/dist/esm/shapes/index.d.ts +0 -9
  191. package/dist/esm/shapes/index.d.ts.map +0 -1
  192. package/dist/esm/solver/ContactSolver.d.ts +0 -94
  193. package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
  194. package/dist/esm/solver/ContactSolver.js +0 -457
  195. package/dist/esm/solver/ContactSolver.js.map +0 -1
  196. package/dist/esm/solver/tolerances.d.ts +0 -2
  197. package/dist/esm/solver/tolerances.d.ts.map +0 -1
  198. package/dist/esm/solver/tolerances.js +0 -36
  199. package/dist/esm/solver/tolerances.js.map +0 -1
  200. package/dist/esm/sort.d.ts +0 -2
  201. package/dist/esm/sort.d.ts.map +0 -1
  202. package/dist/esm/sort.js +0 -44
  203. package/dist/esm/sort.js.map +0 -1
  204. package/dist/esm/types.d.ts +0 -35
  205. package/dist/esm/types.d.ts.map +0 -1
  206. package/dist/esm/types.js +0 -26
  207. package/dist/esm/types.js.map +0 -1
@@ -1,512 +0,0 @@
1
- import { aabbContainsPoint, aabbOverlap, createAabb } from "../Aabb.js";
2
- import { applyRotation, applyTransform, createTransform } from "../math.js";
3
- import { resolveFilter, shouldCollide } from "../types.js";
4
- import { authoredCollider } from "../Collider.js";
5
- import { closestPointOnSegment, pointSegmentDistanceSquared } from "../collision/segments.js";
6
- import { testOverlap } from "../collision/narrowphase.js";
7
-
8
- //#region src/query/QueryEngine.ts
9
- /** Reused sink for the closest-point primitives; queries run sequentially. */
10
- const _pointScratch = {
11
- x: 0,
12
- y: 0
13
- };
14
- /**
15
- * Spatial queries over the world's live collider set. The engine holds a
16
- * reference to the world's collider array (kept world-synchronised on every
17
- * body move), so queries always see current placements. Array-returning queries
18
- * follow the three explicit allocation forms: fresh array, caller-owned `out`,
19
- * or an allocation-free callback - never a hidden shared buffer.
20
- *
21
- * The engine scans the geometry the broad phase holds, which for a chain
22
- * collider is its per-edge proxies. Every result is reported as the authored
23
- * collider, and an overlap query reports a chain once however many of its edges
24
- * it touches. A ray still reports one hit per edge it crosses, because those are
25
- * distinct intersections.
26
- */
27
- var QueryEngine = class {
28
- _colliders;
29
- _spatialIndex;
30
- _scratchHits = [];
31
- _scratchHitsForEach = [];
32
- /** Chains already reported by the running `forEachAabbHit`, so one chain is one callback. */
33
- _scratchSeenForEach = [];
34
- _scratchAabb = createAabb();
35
- constructor(colliders, spatialIndex) {
36
- this._colliders = colliders;
37
- this._spatialIndex = spatialIndex;
38
- }
39
- /**
40
- * Colliders to scan for a query over `bounds` - the spatial index's narrowed
41
- * result if one is wired, else every live collider. `sync` is called first so
42
- * colliders added/moved since the index's last detection pass (including
43
- * before the world's very first `step()`) are still found.
44
- *
45
- * `buffer` is the scratch array the spatial index writes candidates into
46
- * (cleared and refilled in place). Callers whose per-candidate loop can
47
- * re-enter `_candidatesFor` - directly or via caller-supplied callback code -
48
- * must pass a buffer dedicated to them, so a nested call refilling its own
49
- * buffer can't truncate/corrupt an outer call's still-live iteration.
50
- */
51
- _candidatesFor(bounds, buffer) {
52
- if (this._spatialIndex === void 0) return this._colliders;
53
- this._spatialIndex.sync(this._colliders);
54
- return this._spatialIndex.queryAabb(bounds, buffer);
55
- }
56
- /** Colliders containing `point`. Allocates a fresh array. */
57
- queryPoint(point, filter) {
58
- const out = [];
59
- const resolved = filter ? resolveFilter(filter) : null;
60
- const bounds = this._scratchAabb;
61
- bounds.minX = point.x;
62
- bounds.minY = point.y;
63
- bounds.maxX = point.x;
64
- bounds.maxY = point.y;
65
- for (const collider of this._candidatesFor(bounds, this._scratchHits)) {
66
- if (resolved && !shouldCollide(resolved, collider.filter)) continue;
67
- if (pointInCollider(collider, point.x, point.y)) out.push(collider);
68
- }
69
- return out;
70
- }
71
- /** Colliders whose AABB overlaps `bounds`. Writes into `out` (cleared first) when given, else a fresh array. */
72
- queryAabb(bounds, filter, out) {
73
- const result = out ?? [];
74
- result.length = 0;
75
- const resolved = filter ? resolveFilter(filter) : null;
76
- for (const collider of this._candidatesFor(bounds, this._scratchHits)) {
77
- const authored = authoredCollider(collider);
78
- if (resolved && !shouldCollide(resolved, authored.filter)) continue;
79
- if (aabbOverlap(collider.aabb, bounds) && !alreadyReported(collider, authored, result)) result.push(authored);
80
- }
81
- return result;
82
- }
83
- /**
84
- * Invoke `callback` for each collider whose AABB overlaps `bounds`. Allocation-free.
85
- *
86
- * NOT re-entrant on itself: `callback` runs mid-traversal over a scratch
87
- * buffer dedicated to this method, so it may safely call `queryPoint`,
88
- * `queryAabb`, or `overlapShape` on this same `PhysicsWorld`/`QueryEngine`
89
- * (they use a separate buffer and never invoke caller code mid-loop). It
90
- * must NOT call `forEachAabbHit` again - directly or indirectly - on the
91
- * same instance: the nested call would refill the same shared buffer this
92
- * traversal is still iterating, silently truncating/corrupting it. This
93
- * mirrors `DynamicAabbTree.query()`'s own non-reentrancy contract.
94
- */
95
- forEachAabbHit(bounds, filter, callback) {
96
- const resolved = filter ? resolveFilter(filter) : null;
97
- const reported = this._scratchSeenForEach;
98
- reported.length = 0;
99
- for (const collider of this._candidatesFor(bounds, this._scratchHitsForEach)) {
100
- const authored = authoredCollider(collider);
101
- if (resolved && !shouldCollide(resolved, authored.filter)) continue;
102
- if (!aabbOverlap(collider.aabb, bounds) || alreadyReported(collider, authored, reported)) continue;
103
- if (collider !== authored) reported.push(authored);
104
- callback(authored);
105
- }
106
- }
107
- /** Nearest collider hit by the ray from `origin` along `direction`, or `null`. */
108
- rayCast(origin, direction, filter, maxDistance = Infinity) {
109
- const length = Math.hypot(direction.x, direction.y);
110
- if (length < 1e-9) throw new RangeError("QueryEngine.rayCast: direction must be non-zero.");
111
- const dx = direction.x / length;
112
- const dy = direction.y / length;
113
- const resolved = filter ? resolveFilter(filter) : null;
114
- let best = null;
115
- const consider = (collider) => {
116
- const authored = authoredCollider(collider);
117
- if (resolved && !shouldCollide(resolved, authored.filter)) return;
118
- const hit = rayCastCollider(collider, origin.x, origin.y, dx, dy, best ? best.distance : maxDistance);
119
- if (hit && (best === null || hit.distance < best.distance)) {
120
- hit.collider = authored;
121
- best = hit;
122
- }
123
- };
124
- if (this._spatialIndex === void 0) for (const collider of this._colliders) consider(collider);
125
- else {
126
- this._spatialIndex.sync(this._colliders);
127
- this._spatialIndex.rayCast(origin.x, origin.y, dx, dy, maxDistance, consider);
128
- }
129
- return best;
130
- }
131
- /** All collider hits along the ray, sorted by distance. Writes into `out` (cleared first) when given. */
132
- rayCastAll(origin, direction, filter, out, maxDistance = Infinity) {
133
- const length = Math.hypot(direction.x, direction.y);
134
- if (length < 1e-9) throw new RangeError("QueryEngine.rayCastAll: direction must be non-zero.");
135
- const dx = direction.x / length;
136
- const dy = direction.y / length;
137
- const resolved = filter ? resolveFilter(filter) : null;
138
- const result = out ?? [];
139
- result.length = 0;
140
- const consider = (collider) => {
141
- const authored = authoredCollider(collider);
142
- if (resolved && !shouldCollide(resolved, authored.filter)) return;
143
- const hit = rayCastCollider(collider, origin.x, origin.y, dx, dy, maxDistance);
144
- if (hit) {
145
- hit.collider = authored;
146
- result.push(hit);
147
- }
148
- };
149
- if (this._spatialIndex === void 0) for (const collider of this._colliders) consider(collider);
150
- else {
151
- this._spatialIndex.sync(this._colliders);
152
- this._spatialIndex.rayCast(origin.x, origin.y, dx, dy, maxDistance, consider);
153
- }
154
- result.sort((a, b) => a.distance - b.distance);
155
- return result;
156
- }
157
- /**
158
- * Colliders overlapping `shape` placed at `position`/`angle`. Allocates a
159
- * fresh array.
160
- *
161
- * A chain query shape is tested edge by edge, exactly as a chain collider is
162
- * solved. Two boundaries have no overlap volume, so a chain - like a segment -
163
- * never reports another chain or segment.
164
- */
165
- overlapShape(shape, position, filter, angle = 0) {
166
- const proxies = queryProxies(shape, position.x, position.y, angle);
167
- const out = [];
168
- const resolved = filter ? resolveFilter(filter) : null;
169
- const bounds = proxiesAabb(shape, proxies, this._scratchAabb);
170
- for (const collider of this._candidatesFor(bounds, this._scratchHits)) {
171
- const authored = authoredCollider(collider);
172
- if (resolved && !shouldCollide(resolved, authored.filter)) continue;
173
- if (alreadyReported(collider, authored, out)) continue;
174
- for (const proxy of proxies) if (testOverlap(proxy, collider)) {
175
- out.push(authored);
176
- break;
177
- }
178
- }
179
- return out;
180
- }
181
- };
182
- /** Read a flat vertex/normal buffer in-bounds: callers index within 0..count-1. */
183
- /** `true` when world point `(px, py)` lies inside `collider`'s shape. */
184
- const pointInCollider = (collider, px, py) => {
185
- if (!aabbContainsPoint(collider.aabb, px, py)) return false;
186
- if (collider.shape.type === "circle") {
187
- const c = collider.worldCenter;
188
- const r = collider.shape.radius;
189
- const dx = px - c.x;
190
- const dy = py - c.y;
191
- return dx * dx + dy * dy <= r * r;
192
- }
193
- if (collider.shape.type === "chain") return false;
194
- if (collider.shape.type === "segment") return false;
195
- if (collider.shape.type === "capsule") {
196
- const spine = collider.worldVertices;
197
- return pointSegmentDistanceSquared(px, py, spine[0], spine[1], spine[2], spine[3], _pointScratch) <= collider.shape.radius * collider.shape.radius;
198
- }
199
- const verts = collider.worldVertices;
200
- const normals = collider.worldNormals;
201
- const count = collider.shape.count;
202
- for (let i = 0; i < count; i++) {
203
- const nx = normals[i * 2];
204
- const ny = normals[i * 2 + 1];
205
- const vx = verts[i * 2];
206
- const vy = verts[i * 2 + 1];
207
- if (nx * (px - vx) + ny * (py - vy) > 0) return false;
208
- }
209
- return true;
210
- };
211
- /** Cast the (normalised) ray against one collider, returning the entry hit or `null`. */
212
- const rayCastCollider = (collider, ox, oy, dx, dy, maxDistance) => {
213
- switch (collider.shape.type) {
214
- case "circle": return rayCastCircle(collider, ox, oy, dx, dy, maxDistance);
215
- case "capsule": return rayCastCapsule(collider, collider.shape.radius, ox, oy, dx, dy, maxDistance);
216
- case "segment": return rayCastSegment(collider, ox, oy, dx, dy, maxDistance);
217
- case "polygon": return rayCastPolygon(collider, ox, oy, dx, dy, maxDistance);
218
- case "chain": return null;
219
- }
220
- };
221
- /**
222
- * Ray against a segment: a plain segment/segment crossing. The reported normal is
223
- * the segment's own side normal, flipped to face the incoming ray - a boundary
224
- * blocks from both sides, so which of its two normals applies is decided by where
225
- * the ray comes from.
226
- */
227
- const rayCastSegment = (collider, ox, oy, dx, dy, maxDistance) => {
228
- const ends = collider.worldVertices;
229
- const ax = ends[0];
230
- const ay = ends[1];
231
- const ex = ends[2] - ax;
232
- const ey = ends[3] - ay;
233
- const denominator = dx * ey - dy * ex;
234
- if (Math.abs(denominator) < 1e-12) return null;
235
- const rx = ax - ox;
236
- const ry = ay - oy;
237
- const distance = (rx * ey - ry * ex) / denominator;
238
- const along = (rx * dy - ry * dx) / denominator;
239
- if (distance < 0 || distance > maxDistance || along < 0 || along > 1) return null;
240
- const nx = collider.worldNormals[0];
241
- const ny = collider.worldNormals[1];
242
- const facing = nx * dx + ny * dy > 0 ? -1 : 1;
243
- return {
244
- collider,
245
- body: collider.body,
246
- point: {
247
- x: ox + dx * distance,
248
- y: oy + dy * distance
249
- },
250
- normal: {
251
- x: nx * facing,
252
- y: ny * facing
253
- },
254
- distance
255
- };
256
- };
257
- /**
258
- * Ray against a capsule: the first point along the ray whose distance to the
259
- * spine equals the radius.
260
- *
261
- * Found by scanning for the first sample inside and bisecting the bracket that
262
- * produced it, rather than by three closed-form feature tests (two caps and the
263
- * side slab). The distance-to-spine function is continuous and, approaching the
264
- * capsule from outside, monotone up to the first touch, so the bracket is valid;
265
- * a fixed 40 bisections put the result far below the engine's contact slop. The
266
- * cost is a query-path concern only - the solver never runs this.
267
- */
268
- const rayCastCapsule = (collider, radius, ox, oy, dx, dy, maxDistance) => {
269
- const spine = collider.worldVertices;
270
- const ax = spine[0];
271
- const ay = spine[1];
272
- const bx = spine[2];
273
- const by = spine[3];
274
- const radiusSquared = radius * radius;
275
- if (pointSegmentDistanceSquared(ox, oy, ax, ay, bx, by, _pointScratch) <= radiusSquared) return null;
276
- const box = collider.aabb;
277
- let near = 0;
278
- let far = maxDistance;
279
- for (let axis = 0; axis < 2; axis++) {
280
- const origin = axis === 0 ? ox : oy;
281
- const direction = axis === 0 ? dx : dy;
282
- const lo = axis === 0 ? box.minX : box.minY;
283
- const hi = axis === 0 ? box.maxX : box.maxY;
284
- if (Math.abs(direction) < 1e-12) {
285
- if (origin < lo || origin > hi) return null;
286
- continue;
287
- }
288
- const t0 = (lo - origin) / direction;
289
- const t1 = (hi - origin) / direction;
290
- near = Math.max(near, Math.min(t0, t1));
291
- far = Math.min(far, Math.max(t0, t1));
292
- }
293
- if (near > far) return null;
294
- const steps = 32;
295
- const stepLength = (far - near) / steps;
296
- let entered = -1;
297
- for (let i = 1; i <= steps; i++) {
298
- const t = near + i * stepLength;
299
- if (pointSegmentDistanceSquared(ox + dx * t, oy + dy * t, ax, ay, bx, by, _pointScratch) <= radiusSquared) {
300
- entered = t;
301
- break;
302
- }
303
- }
304
- if (entered < 0) return null;
305
- let lo = entered - stepLength;
306
- let hi = entered;
307
- for (let i = 0; i < 40; i++) {
308
- const mid = (lo + hi) / 2;
309
- if (pointSegmentDistanceSquared(ox + dx * mid, oy + dy * mid, ax, ay, bx, by, _pointScratch) <= radiusSquared) hi = mid;
310
- else lo = mid;
311
- }
312
- const hitX = ox + dx * hi;
313
- const hitY = oy + dy * hi;
314
- closestPointOnSegment(hitX, hitY, ax, ay, bx, by, _pointScratch);
315
- const nx = hitX - _pointScratch.x;
316
- const ny = hitY - _pointScratch.y;
317
- const length = Math.hypot(nx, ny) || 1;
318
- return {
319
- collider,
320
- body: collider.body,
321
- point: {
322
- x: hitX,
323
- y: hitY
324
- },
325
- normal: {
326
- x: nx / length,
327
- y: ny / length
328
- },
329
- distance: hi
330
- };
331
- };
332
- const rayCastCircle = (collider, ox, oy, dx, dy, maxDistance) => {
333
- const c = collider.worldCenter;
334
- const r = collider.shape.type === "circle" ? collider.shape.radius : 0;
335
- const mx = ox - c.x;
336
- const my = oy - c.y;
337
- const b = mx * dx + my * dy;
338
- const cc = mx * mx + my * my - r * r;
339
- if (cc > 0 && b > 0) return null;
340
- const disc = b * b - cc;
341
- if (disc < 0) return null;
342
- let t = -b - Math.sqrt(disc);
343
- if (t < 0) t = 0;
344
- if (t > maxDistance) return null;
345
- const px = ox + dx * t;
346
- const py = oy + dy * t;
347
- const nx = (px - c.x) / r;
348
- const ny = (py - c.y) / r;
349
- return {
350
- collider,
351
- body: collider.body,
352
- point: {
353
- x: px,
354
- y: py
355
- },
356
- normal: {
357
- x: nx,
358
- y: ny
359
- },
360
- distance: t
361
- };
362
- };
363
- const rayCastPolygon = (collider, ox, oy, dx, dy, maxDistance) => {
364
- const verts = collider.worldVertices;
365
- const normals = collider.worldNormals;
366
- const count = collider.shape.type === "polygon" ? collider.shape.count : 0;
367
- let tmin = 0;
368
- let tmax = maxDistance;
369
- let enterNx = 0;
370
- let enterNy = 0;
371
- let entered = false;
372
- for (let i = 0; i < count; i++) {
373
- const nx = normals[i * 2];
374
- const ny = normals[i * 2 + 1];
375
- const vx = verts[i * 2];
376
- const vy = verts[i * 2 + 1];
377
- const numerator = nx * (vx - ox) + ny * (vy - oy);
378
- const denominator = nx * dx + ny * dy;
379
- if (denominator === 0) {
380
- if (numerator < 0) return null;
381
- continue;
382
- }
383
- const t = numerator / denominator;
384
- if (denominator < 0) {
385
- if (t > tmin) {
386
- tmin = t;
387
- enterNx = nx;
388
- enterNy = ny;
389
- entered = true;
390
- }
391
- } else if (t < tmax) tmax = t;
392
- if (tmin > tmax) return null;
393
- }
394
- if (!entered || tmin < 0 || tmin > maxDistance) return null;
395
- return {
396
- collider,
397
- body: collider.body,
398
- point: {
399
- x: ox + dx * tmin,
400
- y: oy + dy * tmin
401
- },
402
- normal: {
403
- x: enterNx,
404
- y: enterNy
405
- },
406
- distance: tmin
407
- };
408
- };
409
- /**
410
- * Throwaway collision proxies for a query shape placed at `(x, y)` with `angle`:
411
- * one, or one per edge for a chain.
412
- */
413
- const queryProxies = (shape, x, y, angle) => {
414
- if (shape.type !== "chain") return [makeProxy(shape, x, y, angle)];
415
- return shape.edges.map((edge) => makeProxy(edge, x, y, angle));
416
- };
417
- /** World AABB covering every proxy of a query shape. */
418
- const proxiesAabb = (shape, proxies, out) => {
419
- if (shape.type !== "chain") return proxyAabb(shape, proxies[0], out);
420
- let minX = Infinity;
421
- let minY = Infinity;
422
- let maxX = -Infinity;
423
- let maxY = -Infinity;
424
- for (const proxy of proxies) {
425
- const edgeBounds = proxyAabb(proxy.shape, proxy, _scratchEdgeAabb);
426
- minX = edgeBounds.minX < minX ? edgeBounds.minX : minX;
427
- minY = edgeBounds.minY < minY ? edgeBounds.minY : minY;
428
- maxX = edgeBounds.maxX > maxX ? edgeBounds.maxX : maxX;
429
- maxY = edgeBounds.maxY > maxY ? edgeBounds.maxY : maxY;
430
- }
431
- out.minX = minX;
432
- out.minY = minY;
433
- out.maxX = maxX;
434
- out.maxY = maxY;
435
- return out;
436
- };
437
- /** Scratch for the per-edge bounds a chain query shape unions. */
438
- const _scratchEdgeAabb = createAabb();
439
- /**
440
- * `true` when `authored` is already in `reported`. Only a chain can be reached
441
- * twice in one query (once per edge proxy), so nothing else pays for the scan.
442
- */
443
- const alreadyReported = (candidate, authored, reported) => candidate !== authored && reported.includes(authored);
444
- /** Build a throwaway collision proxy for a shape placed at `(x, y)` with `angle`. */
445
- const makeProxy = (shape, x, y, angle) => {
446
- if (shape.type === "circle") return {
447
- shape,
448
- worldCenter: {
449
- x,
450
- y
451
- },
452
- worldVertices: [],
453
- worldNormals: []
454
- };
455
- const count = shape.type === "polygon" ? shape.count : 2;
456
- const transform = createTransform(x, y, angle);
457
- const worldVertices = [];
458
- const worldNormals = [];
459
- const out = {
460
- x: 0,
461
- y: 0
462
- };
463
- for (let i = 0; i < count; i++) {
464
- applyTransform(transform, shape.vertices[i * 2], shape.vertices[i * 2 + 1], out);
465
- worldVertices.push(out.x, out.y);
466
- applyRotation(transform, shape.normals[i * 2], shape.normals[i * 2 + 1], out);
467
- worldNormals.push(out.x, out.y);
468
- }
469
- return {
470
- shape,
471
- worldCenter: {
472
- x,
473
- y
474
- },
475
- worldVertices,
476
- worldNormals
477
- };
478
- };
479
- /** Compute the world AABB of an already-built collision proxy (reuses its cached vertices/centre - no extra transform work). */
480
- const proxyAabb = (shape, proxy, out) => {
481
- if (shape.type === "circle") {
482
- const r = shape.radius;
483
- out.minX = proxy.worldCenter.x - r;
484
- out.minY = proxy.worldCenter.y - r;
485
- out.maxX = proxy.worldCenter.x + r;
486
- out.maxY = proxy.worldCenter.y + r;
487
- return out;
488
- }
489
- const verts = proxy.worldVertices;
490
- let minX = Infinity;
491
- let minY = Infinity;
492
- let maxX = -Infinity;
493
- let maxY = -Infinity;
494
- for (let i = 0; i < verts.length; i += 2) {
495
- const x = verts[i];
496
- const y = verts[i + 1];
497
- minX = x < minX ? x : minX;
498
- minY = y < minY ? y : minY;
499
- maxX = x > maxX ? x : maxX;
500
- maxY = y > maxY ? y : maxY;
501
- }
502
- const radius = shape.type === "capsule" ? shape.radius : 0;
503
- out.minX = minX - radius;
504
- out.minY = minY - radius;
505
- out.maxX = maxX + radius;
506
- out.maxY = maxY + radius;
507
- return out;
508
- };
509
-
510
- //#endregion
511
- export { QueryEngine };
512
- //# sourceMappingURL=QueryEngine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryEngine.js","names":[],"sources":["../../../src/query/QueryEngine.ts"],"sourcesContent":["import type { AabbLike, PointLike } from '@codexo/exojs';\n\nimport { aabbContainsPoint, aabbOverlap, createAabb } from '../Aabb';\nimport type { Collider } from '../Collider';\nimport { authoredCollider } from '../Collider';\nimport type { CollisionProxy } from '../collision/CollisionProxy';\nimport { testOverlap } from '../collision/narrowphase';\nimport { closestPointOnSegment, pointSegmentDistanceSquared } from '../collision/segments';\nimport { applyRotation, applyTransform, createTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { AnyShape } from '../shapes/AnyShape';\nimport type { ChainShape } from '../shapes/ChainShape';\nimport { resolveFilter, shouldCollide } from '../types';\nimport type { SpatialIndex } from './SpatialIndex';\n\n/** Reused sink for the closest-point primitives; queries run sequentially. */\nconst _pointScratch: PointLike = { x: 0, y: 0 };\n\n/** Every shape kind that can be a collision operand - a chain is solved per edge. */\ntype SolverShape = Exclude<AnyShape, ChainShape>;\n\n/** A category/mask/group filter applied to a query. Omitting it matches everything. */\nexport type QueryFilter = Partial<{ category: number; mask: number; group: number }>;\n\n/** A single ray-cast intersection. */\nexport interface RayHit {\n collider: Collider;\n body: PhysicsBody;\n /** World-space hit position. */\n point: { x: number; y: number };\n /** Surface normal at the hit (unit, pointing back toward the ray origin). */\n normal: { x: number; y: number };\n /** Distance from the origin along the (normalised) ray direction. */\n distance: number;\n}\n\n/**\n * Spatial queries over the world's live collider set. The engine holds a\n * reference to the world's collider array (kept world-synchronised on every\n * body move), so queries always see current placements. Array-returning queries\n * follow the three explicit allocation forms: fresh array, caller-owned `out`,\n * or an allocation-free callback - never a hidden shared buffer.\n *\n * The engine scans the geometry the broad phase holds, which for a chain\n * collider is its per-edge proxies. Every result is reported as the authored\n * collider, and an overlap query reports a chain once however many of its edges\n * it touches. A ray still reports one hit per edge it crosses, because those are\n * distinct intersections.\n */\nexport class QueryEngine {\n private readonly _colliders: readonly Collider[];\n private readonly _spatialIndex: SpatialIndex | undefined;\n private readonly _scratchHits: Collider[] = [];\n private readonly _scratchHitsForEach: Collider[] = [];\n /** Chains already reported by the running `forEachAabbHit`, so one chain is one callback. */\n private readonly _scratchSeenForEach: Collider[] = [];\n private readonly _scratchAabb: AabbLike = createAabb();\n\n public constructor(colliders: readonly Collider[], spatialIndex?: SpatialIndex) {\n this._colliders = colliders;\n this._spatialIndex = spatialIndex;\n }\n\n /**\n * Colliders to scan for a query over `bounds` - the spatial index's narrowed\n * result if one is wired, else every live collider. `sync` is called first so\n * colliders added/moved since the index's last detection pass (including\n * before the world's very first `step()`) are still found.\n *\n * `buffer` is the scratch array the spatial index writes candidates into\n * (cleared and refilled in place). Callers whose per-candidate loop can\n * re-enter `_candidatesFor` - directly or via caller-supplied callback code -\n * must pass a buffer dedicated to them, so a nested call refilling its own\n * buffer can't truncate/corrupt an outer call's still-live iteration.\n */\n private _candidatesFor(bounds: AabbLike, buffer: Collider[]): readonly Collider[] {\n if (this._spatialIndex === undefined) {\n return this._colliders;\n }\n\n this._spatialIndex.sync(this._colliders);\n\n return this._spatialIndex.queryAabb(bounds, buffer);\n }\n\n /** Colliders containing `point`. Allocates a fresh array. */\n public queryPoint(point: Readonly<PointLike>, filter?: QueryFilter): Collider[] {\n const out: Collider[] = [];\n const resolved = filter ? resolveFilter(filter) : null;\n const bounds = this._scratchAabb;\n\n bounds.minX = point.x;\n bounds.minY = point.y;\n bounds.maxX = point.x;\n bounds.maxY = point.y;\n\n // A chain edge encloses no area, so a chain can never answer a point query\n // and no de-duplication is needed here.\n for (const collider of this._candidatesFor(bounds, this._scratchHits)) {\n if (resolved && !shouldCollide(resolved, collider.filter)) {\n continue;\n }\n\n if (pointInCollider(collider, point.x, point.y)) {\n out.push(collider);\n }\n }\n\n return out;\n }\n\n /** Colliders whose AABB overlaps `bounds`. Writes into `out` (cleared first) when given, else a fresh array. */\n public queryAabb(bounds: AabbLike, filter?: QueryFilter, out?: Collider[]): Collider[] {\n const result = out ?? [];\n result.length = 0;\n const resolved = filter ? resolveFilter(filter) : null;\n\n for (const collider of this._candidatesFor(bounds, this._scratchHits)) {\n const authored = authoredCollider(collider);\n\n if (resolved && !shouldCollide(resolved, authored.filter)) {\n continue;\n }\n\n if (aabbOverlap(collider.aabb, bounds) && !alreadyReported(collider, authored, result)) {\n result.push(authored);\n }\n }\n\n return result;\n }\n\n /**\n * Invoke `callback` for each collider whose AABB overlaps `bounds`. Allocation-free.\n *\n * NOT re-entrant on itself: `callback` runs mid-traversal over a scratch\n * buffer dedicated to this method, so it may safely call `queryPoint`,\n * `queryAabb`, or `overlapShape` on this same `PhysicsWorld`/`QueryEngine`\n * (they use a separate buffer and never invoke caller code mid-loop). It\n * must NOT call `forEachAabbHit` again - directly or indirectly - on the\n * same instance: the nested call would refill the same shared buffer this\n * traversal is still iterating, silently truncating/corrupting it. This\n * mirrors `DynamicAabbTree.query()`'s own non-reentrancy contract.\n */\n public forEachAabbHit(bounds: AabbLike, filter: QueryFilter | undefined, callback: (collider: Collider) => void): void {\n const resolved = filter ? resolveFilter(filter) : null;\n const reported = this._scratchSeenForEach;\n\n reported.length = 0;\n\n for (const collider of this._candidatesFor(bounds, this._scratchHitsForEach)) {\n const authored = authoredCollider(collider);\n\n if (resolved && !shouldCollide(resolved, authored.filter)) {\n continue;\n }\n\n if (!aabbOverlap(collider.aabb, bounds) || alreadyReported(collider, authored, reported)) {\n continue;\n }\n\n if (collider !== authored) {\n reported.push(authored);\n }\n\n callback(authored);\n }\n }\n\n /** Nearest collider hit by the ray from `origin` along `direction`, or `null`. */\n public rayCast(origin: Readonly<PointLike>, direction: Readonly<PointLike>, filter?: QueryFilter, maxDistance = Infinity): RayHit | null {\n const length = Math.hypot(direction.x, direction.y);\n\n if (length < 1e-9) {\n throw new RangeError('QueryEngine.rayCast: direction must be non-zero.');\n }\n\n const dx = direction.x / length;\n const dy = direction.y / length;\n const resolved = filter ? resolveFilter(filter) : null;\n\n let best: RayHit | null = null;\n const consider = (collider: Collider): void => {\n const authored = authoredCollider(collider);\n\n if (resolved && !shouldCollide(resolved, authored.filter)) {\n return;\n }\n\n const hit = rayCastCollider(collider, origin.x, origin.y, dx, dy, best ? best.distance : maxDistance);\n\n if (hit && (best === null || hit.distance < best.distance)) {\n hit.collider = authored;\n best = hit;\n }\n };\n\n if (this._spatialIndex === undefined) {\n for (const collider of this._colliders) {\n consider(collider);\n }\n } else {\n this._spatialIndex.sync(this._colliders);\n this._spatialIndex.rayCast(origin.x, origin.y, dx, dy, maxDistance, consider);\n }\n\n return best;\n }\n\n /** All collider hits along the ray, sorted by distance. Writes into `out` (cleared first) when given. */\n public rayCastAll(origin: Readonly<PointLike>, direction: Readonly<PointLike>, filter?: QueryFilter, out?: RayHit[], maxDistance = Infinity): RayHit[] {\n const length = Math.hypot(direction.x, direction.y);\n\n if (length < 1e-9) {\n throw new RangeError('QueryEngine.rayCastAll: direction must be non-zero.');\n }\n\n const dx = direction.x / length;\n const dy = direction.y / length;\n const resolved = filter ? resolveFilter(filter) : null;\n const result = out ?? [];\n result.length = 0;\n const consider = (collider: Collider): void => {\n const authored = authoredCollider(collider);\n\n if (resolved && !shouldCollide(resolved, authored.filter)) {\n return;\n }\n\n const hit = rayCastCollider(collider, origin.x, origin.y, dx, dy, maxDistance);\n\n if (hit) {\n hit.collider = authored;\n result.push(hit);\n }\n };\n\n if (this._spatialIndex === undefined) {\n for (const collider of this._colliders) {\n consider(collider);\n }\n } else {\n this._spatialIndex.sync(this._colliders);\n this._spatialIndex.rayCast(origin.x, origin.y, dx, dy, maxDistance, consider);\n }\n\n result.sort((a, b) => a.distance - b.distance);\n\n return result;\n }\n\n /**\n * Colliders overlapping `shape` placed at `position`/`angle`. Allocates a\n * fresh array.\n *\n * A chain query shape is tested edge by edge, exactly as a chain collider is\n * solved. Two boundaries have no overlap volume, so a chain - like a segment -\n * never reports another chain or segment.\n */\n public overlapShape(shape: AnyShape, position: Readonly<PointLike>, filter?: QueryFilter, angle = 0): Collider[] {\n const proxies = queryProxies(shape, position.x, position.y, angle);\n const out: Collider[] = [];\n const resolved = filter ? resolveFilter(filter) : null;\n const bounds = proxiesAabb(shape, proxies, this._scratchAabb);\n\n for (const collider of this._candidatesFor(bounds, this._scratchHits)) {\n const authored = authoredCollider(collider);\n\n if (resolved && !shouldCollide(resolved, authored.filter)) {\n continue;\n }\n\n if (alreadyReported(collider, authored, out)) {\n continue;\n }\n\n for (const proxy of proxies) {\n if (testOverlap(proxy, collider)) {\n out.push(authored);\n break;\n }\n }\n }\n\n return out;\n }\n}\n\n/** Read a flat vertex/normal buffer in-bounds: callers index within 0..count-1. */\n\n/** `true` when world point `(px, py)` lies inside `collider`'s shape. */\nconst pointInCollider = (collider: Collider, px: number, py: number): boolean => {\n if (!aabbContainsPoint(collider.aabb, px, py)) {\n return false;\n }\n\n if (collider.shape.type === 'circle') {\n const c = collider.worldCenter;\n const r = collider.shape.radius;\n const dx = px - c.x;\n const dy = py - c.y;\n\n return dx * dx + dy * dy <= r * r;\n }\n\n if (collider.shape.type === 'chain') {\n // Unreachable through the world's own geometry - a chain is scanned through\n // its edge proxies - and the same answer as a segment either way.\n return false;\n }\n\n if (collider.shape.type === 'segment') {\n // A boundary encloses no area. Reporting a hit within some epsilon would make\n // the answer depend on an engine constant rather than the authored geometry;\n // ray casts and AABB queries are the meaningful questions for a segment.\n return false;\n }\n\n if (collider.shape.type === 'capsule') {\n const spine = collider.worldVertices;\n\n return pointSegmentDistanceSquared(px, py, spine[0]!, spine[1]!, spine[2]!, spine[3]!, _pointScratch) <= collider.shape.radius * collider.shape.radius;\n }\n\n const verts = collider.worldVertices;\n const normals = collider.worldNormals;\n const count = collider.shape.count;\n\n for (let i = 0; i < count; i++) {\n const nx = normals[i * 2]!;\n const ny = normals[i * 2 + 1]!;\n const vx = verts[i * 2]!;\n const vy = verts[i * 2 + 1]!;\n\n if (nx * (px - vx) + ny * (py - vy) > 0) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Cast the (normalised) ray against one collider, returning the entry hit or `null`. */\nconst rayCastCollider = (collider: Collider, ox: number, oy: number, dx: number, dy: number, maxDistance: number): RayHit | null => {\n switch (collider.shape.type) {\n case 'circle':\n return rayCastCircle(collider, ox, oy, dx, dy, maxDistance);\n case 'capsule':\n return rayCastCapsule(collider, collider.shape.radius, ox, oy, dx, dy, maxDistance);\n case 'segment':\n return rayCastSegment(collider, ox, oy, dx, dy, maxDistance);\n case 'polygon':\n return rayCastPolygon(collider, ox, oy, dx, dy, maxDistance);\n case 'chain':\n // A chain collider is never scanned itself; its edge proxies are.\n return null;\n }\n};\n\n/**\n * Ray against a segment: a plain segment/segment crossing. The reported normal is\n * the segment's own side normal, flipped to face the incoming ray - a boundary\n * blocks from both sides, so which of its two normals applies is decided by where\n * the ray comes from.\n */\nconst rayCastSegment = (collider: Collider, ox: number, oy: number, dx: number, dy: number, maxDistance: number): RayHit | null => {\n const ends = collider.worldVertices;\n const ax = ends[0]!;\n const ay = ends[1]!;\n const ex = ends[2]! - ax;\n const ey = ends[3]! - ay;\n const denominator = dx * ey - dy * ex;\n\n // Parallel (or collinear): no single crossing point to report.\n if (Math.abs(denominator) < 1e-12) {\n return null;\n }\n\n const rx = ax - ox;\n const ry = ay - oy;\n const distance = (rx * ey - ry * ex) / denominator;\n const along = (rx * dy - ry * dx) / denominator;\n\n if (distance < 0 || distance > maxDistance || along < 0 || along > 1) {\n return null;\n }\n\n const nx = collider.worldNormals[0]!;\n const ny = collider.worldNormals[1]!;\n const facing = nx * dx + ny * dy > 0 ? -1 : 1;\n\n return {\n collider,\n body: collider.body,\n point: { x: ox + dx * distance, y: oy + dy * distance },\n normal: { x: nx * facing, y: ny * facing },\n distance,\n };\n};\n\n/**\n * Ray against a capsule: the first point along the ray whose distance to the\n * spine equals the radius.\n *\n * Found by scanning for the first sample inside and bisecting the bracket that\n * produced it, rather than by three closed-form feature tests (two caps and the\n * side slab). The distance-to-spine function is continuous and, approaching the\n * capsule from outside, monotone up to the first touch, so the bracket is valid;\n * a fixed 40 bisections put the result far below the engine's contact slop. The\n * cost is a query-path concern only - the solver never runs this.\n */\nconst rayCastCapsule = (collider: Collider, radius: number, ox: number, oy: number, dx: number, dy: number, maxDistance: number): RayHit | null => {\n const spine = collider.worldVertices;\n const ax = spine[0]!;\n const ay = spine[1]!;\n const bx = spine[2]!;\n const by = spine[3]!;\n const radiusSquared = radius * radius;\n\n // An origin already inside the solid has no entry point, matching the circle\n // and polygon paths.\n if (pointSegmentDistanceSquared(ox, oy, ax, ay, bx, by, _pointScratch) <= radiusSquared) {\n return null;\n }\n\n // Bound the scan by where the ray crosses the collider's AABB. `maxDistance`\n // is routinely Infinity, and the box already carries the capsule's radius, so\n // this is both finite and tight.\n const box = collider.aabb;\n let near = 0;\n let far = maxDistance;\n\n for (let axis = 0; axis < 2; axis++) {\n const origin = axis === 0 ? ox : oy;\n const direction = axis === 0 ? dx : dy;\n const lo = axis === 0 ? box.minX : box.minY;\n const hi = axis === 0 ? box.maxX : box.maxY;\n\n if (Math.abs(direction) < 1e-12) {\n if (origin < lo || origin > hi) {\n return null;\n }\n\n continue;\n }\n\n const t0 = (lo - origin) / direction;\n const t1 = (hi - origin) / direction;\n\n near = Math.max(near, Math.min(t0, t1));\n far = Math.min(far, Math.max(t0, t1));\n }\n\n if (near > far) {\n return null;\n }\n\n const steps = 32;\n const stepLength = (far - near) / steps;\n let entered = -1;\n\n for (let i = 1; i <= steps; i++) {\n const t = near + i * stepLength;\n\n if (pointSegmentDistanceSquared(ox + dx * t, oy + dy * t, ax, ay, bx, by, _pointScratch) <= radiusSquared) {\n entered = t;\n\n break;\n }\n }\n\n if (entered < 0) {\n return null;\n }\n\n let lo = entered - stepLength;\n let hi = entered;\n\n for (let i = 0; i < 40; i++) {\n const mid = (lo + hi) / 2;\n\n if (pointSegmentDistanceSquared(ox + dx * mid, oy + dy * mid, ax, ay, bx, by, _pointScratch) <= radiusSquared) {\n hi = mid;\n } else {\n lo = mid;\n }\n }\n\n const hitX = ox + dx * hi;\n const hitY = oy + dy * hi;\n\n closestPointOnSegment(hitX, hitY, ax, ay, bx, by, _pointScratch);\n\n const nx = hitX - _pointScratch.x;\n const ny = hitY - _pointScratch.y;\n const length = Math.hypot(nx, ny) || 1;\n\n return {\n collider,\n body: collider.body,\n point: { x: hitX, y: hitY },\n normal: { x: nx / length, y: ny / length },\n distance: hi,\n };\n};\n\nconst rayCastCircle = (collider: Collider, ox: number, oy: number, dx: number, dy: number, maxDistance: number): RayHit | null => {\n const c = collider.worldCenter;\n // Dispatched only for circle colliders; the fallback is unreachable.\n const r = collider.shape.type === 'circle' ? collider.shape.radius : 0;\n const mx = ox - c.x;\n const my = oy - c.y;\n const b = mx * dx + my * dy;\n const cc = mx * mx + my * my - r * r;\n\n // Origin outside and pointing away.\n if (cc > 0 && b > 0) {\n return null;\n }\n\n const disc = b * b - cc;\n\n if (disc < 0) {\n return null;\n }\n\n let t = -b - Math.sqrt(disc);\n\n if (t < 0) {\n t = 0;\n }\n\n if (t > maxDistance) {\n return null;\n }\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = (px - c.x) / r;\n const ny = (py - c.y) / r;\n\n return { collider, body: collider.body, point: { x: px, y: py }, normal: { x: nx, y: ny }, distance: t };\n};\n\nconst rayCastPolygon = (collider: Collider, ox: number, oy: number, dx: number, dy: number, maxDistance: number): RayHit | null => {\n const verts = collider.worldVertices;\n const normals = collider.worldNormals;\n // Dispatched only for polygon colliders; the fallback is unreachable.\n const count = collider.shape.type === 'polygon' ? collider.shape.count : 0;\n\n let tmin = 0;\n let tmax = maxDistance;\n let enterNx = 0;\n let enterNy = 0;\n let entered = false;\n\n for (let i = 0; i < count; i++) {\n const nx = normals[i * 2]!;\n const ny = normals[i * 2 + 1]!;\n const vx = verts[i * 2]!;\n const vy = verts[i * 2 + 1]!;\n const numerator = nx * (vx - ox) + ny * (vy - oy);\n const denominator = nx * dx + ny * dy;\n\n if (denominator === 0) {\n // Parallel to this face: if the origin is outside it, the ray misses.\n if (numerator < 0) {\n return null;\n }\n\n continue;\n }\n\n const t = numerator / denominator;\n\n if (denominator < 0) {\n // Entering this half-plane.\n if (t > tmin) {\n tmin = t;\n enterNx = nx;\n enterNy = ny;\n entered = true;\n }\n } else if (t < tmax) {\n // Leaving this half-plane.\n tmax = t;\n }\n\n if (tmin > tmax) {\n return null;\n }\n }\n\n if (!entered || tmin < 0 || tmin > maxDistance) {\n return null;\n }\n\n return {\n collider,\n body: collider.body,\n point: { x: ox + dx * tmin, y: oy + dy * tmin },\n normal: { x: enterNx, y: enterNy },\n distance: tmin,\n };\n};\n\n/**\n * Throwaway collision proxies for a query shape placed at `(x, y)` with `angle`:\n * one, or one per edge for a chain.\n */\nconst queryProxies = (shape: AnyShape, x: number, y: number, angle: number): readonly CollisionProxy[] => {\n if (shape.type !== 'chain') {\n return [makeProxy(shape, x, y, angle)];\n }\n\n return shape.edges.map(edge => makeProxy(edge, x, y, angle));\n};\n\n/** World AABB covering every proxy of a query shape. */\nconst proxiesAabb = (shape: AnyShape, proxies: readonly CollisionProxy[], out: AabbLike): AabbLike => {\n if (shape.type !== 'chain') {\n return proxyAabb(shape, proxies[0]!, out);\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const proxy of proxies) {\n const edgeBounds = proxyAabb(proxy.shape as SolverShape, proxy, _scratchEdgeAabb);\n\n minX = edgeBounds.minX < minX ? edgeBounds.minX : minX;\n minY = edgeBounds.minY < minY ? edgeBounds.minY : minY;\n maxX = edgeBounds.maxX > maxX ? edgeBounds.maxX : maxX;\n maxY = edgeBounds.maxY > maxY ? edgeBounds.maxY : maxY;\n }\n\n out.minX = minX;\n out.minY = minY;\n out.maxX = maxX;\n out.maxY = maxY;\n\n return out;\n};\n\n/** Scratch for the per-edge bounds a chain query shape unions. */\nconst _scratchEdgeAabb: AabbLike = createAabb();\n\n/**\n * `true` when `authored` is already in `reported`. Only a chain can be reached\n * twice in one query (once per edge proxy), so nothing else pays for the scan.\n */\nconst alreadyReported = (candidate: Collider, authored: Collider, reported: readonly Collider[]): boolean =>\n candidate !== authored && reported.includes(authored);\n\n/** Build a throwaway collision proxy for a shape placed at `(x, y)` with `angle`. */\nconst makeProxy = (shape: SolverShape, x: number, y: number, angle: number): CollisionProxy => {\n if (shape.type === 'circle') {\n return { shape, worldCenter: { x, y }, worldVertices: [], worldNormals: [] };\n }\n\n const count = shape.type === 'polygon' ? shape.count : 2;\n const transform = createTransform(x, y, angle);\n const worldVertices: number[] = [];\n const worldNormals: number[] = [];\n const out: PointLike = { x: 0, y: 0 };\n\n for (let i = 0; i < count; i++) {\n applyTransform(transform, shape.vertices[i * 2]!, shape.vertices[i * 2 + 1]!, out);\n worldVertices.push(out.x, out.y);\n applyRotation(transform, shape.normals[i * 2]!, shape.normals[i * 2 + 1]!, out);\n worldNormals.push(out.x, out.y);\n }\n\n return { shape, worldCenter: { x, y }, worldVertices, worldNormals };\n};\n\n/** Compute the world AABB of an already-built collision proxy (reuses its cached vertices/centre - no extra transform work). */\nconst proxyAabb = (shape: SolverShape, proxy: CollisionProxy, out: AabbLike): AabbLike => {\n if (shape.type === 'circle') {\n const r = shape.radius;\n\n out.minX = proxy.worldCenter.x - r;\n out.minY = proxy.worldCenter.y - r;\n out.maxX = proxy.worldCenter.x + r;\n out.maxY = proxy.worldCenter.y + r;\n\n return out;\n }\n\n const verts = proxy.worldVertices;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < verts.length; i += 2) {\n const x = verts[i]!;\n const y = verts[i + 1]!;\n\n minX = x < minX ? x : minX;\n minY = y < minY ? y : minY;\n maxX = x > maxX ? x : maxX;\n maxY = y > maxY ? y : maxY;\n }\n\n const radius = shape.type === 'capsule' ? shape.radius : 0;\n\n out.minX = minX - radius;\n out.minY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,SAAS,IAAI,IAAK,MAAM,SAAS,IAAI,IAAI,IAAK,GAAG;EACjF,cAAc,KAAK,IAAI,GAAG,IAAI,CAAC;EAC/B,cAAc,WAAW,MAAM,QAAQ,IAAI,IAAK,MAAM,QAAQ,IAAI,IAAI,IAAK,GAAG;EAC9E,aAAa,KAAK,IAAI,GAAG,IAAI,CAAC;CAChC;CAEA,OAAO;EAAE;EAAO,aAAa;GAAE;GAAG;EAAE;EAAG;EAAe;CAAa;AACrE;;AAGA,MAAM,aAAa,OAAoB,OAAuB,QAA4B;CACxF,IAAI,MAAM,SAAS,UAAU;EAC3B,MAAM,IAAI,MAAM;EAEhB,IAAI,OAAO,MAAM,YAAY,IAAI;EACjC,IAAI,OAAO,MAAM,YAAY,IAAI;EACjC,IAAI,OAAO,MAAM,YAAY,IAAI;EACjC,IAAI,OAAO,MAAM,YAAY,IAAI;EAEjC,OAAO;CACT;CAEA,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxC,MAAM,IAAI,MAAM;EAChB,MAAM,IAAI,MAAM,IAAI;EAEpB,OAAO,IAAI,OAAO,IAAI;EACtB,OAAO,IAAI,OAAO,IAAI;EACtB,OAAO,IAAI,OAAO,IAAI;EACtB,OAAO,IAAI,OAAO,IAAI;CACxB;CAEA,MAAM,SAAS,MAAM,SAAS,YAAY,MAAM,SAAS;CAEzD,IAAI,OAAO,OAAO;CAClB,IAAI,OAAO,OAAO;CAClB,IAAI,OAAO,OAAO;CAClB,IAAI,OAAO,OAAO;CAElB,OAAO;AACT"}
@@ -1,34 +0,0 @@
1
- import type { AabbLike } from '@codexo/exojs';
2
- import type { Collider } from '../Collider';
3
- /**
4
- * Optional backend capability: an accelerated AABB-overlap query over the
5
- * world's live colliders. {@link QueryEngine} narrows its otherwise-linear
6
- * scan through this when the active {@link PhysicsBackend} provides one.
7
- */
8
- export interface SpatialIndex {
9
- /**
10
- * Ensure every live collider in `colliders` is represented in the index
11
- * (insert new leaves, reinsert moved ones) before a query. The underlying
12
- * tree is normally kept in sync once per physics step (via the broad
13
- * phase's own detection pass); a caller that queries before the world's
14
- * first `step()` - or between steps, after adding/moving colliders - has
15
- * no such guarantee, so {@link QueryEngine} calls this before every
16
- * narrowed query. A leaf whose tight AABB stays inside its stored fat AABB
17
- * costs nothing to re-sync, so calling this redundantly (e.g. right after
18
- * a step already synced it) is cheap.
19
- */
20
- sync(colliders: readonly Collider[]): void;
21
- /** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */
22
- queryAabb(aabb: Readonly<AabbLike>, out: Collider[]): Collider[];
23
- /**
24
- * Invoke `callback` for each collider whose AABB the ray from `originX,
25
- * originY` along `dirX, dirY` could cross within `maxDistance` (`Infinity`
26
- * for an unbounded ray). Narrows the candidate set for {@link QueryEngine}'s
27
- * ray-cast the way {@link queryAabb} does for its overlap queries: the hit
28
- * set is conservative (never misses a true intersection, may include AABB
29
- * false positives), and {@link QueryEngine} applies the exact per-shape ray
30
- * math to each candidate. Order is unspecified.
31
- */
32
- rayCast(originX: number, originY: number, dirX: number, dirY: number, maxDistance: number, callback: (collider: Collider) => void): void;
33
- }
34
- //# sourceMappingURL=SpatialIndex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpatialIndex.d.ts","sourceRoot":"","sources":["../../../src/query/SpatialIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;OAUG;IACH,IAAI,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC3C,8FAA8F;IAC9F,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC;IACjE;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,GAAG,IAAI,CAAC;CAC1I"}
@@ -1,14 +0,0 @@
1
- import type { CapsuleShape } from './CapsuleShape';
2
- import type { ChainShape } from './ChainShape';
3
- import type { CircleShape } from './CircleShape';
4
- import type { PolygonShape } from './PolygonShape';
5
- import type { SegmentShape } from './SegmentShape';
6
- /**
7
- * Discriminated union of the concrete shape kinds. Narrow via the literal
8
- * `shape.type` discriminant (`'circle'` → {@link CircleShape}, `'capsule'` →
9
- * {@link CapsuleShape}, `'polygon'` → {@link PolygonShape}) - no `as` casts
10
- * needed. {@link BoxShape} is a {@link PolygonShape} subclass and carries
11
- * `type: 'polygon'`.
12
- */
13
- export type AnyShape = CapsuleShape | ChainShape | CircleShape | PolygonShape | SegmentShape;
14
- //# sourceMappingURL=AnyShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnyShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/AnyShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC"}
@@ -1,12 +0,0 @@
1
- import { PolygonShape } from './PolygonShape';
2
- /**
3
- * Axis-aligned box of `width × height` centred on the collider's local origin -
4
- * a convenience over {@link PolygonShape}. The result is a regular polygon, so
5
- * it participates in the polygon narrow phase like any other convex shape.
6
- */
7
- export declare class BoxShape extends PolygonShape {
8
- readonly width: number;
9
- readonly height: number;
10
- constructor(width: number, height: number);
11
- }
12
- //# sourceMappingURL=BoxShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BoxShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/BoxShape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,YAAmB,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAiB/C;CACF"}