From 2790fda04ec978e7db28272ccb526770c490765a Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 5 Nov 2012 10:05:16 +1000 Subject: [PATCH] Add from_value vector constructors --- src/test/test_vector.rs | 9 +++++++-- src/vector.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/test_vector.rs b/src/test/test_vector.rs index dc1d7a3..10eaef5 100644 --- a/src/test/test_vector.rs +++ b/src/test/test_vector.rs @@ -12,6 +12,9 @@ fn test_Vec2() { let f1 = 1.5f; let f2 = 0.5f; + assert Vec2::new(1f, 2f) == a; + assert Vec2::from_value(1f32) == Vec2::new(1f32, 1f32); + assert Vec2::zero() == Vec2::new(0f, 0f); assert Vec2::unit_x() == Vec2::new(1f, 0f); assert Vec2::unit_y() == Vec2::new(0f, 1f); @@ -59,7 +62,8 @@ fn test_Vec3() { let f1 = 1.5f; let f2 = 0.5f; - assert a == Vec3::new(1f, 2f, 3f); + assert Vec3::new(1f, 2f, 3f) == a; + assert Vec3::from_value(1f32) == Vec3::new(1f32, 1f32, 1f32); assert Vec3::zero() == Vec3::new(0f, 0f, 0f); assert Vec3::unit_x() == Vec3::new(1f, 0f, 0f); @@ -113,7 +117,8 @@ fn test_Vec4() { let f1 = 1.5f; let f2 = 0.5f; - assert a == Vec4::new(1f, 2f, 3f, 4f); + assert Vec4::new(1f, 2f, 3f, 4f) == a; + assert Vec4::from_value(1f32) == Vec4::new(1f32, 1f32, 1f32, 1f32); assert Vec4::zero() == Vec4::new(0f, 0f, 0f, 0f); assert Vec4::unit_x() == Vec4::new(1f, 0f, 0f, 0f); diff --git a/src/vector.rs b/src/vector.rs index e7605ab..8b6b171 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -49,6 +49,11 @@ pub mod Vec2 { Vec2 { x: move x, y: move y } } + #[inline(always)] + pub pure fn from_value(value: T) -> Vec2 { + Vec2::new(value, value) + } + #[inline(always)] pub pure fn zero() -> Vec2 { let _0 = cast(0); @@ -238,6 +243,11 @@ pub mod Vec3 { Vec3 { x: move x, y: move y, z: move z } } + #[inline(always)] + pub pure fn from_value(value: T) -> Vec3 { + Vec3::new(value, value, value) + } + #[inline(always)] pub pure fn zero() -> Vec3 { let _0 = cast(0); @@ -456,6 +466,11 @@ pub mod Vec4 { Vec4 { x: move x, y: move y, z: move z, w: move w } } + #[inline(always)] + pub pure fn from_value(value: T) -> Vec4 { + Vec4::new(value, value, value, value) + } + #[inline(always)] pub pure fn zero() -> Vec4 { let _0 = cast(0);