Delaunay triangulation and Voronoi diagrams.
The functionality comes from a Javascript port of the following libraries:
- delaunator (external)
- d3-delaunay (the port is included in this package)
The entry point is the DelaunayTriangulation
class.
val points: List<Vector2>
val delaunay = DelaunayTriangulation(points)
// or
val delaunay = points.delaunayTriangulation()
This is how you retrieve the triangulation results:
val triangles: List<Triangle> = delaunay.triangles()
val halfedges: List<ShapeContour> = delaunay.halfedges()
val hull: ShapeContour = delaunay.hull()
The bounds specify where the Voronoi diagram will be clipped.
val bounds: Rectangle
val delaunay = points.delaunayTriangulation()
val voronoi = delaunay.voronoiDiagram(bounds)
// or
val voronoi = points.voronoiDiagram(bounds)
See To Infinity and Back Again for an interactive explanation of Voronoi cell clipping.
This is how you retrieve th results:
val cells: List<ShapeContour> = voronoi.cellPolygons()
val cell: ShapeContour = voronoi.cellPolygon(int) // index
val circumcenters: List<Vector2> = voronoi.circumcenters
// Returns true if the cell with the specified index i contains the specified vector
val containsVector = voronoi.contains(int, Vector2)
Ricardo Matias / @ricardomatias Edwin Jakobs / @edwinRNDR