cannon-es-control
Version:
A lightweight 3D physics engine written in JavaScript with control system tools
31 lines (26 loc) • 1.07 kB
text/typescript
import type { World } from '../src/world/World'
import type { TestConfig } from './helpers'
type ToBeCollidingRecieved = [World, number, number, boolean]
expect.extend({
toBeColliding([world, bodyAIndex, bodyBIndex, isFirstStep]: ToBeCollidingRecieved, testConfig: TestConfig) {
const bodyA = world.bodies[bodyAIndex]
const bodyB = world.bodies[bodyBIndex]
const isColliding = isFirstStep
? !!world.collisionMatrix.get(bodyA, bodyB)
: !!world.collisionMatrixPrevious.get(bodyA, bodyB)
const expected = testConfig.colliding[bodyAIndex + '-' + bodyBIndex] === true
return {
pass: isColliding === expected,
message: () =>
[
`${expected ? 'Should be colliding' : 'Should not be colliding'}`,
`testConfig=${JSON.stringify(testConfig)}`,
`isFirstStep=${isFirstStep}`,
`expected=${expected}`,
`isColliding=${isColliding}`,
`bodyAIndex=${bodyAIndex}`,
`bodyBIndex=${bodyBIndex}`,
].join(', '),
}
},
})