@flighthq/collision 0.2.1-next.841.373388f → 0.3.0-next.1032.e2b99fc

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 (51) hide show
  1. package/dist/collideContactManifold.d.ts +3 -0
  2. package/dist/collideContactManifold.d.ts.map +1 -0
  3. package/dist/collideContactManifold.js +109 -0
  4. package/dist/collideContactManifold.js.map +1 -0
  5. package/dist/contactFeatureId.d.ts +3 -0
  6. package/dist/contactFeatureId.d.ts.map +1 -0
  7. package/dist/contactFeatureId.js +26 -0
  8. package/dist/contactFeatureId.js.map +1 -0
  9. package/dist/contactManifold.d.ts +4 -0
  10. package/dist/contactManifold.d.ts.map +1 -0
  11. package/dist/contactManifold.js +30 -0
  12. package/dist/contactManifold.js.map +1 -0
  13. package/dist/contract.d.ts +9 -0
  14. package/dist/contract.d.ts.map +1 -0
  15. package/dist/contract.js +9 -0
  16. package/dist/contract.js.map +1 -0
  17. package/dist/convexVertices.d.ts +4 -0
  18. package/dist/convexVertices.d.ts.map +1 -0
  19. package/dist/convexVertices.js +41 -0
  20. package/dist/convexVertices.js.map +1 -0
  21. package/dist/index.d.ts +1 -5
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -5
  24. package/dist/index.js.map +1 -1
  25. package/dist/manifold.d.ts +1 -1
  26. package/dist/manifold.d.ts.map +1 -1
  27. package/dist/pointContainment.d.ts +1 -1
  28. package/dist/pointContainment.d.ts.map +1 -1
  29. package/dist/segmentCollision.d.ts +1 -1
  30. package/dist/segmentCollision.d.ts.map +1 -1
  31. package/dist/segmentCollision.js.map +1 -1
  32. package/dist/shapeCollision.d.ts +1 -1
  33. package/dist/shapeCollision.d.ts.map +1 -1
  34. package/dist/shapeCollision.js +2 -37
  35. package/dist/shapeCollision.js.map +1 -1
  36. package/dist/shapeContact.d.ts +12 -0
  37. package/dist/shapeContact.d.ts.map +1 -0
  38. package/dist/shapeContact.js +331 -0
  39. package/dist/shapeContact.js.map +1 -0
  40. package/dist/testCollision.d.ts +1 -1
  41. package/dist/testCollision.d.ts.map +1 -1
  42. package/package.json +7 -3
  43. package/src/collideContactManifold.test.ts +133 -0
  44. package/src/contactFeatureId.test.ts +50 -0
  45. package/src/contactManifold.test.ts +55 -0
  46. package/src/convexVertices.test.ts +55 -0
  47. package/src/pointContainment.test.ts +1 -1
  48. package/src/segmentCollision.test.ts +7 -1
  49. package/src/shapeCollision.test.ts +1 -1
  50. package/src/shapeContact.test.ts +422 -0
  51. package/src/testCollision.test.ts +1 -1
@@ -0,0 +1,331 @@
1
+ import { FEATURE_INDEX_LIMIT, packContactFeatureId } from './contactFeatureId';
2
+ import { clearCollisionContactManifold } from './contactManifold';
3
+ import { writeAabbVertices, writeObbVertices } from './convexVertices';
4
+ import { createCollisionManifold } from './manifold';
5
+ import { testCircleAabbCollision, testCircleCircleCollision, testCircleObbCollision, testCirclePolygonCollision, } from './shapeCollision';
6
+ // The 2D narrow-phase contact tests — the same ten manifold-bearing pairs as the `test*Collision`
7
+ // family, but resolving the full contact set instead of only the minimum-translation vector. Each
8
+ // writes an `out` CollisionContactManifold and returns whether the pair overlaps; the normal, depth,
9
+ // and touching-is-not-overlapping convention match `test*Collision` exactly.
10
+ //
11
+ // These are a strict superset of the lean tests and cost more: convex pairs run reference/incident
12
+ // face selection and segment clipping on top of the separating-axis search. They live in their own
13
+ // module, and take their own entry points, so a bundle that only asks "do these overlap?" links the
14
+ // lean path alone and never pays for the clipping machinery. Reach for these when simulating the
15
+ // pair (a rigid-body solver needs a point to apply an impulse at); reach for `test*Collision` when
16
+ // merely detecting it.
17
+ //
18
+ // Convex pairs resolve up to two points by clipping the incident face against the reference face's
19
+ // side planes. Circle pairs are single-point by construction: a circle touches a convex shape along
20
+ // one surface point.
21
+ // Axis-aligned box vs axis-aligned box.
22
+ export function collideAabbAabbContactManifold(a, b, out) {
23
+ writeAabbVertices(a, contactScratchA);
24
+ writeAabbVertices(b, contactScratchB);
25
+ return convexContact(contactScratchA, 4, contactScratchB, 4, out);
26
+ }
27
+ // Axis-aligned box vs oriented box.
28
+ export function collideAabbObbContactManifold(a, b, out) {
29
+ writeAabbVertices(a, contactScratchA);
30
+ writeObbVertices(b, contactScratchB);
31
+ return convexContact(contactScratchA, 4, contactScratchB, 4, out);
32
+ }
33
+ // Axis-aligned box vs convex polygon.
34
+ export function collideAabbPolygonContactManifold(a, b, out) {
35
+ writeAabbVertices(a, contactScratchA);
36
+ const bPoints = b.points;
37
+ return convexContact(contactScratchA, 4, bPoints, bPoints.length >> 1, out);
38
+ }
39
+ // Circle vs axis-aligned box. One contact point, on the circle's surface.
40
+ export function collideCircleAabbContactManifold(a, b, out) {
41
+ if (!testCircleAabbCollision(a, b, leanScratch)) {
42
+ clearCollisionContactManifold(out);
43
+ return false;
44
+ }
45
+ return writeCircleContact(a.x, a.y, a.radius, out);
46
+ }
47
+ // Circle vs circle. One contact point, on A's surface.
48
+ export function collideCircleCircleContactManifold(a, b, out) {
49
+ if (!testCircleCircleCollision(a, b, leanScratch)) {
50
+ clearCollisionContactManifold(out);
51
+ return false;
52
+ }
53
+ return writeCircleContact(a.x, a.y, a.radius, out);
54
+ }
55
+ // Circle vs oriented box. One contact point, on the circle's surface.
56
+ export function collideCircleObbContactManifold(a, b, out) {
57
+ if (!testCircleObbCollision(a, b, leanScratch)) {
58
+ clearCollisionContactManifold(out);
59
+ return false;
60
+ }
61
+ return writeCircleContact(a.x, a.y, a.radius, out);
62
+ }
63
+ // Circle vs convex polygon. One contact point, on the circle's surface.
64
+ export function collideCirclePolygonContactManifold(a, b, out) {
65
+ if (!testCirclePolygonCollision(a, b, leanScratch)) {
66
+ clearCollisionContactManifold(out);
67
+ return false;
68
+ }
69
+ return writeCircleContact(a.x, a.y, a.radius, out);
70
+ }
71
+ // Oriented box vs oriented box.
72
+ export function collideObbObbContactManifold(a, b, out) {
73
+ writeObbVertices(a, contactScratchA);
74
+ writeObbVertices(b, contactScratchB);
75
+ return convexContact(contactScratchA, 4, contactScratchB, 4, out);
76
+ }
77
+ // Oriented box vs convex polygon.
78
+ export function collideObbPolygonContactManifold(a, b, out) {
79
+ writeObbVertices(a, contactScratchA);
80
+ const bPoints = b.points;
81
+ return convexContact(contactScratchA, 4, bPoints, bPoints.length >> 1, out);
82
+ }
83
+ // Convex polygon vs convex polygon — the general convex contact core.
84
+ export function collidePolygonPolygonContactManifold(a, b, out) {
85
+ const aPoints = a.points;
86
+ const bPoints = b.points;
87
+ return convexContact(aPoints, aPoints.length >> 1, bPoints, bPoints.length >> 1, out);
88
+ }
89
+ // Convex-vs-convex contact resolution over two flat `[x0,y0,...]` vertex lists, writing the
90
+ // manifold pushing **A out of B**.
91
+ //
92
+ // The separating-axis search runs per shape and reports the *least negative* separation — the
93
+ // shallowest face, which is the axis a solver must push along. The shape owning that face is the
94
+ // **reference**; the other is the **incident**, and its most anti-parallel face is the one actually
95
+ // in contact. Clipping that incident face against the reference face's two side planes leaves the
96
+ // overlapping span, whose endpoints (those still behind the reference face) are the contact points.
97
+ // This is the standard 2D face-clipping construction; the one-point cases fall out of it naturally
98
+ // when the clip collapses to a corner.
99
+ function convexContact(ax, an, bx, bn, out) {
100
+ // Fewer than three vertices has no interior and no face to clip against. Degenerate input would
101
+ // otherwise leave the separation search with no candidate axis and poison the manifold with NaN,
102
+ // which in a physics step is unrecoverable — report a clean miss instead. Past FEATURE_INDEX_LIMIT
103
+ // the face indices no longer pack into distinct feature ids, and a silently aliased id is worse than
104
+ // a reported miss: the solver would warm-start a contact from an unrelated contact's impulse.
105
+ if (an < 3 || bn < 3 || an > FEATURE_INDEX_LIMIT || bn > FEATURE_INDEX_LIMIT) {
106
+ clearCollisionContactManifold(out);
107
+ return false;
108
+ }
109
+ const separationA = maxFaceSeparation(ax, an, bx, bn);
110
+ if (separationA >= 0 || separationEdge < 0) {
111
+ clearCollisionContactManifold(out);
112
+ return false;
113
+ }
114
+ const edgeA = separationEdge;
115
+ const normalAX = separationNormalX;
116
+ const normalAY = separationNormalY;
117
+ const separationB = maxFaceSeparation(bx, bn, ax, an);
118
+ if (separationB >= 0 || separationEdge < 0) {
119
+ clearCollisionContactManifold(out);
120
+ return false;
121
+ }
122
+ const edgeB = separationEdge;
123
+ // Near-ties get a magnitude-relative nudge toward A so the reference shape does not flip between
124
+ // frames on floating-point noise. A flip renumbers every feature id, which would silently discard
125
+ // the solver's warm-start impulses and make a resting stack jitter.
126
+ const magnitude = Math.abs(separationA) > Math.abs(separationB) ? Math.abs(separationA) : Math.abs(separationB);
127
+ const referenceIsA = separationB <= separationA + REFERENCE_BIAS * magnitude;
128
+ const referenceX = referenceIsA ? ax : bx;
129
+ const referenceCount = referenceIsA ? an : bn;
130
+ const incidentX = referenceIsA ? bx : ax;
131
+ const incidentCount = referenceIsA ? bn : an;
132
+ const referenceEdge = referenceIsA ? edgeA : edgeB;
133
+ const normalX = referenceIsA ? normalAX : separationNormalX;
134
+ const normalY = referenceIsA ? normalAY : separationNormalY;
135
+ const referenceNext = referenceEdge + 1 === referenceCount ? 0 : referenceEdge + 1;
136
+ const v1X = referenceX[referenceEdge << 1];
137
+ const v1Y = referenceX[(referenceEdge << 1) + 1];
138
+ const v2X = referenceX[referenceNext << 1];
139
+ const v2Y = referenceX[(referenceNext << 1) + 1];
140
+ const incidentEdge = mostAntiParallelEdge(incidentX, incidentCount, normalX, normalY);
141
+ const incidentNext = incidentEdge + 1 === incidentCount ? 0 : incidentEdge + 1;
142
+ const p0X = incidentX[incidentEdge << 1];
143
+ const p0Y = incidentX[(incidentEdge << 1) + 1];
144
+ const p1X = incidentX[incidentNext << 1];
145
+ const p1Y = incidentX[(incidentNext << 1) + 1];
146
+ // The reference face's own extent along its tangent bounds the contact span; the incident segment
147
+ // is clipped to it in parameter space, which keeps both endpoints on the incident surface.
148
+ let tangentX = v2X - v1X;
149
+ let tangentY = v2Y - v1Y;
150
+ const tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
151
+ if (tangentLength <= EPS) {
152
+ clearCollisionContactManifold(out);
153
+ return false;
154
+ }
155
+ tangentX /= tangentLength;
156
+ tangentY /= tangentLength;
157
+ const low = tangentX * v1X + tangentY * v1Y;
158
+ const high = tangentX * v2X + tangentY * v2Y;
159
+ const t0 = tangentX * p0X + tangentY * p0Y;
160
+ const t1 = tangentX * p1X + tangentY * p1Y;
161
+ let clipStart = 0;
162
+ let clipEnd = 1;
163
+ const tangentSpan = t1 - t0;
164
+ if (Math.abs(tangentSpan) > EPS) {
165
+ const sLow = (low - t0) / tangentSpan;
166
+ const sHigh = (high - t0) / tangentSpan;
167
+ const sMin = sLow < sHigh ? sLow : sHigh;
168
+ const sMax = sLow < sHigh ? sHigh : sLow;
169
+ if (sMin > clipStart)
170
+ clipStart = sMin;
171
+ if (sMax < clipEnd)
172
+ clipEnd = sMax;
173
+ }
174
+ else if (t0 < low - EPS || t0 > high + EPS) {
175
+ clipStart = 1;
176
+ clipEnd = 0;
177
+ }
178
+ // The MTV normal is the reference face's outward normal, which points from the reference shape
179
+ // toward the incident one. Pushing A out of B therefore means negating it exactly when A is the
180
+ // reference shape.
181
+ const referenceSeparation = referenceIsA ? separationA : separationB;
182
+ out.normalX = referenceIsA ? -normalX : normalX;
183
+ out.normalY = referenceIsA ? -normalY : normalY;
184
+ out.depth = -referenceSeparation;
185
+ out.overlapping = true;
186
+ out.pointCount = 0;
187
+ if (clipStart <= clipEnd) {
188
+ const first = packContactFeatureId(referenceIsA, referenceEdge, incidentEdge, false);
189
+ appendClippedContact(p0X, p0Y, p1X, p1Y, clipStart, v1X, v1Y, normalX, normalY, first, out);
190
+ if (clipEnd > clipStart) {
191
+ const second = packContactFeatureId(referenceIsA, referenceEdge, incidentEdge, true);
192
+ appendClippedContact(p0X, p0Y, p1X, p1Y, clipEnd, v1X, v1Y, normalX, normalY, second, out);
193
+ }
194
+ }
195
+ return true;
196
+ }
197
+ // Evaluates the clipped incident point at parameter `s` and appends it when it lies behind the
198
+ // reference face (that is, actually penetrating). Points that clip into the face's span but sit in
199
+ // front of it are separated at that end of the contact and carry no impulse.
200
+ function appendClippedContact(p0X, p0Y, p1X, p1Y, s, faceX, faceY, normalX, normalY, featureId, out) {
201
+ const x = p0X + (p1X - p0X) * s;
202
+ const y = p0Y + (p1Y - p0Y) * s;
203
+ const separation = normalX * (x - faceX) + normalY * (y - faceY);
204
+ if (separation > 0)
205
+ return;
206
+ const point = out.points[out.pointCount];
207
+ point.x = x;
208
+ point.y = y;
209
+ point.depth = -separation;
210
+ point.featureId = featureId;
211
+ out.pointCount++;
212
+ }
213
+ // Returns the greatest separation of shape O from any face of shape S, writing the winning face's
214
+ // index and unit outward normal into the module scratch. A positive result means a separating axis
215
+ // exists and the pair is disjoint; the least-negative result is the minimum-translation face.
216
+ // Outward orientation is derived from S's centroid, so winding does not matter — matching the
217
+ // winding-agnostic contract the lean tests already document.
218
+ function maxFaceSeparation(sx, sn, ox, on) {
219
+ let centroidX = 0;
220
+ let centroidY = 0;
221
+ for (let i = 0; i < sn; i++) {
222
+ centroidX += sx[i << 1];
223
+ centroidY += sx[(i << 1) + 1];
224
+ }
225
+ centroidX /= sn;
226
+ centroidY /= sn;
227
+ let best = -Infinity;
228
+ let bestEdge = -1;
229
+ let bestNormalX = 0;
230
+ let bestNormalY = 0;
231
+ for (let i = 0; i < sn; i++) {
232
+ const j = i + 1 === sn ? 0 : i + 1;
233
+ const x0 = sx[i << 1];
234
+ const y0 = sx[(i << 1) + 1];
235
+ let normalX = sx[(j << 1) + 1] - y0;
236
+ let normalY = x0 - sx[j << 1];
237
+ const length = Math.sqrt(normalX * normalX + normalY * normalY);
238
+ if (length <= EPS)
239
+ continue;
240
+ normalX /= length;
241
+ normalY /= length;
242
+ if (normalX * (x0 - centroidX) + normalY * (y0 - centroidY) < 0) {
243
+ normalX = -normalX;
244
+ normalY = -normalY;
245
+ }
246
+ let separation = Infinity;
247
+ for (let k = 0; k < on; k++) {
248
+ const projected = normalX * (ox[k << 1] - x0) + normalY * (ox[(k << 1) + 1] - y0);
249
+ if (projected < separation)
250
+ separation = projected;
251
+ }
252
+ if (separation > best) {
253
+ best = separation;
254
+ bestEdge = i;
255
+ bestNormalX = normalX;
256
+ bestNormalY = normalY;
257
+ }
258
+ }
259
+ separationEdge = bestEdge;
260
+ separationNormalX = bestNormalX;
261
+ separationNormalY = bestNormalY;
262
+ return best;
263
+ }
264
+ // Returns the index of the shape's face whose outward normal opposes (`normalX`,`normalY`) most
265
+ // directly — the face lying against the reference face, and so the one to clip.
266
+ function mostAntiParallelEdge(px, pn, normalX, normalY) {
267
+ let centroidX = 0;
268
+ let centroidY = 0;
269
+ for (let i = 0; i < pn; i++) {
270
+ centroidX += px[i << 1];
271
+ centroidY += px[(i << 1) + 1];
272
+ }
273
+ centroidX /= pn;
274
+ centroidY /= pn;
275
+ let best = Infinity;
276
+ let bestEdge = 0;
277
+ for (let i = 0; i < pn; i++) {
278
+ const j = i + 1 === pn ? 0 : i + 1;
279
+ const x0 = px[i << 1];
280
+ const y0 = px[(i << 1) + 1];
281
+ let edgeNormalX = px[(j << 1) + 1] - y0;
282
+ let edgeNormalY = x0 - px[j << 1];
283
+ const length = Math.sqrt(edgeNormalX * edgeNormalX + edgeNormalY * edgeNormalY);
284
+ if (length <= EPS)
285
+ continue;
286
+ edgeNormalX /= length;
287
+ edgeNormalY /= length;
288
+ if (edgeNormalX * (x0 - centroidX) + edgeNormalY * (y0 - centroidY) < 0) {
289
+ edgeNormalX = -edgeNormalX;
290
+ edgeNormalY = -edgeNormalY;
291
+ }
292
+ const alignment = edgeNormalX * normalX + edgeNormalY * normalY;
293
+ if (alignment < best) {
294
+ best = alignment;
295
+ bestEdge = i;
296
+ }
297
+ }
298
+ return bestEdge;
299
+ }
300
+ // Promotes the lean manifold left in `leanScratch` by a circle test into a single-point contact.
301
+ // The circle's deepest point lies one radius along the inward normal from its center; a circle has
302
+ // no face, so there is one feature pair and one constant id.
303
+ function writeCircleContact(cx, cy, radius, out) {
304
+ const normalX = leanScratch.normalX;
305
+ const normalY = leanScratch.normalY;
306
+ const depth = leanScratch.depth;
307
+ out.normalX = normalX;
308
+ out.normalY = normalY;
309
+ out.depth = depth;
310
+ out.overlapping = true;
311
+ const point = out.points[0];
312
+ point.x = cx - normalX * radius;
313
+ point.y = cy - normalY * radius;
314
+ point.depth = depth;
315
+ point.featureId = 0;
316
+ out.pointCount = 1;
317
+ return true;
318
+ }
319
+ const EPS = 1e-9;
320
+ // Fraction of the deeper separation by which the reference face must be beaten before the incident
321
+ // shape takes over as reference. Relative rather than absolute so it holds at any world scale.
322
+ const REFERENCE_BIAS = 1e-6;
323
+ // Feature ids pack (reference shape, reference edge, incident edge, clip slot) into one integer.
324
+ // Ten bits per edge index covers any polygon the SAT core can handle in useful time.
325
+ const contactScratchA = new Float64Array(8);
326
+ const contactScratchB = new Float64Array(8);
327
+ const leanScratch = createCollisionManifold();
328
+ let separationEdge = -1;
329
+ let separationNormalX = 0;
330
+ let separationNormalY = 0;
331
+ //# sourceMappingURL=shapeContact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shapeContact.js","sourceRoot":"","sources":["../src/shapeContact.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAE1B,kGAAkG;AAClG,kGAAkG;AAClG,qGAAqG;AACrG,6EAA6E;AAC7E,EAAE;AACF,mGAAmG;AACnG,mGAAmG;AACnG,oGAAoG;AACpG,iGAAiG;AACjG,mGAAmG;AACnG,uBAAuB;AACvB,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG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;AAC5B,iGAAiG;AACjG,qFAAqF;AACrF,MAAM,eAAe,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AAC5C,MAAM,eAAe,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAsB,uBAAuB,EAAE,CAAC;AACjE,IAAI,cAAc,GAAG,CAAC,CAAC,CAAC;AACxB,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAC1B,IAAI,iBAAiB,GAAG,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
- import type { CollisionManifold, CollisionShape } from '@flighthq/types';
1
+ import type { CollisionManifold, CollisionShape } from '@flighthq/types/contract';
2
2
  export declare function testCollision(a: Readonly<CollisionShape>, b: Readonly<CollisionShape>, out: CollisionManifold): boolean;
3
3
  //# sourceMappingURL=testCollision.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testCollision.d.ts","sourceRoot":"","sources":["../src/testCollision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAsB,MAAM,iBAAiB,CAAC;AAuB7F,wBAAgB,aAAa,CAC3B,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC3B,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC3B,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAiET"}
1
+ {"version":3,"file":"testCollision.d.ts","sourceRoot":"","sources":["../src/testCollision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAsB,MAAM,0BAA0B,CAAC;AAuBtG,wBAAgB,aAAa,CAC3B,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC3B,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC3B,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAiET"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/collision",
3
- "version": "0.2.1-next.841.373388f",
3
+ "version": "0.3.0-next.1032.e2b99fc",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/flighthq/flight.git",
@@ -13,6 +13,10 @@
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
15
  "default": "./dist/index.js"
16
+ },
17
+ "./contract": {
18
+ "types": "./dist/contract.d.ts",
19
+ "default": "./dist/contract.js"
16
20
  }
17
21
  },
18
22
  "files": [
@@ -32,8 +36,8 @@
32
36
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
33
37
  },
34
38
  "dependencies": {
35
- "@flighthq/geometry": "0.2.1-next.841.373388f",
36
- "@flighthq/types": "0.2.1-next.841.373388f"
39
+ "@flighthq/geometry": "0.3.0-next.1032.e2b99fc",
40
+ "@flighthq/types": "0.3.0-next.1032.e2b99fc"
37
41
  },
38
42
  "devDependencies": {
39
43
  "typescript": "^5.3.0"
@@ -0,0 +1,133 @@
1
+ import type { CollisionShape } from '@flighthq/types/contract';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { collideContactManifold } from './collideContactManifold';
5
+ import { createCollisionContactManifold } from './contactManifold';
6
+ import { collideAabbAabbContactManifold, collideCircleAabbContactManifold } from './shapeContact';
7
+
8
+ describe('collideContactManifold', () => {
9
+ it('dispatches a box-box pair to the same contact as the direct function', () => {
10
+ const dispatched = createCollisionContactManifold();
11
+ const direct = createCollisionContactManifold();
12
+ const box: CollisionShape = { kind: 'aabb', minX: 0, minY: -0.1, maxX: 2, maxY: 1.9 };
13
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
14
+
15
+ expect(collideContactManifold(box, ground, dispatched)).toBe(true);
16
+ expect(collideAabbAabbContactManifold(box, ground, direct)).toBe(true);
17
+ expect(dispatched.normalY).toBeCloseTo(direct.normalY);
18
+ expect(dispatched.depth).toBeCloseTo(direct.depth);
19
+ expect(dispatched.pointCount).toBe(direct.pointCount);
20
+ for (let i = 0; i < direct.pointCount; i++) {
21
+ expect(dispatched.points[i].x).toBeCloseTo(direct.points[i].x);
22
+ expect(dispatched.points[i].y).toBeCloseTo(direct.points[i].y);
23
+ }
24
+ });
25
+
26
+ it('dispatches a circle-box pair given in either kind order', () => {
27
+ const dispatched = createCollisionContactManifold();
28
+ const direct = createCollisionContactManifold();
29
+ const circle: CollisionShape = { kind: 'circle', x: 0, y: 0.9, radius: 1 };
30
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
31
+
32
+ expect(collideContactManifold(circle, ground, dispatched)).toBe(true);
33
+ expect(collideCircleAabbContactManifold(circle, ground, direct)).toBe(true);
34
+ expect(dispatched.normalY).toBeCloseTo(direct.normalY);
35
+ expect(dispatched.points[0].y).toBeCloseTo(direct.points[0].y);
36
+ });
37
+
38
+ it('negates the normal but keeps the world-space points when the pair arrives reversed', () => {
39
+ const forward = createCollisionContactManifold();
40
+ const reversed = createCollisionContactManifold();
41
+ const circle: CollisionShape = { kind: 'circle', x: 0, y: 0.9, radius: 1 };
42
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
43
+
44
+ expect(collideContactManifold(circle, ground, forward)).toBe(true);
45
+ expect(collideContactManifold(ground, circle, reversed)).toBe(true);
46
+ expect(reversed.normalX).toBeCloseTo(-forward.normalX);
47
+ expect(reversed.normalY).toBeCloseTo(-forward.normalY);
48
+ expect(reversed.depth).toBeCloseTo(forward.depth);
49
+ expect(reversed.points[0].x).toBeCloseTo(forward.points[0].x);
50
+ expect(reversed.points[0].y).toBeCloseTo(forward.points[0].y);
51
+ });
52
+
53
+ it('assigns identical feature ids to a mixed-kind pair given in either order', () => {
54
+ // Different kinds are ordered by kind rank before dispatch, so the same shape owns the reference
55
+ // face either way round and the ids are genuinely order-invariant.
56
+ const forward = createCollisionContactManifold();
57
+ const reversed = createCollisionContactManifold();
58
+ const box: CollisionShape = { kind: 'aabb', minX: 0, minY: -0.1, maxX: 2, maxY: 1.9 };
59
+ const ground: CollisionShape = { kind: 'polygon', points: [-5, -1, 5, -1, 5, 0, -5, 0] };
60
+
61
+ expect(collideContactManifold(box, ground, forward)).toBe(true);
62
+ expect(collideContactManifold(ground, box, reversed)).toBe(true);
63
+ expect(reversed.pointCount).toBe(forward.pointCount);
64
+ for (let i = 0; i < forward.pointCount; i++) {
65
+ expect(reversed.points[i].featureId).toBe(forward.points[i].featureId);
66
+ expect(reversed.points[i].x).toBeCloseTo(forward.points[i].x);
67
+ expect(reversed.points[i].y).toBeCloseTo(forward.points[i].y);
68
+ }
69
+ });
70
+
71
+ it('keeps overlap, normal and depth order-invariant for a same-kind pair, but not point identity', () => {
72
+ // Two AABBs tie exactly on separation, so the reference face resolves toward the first argument and
73
+ // the contact points land on whichever surface that selects. The pair-level answer is unchanged —
74
+ // the normal negates and the depth is equal — while the points sit one penetration depth apart and
75
+ // carry different ids. Pinned deliberately: a caller keying a warm-start cache on these ids must
76
+ // supply a stable argument order, and this is the behaviour it would otherwise be surprised by.
77
+ const forward = createCollisionContactManifold();
78
+ const reversed = createCollisionContactManifold();
79
+ const box: CollisionShape = { kind: 'aabb', minX: 0, minY: -0.1, maxX: 2, maxY: 1.9 };
80
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
81
+
82
+ expect(collideContactManifold(box, ground, forward)).toBe(true);
83
+ expect(collideContactManifold(ground, box, reversed)).toBe(true);
84
+ expect(reversed.normalX).toBeCloseTo(-forward.normalX);
85
+ expect(reversed.normalY).toBeCloseTo(-forward.normalY);
86
+ expect(reversed.depth).toBeCloseTo(forward.depth);
87
+ expect(reversed.pointCount).toBe(forward.pointCount);
88
+ expect(reversed.points[0].y).toBeCloseTo(forward.points[0].y - forward.depth);
89
+ expect(reversed.points[0].featureId).not.toBe(forward.points[0].featureId);
90
+ });
91
+
92
+ it('is bit-for-bit repeatable for a fixed argument order', () => {
93
+ // The stability a warm-start cache actually depends on: the same call, made again, produces the
94
+ // same ids and the same points. Order-invariance is the caller's to arrange; repeatability is ours.
95
+ const first = createCollisionContactManifold();
96
+ const second = createCollisionContactManifold();
97
+ const box: CollisionShape = { kind: 'aabb', minX: 0, minY: -0.1, maxX: 2, maxY: 1.9 };
98
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
99
+
100
+ expect(collideContactManifold(box, ground, first)).toBe(true);
101
+ expect(collideContactManifold(box, ground, second)).toBe(true);
102
+ expect(second.pointCount).toBe(first.pointCount);
103
+ for (let i = 0; i < first.pointCount; i++) {
104
+ expect(second.points[i].featureId).toBe(first.points[i].featureId);
105
+ expect(second.points[i].x).toBe(first.points[i].x);
106
+ expect(second.points[i].y).toBe(first.points[i].y);
107
+ expect(second.points[i].depth).toBe(first.points[i].depth);
108
+ }
109
+ });
110
+
111
+ it('reports area-less kinds as non-overlapping and carrying no contact', () => {
112
+ const out = createCollisionContactManifold();
113
+ const segment: CollisionShape = { kind: 'segment', x0: 0, y0: 0, x1: 5, y1: 5 };
114
+ const box: CollisionShape = { kind: 'aabb', minX: 0, minY: 0, maxX: 10, maxY: 10 };
115
+ expect(collideContactManifold(segment, box, out)).toBe(false);
116
+ expect(out.overlapping).toBe(false);
117
+ expect(out.pointCount).toBe(0);
118
+
119
+ const point: CollisionShape = { kind: 'point', x: 1, y: 1 };
120
+ expect(collideContactManifold(point, box, out)).toBe(false);
121
+ expect(out.pointCount).toBe(0);
122
+ });
123
+
124
+ it('clears a previously populated manifold when the pair separates', () => {
125
+ const out = createCollisionContactManifold();
126
+ const ground: CollisionShape = { kind: 'aabb', minX: -5, minY: -1, maxX: 5, maxY: 0 };
127
+ expect(collideContactManifold({ kind: 'aabb', minX: 0, minY: -0.1, maxX: 2, maxY: 1.9 }, ground, out)).toBe(true);
128
+ expect(out.pointCount).toBe(2);
129
+ expect(collideContactManifold({ kind: 'aabb', minX: 0, minY: 9, maxX: 2, maxY: 11 }, ground, out)).toBe(false);
130
+ expect(out.pointCount).toBe(0);
131
+ expect(out.depth).toBe(0);
132
+ });
133
+ });
@@ -0,0 +1,50 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { FEATURE_INDEX_LIMIT, packContactFeatureId } from './contactFeatureId';
4
+
5
+ describe('packContactFeatureId', () => {
6
+ it('separates the exact face pairs the previous shift packing aliased', () => {
7
+ // The reported regression, stated as arithmetic rather than hoped for through geometry: shifting an
8
+ // unmasked incident index left by 1 into a 10-bit field spilled it into the reference field, so face
9
+ // pair (0, 1024) and face pair (1, 0) produced one id. A solver keyed on that id would warm-start
10
+ // one contact with an impulse belonging to a different pair of faces entirely.
11
+ expect(((0 << 11) | (1024 << 1)) === ((1 << 11) | (0 << 1))).toBe(true); // the old collision
12
+ expect(packContactFeatureId(true, 0, 1024, false)).not.toBe(packContactFeatureId(true, 1, 0, false));
13
+ });
14
+
15
+ it('gives every distinct feature its own id across the packing boundaries', () => {
16
+ // Sweeps each field across the values where a fixed-width packing wraps — its own boundary and the
17
+ // one below it — and checks the whole cross product collides nowhere.
18
+ const edges = [0, 1, 2, 1023, 1024, 1025, 2047, 2048, FEATURE_INDEX_LIMIT - 1];
19
+ const seen = new Map<number, string>();
20
+ for (const referenceIsA of [false, true]) {
21
+ for (const referenceEdge of edges) {
22
+ for (const incidentEdge of edges) {
23
+ for (const secondPoint of [false, true]) {
24
+ const id = packContactFeatureId(referenceIsA, referenceEdge, incidentEdge, secondPoint);
25
+ const key = `${referenceIsA}/${referenceEdge}/${incidentEdge}/${secondPoint}`;
26
+ expect(seen.get(id)).toBeUndefined();
27
+ seen.set(id, key);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ expect(seen.size).toBe(2 * edges.length * edges.length * 2);
33
+ });
34
+
35
+ it('stays an exactly representable integer at the widest packing', () => {
36
+ // Every id must survive as an exact integer: one rounded id is two features sharing an identity.
37
+ const widest = packContactFeatureId(true, FEATURE_INDEX_LIMIT - 1, FEATURE_INDEX_LIMIT - 1, true);
38
+ expect(Number.isSafeInteger(widest)).toBe(true);
39
+ expect(widest).toBeLessThan(Number.MAX_SAFE_INTEGER);
40
+ expect(widest + 1).not.toBe(widest);
41
+ });
42
+
43
+ it('distinguishes the two contact points of one face pair', () => {
44
+ expect(packContactFeatureId(true, 3, 7, false)).not.toBe(packContactFeatureId(true, 3, 7, true));
45
+ });
46
+
47
+ it('distinguishes which shape owned the reference face', () => {
48
+ expect(packContactFeatureId(false, 3, 7, false)).not.toBe(packContactFeatureId(true, 3, 7, false));
49
+ });
50
+ });
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { clearCollisionContactManifold, createCollisionContactManifold } from './contactManifold';
4
+
5
+ describe('clearCollisionContactManifold', () => {
6
+ it('resets the manifold to the non-overlapping state', () => {
7
+ const manifold = createCollisionContactManifold();
8
+ manifold.overlapping = true;
9
+ manifold.normalX = 1;
10
+ manifold.normalY = -1;
11
+ manifold.depth = 4;
12
+ manifold.pointCount = 2;
13
+
14
+ clearCollisionContactManifold(manifold);
15
+ expect(manifold.overlapping).toBe(false);
16
+ expect(manifold.normalX).toBe(0);
17
+ expect(manifold.normalY).toBe(0);
18
+ expect(manifold.depth).toBe(0);
19
+ expect(manifold.pointCount).toBe(0);
20
+ });
21
+
22
+ it('keeps the point array allocated so a cleared manifold stays reusable', () => {
23
+ const manifold = createCollisionContactManifold();
24
+ const points = manifold.points;
25
+ clearCollisionContactManifold(manifold);
26
+ expect(manifold.points).toBe(points);
27
+ expect(manifold.points).toHaveLength(2);
28
+ });
29
+ });
30
+
31
+ describe('createCollisionContactManifold', () => {
32
+ it('starts non-overlapping with zeroed normal, depth, and point count', () => {
33
+ const manifold = createCollisionContactManifold();
34
+ expect(manifold.overlapping).toBe(false);
35
+ expect(manifold.normalX).toBe(0);
36
+ expect(manifold.normalY).toBe(0);
37
+ expect(manifold.depth).toBe(0);
38
+ expect(manifold.pointCount).toBe(0);
39
+ });
40
+
41
+ it('preallocates both contact points so the hot path never allocates', () => {
42
+ const manifold = createCollisionContactManifold();
43
+ expect(manifold.points).toHaveLength(2);
44
+ for (const point of manifold.points) {
45
+ expect(point).toEqual({ x: 0, y: 0, depth: 0, featureId: 0 });
46
+ }
47
+ });
48
+
49
+ it('gives each manifold its own points rather than sharing one array', () => {
50
+ const first = createCollisionContactManifold();
51
+ const second = createCollisionContactManifold();
52
+ expect(first.points).not.toBe(second.points);
53
+ expect(first.points[0]).not.toBe(second.points[0]);
54
+ });
55
+ });