From f3183dd0f11ab148d9553a3599424f837dd74184 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 4 Nov 2012 14:39:33 +1000 Subject: [PATCH] Reduce zero and one casts --- src/quaternion.rs | 20 ++++++-- src/vector.rs | 115 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 115 insertions(+), 20 deletions(-) diff --git a/src/quaternion.rs b/src/quaternion.rs index be6133b..95df21d 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -51,11 +51,25 @@ pub mod Quat { Quat { w: move w, x: move x, y: move y, z: move z } } - #[inline(always)] pub pure fn zero () -> Quat { Quat { w: from_int(0), x: from_int(0), y: from_int(0), z: from_int(0) } } - #[inline(always)] pub pure fn identity () -> Quat { Quat { w: from_int(1), x: from_int(0), y: from_int(0), z: from_int(0) } } + #[inline(always)] + pub pure fn from_sv(s: T, v: Vec3) -> Quat { + Quat::new(s, v.x, v.y, v.z) + } + + #[inline(always)] + pub pure fn zero () -> Quat { + let _0 = cast(0); + Quat::new(_0, _0, _0, _0) + } + + #[inline(always)] + pub pure fn identity () -> Quat { + let _0 = cast(0); + Quat::new(cast(1), _0, _0, _0) + } } -pub impl Quat: Quaternion { +pub impl Quat: Quaternion { #[inline(always)] pure fn dim() -> uint { 4 } diff --git a/src/vector.rs b/src/vector.rs index 2c8cee1..e7605ab 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -49,10 +49,31 @@ pub mod Vec2 { Vec2 { x: move x, y: move y } } - #[inline(always)] pub pure fn zero () -> Vec2 { Vec2 { x: from_int(0), y: from_int(0) } } - #[inline(always)] pub pure fn unit_x () -> Vec2 { Vec2 { x: from_int(1), y: from_int(0) } } - #[inline(always)] pub pure fn unit_y () -> Vec2 { Vec2 { x: from_int(0), y: from_int(1) } } - #[inline(always)] pub pure fn identity () -> Vec2 { Vec2 { x: from_int(1), y: from_int(1) } } + #[inline(always)] + pub pure fn zero() -> Vec2 { + let _0 = cast(0); + Vec2::new(_0, _0) + } + + #[inline(always)] + pub pure fn unit_x() -> Vec2 { + let _0 = cast(0); + let _1 = cast(1); + Vec2::new(_1, _0) + } + + #[inline(always)] + pub pure fn unit_y() -> Vec2 { + let _0 = cast(0); + let _1 = cast(1); + Vec2::new(_0, _1) + } + + #[inline(always)] + pub pure fn identity() -> Vec2 { + let _1 = cast(1); + Vec2::new(_1, _1) + } } pub impl Vec2: Vector { @@ -216,12 +237,39 @@ pub mod Vec3 { pub pure fn new(x: T, y: T, z: T) -> Vec3 { Vec3 { x: move x, y: move y, z: move z } } - - #[inline(always)] pub pure fn zero () -> Vec3 { Vec3 { x: from_int(0), y: from_int(0), z: from_int(0) } } - #[inline(always)] pub pure fn unit_x () -> Vec3 { Vec3 { x: from_int(1), y: from_int(0), z: from_int(0) } } - #[inline(always)] pub pure fn unit_y () -> Vec3 { Vec3 { x: from_int(0), y: from_int(1), z: from_int(0) } } - #[inline(always)] pub pure fn unit_z () -> Vec3 { Vec3 { x: from_int(0), y: from_int(0), z: from_int(1) } } - #[inline(always)] pub pure fn identity () -> Vec3 { Vec3 { x: from_int(1), y: from_int(1), z: from_int(1) } } + + #[inline(always)] + pub pure fn zero() -> Vec3 { + let _0 = cast(0); + Vec3::new(_0, _0, _0) + } + + #[inline(always)] + pub pure fn unit_x() -> Vec3 { + let _0 = cast(0); + let _1 = cast(1); + Vec3::new(_1, _0, _0) + } + + #[inline(always)] + pub pure fn unit_y() -> Vec3 { + let _0 = cast(0); + let _1 = cast(1); + Vec3::new(_0, _1, _0) + } + + #[inline(always)] + pub pure fn unit_z() -> Vec3 { + let _0 = cast(0); + let _1 = cast(1); + Vec3::new(_0, _0, _1) + } + + #[inline(always)] + pub pure fn identity() -> Vec3 { + let _1 = cast(1); + Vec3::new(_1, _1, _1) + } } pub impl Vec3: Vector3 { @@ -407,13 +455,46 @@ pub mod Vec4 { pub pure fn new(x: T, y: T, z: T, w: T) -> Vec4 { Vec4 { x: move x, y: move y, z: move z, w: move w } } - - #[inline(always)] pub pure fn zero () -> Vec4 { Vec4 { x: from_int(0), y: from_int(0), z: from_int(0), w: from_int(0) } } - #[inline(always)] pub pure fn unit_x () -> Vec4 { Vec4 { x: from_int(1), y: from_int(0), z: from_int(0), w: from_int(0) } } - #[inline(always)] pub pure fn unit_y () -> Vec4 { Vec4 { x: from_int(0), y: from_int(1), z: from_int(0), w: from_int(0) } } - #[inline(always)] pub pure fn unit_z () -> Vec4 { Vec4 { x: from_int(0), y: from_int(0), z: from_int(1), w: from_int(0) } } - #[inline(always)] pub pure fn unit_w () -> Vec4 { Vec4 { x: from_int(0), y: from_int(0), z: from_int(0), w: from_int(1) } } - #[inline(always)] pub pure fn identity () -> Vec4 { Vec4 { x: from_int(1), y: from_int(1), z: from_int(1), w: from_int(1) } } + + #[inline(always)] + pub pure fn zero() -> Vec4 { + let _0 = cast(0); + Vec4::new(_0, _0, _0, _0) + } + + #[inline(always)] + pub pure fn unit_x() -> Vec4 { + let _0 = cast(0); + let _1 = cast(1); + Vec4::new(_1, _0, _0, _0) + } + + #[inline(always)] + pub pure fn unit_y() -> Vec4 { + let _0 = cast(0); + let _1 = cast(1); + Vec4::new(_0, _1, _0, _0) + } + + #[inline(always)] + pub pure fn unit_z() -> Vec4 { + let _0 = cast(0); + let _1 = cast(1); + Vec4::new(_0, _0, _1, _0) + } + + #[inline(always)] + pub pure fn unit_w() -> Vec4 { + let _0 = cast(0); + let _1 = cast(1); + Vec4::new(_0, _0, _0, _1) + } + + #[inline(always)] + pub pure fn identity() -> Vec4 { + let _1 = cast(1); + Vec4::new(_1, _1, _1, _1) + } } pub impl Vec4: Vector {