[orx-kdtree] Refactor KDTree interface to improve ease of use
This commit is contained in:
@@ -2,13 +2,13 @@ import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.kdtree.buildKDTree
|
||||
import org.openrndr.extra.kdtree.findKNearest
|
||||
import org.openrndr.extra.kdtree.kdTree
|
||||
import org.openrndr.extra.kdtree.vector2Mapper
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.LineSegment
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
|
||||
configure {
|
||||
width = 1080
|
||||
height = 720
|
||||
@@ -18,12 +18,12 @@ fun main() {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = buildKDTree(points, 2, ::vector2Mapper)
|
||||
val tree = points.kdTree()
|
||||
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
|
||||
val kNearest = findKNearest(tree, mouse.position, k=7, dimensions = 2, ::vector2Mapper)
|
||||
val kNearest = tree.findKNearest(mouse.position, k = 7)
|
||||
drawer.fill = ColorRGBa.RED
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.strokeWeight = 2.0
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.kdtree.buildKDTree
|
||||
import org.openrndr.extra.kdtree.findNearest
|
||||
import org.openrndr.extra.kdtree.vector2Mapper
|
||||
import org.openrndr.extra.kdtree.kdTree
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
fun main() {
|
||||
@@ -15,10 +12,10 @@ fun main() {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = buildKDTree(points, 2, ::vector2Mapper)
|
||||
val tree = points.kdTree()
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
val nearest = findNearest(tree, mouse.position, 2, ::vector2Mapper)
|
||||
val nearest = tree.findNearest(mouse.position)
|
||||
nearest?.let {
|
||||
drawer.circle(it.x, it.y, 20.0)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.kdtree.buildKDTree
|
||||
import org.openrndr.extra.kdtree.findAllInRange
|
||||
import org.openrndr.extra.kdtree.vector2Mapper
|
||||
import org.openrndr.extra.kdtree.kdTree
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
|
||||
@@ -18,13 +16,13 @@ fun main() {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = buildKDTree(points, 2, ::vector2Mapper)
|
||||
val tree = points.kdTree()
|
||||
val radius = 50.0
|
||||
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
|
||||
val allInRange = findAllInRange(tree, mouse.position, maxDistance = radius, dimensions = 2, ::vector2Mapper)
|
||||
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.strokeWeight = 2.0
|
||||
|
||||
Reference in New Issue
Block a user