Implement more math conversions

This commit is contained in:
Hanno Braun 2022-02-19 11:42:42 +01:00
parent 8eab780835
commit b147bb8780
3 changed files with 23 additions and 0 deletions

View File

@ -106,6 +106,18 @@ impl<const D: usize> From<nalgebra::Point<f64, D>> for Point<D> {
}
}
impl<const D: usize> From<Point<D>> for [f32; D] {
fn from(point: Point<D>) -> Self {
point.0.map(|scalar| scalar.into_f32())
}
}
impl<const D: usize> From<Point<D>> for [f64; D] {
fn from(point: Point<D>) -> Self {
point.0.map(|scalar| scalar.into_f64())
}
}
impl<const D: usize> ops::Neg for Point<D> {
type Output = Self;

View File

@ -62,6 +62,11 @@ impl Scalar {
Self::from_f64(scalar as f64)
}
/// Convert the scalar into an `f32`
pub fn into_f32(self) -> f32 {
self.0 as f32
}
/// Convert the scalar into a `f64`
pub fn into_f64(self) -> f64 {
self.0

View File

@ -121,6 +121,12 @@ impl<const D: usize> From<nalgebra::SVector<f64, D>> for Vector<D> {
}
}
impl<const D: usize> From<Vector<D>> for [f32; D] {
fn from(vector: Vector<D>) -> Self {
vector.0.map(|scalar| scalar.into_f32())
}
}
impl<const D: usize> ops::Add<Self> for Vector<D> {
type Output = Self;