//! This module contains traits and implements for working with bounding shapes1//!2//! There are four traits used:3//! - [`BoundingVolume`] is a generic abstraction for any bounding volume4//! - [`IntersectsVolume`] abstracts intersection tests against a [`BoundingVolume`]5//! - [`Bounded2d`]/[`Bounded3d`] are abstractions for shapes to generate [`BoundingVolume`]s67/// A trait that generalizes different bounding volumes.8/// Bounding volumes are simplified shapes that are used to get simpler ways to check for9/// overlapping elements or finding intersections.10///11/// This trait supports both 2D and 3D bounding shapes.12pub trait BoundingVolume: Sized {13/// The position type used for the volume. This should be `Vec2` for 2D and `Vec3` for 3D.14type Translation: Clone + Copy + PartialEq;1516/// The rotation type used for the volume. This should be `Rot2` for 2D and `Quat` for 3D.17type Rotation: Clone + Copy + PartialEq;1819/// The type used for the size of the bounding volume. Usually a half size. For example an20/// `f32` radius for a circle, or a `Vec3` with half sizes for x, y and z for a 3D axis-aligned21/// bounding box22type HalfSize;2324/// Returns the center of the bounding volume.25fn center(&self) -> Self::Translation;2627/// Returns the half size of the bounding volume.28fn half_size(&self) -> Self::HalfSize;2930/// Computes the visible surface area of the bounding volume.31/// This method can be useful to make decisions about merging bounding volumes,32/// using a Surface Area Heuristic.33///34/// For 2D shapes this would simply be the area of the shape.35/// For 3D shapes this would usually be half the area of the shape.36fn visible_area(&self) -> f32;3738/// Checks if this bounding volume contains another one.39fn contains(&self, other: &Self) -> bool;4041/// Computes the smallest bounding volume that contains both `self` and `other`.42fn merge(&self, other: &Self) -> Self;4344/// Increases the size of the bounding volume in each direction by the given amount.45fn grow(&self, amount: impl Into<Self::HalfSize>) -> Self;4647/// Decreases the size of the bounding volume in each direction by the given amount.48fn shrink(&self, amount: impl Into<Self::HalfSize>) -> Self;4950/// Scale the size of the bounding volume around its center by the given amount51fn scale_around_center(&self, scale: impl Into<Self::HalfSize>) -> Self;5253/// Transforms the bounding volume by first rotating it around the origin and then applying a translation.54fn transformed_by(55mut self,56translation: impl Into<Self::Translation>,57rotation: impl Into<Self::Rotation>,58) -> Self {59self.transform_by(translation, rotation);60self61}6263/// Transforms the bounding volume by first rotating it around the origin and then applying a translation.64fn transform_by(65&mut self,66translation: impl Into<Self::Translation>,67rotation: impl Into<Self::Rotation>,68) {69self.rotate_by(rotation);70self.translate_by(translation);71}7273/// Translates the bounding volume by the given translation.74fn translated_by(mut self, translation: impl Into<Self::Translation>) -> Self {75self.translate_by(translation);76self77}7879/// Translates the bounding volume by the given translation.80fn translate_by(&mut self, translation: impl Into<Self::Translation>);8182/// Rotates the bounding volume around the origin by the given rotation.83///84/// The result is a combination of the original volume and the rotated volume,85/// so it is guaranteed to be either the same size or larger than the original.86fn rotated_by(mut self, rotation: impl Into<Self::Rotation>) -> Self {87self.rotate_by(rotation);88self89}9091/// Rotates the bounding volume around the origin by the given rotation.92///93/// The result is a combination of the original volume and the rotated volume,94/// so it is guaranteed to be either the same size or larger than the original.95fn rotate_by(&mut self, rotation: impl Into<Self::Rotation>);96}9798/// A trait that generalizes intersection tests against a volume.99/// Intersection tests can be used for a variety of tasks, for example:100/// - Raycasting101/// - Testing for overlap102/// - Checking if an object is within the view frustum of a camera103pub trait IntersectsVolume<Volume: BoundingVolume> {104/// Check if a volume intersects with this intersection test105fn intersects(&self, volume: &Volume) -> bool;106}107108mod bounded2d;109pub use bounded2d::*;110mod bounded3d;111pub use bounded3d::*;112113mod raycast2d;114pub use raycast2d::*;115mod raycast3d;116pub use raycast3d::*;117118119