Skip to main content

nalgebra/third_party/mint/
mint_point.rs

1use crate::base::storage::{RawStorage, RawStorageMut};
2use crate::{OVector, Point, Scalar};
3use std::convert::{AsMut, AsRef};
4
5macro_rules! impl_from_into_mint_1D(
6    ($($NRows: expr => $PT:ident, $VT:ident [$SZ: expr]);* $(;)*) => {$(
7        impl<T> From<mint::$PT<T>> for Point<T, $NRows>
8        where T: Scalar {
9            #[inline]
10            fn from(p: mint::$PT<T>) -> Self {
11                Self {
12                    coords: OVector::from(mint::$VT::from(p)),
13                }
14            }
15        }
16
17        impl<T> Into<mint::$PT<T>> for Point<T, $NRows>
18        where T: Scalar {
19            #[inline]
20            fn into(self) -> mint::$PT<T> {
21                let mint_vec: mint::$VT<T> = self.coords.into();
22                mint::$PT::from(mint_vec)
23            }
24        }
25
26        impl<T> AsRef<mint::$PT<T>> for Point<T, $NRows>
27        where T: Scalar {
28            #[inline]
29            fn as_ref(&self) -> &mint::$PT<T> {
30                unsafe {
31                    &*(self.coords.data.ptr() as *const mint::$PT<T>)
32                }
33            }
34        }
35
36        impl<T> AsMut<mint::$PT<T>> for Point<T, $NRows>
37        where T: Scalar {
38            #[inline]
39            fn as_mut(&mut self) -> &mut mint::$PT<T> {
40                unsafe {
41                    &mut *(self.coords.data.ptr_mut() as *mut mint::$PT<T>)
42                }
43            }
44        }
45    )*}
46);
47
48// Implement for points of dimension 2, 3.
49impl_from_into_mint_1D!(
50    2 => Point2, Vector2[2];
51    3 => Point3, Vector3[3];
52);