[orx-kdtree] Make orx-kdtree a multiplatform module

This commit is contained in:
Edwin Jakobs
2024-01-02 18:13:14 +01:00
parent a1e75269b1
commit 3b57c3ce26
11 changed files with 305 additions and 214 deletions

View File

@@ -0,0 +1,32 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
import org.openrndr.shape.LineSegment
fun main() {
application {
configure {
width = 1080
height = 720
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
extend {
drawer.circles(points, 5.0)
val kNearest = tree.findKNearest(mouse.position, k = 7)
drawer.fill = ColorRGBa.RED
drawer.stroke = ColorRGBa.RED
drawer.strokeWeight = 2.0
drawer.circles(kNearest, 7.0)
drawer.lineSegments(kNearest.map { LineSegment(mouse.position, it) })
}
}
}
}

View File

@@ -0,0 +1,25 @@
import org.openrndr.application
import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
fun main() {
application {
configure {
width = 1280
height = 720
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
extend {
drawer.circles(points, 5.0)
val nearest = tree.findNearest(mouse.position)
nearest?.let {
drawer.circle(it.x, it.y, 20.0)
}
}
}
}
}

View File

@@ -0,0 +1,37 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
fun main() {
application {
configure {
width = 1080
height = 720
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
val radius = 50.0
extend {
drawer.circles(points, 5.0)
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.PINK
drawer.strokeWeight = 2.0
drawer.circles(allInRange, 7.0)
drawer.fill = null
drawer.strokeWeight = 1.0
drawer.circle(mouse.position, radius)
}
}
}
}