Update to latest Rust

This commit is contained in:
Brendan Zabarauskas 2013-10-13 06:56:05 +11:00
parent 2ac675ae10
commit 3862e867ba
5 changed files with 36 additions and 33 deletions

View file

@ -113,15 +113,15 @@ pub trait Angle
/// Returns the interior bisector of the two angles /// Returns the interior bisector of the two angles
#[inline] #[inline]
fn bisect(&self, other: Self) -> Self { fn bisect(&self, other: Self) -> Self {
self.add_a(self.sub_a(other).mul_s(cast(0.5))).normalize() self.add_a(self.sub_a(other).mul_s(cast(0.5).unwrap())).normalize()
} }
fn full_turn() -> Self; fn full_turn() -> Self;
#[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2)) } #[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2).unwrap()) }
#[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3)) } #[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3).unwrap()) }
#[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4)) } #[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4).unwrap()) }
#[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6)) } #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6).unwrap()) }
} }
#[inline] pub fn bisect<S: Float, A: Angle<S>>(a: A, b: A) -> A { a.bisect(b) } #[inline] pub fn bisect<S: Float, A: Angle<S>>(a: A, b: A) -> A { a.bisect(b) }
@ -163,7 +163,7 @@ impl<S: Float> Angle<S> for Rad<S> {
impl<S: Float> Angle<S> for Deg<S> { impl<S: Float> Angle<S> for Deg<S> {
#[inline] fn from<A: Angle<S>>(theta: A) -> Deg<S> { theta.to_deg() } #[inline] fn from<A: Angle<S>>(theta: A) -> Deg<S> { theta.to_deg() }
#[inline] fn full_turn() -> Deg<S> { deg(cast(360)) } #[inline] fn full_turn() -> Deg<S> { deg(cast(360).unwrap()) }
} }
#[inline] pub fn sin<S: Float, A: Angle<S>>(theta: A) -> S { theta.to_rad().s.sin() } #[inline] pub fn sin<S: Float, A: Angle<S>>(theta: A) -> S { theta.to_rad().s.sin() }

View file

@ -22,6 +22,9 @@
#[license = "ASL2"]; #[license = "ASL2"];
#[crate_type = "lib"]; #[crate_type = "lib"];
#[feature(globs)];
#[feature(macro_rules)];
pub mod array; pub mod array;
pub mod matrix; pub mod matrix;
pub mod quaternion; pub mod quaternion;

View file

@ -628,7 +628,7 @@ impl<S:Float> ToQuat<S> for Mat3<S> {
fn to_quat(&self) -> Quat<S> { fn to_quat(&self) -> Quat<S> {
// http://www.cs.ucr.edu/~vbz/resources/Quatut.pdf // http://www.cs.ucr.edu/~vbz/resources/Quatut.pdf
let trace = self.trace(); let trace = self.trace();
let half: S = cast(0.5); let half: S = cast(0.5).unwrap();
match () { match () {
() if trace >= zero::<S>() => { () if trace >= zero::<S>() => {
let s = sqrt(one::<S>() + trace); let s = sqrt(one::<S>() + trace);

View file

@ -78,7 +78,7 @@ pub struct PerspectiveFov<S, A> {
impl<S: Float, A: Angle<S>> PerspectiveFov<S, A> { impl<S: Float, A: Angle<S>> PerspectiveFov<S, A> {
pub fn to_perspective(&self) -> Perspective<S> { pub fn to_perspective(&self) -> Perspective<S> {
let angle = self.fovy.div_s(cast(2)); let angle = self.fovy.div_s(cast(2).unwrap());
let ymax = self.near * tan(angle); let ymax = self.near * tan(angle);
let xmax = ymax * self.aspect; let xmax = ymax * self.aspect;
@ -104,15 +104,15 @@ impl<S: Float, A: Angle<S>> ToMat4<S> for PerspectiveFov<S, A> {
fn to_mat4(&self) -> Mat4<S> { fn to_mat4(&self) -> Mat4<S> {
let half_turn: A = Angle::turn_div_2(); let half_turn: A = Angle::turn_div_2();
assert!(self.fovy > zero(), "The vertical field of view cannot be below zero, found: %?", self.fovy); assert!(self.fovy > zero(), "The vertical field of view cannot be below zero, found: {:?}", self.fovy);
assert!(self.fovy < half_turn, "The vertical field of view cannot be greater than a half turn, found: %?", self.fovy); assert!(self.fovy < half_turn, "The vertical field of view cannot be greater than a half turn, found: {:?}", self.fovy);
assert!(self.aspect > zero(), "The aspect ratio cannot be below zero, found: %?", self.aspect); assert!(self.aspect > zero(), "The aspect ratio cannot be below zero, found: {:?}", self.aspect);
assert!(self.near > zero(), "The near plane distance cannot be below zero, found: %?", self.near); assert!(self.near > zero(), "The near plane distance cannot be below zero, found: {:?}", self.near);
assert!(self.far > zero(), "The far plane distance cannot be below zero, found: %?", self.far); assert!(self.far > zero(), "The far plane distance cannot be below zero, found: {:?}", self.far);
assert!(self.far > self.near, "The far plane cannot be closer than the near plane, found: far: %?, near: %?", self.far, self.near); assert!(self.far > self.near, "The far plane cannot be closer than the near plane, found: far: {:?}, near: {:?}", self.far, self.near);
let f = cot(self.fovy.div_s(cast(2))); let f = cot(self.fovy.div_s(cast(2).unwrap()));
let two: S = cast(2); let two: S = cast(2).unwrap();
let c0r0 = f / self.aspect; let c0r0 = f / self.aspect;
let c0r1 = zero(); let c0r1 = zero();
@ -158,11 +158,11 @@ impl<S: Float> Projection<S> for Perspective<S> {
impl<S: Float> ToMat4<S> for Perspective<S> { impl<S: Float> ToMat4<S> for Perspective<S> {
fn to_mat4(&self) -> Mat4<S> { fn to_mat4(&self) -> Mat4<S> {
assert!(self.left > self.right, "`left` cannot be greater than `right`, found: left: %? right: %?", self.left, self.right); assert!(self.left > self.right, "`left` cannot be greater than `right`, found: left: {:?} right: {:?}", self.left, self.right);
assert!(self.bottom > self.top, "`bottom` cannot be greater than `top`, found: bottom: %? top: %?", self.bottom, self.top); assert!(self.bottom > self.top, "`bottom` cannot be greater than `top`, found: bottom: {:?} top: {:?}", self.bottom, self.top);
assert!(self.near > self.far, "`near` cannot be greater than `far`, found: near: %? far: %?", self.near, self.far); assert!(self.near > self.far, "`near` cannot be greater than `far`, found: near: {:?} far: {:?}", self.near, self.far);
let two: S = cast(2); let two: S = cast(2).unwrap();
let c0r0 = (two * self.near) / (self.right - self.left); let c0r0 = (two * self.near) / (self.right - self.left);
let c0r1 = zero(); let c0r1 = zero();
@ -214,11 +214,11 @@ impl<S: Float> Projection<S> for Ortho<S> {
impl<S: Float> ToMat4<S> for Ortho<S> { impl<S: Float> ToMat4<S> for Ortho<S> {
fn to_mat4(&self) -> Mat4<S> { fn to_mat4(&self) -> Mat4<S> {
assert!(self.left > self.right, "`left` cannot be greater than `right`, found: left: %? right: %?", self.left, self.right); assert!(self.left > self.right, "`left` cannot be greater than `right`, found: left: {:?} right: {:?}", self.left, self.right);
assert!(self.bottom > self.top, "`bottom` cannot be greater than `top`, found: bottom: %? top: %?", self.bottom, self.top); assert!(self.bottom > self.top, "`bottom` cannot be greater than `top`, found: bottom: {:?} top: {:?}", self.bottom, self.top);
assert!(self.near > self.far, "`near` cannot be greater than `far`, found: near: %? far: %?", self.near, self.far); assert!(self.near > self.far, "`near` cannot be greater than `far`, found: near: {:?} far: {:?}", self.near, self.far);
let two: S = cast(2); let two: S = cast(2).unwrap();
let c0r0 = two / (self.right - self.left); let c0r0 = two / (self.right - self.left);
let c0r1 = zero(); let c0r1 = zero();

View file

@ -53,19 +53,19 @@ impl<S: Float> Quat<S> {
/// Create a matrix from a rotation around the `x` axis (pitch). /// Create a matrix from a rotation around the `x` axis (pitch).
#[inline] #[inline]
pub fn from_angle_x<A: Angle<S>>(theta: A) -> Quat<S> { pub fn from_angle_x<A: Angle<S>>(theta: A) -> Quat<S> {
Quat::new(cos(theta.mul_s(cast(0.5))), sin(theta), zero(), zero()) Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), sin(theta), zero(), zero())
} }
/// Create a matrix from a rotation around the `y` axis (yaw). /// Create a matrix from a rotation around the `y` axis (yaw).
#[inline] #[inline]
pub fn from_angle_y<A: Angle<S>>(theta: A) -> Quat<S> { pub fn from_angle_y<A: Angle<S>>(theta: A) -> Quat<S> {
Quat::new(cos(theta.mul_s(cast(0.5))), zero(), sin(theta), zero()) Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), zero(), sin(theta), zero())
} }
/// Create a matrix from a rotation around the `z` axis (roll). /// Create a matrix from a rotation around the `z` axis (roll).
#[inline] #[inline]
pub fn from_angle_z<A: Angle<S>>(theta: A) -> Quat<S> { pub fn from_angle_z<A: Angle<S>>(theta: A) -> Quat<S> {
Quat::new(cos(theta.mul_s(cast(0.5))), zero(), zero(), sin(theta)) Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), zero(), zero(), sin(theta))
} }
/// Create a quaternion from a set of euler angles. /// Create a quaternion from a set of euler angles.
@ -77,9 +77,9 @@ impl<S: Float> Quat<S> {
/// - `z`: the angular rotation around the `z` axis (roll). /// - `z`: the angular rotation around the `z` axis (roll).
pub fn from_euler<A: Angle<S>>(x: A, y: A, z: A) -> Quat<S> { pub fn from_euler<A: Angle<S>>(x: A, y: A, z: A) -> Quat<S> {
// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion
let (sx2, cx2) = sin_cos(x.mul_s(cast(0.5))); let (sx2, cx2) = sin_cos(x.mul_s(cast(0.5).unwrap()));
let (sy2, cy2) = sin_cos(y.mul_s(cast(0.5))); let (sy2, cy2) = sin_cos(y.mul_s(cast(0.5).unwrap()));
let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5))); let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5).unwrap()));
Quat::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2, Quat::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2,
sz2 * cx2 * cy2 - cz2 * sx2 * sy2, sz2 * cx2 * cy2 - cz2 * sx2 * sy2,
@ -90,7 +90,7 @@ impl<S: Float> Quat<S> {
/// Create a quaternion from a rotation around an arbitrary axis /// Create a quaternion from a rotation around an arbitrary axis
#[inline] #[inline]
pub fn from_axis_angle<A: Angle<S>>(axis: &Vec3<S>, angle: A) -> Quat<S> { pub fn from_axis_angle<A: Angle<S>>(axis: &Vec3<S>, angle: A) -> Quat<S> {
let half = angle.mul_s(cast(0.5)); let half = angle.mul_s(cast(0.5).unwrap());
Quat::from_sv(cos(half.clone()), Quat::from_sv(cos(half.clone()),
axis.mul_s(sin(half))) axis.mul_s(sin(half)))
} }
@ -123,7 +123,7 @@ impl<S: Float> Quat<S> {
#[inline] #[inline]
pub fn mul_v(&self, vec: &Vec3<S>) -> Vec3<S> { pub fn mul_v(&self, vec: &Vec3<S>) -> Vec3<S> {
let tmp = self.v.cross(vec).add_v(&vec.mul_s(self.s.clone())); let tmp = self.v.cross(vec).add_v(&vec.mul_s(self.s.clone()));
self.v.cross(&tmp).mul_s(cast(2)).add_v(vec) self.v.cross(&tmp).mul_s(cast(2).unwrap()).add_v(vec)
} }
/// The sum of this quaternion and `other` /// The sum of this quaternion and `other`
@ -243,7 +243,7 @@ impl<S: Float> Quat<S> {
use std::num::cast; use std::num::cast;
let dot = self.dot(other); let dot = self.dot(other);
let dot_threshold = cast(0.9995); let dot_threshold = cast(0.9995).unwrap();
// if quaternions are close together use `nlerp` // if quaternions are close together use `nlerp`
if dot > dot_threshold { if dot > dot_threshold {