# `Cauldron2D.Sectors.Blockmap`
[🔗](https://github.com/jaman/cauldron/blob/v0.2.2/cauldron_2d/lib/cauldron_2d/sectors/blockmap.ex#L1)

A sector map's lines, and the bodies moving through it, sorted into square blocks so
that movement and traces only look at what is near.

    blockmap =
      map
      |> Cauldron2D.Sectors.Blockmap.build(size: 128)
      |> Cauldron2D.Sectors.Blockmap.with_bodies([{:player, {1056.0, -3616.0}, 16.0}, ...])

    Cauldron2D.Sectors.Blockmap.lines_near(blockmap, {x, y}, 16.0)
    Cauldron2D.Sectors.Blockmap.bodies_near(blockmap, {x, y}, 16.0)

Lines are filed once, when the blockmap is built; bodies move, so `with_bodies/2` files
a fresh set and replaces the last, and `put_body/2` and `remove_body/2` file or unfile
one as it moves. A body is `{id, {x, y}, radius}`.

# `body`

```elixir
@type body() :: {term(), {number(), number()}, number()}
```

# `t`

```elixir
@type t() :: %Cauldron2D.Sectors.Blockmap{
  bodies: %{required(integer()) =&gt; [body()]},
  cells: tuple(),
  columns: pos_integer(),
  filed: %{required(term()) =&gt; integer()},
  origin: {float(), float()},
  rows: pos_integer(),
  size: number(),
  widest: float()
}
```

# `bodies_near`

```elixir
@spec bodies_near(t(), {number(), number()}, number()) :: [body()]
```

The bodies whose box overlaps a box of `radius` round `point`.

# `build`

```elixir
@spec build(Cauldron2D.Sectors.Map.t(), keyword()) :: t()
```

File the lines of `map` (a `Cauldron2D.Sectors.Map`). Option `:size`, the block's side, default `128`.

# `cells_of_segment`

```elixir
@spec cells_of_segment(t(), {{number(), number()}, {number(), number()}}) :: [
  non_neg_integer()
]
```

The blocks a segment passes through, in order from `from` to `to`, as block numbers.

# `lines_near`

```elixir
@spec lines_near(t(), {number(), number()}, number()) :: [non_neg_integer()]
```

The indexes of lines filed in the blocks a box of `radius` round `point` touches.

# `put_body`

```elixir
@spec put_body(t(), body()) :: t()
```

File `body`, moving it if a body with its id is filed already.

# `remove_body`

```elixir
@spec remove_body(t(), term()) :: t()
```

Unfile the body with `id`, if one is filed.

# `with_bodies`

```elixir
@spec with_bodies(t(), [body()]) :: t()
```

The blockmap with `bodies` filed, replacing the ones filed before.

---

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