Updates due to changes in numeric-rs

This commit is contained in:
Brendan Zabarauskas 2013-01-28 09:22:15 +11:00
parent bee43bf004
commit ddc617c925
19 changed files with 101 additions and 1315 deletions

View file

@ -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<T:Copy Round> Vec2<T>: Round {
#[inline(always)]
pure fn floor(&self) -> Vec2<T> {
Vec2::new(floor(&self[0]),
floor(&self[1]))
}
#[inline(always)]
pure fn trunc(&self) -> Vec2<T> {
Vec2::new(trunc(&self[0]),
trunc(&self[1]))
}
#[inline(always)]
pure fn round(&self) -> Vec2<T> {
Vec2::new(round(&self[0]),
round(&self[1]))
}
// #[inline(always)]
// pure fn round_even(&self) -> Vec2<T> {
// Vec2::new(round_even(&self[0]),
// round_even(&self[1]))
// }
#[inline(always)]
pure fn ceil(&self) -> Vec2<T> {
Vec2::new(ceil(&self[0]),
ceil(&self[1]))
}
#[inline(always)]
pure fn fract(&self) -> Vec2<T> {
Vec2::new(fract(&self[0]),
fract(&self[1]))
}
}
pub impl<T:Copy Round> Vec3<T>: Round {
#[inline(always)]
pure fn floor(&self) -> Vec3<T> {
Vec3::new(floor(&self[0]),
floor(&self[1]),
floor(&self[2]))
}
#[inline(always)]
pure fn trunc(&self) -> Vec3<T> {
Vec3::new(trunc(&self[0]),
trunc(&self[1]),
trunc(&self[2]))
}
#[inline(always)]
pure fn round(&self) -> Vec3<T> {
Vec3::new(round(&self[0]),
round(&self[1]),
round(&self[2]))
}
// #[inline(always)]
// pure fn round_even(&self) -> Vec3<T> {
// Vec3::new(round_even(&self[0]),
// round_even(&self[1]),
// round_even(&self[2]))
// }
#[inline(always)]
pure fn ceil(&self) -> Vec3<T> {
Vec3::new(ceil(&self[0]),
ceil(&self[1]),
ceil(&self[2]))
}
#[inline(always)]
pure fn fract(&self) -> Vec3<T> {
Vec3::new(fract(&self[0]),
fract(&self[1]),
fract(&self[2]))
}
}
pub impl<T:Copy Round> Vec4<T>: Round {
#[inline(always)]
pure fn floor(&self) -> Vec4<T> {
Vec4::new(floor(&self[0]),
floor(&self[1]),
floor(&self[2]),
floor(&self[3]))
}
#[inline(always)]
pure fn trunc(&self) -> Vec4<T> {
Vec4::new(trunc(&self[0]),
trunc(&self[1]),
trunc(&self[2]),
trunc(&self[3]))
}
#[inline(always)]
pure fn round(&self) -> Vec4<T> {
Vec4::new(round(&self[0]),
round(&self[1]),
round(&self[2]),
round(&self[3]))
}
// #[inline(always)]
// pure fn round_even(&self) -> Vec4<T> {
// 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<T> {
Vec4::new(ceil(&self[0]),
ceil(&self[1]),
ceil(&self[2]),
ceil(&self[3]))
}
#[inline(always)]
pure fn fract(&self) -> Vec4<T> {
Vec4::new(fract(&self[0]),
fract(&self[1]),
fract(&self[2]),
fract(&self[3]))
}
}
// Extent
pub trait ExtentVector<T>: Vector<T> {
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<T:Copy Extent> Vec2<T>: ExtentVector<T> {
#[inline(always)]
pure fn min_t(&self, value: T) -> Vec2<T> {
Vec2::new(min(&self[0], &value),
min(&self[1], &value))
}
#[inline(always)]
pure fn max_t(&self, value: T) -> Vec2<T> {
Vec2::new(max(&self[0], &value),
max(&self[1], &value))
}
#[inline(always)]
pure fn clamp_t(&self, mn: T, mx: T) -> Vec2<T> {
Vec2::new(self[0].clamp(&mn, &mx),
self[1].clamp(&mn, &mx))
}
#[inline(always)]
pure fn min_v(&self, other: &Vec2<T>) -> Vec2<T> {
Vec2::new(min(&self[0], &other[0]),
min(&self[1], &other[1]))
}
#[inline(always)]
pure fn max_v(&self, other: &Vec2<T>) -> Vec2<T> {
Vec2::new(max(&self[0], &other[0]),
max(&self[1], &other[1]))
}
#[inline(always)]
pure fn clamp_v(&self, mn: &Vec2<T>, mx: &Vec2<T>) -> Vec2<T> {
Vec2::new(self[0].clamp(&mn[0], &mx[0]),
self[1].clamp(&mn[1], &mx[1]))
}
}
pub impl<T:Copy Extent> Vec3<T>: ExtentVector<T> {
#[inline(always)]
pure fn min_t(&self, value: T) -> Vec3<T> {
Vec3::new(min(&self[0], &value),
min(&self[1], &value),
min(&self[2], &value))
}
#[inline(always)]
pure fn max_t(&self, value: T) -> Vec3<T> {
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<T> {
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<T>) -> Vec3<T> {
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<T>) -> Vec3<T> {
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<T>, mx: &Vec3<T>) -> Vec3<T> {
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<T:Copy Extent> Vec4<T>: ExtentVector<T> {
#[inline(always)]
pure fn min_t(&self, value: T) -> Vec4<T> {
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<T> {
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<T> {
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<T>) -> Vec4<T> {
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<T>) -> Vec4<T> {
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<T>, mx: &Vec4<T>) -> Vec4<T> {
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<T>: Vector<T> {
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<T:Copy Mix> Vec2<T>: MixVector<T> {
#[inline(always)]
pure fn mix_t(&self, other: T, value: T) -> Vec2<T> {
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<T> {
Vec2::new(self[0].smooth_step(&edge0, &edge1),
self[1].smooth_step(&edge0, &edge1))
}
#[inline(always)]
pure fn step_t(&self, edge: T) -> Vec2<T> {
Vec2::new(self[0].step(&edge),
self[1].step(&edge))
}
#[inline(always)]
pure fn mix_v(&self, other: &Vec2<T>, value: &Vec2<T>) -> Vec2<T> {
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<T>, edge1: &Vec2<T>) -> Vec2<T> {
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<T>) -> Vec2<T> {
Vec2::new(self[0].step(&edge[0]),
self[1].step(&edge[1]))
}
}
pub impl<T:Copy Mix> Vec3<T>: MixVector<T> {
#[inline(always)]
pure fn mix_t(&self, other: T, value: T) -> Vec3<T> {
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<T> {
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<T> {
Vec3::new(self[0].step(&edge),
self[1].step(&edge),
self[2].step(&edge))
}
#[inline(always)]
pure fn mix_v(&self, other: &Vec3<T>, value: &Vec3<T>) -> Vec3<T> {
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<T>, edge1: &Vec3<T>) -> Vec3<T> {
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<T>) -> Vec3<T> {
Vec3::new(self[0].step(&edge[0]),
self[1].step(&edge[1]),
self[2].step(&edge[2]))
}
}
pub impl<T:Copy Mix> Vec4<T>: MixVector<T> {
#[inline(always)]
pure fn mix_t(&self, other: T, value: T) -> Vec4<T> {
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<T> {
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<T> {
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<T>, value: &Vec4<T>) -> Vec4<T> {
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<T>, edge1: &Vec4<T>) -> Vec4<T> {
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<T>) -> Vec4<T> {
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<T:Copy Sign> Vec2<T>: Sign {
#[inline(always)]
pure fn abs(&self) -> Vec2<T> {
Vec2::new(abs(&self[0]),
abs(&self[1]))
}
#[inline(always)]
pure fn sign(&self) -> Vec2<T> {
Vec2::new(sign(&self[0]),
sign(&self[1]))
}
}
pub impl<T:Copy Sign> Vec3<T>: Sign {
#[inline(always)]
pure fn abs(&self) -> Vec3<T> {
Vec3::new(abs(&self[0]),
abs(&self[1]),
abs(&self[2]))
}
#[inline(always)]
pure fn sign(&self) -> Vec3<T> {
Vec3::new(sign(&self[0]),
sign(&self[1]),
sign(&self[2]))
}
}
pub impl<T:Copy Sign> Vec4<T>: Sign {
#[inline(always)]
pure fn abs(&self) -> Vec4<T> {
Vec4::new(abs(&self[0]),
abs(&self[1]),
abs(&self[2]),
abs(&self[3]))
}
#[inline(always)]
pure fn sign(&self) -> Vec4<T> {
Vec4::new(sign(&self[0]),
sign(&self[1]),
sign(&self[2]),
sign(&self[3]))
}
}

View file

@ -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<T>: Vector<T> {
pure fn pow_t(&self, n: T) -> self;
pure fn pow_v(&self, n: &self) -> self;
}
pub impl<T:Copy Exp> Vec2<T>: ExpVector<T> {
#[inline(always)]
pure fn pow_t(&self, n: T) -> Vec2<T> {
Vec2::new(pow(&self[0], &n),
pow(&self[1], &n))
}
#[inline(always)]
pure fn pow_v(&self, n: &Vec2<T>) -> Vec2<T> {
Vec2::new(pow(&self[0], &n[0]),
pow(&self[1], &n[1]))
}
}
pub impl<T:Copy Exp> Vec2<T>: Exp {
#[inline(always)]
pure fn pow(&self, n: &Vec2<T>) -> Vec2<T> {
self.pow_v(n)
}
#[inline(always)]
pure fn exp(&self) -> Vec2<T> {
Vec2::new(exp(&self[0]),
exp(&self[1]))
}
#[inline(always)]
pure fn log_(&self) -> Vec2<T> {
Vec2::new(log_(&self[0]),
log_(&self[1]))
}
#[inline(always)]
pure fn exp2(&self) -> Vec2<T> {
Vec2::new(exp2(&self[0]),
exp2(&self[1]))
}
#[inline(always)]
pure fn log2(&self) -> Vec2<T> {
Vec2::new(log2(&self[0]),
log2(&self[1]))
}
#[inline(always)]
pure fn sqrt(&self) -> Vec2<T> {
Vec2::new(sqrt(&self[0]),
sqrt(&self[1]))
}
#[inline(always)]
pure fn inv_sqrt(&self) -> Vec2<T> {
Vec2::new(inv_sqrt(&self[0]),
inv_sqrt(&self[1]))
}
}
pub impl<T:Copy Exp> Vec3<T>: ExpVector<T> {
#[inline(always)]
pure fn pow_t(&self, n: T) -> Vec3<T> {
Vec3::new(pow(&self[0], &n),
pow(&self[1], &n),
pow(&self[2], &n))
}
#[inline(always)]
pure fn pow_v(&self, n: &Vec3<T>) -> Vec3<T> {
Vec3::new(pow(&self[0], &n[0]),
pow(&self[1], &n[1]),
pow(&self[2], &n[2]))
}
}
pub impl<T:Copy Exp> Vec3<T>: Exp {
#[inline(always)]
pure fn pow(&self, n: &Vec3<T>) -> Vec3<T> {
self.pow_v(n)
}
#[inline(always)]
pure fn exp(&self) -> Vec3<T> {
Vec3::new(exp(&self[0]),
exp(&self[1]),
exp(&self[2]))
}
#[inline(always)]
pure fn log_(&self) -> Vec3<T> {
Vec3::new(log_(&self[0]),
log_(&self[1]),
log_(&self[2]))
}
#[inline(always)]
pure fn exp2(&self) -> Vec3<T> {
Vec3::new(exp2(&self[0]),
exp2(&self[1]),
exp2(&self[2]))
}
#[inline(always)]
pure fn log2(&self) -> Vec3<T> {
Vec3::new(log2(&self[0]),
log2(&self[1]),
log2(&self[2]))
}
#[inline(always)]
pure fn sqrt(&self) -> Vec3<T> {
Vec3::new(sqrt(&self[0]),
sqrt(&self[1]),
sqrt(&self[2]))
}
#[inline(always)]
pure fn inv_sqrt(&self) -> Vec3<T> {
Vec3::new(inv_sqrt(&self[0]),
inv_sqrt(&self[1]),
inv_sqrt(&self[2]))
}
}
pub impl<T:Copy Exp> Vec4<T>: ExpVector<T> {
#[inline(always)]
pure fn pow_t(&self, n: T) -> Vec4<T> {
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<T>) -> Vec4<T> {
Vec4::new(pow(&self[0], &n[0]),
pow(&self[1], &n[1]),
pow(&self[2], &n[2]),
pow(&self[3], &n[3]))
}
}
pub impl<T:Copy Exp> Vec4<T>: Exp {
#[inline(always)]
pure fn pow(&self, n: &Vec4<T>) -> Vec4<T> {
self.pow_v(n)
}
#[inline(always)]
pure fn exp(&self) -> Vec4<T> {
Vec4::new(exp(&self[0]),
exp(&self[1]),
exp(&self[2]),
exp(&self[3]))
}
#[inline(always)]
pure fn log_(&self) -> Vec4<T> {
Vec4::new(log_(&self[0]),
log_(&self[1]),
log_(&self[2]),
log_(&self[3]))
}
#[inline(always)]
pure fn exp2(&self) -> Vec4<T> {
Vec4::new(exp2(&self[0]),
exp2(&self[1]),
exp2(&self[2]),
exp2(&self[3]))
}
#[inline(always)]
pure fn log2(&self) -> Vec4<T> {
Vec4::new(log2(&self[0]),
log2(&self[1]),
log2(&self[2]),
log2(&self[3]))
}
#[inline(always)]
pure fn sqrt(&self) -> Vec4<T> {
Vec4::new(sqrt(&self[0]),
sqrt(&self[1]),
sqrt(&self[2]),
sqrt(&self[3]))
}
#[inline(always)]
pure fn inv_sqrt(&self) -> Vec4<T> {
Vec4::new(inv_sqrt(&self[0]),
inv_sqrt(&self[1]),
inv_sqrt(&self[2]),
inv_sqrt(&self[3]))
}
}

View file

@ -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<T, BoolVec>: Vector<T> {
/**
* 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<T, BoolVec>: Vector<T> {
/**
* 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<bool> {
/**
* # 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<T:Copy Ord> Vec2<T>: OrdinalVector<T, Vec2<bool>> {
#[inline(always)]
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] < other[0],
self[1] < other[1])
}
#[inline(always)]
pure fn less_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] <= other[0],
self[1] <= other[1])
}
#[inline(always)]
pure fn greater_than(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] > other[0],
self[1] > other[1])
}
#[inline(always)]
pure fn greater_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] >= other[0],
self[1] >= other[1])
}
}
pub impl<T:Copy Eq> Vec2<T>: EquableVector<T, Vec2<bool>> {
#[inline(always)]
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] == other[0],
self[1] == other[1])
}
#[inline(always)]
pure fn not_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] != other[0],
self[1] != other[1])
}
}
pub impl Vec2<bool>: 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<bool> {
Vec2::new(!self[0], !self[1])
}
}
pub impl<T:Copy Ord> Vec3<T>: OrdinalVector<T, Vec3<bool>> {
#[inline(always)]
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] < other[0],
self[1] < other[1],
self[2] < other[2])
}
#[inline(always)]
pure fn less_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] <= other[0],
self[1] <= other[1],
self[2] <= other[2])
}
#[inline(always)]
pure fn greater_than(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] > other[0],
self[1] > other[1],
self[2] > other[2])
}
#[inline(always)]
pure fn greater_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] >= other[0],
self[1] >= other[1],
self[2] >= other[2])
}
}
pub impl<T:Copy Eq> Vec3<T>: EquableVector<T, Vec3<bool>> {
#[inline(always)]
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] == other[0],
self[1] == other[1],
self[2] == other[2])
}
#[inline(always)]
pure fn not_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] != other[0],
self[1] != other[1],
self[2] != other[2])
}
}
pub impl Vec3<bool>: 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<bool> {
Vec3::new(!self[0], !self[1], !self[2])
}
}
pub impl<T:Copy Ord> Vec4<T>: OrdinalVector<T, Vec4<bool>> {
#[inline(always)]
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
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<T>) -> Vec4<bool> {
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<T>) -> Vec4<bool> {
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<T>) -> Vec4<bool> {
Vec4::new(self[0] >= other[0],
self[1] >= other[1],
self[2] >= other[2],
self[3] >= other[3])
}
}
pub impl<T:Copy Eq> Vec4<T>: EquableVector<T, Vec4<bool>> {
#[inline(always)]
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
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<T>) -> Vec4<bool> {
Vec4::new(self[0] != other[0],
self[1] != other[1],
self[2] != other[2],
self[3] != other[3])
}
}
pub impl Vec4<bool>: 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<bool> {
Vec4::new(!self[0], !self[1], !self[2], !self[3])
}
}

View file

@ -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<T:Copy Float, A:Copy Angle<T>> Vec2<A>: Trig<Vec2<T>> {
// #[inline(always)]
// pure fn sin(&self) -> Vec2<T> {
// Vec2::new(sin(&self[0]),
// sin(&self[1]))
// }
// #[inline(always)]
// pure fn cos(&self) -> Vec2<T> {
// Vec2::new(cos(&self[0]),
// cos(&self[1]))
// }
// #[inline(always)]
// pure fn tan(&self) -> Vec2<T> {
// Vec2::new(tan(&self[0]),
// tan(&self[1]))
// }
// }
// pub impl<T:Copy Float, A:Copy Angle<T>> Vec3<A>: Trig<Vec3<T>> {
// #[inline(always)]
// pure fn sin(&self) -> Vec3<T> {
// Vec3::new(sin(&self[0]),
// sin(&self[1]),
// sin(&self[2]))
// }
// #[inline(always)]
// pure fn cos(&self) -> Vec3<T> {
// Vec3::new(cos(&self[0]),
// cos(&self[1]),
// cos(&self[2]))
// }
// #[inline(always)]
// pure fn tan(&self) -> Vec3<T> {
// Vec3::new(tan(&self[0]),
// tan(&self[1]),
// tan(&self[2]))
// }
// }
// pub impl<T:Copy Float, A:Copy Angle<T>> Vec4<A>: Trig<Vec4<T>> {
// #[inline(always)]
// pure fn sin(&self) -> Vec4<T> {
// Vec4::new(sin(&self[0]),
// sin(&self[1]),
// sin(&self[2]),
// sin(&self[3]))
// }
// #[inline(always)]
// pure fn cos(&self) -> Vec4<T> {
// Vec4::new(cos(&self[0]),
// cos(&self[1]),
// cos(&self[2]),
// cos(&self[3]))
// }
// #[inline(always)]
// pure fn tan(&self) -> Vec4<T> {
// 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<T:Copy Float> Vec2<T>: InvTrig<Vec2<Radians<T>>> {
// #[inline(always)]
// pure fn asin(&self) -> Vec2<Radians<T>> {
// Vec2::new(asin(&self[0]),
// asin(&self[1]))
// }
// #[inline(always)]
// pure fn acos(&self) -> Vec2<Radians<T>> {
// Vec2::new(acos(&self[0]),
// acos(&self[1]))
// }
// #[inline(always)]
// pure fn atan(&self) -> Vec2<Radians<T>> {
// Vec2::new(atan(&self[0]),
// atan(&self[1]))
// }
// }
// pub impl<T:Copy Float> Vec3<T>: InvTrig<Vec3<Radians<T>>> {
// #[inline(always)]
// pure fn asin(&self) -> Vec3<Radians<T>> {
// Vec3::new(asin(&self[0]),
// asin(&self[1]),
// asin(&self[2]))
// }
// #[inline(always)]
// pure fn acos(&self) -> Vec3<Radians<T>> {
// Vec3::new(acos(&self[0]),
// acos(&self[1]),
// acos(&self[2]))
// }
// #[inline(always)]
// pure fn atan(&self) -> Vec3<Radians<T>> {
// Vec3::new(atan(&self[0]),
// atan(&self[1]),
// atan(&self[2]))
// }
// }
// pub impl<T:Copy Float> Vec4<T>: InvTrig<Vec4<Radians<T>>> {
// #[inline(always)]
// pure fn asin(&self) -> Vec4<Radians<T>> {
// Vec4::new(asin(&self[0]),
// asin(&self[1]),
// asin(&self[2]),
// asin(&self[3]))
// }
// #[inline(always)]
// pure fn acos(&self) -> Vec4<Radians<T>> {
// Vec4::new(acos(&self[0]),
// acos(&self[1]),
// acos(&self[2]),
// acos(&self[3]))
// }
// #[inline(always)]
// pure fn atan(&self) -> Vec4<Radians<T>> {
// Vec4::new(atan(&self[0]),
// atan(&self[1]),
// atan(&self[2]),
// atan(&self[3]))
// }
// }
// Hyp
pub impl <T:Copy Hyp> Vec2<T>: Hyp {
#[inline(always)]
pure fn sinh(&self) -> Vec2<T> {
Vec2::new(sinh(&self[0]),
sinh(&self[1]))
}
#[inline(always)]
pure fn cosh(&self) -> Vec2<T> {
Vec2::new(cosh(&self[0]),
cosh(&self[1]))
}
#[inline(always)]
pure fn tanh(&self) -> Vec2<T> {
Vec2::new(tanh(&self[0]),
tanh(&self[1]))
}
}
pub impl <T:Copy Hyp> Vec3<T>: Hyp {
#[inline(always)]
pure fn sinh(&self) -> Vec3<T> {
Vec3::new(sinh(&self[0]),
sinh(&self[1]),
sinh(&self[2]))
}
#[inline(always)]
pure fn cosh(&self) -> Vec3<T> {
Vec3::new(cosh(&self[0]),
cosh(&self[1]),
cosh(&self[2]))
}
#[inline(always)]
pure fn tanh(&self) -> Vec3<T> {
Vec3::new(tanh(&self[0]),
tanh(&self[1]),
tanh(&self[2]))
}
}
pub impl <T:Copy Hyp> Vec4<T>: Hyp {
#[inline(always)]
pure fn sinh(&self) -> Vec4<T> {
Vec4::new(sinh(&self[0]),
sinh(&self[1]),
sinh(&self[2]),
sinh(&self[3]))
}
#[inline(always)]
pure fn cosh(&self) -> Vec4<T> {
Vec4::new(cosh(&self[0]),
cosh(&self[1]),
cosh(&self[2]),
cosh(&self[3]))
}
#[inline(always)]
pure fn tanh(&self) -> Vec4<T> {
Vec4::new(tanh(&self[0]),
tanh(&self[1]),
tanh(&self[2]),
tanh(&self[3]))
}
}

View file

@ -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).

View file

@ -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;
}
}

View file

@ -1,6 +1,5 @@
use core::cmp::Eq;
use std::cmp::FuzzyEq;
use numeric::types::angle::Angle;
use quat::Quat;

View file

@ -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<T:Copy Float> Mat2<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn from_angle<A:Angle<T>>(theta: A) -> Mat2<T> {
let cos_theta = cos(&theta.to_radians());
let sin_theta = sin(&theta.to_radians());
static pure fn from_angle(radians: T) -> Mat2<T> {
let cos_theta = cos(radians);
let sin_theta = sin(radians);
Mat2::new(cos_theta, -sin_theta,
sin_theta, cos_theta)

View file

@ -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<T:Copy Float> Mat3<T> {
*/
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_x<A:Angle<T>>(theta: A) -> Mat3<T> {
static pure fn from_angle_x(radians: T) -> Mat3<T> {
// 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<T:Copy Float> Mat3<T> {
*/
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_y<A:Angle<T>>(theta: A) -> Mat3<T> {
static pure fn from_angle_y(radians: T) -> Mat3<T> {
// 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<T:Copy Float> Mat3<T> {
*/
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_z<A:Angle<T>>(theta: A) -> Mat3<T> {
static pure fn from_angle_z(radians: T) -> Mat3<T> {
// 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<T:Copy Float> Mat3<T> {
*/
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_xyz<A:Angle<T>>(theta_x: A, theta_y: A, theta_z: A) -> Mat3<T> {
static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Mat3<T> {
// 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<T:Copy Float> Mat3<T> {
*/
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_axis<A:Angle<T>>(theta: A, axis: &Vec3<T>) -> Mat3<T> {
let c = cos(&theta.to_radians());
let s = sin(&theta.to_radians());
static pure fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Mat3<T> {
let c = cos(radians);
let s = sin(radians);
let _1_c = one::<T>() - c;
let x = axis.x;

View file

@ -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<T:Copy Float> Mat4<T>: Matrix<T, Vec4<T>> {
// 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;
}
}

View file

@ -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<T:Copy Float, A:Angle<T>>(fovy: A, aspectRatio: T, near: T, far: T) -> Mat4<T> {
let ymax = near * tan(&fovy.to_radians());
pub pure fn perspective<T:Copy Float>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
let ymax = near * tan(radians(fovy));
let xmax = ymax * aspectRatio;
frustum(-xmax, xmax, -ymax, ymax, near, far)

View file

@ -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<T:Copy Float> Quat<T> {
if dot > dot_threshold {
return self.nlerp(other, amount); // if quaternions are close together use `nlerp`
} else {
let robust_dot = dot.clamp(&-one::<T>(), &one()); // stay within the domain of acos()
let robust_dot = dot.clamp(-one::<T>(), 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<T:Copy Float> Quat<T> {
// TODO: Move to Rotation implementation. See: https://github.com/mozilla/rust/issues/4306
#[inline(always)]
static pure fn from_angle_x<A:Angle<T>>(theta: A) -> Quat<T> {
static pure fn from_angle_x(radians: T) -> Quat<T> {
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<A:Angle<T>>(theta: A) -> Quat<T> {
static pure fn from_angle_y(radians: T) -> Quat<T> {
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<A:Angle<T>>(theta: A) -> Quat<T> {
static pure fn from_angle_z(radians: T) -> Quat<T> {
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<A:Angle<T>>(x: A, y: A, z: A) -> Quat<T> {
static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Quat<T> {
// 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<A:Angle<T>>(theta: A, axis: &Vec3<T>) -> Quat<T> {
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<T>) -> Quat<T> {
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<T:Copy Float> Quat<T> {
Mat3::from_axes(x, y, z).to_quat()
}
pure fn get_angle_axis<A:Angle<T>>(&self) -> (A, Vec3<T>) {
pure fn get_angle_axis(&self) -> (T, Vec3<T>) {
fail(~"Not yet implemented.")
}

View file

@ -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<T> {
static pure fn from<R: Rotation<T>>(rot: R) -> self;
static pure fn from_angle_x<A:Angle<T>>(theta: A) -> self;
static pure fn from_angle_y<A:Angle<T>>(theta: A) -> self;
static pure fn from_angle_z<A:Angle<T>>(theta: A) -> self;
static pure fn from_angle_xyz<A:Angle<T>>(x: A, y: A, z: A) -> self;
static pure fn from_angle_axis<A:Angle<T>>(theta: A, axis: &Vec3<T>) -> 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<T>) -> self;
static pure fn from_axes(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> self;
static pure fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> self;

View file

@ -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<float> = 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]

View file

@ -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

View file

@ -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<T>: NumericVector<T> {
/**
* # 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<T>;
pure fn angle(&self, other: &self) -> T;
/**
* # Return value

View file

@ -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<T:Copy Float> Vec2<T>: EuclideanVector<T> {
}
#[inline(always)]
pure fn angle(&self, other: &Vec2<T>) -> Radians<T> {
atan2(&self.perp_dot(other), &self.dot(other))
pure fn angle(&self, other: &Vec2<T>) -> T {
atan2(self.perp_dot(other), self.dot(other))
}
#[inline(always)]

View file

@ -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<T:Copy Float> Vec3<T>: EuclideanVector<T> {
}
#[inline(always)]
pure fn angle(&self, other: &Vec3<T>) -> Radians<T> {
atan2(&self.cross(other).length(), &self.dot(other))
pure fn angle(&self, other: &Vec3<T>) -> T {
atan2(self.cross(other).length(), self.dot(other))
}
#[inline(always)]

View file

@ -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<T:Copy Float> Vec4<T>: EuclideanVector<T> {
}
#[inline(always)]
pure fn angle(&self, other: &Vec4<T>) -> Radians<T> {
acos(&(self.dot(other) / (self.length() * other.length())))
pure fn angle(&self, other: &Vec4<T>) -> T {
acos(self.dot(other) / (self.length() * other.length()))
}
#[inline(always)]