diff --git a/src/math/point.rs b/src/math/point.rs index bc11fb811..f3c7c258c 100644 --- a/src/math/point.rs +++ b/src/math/point.rs @@ -106,6 +106,18 @@ impl From> for Point { } } +impl From> for [f32; D] { + fn from(point: Point) -> Self { + point.0.map(|scalar| scalar.into_f32()) + } +} + +impl From> for [f64; D] { + fn from(point: Point) -> Self { + point.0.map(|scalar| scalar.into_f64()) + } +} + impl ops::Neg for Point { type Output = Self; diff --git a/src/math/scalar.rs b/src/math/scalar.rs index ccad07cb7..5eabe3a23 100644 --- a/src/math/scalar.rs +++ b/src/math/scalar.rs @@ -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 diff --git a/src/math/vector.rs b/src/math/vector.rs index 3893d0296..7c6dbd203 100644 --- a/src/math/vector.rs +++ b/src/math/vector.rs @@ -121,6 +121,12 @@ impl From> for Vector { } } +impl From> for [f32; D] { + fn from(vector: Vector) -> Self { + vector.0.map(|scalar| scalar.into_f32()) + } +} + impl ops::Add for Vector { type Output = Self;