From 1be49d37c2476b0c31aeb8dae6d10506787b8de4 Mon Sep 17 00:00:00 2001 From: Kxie <56177821+ua-kxie@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:26:16 +0800 Subject: [PATCH] add contains_inclusive and clean up description (#521) --- src/box2d.rs | 13 ++++++++++--- src/box3d.rs | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/box2d.rs b/src/box2d.rs index 4630400..d3b30c4 100644 --- a/src/box2d.rs +++ b/src/box2d.rs @@ -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) -> 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) -> 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. diff --git a/src/box3d.rs b/src/box3d.rs index e802515..ac43ff1 100644 --- a/src/box3d.rs +++ b/src/box3d.rs @@ -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) -> bool { self.min.x <= other.x @@ -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) -> 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.