Macaw.Draw.Geo.Voronoi (macaw_draw v0.1.0)

Copy Markdown View Source

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.

Summary

Types

A refusal: faults with their paths.

t()

Functions

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

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

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).

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

Every cell as one IR path.

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.

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.

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

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

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

Types

bounds()

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

error()

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

A refusal: faults with their paths.

point()

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

t()

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

Functions

cell(v, i)

@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(v, i)

@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(v, i)

@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(v)

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

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

cells_path(v)

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

Every cell as one IR path.

columns(v, output, rows)

@spec columns(t(), :cells | :edges, [term()]) ::
  %{required(String.t()) => [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(v)

@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(v)

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

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

find(arg1, arg2)

@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(points, bounds)

@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).