@gg-web-engine/matter 0.0.72 → 0.0.73

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.
@@ -118,12 +118,12 @@ describe('MatterWorldComponent', () => {
118
118
  });
119
119
  });
120
120
 
121
- describe.skip('Raycast', () => {
121
+ describe('Raycast', () => {
122
122
  it('should return no hit when ray does not intersect any object', () => {
123
123
  // Create a square far away from the ray
124
124
  const square = world.factory.createRigidBody(
125
125
  {
126
- shape: { shape: 'SQUARE', dimensions: { x: 1, y: 1 } },
126
+ shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
127
127
  body: { bodyType: 'static', mass: 0 },
128
128
  },
129
129
  { position: { x: 10, y: 10 } },
@@ -149,7 +149,7 @@ describe('MatterWorldComponent', () => {
149
149
  // Create a square in the path of the ray
150
150
  const square = world.factory.createRigidBody(
151
151
  {
152
- shape: { shape: 'SQUARE', dimensions: { x: 2, y: 2 } },
152
+ shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
153
153
  body: { bodyType: 'static', mass: 0 },
154
154
  },
155
155
  { position: { x: 0, y: -5 } },
@@ -186,7 +186,7 @@ describe('MatterWorldComponent', () => {
186
186
  // Create a square that only belongs to group1
187
187
  const square1 = world.factory.createRigidBody(
188
188
  {
189
- shape: { shape: 'SQUARE', dimensions: { x: 2, y: 2 } },
189
+ shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
190
190
  body: {
191
191
  bodyType: 'static',
192
192
  mass: 0,
@@ -228,7 +228,7 @@ describe('MatterWorldComponent', () => {
228
228
  // Create a square at a known distance
229
229
  const square = world.factory.createRigidBody(
230
230
  {
231
- shape: { shape: 'SQUARE', dimensions: { x: 2, y: 2 } },
231
+ shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
232
232
  body: { bodyType: 'static', mass: 0 },
233
233
  },
234
234
  { position: { x: 0, y: -5 } },
@@ -259,7 +259,7 @@ describe('MatterWorldComponent', () => {
259
259
  // Create a square that belongs to group1
260
260
  const square = world.factory.createRigidBody(
261
261
  {
262
- shape: { shape: 'SQUARE', dimensions: { x: 2, y: 2 } },
262
+ shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
263
263
  body: {
264
264
  bodyType: 'static',
265
265
  mass: 0,
@@ -289,7 +289,7 @@ describe('MatterWorldComponent', () => {
289
289
  // Create two squares at different positions
290
290
  const square1 = world.factory.createRigidBody(
291
291
  {
292
- shape: { shape: 'SQUARE', dimensions: { x: 1, y: 1 } },
292
+ shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
293
293
  body: { bodyType: 'static', mass: 0 },
294
294
  },
295
295
  { position: { x: 0, y: -3 } },
@@ -298,7 +298,7 @@ describe('MatterWorldComponent', () => {
298
298
 
299
299
  const square2 = world.factory.createRigidBody(
300
300
  {
301
- shape: { shape: 'SQUARE', dimensions: { x: 1, y: 1 } },
301
+ shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
302
302
  body: { bodyType: 'static', mass: 0 },
303
303
  },
304
304
  { position: { x: 0, y: -7 } },
@@ -323,7 +323,7 @@ describe('MatterWorldComponent', () => {
323
323
  // Create a square
324
324
  const square = world.factory.createRigidBody(
325
325
  {
326
- shape: { shape: 'SQUARE', dimensions: { x: 4, y: 4 } },
326
+ shape: { shape: 'BOX', dimensions: { x: 4, y: 4 } },
327
327
  body: { bodyType: 'static', mass: 0 },
328
328
  },
329
329
  { position: { x: 0, y: 0 } },
@@ -346,5 +346,40 @@ describe('MatterWorldComponent', () => {
346
346
  // We just verify the method doesn't crash and returns a valid result
347
347
  expect(result).toBeDefined();
348
348
  });
349
+
350
+ it('should never resolve a hit against a trigger, even when the ray starts inside it', () => {
351
+ // A trigger is a sensor with no collision response (ITrigger2dComponent) and must never
352
+ // obstruct a raycast - a world-enclosing trigger (a map-bounds kill volume) would otherwise
353
+ // be "hit" at ~0 distance by every ray cast anywhere inside it. raycast() excludes sensor
354
+ // bodies from its candidate set outright (see its own doc).
355
+ const trigger = world.factory.createTrigger({ shape: 'BOX', dimensions: { x: 100, y: 100 } });
356
+ trigger.addToWorld({ physicsWorld: world } as any);
357
+ world.simulate(1);
358
+
359
+ // from well inside the trigger's volume, hitting nothing else
360
+ const result = world.raycast({
361
+ from: { x: 0, y: 0 },
362
+ to: { x: 0, y: 10 },
363
+ });
364
+ expect(result.hasHit).toBe(false);
365
+
366
+ // a real solid body behind/through the trigger must still be hit normally
367
+ const square = world.factory.createRigidBody(
368
+ {
369
+ shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
370
+ body: { bodyType: 'static', mass: 0 },
371
+ },
372
+ { position: { x: 0, y: -5 } },
373
+ );
374
+ square.addToWorld({ physicsWorld: world } as any);
375
+ world.simulate(1);
376
+
377
+ const throughResult = world.raycast({
378
+ from: { x: 0, y: 0 },
379
+ to: { x: 0, y: -10 },
380
+ });
381
+ expect(throughResult.hasHit).toBe(true);
382
+ expect(throughResult.hitBody).toBe(square);
383
+ });
349
384
  });
350
385
  });