mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-03 17:38:27 +00:00
Re-use fj_math::Point
This commit is contained in:
parent
cd8e0ef734
commit
42956a7961
@ -1,49 +1 @@
|
||||
use std::ops;
|
||||
|
||||
use fj_math::Vector;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct Point<const D: usize> {
|
||||
pub coords: Vector<D>,
|
||||
}
|
||||
|
||||
impl<V, const D: usize> From<V> for Point<D>
|
||||
where
|
||||
V: Into<Vector<D>>,
|
||||
{
|
||||
fn from(coords: V) -> Self {
|
||||
Self {
|
||||
coords: coords.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, const D: usize> ops::Add<V> for Point<D>
|
||||
where
|
||||
V: Into<Vector<D>>,
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: V) -> Self::Output {
|
||||
let other = other.into();
|
||||
let coords = self.coords + other;
|
||||
Self { coords }
|
||||
}
|
||||
}
|
||||
|
||||
impl<const D: usize> ops::Sub<Point<D>> for Point<D> {
|
||||
type Output = Vector<D>;
|
||||
|
||||
fn sub(self, other: Point<D>) -> Self::Output {
|
||||
self.coords - other.coords
|
||||
}
|
||||
}
|
||||
|
||||
impl<const D: usize> ops::Sub<Vector<D>> for Point<D> {
|
||||
type Output = Point<D>;
|
||||
|
||||
fn sub(self, other: Vector<D>) -> Self::Output {
|
||||
let coords = self.coords - other;
|
||||
Self { coords }
|
||||
}
|
||||
}
|
||||
pub use fj_math::Point;
|
||||
|
Loading…
Reference in New Issue
Block a user