From 7eb8bc50c9925e129a32ae49e1bad9b164366f10 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 17 Sep 2013 18:43:20 +1000 Subject: [PATCH] Remove util module --- src/cgmath/lib.rs | 2 -- src/cgmath/projection.rs | 41 ++++++++++++++++++++-------------------- src/cgmath/quaternion.rs | 5 ++--- src/cgmath/util.rs | 22 --------------------- 4 files changed, 22 insertions(+), 48 deletions(-) delete mode 100644 src/cgmath/util.rs diff --git a/src/cgmath/lib.rs b/src/cgmath/lib.rs index 037bbf5..ea340b4 100644 --- a/src/cgmath/lib.rs +++ b/src/cgmath/lib.rs @@ -41,5 +41,3 @@ pub mod frustum; pub mod intersect; pub mod obb; pub mod sphere; - -pub mod util; diff --git a/src/cgmath/projection.rs b/src/cgmath/projection.rs index eafab5f..bb8d009 100644 --- a/src/cgmath/projection.rs +++ b/src/cgmath/projection.rs @@ -13,18 +13,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::num::{zero, one}; +use std::num::{zero, one, cast}; use angle::{Angle, tan, cot}; use frustum::Frustum; use matrix::{Mat4, ToMat4}; -use util::two; /// Create a perspective projection matrix. /// /// This is the equivalent to the [gluPerspective] /// (http://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml) function. -pub fn perspective>(fovy: A, aspect: S, near: S, far: S) -> Mat4 { +pub fn perspective>(fovy: A, aspect: S, near: S, far: S) -> Mat4 { PerspectiveFov { fovy: fovy, aspect: aspect, @@ -37,7 +36,7 @@ pub fn perspective>(fovy: A, aspect: S, near: S, f /// /// This is the equivalent of the now deprecated [glFrustrum] /// (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function. -pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { +pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { Perspective { left: left, right: right, @@ -52,7 +51,7 @@ pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, /// /// This is the equivalent of the now deprecated [glOrtho] /// (http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) function. -pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { +pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { Ortho { left: left, right: right, @@ -76,9 +75,9 @@ pub struct PerspectiveFov { far: S, } -impl> PerspectiveFov { +impl> PerspectiveFov { pub fn to_perspective(&self) -> Perspective { - let angle = self.fovy.div_s(two::()); + let angle = self.fovy.div_s(cast(2)); let ymax = self.near * tan(angle); let xmax = ymax * self.aspect; @@ -93,13 +92,13 @@ impl> PerspectiveFov { } } -impl> Projection for PerspectiveFov { +impl> Projection for PerspectiveFov { fn to_frustum(&self) -> Frustum { self.to_perspective().to_frustum() } } -impl> ToMat4 for PerspectiveFov { +impl> ToMat4 for PerspectiveFov { fn to_mat4(&self) -> Mat4 { let half_turn: A = Angle::turn_div_2(); @@ -110,7 +109,7 @@ impl> ToMat4 for PerspectiveFov { 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(two::())); + let f = cot(self.fovy.div_s(cast(2))); let c0r0 = f / self.aspect; let c0r1 = zero(); @@ -129,7 +128,7 @@ impl> ToMat4 for PerspectiveFov { let c3r0 = zero(); let c3r1 = zero(); - let c3r2 = (two::() * self.far * self.near) / (self.near - self.far); + let c3r2 = (cast::(2) * self.far * self.near) / (self.near - self.far); let c3r3 = zero(); Mat4::new(c0r0, c0r1, c0r2, c0r3, @@ -147,25 +146,25 @@ pub struct Perspective { near: S, far: S, } -impl Projection for Perspective { +impl Projection for Perspective { fn to_frustum(&self) -> Frustum { fail!("Not yet implemented!"); } } -impl ToMat4 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); - let c0r0 = (two::() * self.near) / (self.right - self.left); + let c0r0 = (cast::(2) * self.near) / (self.right - self.left); let c0r1 = zero(); let c0r2 = zero(); let c0r3 = zero(); let c1r0 = zero(); - let c1r1 = (two::() * self.near) / (self.top - self.bottom); + let c1r1 = (cast::(2) * self.near) / (self.top - self.bottom); let c1r2 = zero(); let c1r3 = zero(); @@ -176,7 +175,7 @@ impl ToMat4 for Perspective { let c3r0 = zero(); let c3r1 = zero(); - let c3r2 = -(two::() * self.far * self.near) / (self.far - self.near); + let c3r2 = -(cast::(2) * self.far * self.near) / (self.far - self.near); let c3r3 = zero(); Mat4::new(c0r0, c0r1, c0r2, c0r3, @@ -194,31 +193,31 @@ pub struct Ortho { near: S, far: S, } -impl Projection for Ortho { +impl Projection for Ortho { fn to_frustum(&self) -> Frustum { fail!("Not yet implemented!"); } } -impl ToMat4 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); - let c0r0 = two::() / (self.right - self.left); + let c0r0 = cast::(2) / (self.right - self.left); let c0r1 = zero(); let c0r2 = zero(); let c0r3 = zero(); let c1r0 = zero(); - let c1r1 = two::() / (self.top - self.bottom); + let c1r1 = cast::(2) / (self.top - self.bottom); let c1r2 = zero(); let c1r3 = zero(); let c2r0 = zero(); let c2r1 = zero(); - let c2r2 = -two::() / (self.far - self.near); + let c2r2 = -cast::(2) / (self.far - self.near); let c2r3 = -one::(); let c3r0 = -(self.right + self.left) / (self.right - self.left); diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 60096c3..a5e95ad 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -13,13 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::num::{zero, one, sqrt}; +use std::num::{zero, one, cast, sqrt}; use angle::{Angle, Rad, acos, cos, sin}; use array::{Array, build}; use matrix::{Mat3, ToMat3}; use vector::{Vec3, Vector, EuclideanVector}; -use util::two; /// A quaternion in scalar/vector form #[deriving(Clone, Eq)] @@ -79,7 +78,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(two::()).add_v(vec) + self.v.cross(&tmp).mul_s(cast(2)).add_v(vec) } /// The sum of this quaternion and `other` diff --git a/src/cgmath/util.rs b/src/cgmath/util.rs deleted file mode 100644 index 4925bfe..0000000 --- a/src/cgmath/util.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2013 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::num::one; - -// These functions are horrific! We really need better from-int support -// in std::num. - -#[inline] -pub fn two() -> T { one::() + one::() }