Struct Aabb2
pub struct Aabb2 { /* private fields */ }Expand description
An axis-aligned bounding box represented by inclusive minimum and maximum corners.
Implementations§
§impl Aabb2
impl Aabb2
pub fn try_new(min: Point2, max: Point2) -> Result<Aabb2, GeometryError>
pub fn try_new(min: Point2, max: Point2) -> Result<Aabb2, GeometryError>
Creates a validated axis-aligned bounding box from ordered corners.
§Errors
Returns GeometryError::NonFiniteComponent when either corner
contains a non-finite coordinate.
Returns GeometryError::InvalidBounds when min is greater than
max on either axis.
§Examples
use use_geometry::{Aabb2, GeometryError, Point2};
let bounds = Aabb2::try_new(Point2::new(1.0, 2.0), Point2::new(4.0, 6.0))?;
assert_eq!(bounds.center(), Point2::new(2.5, 4.0));pub const fn from_points(a: Point2, b: Point2) -> Aabb2
pub const fn from_points(a: Point2, b: Point2) -> Aabb2
Creates a bounding box from any two corners, normalizing axis order.
§Examples
use use_geometry::{Aabb2, Point2};
let bounds = Aabb2::from_points(Point2::new(4.0, 1.0), Point2::new(1.0, 3.0));
assert_eq!(bounds.min(), Point2::new(1.0, 1.0));
assert_eq!(bounds.max(), Point2::new(4.0, 3.0));pub fn contains_point(&self, point: Point2) -> bool
pub fn contains_point(&self, point: Point2) -> bool
Returns true when point lies inside or on the boundary.
pub fn contains_point_with_tolerance(
&self,
point: Point2,
tolerance: f64,
) -> Result<bool, GeometryError>
pub fn contains_point_with_tolerance( &self, point: Point2, tolerance: f64, ) -> Result<bool, GeometryError>
Returns true when point lies inside the box expanded by tolerance.
§Errors
Returns GeometryError::NonFiniteTolerance when tolerance is NaN
or infinite.
Returns GeometryError::NegativeTolerance when tolerance is negative.
§Examples
use use_geometry::{Aabb2, GeometryError, Point2};
let bounds = Aabb2::from_points(Point2::new(1.0, 1.0), Point2::new(4.0, 3.0));
assert!(bounds.contains_point_with_tolerance(Point2::new(4.25, 3.0), 0.25)?);pub fn is_degenerate(&self) -> bool
pub fn is_degenerate(&self) -> bool
Returns true when the box has zero width or height.
pub fn is_degenerate_with_tolerance(
&self,
tolerance: f64,
) -> Result<bool, GeometryError>
pub fn is_degenerate_with_tolerance( &self, tolerance: f64, ) -> Result<bool, GeometryError>
Returns true when the box width or height is within tolerance of zero.
§Errors
Returns GeometryError::NonFiniteTolerance when tolerance is NaN
or infinite.
Returns GeometryError::NegativeTolerance when tolerance is negative.