shapeContains

View sourceshapeContains(shape: Collider2D, point: Vector2): boolean

Tests a point against the current representation of a Collider2D.

A shape whose type is Collider2D.Circle is interpreted using the engine’s circle encoding: shape.vertices[0] is the center and shape.vertices[1].x is the radius. Every other type is treated as a polygon and passed to verticesContain, which expects clockwise, convex vertices. Circle and polygon boundaries are both considered contained.

The helper reads type and vertices only. It does not update the collider, inspect its geometry or angle, or validate a manually assembled shape.

Examples

import { Vector2 } from '@wimaengine/math'
import { Collider2D, shapeContains } from '@wimaengine/narrowphase'

const circle = Collider2D.circle(2)
shapeContains(circle, new Vector2(1, 1)) // true

Parameters

NameDescriptionDefault
shape

Collider whose current shape is tested.

—
point

Point to test.

—

Returns

true when the point is inside or on the boundary of the collider.