geo_index/rtree/sort/trait.rs
1use crate::indices::MutableIndices;
2use crate::r#type::IndexableNum;
3
4/// Parameters that are passed in to the `sort` function of the `Sort` trait.
5pub struct SortParams<N: IndexableNum> {
6 /// The number of items in this RTree
7 pub num_items: usize,
8 /// The node size of this RTree
9 pub node_size: usize,
10 /// The global min_x of this RTree
11 pub min_x: N,
12 /// The global min_y of this RTree
13 pub min_y: N,
14 /// The global max_x of this RTree
15 pub max_x: N,
16 /// The global max_y of this RTree
17 pub max_y: N,
18}
19
20/// A trait for sorting the elements of an RTree.
21pub trait Sort<N: IndexableNum> {
22 /// Sort the mutable slice of `boxes` and `indices`.
23 ///
24 /// ## Invariants:
25 ///
26 /// - Each element in `boxes` consists of four numbers.
27 /// - Each element in `boxes` is ordered `[min_x, min_y, max_x, max_y]`.
28 /// - The relative order of elements within `boxes` and `indices` must be maintained. If you're
29 /// swapping the first box with the second box, you must also swap the first index with the
30 /// second index.
31 fn sort(sort_params: &mut SortParams<N>, boxes: &mut [N], indices: &mut MutableIndices);
32}