2020-04-05 23:53:27 +08:00
|
|
|
use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, RealField};
|
|
|
|
use alga::linear::{AffineSpace, EuclideanSpace};
|
|
|
|
|
2021-04-08 17:53:01 +08:00
|
|
|
use crate::base::{CVectorN, Scalar};
|
2020-04-05 23:53:27 +08:00
|
|
|
|
|
|
|
use crate::geometry::Point;
|
|
|
|
|
2021-04-08 17:53:01 +08:00
|
|
|
impl<N: Scalar + Field, const D: usize> AffineSpace for Point<N, D>
|
2020-04-05 23:53:27 +08:00
|
|
|
where
|
|
|
|
N: Scalar + Field,
|
|
|
|
{
|
2021-04-08 17:53:01 +08:00
|
|
|
type Translation = CVectorN<N, D>;
|
2020-04-05 23:53:27 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 17:53:01 +08:00
|
|
|
impl<N: RealField + simba::scalar::RealField, const D: usize> EuclideanSpace for Point<N, D> {
|
|
|
|
type Coordinates = CVectorN<N, D>;
|
2020-04-05 23:53:27 +08:00
|
|
|
type RealField = N;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn origin() -> Self {
|
|
|
|
Self::origin()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn coordinates(&self) -> Self::Coordinates {
|
|
|
|
self.coords.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn from_coordinates(coords: Self::Coordinates) -> Self {
|
|
|
|
Self::from(coords)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scale_by(&self, n: N) -> Self {
|
|
|
|
self * n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Ordering
|
|
|
|
*
|
|
|
|
*/
|
2021-04-08 17:53:01 +08:00
|
|
|
impl<N, const D: usize> MeetSemilattice for Point<N, D>
|
2020-04-05 23:53:27 +08:00
|
|
|
where
|
|
|
|
N: Scalar + MeetSemilattice,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn meet(&self, other: &Self) -> Self {
|
|
|
|
Self::from(self.coords.meet(&other.coords))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 17:53:01 +08:00
|
|
|
impl<N, const D: usize> JoinSemilattice for Point<N, D>
|
2020-04-05 23:53:27 +08:00
|
|
|
where
|
|
|
|
N: Scalar + JoinSemilattice,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn join(&self, other: &Self) -> Self {
|
|
|
|
Self::from(self.coords.join(&other.coords))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 17:53:01 +08:00
|
|
|
impl<N, const D: usize> Lattice for Point<N, D>
|
2020-04-05 23:53:27 +08:00
|
|
|
where
|
|
|
|
N: Scalar + Lattice,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn meet_join(&self, other: &Self) -> (Self, Self) {
|
|
|
|
let (meet, join) = self.coords.meet_join(&other.coords);
|
|
|
|
|
|
|
|
(Self::from(meet), Self::from(join))
|
|
|
|
}
|
|
|
|
}
|