pub struct RTreed<C: Keyed>where
C::Value: RTreeObject,{ /* private fields */ }Implementations§
Source§impl<C: Keyed> RTreed<C>where
C::Value: RTreeObject,
impl<C: Keyed> RTreed<C>where
C::Value: RTreeObject,
Sourcepub fn new(collection: C) -> Self
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
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}pub fn collection(&self) -> &C
Sourcepub fn rtree(&self) -> &RTree<GeomWithData<C::Value, C::Key>>
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
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>
impl<K, C> RTreed<C>
Sourcepub fn get(&self, key: &K) -> Option<&C::Value>
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
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>
impl<K, C> RTreed<C>
Sourcepub fn insert(&mut self, key: K, value: C::Value) -> <C as Insert<K>>::Output
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, V, C> RTreed<C>
impl<K, V, C> RTreed<C>
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
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
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>,
impl<V, C> RTreed<C>where
V: Clone + PartialEq + RTreeObject,
C: Keyed<Key = usize, Value = V> + Get<usize> + Len + SwapRemove<usize, Output = V>,
Sourcepub fn swap_remove(&mut self, key: &usize) -> V
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>
impl<K, C> RTreed<C>
Sourcepub fn push(&mut self, value: C::Value) -> K
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
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.
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>)
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,
impl<C: Keyed> AsRef<RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>> for RTreed<C>where
C::Value: RTreeObject,
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>,
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
type Output = V
Return type of
swap_remove.Source§fn swap_remove(&mut self, key: &usize) -> V
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>
impl<C> RefUnwindSafe for RTreed<C>where
C: RefUnwindSafe,
RTree<GeomWithData<<C as Container>::Value, <C as Keyed>::Key>>: RefUnwindSafe,
impl<C> Send for RTreed<C>
impl<C> Sync for RTreed<C>
impl<C> Unpin for RTreed<C>
impl<C> UnsafeUnpin for RTreed<C>
impl<C> UnwindSafe for RTreed<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> QuantizeInto<U> for Twhere
U: QuantizeFrom<T>,
impl<T, U> QuantizeInto<U> for Twhere
U: QuantizeFrom<T>,
Source§fn quantize_into(self, multiplier: T) -> U
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.