From c84ca595b737bebeee37b3b113b0f1648a3e0ff7 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sat, 7 Sep 2013 15:08:59 +1000 Subject: [PATCH] Add Vec{2, 3, 4}::unit_{x, y, z, w} functions --- src/cgmath/vector.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index a4cddd9..d5c6d0d 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -65,6 +65,24 @@ vec!(impl Vec2 { x, y }) vec!(impl Vec3 { x, y, z }) vec!(impl Vec4 { x, y, z, w }) +impl Vec2 { + #[inline] pub fn unit_x() -> Vec2 { Vec2::new(one(), zero()) } + #[inline] pub fn unit_y() -> Vec2 { Vec2::new(zero(), one()) } +} + +impl Vec3 { + #[inline] pub fn unit_x() -> Vec3 { Vec3::new(one(), zero(), zero()) } + #[inline] pub fn unit_y() -> Vec3 { Vec3::new(zero(), one(), zero()) } + #[inline] pub fn unit_z() -> Vec3 { Vec3::new(zero(), zero(), one()) } +} + +impl Vec4 { + #[inline] pub fn unit_x() -> Vec4 { Vec4::new(one(), zero(), zero(), zero()) } + #[inline] pub fn unit_y() -> Vec4 { Vec4::new(zero(), one(), zero(), zero()) } + #[inline] pub fn unit_z() -> Vec4 { Vec4::new(zero(), zero(), one(), zero()) } + #[inline] pub fn unit_w() -> Vec4 { Vec4::new(zero(), zero(), zero(), one()) } +} + array!(impl Vec2 -> [S, ..2]) array!(impl Vec3 -> [S, ..3]) array!(impl Vec4 -> [S, ..4])