Adds conversions to and from mint Point types.
This commit is contained in:
parent
4b3a157513
commit
a3c4dbca95
|
@ -6,6 +6,16 @@ use base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
|
|||
use base::allocator::Allocator;
|
||||
|
||||
use geometry::Point;
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
#[cfg(feature = "mint")]
|
||||
use base::dimension::{U2, U3};
|
||||
#[cfg(feature = "mint")]
|
||||
use std::convert::{AsMut, AsRef, From, Into};
|
||||
#[cfg(feature = "mint")]
|
||||
use base::storage::{Storage, StorageMut};
|
||||
#[cfg(feature = "mint")]
|
||||
use std::mem;
|
||||
|
||||
/*
|
||||
* This file provides the following conversions:
|
||||
|
@ -13,6 +23,8 @@ use geometry::Point;
|
|||
*
|
||||
* Point -> Point
|
||||
* Point -> Vector (homogeneous)
|
||||
*
|
||||
* mint::Point <-> Point
|
||||
*/
|
||||
|
||||
impl<N1, N2, D> SubsetOf<Point<N2, D>> for Point<N1, D>
|
||||
|
@ -67,3 +79,57 @@ where
|
|||
Self::from_coordinates(::convert_unchecked(coords))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
macro_rules! impl_from_into_mint_1D(
|
||||
($($NRows: ident => $PT:ident, $VT:ident [$SZ: expr]);* $(;)*) => {$(
|
||||
impl<N> From<mint::$PT<N>> for Point<N, $NRows>
|
||||
where N: Scalar,
|
||||
DefaultAllocator: Allocator<N, $NRows> {
|
||||
#[inline]
|
||||
fn from(p: mint::$PT<N>) -> Self {
|
||||
Self {
|
||||
coords: VectorN::from(mint::$VT::from(p)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Into<mint::$PT<N>> for Point<N, $NRows>
|
||||
where N: Scalar {
|
||||
#[inline]
|
||||
fn into(self) -> mint::$PT<N> {
|
||||
let mint_vec: mint::$VT<N> = self.coords.into();
|
||||
mint::$PT::from(mint_vec)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> AsRef<mint::$PT<N>> for Point<N, $NRows>
|
||||
where N: Scalar {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &mint::$PT<N> {
|
||||
unsafe {
|
||||
mem::transmute(self.coords.data.ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> AsMut<mint::$PT<N>> for Point<N, $NRows>
|
||||
where N: Scalar {
|
||||
#[inline]
|
||||
fn as_mut(&mut self) -> &mut mint::$PT<N> {
|
||||
unsafe {
|
||||
mem::transmute(self.coords.data.ptr_mut())
|
||||
}
|
||||
}
|
||||
}
|
||||
)*}
|
||||
);
|
||||
|
||||
// Implement for points of dimension 2, 3.
|
||||
#[cfg(feature = "mint")]
|
||||
impl_from_into_mint_1D!(
|
||||
U2 => Point2, Vector2[2];
|
||||
U3 => Point3, Vector3[3];
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue