diff --git a/orx-triangulation/src/commonMain/kotlin/Delaunay.kt b/orx-triangulation/src/commonMain/kotlin/Delaunay.kt index 409325d1..36f8ddcd 100644 --- a/orx-triangulation/src/commonMain/kotlin/Delaunay.kt +++ b/orx-triangulation/src/commonMain/kotlin/Delaunay.kt @@ -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) } diff --git a/orx-triangulation/src/commonMain/kotlin/DelaunayTriangulation.kt b/orx-triangulation/src/commonMain/kotlin/DelaunayTriangulation.kt index 33a08520..4f57c9eb 100644 --- a/orx-triangulation/src/commonMain/kotlin/DelaunayTriangulation.kt +++ b/orx-triangulation/src/commonMain/kotlin/DelaunayTriangulation.kt @@ -81,6 +81,15 @@ class DelaunayTriangulation(val points: List) { 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.delaunayTriangulation(): DelaunayTriangulation { return DelaunayTriangulation(this) } diff --git a/orx-triangulation/src/commonMain/kotlin/VoronoiDiagram.kt b/orx-triangulation/src/commonMain/kotlin/VoronoiDiagram.kt index a00b14fe..e4627f55 100644 --- a/orx-triangulation/src/commonMain/kotlin/VoronoiDiagram.kt +++ b/orx-triangulation/src/commonMain/kotlin/VoronoiDiagram.kt @@ -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.voronoiDiagram(bounds: Rectangle = this.bounds): VoronoiDiagram { val d = this.delaunayTriangulation() return d.voronoiDiagram(bounds) diff --git a/orx-triangulation/src/jvmDemo/kotlin/DemoDelaunay01.kt b/orx-triangulation/src/jvmDemo/kotlin/DemoDelaunay01.kt index 784d0483..2b3b64e9 100644 --- a/orx-triangulation/src/jvmDemo/kotlin/DemoDelaunay01.kt +++ b/orx-triangulation/src/jvmDemo/kotlin/DemoDelaunay01.kt @@ -5,6 +5,25 @@ import org.openrndr.extra.triangulation.delaunayTriangulation import org.openrndr.math.Vector2 import org.openrndr.shape.Circle +/** + * Entry point of the application. + * + * This method sets up a graphical application using the OPENRNDR framework + * to visually demonstrate Delaunay triangulation on a set of points scattered + * along a circle with Poisson disk sampling. + * + * The application features the following: + * - A central circle with a defined radius. + * - Points generated within the circle using a scatter algorithm that + * maintains specific spacing and avoids clustering. + * - Delaunay triangulation computed from the combined point set. + * - Rendering of triangles that are part of the Delaunay triangulation. + * - Visual styling with dynamic color shading for better clarity of layers + * and triangle order. + * + * This method demonstrates concepts of computational geometry and procedural + * rendering with a focus on interactive visual applications. + */ fun main() { application { configure { diff --git a/orx-triangulation/src/jvmDemo/kotlin/DemoVoronoi01.kt b/orx-triangulation/src/jvmDemo/kotlin/DemoVoronoi01.kt index 2b9eebdc..91230317 100644 --- a/orx-triangulation/src/jvmDemo/kotlin/DemoVoronoi01.kt +++ b/orx-triangulation/src/jvmDemo/kotlin/DemoVoronoi01.kt @@ -6,6 +6,17 @@ import org.openrndr.math.Vector2 import org.openrndr.shape.Circle import org.openrndr.shape.Rectangle +/** + * This program generates a Voronoi diagram within a defined circular area and visualizes it. + * + * The program performs the following: + * - Defines a circular area and a rectangular bounding frame within the canvas. + * - Uses Poisson Disk Sampling to generate points within the circular area. + * - Computes the Delaunay triangulation for the generated points, including equidistant points on the circle boundary. + * - Derives the Voronoi diagram using the Delaunay triangulation and the bounding frame. + * - Extracts the cell polygons of the Voronoi diagram. + * - Renders the Voronoi cell polygons on the canvas, with a pink stroke on a black background. + */ fun main() { application { configure {