From 56487fc0b9ea8df71d3b1caac0c7bbb69bc74a17 Mon Sep 17 00:00:00 2001 From: ncihnegn Date: Sat, 12 Mar 2022 16:37:15 -0800 Subject: [PATCH] Add From for Point so that Point can use unit_x() etc. --- src/point.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/point.rs b/src/point.rs index 77137dc2..ac896051 100644 --- a/src/point.rs +++ b/src/point.rs @@ -112,6 +112,12 @@ macro_rules! impl_point { $PointN::new($($field),+) } + impl From<$VectorN> for $PointN { + fn from(v: $VectorN) -> $PointN { + $PointN { $($field: v.$field),+ } + } + } + impl Array for $PointN { type Element = S; @@ -612,6 +618,7 @@ mod tests { let p: &mut Point3<_> = From::from(p); assert_eq!(p, &POINT3); } + assert_eq!(Point3::from(Vector3::new(1, 2, 3)), POINT3); } #[test]