Skip to content

Commit ca6356c

Browse files
committed
index: improve Aabb2D::intersect documentation
1 parent 543f8bf commit ca6356c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

understory_index/src/types.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ impl<T: Copy + PartialOrd> Aabb2D<T> {
7474
/// method instead.
7575
///
7676
/// The resulting bounding box has zero area if there is no overlap.
77+
///
78+
/// # Examples
79+
///
80+
/// ```
81+
/// use understory_index::Aabb2D;
82+
///
83+
/// let aabb1 = Aabb2D::new(0., 0., 10., 10.);
84+
/// let aabb2 = Aabb2D::new(5., 5., 20., 20.);
85+
/// let aabb3 = Aabb2D::new(15., 15., 30., 30.);
86+
///
87+
/// // Diagramatically, these bounding boxes encode the following.
88+
/// //
89+
/// // +---------+
90+
/// // | 1 +----+---------+
91+
/// // +----+----+ |
92+
/// // | 2 +----+---------+
93+
/// // +---------+----+ |
94+
/// // | 3 |
95+
/// // +--------------+
96+
///
97+
/// let intersection = aabb1.intersect(&aabb2);
98+
/// assert_eq!(intersection, Aabb2D::new(5., 5., 10., 10.));
99+
/// let intersection = aabb1.intersect(&aabb2).intersect(&aabb3);
100+
/// assert!(intersection.is_zero_area());
101+
/// ```
77102
#[inline]
78103
pub fn intersect(&self, other: &Self) -> Self {
79104
let min_x = max_t(self.min_x, other.min_x);

0 commit comments

Comments
 (0)