# Geometry queries
Check point containment, separation, overlap, contact, and casts.

## APIs demonstrated

- [containsPoint2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [distanceBetweenShapes2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [overlapShapes2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [contactBetweenShapes2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [raycastShape2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [shapeCastAgainstShape2D](/reference/functions/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [PibblPhysicsDistance2D](/reference/types/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [PibblPhysicsContactPoint2D](/reference/types/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [PibblPhysicsShapeContact2D](/reference/types/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [PibblPhysicsRay2D](/reference/types/physics-2d/) from `@pibbl/core/physics/2d/geometry`
- [PibblPhysicsShapeHit2D](/reference/types/physics-2d/) from `@pibbl/core/physics/2d/geometry`

## Complete example

[Plain source](/minimal/physics/geometry-queries.ts). Run as a browser module after the document body exists. TSX uses `jsx: "react-jsx"` and `jsxImportSource: "@pibbl/core"`.

```ts
import {
  circleShape2D,
  contactBetweenShapes2D,
  containsPoint2D,
  distanceBetweenShapes2D,
  overlapShapes2D,
  raycastShape2D,
  shapeCastAgainstShape2D,
  type PibblPhysicsContactPoint2D,
  type PibblPhysicsDistance2D,
  type PibblPhysicsRay2D,
  type PibblPhysicsShapeContact2D,
  type PibblPhysicsShapeHit2D,
} from '@pibbl/core/physics/2d/geometry';

const circle = circleShape2D({ radius: 10 });
const first = { position: [20, 20], rotationDegrees: 0 } as const;
const second = { position: [45, 20], rotationDegrees: 0 } as const;
const distance: PibblPhysicsDistance2D = distanceBetweenShapes2D(circle, first, circle, second);
const contact: PibblPhysicsShapeContact2D | null = contactBetweenShapes2D(circle, first, circle, second);
const firstContactPoint: PibblPhysicsContactPoint2D | undefined = contact?.points[0];
const ray: PibblPhysicsRay2D = { origin: [0, 20], direction: [1, 0], maxDistance: 100 };
const rayHit: PibblPhysicsShapeHit2D | null = raycastShape2D(circle, first, ray);
const castHit: PibblPhysicsShapeHit2D | null = shapeCastAgainstShape2D(
  circle, first, [30, 0], circle, second,
);

const output = document.createElement('pre');
output.textContent = [
  `Point inside: ${containsPoint2D(circle, first, [20, 20])}`,
  `Overlapping: ${overlapShapes2D(circle, first, circle, second)}`,
  `Separation: ${distance.separation.toFixed(1)}`,
  `Contact points: ${contact?.points.length ?? 0}`,
  `First contact separation: ${firstContactPoint?.separation.toFixed(1) ?? 'none'}`,
  `Ray hit distance: ${rayHit?.distance.toFixed(1) ?? 'none'}`,
  `Cast impact time: ${castHit?.timeOfImpact.toFixed(2) ?? 'none'}`,
].join('\n');
document.body.append(output);

```

## Usage notes

- The pure geometry entry works without mounting a physics world.

## Documentation version

Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.
