pub struct Rectangle<P> { /* private fields */ }Expand description
Implementations§
Source§impl<P> Rectangle<P>
impl<P> Rectangle<P>
Sourcepub fn from_corners(corner_1: P, corner_2: P) -> Selfwhere
P: Point,
pub fn from_corners(corner_1: P, corner_2: P) -> Selfwhere
P: Point,
Creates a new rectangle defined by two corners.
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}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/undoredo.rs (line 22)
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}Trait Implementations§
impl<P: Copy> Copy for Rectangle<P>
Source§impl<'de, P> Deserialize<'de> for Rectangle<P>where
P: Deserialize<'de>,
Available on crate feature serde only.
impl<'de, P> Deserialize<'de> for Rectangle<P>where
P: Deserialize<'de>,
Available on crate feature
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<P: Eq> Eq for Rectangle<P>
Source§impl<P: Ord> Ord for Rectangle<P>
impl<P: Ord> Ord for Rectangle<P>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<P: PartialOrd> PartialOrd for Rectangle<P>
impl<P: PartialOrd> PartialOrd for Rectangle<P>
Source§impl<P> PointDistance for Rectangle<P>where
P: Point,
impl<P> PointDistance for Rectangle<P>where
P: Point,
Source§fn distance_2(
&self,
point: &<Self::Envelope as Envelope>::Point,
) -> <<Self::Envelope as Envelope>::Point as Point>::Scalar
fn distance_2( &self, point: &<Self::Envelope as Envelope>::Point, ) -> <<Self::Envelope as Envelope>::Point as Point>::Scalar
Returns the squared distance between an object and a point. Read more
Source§fn contains_point(&self, point: &<Self::Envelope as Envelope>::Point) -> bool
fn contains_point(&self, point: &<Self::Envelope as Envelope>::Point) -> bool
Returns
true if a point is contained within this object. Read moreSource§fn distance_2_if_less_or_equal(
&self,
point: &<Self::Envelope as Envelope>::Point,
max_distance_2: <<Self::Envelope as Envelope>::Point as Point>::Scalar,
) -> Option<<<Self::Envelope as Envelope>::Point as Point>::Scalar>
fn distance_2_if_less_or_equal( &self, point: &<Self::Envelope as Envelope>::Point, max_distance_2: <<Self::Envelope as Envelope>::Point as Point>::Scalar, ) -> Option<<<Self::Envelope as Envelope>::Point as Point>::Scalar>
Returns the squared distance to this object, or
None if the distance
is larger than a given maximum value. Read moreSource§impl<P> RTreeObject for Rectangle<P>where
P: Point,
impl<P> RTreeObject for Rectangle<P>where
P: Point,
impl<P: PartialEq> StructuralPartialEq for Rectangle<P>
Auto Trait Implementations§
impl<P> Freeze for Rectangle<P>
impl<P> RefUnwindSafe for Rectangle<P>where
AABB<P>: RefUnwindSafe,
impl<P> Send for Rectangle<P>
impl<P> Sync for Rectangle<P>
impl<P> Unpin for Rectangle<P>
impl<P> UnsafeUnpin for Rectangle<P>where
AABB<P>: UnsafeUnpin,
impl<P> UnwindSafe for Rectangle<P>where
AABB<P>: UnwindSafe,
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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.