@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,555 +0,0 @@
1
- import { chainEdgeAdmits } from "./chainAdjacency.js";
2
- import { needsFlip, symmetricEntry, symmetricTable } from "./dispatch.js";
3
- import { closestPointOnSegment, pointSegmentDistanceSquared } from "./segments.js";
4
-
5
- //#region src/collision/narrowphase.ts
6
- const eps = 1e-9;
7
- /** Reused closest-point sink; the narrow phase is single-threaded and non-reentrant. */
8
- const _segmentScratch = {
9
- x: 0,
10
- y: 0
11
- };
12
- /**
13
- * Generate the contact manifold for `a` vs `b`, writing into `manifold` and
14
- * returning `true` when the colliders touch. The manifold normal is oriented
15
- * from `a` toward `b`.
16
- *
17
- * A pair with no entry in the table is deliberately unsupported and reports no
18
- * contact rather than an approximation.
19
- */
20
- const collide = (a, b, manifold) => {
21
- manifold.reset();
22
- const ta = a.shape.type;
23
- const tb = b.shape.type;
24
- const solver = symmetricEntry(collideTable, ta, tb);
25
- if (solver === void 0) return false;
26
- if (!(needsFlip(ta, tb) ? solver(b, a, manifold, true) : solver(a, b, manifold, false))) return false;
27
- if (!chainEdgeAdmits(a, manifold.normalX, manifold.normalY) || !chainEdgeAdmits(b, -manifold.normalX, -manifold.normalY)) {
28
- manifold.reset();
29
- return false;
30
- }
31
- return true;
32
- };
33
- const radiusOf = (collider) => collider.shape.type === "circle" || collider.shape.type === "capsule" ? collider.shape.radius : 0;
34
- const countOf = (collider) => {
35
- switch (collider.shape.type) {
36
- case "polygon": return collider.shape.count;
37
- case "capsule":
38
- case "segment": return 2;
39
- case "circle":
40
- case "chain": return 0;
41
- }
42
- };
43
- const collideCircles = (a, b, manifold) => {
44
- const ca = a.worldCenter;
45
- const cb = b.worldCenter;
46
- const ra = radiusOf(a);
47
- const rb = radiusOf(b);
48
- let nx = cb.x - ca.x;
49
- let ny = cb.y - ca.y;
50
- const rsum = ra + rb;
51
- const distSq = nx * nx + ny * ny;
52
- if (distSq > rsum * rsum) return false;
53
- const dist = Math.sqrt(distSq);
54
- if (dist > eps) {
55
- nx /= dist;
56
- ny /= dist;
57
- } else {
58
- nx = 0;
59
- ny = 1;
60
- }
61
- manifold.normalX = nx;
62
- manifold.normalY = ny;
63
- const point = manifold.points[0];
64
- point.x = (ca.x + nx * ra + cb.x - nx * rb) * .5;
65
- point.y = (ca.y + ny * ra + cb.y - ny * rb) * .5;
66
- point.penetration = rsum - dist;
67
- point.id = 0;
68
- manifold.pointCount = 1;
69
- return true;
70
- };
71
- /**
72
- * Circle (the `circle` collider) vs polygon. Produces the normal pointing from
73
- * the circle toward the polygon; when `flip` is set (the polygon is collider A),
74
- * the normal is negated so it stays `a → b`.
75
- */
76
- const collideCirclePolygon = (circle, polygon, manifold, flip) => {
77
- const c = circle.worldCenter;
78
- const r = radiusOf(circle);
79
- const verts = polygon.worldVertices;
80
- const normals = polygon.worldNormals;
81
- const count = countOf(polygon);
82
- let maxSep = -Infinity;
83
- let refEdge = 0;
84
- for (let i = 0; i < count; i++) {
85
- const enx = normals[i * 2];
86
- const eny = normals[i * 2 + 1];
87
- const evx = verts[i * 2];
88
- const evy = verts[i * 2 + 1];
89
- const s = enx * (c.x - evx) + eny * (c.y - evy);
90
- if (s > r) return false;
91
- if (s > maxSep) {
92
- maxSep = s;
93
- refEdge = i;
94
- }
95
- }
96
- const refNx = normals[refEdge * 2];
97
- const refNy = normals[refEdge * 2 + 1];
98
- let nx;
99
- let ny;
100
- let penetration;
101
- let px;
102
- let py;
103
- let id;
104
- if (maxSep < eps) {
105
- nx = -refNx;
106
- ny = -refNy;
107
- penetration = r - maxSep;
108
- px = c.x + nx * r;
109
- py = c.y + ny * r;
110
- id = refEdge;
111
- } else {
112
- const j = (refEdge + 1) % count;
113
- const v1x = verts[refEdge * 2];
114
- const v1y = verts[refEdge * 2 + 1];
115
- const v2x = verts[j * 2];
116
- const v2y = verts[j * 2 + 1];
117
- const u1 = (c.x - v1x) * (v2x - v1x) + (c.y - v1y) * (v2y - v1y);
118
- const u2 = (c.x - v2x) * (v1x - v2x) + (c.y - v2y) * (v1y - v2y);
119
- if (u1 <= 0) {
120
- const dx = c.x - v1x;
121
- const dy = c.y - v1y;
122
- const d2 = dx * dx + dy * dy;
123
- if (d2 > r * r) return false;
124
- const d = Math.sqrt(d2);
125
- nx = d > eps ? -dx / d : -refNx;
126
- ny = d > eps ? -dy / d : -refNy;
127
- penetration = r - d;
128
- px = v1x;
129
- py = v1y;
130
- id = refEdge;
131
- } else if (u2 <= 0) {
132
- const dx = c.x - v2x;
133
- const dy = c.y - v2y;
134
- const d2 = dx * dx + dy * dy;
135
- if (d2 > r * r) return false;
136
- const d = Math.sqrt(d2);
137
- nx = d > eps ? -dx / d : -refNx;
138
- ny = d > eps ? -dy / d : -refNy;
139
- penetration = r - d;
140
- px = v2x;
141
- py = v2y;
142
- id = j;
143
- } else {
144
- nx = -refNx;
145
- ny = -refNy;
146
- penetration = r - maxSep;
147
- px = c.x + nx * r;
148
- py = c.y + ny * r;
149
- id = refEdge;
150
- }
151
- }
152
- if (flip) {
153
- nx = -nx;
154
- ny = -ny;
155
- }
156
- manifold.normalX = nx;
157
- manifold.normalY = ny;
158
- const point = manifold.points[0];
159
- point.x = px;
160
- point.y = py;
161
- point.penetration = penetration < 0 ? 0 : penetration;
162
- point.id = id;
163
- manifold.pointCount = 1;
164
- return true;
165
- };
166
- const newClipPair = () => [{
167
- x: 0,
168
- y: 0,
169
- id: 0
170
- }, {
171
- x: 0,
172
- y: 0,
173
- id: 0
174
- }];
175
- const _incidentScratch = newClipPair();
176
- const _clipped1Scratch = newClipPair();
177
- const _clipped2Scratch = newClipPair();
178
- const _sepA = {
179
- separation: 0,
180
- edge: 0
181
- };
182
- const _sepB = {
183
- separation: 0,
184
- edge: 0
185
- };
186
- /** Max separation of `b` from any face of `a`, with the supporting face index. Writes into and returns `out` (allocation-free). */
187
- const findMaxSeparation = (a, b, out) => {
188
- const av = a.worldVertices;
189
- const an = a.worldNormals;
190
- const ac = countOf(a);
191
- const bv = b.worldVertices;
192
- const bc = countOf(b);
193
- let best = -Infinity;
194
- let bestEdge = 0;
195
- for (let i = 0; i < ac; i++) {
196
- const nx = an[i * 2];
197
- const ny = an[i * 2 + 1];
198
- const vx = av[i * 2];
199
- const vy = av[i * 2 + 1];
200
- let minDot = Infinity;
201
- let sx = 0;
202
- let sy = 0;
203
- for (let j = 0; j < bc; j++) {
204
- const bjx = bv[j * 2];
205
- const bjy = bv[j * 2 + 1];
206
- const d = nx * bjx + ny * bjy;
207
- if (d < minDot) {
208
- minDot = d;
209
- sx = bjx;
210
- sy = bjy;
211
- }
212
- }
213
- const separation = nx * (sx - vx) + ny * (sy - vy);
214
- if (separation > best) {
215
- best = separation;
216
- bestEdge = i;
217
- }
218
- }
219
- out.separation = best;
220
- out.edge = bestEdge;
221
- return out;
222
- };
223
- /** Incident face of `inc` = the face most anti-parallel to the reference normal. */
224
- const findIncidentFace = (refNx, refNy, inc, out) => {
225
- const iv = inc.worldVertices;
226
- const inrm = inc.worldNormals;
227
- const ic = countOf(inc);
228
- let minDot = Infinity;
229
- let idx = 0;
230
- for (let i = 0; i < ic; i++) {
231
- const inx = inrm[i * 2];
232
- const iny = inrm[i * 2 + 1];
233
- const d = refNx * inx + refNy * iny;
234
- if (d < minDot) {
235
- minDot = d;
236
- idx = i;
237
- }
238
- }
239
- const j = (idx + 1) % ic;
240
- out[0].x = iv[idx * 2];
241
- out[0].y = iv[idx * 2 + 1];
242
- out[0].id = idx;
243
- out[1].x = iv[j * 2];
244
- out[1].y = iv[j * 2 + 1];
245
- out[1].id = j;
246
- };
247
- /** Clip the 2-vertex segment `input` to the half-plane `dot(n, p) ≤ offset`. */
248
- const clipSegment = (nx, ny, offset, input, output, syntheticId) => {
249
- const in0 = input[0];
250
- const in1 = input[1];
251
- let count = 0;
252
- const d1 = nx * in0.x + ny * in0.y - offset;
253
- const d2 = nx * in1.x + ny * in1.y - offset;
254
- if (d1 <= 0) {
255
- copyClip(in0, count === 0 ? output[0] : output[1]);
256
- count++;
257
- }
258
- if (d2 <= 0) {
259
- copyClip(in1, count === 0 ? output[0] : output[1]);
260
- count++;
261
- }
262
- if (d1 * d2 < 0 && count < 2) {
263
- const alpha = d1 / (d1 - d2);
264
- const target = count === 0 ? output[0] : output[1];
265
- target.x = in0.x + alpha * (in1.x - in0.x);
266
- target.y = in0.y + alpha * (in1.y - in0.y);
267
- target.id = syntheticId;
268
- count++;
269
- }
270
- return count;
271
- };
272
- const copyClip = (from, to) => {
273
- to.x = from.x;
274
- to.y = from.y;
275
- to.id = from.id;
276
- };
277
- const encodeId = (flip, refEdge, incidentId) => (flip ? 1 << 20 : 0) | (refEdge & 255) << 12 | incidentId & 4095;
278
- /**
279
- * Convex ring vs convex ring: SAT reference face + Sutherland-Hodgman clip, with
280
- * each operand allowed a radius that rounds its outline off.
281
- *
282
- * The separations the SAT computes are between the two **cores**; the radii only
283
- * move where touching begins, and since both candidate axes shift by the same
284
- * sum, the reference face the SAT picks is unaffected. A capsule is a two-vertex
285
- * core with a radius and a polygon a many-vertex core without one, so
286
- * polygon/polygon, capsule/polygon and capsule/capsule are all this one routine.
287
- */
288
- const collideRoundedPolygons = (a, b, manifold, callerFlip) => {
289
- const totalRadius = radiusOf(a) + radiusOf(b);
290
- const sepA = findMaxSeparation(a, b, _sepA);
291
- if (sepA.separation >= totalRadius) return false;
292
- const sepB = findMaxSeparation(b, a, _sepB);
293
- if (sepB.separation >= totalRadius) return false;
294
- let ref;
295
- let inc;
296
- let refEdge;
297
- let refSwapped;
298
- if (sepA.separation >= sepB.separation * .95 + sepA.separation * .01) {
299
- ref = a;
300
- inc = b;
301
- refEdge = sepA.edge;
302
- refSwapped = false;
303
- } else {
304
- ref = b;
305
- inc = a;
306
- refEdge = sepB.edge;
307
- refSwapped = true;
308
- }
309
- const rv = ref.worldVertices;
310
- const rn = ref.worldNormals;
311
- const rc = countOf(ref);
312
- const i2 = (refEdge + 1) % rc;
313
- const v1x = rv[refEdge * 2];
314
- const v1y = rv[refEdge * 2 + 1];
315
- const v2x = rv[i2 * 2];
316
- const v2y = rv[i2 * 2 + 1];
317
- const refNx = rn[refEdge * 2];
318
- const refNy = rn[refEdge * 2 + 1];
319
- const incident = _incidentScratch;
320
- findIncidentFace(refNx, refNy, inc, incident);
321
- let tx = v2x - v1x;
322
- let ty = v2y - v1y;
323
- const tl = Math.sqrt(tx * tx + ty * ty);
324
- tx /= tl;
325
- ty /= tl;
326
- const negSide = -(tx * v1x + ty * v1y);
327
- const posSide = tx * v2x + ty * v2y;
328
- const clipped1 = _clipped1Scratch;
329
- if (clipSegment(-tx, -ty, negSide, incident, clipped1, encodeId(refSwapped, refEdge, 4094)) < 2) return false;
330
- const clipped2 = _clipped2Scratch;
331
- if (clipSegment(tx, ty, posSide, clipped1, clipped2, encodeId(refSwapped, refEdge, 4095)) < 2) return false;
332
- const flipNormal = refSwapped !== callerFlip;
333
- manifold.normalX = flipNormal ? -refNx : refNx;
334
- manifold.normalY = flipNormal ? -refNy : refNy;
335
- const refC = refNx * v1x + refNy * v1y;
336
- const incidentRadius = radiusOf(inc);
337
- const points = manifold.points;
338
- let cp = 0;
339
- for (let k = 0; k < 2; k++) {
340
- const cv = k === 0 ? clipped2[0] : clipped2[1];
341
- const separation = refNx * cv.x + refNy * cv.y - refC;
342
- if (separation <= totalRadius) {
343
- const point = cp === 0 ? points[0] : points[1];
344
- point.x = cv.x - refNx * incidentRadius;
345
- point.y = cv.y - refNy * incidentRadius;
346
- point.penetration = totalRadius - separation;
347
- point.id = encodeId(refSwapped, refEdge, cv.id);
348
- cp++;
349
- }
350
- }
351
- manifold.pointCount = cp;
352
- return cp > 0;
353
- };
354
- /**
355
- * Boolean overlap test (no manifold) used by sensors and shape-overlap queries.
356
- * Exact for the circle/circle, circle/polygon and polygon/polygon pairs.
357
- */
358
- const testOverlap = (a, b) => {
359
- const ta = a.shape.type;
360
- const tb = b.shape.type;
361
- const test = symmetricEntry(overlapTable, ta, tb);
362
- if (test === void 0) return false;
363
- return needsFlip(ta, tb) ? test(b, a) : test(a, b);
364
- };
365
- const circlesOverlap = (a, b) => {
366
- const ca = a.worldCenter;
367
- const cb = b.worldCenter;
368
- const rsum = radiusOf(a) + radiusOf(b);
369
- const dx = cb.x - ca.x;
370
- const dy = cb.y - ca.y;
371
- return dx * dx + dy * dy <= rsum * rsum;
372
- };
373
- const roundedPolygonsOverlap = (a, b) => {
374
- const totalRadius = radiusOf(a) + radiusOf(b);
375
- return findMaxSeparation(a, b, _sepA).separation < totalRadius && findMaxSeparation(b, a, _sepB).separation < totalRadius;
376
- };
377
- /**
378
- * Circle vs capsule: a capsule is every point within its radius of the spine, so
379
- * this is a circle/circle test against the spine point nearest the circle centre.
380
- * One contact point - a circle meets a rounded surface in one place, and a second
381
- * would be invented noise for the solver.
382
- */
383
- const collideCircleSpine = (circle, spineShape, manifold, flip) => {
384
- const spine = spineShape.worldVertices;
385
- const centre = circle.worldCenter;
386
- const circleRadius = radiusOf(circle);
387
- const radiusSum = circleRadius + radiusOf(spineShape);
388
- closestPointOnSegment(centre.x, centre.y, spine[0], spine[1], spine[2], spine[3], _segmentScratch);
389
- let nx = _segmentScratch.x - centre.x;
390
- let ny = _segmentScratch.y - centre.y;
391
- const distanceSquared = nx * nx + ny * ny;
392
- if (distanceSquared > radiusSum * radiusSum) return false;
393
- const distance = Math.sqrt(distanceSquared);
394
- if (distance > eps) {
395
- nx /= distance;
396
- ny /= distance;
397
- } else {
398
- nx = spineShape.worldNormals[0];
399
- ny = spineShape.worldNormals[1];
400
- }
401
- manifold.normalX = flip ? -nx : nx;
402
- manifold.normalY = flip ? -ny : ny;
403
- const point = manifold.points[0];
404
- const along = circleRadius + (distance - radiusSum) * .5;
405
- point.x = centre.x + nx * along;
406
- point.y = centre.y + ny * along;
407
- point.penetration = radiusSum - distance;
408
- point.id = 0;
409
- manifold.pointCount = 1;
410
- return true;
411
- };
412
- const circleSpineOverlap = (circle, spineShape) => {
413
- const spine = spineShape.worldVertices;
414
- const centre = circle.worldCenter;
415
- const radiusSum = radiusOf(circle) + radiusOf(spineShape);
416
- return pointSegmentDistanceSquared(centre.x, centre.y, spine[0], spine[1], spine[2], spine[3], _segmentScratch) <= radiusSum * radiusSum;
417
- };
418
- const circlePolygonOverlap = (circle, polygon) => {
419
- const c = circle.worldCenter;
420
- const r = radiusOf(circle);
421
- const verts = polygon.worldVertices;
422
- const normals = polygon.worldNormals;
423
- const count = countOf(polygon);
424
- let maxSep = -Infinity;
425
- let refEdge = 0;
426
- for (let i = 0; i < count; i++) {
427
- const enx = normals[i * 2];
428
- const eny = normals[i * 2 + 1];
429
- const evx = verts[i * 2];
430
- const evy = verts[i * 2 + 1];
431
- const s = enx * (c.x - evx) + eny * (c.y - evy);
432
- if (s > r) return false;
433
- if (s > maxSep) {
434
- maxSep = s;
435
- refEdge = i;
436
- }
437
- }
438
- if (maxSep < eps) return true;
439
- const j = (refEdge + 1) % count;
440
- const v1x = verts[refEdge * 2];
441
- const v1y = verts[refEdge * 2 + 1];
442
- const v2x = verts[j * 2];
443
- const v2y = verts[j * 2 + 1];
444
- const u1 = (c.x - v1x) * (v2x - v1x) + (c.y - v1y) * (v2y - v1y);
445
- const u2 = (c.x - v2x) * (v1x - v2x) + (c.y - v2y) * (v1y - v2y);
446
- if (u1 <= 0) {
447
- const dx = c.x - v1x;
448
- const dy = c.y - v1y;
449
- return dx * dx + dy * dy <= r * r;
450
- }
451
- if (u2 <= 0) {
452
- const dx = c.x - v2x;
453
- const dy = c.y - v2y;
454
- return dx * dx + dy * dy <= r * r;
455
- }
456
- return maxSep <= r;
457
- };
458
- const collideTable = symmetricTable([
459
- [
460
- "circle",
461
- "circle",
462
- collideCircles
463
- ],
464
- [
465
- "circle",
466
- "capsule",
467
- collideCircleSpine
468
- ],
469
- [
470
- "circle",
471
- "segment",
472
- collideCircleSpine
473
- ],
474
- [
475
- "circle",
476
- "polygon",
477
- collideCirclePolygon
478
- ],
479
- [
480
- "capsule",
481
- "capsule",
482
- collideRoundedPolygons
483
- ],
484
- [
485
- "capsule",
486
- "segment",
487
- collideRoundedPolygons
488
- ],
489
- [
490
- "capsule",
491
- "polygon",
492
- collideRoundedPolygons
493
- ],
494
- [
495
- "segment",
496
- "polygon",
497
- collideRoundedPolygons
498
- ],
499
- [
500
- "polygon",
501
- "polygon",
502
- collideRoundedPolygons
503
- ]
504
- ]);
505
- const overlapTable = symmetricTable([
506
- [
507
- "circle",
508
- "circle",
509
- circlesOverlap
510
- ],
511
- [
512
- "circle",
513
- "capsule",
514
- circleSpineOverlap
515
- ],
516
- [
517
- "circle",
518
- "segment",
519
- circleSpineOverlap
520
- ],
521
- [
522
- "circle",
523
- "polygon",
524
- circlePolygonOverlap
525
- ],
526
- [
527
- "capsule",
528
- "capsule",
529
- roundedPolygonsOverlap
530
- ],
531
- [
532
- "capsule",
533
- "segment",
534
- roundedPolygonsOverlap
535
- ],
536
- [
537
- "capsule",
538
- "polygon",
539
- roundedPolygonsOverlap
540
- ],
541
- [
542
- "segment",
543
- "polygon",
544
- roundedPolygonsOverlap
545
- ],
546
- [
547
- "polygon",
548
- "polygon",
549
- roundedPolygonsOverlap
550
- ]
551
- ]);
552
-
553
- //#endregion
554
- export { collide, testOverlap };
555
- //# sourceMappingURL=narrowphase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"narrowphase.js","names":[],"sources":["../../../src/collision/narrowphase.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { chainEdgeAdmits } from './chainAdjacency';\nimport type { CollisionProxy } from './CollisionProxy';\nimport type { PairTable } from './dispatch';\nimport { needsFlip, symmetricEntry, symmetricTable } from './dispatch';\nimport type { Manifold } from './Manifold';\nimport { closestPointOnSegment, pointSegmentDistanceSquared } from './segments';\n\nconst eps = 1e-9;\n\n/** Reused closest-point sink; the narrow phase is single-threaded and non-reentrant. */\nconst _segmentScratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Solves one unordered shape pair. `a` is always the operand of the lower shape\n * kind; `flip` is `true` when the caller's operands were swapped to get there,\n * and the routine must reverse the manifold normal so it still points from the\n * caller's `a` toward its `b`.\n */\ntype CollidePair = (a: CollisionProxy, b: CollisionProxy, manifold: Manifold, flip: boolean) => boolean;\n\n/** Boolean form of {@link CollidePair}; no normal, so no flip to honour. */\ntype OverlapPair = (a: CollisionProxy, b: CollisionProxy) => boolean;\n\n/**\n * Generate the contact manifold for `a` vs `b`, writing into `manifold` and\n * returning `true` when the colliders touch. The manifold normal is oriented\n * from `a` toward `b`.\n *\n * A pair with no entry in the table is deliberately unsupported and reports no\n * contact rather than an approximation.\n */\nexport const collide = (a: CollisionProxy, b: CollisionProxy, manifold: Manifold): boolean => {\n manifold.reset();\n\n const ta = a.shape.type;\n const tb = b.shape.type;\n const solver = symmetricEntry(collideTable, ta, tb);\n\n if (solver === undefined) {\n return false;\n }\n\n const touching = needsFlip(ta, tb) ? solver(b, a, manifold, true) : solver(a, b, manifold, false);\n\n if (!touching) {\n return false;\n }\n\n // The manifold normal points a → b, so it is the direction `a` pushes `b`\n // away along; from b's side the outward direction is its negation.\n if (!chainEdgeAdmits(a, manifold.normalX, manifold.normalY) || !chainEdgeAdmits(b, -manifold.normalX, -manifold.normalY)) {\n manifold.reset();\n\n return false;\n }\n\n return true;\n};\n\n// Both helpers stay cast-free and allocation-free. A capsule is a two-vertex\n// ring with a radius, which is exactly why it shares the polygon routines: the\n// ring supplies `count` and `worldVertices`/`worldNormals`, the radius rounds\n// the result off.\nconst radiusOf = (collider: CollisionProxy): number => (collider.shape.type === 'circle' || collider.shape.type === 'capsule' ? collider.shape.radius : 0);\nconst countOf = (collider: CollisionProxy): number => {\n switch (collider.shape.type) {\n case 'polygon':\n return collider.shape.count;\n case 'capsule':\n case 'segment':\n return 2;\n case 'circle':\n case 'chain':\n // A chain is never an operand here - it is solved through its edge proxies.\n return 0;\n }\n};\n\nconst collideCircles: CollidePair = (a, b, manifold) => {\n const ca = a.worldCenter;\n const cb = b.worldCenter;\n const ra = radiusOf(a);\n const rb = radiusOf(b);\n\n let nx = cb.x - ca.x;\n let ny = cb.y - ca.y;\n const rsum = ra + rb;\n const distSq = nx * nx + ny * ny;\n\n if (distSq > rsum * rsum) {\n return false;\n }\n\n const dist = Math.sqrt(distSq);\n\n if (dist > eps) {\n nx /= dist;\n ny /= dist;\n } else {\n nx = 0;\n ny = 1;\n }\n\n manifold.normalX = nx;\n manifold.normalY = ny;\n\n const point = manifold.points[0];\n // Midpoint of the two surface contact points.\n point.x = (ca.x + nx * ra + cb.x - nx * rb) * 0.5;\n point.y = (ca.y + ny * ra + cb.y - ny * rb) * 0.5;\n point.penetration = rsum - dist;\n point.id = 0;\n manifold.pointCount = 1;\n\n return true;\n};\n\n/**\n * Circle (the `circle` collider) vs polygon. Produces the normal pointing from\n * the circle toward the polygon; when `flip` is set (the polygon is collider A),\n * the normal is negated so it stays `a → b`.\n */\nconst collideCirclePolygon: CollidePair = (circle, polygon, manifold, flip) => {\n const c = circle.worldCenter;\n const r = radiusOf(circle);\n const verts = polygon.worldVertices;\n const normals = polygon.worldNormals;\n const count = countOf(polygon);\n\n let maxSep = -Infinity;\n let refEdge = 0;\n\n for (let i = 0; i < count; i++) {\n // Loop indices are provably in-bounds (0..count-1); the `!` is zero-cost.\n const enx = normals[i * 2]!;\n const eny = normals[i * 2 + 1]!;\n const evx = verts[i * 2]!;\n const evy = verts[i * 2 + 1]!;\n const s = enx * (c.x - evx) + eny * (c.y - evy);\n\n if (s > r) {\n return false;\n }\n\n if (s > maxSep) {\n maxSep = s;\n refEdge = i;\n }\n }\n\n // refEdge/j stay in 0..count-1, so these reads are in-bounds too.\n const refNx = normals[refEdge * 2]!;\n const refNy = normals[refEdge * 2 + 1]!;\n\n let nx: number;\n let ny: number;\n let penetration: number;\n let px: number;\n let py: number;\n let id: number;\n\n if (maxSep < eps) {\n // Centre inside the polygon: push out along the least-penetrating face.\n nx = -refNx;\n ny = -refNy;\n penetration = r - maxSep;\n px = c.x + nx * r;\n py = c.y + ny * r;\n id = refEdge;\n } else {\n const j = (refEdge + 1) % count;\n const v1x = verts[refEdge * 2]!;\n const v1y = verts[refEdge * 2 + 1]!;\n const v2x = verts[j * 2]!;\n const v2y = verts[j * 2 + 1]!;\n const u1 = (c.x - v1x) * (v2x - v1x) + (c.y - v1y) * (v2y - v1y);\n const u2 = (c.x - v2x) * (v1x - v2x) + (c.y - v2y) * (v1y - v2y);\n\n if (u1 <= 0) {\n // Nearest feature is vertex v1 (Voronoi corner region).\n const dx = c.x - v1x;\n const dy = c.y - v1y;\n const d2 = dx * dx + dy * dy;\n\n if (d2 > r * r) {\n return false;\n }\n\n const d = Math.sqrt(d2);\n\n nx = d > eps ? -dx / d : -refNx;\n ny = d > eps ? -dy / d : -refNy;\n penetration = r - d;\n px = v1x;\n py = v1y;\n id = refEdge;\n } else if (u2 <= 0) {\n const dx = c.x - v2x;\n const dy = c.y - v2y;\n const d2 = dx * dx + dy * dy;\n\n if (d2 > r * r) {\n return false;\n }\n\n const d = Math.sqrt(d2);\n\n nx = d > eps ? -dx / d : -refNx;\n ny = d > eps ? -dy / d : -refNy;\n penetration = r - d;\n px = v2x;\n py = v2y;\n id = j;\n } else {\n // Face region.\n nx = -refNx;\n ny = -refNy;\n penetration = r - maxSep;\n px = c.x + nx * r;\n py = c.y + ny * r;\n id = refEdge;\n }\n }\n\n if (flip) {\n nx = -nx;\n ny = -ny;\n }\n\n manifold.normalX = nx;\n manifold.normalY = ny;\n\n const point = manifold.points[0];\n point.x = px;\n point.y = py;\n point.penetration = penetration < 0 ? 0 : penetration;\n point.id = id;\n manifold.pointCount = 1;\n\n return true;\n};\n\ninterface ClipVertex {\n x: number;\n y: number;\n id: number;\n}\n\nconst newClipPair = (): [ClipVertex, ClipVertex] => [\n { x: 0, y: 0, id: 0 },\n { x: 0, y: 0, id: 0 },\n];\n\n// Module-local clip scratch reused across collidePolygons calls instead of\n// allocating a fresh pair per contact. The narrow phase is single-threaded and\n// non-reentrant - a world step calls `collide` strictly sequentially per pair,\n// with no nested self-call or async - so module-global scratch is safe and may\n// be shared across worlds (world-isolation.test.ts guards the multi-world\n// invariant). The three pairs MUST stay separate: incident → clipped1 →\n// clipped2 are simultaneously live (each clip reads the previous clip's output).\nconst _incidentScratch = newClipPair();\nconst _clipped1Scratch = newClipPair();\nconst _clipped2Scratch = newClipPair();\n\ninterface Separation {\n separation: number;\n edge: number;\n}\n\n// Two separate scratches: collidePolygons holds sepA and sepB at the same time.\nconst _sepA: Separation = { separation: 0, edge: 0 };\nconst _sepB: Separation = { separation: 0, edge: 0 };\n\n/** Max separation of `b` from any face of `a`, with the supporting face index. Writes into and returns `out` (allocation-free). */\nconst findMaxSeparation = (a: CollisionProxy, b: CollisionProxy, out: Separation): Separation => {\n const av = a.worldVertices;\n const an = a.worldNormals;\n const ac = countOf(a);\n const bv = b.worldVertices;\n const bc = countOf(b);\n\n let best = -Infinity;\n let bestEdge = 0;\n\n for (let i = 0; i < ac; i++) {\n // i in 0..ac-1 and j in 0..bc-1, so every read below is in-bounds.\n const nx = an[i * 2]!;\n const ny = an[i * 2 + 1]!;\n const vx = av[i * 2]!;\n const vy = av[i * 2 + 1]!;\n\n // Support of b along -n = vertex of b minimising dot(n, vertex).\n let minDot = Infinity;\n let sx = 0;\n let sy = 0;\n\n for (let j = 0; j < bc; j++) {\n const bjx = bv[j * 2]!;\n const bjy = bv[j * 2 + 1]!;\n const d = nx * bjx + ny * bjy;\n\n if (d < minDot) {\n minDot = d;\n sx = bjx;\n sy = bjy;\n }\n }\n\n const separation = nx * (sx - vx) + ny * (sy - vy);\n\n if (separation > best) {\n best = separation;\n bestEdge = i;\n }\n }\n\n out.separation = best;\n out.edge = bestEdge;\n\n return out;\n};\n\n/** Incident face of `inc` = the face most anti-parallel to the reference normal. */\nconst findIncidentFace = (refNx: number, refNy: number, inc: CollisionProxy, out: [ClipVertex, ClipVertex]): void => {\n const iv = inc.worldVertices;\n const inrm = inc.worldNormals;\n const ic = countOf(inc);\n\n let minDot = Infinity;\n let idx = 0;\n\n for (let i = 0; i < ic; i++) {\n const inx = inrm[i * 2]!;\n const iny = inrm[i * 2 + 1]!;\n const d = refNx * inx + refNy * iny;\n\n if (d < minDot) {\n minDot = d;\n idx = i;\n }\n }\n\n const j = (idx + 1) % ic;\n\n // idx/j in 0..ic-1; reads in-bounds. out is a fixed 2-tuple.\n out[0].x = iv[idx * 2]!;\n out[0].y = iv[idx * 2 + 1]!;\n out[0].id = idx;\n out[1].x = iv[j * 2]!;\n out[1].y = iv[j * 2 + 1]!;\n out[1].id = j;\n};\n\n/** Clip the 2-vertex segment `input` to the half-plane `dot(n, p) ≤ offset`. */\nconst clipSegment = (\n nx: number,\n ny: number,\n offset: number,\n input: readonly [ClipVertex, ClipVertex],\n output: [ClipVertex, ClipVertex],\n syntheticId: number,\n): number => {\n // input/output are fixed 2-tuples; count never exceeds 2 (two boundary\n // copies, or one copy plus the guarded intersection), so output[0]/output[1]\n // are the only slots written and both always exist.\n const in0 = input[0];\n const in1 = input[1];\n let count = 0;\n const d1 = nx * in0.x + ny * in0.y - offset;\n const d2 = nx * in1.x + ny * in1.y - offset;\n\n if (d1 <= 0) {\n copyClip(in0, count === 0 ? output[0] : output[1]);\n count++;\n }\n\n if (d2 <= 0) {\n copyClip(in1, count === 0 ? output[0] : output[1]);\n count++;\n }\n\n if (d1 * d2 < 0 && count < 2) {\n const alpha = d1 / (d1 - d2);\n const target = count === 0 ? output[0] : output[1];\n\n target.x = in0.x + alpha * (in1.x - in0.x);\n target.y = in0.y + alpha * (in1.y - in0.y);\n target.id = syntheticId;\n count++;\n }\n\n return count;\n};\n\nconst copyClip = (from: ClipVertex, to: ClipVertex): void => {\n to.x = from.x;\n to.y = from.y;\n to.id = from.id;\n};\n\nconst encodeId = (flip: boolean, refEdge: number, incidentId: number): number => (flip ? 1 << 20 : 0) | ((refEdge & 0xff) << 12) | (incidentId & 0xfff);\n\n/**\n * Convex ring vs convex ring: SAT reference face + Sutherland-Hodgman clip, with\n * each operand allowed a radius that rounds its outline off.\n *\n * The separations the SAT computes are between the two **cores**; the radii only\n * move where touching begins, and since both candidate axes shift by the same\n * sum, the reference face the SAT picks is unaffected. A capsule is a two-vertex\n * core with a radius and a polygon a many-vertex core without one, so\n * polygon/polygon, capsule/polygon and capsule/capsule are all this one routine.\n */\nconst collideRoundedPolygons: CollidePair = (a, b, manifold, callerFlip) => {\n const totalRadius = radiusOf(a) + radiusOf(b);\n const sepA = findMaxSeparation(a, b, _sepA);\n\n if (sepA.separation >= totalRadius) {\n return false;\n }\n\n const sepB = findMaxSeparation(b, a, _sepB);\n\n if (sepB.separation >= totalRadius) {\n return false;\n }\n\n let ref: CollisionProxy;\n let inc: CollisionProxy;\n let refEdge: number;\n // Whether the REFERENCE role went to `b`. Distinct from `callerFlip`, which\n // records that the caller's own operands were swapped to reach the canonical\n // order; the final normal has to undo both.\n let refSwapped: boolean;\n\n // Bias toward keeping A as the reference for stability (reduces ref/incident\n // role flapping when a body rocks slightly).\n if (sepA.separation >= sepB.separation * 0.95 + sepA.separation * 0.01) {\n ref = a;\n inc = b;\n refEdge = sepA.edge;\n refSwapped = false;\n } else {\n ref = b;\n inc = a;\n refEdge = sepB.edge;\n refSwapped = true;\n }\n\n const rv = ref.worldVertices;\n const rn = ref.worldNormals;\n const rc = countOf(ref);\n const i2 = (refEdge + 1) % rc;\n // refEdge/i2 in 0..rc-1, so these reads are in-bounds.\n const v1x = rv[refEdge * 2]!;\n const v1y = rv[refEdge * 2 + 1]!;\n const v2x = rv[i2 * 2]!;\n const v2y = rv[i2 * 2 + 1]!;\n const refNx = rn[refEdge * 2]!;\n const refNy = rn[refEdge * 2 + 1]!;\n\n const incident = _incidentScratch;\n findIncidentFace(refNx, refNy, inc, incident);\n\n // Reference-face tangent (the side-plane direction).\n let tx = v2x - v1x;\n let ty = v2y - v1y;\n // sqrt(x²+y²) over Math.hypot - avoids hypot's variadic/internal-allocation\n // path on the narrow-phase hot path; the operands are bounded edge lengths,\n // so the overflow protection hypot adds is not needed here.\n const tl = Math.sqrt(tx * tx + ty * ty);\n tx /= tl;\n ty /= tl;\n\n const negSide = -(tx * v1x + ty * v1y);\n const posSide = tx * v2x + ty * v2y;\n\n const clipped1 = _clipped1Scratch;\n\n if (clipSegment(-tx, -ty, negSide, incident, clipped1, encodeId(refSwapped, refEdge, 0xffe)) < 2) {\n return false;\n }\n\n const clipped2 = _clipped2Scratch;\n\n if (clipSegment(tx, ty, posSide, clipped1, clipped2, encodeId(refSwapped, refEdge, 0xfff)) < 2) {\n return false;\n }\n\n const flipNormal = refSwapped !== callerFlip;\n\n manifold.normalX = flipNormal ? -refNx : refNx;\n manifold.normalY = flipNormal ? -refNy : refNy;\n\n const refC = refNx * v1x + refNy * v1y;\n const incidentRadius = radiusOf(inc);\n const points = manifold.points;\n let cp = 0;\n\n for (let k = 0; k < 2; k++) {\n // clipped2 is a fixed 2-tuple; k in {0,1} so the clip vertex always exists.\n const cv = k === 0 ? clipped2[0] : clipped2[1];\n const separation = refNx * cv.x + refNy * cv.y - refC;\n\n if (separation <= totalRadius) {\n // The clip vertex lies on the incident CORE; pulling it back along the\n // reference normal by the incident radius puts it on that shape's real\n // surface. A radius-free incident polygon shifts by zero, so the point is\n // the clip vertex exactly as it was before capsules existed.\n // cp reaches at most 2 (one per clip vertex); points[0]/points[1] exist.\n const point = cp === 0 ? points[0] : points[1];\n point.x = cv.x - refNx * incidentRadius;\n point.y = cv.y - refNy * incidentRadius;\n point.penetration = totalRadius - separation;\n point.id = encodeId(refSwapped, refEdge, cv.id);\n cp++;\n }\n }\n\n manifold.pointCount = cp;\n\n return cp > 0;\n};\n\n/**\n * Boolean overlap test (no manifold) used by sensors and shape-overlap queries.\n * Exact for the circle/circle, circle/polygon and polygon/polygon pairs.\n */\nexport const testOverlap = (a: CollisionProxy, b: CollisionProxy): boolean => {\n const ta = a.shape.type;\n const tb = b.shape.type;\n const test = symmetricEntry(overlapTable, ta, tb);\n\n if (test === undefined) {\n return false;\n }\n\n return needsFlip(ta, tb) ? test(b, a) : test(a, b);\n};\n\nconst circlesOverlap: OverlapPair = (a, b) => {\n const ca = a.worldCenter;\n const cb = b.worldCenter;\n const rsum = radiusOf(a) + radiusOf(b);\n const dx = cb.x - ca.x;\n const dy = cb.y - ca.y;\n\n return dx * dx + dy * dy <= rsum * rsum;\n};\n\nconst roundedPolygonsOverlap: OverlapPair = (a, b) => {\n const totalRadius = radiusOf(a) + radiusOf(b);\n\n return findMaxSeparation(a, b, _sepA).separation < totalRadius && findMaxSeparation(b, a, _sepB).separation < totalRadius;\n};\n\n/**\n * Circle vs capsule: a capsule is every point within its radius of the spine, so\n * this is a circle/circle test against the spine point nearest the circle centre.\n * One contact point - a circle meets a rounded surface in one place, and a second\n * would be invented noise for the solver.\n */\nconst collideCircleSpine: CollidePair = (circle, spineShape, manifold, flip) => {\n const spine = spineShape.worldVertices;\n const centre = circle.worldCenter;\n const circleRadius = radiusOf(circle);\n const radiusSum = circleRadius + radiusOf(spineShape);\n\n closestPointOnSegment(centre.x, centre.y, spine[0]!, spine[1]!, spine[2]!, spine[3]!, _segmentScratch);\n\n let nx = _segmentScratch.x - centre.x;\n let ny = _segmentScratch.y - centre.y;\n const distanceSquared = nx * nx + ny * ny;\n\n if (distanceSquared > radiusSum * radiusSum) {\n return false;\n }\n\n const distance = Math.sqrt(distanceSquared);\n\n if (distance > eps) {\n nx /= distance;\n ny /= distance;\n } else {\n // Centre exactly on the spine: the direction is undefined, so take the\n // capsule's own side normal. It is stable from frame to frame, which an\n // axis-aligned guess would not be.\n nx = spineShape.worldNormals[0]!;\n ny = spineShape.worldNormals[1]!;\n }\n\n manifold.normalX = flip ? -nx : nx;\n manifold.normalY = flip ? -ny : ny;\n\n const point = manifold.points[0];\n // Midway between the two surfaces along the contact normal.\n const along = circleRadius + (distance - radiusSum) * 0.5;\n\n point.x = centre.x + nx * along;\n point.y = centre.y + ny * along;\n point.penetration = radiusSum - distance;\n point.id = 0;\n manifold.pointCount = 1;\n\n return true;\n};\n\nconst circleSpineOverlap: OverlapPair = (circle, spineShape) => {\n const spine = spineShape.worldVertices;\n const centre = circle.worldCenter;\n const radiusSum = radiusOf(circle) + radiusOf(spineShape);\n\n return pointSegmentDistanceSquared(centre.x, centre.y, spine[0]!, spine[1]!, spine[2]!, spine[3]!, _segmentScratch) <= radiusSum * radiusSum;\n};\n\nconst circlePolygonOverlap: OverlapPair = (circle, polygon) => {\n const c = circle.worldCenter;\n const r = radiusOf(circle);\n const verts = polygon.worldVertices;\n const normals = polygon.worldNormals;\n const count = countOf(polygon);\n\n let maxSep = -Infinity;\n let refEdge = 0;\n\n for (let i = 0; i < count; i++) {\n // Loop indices are provably in-bounds (0..count-1); the `!` is zero-cost.\n const enx = normals[i * 2]!;\n const eny = normals[i * 2 + 1]!;\n const evx = verts[i * 2]!;\n const evy = verts[i * 2 + 1]!;\n const s = enx * (c.x - evx) + eny * (c.y - evy);\n\n if (s > r) {\n return false;\n }\n\n if (s > maxSep) {\n maxSep = s;\n refEdge = i;\n }\n }\n\n if (maxSep < eps) {\n return true;\n }\n\n const j = (refEdge + 1) % count;\n const v1x = verts[refEdge * 2]!;\n const v1y = verts[refEdge * 2 + 1]!;\n const v2x = verts[j * 2]!;\n const v2y = verts[j * 2 + 1]!;\n const u1 = (c.x - v1x) * (v2x - v1x) + (c.y - v1y) * (v2y - v1y);\n const u2 = (c.x - v2x) * (v1x - v2x) + (c.y - v2y) * (v1y - v2y);\n\n if (u1 <= 0) {\n const dx = c.x - v1x;\n const dy = c.y - v1y;\n\n return dx * dx + dy * dy <= r * r;\n }\n\n if (u2 <= 0) {\n const dx = c.x - v2x;\n const dy = c.y - v2y;\n\n return dx * dx + dy * dy <= r * r;\n }\n\n return maxSep <= r;\n};\n\n// Pair tables, built once at module init. Every unordered pair the engine\n// supports appears exactly once; anything absent reports no contact.\nconst collideTable: PairTable<CollidePair> = symmetricTable<CollidePair>([\n ['circle', 'circle', collideCircles],\n ['circle', 'capsule', collideCircleSpine],\n ['circle', 'segment', collideCircleSpine],\n ['circle', 'polygon', collideCirclePolygon],\n ['capsule', 'capsule', collideRoundedPolygons],\n ['capsule', 'segment', collideRoundedPolygons],\n ['capsule', 'polygon', collideRoundedPolygons],\n // segment/segment is deliberately absent - see `collide`.\n ['segment', 'polygon', collideRoundedPolygons],\n ['polygon', 'polygon', collideRoundedPolygons],\n]);\n\nconst overlapTable: PairTable<OverlapPair> = symmetricTable<OverlapPair>([\n ['circle', 'circle', circlesOverlap],\n ['circle', 'capsule', circleSpineOverlap],\n ['circle', 'segment', circleSpineOverlap],\n ['circle', 'polygon', circlePolygonOverlap],\n ['capsule', 'capsule', roundedPolygonsOverlap],\n ['capsule', 'segment', roundedPolygonsOverlap],\n ['capsule', 'polygon', roundedPolygonsOverlap],\n ['segment', 'polygon', roundedPolygonsOverlap],\n ['polygon', 'polygon', roundedPolygonsOverlap],\n]);\n"],"mappings":";;;;;AASA,MAAM,MAAM;;AAGZ,MAAM,kBAA6B;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;;;AAqBhD,MAAa,WAAW,GAAmB,GAAmB,aAAgC;CAC5F,SAAS,MAAM;CAEf,MAAM,KAAK,EAAE,MAAM;CACnB,MAAM,KAAK,EAAE,MAAM;CACnB,MAAM,SAAS,eAAe,cAAc,IAAI,EAAE;CAElD,IAAI,WAAW,QACb,OAAO;CAKT,IAAI,EAFa,UAAU,IAAI,EAAE,IAAI,OAAO,GAAG,GAAG,UAAU,IAAI,IAAI,OAAO,GAAG,GAAG,UAAU,KAAK,IAG9F,OAAO;CAKT,IAAI,CAAC,gBAAgB,GAAG,SAAS,SAAS,SAAS,OAAO,KAAK,CAAC,gBAAgB,GAAG,CAAC,SAAS,SAAS,CAAC,SAAS,OAAO,GAAG;EACxH,SAAS,MAAM;EAEf,OAAO;CACT;CAEA,OAAO;AACT;AAMA,MAAM,YAAY,aAAsC,SAAS,MAAM,SAAS,YAAY,SAAS,MAAM,SAAS,YAAY,SAAS,MAAM,SAAS;AACxJ,MAAM,WAAW,aAAqC;CACpD,QAAQ,SAAS,MAAM,MAAvB;EACE,KAAK,WACH,OAA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nC;EAAC;EAAU;EAAW;CAAkB;CACxC;EAAC;EAAU;EAAW;CAAkB;CACxC;EAAC;EAAU;EAAW;CAAoB;CAC1C;EAAC;EAAW;EAAW;CAAsB;CAC7C;EAAC;EAAW;EAAW;CAAsB;CAC7C;EAAC;EAAW;EAAW;CAAsB;CAC7C;EAAC;EAAW;EAAW;CAAsB;CAC7C;EAAC;EAAW;EAAW;CAAsB;AAC/C,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { PointLike } from '@codexo/exojs';
2
- /**
3
- * Closest point on the segment `a → b` to `(px, py)`, written into `out`.
4
- * Returns the parameter along the segment, clamped to `[0, 1]`.
5
- */
6
- export declare const closestPointOnSegment: (px: number, py: number, ax: number, ay: number, bx: number, by: number, out: PointLike) => number;
7
- /** Squared distance from `(px, py)` to the segment `a → b`. */
8
- export declare const pointSegmentDistanceSquared: (px: number, py: number, ax: number, ay: number, bx: number, by: number, scratch: PointLike) => number;
9
- /**
10
- * Closest points between the segments `a0 → a1` and `b0 → b1`, written into
11
- * `outA` and `outB`. Returns the squared distance between them.
12
- *
13
- * Parallel and overlapping segments have a whole interval of closest pairs; this
14
- * returns one of them, chosen deterministically. Callers that need a stable
15
- * two-point manifold for such a case must derive it from the face geometry, not
16
- * from this single pair.
17
- */
18
- export declare const segmentSegmentDistanceSquared: (a0x: number, a0y: number, a1x: number, a1y: number, b0x: number, b0y: number, b1x: number, b1y: number, outA: PointLike, outB: PointLike) => number;
19
- //# sourceMappingURL=segments.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../../src/collision/segments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAW/C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,OAAQ,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,OAAO,SAAS,KAAG,MAkB9H,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,2BAA2B,OAAQ,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,WAAW,SAAS,KAAG,MAOxI,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,QACnC,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,QACL,SAAS,QACT,SAAS,KACd,MA4DF,CAAC"}
@@ -1,36 +0,0 @@
1
- //#region src/collision/segments.ts
2
- /** Below this squared length a segment is treated as a single point. */
3
- const degenerateLengthSquared = 1e-12;
4
- /**
5
- * Closest point on the segment `a → b` to `(px, py)`, written into `out`.
6
- * Returns the parameter along the segment, clamped to `[0, 1]`.
7
- */
8
- const closestPointOnSegment = (px, py, ax, ay, bx, by, out) => {
9
- const ex = bx - ax;
10
- const ey = by - ay;
11
- const lengthSquared = ex * ex + ey * ey;
12
- if (lengthSquared <= degenerateLengthSquared) {
13
- out.x = ax;
14
- out.y = ay;
15
- return 0;
16
- }
17
- const t = clamp01(((px - ax) * ex + (py - ay) * ey) / lengthSquared);
18
- out.x = ax + ex * t;
19
- out.y = ay + ey * t;
20
- return t;
21
- };
22
- /** Squared distance from `(px, py)` to the segment `a → b`. */
23
- const pointSegmentDistanceSquared = (px, py, ax, ay, bx, by, scratch) => {
24
- closestPointOnSegment(px, py, ax, ay, bx, by, scratch);
25
- const dx = px - scratch.x;
26
- const dy = py - scratch.y;
27
- return dx * dx + dy * dy;
28
- };
29
- const clamp01 = (value) => {
30
- if (value < 0) return 0;
31
- return value > 1 ? 1 : value;
32
- };
33
-
34
- //#endregion
35
- export { closestPointOnSegment, pointSegmentDistanceSquared };
36
- //# sourceMappingURL=segments.js.map