// R-tree point-containment and distance-threshold queries.
///|
/// True iff `pt` lies within `rect` (closed boundary).
fn rect_contains_point(rect : @type.Rect, pt : @type.Coord) -> Bool {
rect.min().x() <= pt.x() &&
pt.x() <= rect.max().x() &&
rect.min().y() <= pt.y() &&
pt.y() <= rect.max().y()
}
///|
fn[T] locate_at_point_recurse(
node : Node[T],
pt : @type.Coord,
out : Array[T],
) -> Unit {
match node {
Leaf(bbox, entries) => {
if !rect_contains_point(bbox, pt) {
return
}
for i in 0.. {
if !rect_contains_point(bbox, pt) {
return
}
for i in 0.. Array[T] {
let out : Array[T] = []
match self.root {
None => ()
Some(root) => locate_at_point_recurse(root, pt, out)
}
out
}
///|
fn[T] locate_within_distance_recurse(
node : Node[T],
pt : @type.Coord,
max_dist_sq : Double,
out : Array[T],
) -> Unit {
match node {
Leaf(bbox, entries) => {
if rect_min_dist_sq(pt, bbox) > max_dist_sq {
return
}
for i in 0.. {
if rect_min_dist_sq(pt, bbox) > max_dist_sq {
return
}
for i in 0.. Array[T] {
let out : Array[T] = []
let max_dist_sq = r * r
match self.root {
None => ()
Some(root) => locate_within_distance_recurse(root, pt, max_dist_sq, out)
}
out
}