-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from hannobraun/aabb
Add `math::Aabb`
- Loading branch information
Showing
15 changed files
with
121 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use parry3d_f64::bounding_volume::BoundingVolume as _; | ||
|
||
use super::{Point, Vector}; | ||
|
||
/// An axis-aligned bounding box (AABB) | ||
pub struct Aabb { | ||
/// The minimum coordinates of the AABB | ||
pub min: Point<3>, | ||
|
||
/// The maximum coordinates of the AABB | ||
pub max: Point<3>, | ||
} | ||
|
||
impl Aabb { | ||
/// Construct an AABB from a list of points | ||
/// | ||
/// The resulting AABB will contain all the points. | ||
pub fn from_points(points: impl IntoIterator<Item = Point<3>>) -> Self { | ||
let points: Vec<_> = points.into_iter().collect(); | ||
parry3d_f64::bounding_volume::AABB::from_points(&points).into() | ||
} | ||
|
||
/// Construct an AABB from a Parry AABB | ||
pub fn from_parry(aabb: parry3d_f64::bounding_volume::AABB) -> Self { | ||
Self { | ||
min: aabb.mins.into(), | ||
max: aabb.maxs.into(), | ||
} | ||
} | ||
|
||
/// Convert the AABB to a Parry AABB | ||
pub fn to_parry(&self) -> parry3d_f64::bounding_volume::AABB { | ||
parry3d_f64::bounding_volume::AABB { | ||
mins: self.min, | ||
maxs: self.max, | ||
} | ||
} | ||
|
||
/// Access the vertices of the AABB | ||
pub fn vertices(&self) -> [Point<3>; 8] { | ||
self.to_parry().vertices() | ||
} | ||
|
||
/// Compute the center point of the AABB | ||
pub fn center(&self) -> Point<3> { | ||
self.to_parry().center() | ||
} | ||
|
||
/// Compute the size of the AABB | ||
pub fn size(&self) -> Vector<3> { | ||
self.to_parry().extents().into() | ||
} | ||
|
||
/// Merge this AABB with another | ||
pub fn merged(&self, other: &Aabb) -> Aabb { | ||
self.to_parry().merged(&other.to_parry()).into() | ||
} | ||
} | ||
|
||
impl From<parry3d_f64::bounding_volume::AABB> for Aabb { | ||
fn from(aabb: parry3d_f64::bounding_volume::AABB) -> Self { | ||
Self::from_parry(aabb) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
pub mod aabb; | ||
pub mod point; | ||
pub mod segment; | ||
pub mod transform; | ||
pub mod triangle; | ||
pub mod vector; | ||
|
||
pub use self::{ | ||
point::Point, segment::Segment, transform::Transform, triangle::Triangle, | ||
vector::Vector, | ||
aabb::Aabb, point::Point, segment::Segment, transform::Transform, | ||
triangle::Triangle, vector::Vector, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use super::Point; | ||
|
||
/// A triangle | ||
#[derive(Clone, Copy)] | ||
pub struct Triangle { | ||
pub a: Point<3>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters