| 1 |
use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, RealField}; |
| 2 |
use alga::linear::{AffineSpace, EuclideanSpace}; |
| 3 |
|
| 4 |
use crate::base::{SVector, Scalar}; |
| 5 |
|
| 6 |
use crate::geometry::Point; |
| 7 |
|
| 8 |
impl<T: Scalar + Field, const D: usize> AffineSpace for Point<T, D> |
| 9 |
where |
| 10 |
T: Scalar + Field, |
| 11 |
{ |
| 12 |
type Translation = SVector<T, D>; |
| 13 |
} |
| 14 |
|
| 15 |
impl<T: RealField + simba::scalar::RealField, const D: usize> EuclideanSpace for Point<T, D> { |
| 16 |
type Coordinates = SVector<T, D>; |
| 17 |
type RealField = T; |
| 18 |
|
| 19 |
#[inline] |
| 20 |
fn origin() -> Self { |
| 21 |
Self::origin() |
| 22 |
} |
| 23 |
|
| 24 |
#[inline] |
| 25 |
fn coordinates(&self) -> Self::Coordinates { |
| 26 |
self.coords |
| 27 |
} |
| 28 |
|
| 29 |
#[inline] |
| 30 |
fn from_coordinates(coords: Self::Coordinates) -> Self { |
| 31 |
Self::from(coords) |
| 32 |
} |
| 33 |
|
| 34 |
#[inline] |
| 35 |
fn scale_by(&self, n: T) -> Self { |
| 36 |
self * n |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* |
| 42 |
* Ordering |
| 43 |
* |
| 44 |
*/ |
| 45 |
impl<T, const D: usize> MeetSemilattice for Point<T, D> |
| 46 |
where |
| 47 |
T: Scalar + MeetSemilattice, |
| 48 |
{ |
| 49 |
#[inline] |
| 50 |
fn meet(&self, other: &Self) -> Self { |
| 51 |
Self::from(self.coords.meet(&other.coords)) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
impl<T, const D: usize> JoinSemilattice for Point<T, D> |
| 56 |
where |
| 57 |
T: Scalar + JoinSemilattice, |
| 58 |
{ |
| 59 |
#[inline] |
| 60 |
fn join(&self, other: &Self) -> Self { |
| 61 |
Self::from(self.coords.join(&other.coords)) |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
impl<T, const D: usize> Lattice for Point<T, D> |
| 66 |
where |
| 67 |
T: Scalar + Lattice, |
| 68 |
{ |
| 69 |
#[inline] |
| 70 |
fn meet_join(&self, other: &Self) -> (Self, Self) { |
| 71 |
let (meet, join) = self.coords.meet_join(&other.coords); |
| 72 |
|
| 73 |
(Self::from(meet), Self::from(join)) |
| 74 |
} |
| 75 |
} |