SharpVoronoiLib 1.2.0

dotnet add package SharpVoronoiLib --version 1.2.0
                    
NuGet\Install-Package SharpVoronoiLib -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpVoronoiLib" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpVoronoiLib" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SharpVoronoiLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpVoronoiLib --version 1.2.0
                    
#r "nuget: SharpVoronoiLib, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SharpVoronoiLib@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpVoronoiLib&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SharpVoronoiLib&version=1.2.0
                    
Install as a Cake Tool

build_and_test

SharpVoronoiLib

C# implementation of generating a Voronoi diagram from a set of points in a plane (using Fortune's Algorithm) with edge clipping and border closure. This implementation guarantees O(n×ln(n)) performance.

voronoi example

Installation

The library is available as SharpVoronoiLib NuGet package: dotnet add package SharpVoronoiLib via CLI or via your preferred NuGet package manager.

Alternatively, you can download the solution and either copy the SharpVoronoiLib project code or build the project and use the SharpVoronoiLib.dll.

Usage

Quick-start

List<VoronoiSite> sites = new List<VoronoiSite>
{
    new VoronoiSite(300, 300),
    new VoronoiSite(300, 400),
    new VoronoiSite(400, 300)
};

List<VoronoiEdge> edges = VoronoiPlane.TessellateOnce(
    sites, 
    0, 0, 
    600, 600
);

(Note that the algorithm will ignore duplicate sites, so check VoronoiSite.Tesselated for skipped sites if duplicates are possible in your data.)

Full syntax

Full syntax (leaving a reusable VoronoiPlane instance):

VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);

plane.SetSites(sites);

List<VoronoiEdge> edges = plane.Tessellate();

Result structure

The tesselation result for the given VoronoiSites contains VoronoiEdges and VoronoiPoints. The returned collection contains the generated edges.

voronoi terms

  • VoronoiEdge.Start and .End are the start and end points of the edge.
  • VoronoiEdge.Right and .Left are the sites the edge encloses. Border edges move clockwise and will only have the .Right site. And if no points are within the region, both will be null.
  • Edge end VoronoiPoints also contain a .BorderLocation specifying if it's on a border and which one.
  • VoronoiEdge.Neighbours (on-demand) are edges directly "connecting" to this edge, basically creating a traversable edge graph.
  • VoronoiEdge.Length (on-demand) is the distance between its end points.
  • VoronoiSite.Edges (aka cell) contains the edges that enclose the site (the order is not guaranteed).
  • VoronoiSite.ClockwiseEdges (on-demand) contains these edges sorted clockwise (starting from the bottom-right "corner" end point).
  • VoronoiSite.ClockwiseEdgesWound (on-demand) contains these edges also "wound" in the clockwise order so their start/end points form a loop.
  • VoronoiSite.Neighbours contains the site's neighbours (in the Delaunay Triangulation), that is, other sites across its edges.
  • VoronoiSite.Points (on-demand) contains points/vertices of the site's cell, that is, edge end points / edge nodes.
  • VoronoiSite.ClockwisePoints (on-demand) contains these points sorted clockwise (starting from the bottom-right "corner").
  • VoronoiPoint.Edges are edges emerging from this point.
  • VoronoiPoint.Sites (on-demand) are sites touching this point.

voronoi terms - site voronoi terms - edge

Border closing

If closing borders around the boundary is not desired (leaving sites with unclosed edges/polygons):

List<VoronoiEdge> edges = VoronoiPlane.TessellateOnce(
    sites, 
    0, 0, 
    600, 600,
    BorderEdgeGeneration.DoNotMakeBorderEdges
);

Closed versus unclosed:

<img width="484" height="343" alt="closed borders" src="https://github.com/user-attachments/assets/b9d59c77-18f8-4478-9809-9646d59af5be" /> <img width="484" height="343" alt="unclosed borders" src="https://github.com/user-attachments/assets/c2e28f2a-4cf4-4132-bc0f-b5003ddcb27d" />

Site generation

Sites can be quickly randomly-generated (this will guarantee no duplicates and no sites on edges):

VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);

plane.GenerateRandomSites(1000, PointGenerationMethod.Uniform); // also supports .Gaussian or custom implementations

plane.Tessellate();

Uniform and Gaussian:

<img width="475" height="328" alt="random uniform" src="https://github.com/user-attachments/assets/cae69f77-c5cb-4005-ae40-e68f8bcfa868" /> <img width="475" height="328" alt="random gaussian" src="https://github.com/user-attachments/assets/b1a1fea1-d804-4ea5-afd1-adb719894e1a" />

A custom random number generator may also be provided.

Site relaxation

Lloyds relaxation algorithm can be applied to "smooth" cells by spacing them out over several tessalation passes:

VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);

plane.SetSites(sites);

plane.Tessellate();

List<VoronoiEdge> edges = plane.Relax();
// List<VoronoiEdge> edges = plane.Relax(3, 0.7f); // relax 3 times with 70% strength each time 

<img width="475" height="328" alt="no relaxing" src="https://github.com/user-attachments/assets/5294cbb2-2a07-4d3a-98c2-0bfe399013a9" /> → <img width="475" height="328" alt="twice relaxing" src="https://github.com/user-attachments/assets/2ba08672-1c28-4217-b745-2cddf7fc700d" />

Delaunay triangulation

A Voronoi diagram has a corresponding Delaunay triangulation, i.e. site neighbour links:

<img width="475" height="328" alt="site neighbours subtle" src="https://github.com/user-attachments/assets/d4e81817-8650-4761-bacd-63ac83652365" /> <img width="475" height="328" alt="site neighbours distinct" src="https://github.com/user-attachments/assets/c6793e3b-2102-43a3-88b4-0e8e9921ca3e" />

While these normally form triangles, be aware that four or more points in a circle will make this mathematically ambiguous; sites will have neighbours across a vertex crossing other neighbour links. This is extremely rare with random points, but must be checked if using the results for something like a triangle mesh. The library does not currently provide a direct way to gather a list of these triangles.

MonoGame example

A simple interactive MonoGame example is included in MonoGameExample project:

<img width="994" height="498" alt="monogame demo enhanced" src="https://github.com/user-attachments/assets/40be8056-a54f-44c9-85f9-3b1c5f00a03d" />

Dependencies

The main library targets .NET 10.0, 9.0 and .NET Standard 2.0, 2.1 and targets compatible OSes - Windows, Linux & macOS - and .NET and Mono frameworks - Xamarin, Mono, UWP, Unity, etc.

Original library

The key differences from the original VoronoiLib repo:

  • Borders can be closed, that is, edges generated along the boundary
  • Edges and points/sites contain additional useful data
  • Multiple critical and annoyingly-rare bugs and edge cases fixes
  • LOTS more unit testing!

Credits

Original implementation inspired by:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 105 2/24/2026
1.1.0 820 10/17/2025
1.0.6 165 10/10/2025
1.0.5 1,830 5/21/2025
1.0.4 841 10/13/2024