# `Macaw.Draw.Geo.Voronoi`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/geo/voronoi.ex#L1)

Voronoi cells bounded to a rectangle (spec/09 §10), copied from visualize's
`Visualize.Geo.Voronoi` and the `voronoi` step of its `Visualize.Chart.Transform.Geo`.

    iex> {:ok, v} = Macaw.Draw.Geo.Voronoi.new([{25, 50}, {75, 50}], {0, 0, 100, 100})
    iex> Macaw.Draw.Geo.Voronoi.cell(v, 0)
    [{50.0, 0.0}, {50.0, 100.0}, {0, 100}, {0, 0}]

The diagram triangulates its sites (`Macaw.Draw.Geo.Delaunay`) and keeps the circumcenter
of every triangle (the centroid of a degenerate one). Its bounds are required, since every
Voronoi layer is bounded by its plot (decision 4).

- **An interior site's cell** is the circumcenters of its incident triangles, ordered by
  angle about the site and clipped to the bounds (Sutherland–Hodgman), as visualize's.
- **A hull site's cell is complete** (decision 5): bounded besides by two rays, each from
  the circumcenter of the triangle on one of its hull edges, perpendicular to that edge
  and pointing out of the hull, and clipped to the bounds as d3-delaunay clips an infinite
  cell. visualize left these cells open.
- **Collinear sites** cut the bounds by the perpendicular bisectors between neighbors
  along their line; **one site** has the whole bounds; **a duplicate site** an empty cell.

# `bounds`

```elixir
@type bounds() :: {number(), number(), number(), number()}
```

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t()]}
```

A refusal: faults with their paths.

# `point`

```elixir
@type point() :: {number(), number()}
```

# `t`

```elixir
@type t() :: %Macaw.Draw.Geo.Voronoi{
  bounds: bounds(),
  circumcenters: [point()],
  delaunay: Macaw.Draw.Geo.Delaunay.t()
}
```

# `cell`

```elixir
@spec cell(t(), non_neg_integer()) :: [point()] | error()
```

The clipped cell of site `i`, a list of `{x, y}` vertices; `[]` for a duplicate site.

# `cell_path`

```elixir
@spec cell_path(t(), non_neg_integer()) :: Macaw.Draw.IR.Path.t() | error()
```

Site `i`'s cell as an IR path, `M … L … Z`; an empty cell draws nothing.

# `cell_unclipped`

```elixir
@spec cell_unclipped(t(), non_neg_integer()) :: [point()] | error()
```

The finite circumcenters of site `i`'s incident triangles alone, ordered by angle about
the site and unclipped, as visualize answered (spec/09 §10.1).

# `cells`

```elixir
@spec cells(t()) :: [[point()]] | error()
```

Every site's `cell/2`, in site order.

# `cells_path`

```elixir
@spec cells_path(t()) :: Macaw.Draw.IR.Path.t() | error()
```

Every cell as one IR path.

# `columns`

```elixir
@spec columns(t(), :cells | :edges, [term()]) ::
  %{required(String.t()) =&gt; [term()]} | error()
```

The voronoi step's columns (spec/09 §10.2), `rows` mapping a site's position to its
input row: for `:cells` one row per site in input order, `"row"`, `"index"` and `"path"`
(the closed clipped cell, empty for a site without one); for `:edges` one row per edge,
`"x0"`, `"y0"`, `"x1"`, `"y1"` and `"path"`. The output is the atom or its spelling.

# `edges`

```elixir
@spec edges(t()) :: [{point(), point()}] | error()
```

The diagram's edges as `{c1, c2}` segments clipped to the bounds (spec/09 §10.1): for each
triangle in order and each of its edges `(i, j), (j, k), (k, i)` in turn, the segment
between its circumcenter and the neighbor's across that edge, a pair reported once at
its lower triangle; a hull edge gives the ray from the circumcenter to its exit from the
bounds. Read through the half-edges, linear in the triangles.

# `edges_path`

```elixir
@spec edges_path(t()) :: Macaw.Draw.IR.Path.t() | error()
```

Every edge as one IR path, `M … L …` each.

# `find`

```elixir
@spec find(t(), point()) :: non_neg_integer() | nil | error()
```

The index of the site nearest `{x, y}` (Euclidean), ties to the lower index; `nil` with no sites.

# `new`

```elixir
@spec new([point()], bounds()) :: {:ok, t()} | error()
```

The diagram of `points` bounded by `bounds`, `{x0, y0, x1, y1}` with `x0 < x1` and
`y0 < y1` (else `{[:bounds], :inverted}`) (spec/09 §10).

---

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