Merge pull request #165 from csherratt/master

Cleanup warnings in cgmath.
This commit is contained in:
Dzmitry Malyshau 2015-02-08 13:49:46 -05:00
commit bb5aa209f8
25 changed files with 108 additions and 103 deletions

View file

@ -17,4 +17,6 @@ authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>",
name = "cgmath" name = "cgmath"
[dependencies] [dependencies]
rustc-serialize="*" rustc-serialize="*"
rand_macros="*"
rand="*"

View file

@ -13,12 +13,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(test)]
extern crate rand;
extern crate test; extern crate test;
extern crate cgmath; extern crate cgmath;
use std::rand::{IsaacRng, Rng}; use rand::{IsaacRng, Rng};
use std::iter; use std::iter;
use test::Bencher; use test::Bencher;
use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad}; use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad};

View file

@ -13,13 +13,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(test)]
extern crate rand;
extern crate test; extern crate test;
extern crate cgmath; extern crate cgmath;
use std::rand::{IsaacRng, Rng}; use rand::{IsaacRng, Rng};
use test::Bencher; use test::Bencher;
use cgmath::*; use cgmath::*;

View file

@ -13,13 +13,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(test)]
extern crate rand;
extern crate test; extern crate test;
extern crate cgmath; extern crate cgmath;
use std::rand::{IsaacRng, Rng}; use rand::{IsaacRng, Rng};
use test::Bencher; use test::Bencher;
use cgmath::*; use cgmath::*;

View file

@ -13,13 +13,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(test)]
extern crate rand;
extern crate test; extern crate test;
extern crate cgmath; extern crate cgmath;
use std::rand::{IsaacRng, Rng}; use rand::{IsaacRng, Rng};
use test::Bencher; use test::Bencher;
use cgmath::*; use cgmath::*;

View file

@ -122,7 +122,7 @@ impl<S: BaseNum> Aabb<S, Vector2<S>, Point2<S>> for Aabb2<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Aabb2<S> { impl<S: BaseNum> fmt::Debug for Aabb2<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?} - {:?}]", self.min, self.max) write!(f, "[{:?} - {:?}]", self.min, self.max)
} }
@ -169,7 +169,7 @@ impl<S: BaseNum> Aabb<S, Vector3<S>, Point3<S>> for Aabb3<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Aabb3<S> { impl<S: BaseNum> fmt::Debug for Aabb3<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?} - {:?}]", self.min, self.max) write!(f, "[{:?} - {:?}]", self.min, self.max)
} }

View file

@ -24,10 +24,12 @@ use approx::ApproxEq;
use num::{BaseFloat, One, one, Zero, zero}; use num::{BaseFloat, One, one, Zero, zero};
/// An angle, in radians /// An angle, in radians
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable)]
pub struct Rad<S> { pub s: S } pub struct Rad<S> { pub s: S }
/// An angle, in degrees /// An angle, in degrees
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable)]
pub struct Deg<S> { pub s: S } pub struct Deg<S> { pub s: S }
/// Create a new angle, in radians /// Create a new angle, in radians

View file

@ -15,7 +15,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_type = "dylib"] #![crate_type = "dylib"]
#![feature(old_impl_check)] #![feature(old_impl_check, plugin, core, std_misc)]
//! Computer graphics-centric math. //! Computer graphics-centric math.
//! //!
@ -32,6 +32,9 @@
//! These are provided for convenience. //! These are provided for convenience.
extern crate "rustc-serialize" as rustc_serialize; extern crate "rustc-serialize" as rustc_serialize;
extern crate rand;
#[plugin]
extern crate rand_macros;
// Re-exports // Re-exports

View file

@ -30,15 +30,18 @@ use vector::{Vector, EuclideanVector};
use vector::{Vector2, Vector3, Vector4}; use vector::{Vector2, Vector3, Vector4};
/// A 2 x 2, column major matrix /// A 2 x 2, column major matrix
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> } pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> }
/// A 3 x 3, column major matrix /// A 3 x 3, column major matrix
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> } pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> }
/// A 4 x 4, column major matrix /// A 4 x 4, column major matrix
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> } pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
@ -1375,7 +1378,7 @@ impl<S: BaseFloat + 'static> ToQuaternion<S> for Matrix3<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Matrix2<S> { impl<S: BaseNum> fmt::Debug for Matrix2<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}], [{:?}, {:?}]]", write!(f, "[[{:?}, {:?}], [{:?}, {:?}]]",
self[0][0], self[0][1], self[0][0], self[0][1],
@ -1383,7 +1386,7 @@ impl<S: BaseNum> fmt::Show for Matrix2<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Matrix3<S> { impl<S: BaseNum> fmt::Debug for Matrix3<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}]]", write!(f, "[[{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}]]",
self[0][0], self[0][1], self[0][2], self[0][0], self[0][1], self[0][2],
@ -1392,7 +1395,7 @@ impl<S: BaseNum> fmt::Show for Matrix3<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Matrix4<S> { impl<S: BaseNum> fmt::Debug for Matrix4<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}]]", write!(f, "[[{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}]]",
self[0][0], self[0][1], self[0][2], self[0][3], self[0][0], self[0][1], self[0][2], self[0][3],

View file

@ -129,7 +129,7 @@ ApproxEq<S> for Plane<S> {
} }
} }
impl<S: BaseFloat> fmt::Show for Plane<S> { impl<S: BaseFloat> fmt::Debug for Plane<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}x + {:?}y + {:?}z - {:?} = 0", write!(f, "{:?}x + {:?}y + {:?}z - {:?} = 0",
self.n.x, self.n.y, self.n.z, self.d) self.n.x, self.n.y, self.n.z, self.d)

View file

@ -428,13 +428,13 @@ impl<S: BaseFloat> ApproxEq<S> for Point3<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Point2<S> { impl<S: BaseNum> fmt::Debug for Point2<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?}, {:?}]", self.x, self.y) write!(f, "[{:?}, {:?}]", self.x, self.y)
} }
} }
impl<S: BaseNum> fmt::Show for Point3<S> { impl<S: BaseNum> fmt::Debug for Point3<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z) write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z)
} }

View file

@ -30,7 +30,8 @@ use vector::{Vector3, Vector, EuclideanVector};
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
/// form. /// form.
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Quaternion<S> { pub s: S, pub v: Vector3<S> } pub struct Quaternion<S> { pub s: S, pub v: Vector3<S> }
/// Represents types which can be expressed as a quaternion. /// Represents types which can be expressed as a quaternion.
@ -368,7 +369,7 @@ impl<S: BaseFloat> Neg for Quaternion<S> {
} }
} }
impl<S: BaseFloat> fmt::Show for Quaternion<S> { impl<S: BaseFloat> fmt::Debug for Quaternion<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} + {:?}i + {:?}j + {:?}k", write!(f, "{:?} + {:?}i + {:?}j + {:?}k",
self.s, self.s,

View file

@ -151,7 +151,7 @@ impl<S: BaseFloat + 'static, R: Rotation3<S>> ToMatrix4<S> for Decomposed<S, Vec
impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<S,Vector3<S>,R> where S: 'static {} impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<S,Vector3<S>,R> where S: 'static {}
impl<S: BaseFloat, R: fmt::Show + Rotation3<S>> fmt::Show for Decomposed<S,Vector3<S>,R> { impl<S: BaseFloat, R: fmt::Debug + Rotation3<S>> fmt::Debug for Decomposed<S,Vector3<S>,R> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "(scale({:?}), rot({:?}), disp{:?})", write!(f, "(scale({:?}), rot({:?}), disp{:?})",
self.scale, self.rot, self.disp) self.scale, self.rot, self.disp)

View file

@ -178,7 +178,8 @@ pub trait Vector<S: BaseNum>: Array1<S> + Zero + One + Neg<Output=Self> {
// Utility macro for generating associated functions for the vectors // Utility macro for generating associated functions for the vectors
macro_rules! vec( macro_rules! vec(
($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr, $constructor:ident) => ( ($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr, $constructor:ident) => (
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable, Rand)] #[derive_Rand]
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
pub struct $Self<S> { $(pub $field: S),+ } pub struct $Self<S> { $(pub $field: S),+ }
impl<$S> $Self<$S> { impl<$S> $Self<$S> {
@ -557,19 +558,19 @@ impl<S: BaseFloat> EuclideanVector<S> for Vector4<S> {
} }
} }
impl<S: BaseNum> fmt::Show for Vector2<S> { impl<S: BaseNum> fmt::Debug for Vector2<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?}, {:?}]", self.x, self.y) write!(f, "[{:?}, {:?}]", self.x, self.y)
} }
} }
impl<S: BaseNum> fmt::Show for Vector3<S> { impl<S: BaseNum> fmt::Debug for Vector3<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z) write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z)
} }
} }
impl<S: BaseNum> fmt::Show for Vector4<S> { impl<S: BaseNum> fmt::Debug for Vector4<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?}, {:?}, {:?}, {:?}]", self.x, self.y, self.z, self.w) write!(f, "[{:?}, {:?}, {:?}, {:?}]", self.x, self.y, self.z, self.w)
} }

View file

@ -13,8 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::{Aabb, Aabb2, Aabb3}; use cgmath::{Aabb, Aabb2, Aabb3};
@ -24,46 +22,46 @@ use cgmath::{Ray, Intersect};
#[test] #[test]
fn test_aabb() { fn test_aabb() {
let aabb = Aabb2::new(Point2::new(-20i, 30i), Point2::new(10i, -10i)); let aabb = Aabb2::new(Point2::new(-20is, 30is), Point2::new(10is, -10is));
assert_eq!(aabb.min(), &Point2::new(-20i, -10i)); assert_eq!(aabb.min(), &Point2::new(-20is, -10is));
assert_eq!(aabb.max(), &Point2::new(10i, 30i)); assert_eq!(aabb.max(), &Point2::new(10is, 30is));
assert_eq!(aabb.dim(), Vector2::new(30i, 40i)); assert_eq!(aabb.dim(), Vector2::new(30is, 40is));
assert_eq!(aabb.volume(), 30i * 40i); assert_eq!(aabb.volume(), 30is * 40is);
assert_eq!(aabb.center(), Point2::new(-5i, 10i)); assert_eq!(aabb.center(), Point2::new(-5is, 10is));
assert!(aabb.contains(&Point2::new(0i, 0i))); assert!(aabb.contains(&Point2::new(0is, 0is)));
assert!(!aabb.contains(&Point2::new(-50i, -50i))); assert!(!aabb.contains(&Point2::new(-50is, -50is)));
assert!(!aabb.contains(&Point2::new(50i, 50i))); assert!(!aabb.contains(&Point2::new(50is, 50is)));
assert_eq!(aabb.grow(&Point2::new(0i, 0i)), aabb); assert_eq!(aabb.grow(&Point2::new(0is, 0is)), aabb);
assert_eq!(aabb.grow(&Point2::new(100i, 100i)), assert_eq!(aabb.grow(&Point2::new(100is, 100is)),
Aabb2::new(Point2::new(-20i, -10i), Point2::new(100i, 100i))); Aabb2::new(Point2::new(-20is, -10is), Point2::new(100is, 100is)));
assert_eq!(aabb.grow(&Point2::new(-100i, -100i)), assert_eq!(aabb.grow(&Point2::new(-100is, -100is)),
Aabb2::new(Point2::new(-100i, -100i), Point2::new(10i, 30i))); Aabb2::new(Point2::new(-100is, -100is), Point2::new(10is, 30is)));
let aabb = Aabb3::new(Point3::new(-20i, 30i, 5i), Point3::new(10i, -10i, -5i)); let aabb = Aabb3::new(Point3::new(-20is, 30is, 5is), Point3::new(10is, -10is, -5is));
assert_eq!(aabb.min(), &Point3::new(-20i, -10i, -5i)); assert_eq!(aabb.min(), &Point3::new(-20is, -10is, -5is));
assert_eq!(aabb.max(), &Point3::new(10i, 30i, 5i)); assert_eq!(aabb.max(), &Point3::new(10is, 30is, 5is));
assert_eq!(aabb.dim(), Vector3::new(30i, 40i, 10i)); assert_eq!(aabb.dim(), Vector3::new(30is, 40is, 10is));
assert_eq!(aabb.volume(), 30i * 40i * 10i); assert_eq!(aabb.volume(), 30is * 40is * 10is);
assert_eq!(aabb.center(), Point3::new(-5i, 10i, 0i)); assert_eq!(aabb.center(), Point3::new(-5is, 10is, 0is));
assert!(aabb.contains(&Point3::new(0i, 0i, 0i))); assert!(aabb.contains(&Point3::new(0is, 0is, 0is)));
assert!(!aabb.contains(&Point3::new(-100i, 0i, 0i))); assert!(!aabb.contains(&Point3::new(-100is, 0is, 0is)));
assert!(!aabb.contains(&Point3::new(100i, 0i, 0i))); assert!(!aabb.contains(&Point3::new(100is, 0is, 0is)));
assert!(aabb.contains(&Point3::new(9i, 29i, -1i))); assert!(aabb.contains(&Point3::new(9is, 29is, -1is)));
assert!(!aabb.contains(&Point3::new(10i, 30i, 5i))); assert!(!aabb.contains(&Point3::new(10is, 30is, 5is)));
assert!(aabb.contains(&Point3::new(-20i, -10i, -5i))); assert!(aabb.contains(&Point3::new(-20is, -10is, -5is)));
assert!(!aabb.contains(&Point3::new(-21i, -11i, -6i))); assert!(!aabb.contains(&Point3::new(-21is, -11is, -6is)));
assert_eq!(aabb.add_v(&Vector3::new(1i, 2i, 3i)), assert_eq!(aabb.add_v(&Vector3::new(1is, 2is, 3is)),
Aabb3::new(Point3::new(-19i, 32i, 8i), Point3::new(11i, -8i, -2i))); Aabb3::new(Point3::new(-19is, 32is, 8is), Point3::new(11is, -8is, -2is)));
assert_eq!(aabb.mul_s(2i), assert_eq!(aabb.mul_s(2is),
Aabb3::new(Point3::new(-40i, -20i, -10i), Point3::new(20i, 60i, 10i))); Aabb3::new(Point3::new(-40is, -20is, -10is), Point3::new(20is, 60is, 10is)));
assert_eq!(aabb.mul_v(&Vector3::new(1i, 2i, 3i)), assert_eq!(aabb.mul_v(&Vector3::new(1is, 2is, 3is)),
Aabb3::new(Point3::new(-20i, -20i, -15i), Point3::new(10i, 60i, 15i))); Aabb3::new(Point3::new(-20is, -20is, -15is), Point3::new(10is, 60is, 15is)));
} }
#[test] #[test]

View file

@ -13,8 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::{Angle, Rad, Deg, rad, deg}; use cgmath::{Angle, Rad, Deg, rad, deg};

View file

@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#[macro_use] #[macro_use]
extern crate cgmath; extern crate cgmath;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::*; use cgmath::*;

View file

@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(core)]
extern crate cgmath; extern crate cgmath;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::*; use cgmath::*;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::Point3; use cgmath::Point3;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::{ToMatrix4, ToMatrix3}; use cgmath::{ToMatrix4, ToMatrix3};

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::*; use cgmath::*;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
extern crate cgmath; extern crate cgmath;
use cgmath::*; use cgmath::*;

View file

@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![feature(core)]
#[macro_use] #[macro_use]
extern crate cgmath; extern crate cgmath;
@ -29,23 +31,23 @@ fn test_constructor() {
#[test] #[test]
fn test_from_value() { fn test_from_value() {
assert_eq!(Vector2::from_value(102i), Vector2::new(102i, 102i)); assert_eq!(Vector2::from_value(102is), Vector2::new(102is, 102is));
assert_eq!(Vector3::from_value(22i), Vector3::new(22i, 22i, 22i)); assert_eq!(Vector3::from_value(22is), Vector3::new(22is, 22is, 22is));
assert_eq!(Vector4::from_value(76.5f64), Vector4::new(76.5f64, 76.5f64, 76.5f64, 76.5f64)); assert_eq!(Vector4::from_value(76.5f64), Vector4::new(76.5f64, 76.5f64, 76.5f64, 76.5f64));
} }
#[test] #[test]
fn test_dot() { fn test_dot() {
assert_eq!(Vector2::new(1i, 2i).dot(&Vector2::new(3i, 4i)), 11i); assert_eq!(Vector2::new(1is, 2is).dot(&Vector2::new(3is, 4is)), 11is);
assert_eq!(Vector3::new(1i, 2i, 3i).dot(&Vector3::new(4i, 5i, 6i)), 32i); assert_eq!(Vector3::new(1is, 2is, 3is).dot(&Vector3::new(4is, 5is, 6is)), 32is);
assert_eq!(Vector4::new(1i, 2i, 3i, 4i).dot(&Vector4::new(5i, 6i, 7i, 8i)), 70i); assert_eq!(Vector4::new(1is, 2is, 3is, 4is).dot(&Vector4::new(5is, 6is, 7is, 8is)), 70is);
} }
#[test] #[test]
fn test_comp_add() { fn test_comp_add() {
assert_eq!(Vector2::new(1i, 2i).comp_add(), 3i); assert_eq!(Vector2::new(1is, 2is).comp_add(), 3is);
assert_eq!(Vector3::new(1i, 2i, 3i).comp_add(), 6i); assert_eq!(Vector3::new(1is, 2is, 3is).comp_add(), 6is);
assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_add(), 10i); assert_eq!(Vector4::new(1is, 2is, 3is, 4is).comp_add(), 10is);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_add(), 7.0f64); assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_add(), 7.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_add(), 15.0f64); assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_add(), 15.0f64);
@ -54,9 +56,9 @@ fn test_comp_add() {
#[test] #[test]
fn test_comp_mul() { fn test_comp_mul() {
assert_eq!(Vector2::new(1i, 2i).comp_mul(), 2i); assert_eq!(Vector2::new(1is, 2is).comp_mul(), 2is);
assert_eq!(Vector3::new(1i, 2i, 3i).comp_mul(), 6i); assert_eq!(Vector3::new(1is, 2is, 3is).comp_mul(), 6is);
assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_mul(), 24i); assert_eq!(Vector4::new(1is, 2is, 3is, 4is).comp_mul(), 24is);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_mul(), 12.0f64); assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_mul(), 12.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_mul(), 120.0f64); assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_mul(), 120.0f64);
@ -65,9 +67,9 @@ fn test_comp_mul() {
#[test] #[test]
fn test_comp_min() { fn test_comp_min() {
assert_eq!(Vector2::new(1i, 2i).comp_min(), 1i); assert_eq!(Vector2::new(1is, 2is).comp_min(), 1is);
assert_eq!(Vector3::new(1i, 2i, 3i).comp_min(), 1i); assert_eq!(Vector3::new(1is, 2is, 3is).comp_min(), 1is);
assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_min(), 1i); assert_eq!(Vector4::new(1is, 2is, 3is, 4is).comp_min(), 1is);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_min(), 3.0f64); assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_min(), 3.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_min(), 4.0f64); assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_min(), 4.0f64);
@ -76,9 +78,9 @@ fn test_comp_min() {
#[test] #[test]
fn test_comp_max() { fn test_comp_max() {
assert_eq!(Vector2::new(1i, 2i).comp_max(), 2i); assert_eq!(Vector2::new(1is, 2is).comp_max(), 2is);
assert_eq!(Vector3::new(1i, 2i, 3i).comp_max(), 3i); assert_eq!(Vector3::new(1is, 2is, 3is).comp_max(), 3is);
assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_max(), 4i); assert_eq!(Vector4::new(1is, 2is, 3is, 4is).comp_max(), 4is);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_max(), 4.0f64); assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_max(), 4.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_max(), 6.0f64); assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_max(), 6.0f64);
@ -87,9 +89,9 @@ fn test_comp_max() {
#[test] #[test]
fn test_cross() { fn test_cross() {
let a = Vector3::new(1i, 2i, 3i); let a = Vector3::new(1is, 2is, 3is);
let b = Vector3::new(4i, 5i, 6i); let b = Vector3::new(4is, 5is, 6is);
let r = Vector3::new(-3i, 6i, -3i); let r = Vector3::new(-3is, 6is, -3is);
assert_eq!(a.cross(&b), r); assert_eq!(a.cross(&b), r);
let mut a = a; let mut a = a;
@ -110,8 +112,8 @@ mod test_length {
#[test] #[test]
fn test_vector2(){ fn test_vector2(){
let (a, a_res) = (Vector2::new(3.0f64, 4.0f64), 5.0f64); // (3i, 4i, 5i) Pythagorean triple let (a, a_res) = (Vector2::new(3.0f64, 4.0f64), 5.0f64); // (3is, 4is, 5is) Pythagorean triple
let (b, b_res) = (Vector2::new(5.0f64, 12.0f64), 13.0f64); // (5i, 12i, 13i) Pythagorean triple let (b, b_res) = (Vector2::new(5.0f64, 12.0f64), 13.0f64); // (5is, 12is, 13is) Pythagorean triple
assert_eq!(a.length2(), a_res * a_res); assert_eq!(a.length2(), a_res * a_res);
assert_eq!(b.length2(), b_res * b_res); assert_eq!(b.length2(), b_res * b_res);
@ -122,8 +124,8 @@ mod test_length {
#[test] #[test]
fn test_vector3(){ fn test_vector3(){
let (a, a_res) = (Vector3::new(2.0f64, 3.0f64, 6.0f64), 7.0f64); // (2i, 3i, 6i, 7i) Pythagorean quadruple let (a, a_res) = (Vector3::new(2.0f64, 3.0f64, 6.0f64), 7.0f64); // (2is, 3is, 6is, 7is) Pythagorean quadruple
let (b, b_res) = (Vector3::new(1.0f64, 4.0f64, 8.0f64), 9.0f64); // (1i, 4i, 8i, 9i) Pythagorean quadruple let (b, b_res) = (Vector3::new(1.0f64, 4.0f64, 8.0f64), 9.0f64); // (1is, 4is, 8is, 9is) Pythagorean quadruple
assert_eq!(a.length2(), a_res * a_res); assert_eq!(a.length2(), a_res * a_res);
assert_eq!(b.length2(), b_res * b_res); assert_eq!(b.length2(), b_res * b_res);
@ -134,8 +136,8 @@ mod test_length {
#[test] #[test]
fn test_vector4(){ fn test_vector4(){
let (a, a_res) = (Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64), 11.0f64); // (1i, 2i, 4i, 10i, 11i) Pythagorean quintuple let (a, a_res) = (Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64), 11.0f64); // (1is, 2is, 4is, 10is, 11is) Pythagorean quintuple
let (b, b_res) = (Vector4::new(1.0f64, 2.0f64, 8.0f64, 10.0f64), 13.0f64); // (1i, 2i, 8i, 10i, 13i) Pythagorean quintuple let (b, b_res) = (Vector4::new(1.0f64, 2.0f64, 8.0f64, 10.0f64), 13.0f64); // (1is, 2is, 8is, 10is, 13is) Pythagorean quintuple
assert_eq!(a.length2(), a_res * a_res); assert_eq!(a.length2(), a_res * a_res);
assert_eq!(b.length2(), b_res * b_res); assert_eq!(b.length2(), b_res * b_res);