diff --git a/src/aabb.rs b/src/aabb.rs index 122e6bd..b8df9ba 100644 --- a/src/aabb.rs +++ b/src/aabb.rs @@ -84,7 +84,7 @@ pub trait Aabb, P: Point> { } /// A two-dimensional AABB, aka a rectangle. -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Aabb3 { pub min: Point3, pub max: Point3, diff --git a/src/angle.rs b/src/angle.rs index 7536550..d8f8249 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -23,10 +23,10 @@ use approx::ApproxEq; use num::{BaseFloat, One, one, Zero, zero}; /// An angle, in radians -#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] pub struct Rad { pub s: S } /// An angle, in degrees -#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] pub struct Deg { pub s: S } /// Create a new angle, in radians @@ -77,7 +77,7 @@ pub trait Angle S: BaseFloat > : Clone + Zero -+ PartialEq + Equiv + PartialOrd ++ PartialEq + PartialOrd + ApproxEq + Neg + ToRad @@ -153,6 +153,8 @@ pub trait Angle #[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3i).unwrap()) } #[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4i).unwrap()) } #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6i).unwrap()) } + + #[inline] fn equiv(&self, other: &Self) -> bool { self.normalize() == other.normalize() } } #[inline] pub fn bisect>(a: A, b: A) -> A { a.bisect(b) } @@ -196,20 +198,6 @@ impl Mul, Deg> for Deg { #[inline] fn mul(&self, othe impl One for Rad { #[inline] fn one() -> Rad { rad(one()) } } impl One for Deg { #[inline] fn one() -> Deg { deg(one()) } } -impl -Equiv> for Rad { - fn equiv(&self, other: &Rad) -> bool { - self.normalize() == other.normalize() - } -} - -impl -Equiv> for Deg { - fn equiv(&self, other: &Deg) -> bool { - self.normalize() == other.normalize() - } -} - impl Angle for Rad { #[inline] fn from>(theta: A) -> Rad { theta.to_rad() } diff --git a/src/cgmath.rs b/src/cgmath.rs index ae72713..072b24e 100644 --- a/src/cgmath.rs +++ b/src/cgmath.rs @@ -15,8 +15,6 @@ #![crate_type = "rlib"] #![crate_type = "dylib"] -#![comment = "A mathematics library for computer graphics."] -#![license = "ASL2"] #![feature(globs)] #![feature(macro_rules)] diff --git a/src/cylinder.rs b/src/cylinder.rs index be8a835..d13b0b8 100644 --- a/src/cylinder.rs +++ b/src/cylinder.rs @@ -18,7 +18,7 @@ use point::Point3; use vector::Vector3; -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Cylinder { pub center: Point3, pub axis: Vector3, diff --git a/src/frustum.rs b/src/frustum.rs index 08500cc..8ebe229 100644 --- a/src/frustum.rs +++ b/src/frustum.rs @@ -22,7 +22,7 @@ use plane::Plane; use point::Point3; use vector::{Vector, EuclideanVector}; -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Frustum { pub left: Plane, pub right: Plane, @@ -59,7 +59,7 @@ Frustum { } } -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct FrustumPoints { pub near_top_left: Point3, pub near_top_right: Point3, diff --git a/src/line.rs b/src/line.rs index 84843ba..a0e3153 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Line

{ pub origin: P, pub dest: P, diff --git a/src/matrix.rs b/src/matrix.rs index 6d43707..fd73a54 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -29,15 +29,15 @@ use vector::{Vector, EuclideanVector}; use vector::{Vector2, Vector3, Vector4}; /// A 2 x 2, column major matrix -#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)] pub struct Matrix2 { pub x: Vector2, pub y: Vector2 } /// A 3 x 3, column major matrix -#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)] pub struct Matrix3 { pub x: Vector3, pub y: Vector3, pub z: Vector3 } /// A 4 x 4, column major matrix -#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)] pub struct Matrix4 { pub x: Vector4, pub y: Vector4, pub z: Vector4, pub w: Vector4 } diff --git a/src/obb.rs b/src/obb.rs index c1a1c21..15ad539 100644 --- a/src/obb.rs +++ b/src/obb.rs @@ -18,14 +18,14 @@ use point::{Point2, Point3}; use vector::{Vector2, Vector3}; -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Obb2 { pub center: Point2, pub axis: Vector2, pub extents: Vector2, } -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Obb3 { pub center: Point3, pub axis: Vector3, diff --git a/src/plane.rs b/src/plane.rs index 3efb1c0..1c36b19 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Plane { pub n: Vector3, pub d: S, diff --git a/src/point.rs b/src/point.rs index 1b9aa87..1566989 100644 --- a/src/point.rs +++ b/src/point.rs @@ -26,11 +26,11 @@ use num::{BaseNum, BaseFloat, one, zero}; use vector::*; /// A point in 2-dimensional space. -#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)] +#[deriving(PartialEq, Copy, Clone, Hash, Encodable, Decodable)] pub struct Point2 { pub x: S, pub y: S } /// A point in 3-dimensional space. -#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)] +#[deriving(PartialEq, Copy, Clone, Hash, Encodable, Decodable)] pub struct Point3 { pub x: S, pub y: S, pub z: S } diff --git a/src/projection.rs b/src/projection.rs index 6baaab7..e574767 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Ortho { pub left: S, right: S, pub bottom: S, top: S, diff --git a/src/quaternion.rs b/src/quaternion.rs index c9f4eac..45e7a96 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -29,7 +29,7 @@ use vector::{Vector3, Vector, EuclideanVector}; /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// form. -#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)] pub struct Quaternion { pub s: S, pub v: Vector3 } /// Represents types which can be expressed as a quaternion. diff --git a/src/ray.rs b/src/ray.rs index 0bb0c47..879a2c4 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(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Ray { pub origin: P, pub direction: V, diff --git a/src/rotation.rs b/src/rotation.rs index 74f2e44..547108f 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -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, Clone, Encodable, Decodable)] +#[deriving(PartialEq, Copy, Clone, Encodable, Decodable)] 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, Clone, Encodable, Decodable)] +#[deriving(PartialEq, Copy, Clone, Encodable, Decodable)] pub struct Basis3 { mat: Matrix3 } diff --git a/src/sphere.rs b/src/sphere.rs index 201473b..a1f6b83 100644 --- a/src/sphere.rs +++ b/src/sphere.rs @@ -21,7 +21,7 @@ use point::{Point, Point3}; use ray::Ray3; use vector::Vector; -#[deriving(Clone, PartialEq, Encodable, Decodable)] +#[deriving(Copy, Clone, PartialEq, Encodable, Decodable)] pub struct Sphere { pub center: Point3, pub radius: S, diff --git a/src/transform.rs b/src/transform.rs index b69f3e7..f83397b 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -76,7 +76,7 @@ pub trait Transform, P: Point> { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. -#[deriving(Encodable, Decodable)] +#[deriving(Copy, Clone, Encodable, Decodable)] 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 8351b99..5bdceee 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -177,7 +177,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, Clone, Hash, Encodable, Decodable, Rand)] + #[deriving(PartialEq, Eq, Copy, Clone, Hash, Encodable, Decodable, Rand)] pub struct $Self { $(pub $field: S),+ } impl<$S> $Self<$S> {