Skip to main content

RTreed

Struct RTreed 

Source
pub struct RTreed<C: Keyed>
where C::Value: RTreeObject,
{ /* private fields */ }

Implementations§

Source§

impl<C: Keyed> RTreed<C>
where C::Value: RTreeObject,

Source

pub fn new(collection: C) -> Self

Examples found in repository?
examples/hashmap.rs (line 15)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::new(rect_hashmap);
16
17    // Insert two rectangles, recording them in the R-tree.
18    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
19    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
20
21    // Locate the two rectangles in the R-tree.
22    assert_eq!(
23        rtreed
24            .rtree()
25            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
26            .count(),
27        2
28    );
29
30    // Now remove one of the rectangles, recording this in the R-tree.
31    rtreed.remove(&1);
32
33    // Make the same query to the R-tree as before.
34    // Only one rectangle is now present.
35    assert_eq!(
36        rtreed
37            .rtree()
38            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
39            .count(),
40        1
41    );
42}
More examples
Hide additional examples
examples/multipolygon.rs (line 11)
9fn main() {
10    let multipolygon: MultiPolygon<f64> = MultiPolygon::new(vec![]);
11    let mut rtreed = RTreed::new(multipolygon);
12
13    // Push two polygons, recording them in the R-tree.
14    rtreed.push(Polygon::new(
15        line_string![
16            (x: 0.0, y: 0.0),
17            (x: 1.0, y: 0.0),
18            (x: 1.0, y: 1.0),
19            (x: 0.0, y: 0.0),
20        ],
21        vec![],
22    ));
23    rtreed.push(Polygon::new(
24        line_string![
25            (x: 1.0, y: 1.0),
26            (x: 2.0, y: 1.0),
27            (x: 2.0, y: 2.0),
28            (x: 1.0, y: 1.0),
29        ],
30        vec![],
31    ));
32
33    // Locate the two polygons in the R-tree.
34    assert_eq!(
35        rtreed
36            .rtree()
37            .locate_in_envelope(AABB::from_corners(
38                Point::new(0.0, 0.0),
39                Point::new(2.0, 2.0),
40            ))
41            .count(),
42        2
43    );
44
45    // Access a polygon by its index in the MultiPolygon.
46    assert_eq!(
47        rtreed.get(&0),
48        Some(&Polygon::new(
49            line_string![
50                (x: 0.0, y: 0.0),
51                (x: 1.0, y: 0.0),
52                (x: 1.0, y: 1.0),
53                (x: 0.0, y: 0.0),
54            ],
55            vec![],
56        ))
57    );
58}
examples/vec.rs (line 13)
8fn main() {
9    // A vec of 2D rectangles will be the underlying collection.
10    let rect_vec: Vec<Rectangle<(i32, i32)>> = Vec::new();
11
12    // Wrap `RTreed` around the vec.
13    let mut rtreed = RTreed::new(rect_vec);
14
15    // Push two rectangles, recording them in the R-tree.
16    rtreed.push(Rectangle::from_corners((0, 0), (1, 1)));
17    rtreed.push(Rectangle::from_corners((1, 1), (2, 2)));
18
19    // Locate the two rectangles in the R-tree.
20    assert_eq!(
21        rtreed
22            .rtree()
23            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
24            .count(),
25        2
26    );
27
28    // Access a rectangle by its index in the vec.
29    assert_eq!(
30        rtreed.get(&0),
31        Some(&Rectangle::from_corners((0, 0), (1, 1)))
32    );
33
34    // Push one more rectangle.
35    rtreed.push(Rectangle::from_corners((2, 2), (3, 3)));
36
37    // Swap-remove the first rectangle.
38    assert_eq!(
39        rtreed.swap_remove(&0),
40        Rectangle::from_corners((0, 0), (1, 1))
41    );
42
43    // Now the latest-pushed rectangle occupies the place of the first
44    // rectangle. The second rectangle is as it was previously.
45    assert_eq!(
46        rtreed.get(&0),
47        Some(&Rectangle::from_corners((2, 2), (3, 3)))
48    );
49    assert_eq!(
50        rtreed.get(&1),
51        Some(&Rectangle::from_corners((1, 1), (2, 2)))
52    );
53    assert_eq!(
54        rtreed
55            .rtree()
56            .locate_in_envelope(AABB::from_corners((0, 0), (3, 3)))
57            .count(),
58        2
59    );
60}
examples/thunderdome.rs (line 16)
10fn main() {
11    // A generational arena of 2D polygons from `geo` will be the underlying
12    // collection.
13    let polygon_arena: Arena<Polygon<f64>> = Arena::new();
14
15    // Wrap `RTreed` around the arena.
16    let mut rtreed = RTreed::new(polygon_arena);
17
18    // Insert two polygons (two non-regular pentagons), recording them in the
19    // R-tree.
20    let first = rtreed.push(Polygon::new(
21        line_string![
22            (x: 0.0, y: 0.0),
23            (x: 2.0, y: 0.5),
24            (x: 2.5, y: 2.0),
25            (x: 1.0, y: 2.5),
26            (x: 0.0, y: 1.0),
27            (x: 0.0, y: 0.0),
28        ],
29        vec![],
30    ));
31    rtreed.push(Polygon::new(
32        line_string![
33            (x: 2.0, y: 2.0),
34            (x: 5.0, y: 2.5),
35            (x: 4.5, y: 4.0),
36            (x: 3.0, y: 5.0),
37            (x: 2.0, y: 2.0),
38        ],
39        vec![],
40    ));
41
42    // Locate the two polygons in the R-tree.
43    assert_eq!(
44        rtreed
45            .rtree()
46            .locate_in_envelope(AABB::from_corners(
47                Point::new(0.0, 0.0),
48                Point::new(5.0, 5.0),
49            ))
50            .count(),
51        2
52    );
53
54    // Now remove one of the polygons, recording this in the R-tree.
55    rtreed.remove(&first);
56
57    // Make the same query to the R-tree as before.
58    // Only one polygon is now present.
59    assert_eq!(
60        rtreed
61            .rtree()
62            .locate_in_envelope(AABB::from_corners(
63                Point::new(0.0, 0.0),
64                Point::new(5.0, 5.0),
65            ))
66            .count(),
67        1
68    );
69}
examples/undoredo.rs (line 18)
11fn main() {
12    // A hashmap of 2D rectangles will be the underlying container.
13    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
14    // Wrap `RTreed` around the hashmap and then `Recorder` around it.
15    let mut recorder = Recorder::<
16        RTreed<HashMap<i32, Rectangle<(i32, i32)>>>,
17        RTreedHalfDelta<i32, Rectangle<(i32, i32)>>,
18    >::new(RTreed::new(rect_hashmap));
19    let mut undoredo: UndoRedo<RTreedDelta<i32, Rectangle<(i32, i32)>>> = UndoRedo::new();
20
21    // Insert two rectangles, recording them in the R-tree.
22    recorder.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
23    undoredo.commit(&mut recorder);
24
25    recorder.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
26    undoredo.commit(&mut recorder);
27
28    // Locate the two rectangles in the R-tree.
29    assert_eq!(
30        recorder
31            .container()
32            .rtree()
33            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
34            .count(),
35        2
36    );
37
38    undoredo.undo(&mut recorder);
39
40    // After undo, there is now only one rectangle.
41    assert_eq!(
42        recorder
43            .container()
44            .rtree()
45            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
46            .count(),
47        1
48    );
49
50    undoredo.undo(&mut recorder);
51
52    // After another undo, there is no rectangles anymore.
53    assert_eq!(
54        recorder
55            .container()
56            .rtree()
57            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
58            .count(),
59        0
60    );
61
62    undoredo.redo(&mut recorder);
63
64    // After redo, we are back to one rectangle.
65    assert_eq!(
66        recorder
67            .container()
68            .rtree()
69            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
70            .count(),
71        1
72    );
73
74    undoredo.redo(&mut recorder);
75
76    // After another redo, we are back to two rectangles.
77    assert_eq!(
78        recorder
79            .container()
80            .rtree()
81            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
82            .count(),
83        2
84    );
85}
Source

pub fn collection(&self) -> &C

Source

pub fn rtree(&self) -> &RTree<GeomWithData<C::Value, C::Key>>

Examples found in repository?
examples/hashmap.rs (line 24)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::new(rect_hashmap);
16
17    // Insert two rectangles, recording them in the R-tree.
18    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
19    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
20
21    // Locate the two rectangles in the R-tree.
22    assert_eq!(
23        rtreed
24            .rtree()
25            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
26            .count(),
27        2
28    );
29
30    // Now remove one of the rectangles, recording this in the R-tree.
31    rtreed.remove(&1);
32
33    // Make the same query to the R-tree as before.
34    // Only one rectangle is now present.
35    assert_eq!(
36        rtreed
37            .rtree()
38            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
39            .count(),
40        1
41    );
42}
More examples
Hide additional examples
examples/multipolygon.rs (line 36)
9fn main() {
10    let multipolygon: MultiPolygon<f64> = MultiPolygon::new(vec![]);
11    let mut rtreed = RTreed::new(multipolygon);
12
13    // Push two polygons, recording them in the R-tree.
14    rtreed.push(Polygon::new(
15        line_string![
16            (x: 0.0, y: 0.0),
17            (x: 1.0, y: 0.0),
18            (x: 1.0, y: 1.0),
19            (x: 0.0, y: 0.0),
20        ],
21        vec![],
22    ));
23    rtreed.push(Polygon::new(
24        line_string![
25            (x: 1.0, y: 1.0),
26            (x: 2.0, y: 1.0),
27            (x: 2.0, y: 2.0),
28            (x: 1.0, y: 1.0),
29        ],
30        vec![],
31    ));
32
33    // Locate the two polygons in the R-tree.
34    assert_eq!(
35        rtreed
36            .rtree()
37            .locate_in_envelope(AABB::from_corners(
38                Point::new(0.0, 0.0),
39                Point::new(2.0, 2.0),
40            ))
41            .count(),
42        2
43    );
44
45    // Access a polygon by its index in the MultiPolygon.
46    assert_eq!(
47        rtreed.get(&0),
48        Some(&Polygon::new(
49            line_string![
50                (x: 0.0, y: 0.0),
51                (x: 1.0, y: 0.0),
52                (x: 1.0, y: 1.0),
53                (x: 0.0, y: 0.0),
54            ],
55            vec![],
56        ))
57    );
58}
examples/vec.rs (line 22)
8fn main() {
9    // A vec of 2D rectangles will be the underlying collection.
10    let rect_vec: Vec<Rectangle<(i32, i32)>> = Vec::new();
11
12    // Wrap `RTreed` around the vec.
13    let mut rtreed = RTreed::new(rect_vec);
14
15    // Push two rectangles, recording them in the R-tree.
16    rtreed.push(Rectangle::from_corners((0, 0), (1, 1)));
17    rtreed.push(Rectangle::from_corners((1, 1), (2, 2)));
18
19    // Locate the two rectangles in the R-tree.
20    assert_eq!(
21        rtreed
22            .rtree()
23            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
24            .count(),
25        2
26    );
27
28    // Access a rectangle by its index in the vec.
29    assert_eq!(
30        rtreed.get(&0),
31        Some(&Rectangle::from_corners((0, 0), (1, 1)))
32    );
33
34    // Push one more rectangle.
35    rtreed.push(Rectangle::from_corners((2, 2), (3, 3)));
36
37    // Swap-remove the first rectangle.
38    assert_eq!(
39        rtreed.swap_remove(&0),
40        Rectangle::from_corners((0, 0), (1, 1))
41    );
42
43    // Now the latest-pushed rectangle occupies the place of the first
44    // rectangle. The second rectangle is as it was previously.
45    assert_eq!(
46        rtreed.get(&0),
47        Some(&Rectangle::from_corners((2, 2), (3, 3)))
48    );
49    assert_eq!(
50        rtreed.get(&1),
51        Some(&Rectangle::from_corners((1, 1), (2, 2)))
52    );
53    assert_eq!(
54        rtreed
55            .rtree()
56            .locate_in_envelope(AABB::from_corners((0, 0), (3, 3)))
57            .count(),
58        2
59    );
60}
examples/thunderdome.rs (line 45)
10fn main() {
11    // A generational arena of 2D polygons from `geo` will be the underlying
12    // collection.
13    let polygon_arena: Arena<Polygon<f64>> = Arena::new();
14
15    // Wrap `RTreed` around the arena.
16    let mut rtreed = RTreed::new(polygon_arena);
17
18    // Insert two polygons (two non-regular pentagons), recording them in the
19    // R-tree.
20    let first = rtreed.push(Polygon::new(
21        line_string![
22            (x: 0.0, y: 0.0),
23            (x: 2.0, y: 0.5),
24            (x: 2.5, y: 2.0),
25            (x: 1.0, y: 2.5),
26            (x: 0.0, y: 1.0),
27            (x: 0.0, y: 0.0),
28        ],
29        vec![],
30    ));
31    rtreed.push(Polygon::new(
32        line_string![
33            (x: 2.0, y: 2.0),
34            (x: 5.0, y: 2.5),
35            (x: 4.5, y: 4.0),
36            (x: 3.0, y: 5.0),
37            (x: 2.0, y: 2.0),
38        ],
39        vec![],
40    ));
41
42    // Locate the two polygons in the R-tree.
43    assert_eq!(
44        rtreed
45            .rtree()
46            .locate_in_envelope(AABB::from_corners(
47                Point::new(0.0, 0.0),
48                Point::new(5.0, 5.0),
49            ))
50            .count(),
51        2
52    );
53
54    // Now remove one of the polygons, recording this in the R-tree.
55    rtreed.remove(&first);
56
57    // Make the same query to the R-tree as before.
58    // Only one polygon is now present.
59    assert_eq!(
60        rtreed
61            .rtree()
62            .locate_in_envelope(AABB::from_corners(
63                Point::new(0.0, 0.0),
64                Point::new(5.0, 5.0),
65            ))
66            .count(),
67        1
68    );
69}
examples/undoredo.rs (line 32)
11fn main() {
12    // A hashmap of 2D rectangles will be the underlying container.
13    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
14    // Wrap `RTreed` around the hashmap and then `Recorder` around it.
15    let mut recorder = Recorder::<
16        RTreed<HashMap<i32, Rectangle<(i32, i32)>>>,
17        RTreedHalfDelta<i32, Rectangle<(i32, i32)>>,
18    >::new(RTreed::new(rect_hashmap));
19    let mut undoredo: UndoRedo<RTreedDelta<i32, Rectangle<(i32, i32)>>> = UndoRedo::new();
20
21    // Insert two rectangles, recording them in the R-tree.
22    recorder.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
23    undoredo.commit(&mut recorder);
24
25    recorder.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
26    undoredo.commit(&mut recorder);
27
28    // Locate the two rectangles in the R-tree.
29    assert_eq!(
30        recorder
31            .container()
32            .rtree()
33            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
34            .count(),
35        2
36    );
37
38    undoredo.undo(&mut recorder);
39
40    // After undo, there is now only one rectangle.
41    assert_eq!(
42        recorder
43            .container()
44            .rtree()
45            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
46            .count(),
47        1
48    );
49
50    undoredo.undo(&mut recorder);
51
52    // After another undo, there is no rectangles anymore.
53    assert_eq!(
54        recorder
55            .container()
56            .rtree()
57            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
58            .count(),
59        0
60    );
61
62    undoredo.redo(&mut recorder);
63
64    // After redo, we are back to one rectangle.
65    assert_eq!(
66        recorder
67            .container()
68            .rtree()
69            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
70            .count(),
71        1
72    );
73
74    undoredo.redo(&mut recorder);
75
76    // After another redo, we are back to two rectangles.
77    assert_eq!(
78        recorder
79            .container()
80            .rtree()
81            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
82            .count(),
83        2
84    );
85}
Source§

impl<K, C> RTreed<C>
where C: Keyed<Key = K> + Get<K>, C::Value: RTreeObject,

Source

pub fn get(&self, key: &K) -> Option<&C::Value>

Examples found in repository?
examples/multipolygon.rs (line 47)
9fn main() {
10    let multipolygon: MultiPolygon<f64> = MultiPolygon::new(vec![]);
11    let mut rtreed = RTreed::new(multipolygon);
12
13    // Push two polygons, recording them in the R-tree.
14    rtreed.push(Polygon::new(
15        line_string![
16            (x: 0.0, y: 0.0),
17            (x: 1.0, y: 0.0),
18            (x: 1.0, y: 1.0),
19            (x: 0.0, y: 0.0),
20        ],
21        vec![],
22    ));
23    rtreed.push(Polygon::new(
24        line_string![
25            (x: 1.0, y: 1.0),
26            (x: 2.0, y: 1.0),
27            (x: 2.0, y: 2.0),
28            (x: 1.0, y: 1.0),
29        ],
30        vec![],
31    ));
32
33    // Locate the two polygons in the R-tree.
34    assert_eq!(
35        rtreed
36            .rtree()
37            .locate_in_envelope(AABB::from_corners(
38                Point::new(0.0, 0.0),
39                Point::new(2.0, 2.0),
40            ))
41            .count(),
42        2
43    );
44
45    // Access a polygon by its index in the MultiPolygon.
46    assert_eq!(
47        rtreed.get(&0),
48        Some(&Polygon::new(
49            line_string![
50                (x: 0.0, y: 0.0),
51                (x: 1.0, y: 0.0),
52                (x: 1.0, y: 1.0),
53                (x: 0.0, y: 0.0),
54            ],
55            vec![],
56        ))
57    );
58}
More examples
Hide additional examples
examples/vec.rs (line 30)
8fn main() {
9    // A vec of 2D rectangles will be the underlying collection.
10    let rect_vec: Vec<Rectangle<(i32, i32)>> = Vec::new();
11
12    // Wrap `RTreed` around the vec.
13    let mut rtreed = RTreed::new(rect_vec);
14
15    // Push two rectangles, recording them in the R-tree.
16    rtreed.push(Rectangle::from_corners((0, 0), (1, 1)));
17    rtreed.push(Rectangle::from_corners((1, 1), (2, 2)));
18
19    // Locate the two rectangles in the R-tree.
20    assert_eq!(
21        rtreed
22            .rtree()
23            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
24            .count(),
25        2
26    );
27
28    // Access a rectangle by its index in the vec.
29    assert_eq!(
30        rtreed.get(&0),
31        Some(&Rectangle::from_corners((0, 0), (1, 1)))
32    );
33
34    // Push one more rectangle.
35    rtreed.push(Rectangle::from_corners((2, 2), (3, 3)));
36
37    // Swap-remove the first rectangle.
38    assert_eq!(
39        rtreed.swap_remove(&0),
40        Rectangle::from_corners((0, 0), (1, 1))
41    );
42
43    // Now the latest-pushed rectangle occupies the place of the first
44    // rectangle. The second rectangle is as it was previously.
45    assert_eq!(
46        rtreed.get(&0),
47        Some(&Rectangle::from_corners((2, 2), (3, 3)))
48    );
49    assert_eq!(
50        rtreed.get(&1),
51        Some(&Rectangle::from_corners((1, 1), (2, 2)))
52    );
53    assert_eq!(
54        rtreed
55            .rtree()
56            .locate_in_envelope(AABB::from_corners((0, 0), (3, 3)))
57            .count(),
58        2
59    );
60}
Source§

impl<K, C> RTreed<C>
where K: Clone, C: Keyed<Key = K> + Get<K> + Insert<K>, C::Value: Clone + RTreeObject,

Source

pub fn insert(&mut self, key: K, value: C::Value) -> <C as Insert<K>>::Output

Examples found in repository?
examples/hashmap.rs (line 18)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::new(rect_hashmap);
16
17    // Insert two rectangles, recording them in the R-tree.
18    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
19    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
20
21    // Locate the two rectangles in the R-tree.
22    assert_eq!(
23        rtreed
24            .rtree()
25            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
26            .count(),
27        2
28    );
29
30    // Now remove one of the rectangles, recording this in the R-tree.
31    rtreed.remove(&1);
32
33    // Make the same query to the R-tree as before.
34    // Only one rectangle is now present.
35    assert_eq!(
36        rtreed
37            .rtree()
38            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
39            .count(),
40        1
41    );
42}
Source§

impl<K, C> RTreed<C>
where K: Clone + PartialEq, C: Keyed<Key = K> + Set<K>, C::Value: Clone + PartialEq + RTreeObject,

Source

pub fn set(&mut self, key: K, value: C::Value) -> <C as Set<K>>::Output

Source§

impl<K, V, C> RTreed<C>
where K: Clone + PartialEq, V: Clone + PartialEq + RTreeObject, C: Keyed<Key = K, Value = V> + Remove<K, Output = Option<V>>,

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Examples found in repository?
examples/hashmap.rs (line 31)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::new(rect_hashmap);
16
17    // Insert two rectangles, recording them in the R-tree.
18    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
19    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
20
21    // Locate the two rectangles in the R-tree.
22    assert_eq!(
23        rtreed
24            .rtree()
25            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
26            .count(),
27        2
28    );
29
30    // Now remove one of the rectangles, recording this in the R-tree.
31    rtreed.remove(&1);
32
33    // Make the same query to the R-tree as before.
34    // Only one rectangle is now present.
35    assert_eq!(
36        rtreed
37            .rtree()
38            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
39            .count(),
40        1
41    );
42}
More examples
Hide additional examples
examples/thunderdome.rs (line 55)
10fn main() {
11    // A generational arena of 2D polygons from `geo` will be the underlying
12    // collection.
13    let polygon_arena: Arena<Polygon<f64>> = Arena::new();
14
15    // Wrap `RTreed` around the arena.
16    let mut rtreed = RTreed::new(polygon_arena);
17
18    // Insert two polygons (two non-regular pentagons), recording them in the
19    // R-tree.
20    let first = rtreed.push(Polygon::new(
21        line_string![
22            (x: 0.0, y: 0.0),
23            (x: 2.0, y: 0.5),
24            (x: 2.5, y: 2.0),
25            (x: 1.0, y: 2.5),
26            (x: 0.0, y: 1.0),
27            (x: 0.0, y: 0.0),
28        ],
29        vec![],
30    ));
31    rtreed.push(Polygon::new(
32        line_string![
33            (x: 2.0, y: 2.0),
34            (x: 5.0, y: 2.5),
35            (x: 4.5, y: 4.0),
36            (x: 3.0, y: 5.0),
37            (x: 2.0, y: 2.0),
38        ],
39        vec![],
40    ));
41
42    // Locate the two polygons in the R-tree.
43    assert_eq!(
44        rtreed
45            .rtree()
46            .locate_in_envelope(AABB::from_corners(
47                Point::new(0.0, 0.0),
48                Point::new(5.0, 5.0),
49            ))
50            .count(),
51        2
52    );
53
54    // Now remove one of the polygons, recording this in the R-tree.
55    rtreed.remove(&first);
56
57    // Make the same query to the R-tree as before.
58    // Only one polygon is now present.
59    assert_eq!(
60        rtreed
61            .rtree()
62            .locate_in_envelope(AABB::from_corners(
63                Point::new(0.0, 0.0),
64                Point::new(5.0, 5.0),
65            ))
66            .count(),
67        1
68    );
69}
Source§

impl<V, C> RTreed<C>
where V: Clone + PartialEq + RTreeObject, C: Keyed<Key = usize, Value = V> + Get<usize> + Len + SwapRemove<usize, Output = V>,

Source

pub fn swap_remove(&mut self, key: &usize) -> V

Examples found in repository?
examples/vec.rs (line 39)
8fn main() {
9    // A vec of 2D rectangles will be the underlying collection.
10    let rect_vec: Vec<Rectangle<(i32, i32)>> = Vec::new();
11
12    // Wrap `RTreed` around the vec.
13    let mut rtreed = RTreed::new(rect_vec);
14
15    // Push two rectangles, recording them in the R-tree.
16    rtreed.push(Rectangle::from_corners((0, 0), (1, 1)));
17    rtreed.push(Rectangle::from_corners((1, 1), (2, 2)));
18
19    // Locate the two rectangles in the R-tree.
20    assert_eq!(
21        rtreed
22            .rtree()
23            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
24            .count(),
25        2
26    );
27
28    // Access a rectangle by its index in the vec.
29    assert_eq!(
30        rtreed.get(&0),
31        Some(&Rectangle::from_corners((0, 0), (1, 1)))
32    );
33
34    // Push one more rectangle.
35    rtreed.push(Rectangle::from_corners((2, 2), (3, 3)));
36
37    // Swap-remove the first rectangle.
38    assert_eq!(
39        rtreed.swap_remove(&0),
40        Rectangle::from_corners((0, 0), (1, 1))
41    );
42
43    // Now the latest-pushed rectangle occupies the place of the first
44    // rectangle. The second rectangle is as it was previously.
45    assert_eq!(
46        rtreed.get(&0),
47        Some(&Rectangle::from_corners((2, 2), (3, 3)))
48    );
49    assert_eq!(
50        rtreed.get(&1),
51        Some(&Rectangle::from_corners((1, 1), (2, 2)))
52    );
53    assert_eq!(
54        rtreed
55            .rtree()
56            .locate_in_envelope(AABB::from_corners((0, 0), (3, 3)))
57            .count(),
58        2
59    );
60}
Source§

impl<K, C> RTreed<C>
where K: Clone, C: Keyed<Key = K> + Push<K>, C::Value: Clone + RTreeObject,

Source

pub fn push(&mut self, value: C::Value) -> K

Examples found in repository?
examples/multipolygon.rs (lines 14-22)
9fn main() {
10    let multipolygon: MultiPolygon<f64> = MultiPolygon::new(vec![]);
11    let mut rtreed = RTreed::new(multipolygon);
12
13    // Push two polygons, recording them in the R-tree.
14    rtreed.push(Polygon::new(
15        line_string![
16            (x: 0.0, y: 0.0),
17            (x: 1.0, y: 0.0),
18            (x: 1.0, y: 1.0),
19            (x: 0.0, y: 0.0),
20        ],
21        vec![],
22    ));
23    rtreed.push(Polygon::new(
24        line_string![
25            (x: 1.0, y: 1.0),
26            (x: 2.0, y: 1.0),
27            (x: 2.0, y: 2.0),
28            (x: 1.0, y: 1.0),
29        ],
30        vec![],
31    ));
32
33    // Locate the two polygons in the R-tree.
34    assert_eq!(
35        rtreed
36            .rtree()
37            .locate_in_envelope(AABB::from_corners(
38                Point::new(0.0, 0.0),
39                Point::new(2.0, 2.0),
40            ))
41            .count(),
42        2
43    );
44
45    // Access a polygon by its index in the MultiPolygon.
46    assert_eq!(
47        rtreed.get(&0),
48        Some(&Polygon::new(
49            line_string![
50                (x: 0.0, y: 0.0),
51                (x: 1.0, y: 0.0),
52                (x: 1.0, y: 1.0),
53                (x: 0.0, y: 0.0),
54            ],
55            vec![],
56        ))
57    );
58}
More examples
Hide additional examples
examples/vec.rs (line 16)
8fn main() {
9    // A vec of 2D rectangles will be the underlying collection.
10    let rect_vec: Vec<Rectangle<(i32, i32)>> = Vec::new();
11
12    // Wrap `RTreed` around the vec.
13    let mut rtreed = RTreed::new(rect_vec);
14
15    // Push two rectangles, recording them in the R-tree.
16    rtreed.push(Rectangle::from_corners((0, 0), (1, 1)));
17    rtreed.push(Rectangle::from_corners((1, 1), (2, 2)));
18
19    // Locate the two rectangles in the R-tree.
20    assert_eq!(
21        rtreed
22            .rtree()
23            .locate_in_envelope(AABB::from_corners((0, 0), (2, 2)))
24            .count(),
25        2
26    );
27
28    // Access a rectangle by its index in the vec.
29    assert_eq!(
30        rtreed.get(&0),
31        Some(&Rectangle::from_corners((0, 0), (1, 1)))
32    );
33
34    // Push one more rectangle.
35    rtreed.push(Rectangle::from_corners((2, 2), (3, 3)));
36
37    // Swap-remove the first rectangle.
38    assert_eq!(
39        rtreed.swap_remove(&0),
40        Rectangle::from_corners((0, 0), (1, 1))
41    );
42
43    // Now the latest-pushed rectangle occupies the place of the first
44    // rectangle. The second rectangle is as it was previously.
45    assert_eq!(
46        rtreed.get(&0),
47        Some(&Rectangle::from_corners((2, 2), (3, 3)))
48    );
49    assert_eq!(
50        rtreed.get(&1),
51        Some(&Rectangle::from_corners((1, 1), (2, 2)))
52    );
53    assert_eq!(
54        rtreed
55            .rtree()
56            .locate_in_envelope(AABB::from_corners((0, 0), (3, 3)))
57            .count(),
58        2
59    );
60}
examples/thunderdome.rs (lines 20-30)
10fn main() {
11    // A generational arena of 2D polygons from `geo` will be the underlying
12    // collection.
13    let polygon_arena: Arena<Polygon<f64>> = Arena::new();
14
15    // Wrap `RTreed` around the arena.
16    let mut rtreed = RTreed::new(polygon_arena);
17
18    // Insert two polygons (two non-regular pentagons), recording them in the
19    // R-tree.
20    let first = rtreed.push(Polygon::new(
21        line_string![
22            (x: 0.0, y: 0.0),
23            (x: 2.0, y: 0.5),
24            (x: 2.5, y: 2.0),
25            (x: 1.0, y: 2.5),
26            (x: 0.0, y: 1.0),
27            (x: 0.0, y: 0.0),
28        ],
29        vec![],
30    ));
31    rtreed.push(Polygon::new(
32        line_string![
33            (x: 2.0, y: 2.0),
34            (x: 5.0, y: 2.5),
35            (x: 4.5, y: 4.0),
36            (x: 3.0, y: 5.0),
37            (x: 2.0, y: 2.0),
38        ],
39        vec![],
40    ));
41
42    // Locate the two polygons in the R-tree.
43    assert_eq!(
44        rtreed
45            .rtree()
46            .locate_in_envelope(AABB::from_corners(
47                Point::new(0.0, 0.0),
48                Point::new(5.0, 5.0),
49            ))
50            .count(),
51        2
52    );
53
54    // Now remove one of the polygons, recording this in the R-tree.
55    rtreed.remove(&first);
56
57    // Make the same query to the R-tree as before.
58    // Only one polygon is now present.
59    assert_eq!(
60        rtreed
61            .rtree()
62            .locate_in_envelope(AABB::from_corners(
63                Point::new(0.0, 0.0),
64                Point::new(5.0, 5.0),
65            ))
66            .count(),
67        1
68    );
69}

Trait Implementations§

Source§

impl<K: Clone + PartialEq, V: Clone + PartialEq + RTreeObject, C: Get<K> + Keyed<Key = K, Value = V> + Insert<K> + Remove<K, Output = Option<V>>, DC: IntoIter<K> + Keyed<Key = K, Value = V>> ApplyDelta<DC> for RTreed<C>

Available on crate feature undoredo only.
Source§

fn apply_delta(&mut self, delta: Delta<DC>)

Apply the changes in a delta to a container. Read more
Source§

impl<C: Keyed> AsRef<RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>> for RTreed<C>
where C::Value: RTreeObject,

Source§

fn as_ref(&self) -> &RTree<GeomWithData<C::Value, C::Key>>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<C: Clone + Keyed> Clone for RTreed<C>
where C::Value: RTreeObject + Clone, C::Key: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Keyed> Container for RTreed<C>
where C::Value: RTreeObject,

Source§

type Value = <C as Container>::Value

Type of the values in the collection.
Source§

impl<C: Debug + Keyed> Debug for RTreed<C>
where C::Value: RTreeObject + Debug, C::Key: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Default + Keyed> Default for RTreed<C>
where C::Value: RTreeObject + Default, C::Key: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, C> Get<K> for RTreed<C>
where C: Keyed<Key = K> + Get<K>, C::Value: RTreeObject,

Source§

fn get(&self, key: &K) -> Option<&C::Value>

Returns a reference to the value corresponding to the key.
Source§

impl<K, C> Insert<K> for RTreed<C>
where K: Clone, C: Keyed<Key = K> + Get<K> + Insert<K>, C::Value: Clone + RTreeObject,

Source§

type Output = <C as Insert<K>>::Output

Return type of insert.
Source§

fn insert(&mut self, key: K, value: C::Value) -> Self::Output

Insert a new key-value pair into the container at an arbitrary key. Read more
Source§

impl<K, C> IntoIter<K> for RTreed<C>
where C: Keyed<Key = K> + IntoIter<K>, C::Value: RTreeObject,

Source§

type IntoIter = <C as IntoIter<K>>::IntoIter

Iterator that consumes the collection.
Source§

fn into_iter(self) -> C::IntoIter

Consume the collection and yield owned key-value pairs.
Source§

impl<C: Keyed> Keyed for RTreed<C>
where C::Value: RTreeObject,

Source§

type Key = <C as Keyed>::Key

Type of the keys in the keyed collection.
Source§

impl<K, C> Push<K> for RTreed<C>
where K: Clone, C: Keyed<Key = K> + Push<K>, C::Value: Clone + RTreeObject,

Source§

fn push(&mut self, value: C::Value) -> K

Insert a value into the collection without specifying a key, returning the key that was automatically generated.
Source§

impl<K, V, C> Remove<K> for RTreed<C>
where K: Clone + PartialEq, V: Clone + PartialEq + RTreeObject, C: Keyed<Key = K, Value = V> + Remove<K, Output = Option<V>>,

Source§

type Output = Option<V>

Return type of remove.
Source§

fn remove(&mut self, key: &K) -> Option<V>

Remove an element under a key from the collection, returning the value at the key if the key was previously in the map. Other keys are not invalidated. Read more
Source§

impl<K, C> Set<K> for RTreed<C>
where K: Clone + PartialEq, C: Keyed<Key = K> + Set<K> + Insert<K>, C::Value: Clone + PartialEq + RTreeObject,

Source§

type Output = <C as Set<K>>::Output

Return type of set.
Source§

fn set(&mut self, key: K, value: C::Value) -> Self::Output

Set the value of an already existing element under a key. Read more
Source§

impl<V, C> SwapRemove<usize> for RTreed<C>
where V: Clone + PartialEq + RTreeObject, C: Keyed<Key = usize, Value = V> + Get<usize> + Len + SwapRemove<usize, Output = V>,

Source§

type Output = V

Return type of swap_remove.
Source§

fn swap_remove(&mut self, key: &usize) -> V

Remove an element under a key by swapping it with the last element, returning the removed value. Read more

Auto Trait Implementations§

§

impl<C> Freeze for RTreed<C>
where C: Freeze, RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>: Freeze,

§

impl<C> RefUnwindSafe for RTreed<C>

§

impl<C> Send for RTreed<C>
where C: Send, RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>: Send,

§

impl<C> Sync for RTreed<C>
where C: Sync, RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>: Sync,

§

impl<C> Unpin for RTreed<C>
where C: Unpin, RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>: Unpin,

§

impl<C> UnsafeUnpin for RTreed<C>

§

impl<C> UnwindSafe for RTreed<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<V> Assign for V
where V: Keyed,

Source§

fn assign(&mut self, value: V)

Replace self with a new value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

Source§

fn cast_into(self) -> U

Convert this value’s type into another type to another using Rust’s as keyword casting.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> QuantizeInto<U> for T
where U: QuantizeFrom<T>,

Source§

fn quantize_into(self, multiplier: T) -> U

Multiply a number by a multiplier, round it to an integer, and convert it to another type, or do nothing if input type is integer.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.