@flighthq/collision 0.3.1-next.975.01aea94 → 0.4.0-next.1261.f361161

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/collision",
3
- "version": "0.3.1-next.975.01aea94",
3
+ "version": "0.4.0-next.1261.f361161",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,9 +38,9 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/geometry": "0.3.1-next.975.01aea94",
42
- "@flighthq/log": "0.3.1-next.975.01aea94",
43
- "@flighthq/types": "0.3.1-next.975.01aea94"
41
+ "@flighthq/geometry": "0.4.0-next.1261.f361161",
42
+ "@flighthq/log": "0.4.0-next.1261.f361161",
43
+ "@flighthq/types": "0.4.0-next.1261.f361161"
44
44
  },
45
45
  "devDependencies": {
46
46
  "typescript": "^5.3.0"
@@ -129,5 +129,61 @@ describe('collideContactManifold', () => {
129
129
  expect(collideContactManifold({ kind: 'aabb', minX: 0, minY: 9, maxX: 2, maxY: 11 }, ground, out)).toBe(false);
130
130
  expect(out.pointCount).toBe(0);
131
131
  expect(out.depth).toBe(0);
132
+ // The NORMAL is the field a stale manifold reports most convincingly: a caller that checks the
133
+ // boolean is safe, but one that reads the normal after a false return gets the previous hit's
134
+ // direction, which is a plausible value rather than an obviously wrong one.
135
+ expect(out.overlapping).toBe(false);
136
+ expect(out.normalX).toBe(0);
137
+ expect(out.normalY).toBe(0);
138
+ });
139
+
140
+ it('clears the same manifold when the following pair is a DIFFERENT kind that misses', () => {
141
+ // Reuse across kinds, because the miss path is per-kind: a pair that clears correctly within its own
142
+ // kind says nothing about the path a different kind takes to the same shared manifold.
143
+ const out = createCollisionContactManifold();
144
+ expect(
145
+ collideContactManifold(
146
+ { kind: 'obb', halfH: 2, halfW: 2, rotation: 0.3, x: 0, y: 0 },
147
+ { kind: 'obb', halfH: 2, halfW: 2, rotation: -0.2, x: 1, y: 1 },
148
+ out,
149
+ ),
150
+ ).toBe(true);
151
+ expect(out.pointCount).toBeGreaterThan(0);
152
+ expect(Math.abs(out.normalX) + Math.abs(out.normalY)).toBeGreaterThan(0);
153
+
154
+ expect(
155
+ collideContactManifold(
156
+ { kind: 'circle', radius: 1, x: 0, y: 0 },
157
+ { kind: 'circle', radius: 1, x: 50, y: 0 },
158
+ out,
159
+ ),
160
+ ).toBe(false);
161
+ expect(out).toMatchObject({ depth: 0, normalX: 0, normalY: 0, overlapping: false, pointCount: 0 });
162
+ });
163
+
164
+ it('leaves the point ARRAY untouched behind pointCount, which is the contract callers read', () => {
165
+ // Stated rather than assumed: clearing resets pointCount, not the two point slots behind it. A test
166
+ // asserting the slots were zeroed would be pinning an implementation detail the contract does not
167
+ // promise, and would fail the day the manifold reuses its allocation differently.
168
+ const out = createCollisionContactManifold();
169
+ expect(
170
+ collideContactManifold(
171
+ { kind: 'aabb', maxX: 2, maxY: 2, minX: 0, minY: 0 },
172
+ { kind: 'aabb', maxX: 3, maxY: 3, minX: 1, minY: 1 },
173
+ out,
174
+ ),
175
+ ).toBe(true);
176
+ const populated = out.points.map((point) => ({ x: point.x, y: point.y }));
177
+
178
+ expect(
179
+ collideContactManifold(
180
+ { kind: 'aabb', maxX: 1, maxY: 1, minX: 0, minY: 0 },
181
+ { kind: 'aabb', maxX: 41, maxY: 41, minX: 40, minY: 40 },
182
+ out,
183
+ ),
184
+ ).toBe(false);
185
+
186
+ expect(out.pointCount).toBe(0);
187
+ expect(out.points.map((point) => ({ x: point.x, y: point.y }))).toEqual(populated);
132
188
  });
133
189
  });