]> git.nega.tv - josh/narcissus/commitdiff
Add point -> vector conversion functions
authorJoshua Simmons <josh@nega.tv>
Sun, 11 Sep 2022 14:02:52 +0000 (16:02 +0200)
committerJoshua Simmons <josh@nega.tv>
Sun, 11 Sep 2022 14:02:52 +0000 (16:02 +0200)
narcissus-maths/src/point2.rs
narcissus-maths/src/point3.rs

index 5351cd1cb2960e1d169997e182b362b8372cb3f2..ed4eac6fba87c0fd31a6805a47b47d7b29d446ad 100644 (file)
@@ -18,6 +18,12 @@ impl Point2 {
         Self { x, y }
     }
 
+    /// Converts this point to the equivalent vector.
+    #[inline(always)]
+    pub const fn as_vec2(self) -> Vec2 {
+        Vec2::new(self.x, self.y)
+    }
+
     /// Returns a new [`Point2`] with the function `f` applied to each coordinate of `self` in order.
     #[inline(always)]
     pub fn map<F>(self, mut f: F) -> Self
index c3b9ebb029f55d16539acfe1280540ad1d9cc2d0..f5a7e07f1ed596081bbd8c1c1c2886a693718a1f 100644 (file)
@@ -19,6 +19,12 @@ impl Point3 {
         Point3 { x, y, z }
     }
 
+    /// Converts this point to the equivalent vector.
+    #[inline(always)]
+    pub const fn as_vec3(self) -> Vec3 {
+        Vec3::new(self.x, self.y, self.z)
+    }
+
     /// Returns a new [`Point3`] with the function `f` applied to each coordinate of `self` in order.
     #[inline(always)]
     pub fn map<F>(self, mut f: F) -> Point3