Skip to content

Commit

Permalink
Merge pull request #504 from hannobraun/math
Browse files Browse the repository at this point in the history
Make some small improvements to the `fj_math` API
  • Loading branch information
hannobraun authored Apr 26, 2022
2 parents 1233f21 + 3c74a74 commit c847da2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions crates/fj-math/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl Aabb<3> {
self.to_parry().extents().into()
}

/// Compute an AABB that includes an additional point
pub fn include_point(self, point: &Point<3>) -> Self {
let mut aabb = self.to_parry();
aabb.take_point(point.to_na());

Self::from_parry(aabb)
}

/// Merge this AABB with another
pub fn merged(&self, other: &Self) -> Self {
self.to_parry().merged(&other.to_parry()).into()
Expand Down
9 changes: 6 additions & 3 deletions crates/fj-math/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ impl<const D: usize> ops::Neg for Point<D> {
}
}

impl<const D: usize> ops::Add<Vector<D>> for Point<D> {
impl<V, const D: usize> ops::Add<V> for Point<D>
where
V: Into<Vector<D>>,
{
type Output = Self;

fn add(self, rhs: Vector<D>) -> Self::Output {
self.to_na().add(rhs.to_na()).into()
fn add(self, rhs: V) -> Self::Output {
self.to_na().add(rhs.into().to_na()).into()
}
}

Expand Down
9 changes: 6 additions & 3 deletions crates/fj-math/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ impl<const D: usize> ops::Neg for Vector<D> {
}
}

impl<const D: usize> ops::Add<Self> for Vector<D> {
impl<V, const D: usize> ops::Add<V> for Vector<D>
where
V: Into<Self>,
{
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
self.to_na().add(rhs.to_na()).into()
fn add(self, rhs: V) -> Self::Output {
self.to_na().add(rhs.into().to_na()).into()
}
}

Expand Down

0 comments on commit c847da2

Please sign in to comment.