Skip to content

Commit

Permalink
add contains_inclusive and clean up description (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
ua-kxie authored Mar 22, 2024
1 parent b27ae33 commit 1be49d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/box2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,21 @@ where
&& self.max.y > other.min.y
}

/// Returns `true` if this box contains the point. Points are considered
/// in the box if they are on the front, left or top faces, but outside if they
/// are on the back, right or bottom faces.
/// Returns `true` if this box2d contains the point `p`. A point is considered
/// in the box2d if it lies on the left or top edges, but outside if it lies
/// on the right or bottom edges.
#[inline]
pub fn contains(&self, p: Point2D<T, U>) -> bool {
self.min.x <= p.x && p.x < self.max.x && self.min.y <= p.y && p.y < self.max.y
}

/// Returns `true` if this box contains the point `p`. A point is considered
/// in the box2d if it lies on any edge of the box2d.
#[inline]
pub fn contains_inclusive(&self, p: Point2D<T, U>) -> bool {
self.min.x <= p.x && p.x <= self.max.x && self.min.y <= p.y && p.y <= self.max.y
}

/// Returns `true` if this box contains the interior of the other box. Always
/// returns `true` if other is empty, and always returns `false` if other is
/// nonempty but this box is empty.
Expand Down
18 changes: 15 additions & 3 deletions src/box3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ where
&& self.max.z > other.min.z
}

/// Returns `true` if this box3d contains the point. Points are considered
/// in the box3d if they are on the front, left or top faces, but outside if they
/// are on the back, right or bottom faces.
/// Returns `true` if this box3d contains the point `p`. A point is considered
/// in the box3d if it lies on the front, left or top faces, but outside if it lies
/// on the back, right or bottom faces.
#[inline]
pub fn contains(&self, other: Point3D<T, U>) -> bool {
self.min.x <= other.x
Expand All @@ -155,6 +155,18 @@ where
&& other.z < self.max.z
}

/// Returns `true` if this box3d contains the point `p`. A point is considered
/// in the box3d if it lies on any face of the box3d.
#[inline]
pub fn contains_inclusive(&self, other: Point3D<T, U>) -> bool {
self.min.x <= other.x
&& other.x <= self.max.x
&& self.min.y <= other.y
&& other.y <= self.max.y
&& self.min.z <= other.z
&& other.z <= self.max.z
}

/// Returns `true` if this box3d contains the interior of the other box3d. Always
/// returns `true` if other is empty, and always returns `false` if other is
/// nonempty but this box3d is empty.
Expand Down

0 comments on commit 1be49d3

Please sign in to comment.