From 22c2fe4755c74cb0c674267cc1af8945a51446a3 Mon Sep 17 00:00:00 2001 From: Connorcpu Date: Sat, 3 Jan 2015 13:29:26 -0800 Subject: [PATCH] Updated to rust nightly --- benches/common/macros.rs | 2 +- benches/construction.rs | 7 +++--- src/aabb.rs | 6 ++--- src/angle.rs | 5 ++-- src/approx.rs | 2 +- src/array.rs | 1 + src/cgmath.rs | 1 + src/cylinder.rs | 2 +- src/frustum.rs | 4 ++-- src/line.rs | 2 +- src/matrix.rs | 52 +++++++++++++++++++++------------------- src/num.rs | 1 + src/obb.rs | 4 ++-- src/plane.rs | 2 +- src/point.rs | 33 ++++++++++++------------- src/projection.rs | 6 ++--- src/quaternion.rs | 7 +++--- src/ray.rs | 2 +- src/rotation.rs | 6 ++--- src/sphere.rs | 2 +- src/transform.rs | 6 ++--- src/vector.rs | 20 +++++++++------- 22 files changed, 92 insertions(+), 81 deletions(-) diff --git a/benches/common/macros.rs b/benches/common/macros.rs index b175a8d..8512d94 100644 --- a/benches/common/macros.rs +++ b/benches/common/macros.rs @@ -76,7 +76,7 @@ macro_rules! bench_unop( i = (i + 1) & (LEN - 1); unsafe { - test::black_box(elems.unsafe_mut(i).$unop()) + test::black_box(elems.unchecked_mut(i).$unop()) } }) } diff --git a/benches/construction.rs b/benches/construction.rs index 39b72d7..5cb4ff0 100644 --- a/benches/construction.rs +++ b/benches/construction.rs @@ -19,6 +19,7 @@ extern crate test; extern crate cgmath; use std::rand::{IsaacRng, Rng}; +use std::iter; use test::Bencher; use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad}; @@ -30,15 +31,15 @@ fn bench_from_axis_angle>(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); - let axis = Vec::from_fn(LEN, |_| rng.gen::>()); - let angle = Vec::from_fn(LEN, |_| rng.gen::>()); + let axis: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::>()).collect(); + let angle: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::>()).collect(); let mut i = 0; bh.iter(|| { i = (i + 1) & (LEN - 1); unsafe { - let res: T = Rotation3::from_axis_angle(axis.unsafe_get(i), *angle.unsafe_get(i)); + let res: T = Rotation3::from_axis_angle(axis.get_unchecked(i), *angle.get_unchecked(i)); test::black_box(res) } }) diff --git a/src/aabb.rs b/src/aabb.rs index f07b7c1..c232701 100644 --- a/src/aabb.rs +++ b/src/aabb.rs @@ -28,7 +28,7 @@ use num::{zero, one, BaseNum, BaseFloat}; use std::fmt; use std::num::Float; -pub trait Aabb, P: Point> { +pub trait Aabb, P: Point>: Sized { /// Create a new AABB using two points as opposing corners. fn new(p1: P, p2: P) -> Self; @@ -84,7 +84,7 @@ pub trait Aabb, P: Point> { } /// A two-dimensional AABB, aka a rectangle. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Aabb2 { pub min: Point2, pub max: Point2, @@ -129,7 +129,7 @@ impl fmt::Show for Aabb2 { } /// A three-dimensional AABB, aka a rectangular prism. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Aabb3 { pub min: Point3, pub max: Point3, diff --git a/src/angle.rs b/src/angle.rs index a372fe9..91cbc7b 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -18,15 +18,16 @@ use std::fmt; use std::f64; use std::num::{cast, Float}; +use std::ops::*; use approx::ApproxEq; use num::{BaseFloat, One, one, Zero, zero}; /// An angle, in radians -#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] pub struct Rad { pub s: S } /// An angle, in degrees -#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)] pub struct Deg { pub s: S } /// Create a new angle, in radians diff --git a/src/approx.rs b/src/approx.rs index 0399dbf..e07c276 100644 --- a/src/approx.rs +++ b/src/approx.rs @@ -16,7 +16,7 @@ use std::num; use std::num::Float; -pub trait ApproxEq { +pub trait ApproxEq: Sized { fn approx_epsilon(_hack: Option) -> T { num::cast(1.0e-5f64).unwrap() } diff --git a/src/array.rs b/src/array.rs index 7d7436e..9322a52 100644 --- a/src/array.rs +++ b/src/array.rs @@ -15,6 +15,7 @@ use std::mem; use std::ptr; +use std::ops::*; /// An array containing elements of type `Element` pub trait Array1: Index + IndexMut { diff --git a/src/cgmath.rs b/src/cgmath.rs index 021d02f..b6260e3 100644 --- a/src/cgmath.rs +++ b/src/cgmath.rs @@ -18,6 +18,7 @@ #![feature(globs)] #![feature(macro_rules)] +#![feature(old_orphan_check)] //! Computer graphics-centric math. //! diff --git a/src/cylinder.rs b/src/cylinder.rs index 6876710..22d2dfd 100644 --- a/src/cylinder.rs +++ b/src/cylinder.rs @@ -18,7 +18,7 @@ use point::Point3; use vector::Vector3; -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Cylinder { pub center: Point3, pub axis: Vector3, diff --git a/src/frustum.rs b/src/frustum.rs index 9ca83ff..579bb1d 100644 --- a/src/frustum.rs +++ b/src/frustum.rs @@ -22,7 +22,7 @@ use plane::Plane; use point::Point3; use vector::{Vector, EuclideanVector}; -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Frustum { pub left: Plane, pub right: Plane, @@ -59,7 +59,7 @@ Frustum { } } -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct FrustumPoints { pub near_top_left: Point3, pub near_top_right: Point3, diff --git a/src/line.rs b/src/line.rs index bb7b63c..13eae20 100644 --- a/src/line.rs +++ b/src/line.rs @@ -22,7 +22,7 @@ use ray::{Ray2}; use intersect::Intersect; /// A generic directed line segment from `origin` to `dest`. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Line

{ pub origin: P, pub dest: P, diff --git a/src/matrix.rs b/src/matrix.rs index d82010d..9b0a73b 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -18,6 +18,7 @@ use std::fmt; use std::mem; use std::num::cast; +use std::ops::*; use angle::{Rad, sin, cos, sin_cos}; use approx::ApproxEq; @@ -29,15 +30,15 @@ use vector::{Vector, EuclideanVector}; use vector::{Vector2, Vector3, Vector4}; /// A 2 x 2, column major matrix -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] pub struct Matrix2 { pub x: Vector2, pub y: Vector2 } /// A 3 x 3, column major matrix -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] pub struct Matrix3 { pub x: Vector3, pub y: Vector3, pub z: Vector3 } /// A 4 x 4, column major matrix -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] pub struct Matrix4 { pub x: Vector4, pub y: Vector4, pub z: Vector4, pub w: Vector4 } @@ -287,7 +288,8 @@ Matrix4 { pub trait Matrix>: Array2 + Neg + Zero + One - + ApproxEq { + + ApproxEq + + Sized { /// Multiply this matrix by a scalar, returning the new matrix. fn mul_s(&self, s: S) -> Self; /// Divide this matrix by a scalar, returning the new matrix. @@ -393,9 +395,9 @@ impl One for Matrix2 { #[inline] fn one() -> Matrix2 { Matri impl One for Matrix3 { #[inline] fn one() -> Matrix3 { Matrix3::identity() } } impl One for Matrix4 { #[inline] fn one() -> Matrix4 { Matrix4::identity() } } -impl FixedArray<[[S, ..2], ..2]> for Matrix2 { +impl FixedArray<[[S; 2]; 2]> for Matrix2 { #[inline] - fn into_fixed(self) -> [[S, ..2], ..2] { + fn into_fixed(self) -> [[S; 2]; 2] { match self { Matrix2 { x, y } => [ x.into_fixed(), @@ -405,17 +407,17 @@ impl FixedArray<[[S, ..2], ..2]> for Matrix2 { } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [[S, ..2], ..2] { + fn as_fixed<'a>(&'a self) -> &'a [[S; 2]; 2] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..2], ..2] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 2]; 2] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [[S, ..2], ..2]) -> Matrix2 { + fn from_fixed(_v: [[S; 2]; 2]) -> Matrix2 { // match v { // [x, y] => Matrix2 { // x: FixedArray::from_fixed(x), @@ -426,12 +428,12 @@ impl FixedArray<[[S, ..2], ..2]> for Matrix2 { } #[inline] - fn from_fixed_ref<'a>(v: &'a [[S, ..2], ..2]) -> &'a Matrix2 { + fn from_fixed_ref<'a>(v: &'a [[S; 2]; 2]) -> &'a Matrix2 { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [[S, ..2], ..2]) -> &'a mut Matrix2 { + fn from_fixed_mut<'a>(v: &'a mut [[S; 2]; 2]) -> &'a mut Matrix2 { unsafe { mem::transmute(v) } } } @@ -471,9 +473,9 @@ impl Array2, Vector2, S> for Matrix2 { } } -impl FixedArray<[[S, ..3], ..3]> for Matrix3 { +impl FixedArray<[[S; 3]; 3]> for Matrix3 { #[inline] - fn into_fixed(self) -> [[S, ..3], ..3] { + fn into_fixed(self) -> [[S; 3]; 3] { match self { Matrix3 { x, y, z } => [ x.into_fixed(), @@ -484,17 +486,17 @@ impl FixedArray<[[S, ..3], ..3]> for Matrix3 { } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [[S, ..3], ..3] { + fn as_fixed<'a>(&'a self) -> &'a [[S; 3]; 3] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..3], ..3] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 3]; 3] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [[S, ..3], ..3]) -> Matrix3 { + fn from_fixed(_v: [[S; 3]; 3]) -> Matrix3 { // match v { // [x, y, z] => Matrix3 { // x: FixedArray::from_fixed(x), @@ -506,12 +508,12 @@ impl FixedArray<[[S, ..3], ..3]> for Matrix3 { } #[inline] - fn from_fixed_ref<'a>(v: &'a [[S, ..3], ..3]) -> &'a Matrix3 { + fn from_fixed_ref<'a>(v: &'a [[S; 3]; 3]) -> &'a Matrix3 { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [[S, ..3], ..3]) -> &'a mut Matrix3 { + fn from_fixed_mut<'a>(v: &'a mut [[S; 3]; 3]) -> &'a mut Matrix3 { unsafe { mem::transmute(v) } } } @@ -554,9 +556,9 @@ impl Array2, Vector3, S> for Matrix3 { } } -impl FixedArray<[[S, ..4], ..4]> for Matrix4 { +impl FixedArray<[[S; 4]; 4]> for Matrix4 { #[inline] - fn into_fixed(self) -> [[S, ..4], ..4] { + fn into_fixed(self) -> [[S; 4]; 4] { match self { Matrix4 { x, y, z, w } => [ x.into_fixed(), @@ -568,17 +570,17 @@ impl FixedArray<[[S, ..4], ..4]> for Matrix4 { } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [[S, ..4], ..4] { + fn as_fixed<'a>(&'a self) -> &'a [[S; 4]; 4] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..4], ..4] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 4]; 4] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [[S, ..4], ..4]) -> Matrix4 { + fn from_fixed(_v: [[S; 4]; 4]) -> Matrix4 { // match v { // [x, y, z, w] => Matrix4 { // x: FixedArray::from_fixed(x), @@ -591,12 +593,12 @@ impl FixedArray<[[S, ..4], ..4]> for Matrix4 { } #[inline] - fn from_fixed_ref<'a>(v: &'a [[S, ..4], ..4]) -> &'a Matrix4 { + fn from_fixed_ref<'a>(v: &'a [[S; 4]; 4]) -> &'a Matrix4 { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [[S, ..4], ..4]) -> &'a mut Matrix4 { + fn from_fixed_mut<'a>(v: &'a mut [[S; 4]; 4]) -> &'a mut Matrix4 { unsafe { mem::transmute(v) } } } diff --git a/src/num.rs b/src/num.rs index 003b395..fe2d3d2 100644 --- a/src/num.rs +++ b/src/num.rs @@ -18,6 +18,7 @@ use approx::ApproxEq; use std::cmp; use std::fmt; use std::num::{FloatMath, Int, NumCast, Float}; +use std::ops::*; /// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html). pub trait PartialOrd { diff --git a/src/obb.rs b/src/obb.rs index 4c3302e..eefe5a4 100644 --- a/src/obb.rs +++ b/src/obb.rs @@ -18,14 +18,14 @@ use point::{Point2, Point3}; use vector::{Vector2, Vector3}; -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Obb2 { pub center: Point2, pub axis: Vector2, pub extents: Vector2, } -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Obb3 { pub center: Point3, pub axis: Vector3, diff --git a/src/plane.rs b/src/plane.rs index 0127153..a1314b1 100644 --- a/src/plane.rs +++ b/src/plane.rs @@ -39,7 +39,7 @@ use vector::{Vector, EuclideanVector}; /// The `A*x + B*y + C*z - D = 0` form is preferred over the other common /// alternative, `A*x + B*y + C*z + D = 0`, because it tends to avoid /// superfluous negations (see _Real Time Collision Detection_, p. 55). -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Plane { pub n: Vector3, pub d: S, diff --git a/src/point.rs b/src/point.rs index 6d65f71..4114860 100644 --- a/src/point.rs +++ b/src/point.rs @@ -19,6 +19,7 @@ use std::fmt; use std::mem; +use std::ops::*; use approx::ApproxEq; use array::{Array1, FixedArray}; @@ -26,11 +27,11 @@ use num::{BaseNum, BaseFloat, one, zero}; use vector::*; /// A point in 2-dimensional space. -#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] pub struct Point2 { pub x: S, pub y: S } /// A point in 3-dimensional space. -#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] pub struct Point3 { pub x: S, pub y: S, pub z: S } @@ -101,35 +102,35 @@ pub trait Point>: Array1 + Clone { fn max(&self, p: &Self) -> Self; } -impl FixedArray<[S, ..2]> for Point2 { +impl FixedArray<[S; 2]> for Point2 { #[inline] - fn into_fixed(self) -> [S, ..2] { + fn into_fixed(self) -> [S; 2] { match self { Point2 { x, y } => [x, y] } } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [S, ..2] { + fn as_fixed<'a>(&'a self) -> &'a [S; 2] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S, ..2] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S; 2] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [S, ..2]) -> Point2 { + fn from_fixed(_v: [S; 2]) -> Point2 { // match v { [x, y] => Point2 { x: x, y: y } } panic!("Unimplemented, pending a fix for rust-lang/rust#16418"); } #[inline] - fn from_fixed_ref<'a>(v: &'a [S, ..2]) -> &'a Point2 { + fn from_fixed_ref<'a>(v: &'a [S; 2]) -> &'a Point2 { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [S, ..2]) -> &'a mut Point2 { + fn from_fixed_mut<'a>(v: &'a mut [S; 2]) -> &'a mut Point2 { unsafe { mem::transmute(v) } } } @@ -255,35 +256,35 @@ impl ApproxEq for Point2 { } } -impl FixedArray<[S, ..3]> for Point3 { +impl FixedArray<[S; 3]> for Point3 { #[inline] - fn into_fixed(self) -> [S, ..3] { + fn into_fixed(self) -> [S; 3] { match self { Point3 { x, y, z } => [x, y, z] } } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [S, ..3] { + fn as_fixed<'a>(&'a self) -> &'a [S; 3] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S, ..3] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S; 3] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [S, ..3]) -> Point3 { + fn from_fixed(_v: [S; 3]) -> Point3 { // match v { [x, y, z] => Point3 { x: x, y: y, z: z } } panic!("Unimplemented, pending a fix for rust-lang/rust#16418") } #[inline] - fn from_fixed_ref<'a>(v: &'a [S, ..3]) -> &'a Point3 { + fn from_fixed_ref<'a>(v: &'a [S; 3]) -> &'a Point3 { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [S, ..3]) -> &'a mut Point3 { + fn from_fixed_mut<'a>(v: &'a mut [S; 3]) -> &'a mut Point3 { unsafe { mem::transmute(v) } } } diff --git a/src/projection.rs b/src/projection.rs index 1d97850..999fdcf 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -69,7 +69,7 @@ pub trait Projection: ToMatrix4 { } /// A perspective projection based on a vertical field-of-view angle. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct PerspectiveFov { pub fovy: A, pub aspect: S, @@ -143,7 +143,7 @@ impl> ToMatrix4 for PerspectiveFov { } /// A perspective projection with arbitrary left/right/bottom/top distances -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Perspective { pub left: S, right: S, pub bottom: S, top: S, @@ -193,7 +193,7 @@ impl ToMatrix4 for Perspective { } /// An orthographic projection with arbitrary left/right/bottom/top distances -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Ortho { pub left: S, right: S, pub bottom: S, top: S, diff --git a/src/quaternion.rs b/src/quaternion.rs index 715899a..b1eaa77 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -17,6 +17,7 @@ use std::fmt; use std::mem; use std::f64; use std::num::{cast, Float}; +use std::ops::*; use angle::{Angle, Rad, acos, sin, sin_cos, rad}; use approx::ApproxEq; @@ -29,7 +30,7 @@ use vector::{Vector3, Vector, EuclideanVector}; /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// form. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)] pub struct Quaternion { pub s: S, pub v: Vector3 } /// Represents types which can be expressed as a quaternion. @@ -52,7 +53,7 @@ impl Array1 for Quaternion { impl Index for Quaternion { #[inline] fn index<'a>(&'a self, i: &uint) -> &'a S { - let slice: &[S, ..4] = unsafe { mem::transmute(self) }; + let slice: &[S; 4] = unsafe { mem::transmute(self) }; &slice[*i] } } @@ -60,7 +61,7 @@ impl Index for Quaternion { impl IndexMut for Quaternion { #[inline] fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut S { - let slice: &'a mut [S, ..4] = unsafe { mem::transmute(self) }; + let slice: &'a mut [S; 4] = unsafe { mem::transmute(self) }; &mut slice[*i] } } diff --git a/src/ray.rs b/src/ray.rs index 46ad081..a86b608 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -19,7 +19,7 @@ use vector::{Vector, Vector2, Vector3}; /// A generic ray starting at `origin` and extending infinitely in /// `direction`. -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Ray { pub origin: P, pub direction: V, diff --git a/src/rotation.rs b/src/rotation.rs index 881071a..4c0ce2a 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -26,7 +26,7 @@ use vector::{Vector, Vector2, Vector3}; /// A trait for a generic rotation. A rotation is a transformation that /// creates a circular motion, and preserves at least one point in the space. -pub trait Rotation, P: Point>: PartialEq + ApproxEq { +pub trait Rotation, P: Point>: PartialEq + ApproxEq + Sized { /// Create the identity transform (causes no transformation). fn identity() -> Self; @@ -161,7 +161,7 @@ pub trait Rotation3: Rotation, Point3> /// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x); /// assert!(unit_y3.approx_eq(&unit_y2)); /// ``` -#[deriving(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)] pub struct Basis2 { mat: Matrix2 } @@ -239,7 +239,7 @@ impl Rotation2 for Basis2 { /// inversion, can be implemented more efficiently than the implementations for /// `math::Matrix3`. To ensure orthogonality is maintained, the operations have /// been restricted to a subeset of those implemented on `Matrix3`. -#[deriving(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)] pub struct Basis3 { mat: Matrix3 } diff --git a/src/sphere.rs b/src/sphere.rs index b376722..46474e9 100644 --- a/src/sphere.rs +++ b/src/sphere.rs @@ -21,7 +21,7 @@ use point::{Point, Point3}; use ray::Ray3; use vector::Vector; -#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Sphere { pub center: Point3, pub radius: S, diff --git a/src/transform.rs b/src/transform.rs index d6a6a2d..9038431 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -26,7 +26,7 @@ use vector::{Vector, Vector3}; /// A trait representing an [affine /// transformation](https://en.wikipedia.org/wiki/Affine_transformation) that /// can be applied to points or vectors. An affine transformation is one which -pub trait Transform, P: Point> { +pub trait Transform, P: Point>: Sized { /// Create an identity transformation. That is, a transformation which /// does nothing. fn identity() -> Self; @@ -76,7 +76,7 @@ pub trait Transform, P: Point> { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. -#[deriving(Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable)] pub struct Decomposed { pub scale: S, pub rot: R, @@ -159,7 +159,7 @@ impl> fmt::Show for Decomposed { pub mat: Matrix4, } diff --git a/src/vector.rs b/src/vector.rs index d40c9cf..75c8cd2 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -99,6 +99,7 @@ use std::fmt; use std::mem; use std::num::NumCast; +use std::ops::*; use angle::{Rad, atan2, acos}; use approx::ApproxEq; @@ -177,7 +178,7 @@ pub trait Vector: Array1 + Zero + One + Neg { // Utility macro for generating associated functions for the vectors macro_rules! vec( ($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr) => ( - #[deriving(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable, Rand)] + #[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable, Rand)] pub struct $Self { $(pub $field: S),+ } impl<$S> $Self<$S> { @@ -217,35 +218,35 @@ macro_rules! vec( } } - impl<$S> FixedArray<[$S, ..$n]> for $Self<$S> { + impl<$S> FixedArray<[$S; $n]> for $Self<$S> { #[inline] - fn into_fixed(self) -> [$S, ..$n] { + fn into_fixed(self) -> [$S; $n] { match self { $Self { $($field),+ } => [$($field),+] } } #[inline] - fn as_fixed<'a>(&'a self) -> &'a [$S, ..$n] { + fn as_fixed<'a>(&'a self) -> &'a [$S; $n] { unsafe { mem::transmute(self) } } #[inline] - fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [$S, ..$n] { + fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [$S; $n] { unsafe { mem::transmute(self) } } #[inline] - fn from_fixed(_v: [$S, ..$n]) -> $Self<$S> { + fn from_fixed(_v: [$S; $n]) -> $Self<$S> { // match v { [$($field),+] => $Self { $($field: $field),+ } } panic!("Unimplemented, pending a fix for rust-lang/rust#16418"); } #[inline] - fn from_fixed_ref<'a>(v: &'a [$S, ..$n]) -> &'a $Self<$S> { + fn from_fixed_ref<'a>(v: &'a [$S; $n]) -> &'a $Self<$S> { unsafe { mem::transmute(v) } } #[inline] - fn from_fixed_mut<'a>(v: &'a mut [$S, ..$n]) -> &'a mut $Self<$S> { + fn from_fixed_mut<'a>(v: &'a mut [$S; $n]) -> &'a mut $Self<$S> { unsafe { mem::transmute(v) } } } @@ -442,7 +443,8 @@ impl Vector4 { /// Specifies geometric operations for vectors. This is only implemented for /// 2-dimensional and 3-dimensional vectors. pub trait EuclideanVector: Vector - + ApproxEq { + + ApproxEq + + Sized { /// Returns `true` if the vector is perpendicular (at right angles) to the /// other vector. fn is_perpendicular(&self, other: &Self) -> bool {