Closed wzli closed 2 years ago
I believe r-tree can only be used with Euclidean metric; what's used (l-infinity) is not a Euclidean norm. I am unsure if there's a different data structure that supports this metric.
Edit: incorrect mouse clicks. I'll leave the issue open for a while.
Since you are essentially looking for a rectangular box around the query point, would this example cover your use-case: https://docs.rs/rstar/latest/rstar/struct.RTree.html#example-3 ?
use rstar::{RTree, AABB};
let mut tree = RTree::bulk_load(vec![
[0.0, 0.0],
[0.0, 1.0],
[1.0, 1.0]
]);
let half_unit_square = AABB::from_corners([0.0, 0.0], [0.5, 1.0]);
let unit_square = AABB::from_corners([0.0, 0.0], [1.0, 1.0]);
let elements_in_half_unit_square = tree.locate_in_envelope(&half_unit_square);
let elements_in_unit_square = tree.locate_in_envelope(&unit_square);
assert_eq!(elements_in_half_unit_square.count(), 2);
assert_eq!(elements_in_unit_square.count(), 3);
Yes, querying an square box is a workable substitute, thanks. There could be a disclaimer about euclidean metrics only though, it's not so obvious once you have the freedom to implement your own. And particularly when it goes undetected since most things work as normal.
Hi, I'm trying to make a game on a square grid. Objects can move one of 8 cardinal directions each step. So the distance metric is modified to reflect this constraint. Things mostly seem to work, but troubleshooting a bug lead to discovering unexpected behavior with the locate_within_distance call.
Reproduce (on 0.9.3):
Output: