[orx-kdtree] Add generated and verified documentation

This commit is contained in:
Edwin Jakobs
2025-01-18 23:21:48 +01:00
parent 9a84b12198
commit 55b7ffdfb3
4 changed files with 48 additions and 0 deletions

View File

@@ -1,5 +1,16 @@
package org.openrndr.extra.kdtree
/**
* Selects the nth element from the given list after partially sorting it based on a mapping function.
*
* This method modifies the input list to reorder its elements such that the nth element is placed
* at the correct sorted position if the list were fully sorted according to the provided mapper.
*
* @param items The list of elements to process and partially sort.
* @param n The zero-based index of the element to select after partial sorting.
* @param mapper A lambda function that maps an element of type T to a Double, used to determine sorting order.
* @return The nth element in the reordered list.
*/
fun <T> selectNth(items: MutableList<T>, n: Int, mapper: (T)->Double): T {
var from = 0
var to = items.size - 1

View File

@@ -4,6 +4,18 @@ import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
import org.openrndr.shape.LineSegment
/**
* This demo initializes an interactive graphical application where 1000 randomly distributed points
* are displayed on a 2D canvas. A KD-tree structure is used for spatial querying of the points, enabling
* efficient nearest-neighbor searches based on the user's cursor position. The closest 7 points to the
* cursor are highlighted with circles and lines connecting them to the cursor.
*
* Key features:
* - Generates 1000 random 2D points within the canvas dimensions (1080x720).
* - Builds a KD-tree from the list of points for optimized spatial querying.
* - Visualizes the points and highlights the 7 nearest neighbors to the user's cursor position dynamically.
* - Highlights include red-colored circles around the nearest points and red lines connecting them to the cursor.
*/
fun main() {
application {
configure {

View File

@@ -2,6 +2,18 @@ import org.openrndr.application
import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
/**
* Initializes an interactive graphical application that displays 1000 randomly distributed 2D points
* on a canvas of dimensions 1280x720. The points are organized into a KD-tree for efficient spatial querying.
*
* Key functionality:
* - Displays the points as small circles on the canvas.
* - Dynamically highlights the nearest point to the cursor's position by drawing a larger circle around it.
*
* Highlights:
* - KD-tree structure enables efficient nearest-neighbor searches.
* - The nearest point to the cursor is determined and visually emphasized in real-time as the cursor moves.
*/
fun main() {
application {
configure {

View File

@@ -4,6 +4,19 @@ import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
/**
* Initializes an interactive graphical application that demonstrates spatial querying with KD-trees.
* A canvas is populated with 1000 randomly distributed 2D points, and a KD-tree is used for efficient
* spatial operations. The program dynamically highlights points within a specified radius from the
* user's cursor position.
*
* Key features:
* - Generates and displays 1000 random 2D points within canvas dimensions of 1080x720.
* - Builds a KD-tree structure for optimized querying of spatial data.
* - Dynamically highlights points within a specified radius (50.0) from the cursor position.
* - Visualizes the current query radius around the cursor as an outline circle.
* - Uses different fill and stroke styles to distinguish highlighted points and query visuals.
*/
fun main() {
application {