# `Cauldron2D.Collision.Buckets`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d/lib/cauldron_2d/collision/buckets.ex#L1)

Bodies sorted into square buckets, so that only neighbours are compared.

    buckets =
      Cauldron2D.Collision.Buckets.new(4)
      |> Cauldron2D.Collision.Buckets.insert(:ball, {10.5, 3.2}, 0.5)
      |> Cauldron2D.Collision.Buckets.insert(:coin_9, {10.9, 3.0}, 0.1)

    Cauldron2D.Collision.Buckets.pairs(buckets)       # => [{:ball, :coin_9}]
    Cauldron2D.Collision.Buckets.near(buckets, {10.0, 3.0}, 1.0)

The bucket size is in tiles and should be at least the largest radius plus the largest
reach queried, so that a body is never further than one bucket from anything it can touch.
Build a fresh set each tick; there is no removal.

# `id`

```elixir
@type id() :: term()
```

# `t`

```elixir
@type t() :: %Cauldron2D.Collision.Buckets{
  cells: %{required({integer(), integer()}) =&gt; [entry()]},
  size: pos_integer()
}
```

# `insert`

```elixir
@spec insert(t(), id(), Cauldron2D.Collision.point(), number()) :: t()
```

Add a body under `id`.

# `near`

```elixir
@spec near(t(), Cauldron2D.Collision.point(), number()) :: [id()]
```

Ids of every body within `reach` of `pos`, measured surface to point.

# `new`

```elixir
@spec new(pos_integer()) :: t()
```

An empty set with buckets `size` tiles across.

# `pairs`

```elixir
@spec pairs(t()) :: [{id(), id()}]
```

Every pair of overlapping bodies, each once, as `{id, id}` with the smaller id first.

---

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