Voronoi diagram for spatial partitioning.
Computes the Voronoi tessellation from a Delaunay triangulation. Each cell contains all points closer to its site than to any other site.
Examples
points = [{0, 0}, {100, 0}, {50, 100}, {25, 50}, {75, 50}]
voronoi = Visualize.Geo.Voronoi.new(points)
|> Visualize.Geo.Voronoi.bounds([0, 0, 200, 200])
# Get cell for a specific point
cell = Visualize.Geo.Voronoi.cell(voronoi, 0)
# Render all cells as SVG paths
paths = Visualize.Geo.Voronoi.render_cells(voronoi)
# Find which cell contains a point
i = Visualize.Geo.Voronoi.find(voronoi, {30, 30})
Summary
Functions
Sets the clipping bounds [x0, y0, x1, y1]
Returns the Voronoi cell polygon for a given point index
Returns a cell's vertices without clipping to bounds.
Returns all Voronoi cells as lists of vertices
Returns the edges of the Voronoi diagram
Finds which cell contains the given point
Creates a new Voronoi diagram from points
Generates SVG path data for a specific cell
Generates SVG path data for all cells
Generates SVG with clipPath for rendering cells.
Generates SVG path data for all Voronoi edges
Types
Functions
Sets the clipping bounds [x0, y0, x1, y1]
@spec cell(t(), non_neg_integer()) :: [point()]
Returns the Voronoi cell polygon for a given point index
@spec cell_unclipped(t(), non_neg_integer()) :: [point()]
Returns a cell's vertices without clipping to bounds.
Useful when you want to use SVG clipPath for rendering.
Returns all Voronoi cells as lists of vertices
Returns the edges of the Voronoi diagram
Finds which cell contains the given point
Creates a new Voronoi diagram from points
@spec render_cell(t(), non_neg_integer()) :: String.t()
Generates SVG path data for a specific cell
Generates SVG path data for all cells
Generates SVG with clipPath for rendering cells.
Uses SVG's native clipPath instead of algorithmic clipping. More efficient for rendering, but doesn't compute actual clipped vertices.
Options
:clip_id- ID for the clipPath element (default: "voronoi-clip"):stroke- Stroke color for cell edges (default: "#ccc"):fill- Fill color for cells (default: "none")
Example
voronoi = Voronoi.new(points) |> Voronoi.bounds([0, 0, 400, 400])
svg = Voronoi.render_cells_clipped(voronoi)
Generates SVG path data for all Voronoi edges