From 3862e867ba1db993542b073e8c5387cb5f39003c Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 13 Oct 2013 06:56:05 +1100 Subject: [PATCH] Update to latest Rust --- src/cgmath/angle.rs | 12 ++++++------ src/cgmath/lib.rs | 3 +++ src/cgmath/matrix.rs | 2 +- src/cgmath/projection.rs | 34 +++++++++++++++++----------------- src/cgmath/quaternion.rs | 18 +++++++++--------- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/cgmath/angle.rs b/src/cgmath/angle.rs index ad71f15..7b80e96 100644 --- a/src/cgmath/angle.rs +++ b/src/cgmath/angle.rs @@ -113,15 +113,15 @@ pub trait Angle /// Returns the interior bisector of the two angles #[inline] 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; - #[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2)) } - #[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3)) } - #[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4)) } - #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6)) } + #[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).unwrap()) } + #[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).unwrap()) } } #[inline] pub fn bisect>(a: A, b: A) -> A { a.bisect(b) } @@ -163,7 +163,7 @@ impl Angle for Rad { impl Angle for Deg { #[inline] fn from>(theta: A) -> Deg { theta.to_deg() } - #[inline] fn full_turn() -> Deg { deg(cast(360)) } + #[inline] fn full_turn() -> Deg { deg(cast(360).unwrap()) } } #[inline] pub fn sin>(theta: A) -> S { theta.to_rad().s.sin() } diff --git a/src/cgmath/lib.rs b/src/cgmath/lib.rs index ea340b4..7842085 100644 --- a/src/cgmath/lib.rs +++ b/src/cgmath/lib.rs @@ -22,6 +22,9 @@ #[license = "ASL2"]; #[crate_type = "lib"]; +#[feature(globs)]; +#[feature(macro_rules)]; + pub mod array; pub mod matrix; pub mod quaternion; diff --git a/src/cgmath/matrix.rs b/src/cgmath/matrix.rs index e00662d..9322f32 100644 --- a/src/cgmath/matrix.rs +++ b/src/cgmath/matrix.rs @@ -628,7 +628,7 @@ impl ToQuat for Mat3 { fn to_quat(&self) -> Quat { // http://www.cs.ucr.edu/~vbz/resources/Quatut.pdf let trace = self.trace(); - let half: S = cast(0.5); + let half: S = cast(0.5).unwrap(); match () { () if trace >= zero::() => { let s = sqrt(one::() + trace); diff --git a/src/cgmath/projection.rs b/src/cgmath/projection.rs index 0ede2a1..98f931f 100644 --- a/src/cgmath/projection.rs +++ b/src/cgmath/projection.rs @@ -78,7 +78,7 @@ pub struct PerspectiveFov { impl> PerspectiveFov { pub fn to_perspective(&self) -> Perspective { - let angle = self.fovy.div_s(cast(2)); + let angle = self.fovy.div_s(cast(2).unwrap()); let ymax = self.near * tan(angle); let xmax = ymax * self.aspect; @@ -104,15 +104,15 @@ impl> ToMat4 for PerspectiveFov { fn to_mat4(&self) -> Mat4 { 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 < 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.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 > self.near, "The far plane cannot be closer than the near plane, found: far: %?, near: %?", self.far, self.near); + 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.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.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); - let f = cot(self.fovy.div_s(cast(2))); - let two: S = cast(2); + let f = cot(self.fovy.div_s(cast(2).unwrap())); + let two: S = cast(2).unwrap(); let c0r0 = f / self.aspect; let c0r1 = zero(); @@ -158,11 +158,11 @@ impl Projection for Perspective { impl ToMat4 for Perspective { fn to_mat4(&self) -> Mat4 { - 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.near > self.far, "`near` cannot be greater than `far`, found: near: %? far: %?", self.near, self.far); + 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.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 c0r1 = zero(); @@ -214,11 +214,11 @@ impl Projection for Ortho { impl ToMat4 for Ortho { fn to_mat4(&self) -> Mat4 { - 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.near > self.far, "`near` cannot be greater than `far`, found: near: %? far: %?", self.near, self.far); + 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.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 c0r1 = zero(); diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 29cc10f..4d99872 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -53,19 +53,19 @@ impl Quat { /// Create a matrix from a rotation around the `x` axis (pitch). #[inline] pub fn from_angle_x>(theta: A) -> Quat { - 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). #[inline] pub fn from_angle_y>(theta: A) -> Quat { - 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). #[inline] pub fn from_angle_z>(theta: A) -> Quat { - 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. @@ -77,9 +77,9 @@ impl Quat { /// - `z`: the angular rotation around the `z` axis (roll). pub fn from_euler>(x: A, y: A, z: A) -> Quat { // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion - let (sx2, cx2) = sin_cos(x.mul_s(cast(0.5))); - let (sy2, cy2) = sin_cos(y.mul_s(cast(0.5))); - let (sz2, cz2) = sin_cos(z.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).unwrap())); + let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5).unwrap())); Quat::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2, sz2 * cx2 * cy2 - cz2 * sx2 * sy2, @@ -90,7 +90,7 @@ impl Quat { /// Create a quaternion from a rotation around an arbitrary axis #[inline] pub fn from_axis_angle>(axis: &Vec3, angle: A) -> Quat { - let half = angle.mul_s(cast(0.5)); + let half = angle.mul_s(cast(0.5).unwrap()); Quat::from_sv(cos(half.clone()), axis.mul_s(sin(half))) } @@ -123,7 +123,7 @@ impl Quat { #[inline] pub fn mul_v(&self, vec: &Vec3) -> Vec3 { 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` @@ -243,7 +243,7 @@ impl Quat { use std::num::cast; 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 dot > dot_threshold {