From ddc617c925b2978c60c481d9fa85f711ba6dc654 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 28 Jan 2013 09:22:15 +1100 Subject: [PATCH] Updates due to changes in numeric-rs --- src/funs/common.rs | 483 ----------------------------------- src/funs/exponential.rs | 213 --------------- src/funs/relational.rs | 264 ------------------- src/funs/triganomic.rs | 230 ----------------- src/gltypes.rs | 2 + src/lmath.rc | 15 +- src/mat.rs | 1 - src/mat2.rs | 11 +- src/mat3.rs | 45 ++-- src/mat4.rs | 7 +- src/{funs => }/projection.rs | 10 +- src/quat.rs | 53 ++-- src/rot.rs | 12 +- src/test/test_quat.rs | 15 +- src/test/test_vec.rs | 22 +- src/vec.rs | 6 +- src/vec2.rs | 9 +- src/vec3.rs | 9 +- src/vec4.rs | 9 +- 19 files changed, 101 insertions(+), 1315 deletions(-) delete mode 100644 src/funs/common.rs delete mode 100644 src/funs/exponential.rs delete mode 100644 src/funs/relational.rs delete mode 100644 src/funs/triganomic.rs rename src/{funs => }/projection.rs (83%) diff --git a/src/funs/common.rs b/src/funs/common.rs deleted file mode 100644 index 1488618..0000000 --- a/src/funs/common.rs +++ /dev/null @@ -1,483 +0,0 @@ -/** - * Common Functions - * - * This module corresponds to Section 8.3 of the [GLSL 4.30.6 specification] - * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). - */ - -use numeric::funs::*; -use numeric::traits::*; - -use vec::{Vector, Vec2, Vec3, Vec4}; - -// Round - -pub impl Vec2: Round { - #[inline(always)] - pure fn floor(&self) -> Vec2 { - Vec2::new(floor(&self[0]), - floor(&self[1])) - } - - #[inline(always)] - pure fn trunc(&self) -> Vec2 { - Vec2::new(trunc(&self[0]), - trunc(&self[1])) - } - - #[inline(always)] - pure fn round(&self) -> Vec2 { - Vec2::new(round(&self[0]), - round(&self[1])) - } - - // #[inline(always)] - // pure fn round_even(&self) -> Vec2 { - // Vec2::new(round_even(&self[0]), - // round_even(&self[1])) - // } - - #[inline(always)] - pure fn ceil(&self) -> Vec2 { - Vec2::new(ceil(&self[0]), - ceil(&self[1])) - } - - #[inline(always)] - pure fn fract(&self) -> Vec2 { - Vec2::new(fract(&self[0]), - fract(&self[1])) - } -} - -pub impl Vec3: Round { - #[inline(always)] - pure fn floor(&self) -> Vec3 { - Vec3::new(floor(&self[0]), - floor(&self[1]), - floor(&self[2])) - } - - #[inline(always)] - pure fn trunc(&self) -> Vec3 { - Vec3::new(trunc(&self[0]), - trunc(&self[1]), - trunc(&self[2])) - } - - #[inline(always)] - pure fn round(&self) -> Vec3 { - Vec3::new(round(&self[0]), - round(&self[1]), - round(&self[2])) - } - - // #[inline(always)] - // pure fn round_even(&self) -> Vec3 { - // Vec3::new(round_even(&self[0]), - // round_even(&self[1]), - // round_even(&self[2])) - // } - - #[inline(always)] - pure fn ceil(&self) -> Vec3 { - Vec3::new(ceil(&self[0]), - ceil(&self[1]), - ceil(&self[2])) - } - - #[inline(always)] - pure fn fract(&self) -> Vec3 { - Vec3::new(fract(&self[0]), - fract(&self[1]), - fract(&self[2])) - } -} - -pub impl Vec4: Round { - #[inline(always)] - pure fn floor(&self) -> Vec4 { - Vec4::new(floor(&self[0]), - floor(&self[1]), - floor(&self[2]), - floor(&self[3])) - } - - #[inline(always)] - pure fn trunc(&self) -> Vec4 { - Vec4::new(trunc(&self[0]), - trunc(&self[1]), - trunc(&self[2]), - trunc(&self[3])) - } - - #[inline(always)] - pure fn round(&self) -> Vec4 { - Vec4::new(round(&self[0]), - round(&self[1]), - round(&self[2]), - round(&self[3])) - } - - // #[inline(always)] - // pure fn round_even(&self) -> Vec4 { - // Vec4::new(round_even(&self[0]), - // round_even(&self[1]), - // round_even(&self[2]), - // round_even(&self[3])) - // } - - #[inline(always)] - pure fn ceil(&self) -> Vec4 { - Vec4::new(ceil(&self[0]), - ceil(&self[1]), - ceil(&self[2]), - ceil(&self[3])) - } - - #[inline(always)] - pure fn fract(&self) -> Vec4 { - Vec4::new(fract(&self[0]), - fract(&self[1]), - fract(&self[2]), - fract(&self[3])) - } -} - -// Extent - -pub trait ExtentVector: Vector { - pure fn min_t(&self, value: T) -> self; - pure fn max_t(&self, value: T) -> self; - pure fn clamp_t(&self, mn: T, mx: T) -> self; - - pure fn min_v(&self, other: &self) -> self; - pure fn max_v(&self, other: &self) -> self; - pure fn clamp_v(&self, mn: &self, mx: &self) -> self; -} - -pub impl Vec2: ExtentVector { - #[inline(always)] - pure fn min_t(&self, value: T) -> Vec2 { - Vec2::new(min(&self[0], &value), - min(&self[1], &value)) - } - - #[inline(always)] - pure fn max_t(&self, value: T) -> Vec2 { - Vec2::new(max(&self[0], &value), - max(&self[1], &value)) - } - - #[inline(always)] - pure fn clamp_t(&self, mn: T, mx: T) -> Vec2 { - Vec2::new(self[0].clamp(&mn, &mx), - self[1].clamp(&mn, &mx)) - } - - #[inline(always)] - pure fn min_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(min(&self[0], &other[0]), - min(&self[1], &other[1])) - } - - #[inline(always)] - pure fn max_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(max(&self[0], &other[0]), - max(&self[1], &other[1])) - } - - #[inline(always)] - pure fn clamp_v(&self, mn: &Vec2, mx: &Vec2) -> Vec2 { - Vec2::new(self[0].clamp(&mn[0], &mx[0]), - self[1].clamp(&mn[1], &mx[1])) - } -} - -pub impl Vec3: ExtentVector { - #[inline(always)] - pure fn min_t(&self, value: T) -> Vec3 { - Vec3::new(min(&self[0], &value), - min(&self[1], &value), - min(&self[2], &value)) - } - - #[inline(always)] - pure fn max_t(&self, value: T) -> Vec3 { - Vec3::new(max(&self[0], &value), - max(&self[1], &value), - max(&self[2], &value)) - } - - #[inline(always)] - pure fn clamp_t(&self, mn: T, mx: T) -> Vec3 { - Vec3::new(self[0].clamp(&mn, &mx), - self[1].clamp(&mn, &mx), - self[2].clamp(&mn, &mx)) - } - - #[inline(always)] - pure fn min_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(min(&self[0], &other[0]), - min(&self[1], &other[1]), - min(&self[2], &other[2])) - } - - #[inline(always)] - pure fn max_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(max(&self[0], &other[0]), - max(&self[1], &other[1]), - max(&self[2], &other[2])) - } - - #[inline(always)] - pure fn clamp_v(&self, mn: &Vec3, mx: &Vec3) -> Vec3 { - Vec3::new(self[0].clamp(&mn[0], &mx[0]), - self[1].clamp(&mn[1], &mx[1]), - self[2].clamp(&mn[2], &mx[2])) - } -} - -pub impl Vec4: ExtentVector { - #[inline(always)] - pure fn min_t(&self, value: T) -> Vec4 { - Vec4::new(min(&self[0], &value), - min(&self[1], &value), - min(&self[2], &value), - min(&self[3], &value)) - } - - #[inline(always)] - pure fn max_t(&self, value: T) -> Vec4 { - Vec4::new(max(&self[0], &value), - max(&self[1], &value), - max(&self[2], &value), - max(&self[3], &value)) - } - - #[inline(always)] - pure fn clamp_t(&self, mn: T, mx: T) -> Vec4 { - Vec4::new(self[0].clamp(&mn, &mx), - self[1].clamp(&mn, &mx), - self[2].clamp(&mn, &mx), - self[3].clamp(&mn, &mx)) - } - - #[inline(always)] - pure fn min_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(min(&self[0], &other[0]), - min(&self[1], &other[1]), - min(&self[2], &other[2]), - min(&self[3], &other[3])) - } - - #[inline(always)] - pure fn max_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(max(&self[0], &other[0]), - max(&self[1], &other[1]), - max(&self[2], &other[2]), - max(&self[3], &other[3])) - } - - #[inline(always)] - pure fn clamp_v(&self, mn: &Vec4, mx: &Vec4) -> Vec4 { - Vec4::new(self[0].clamp(&mn[0], &mx[0]), - self[1].clamp(&mn[1], &mx[1]), - self[2].clamp(&mn[2], &mx[2]), - self[3].clamp(&mn[3], &mx[3])) - } -} - -// Mix - -pub trait MixVector: Vector { - pure fn mix_t(&self, other: T, value: T) -> self; - pure fn smooth_step_t(&self, edge0: T, edge1: T) -> self; - pure fn step_t(&self, edge: T) -> self; - - pure fn mix_v(&self, other: &self, value: &self) -> self; - pure fn smooth_step_v(&self, edge0: &self, edge1: &self) -> self; - pure fn step_v(&self, edge: &self) -> self; -} - -pub impl Vec2: MixVector { - #[inline(always)] - pure fn mix_t(&self, other: T, value: T) -> Vec2 { - Vec2::new(self[0].mix(&other, &value), - self[1].mix(&other, &value)) - } - - #[inline(always)] - pure fn smooth_step_t(&self, edge0: T, edge1: T) -> Vec2 { - Vec2::new(self[0].smooth_step(&edge0, &edge1), - self[1].smooth_step(&edge0, &edge1)) - } - - #[inline(always)] - pure fn step_t(&self, edge: T) -> Vec2 { - Vec2::new(self[0].step(&edge), - self[1].step(&edge)) - } - - #[inline(always)] - pure fn mix_v(&self, other: &Vec2, value: &Vec2) -> Vec2 { - Vec2::new(self[0].mix(&other[0], &value[0]), - self[1].mix(&other[1], &value[1])) - } - - #[inline(always)] - pure fn smooth_step_v(&self, edge0: &Vec2, edge1: &Vec2) -> Vec2 { - Vec2::new(self[0].smooth_step(&edge0[0], &edge1[0]), - self[1].smooth_step(&edge0[1], &edge1[1])) - } - - #[inline(always)] - pure fn step_v(&self, edge: &Vec2) -> Vec2 { - Vec2::new(self[0].step(&edge[0]), - self[1].step(&edge[1])) - } -} - -pub impl Vec3: MixVector { - #[inline(always)] - pure fn mix_t(&self, other: T, value: T) -> Vec3 { - Vec3::new(self[0].mix(&other, &value), - self[1].mix(&other, &value), - self[2].mix(&other, &value)) - } - - #[inline(always)] - pure fn smooth_step_t(&self, edge0: T, edge1: T) -> Vec3 { - Vec3::new(self[0].smooth_step(&edge0, &edge1), - self[1].smooth_step(&edge0, &edge1), - self[2].smooth_step(&edge0, &edge1)) - } - - #[inline(always)] - pure fn step_t(&self, edge: T) -> Vec3 { - Vec3::new(self[0].step(&edge), - self[1].step(&edge), - self[2].step(&edge)) - } - - #[inline(always)] - pure fn mix_v(&self, other: &Vec3, value: &Vec3) -> Vec3 { - Vec3::new(self[0].mix(&other[0], &value[0]), - self[1].mix(&other[1], &value[1]), - self[2].mix(&other[2], &value[2])) - } - - #[inline(always)] - pure fn smooth_step_v(&self, edge0: &Vec3, edge1: &Vec3) -> Vec3 { - Vec3::new(self[0].smooth_step(&edge0[0], &edge1[0]), - self[1].smooth_step(&edge0[1], &edge1[1]), - self[2].smooth_step(&edge0[2], &edge1[2])) - } - - #[inline(always)] - pure fn step_v(&self, edge: &Vec3) -> Vec3 { - Vec3::new(self[0].step(&edge[0]), - self[1].step(&edge[1]), - self[2].step(&edge[2])) - } -} - -pub impl Vec4: MixVector { - #[inline(always)] - pure fn mix_t(&self, other: T, value: T) -> Vec4 { - Vec4::new(self[0].mix(&other, &value), - self[1].mix(&other, &value), - self[2].mix(&other, &value), - self[3].mix(&other, &value)) - } - - #[inline(always)] - pure fn smooth_step_t(&self, edge0: T, edge1: T) -> Vec4 { - Vec4::new(self[0].smooth_step(&edge0, &edge1), - self[1].smooth_step(&edge0, &edge1), - self[2].smooth_step(&edge0, &edge1), - self[3].smooth_step(&edge0, &edge1)) - } - - #[inline(always)] - pure fn step_t(&self, edge: T) -> Vec4 { - Vec4::new(self[0].step(&edge), - self[1].step(&edge), - self[2].step(&edge), - self[3].step(&edge)) - } - - #[inline(always)] - pure fn mix_v(&self, other: &Vec4, value: &Vec4) -> Vec4 { - Vec4::new(self[0].mix(&other[0], &value[0]), - self[1].mix(&other[1], &value[1]), - self[2].mix(&other[2], &value[2]), - self[3].mix(&other[3], &value[3])) - } - - #[inline(always)] - pure fn smooth_step_v(&self, edge0: &Vec4, edge1: &Vec4) -> Vec4 { - Vec4::new(self[0].smooth_step(&edge0[0], &edge1[0]), - self[1].smooth_step(&edge0[1], &edge1[1]), - self[2].smooth_step(&edge0[2], &edge1[2]), - self[3].smooth_step(&edge0[3], &edge1[3])) - } - - #[inline(always)] - pure fn step_v(&self, edge: &Vec4) -> Vec4 { - Vec4::new(self[0].step(&edge[0]), - self[1].step(&edge[1]), - self[2].step(&edge[2]), - self[3].step(&edge[3])) - } -} - -// Sign - -pub impl Vec2: Sign { - #[inline(always)] - pure fn abs(&self) -> Vec2 { - Vec2::new(abs(&self[0]), - abs(&self[1])) - } - - #[inline(always)] - pure fn sign(&self) -> Vec2 { - Vec2::new(sign(&self[0]), - sign(&self[1])) - } -} - -pub impl Vec3: Sign { - #[inline(always)] - pure fn abs(&self) -> Vec3 { - Vec3::new(abs(&self[0]), - abs(&self[1]), - abs(&self[2])) - } - - #[inline(always)] - pure fn sign(&self) -> Vec3 { - Vec3::new(sign(&self[0]), - sign(&self[1]), - sign(&self[2])) - } -} - -pub impl Vec4: Sign { - #[inline(always)] - pure fn abs(&self) -> Vec4 { - Vec4::new(abs(&self[0]), - abs(&self[1]), - abs(&self[2]), - abs(&self[3])) - } - - #[inline(always)] - pure fn sign(&self) -> Vec4 { - Vec4::new(sign(&self[0]), - sign(&self[1]), - sign(&self[2]), - sign(&self[3])) - } -} diff --git a/src/funs/exponential.rs b/src/funs/exponential.rs deleted file mode 100644 index 03088f7..0000000 --- a/src/funs/exponential.rs +++ /dev/null @@ -1,213 +0,0 @@ -/** - * Exponential Functions - * - * This module corresponds to Section 8.2 of the [GLSL 4.30.6 specification] - * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). - */ - -use numeric::funs::*; -use numeric::traits::*; - -use vec::{Vector, Vec2, Vec3, Vec4}; - -// Exp - -pub trait ExpVector: Vector { - pure fn pow_t(&self, n: T) -> self; - pure fn pow_v(&self, n: &self) -> self; -} - -pub impl Vec2: ExpVector { - #[inline(always)] - pure fn pow_t(&self, n: T) -> Vec2 { - Vec2::new(pow(&self[0], &n), - pow(&self[1], &n)) - } - - #[inline(always)] - pure fn pow_v(&self, n: &Vec2) -> Vec2 { - Vec2::new(pow(&self[0], &n[0]), - pow(&self[1], &n[1])) - } -} - -pub impl Vec2: Exp { - #[inline(always)] - pure fn pow(&self, n: &Vec2) -> Vec2 { - self.pow_v(n) - } - - #[inline(always)] - pure fn exp(&self) -> Vec2 { - Vec2::new(exp(&self[0]), - exp(&self[1])) - } - - #[inline(always)] - pure fn log_(&self) -> Vec2 { - Vec2::new(log_(&self[0]), - log_(&self[1])) - } - - #[inline(always)] - pure fn exp2(&self) -> Vec2 { - Vec2::new(exp2(&self[0]), - exp2(&self[1])) - } - - #[inline(always)] - pure fn log2(&self) -> Vec2 { - Vec2::new(log2(&self[0]), - log2(&self[1])) - } - - #[inline(always)] - pure fn sqrt(&self) -> Vec2 { - Vec2::new(sqrt(&self[0]), - sqrt(&self[1])) - } - - #[inline(always)] - pure fn inv_sqrt(&self) -> Vec2 { - Vec2::new(inv_sqrt(&self[0]), - inv_sqrt(&self[1])) - } -} - -pub impl Vec3: ExpVector { - #[inline(always)] - pure fn pow_t(&self, n: T) -> Vec3 { - Vec3::new(pow(&self[0], &n), - pow(&self[1], &n), - pow(&self[2], &n)) - } - - #[inline(always)] - pure fn pow_v(&self, n: &Vec3) -> Vec3 { - Vec3::new(pow(&self[0], &n[0]), - pow(&self[1], &n[1]), - pow(&self[2], &n[2])) - } -} - -pub impl Vec3: Exp { - #[inline(always)] - pure fn pow(&self, n: &Vec3) -> Vec3 { - self.pow_v(n) - } - - #[inline(always)] - pure fn exp(&self) -> Vec3 { - Vec3::new(exp(&self[0]), - exp(&self[1]), - exp(&self[2])) - } - - #[inline(always)] - pure fn log_(&self) -> Vec3 { - Vec3::new(log_(&self[0]), - log_(&self[1]), - log_(&self[2])) - } - - #[inline(always)] - pure fn exp2(&self) -> Vec3 { - Vec3::new(exp2(&self[0]), - exp2(&self[1]), - exp2(&self[2])) - } - - #[inline(always)] - pure fn log2(&self) -> Vec3 { - Vec3::new(log2(&self[0]), - log2(&self[1]), - log2(&self[2])) - } - - #[inline(always)] - pure fn sqrt(&self) -> Vec3 { - Vec3::new(sqrt(&self[0]), - sqrt(&self[1]), - sqrt(&self[2])) - } - - #[inline(always)] - pure fn inv_sqrt(&self) -> Vec3 { - Vec3::new(inv_sqrt(&self[0]), - inv_sqrt(&self[1]), - inv_sqrt(&self[2])) - } -} - -pub impl Vec4: ExpVector { - #[inline(always)] - pure fn pow_t(&self, n: T) -> Vec4 { - Vec4::new(pow(&self[0], &n), - pow(&self[1], &n), - pow(&self[2], &n), - pow(&self[3], &n)) - } - - #[inline(always)] - pure fn pow_v(&self, n: &Vec4) -> Vec4 { - Vec4::new(pow(&self[0], &n[0]), - pow(&self[1], &n[1]), - pow(&self[2], &n[2]), - pow(&self[3], &n[3])) - } -} - -pub impl Vec4: Exp { - #[inline(always)] - pure fn pow(&self, n: &Vec4) -> Vec4 { - self.pow_v(n) - } - - #[inline(always)] - pure fn exp(&self) -> Vec4 { - Vec4::new(exp(&self[0]), - exp(&self[1]), - exp(&self[2]), - exp(&self[3])) - } - - #[inline(always)] - pure fn log_(&self) -> Vec4 { - Vec4::new(log_(&self[0]), - log_(&self[1]), - log_(&self[2]), - log_(&self[3])) - } - - #[inline(always)] - pure fn exp2(&self) -> Vec4 { - Vec4::new(exp2(&self[0]), - exp2(&self[1]), - exp2(&self[2]), - exp2(&self[3])) - } - - #[inline(always)] - pure fn log2(&self) -> Vec4 { - Vec4::new(log2(&self[0]), - log2(&self[1]), - log2(&self[2]), - log2(&self[3])) - } - - #[inline(always)] - pure fn sqrt(&self) -> Vec4 { - Vec4::new(sqrt(&self[0]), - sqrt(&self[1]), - sqrt(&self[2]), - sqrt(&self[3])) - } - - #[inline(always)] - pure fn inv_sqrt(&self) -> Vec4 { - Vec4::new(inv_sqrt(&self[0]), - inv_sqrt(&self[1]), - inv_sqrt(&self[2]), - inv_sqrt(&self[3])) - } -} \ No newline at end of file diff --git a/src/funs/relational.rs b/src/funs/relational.rs deleted file mode 100644 index 61b0dba..0000000 --- a/src/funs/relational.rs +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Vector Relational Functions - * - * This module corresponds to Section 8.7 of the [GLSL 4.30.6 specification] - * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). - */ - -use core::cmp::{Eq, Ord}; -use vec::{Vector, Vec2, Vec3, Vec4}; - -/** - * Component-wise vector comparison methods - */ -pub trait OrdinalVector: Vector { - /** - * Component-wise compare of `self < other` - */ - pure fn less_than(&self, other: &self) -> BoolVec; - - /** - * Component-wise compare of `self <= other` - */ - pure fn less_than_equal(&self, other: &self) -> BoolVec; - - /** - * Component-wise compare of `self > other` - */ - pure fn greater_than(&self, other: &self) -> BoolVec; - - /** - * Component-wise compare of `self >= other` - */ - pure fn greater_than_equal(&self, other: &self) -> BoolVec; -} - -/** - * Component-wise equality comparison methods - */ -pub trait EquableVector: Vector { - /** - * Component-wise compare of `self == other` - */ - pure fn equal(&self, other: &self) -> BoolVec; - - /** - * Component-wise compare of `self != other` - */ - pure fn not_equal(&self, other: &self) -> BoolVec; -} - -/** - * A vector with boolean components - */ -pub trait BooleanVector: Vector { - /** - * # Return value - * - * `true` if of any component is `true` - */ - pure fn any(&self) -> bool; - - /** - * # Return value - * - * `true` only if all components are `true` - */ - pure fn all(&self) -> bool; - - /** - * # Return value - * - * the component-wise logical complement - */ - pure fn not(&self) -> self; -} - -pub impl Vec2: OrdinalVector> { - #[inline(always)] - pure fn less_than(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] < other[0], - self[1] < other[1]) - } - - #[inline(always)] - pure fn less_than_equal(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] <= other[0], - self[1] <= other[1]) - } - - #[inline(always)] - pure fn greater_than(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] > other[0], - self[1] > other[1]) - } - - #[inline(always)] - pure fn greater_than_equal(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] >= other[0], - self[1] >= other[1]) - } -} - -pub impl Vec2: EquableVector> { - #[inline(always)] - pure fn equal(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] == other[0], - self[1] == other[1]) - } - - #[inline(always)] - pure fn not_equal(&self, other: &Vec2) -> Vec2 { - Vec2::new(self[0] != other[0], - self[1] != other[1]) - } -} - -pub impl Vec2: BooleanVector { - #[inline(always)] - pure fn any(&self) -> bool { - self[0] || self[1] - } - - #[inline(always)] - pure fn all(&self) -> bool { - self[0] && self[1] - } - - #[inline(always)] - pure fn not(&self) -> Vec2 { - Vec2::new(!self[0], !self[1]) - } -} - -pub impl Vec3: OrdinalVector> { - #[inline(always)] - pure fn less_than(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] < other[0], - self[1] < other[1], - self[2] < other[2]) - } - - #[inline(always)] - pure fn less_than_equal(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] <= other[0], - self[1] <= other[1], - self[2] <= other[2]) - } - - #[inline(always)] - pure fn greater_than(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] > other[0], - self[1] > other[1], - self[2] > other[2]) - } - - #[inline(always)] - pure fn greater_than_equal(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] >= other[0], - self[1] >= other[1], - self[2] >= other[2]) - } -} - -pub impl Vec3: EquableVector> { - #[inline(always)] - pure fn equal(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] == other[0], - self[1] == other[1], - self[2] == other[2]) - } - - #[inline(always)] - pure fn not_equal(&self, other: &Vec3) -> Vec3 { - Vec3::new(self[0] != other[0], - self[1] != other[1], - self[2] != other[2]) - } -} - -pub impl Vec3: BooleanVector { - #[inline(always)] - pure fn any(&self) -> bool { - self[0] || self[1] || self[2] - } - - #[inline(always)] - pure fn all(&self) -> bool { - self[0] && self[1] && self[2] - } - - #[inline(always)] - pure fn not(&self) -> Vec3 { - Vec3::new(!self[0], !self[1], !self[2]) - } -} - -pub impl Vec4: OrdinalVector> { - #[inline(always)] - pure fn less_than(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] < other[0], - self[1] < other[1], - self[2] < other[2], - self[3] < other[3]) - } - - #[inline(always)] - pure fn less_than_equal(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] <= other[0], - self[1] <= other[1], - self[2] <= other[2], - self[3] <= other[3]) - } - - #[inline(always)] - pure fn greater_than(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] > other[0], - self[1] > other[1], - self[2] > other[2], - self[3] > other[3]) - } - - #[inline(always)] - pure fn greater_than_equal(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] >= other[0], - self[1] >= other[1], - self[2] >= other[2], - self[3] >= other[3]) - } -} - -pub impl Vec4: EquableVector> { - #[inline(always)] - pure fn equal(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] == other[0], - self[1] == other[1], - self[2] == other[2], - self[3] == other[3]) - } - - #[inline(always)] - pure fn not_equal(&self, other: &Vec4) -> Vec4 { - Vec4::new(self[0] != other[0], - self[1] != other[1], - self[2] != other[2], - self[3] != other[3]) - } -} - -pub impl Vec4: BooleanVector { - #[inline(always)] - pure fn any(&self) -> bool { - self[0] || self[1] || self[2] || self[3] - } - - #[inline(always)] - pure fn all(&self) -> bool { - self[0] && self[1] && self[2] && self[3] - } - - #[inline(always)] - pure fn not(&self) -> Vec4 { - Vec4::new(!self[0], !self[1], !self[2], !self[3]) - } -} \ No newline at end of file diff --git a/src/funs/triganomic.rs b/src/funs/triganomic.rs deleted file mode 100644 index 56fbc80..0000000 --- a/src/funs/triganomic.rs +++ /dev/null @@ -1,230 +0,0 @@ -/** - * Angle and Trigonometry Functions - * - * This module corresponds to Section 8.1 of the [GLSL 4.30.6 specification] - * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). - */ - -use numeric::funs::*; -use numeric::traits::*; -use numeric::types::angle::{Angle, Radians}; -use numeric::types::float::Float; - -use vec::{Vec3, Vec2, Vec4}; - -// see issue: https://github.com/mozilla/rust/issues/4208 - -// // Trig - -// pub impl> Vec2: Trig> { -// #[inline(always)] -// pure fn sin(&self) -> Vec2 { -// Vec2::new(sin(&self[0]), -// sin(&self[1])) -// } - -// #[inline(always)] -// pure fn cos(&self) -> Vec2 { -// Vec2::new(cos(&self[0]), -// cos(&self[1])) -// } - -// #[inline(always)] -// pure fn tan(&self) -> Vec2 { -// Vec2::new(tan(&self[0]), -// tan(&self[1])) -// } -// } - -// pub impl> Vec3: Trig> { -// #[inline(always)] -// pure fn sin(&self) -> Vec3 { -// Vec3::new(sin(&self[0]), -// sin(&self[1]), -// sin(&self[2])) -// } - -// #[inline(always)] -// pure fn cos(&self) -> Vec3 { -// Vec3::new(cos(&self[0]), -// cos(&self[1]), -// cos(&self[2])) -// } - -// #[inline(always)] -// pure fn tan(&self) -> Vec3 { -// Vec3::new(tan(&self[0]), -// tan(&self[1]), -// tan(&self[2])) -// } -// } - -// pub impl> Vec4: Trig> { -// #[inline(always)] -// pure fn sin(&self) -> Vec4 { -// Vec4::new(sin(&self[0]), -// sin(&self[1]), -// sin(&self[2]), -// sin(&self[3])) -// } - -// #[inline(always)] -// pure fn cos(&self) -> Vec4 { -// Vec4::new(cos(&self[0]), -// cos(&self[1]), -// cos(&self[2]), -// cos(&self[3])) -// } - -// #[inline(always)] -// pure fn tan(&self) -> Vec4 { -// Vec4::new(tan(&self[0]), -// tan(&self[1]), -// tan(&self[2]), -// tan(&self[3])) -// } -// } - -// see issue: https://github.com/mozilla/rust/issues/4208 - -// // InvTrig - -// pub impl Vec2: InvTrig>> { -// #[inline(always)] -// pure fn asin(&self) -> Vec2> { -// Vec2::new(asin(&self[0]), -// asin(&self[1])) -// } - -// #[inline(always)] -// pure fn acos(&self) -> Vec2> { -// Vec2::new(acos(&self[0]), -// acos(&self[1])) -// } - -// #[inline(always)] -// pure fn atan(&self) -> Vec2> { -// Vec2::new(atan(&self[0]), -// atan(&self[1])) -// } -// } - -// pub impl Vec3: InvTrig>> { -// #[inline(always)] -// pure fn asin(&self) -> Vec3> { -// Vec3::new(asin(&self[0]), -// asin(&self[1]), -// asin(&self[2])) -// } - -// #[inline(always)] -// pure fn acos(&self) -> Vec3> { -// Vec3::new(acos(&self[0]), -// acos(&self[1]), -// acos(&self[2])) -// } - -// #[inline(always)] -// pure fn atan(&self) -> Vec3> { -// Vec3::new(atan(&self[0]), -// atan(&self[1]), -// atan(&self[2])) -// } -// } - -// pub impl Vec4: InvTrig>> { -// #[inline(always)] -// pure fn asin(&self) -> Vec4> { -// Vec4::new(asin(&self[0]), -// asin(&self[1]), -// asin(&self[2]), -// asin(&self[3])) -// } - -// #[inline(always)] -// pure fn acos(&self) -> Vec4> { -// Vec4::new(acos(&self[0]), -// acos(&self[1]), -// acos(&self[2]), -// acos(&self[3])) -// } - -// #[inline(always)] -// pure fn atan(&self) -> Vec4> { -// Vec4::new(atan(&self[0]), -// atan(&self[1]), -// atan(&self[2]), -// atan(&self[3])) -// } -// } - -// Hyp - -pub impl Vec2: Hyp { - #[inline(always)] - pure fn sinh(&self) -> Vec2 { - Vec2::new(sinh(&self[0]), - sinh(&self[1])) - } - - #[inline(always)] - pure fn cosh(&self) -> Vec2 { - Vec2::new(cosh(&self[0]), - cosh(&self[1])) - } - - #[inline(always)] - pure fn tanh(&self) -> Vec2 { - Vec2::new(tanh(&self[0]), - tanh(&self[1])) - } -} - -pub impl Vec3: Hyp { - #[inline(always)] - pure fn sinh(&self) -> Vec3 { - Vec3::new(sinh(&self[0]), - sinh(&self[1]), - sinh(&self[2])) - } - - #[inline(always)] - pure fn cosh(&self) -> Vec3 { - Vec3::new(cosh(&self[0]), - cosh(&self[1]), - cosh(&self[2])) - } - - #[inline(always)] - pure fn tanh(&self) -> Vec3 { - Vec3::new(tanh(&self[0]), - tanh(&self[1]), - tanh(&self[2])) - } -} - -pub impl Vec4: Hyp { - #[inline(always)] - pure fn sinh(&self) -> Vec4 { - Vec4::new(sinh(&self[0]), - sinh(&self[1]), - sinh(&self[2]), - sinh(&self[3])) - } - - #[inline(always)] - pure fn cosh(&self) -> Vec4 { - Vec4::new(cosh(&self[0]), - cosh(&self[1]), - cosh(&self[2]), - cosh(&self[3])) - } - - #[inline(always)] - pure fn tanh(&self) -> Vec4 { - Vec4::new(tanh(&self[0]), - tanh(&self[1]), - tanh(&self[2]), - tanh(&self[3])) - } -} \ No newline at end of file diff --git a/src/gltypes.rs b/src/gltypes.rs index 94c7690..d73eea4 100644 --- a/src/gltypes.rs +++ b/src/gltypes.rs @@ -26,6 +26,8 @@ use mat::{Matrix, Mat2, Mat3, Mat4}; use vec::{Vector, NumericVector, Vec2, Vec3, Vec4}; use quat::{/*Quaternion, */Quat}; +use numeric::*; + // Vector aliases, corresponding to Section 4.1.5 of the [GLSL 4.30.6 specification] // (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). diff --git a/src/lmath.rc b/src/lmath.rc index 4c227bf..ae58985 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -23,6 +23,8 @@ pub mod vec2; pub mod vec3; pub mod vec4; +pub mod projection; + #[test] mod test { mod test_gltypes; @@ -31,16 +33,3 @@ mod test { mod test_rot; mod test_vec; } - -pub mod funs { - pub mod common; - pub mod exponential; - pub mod projection; - pub mod triganomic; - - #[test] - mod test { - // #[path = "funs/test/test_common.rs"] - // mod test_common; - } -} diff --git a/src/mat.rs b/src/mat.rs index 861b1b5..1ffbec1 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1,6 +1,5 @@ use core::cmp::Eq; use std::cmp::FuzzyEq; -use numeric::types::angle::Angle; use quat::Quat; diff --git a/src/mat2.rs b/src/mat2.rs index efa7879..6f92021 100644 --- a/src/mat2.rs +++ b/src/mat2.rs @@ -5,9 +5,8 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Angle, Float}; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number::{zero,one}; use vec::Vec2; @@ -107,9 +106,9 @@ pub impl Mat2 { // FIXME: An interim solution to the issues with static functions #[inline(always)] - static pure fn from_angle>(theta: A) -> Mat2 { - let cos_theta = cos(&theta.to_radians()); - let sin_theta = sin(&theta.to_radians()); + static pure fn from_angle(radians: T) -> Mat2 { + let cos_theta = cos(radians); + let sin_theta = sin(radians); Mat2::new(cos_theta, -sin_theta, sin_theta, cos_theta) diff --git a/src/mat3.rs b/src/mat3.rs index caed487..6745cbf 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -5,10 +5,9 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Angle, Float}; -use numeric::types::number::Number; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number; +use numeric::number::Number::{zero,one}; use quat::Quat; use rot::Rotation; @@ -132,10 +131,10 @@ pub impl Mat3 { */ // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_x>(theta: A) -> Mat3 { + static pure fn from_angle_x(radians: T) -> Mat3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let cos_theta = cos(&theta.to_radians()); - let sin_theta = sin(&theta.to_radians()); + let cos_theta = cos(radians); + let sin_theta = sin(radians); Mat3::new( one(), zero(), zero(), zero(), cos_theta, sin_theta, @@ -147,10 +146,10 @@ pub impl Mat3 { */ // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_y>(theta: A) -> Mat3 { + static pure fn from_angle_y(radians: T) -> Mat3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let cos_theta = cos(&theta.to_radians()); - let sin_theta = sin(&theta.to_radians()); + let cos_theta = cos(radians); + let sin_theta = sin(radians); Mat3::new(cos_theta, zero(), -sin_theta, zero(), one(), zero(), @@ -162,10 +161,10 @@ pub impl Mat3 { */ // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_z>(theta: A) -> Mat3 { + static pure fn from_angle_z(radians: T) -> Mat3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let cos_theta = cos(&theta.to_radians()); - let sin_theta = sin(&theta.to_radians()); + let cos_theta = cos(radians); + let sin_theta = sin(radians); Mat3::new( cos_theta, sin_theta, zero(), -sin_theta, cos_theta, zero(), @@ -183,14 +182,14 @@ pub impl Mat3 { */ // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_xyz>(theta_x: A, theta_y: A, theta_z: A) -> Mat3 { + static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Mat3 { // http://en.wikipedia.org/wiki/Rotation_matrix#General_rotations - let cx = cos(&theta_x.to_radians()); - let sx = sin(&theta_x.to_radians()); - let cy = cos(&theta_y.to_radians()); - let sy = sin(&theta_y.to_radians()); - let cz = cos(&theta_z.to_radians()); - let sz = sin(&theta_z.to_radians()); + let cx = cos(radians_x); + let sx = sin(radians_x); + let cy = cos(radians_y); + let sy = sin(radians_y); + let cz = cos(radians_z); + let sz = sin(radians_z); Mat3::new( cy*cz, cy*sz, -sy, -cx*sz + sx*sy*cz, cx*cz + sx*sy*sz, sx*cy, @@ -202,9 +201,9 @@ pub impl Mat3 { */ // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_axis>(theta: A, axis: &Vec3) -> Mat3 { - let c = cos(&theta.to_radians()); - let s = sin(&theta.to_radians()); + static pure fn from_angle_axis(radians: T, axis: &Vec3) -> Mat3 { + let c = cos(radians); + let s = sin(radians); let _1_c = one::() - c; let x = axis.x; diff --git a/src/mat4.rs b/src/mat4.rs index 670ac60..5e13825 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -5,9 +5,8 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Angle, Float}; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number::{zero,one}; use vec::Vec4; @@ -293,7 +292,7 @@ pub impl Mat4: Matrix> { // Find largest element in col j let mut i1 = j; for uint::range(j + 1, 4) |i| { - if abs(&A[j][i]) > abs(&A[j][i1]) { + if abs(A[j][i]) > abs(A[j][i1]) { i1 = i; } } diff --git a/src/funs/projection.rs b/src/projection.rs similarity index 83% rename from src/funs/projection.rs rename to src/projection.rs index 1f24b9e..54157cd 100644 --- a/src/funs/projection.rs +++ b/src/projection.rs @@ -1,7 +1,5 @@ -use numeric::funs::*; -use numeric::types::angle::Angle; -use numeric::types::float::Float; -use numeric::types::number::Number; +use numeric::*; +use numeric::number::Number; use mat::Mat4; @@ -12,8 +10,8 @@ use mat::Mat4; * can be found [here](http://www.opengl.org/wiki/GluPerspective_code). */ #[inline(always)] -pub pure fn perspective>(fovy: A, aspectRatio: T, near: T, far: T) -> Mat4 { - let ymax = near * tan(&fovy.to_radians()); +pub pure fn perspective(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4 { + let ymax = near * tan(radians(fovy)); let xmax = ymax * aspectRatio; frustum(-xmax, xmax, -ymax, ymax, near, far) diff --git a/src/quat.rs b/src/quat.rs index 8131efc..6ef9619 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -14,11 +14,9 @@ use core::sys::size_of; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::angle::Angle; -use numeric::types::float::Float; -use numeric::types::number::Number; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number; +use numeric::number::Number::{zero,one}; use mat::{Mat3, Mat4}; use vec::Vec3; @@ -274,15 +272,15 @@ pub impl Quat { if dot > dot_threshold { return self.nlerp(other, amount); // if quaternions are close together use `nlerp` } else { - let robust_dot = dot.clamp(&-one::(), &one()); // stay within the domain of acos() + let robust_dot = dot.clamp(-one::(), one()); // stay within the domain of acos() - let theta_0 = acos(&robust_dot); // the angle between the quaternions + let theta_0 = acos(robust_dot); // the angle between the quaternions let theta = theta_0 * amount; // the fraction of theta specified by `amount` let q = other.sub_q(&self.mul_t(robust_dot)) .normalize(); - return self.mul_t(cos(&theta)).add_q(&q.mul_t(sin(&theta))); + return self.mul_t(cos(theta)).add_q(&q.mul_t(sin(theta))); } } @@ -302,47 +300,44 @@ pub impl Quat { // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_x>(theta: A) -> Quat { + static pure fn from_angle_x(radians: T) -> Quat { let _2 = Number::from(2); - let rad = theta.to_radians(); - Quat::new((rad / _2).cos(), rad.sin(), zero(), zero()) + Quat::new(cos(radians / _2), sin(radians), zero(), zero()) } // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_y>(theta: A) -> Quat { + static pure fn from_angle_y(radians: T) -> Quat { let _2 = Number::from(2); - let rad = theta.to_radians(); - Quat::new((rad / _2).cos(), zero(), rad.sin(), zero()) + Quat::new(cos(radians / _2), zero(), sin(radians), zero()) } // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_z>(theta: A) -> Quat { + static pure fn from_angle_z(radians: T) -> Quat { let _2 = Number::from(2); - let rad = theta.to_radians(); - Quat::new((rad / _2).cos(), zero(), zero(), rad.sin()) + Quat::new(cos(radians / _2), zero(), zero(), sin(radians)) } // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_xyz>(x: A, y: A, z: A) -> Quat { + static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Quat { // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion let _2 = Number::from(2); - let xdiv2 = x.to_radians() / _2; - let ydiv2 = y.to_radians() / _2; - let zdiv2 = z.to_radians() / _2; - Quat::new(cos(&zdiv2) * cos(&xdiv2) * cos(&ydiv2) + sin(&zdiv2) * sin(&xdiv2) * sin(&ydiv2), - sin(&zdiv2) * cos(&xdiv2) * cos(&ydiv2) - cos(&zdiv2) * sin(&xdiv2) * sin(&ydiv2), - cos(&zdiv2) * sin(&xdiv2) * cos(&ydiv2) + sin(&zdiv2) * cos(&xdiv2) * sin(&ydiv2), - cos(&zdiv2) * cos(&xdiv2) * sin(&ydiv2) - sin(&zdiv2) * sin(&xdiv2) * cos(&ydiv2)) + let xdiv2 = radians_x / _2; + let ydiv2 = radians_y / _2; + let zdiv2 = radians_z / _2; + Quat::new(cos(zdiv2) * cos(xdiv2) * cos(ydiv2) + sin(zdiv2) * sin(xdiv2) * sin(ydiv2), + sin(zdiv2) * cos(xdiv2) * cos(ydiv2) - cos(zdiv2) * sin(xdiv2) * sin(ydiv2), + cos(zdiv2) * sin(xdiv2) * cos(ydiv2) + sin(zdiv2) * cos(xdiv2) * sin(ydiv2), + cos(zdiv2) * cos(xdiv2) * sin(ydiv2) - sin(zdiv2) * sin(xdiv2) * cos(ydiv2)) } // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 #[inline(always)] - static pure fn from_angle_axis>(theta: A, axis: &Vec3) -> Quat { - let half = theta.to_radians() / Number::from(2); - Quat::from_sv(cos(&half), axis.mul_t(sin(&half))) + static pure fn from_angle_axis(radians: T, axis: &Vec3) -> Quat { + let half = radians / Number::from(2); + Quat::from_sv(cos(half), axis.mul_t(sin(half))) } // TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306 @@ -351,7 +346,7 @@ pub impl Quat { Mat3::from_axes(x, y, z).to_quat() } - pure fn get_angle_axis>(&self) -> (A, Vec3) { + pure fn get_angle_axis(&self) -> (T, Vec3) { fail(~"Not yet implemented.") } diff --git a/src/rot.rs b/src/rot.rs index fde7409..6313ea7 100644 --- a/src/rot.rs +++ b/src/rot.rs @@ -1,5 +1,3 @@ -use numeric::types::angle::Angle; - use mat::Mat3; use quat::Quat; use vec::Vec3; @@ -10,11 +8,11 @@ use vec::Vec3; pub trait Rotation { static pure fn from>(rot: R) -> self; - static pure fn from_angle_x>(theta: A) -> self; - static pure fn from_angle_y>(theta: A) -> self; - static pure fn from_angle_z>(theta: A) -> self; - static pure fn from_angle_xyz>(x: A, y: A, z: A) -> self; - static pure fn from_angle_axis>(theta: A, axis: &Vec3) -> self; + static pure fn from_angle_x(radians: T) -> self; + static pure fn from_angle_y(radians: T) -> self; + static pure fn from_angle_z(radians: T) -> self; + static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> self; + static pure fn from_angle_axis(radians: T, axis: &Vec3) -> self; static pure fn from_axes(x: Vec3, y: Vec3, z: Vec3) -> self; static pure fn look_at(dir: &Vec3, up: &Vec3) -> self; diff --git a/src/test/test_quat.rs b/src/test/test_quat.rs index ff327c6..7d2f13a 100644 --- a/src/test/test_quat.rs +++ b/src/test/test_quat.rs @@ -1,5 +1,4 @@ -use numeric::funs::sqrt; -use numeric::types::angle::*; +use numeric::*; use mat::*; use quat::*; @@ -30,17 +29,19 @@ fn test_quat() { #[test] fn test_quat_2() { + use numeric::types::{Degrees, Radians}; + let v = Vec3::new(1.0, 0.0, 0.0); // let q: Quat = rot::Rotation::from_angle_axis(Degrees(-45.0), &Vec3::new(0.0, 0.0, -1.0)); - let q = Quat::from_angle_axis(Degrees(-45.0), &Vec3::new(0.0, 0.0, -1.0)); + let q = Quat::from_angle_axis(radians(-45.0), &Vec3::new(0.0, 0.0, -1.0)); // http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees - assert q.mul_v(&v).fuzzy_eq(&Vec3::new(1.0/sqrt(&2.0), 1.0/sqrt(&2.0), 0.0)); + assert q.mul_v(&v).fuzzy_eq(&Vec3::new(1.0/sqrt(2.0), 1.0/sqrt(2.0), 0.0)); assert q.mul_v(&v).length() == v.length(); - assert q.to_mat3().fuzzy_eq(&Mat3::new( 1.0/sqrt(&2.0), 1.0/sqrt(&2.0), 0.0, - -1.0/sqrt(&2.0), 1.0/sqrt(&2.0), 0.0, - 0.0, 0.0, 1.0)); + assert q.to_mat3().fuzzy_eq(&Mat3::new( 1.0/sqrt(2.0), 1.0/sqrt(2.0), 0.0, + -1.0/sqrt(2.0), 1.0/sqrt(2.0), 0.0, + 0.0, 0.0, 1.0)); } #[test] diff --git a/src/test/test_vec.rs b/src/test/test_vec.rs index 9a99103..96be9c8 100644 --- a/src/test/test_vec.rs +++ b/src/test/test_vec.rs @@ -1,6 +1,6 @@ use std::cmp::FuzzyEq; -use numeric::types::float::*; -use numeric::types::angle::*; +use numeric::*; +use numeric::float::Float; use vec::*; @@ -108,9 +108,9 @@ fn test_vec2_euclidean() { assert a.distance(&b) == 5f; assert a.distance2(&b) == 5f * 5f; - assert Vec2::new(1f, 0f).angle(&Vec2::new(0f, 1f)).fuzzy_eq(&Angle::quadrant()); - assert Vec2::new(10f, 0f).angle(&Vec2::new(0f, 5f)).fuzzy_eq(&Angle::quadrant()); - assert Vec2::new(-1f, 0f).angle(&Vec2::new(0f, 1f)).fuzzy_eq(&-Angle::quadrant()); + assert Vec2::new(1f, 0f).angle(&Vec2::new(0f, 1f)).fuzzy_eq(&Float::frac_pi2()); + assert Vec2::new(10f, 0f).angle(&Vec2::new(0f, 5f)).fuzzy_eq(&Float::frac_pi2()); + assert Vec2::new(-1f, 0f).angle(&Vec2::new(0f, 1f)).fuzzy_eq(&Float::frac_pi2()); assert Vec2::new(3f, 4f).normalize().fuzzy_eq(&Vec2::new(3f/5f, 4f/5f)); // TODO: test normalize_to, normalize_self, and normalize_self_to @@ -265,9 +265,9 @@ fn test_vec3_euclidean() { assert a.distance(&b) == 9f; assert a.distance2(&b) == 9f * 9f; - assert Vec3::new(1f, 0f, 1f).angle(&Vec3::new(1f, 1f, 0f)).fuzzy_eq(&Angle::sextant()); - assert Vec3::new(10f, 0f, 10f).angle(&Vec3::new(5f, 5f, 0f)).fuzzy_eq(&Angle::sextant()); - assert Vec3::new(-1f, 0f, -1f).angle(&Vec3::new(1f, -1f, 0f)).fuzzy_eq(&Radians(2f * Float::frac_pi_3())); + assert Vec3::new(1f, 0f, 1f).angle(&Vec3::new(1f, 1f, 0f)).fuzzy_eq(&Float::frac_pi3()); + assert Vec3::new(10f, 0f, 10f).angle(&Vec3::new(5f, 5f, 0f)).fuzzy_eq(&Float::frac_pi3()); + assert Vec3::new(-1f, 0f, -1f).angle(&Vec3::new(1f, -1f, 0f)).fuzzy_eq(&(2f * Float::frac_pi_3())); assert Vec3::new(2f, 3f, 6f).normalize().fuzzy_eq(&Vec3::new(2f/7f, 3f/7f, 6f/7f)); // TODO: test normalize_to, normalize_self, and normalize_self_to @@ -418,9 +418,9 @@ fn test_vec4_euclidean() { assert a.distance(&b) == 13f; assert a.distance2(&b) == 13f * 13f; - assert Vec4::new(1f, 0f, 1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)).fuzzy_eq(&Angle::quadrant()); - assert Vec4::new(10f, 0f, 10f, 0f).angle(&Vec4::new(0f, 5f, 0f, 5f)).fuzzy_eq(&Angle::quadrant()); - assert Vec4::new(-1f, 0f, -1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)).fuzzy_eq(&Angle::quadrant()); + assert Vec4::new(1f, 0f, 1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)).fuzzy_eq(&Float::frac_pi_2()); + assert Vec4::new(10f, 0f, 10f, 0f).angle(&Vec4::new(0f, 5f, 0f, 5f)).fuzzy_eq(&Float::frac_pi_2()); + assert Vec4::new(-1f, 0f, -1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)).fuzzy_eq(&Float::frac_pi_2()); assert Vec4::new(1f, 2f, 4f, 10f).normalize().fuzzy_eq(&Vec4::new(1f/11f, 2f/11f, 4f/11f, 10f/11f)); // TODO: test normalize_to, normalize_self, and normalize_self_to diff --git a/src/vec.rs b/src/vec.rs index fe64ac4..ba8dd72 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -2,7 +2,7 @@ use core::cmp::Eq; use std::cmp::FuzzyEq; -use numeric::types::{Number, Radians}; +use numeric::Number; pub use vec2::Vec2; pub use vec3::Vec3; @@ -280,9 +280,9 @@ pub trait EuclideanVector: NumericVector { /** * # Return value * - * The angle between the vector and `other` + * The angle between the vector and `other` in radians */ - pure fn angle(&self, other: &self) -> Radians; + pure fn angle(&self, other: &self) -> T; /** * # Return value diff --git a/src/vec2.rs b/src/vec2.rs index 56b5111..611eb5e 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -5,9 +5,8 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Float, Number, Radians}; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number::{zero,one}; use vec::{ Vec3, @@ -234,8 +233,8 @@ pub impl Vec2: EuclideanVector { } #[inline(always)] - pure fn angle(&self, other: &Vec2) -> Radians { - atan2(&self.perp_dot(other), &self.dot(other)) + pure fn angle(&self, other: &Vec2) -> T { + atan2(self.perp_dot(other), self.dot(other)) } #[inline(always)] diff --git a/src/vec3.rs b/src/vec3.rs index e8df648..aa40b09 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -5,9 +5,8 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Float, Number, Radians}; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number::{zero,one}; use vec::{ Vec4, @@ -261,8 +260,8 @@ pub impl Vec3: EuclideanVector { } #[inline(always)] - pure fn angle(&self, other: &Vec3) -> Radians { - atan2(&self.cross(other).length(), &self.dot(other)) + pure fn angle(&self, other: &Vec3) -> T { + atan2(self.cross(other).length(), self.dot(other)) } #[inline(always)] diff --git a/src/vec4.rs b/src/vec4.rs index 09aa3a4..cf3d9d4 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -5,9 +5,8 @@ use core::util::swap; use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use numeric::funs::*; -use numeric::types::{Float, Number, Radians}; -use numeric::types::number::Number::{one, zero}; +use numeric::*; +use numeric::number::Number::{zero,one}; use vec::{ Vector, @@ -252,8 +251,8 @@ pub impl Vec4: EuclideanVector { } #[inline(always)] - pure fn angle(&self, other: &Vec4) -> Radians { - acos(&(self.dot(other) / (self.length() * other.length()))) + pure fn angle(&self, other: &Vec4) -> T { + acos(self.dot(other) / (self.length() * other.length())) } #[inline(always)]