# `BB.Collision.BroadPhase`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/collision/broad_phase.ex#L5)

Broad phase collision detection using Axis-Aligned Bounding Boxes (AABBs).

The broad phase is a fast culling step that eliminates pairs of objects that
cannot possibly be colliding. This reduces the number of expensive narrow-phase
collision tests required.

AABBs are simple boxes aligned to the world axes, making overlap tests very fast.
They may be larger than the actual geometry (especially for rotated objects),
so a positive broad phase result only indicates *potential* collision.

# `aabb`

```elixir
@type aabb() :: {min :: BB.Math.Vec3.t(), max :: BB.Math.Vec3.t()}
```

# `centre`

```elixir
@spec centre(aabb()) :: BB.Math.Vec3.t()
```

Compute the centre point of an AABB.

# `compute_aabb`

```elixir
@spec compute_aabb(BB.Robot.Link.geometry(), BB.Math.Transform.t()) :: aabb()
```

Compute the AABB for a collision geometry in world space.

Takes a geometry specification (as stored in Robot.Link) and a transform
representing the geometry's position and orientation in world space.

## Supported Geometry Types

- `{:sphere, %{radius: float()}}` - Sphere
- `{:capsule, %{radius: float(), length: float()}}` - Capsule (cylinder with spherical caps)
- `{:cylinder, %{radius: float(), height: float()}}` - Cylinder (treated as capsule)
- `{:box, %{x: float(), y: float(), z: float()}}` - Box

## Examples

    iex> geometry = {:sphere, %{radius: 1.0}}
    iex> transform = Transform.identity()
    iex> {min, max} = BB.Collision.BroadPhase.compute_aabb(geometry, transform)
    iex> {Vec3.x(min), Vec3.x(max)}
    {-1.0, 1.0}

# `contains_point?`

```elixir
@spec contains_point?(aabb(), BB.Math.Vec3.t()) :: boolean()
```

Check if a point is inside an AABB.

# `expand`

```elixir
@spec expand(aabb(), float()) :: aabb()
```

Expand an AABB by a margin in all directions.

Useful for adding safety buffers to collision checks.

# `merge`

```elixir
@spec merge(aabb(), aabb()) :: aabb()
```

Merge two AABBs into a single AABB that contains both.

# `overlap?`

```elixir
@spec overlap?(aabb(), aabb()) :: boolean()
```

Check if two AABBs overlap.

This is a very fast O(1) test - two AABBs overlap if and only if they overlap
on all three axes.

# `size`

```elixir
@spec size(aabb()) :: BB.Math.Vec3.t()
```

Compute the size (extents) of an AABB in each dimension.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
