jacobusmmsmit / DiscreteVoronoi.jl

Julia implementation of various algorithms for calculating discrete Voronoi diagrams.
MIT License
5 stars 1 forks source link
graphics julia voronoi

DiscreteVoronoi

A package for computing discrete approximations of Voronoi diagrams. All Voronoi diagram calculating functions are in-place.

Currently, to use this package you need to declare your sites as a Vector{SVector{2,Int}} and your grid as a Matrix{SVector{2,Int}} and hence there is a strong dependency on StaticArrays.

using DiscreteVoronoi
using StaticArrays

# Testing
n = 50
p = 10
grid = zeros(SVector{2,Int}, n, n)
sites = [SVector{2,Int}(rand(1:n, 2)) for _ in 1:p]
redac_voronoi!(grid, sites)

There are currently three ways of computing discrete Voronoi diagrams exported, they are all completely allocation free and called in the same way:

Which algorithm you should use for the fastest execution time depends somewhat on the task at hand. The best thing to do is to try all above for your usecase and decide from benchmarks. As a rule of thumb, the larger the grid is the better the divide-and-conquer methods will be in comparison. Particularly if the number of sites scales with the size of the grid (n^2) faster than log(n) (natural log), then redac_voronoi! will be much faster than dac_voronoi!.

Additionally, the package exports some helper functions for analysing Voronoi diagrams and writing your own algorithms:

Work in progress:

Contributions: