[orx-triangulation] Add generated and verified documentation

This commit is contained in:
Edwin Jakobs
2025-01-19 00:13:44 +01:00
parent 8ef7264c63
commit 1752685476
5 changed files with 51 additions and 0 deletions

View File

@@ -222,5 +222,11 @@ class Delaunay(val points: DoubleArray) {
return c
}
/**
* Generates a Voronoi diagram based on the current Delaunay triangulation and the provided bounds.
*
* @param bounds A rectangle defining the boundaries within which the Voronoi diagram will be generated.
* @return A Voronoi instance representing the resulting Voronoi diagram.
*/
fun voronoi(bounds: Rectangle): Voronoi = Voronoi(this, bounds)
}

View File

@@ -81,6 +81,15 @@ class DelaunayTriangulation(val points: List<Vector2>) {
fun nearestPoint(query: Vector2): Vector2 = points[nearest(query)]
}
/**
* Computes the Delaunay triangulation for the list of 2D points.
*
* The Delaunay triangulation is a triangulation of a set of points such that
* no point is inside the circumcircle of any triangle. It maximizes the minimum
* angle of all the angles in the triangles, avoiding skinny triangles.
*
* @return A DelaunayTriangulation object representing the triangulation of the given points.
*/
fun List<Vector2>.delaunayTriangulation(): DelaunayTriangulation {
return DelaunayTriangulation(this)
}

View File

@@ -81,6 +81,12 @@ class VoronoiDiagram(val delaunayTriangulation: DelaunayTriangulation, val bound
}
}
/**
* Generates a Voronoi diagram based on the points in the list and the provided bounds.
*
* @param bounds The rectangular bounds within which the Voronoi diagram is generated. Defaults to the bounds of the point list.
* @return A VoronoiDiagram object representing the calculated Voronoi diagram.
*/
fun List<Vector2>.voronoiDiagram(bounds: Rectangle = this.bounds): VoronoiDiagram {
val d = this.delaunayTriangulation()
return d.voronoiDiagram(bounds)