Skip to content

Commit

Permalink
Merge pull request #547 from connor-lennox/point-arithmetic
Browse files Browse the repository at this point in the history
Point arithmetic
  • Loading branch information
hannobraun authored May 7, 2022
2 parents a4df039 + 1bad390 commit 18f0b97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
11 changes: 11 additions & 0 deletions crates/fj-math/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ where
}
}

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

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

impl<const D: usize> ops::Sub<Self> for Point<D> {
type Output = Vector<D>;

Expand Down
26 changes: 5 additions & 21 deletions crates/fj-viewer/src/graphics/vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_interop::{
debug::DebugInfo,
mesh::{Index, Mesh},
};
use fj_math::Point;
use fj_math::{Point, Vector};

#[derive(Debug)]
pub struct Vertices {
Expand Down Expand Up @@ -55,32 +55,16 @@ impl Vertices {

self.push_line(
[
Point::from_array([
position.x.into_f64() - d,
position.y.into_f64(),
position.z.into_f64(),
]),
Point::from_array([
position.x.into_f64() + d,
position.y.into_f64(),
position.z.into_f64(),
]),
position - Vector::from([d, 0., 0.]),
position + Vector::from([d, 0., 0.]),
],
normal,
color,
);
self.push_line(
[
Point::from_array([
position.x.into_f64(),
position.y.into_f64() - d,
position.z.into_f64(),
]),
Point::from_array([
position.x.into_f64(),
position.y.into_f64() + d,
position.z.into_f64(),
]),
position - Vector::from([0., d, 0.]),
position + Vector::from([0., d, 0.]),
],
normal,
color,
Expand Down

0 comments on commit 18f0b97

Please sign in to comment.