Add from_value vector constructors

This commit is contained in:
Brendan Zabarauskas 2012-11-05 10:05:16 +10:00
parent 4e90754263
commit 2790fda04e
2 changed files with 22 additions and 2 deletions

View file

@ -12,6 +12,9 @@ fn test_Vec2() {
let f1 = 1.5f; let f1 = 1.5f;
let f2 = 0.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::zero() == Vec2::new(0f, 0f);
assert Vec2::unit_x() == Vec2::new(1f, 0f); assert Vec2::unit_x() == Vec2::new(1f, 0f);
assert Vec2::unit_y() == Vec2::new(0f, 1f); assert Vec2::unit_y() == Vec2::new(0f, 1f);
@ -59,7 +62,8 @@ fn test_Vec3() {
let f1 = 1.5f; let f1 = 1.5f;
let f2 = 0.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::zero() == Vec3::new(0f, 0f, 0f);
assert Vec3::unit_x() == Vec3::new(1f, 0f, 0f); assert Vec3::unit_x() == Vec3::new(1f, 0f, 0f);
@ -113,7 +117,8 @@ fn test_Vec4() {
let f1 = 1.5f; let f1 = 1.5f;
let f2 = 0.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::zero() == Vec4::new(0f, 0f, 0f, 0f);
assert Vec4::unit_x() == Vec4::new(1f, 0f, 0f, 0f); assert Vec4::unit_x() == Vec4::new(1f, 0f, 0f, 0f);

View file

@ -49,6 +49,11 @@ pub mod Vec2 {
Vec2 { x: move x, y: move y } Vec2 { x: move x, y: move y }
} }
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec2<T> {
Vec2::new(value, value)
}
#[inline(always)] #[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec2<T> { pub pure fn zero<T:Copy NumCast>() -> Vec2<T> {
let _0 = cast(0); let _0 = cast(0);
@ -238,6 +243,11 @@ pub mod Vec3 {
Vec3 { x: move x, y: move y, z: move z } Vec3 { x: move x, y: move y, z: move z }
} }
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec3<T> {
Vec3::new(value, value, value)
}
#[inline(always)] #[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec3<T> { pub pure fn zero<T:Copy NumCast>() -> Vec3<T> {
let _0 = cast(0); let _0 = cast(0);
@ -456,6 +466,11 @@ pub mod Vec4 {
Vec4 { x: move x, y: move y, z: move z, w: move w } Vec4 { x: move x, y: move y, z: move z, w: move w }
} }
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec4<T> {
Vec4::new(value, value, value, value)
}
#[inline(always)] #[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec4<T> { pub pure fn zero<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0); let _0 = cast(0);