Add deriving Copy to all structs that would previously be inferred to be Copy

Remove use of deprecated Equiv trait
Remove unsed attributes
This commit is contained in:
Jameson Ernst 2014-12-12 17:06:52 -08:00
parent 6f058eab4b
commit 5726e6c7dc
17 changed files with 30 additions and 44 deletions

View file

@ -84,7 +84,7 @@ pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>> {
} }
/// A two-dimensional AABB, aka a rectangle. /// A two-dimensional AABB, aka a rectangle.
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Aabb2<S> { pub struct Aabb2<S> {
pub min: Point2<S>, pub min: Point2<S>,
pub max: Point2<S>, pub max: Point2<S>,
@ -129,7 +129,7 @@ impl<S: BaseNum> fmt::Show for Aabb2<S> {
} }
/// A three-dimensional AABB, aka a rectangular prism. /// A three-dimensional AABB, aka a rectangular prism.
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Aabb3<S> { pub struct Aabb3<S> {
pub min: Point3<S>, pub min: Point3<S>,
pub max: Point3<S>, pub max: Point3<S>,

View file

@ -23,10 +23,10 @@ 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
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)]
pub struct Rad<S> { pub s: S } pub struct Rad<S> { pub s: S }
/// An angle, in degrees /// An angle, in degrees
#[deriving(Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, Encodable, Decodable, Rand)]
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
@ -77,7 +77,7 @@ pub trait Angle
S: BaseFloat S: BaseFloat
> >
: Clone + Zero : Clone + Zero
+ PartialEq + Equiv<Self> + PartialOrd + PartialEq + PartialOrd
+ ApproxEq<S> + ApproxEq<S>
+ Neg<Self> + Neg<Self>
+ ToRad<S> + ToRad<S>
@ -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_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_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 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<S: BaseFloat, A: Angle<S>>(a: A, b: A) -> A { a.bisect(b) } #[inline] pub fn bisect<S: BaseFloat, A: Angle<S>>(a: A, b: A) -> A { a.bisect(b) }
@ -196,20 +198,6 @@ impl<S: BaseFloat> Mul<Deg<S>, Deg<S>> for Deg<S> { #[inline] fn mul(&self, othe
impl<S: BaseFloat> One for Rad<S> { #[inline] fn one() -> Rad<S> { rad(one()) } } impl<S: BaseFloat> One for Rad<S> { #[inline] fn one() -> Rad<S> { rad(one()) } }
impl<S: BaseFloat> One for Deg<S> { #[inline] fn one() -> Deg<S> { deg(one()) } } impl<S: BaseFloat> One for Deg<S> { #[inline] fn one() -> Deg<S> { deg(one()) } }
impl<S: BaseFloat>
Equiv<Rad<S>> for Rad<S> {
fn equiv(&self, other: &Rad<S>) -> bool {
self.normalize() == other.normalize()
}
}
impl<S: BaseFloat>
Equiv<Deg<S>> for Deg<S> {
fn equiv(&self, other: &Deg<S>) -> bool {
self.normalize() == other.normalize()
}
}
impl<S: BaseFloat> impl<S: BaseFloat>
Angle<S> for Rad<S> { Angle<S> for Rad<S> {
#[inline] fn from<A: Angle<S>>(theta: A) -> Rad<S> { theta.to_rad() } #[inline] fn from<A: Angle<S>>(theta: A) -> Rad<S> { theta.to_rad() }

View file

@ -15,8 +15,6 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_type = "dylib"] #![crate_type = "dylib"]
#![comment = "A mathematics library for computer graphics."]
#![license = "ASL2"]
#![feature(globs)] #![feature(globs)]
#![feature(macro_rules)] #![feature(macro_rules)]

View file

@ -18,7 +18,7 @@
use point::Point3; use point::Point3;
use vector::Vector3; use vector::Vector3;
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Cylinder<S> { pub struct Cylinder<S> {
pub center: Point3<S>, pub center: Point3<S>,
pub axis: Vector3<S>, pub axis: Vector3<S>,

View file

@ -22,7 +22,7 @@ use plane::Plane;
use point::Point3; use point::Point3;
use vector::{Vector, EuclideanVector}; use vector::{Vector, EuclideanVector};
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Frustum<S> { pub struct Frustum<S> {
pub left: Plane<S>, pub left: Plane<S>,
pub right: Plane<S>, pub right: Plane<S>,
@ -59,7 +59,7 @@ Frustum<S> {
} }
} }
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct FrustumPoints<S> { pub struct FrustumPoints<S> {
pub near_top_left: Point3<S>, pub near_top_left: Point3<S>,
pub near_top_right: Point3<S>, pub near_top_right: Point3<S>,

View file

@ -22,7 +22,7 @@ use ray::{Ray2};
use intersect::Intersect; use intersect::Intersect;
/// A generic directed line segment from `origin` to `dest`. /// A generic directed line segment from `origin` to `dest`.
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Line<P> { pub struct Line<P> {
pub origin: P, pub origin: P,
pub dest: P, pub dest: P,

View file

@ -29,15 +29,15 @@ 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
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)]
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
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)]
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
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)]
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> }

View file

@ -18,14 +18,14 @@
use point::{Point2, Point3}; use point::{Point2, Point3};
use vector::{Vector2, Vector3}; use vector::{Vector2, Vector3};
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Obb2<S> { pub struct Obb2<S> {
pub center: Point2<S>, pub center: Point2<S>,
pub axis: Vector2<S>, pub axis: Vector2<S>,
pub extents: Vector2<S>, pub extents: Vector2<S>,
} }
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Obb3<S> { pub struct Obb3<S> {
pub center: Point3<S>, pub center: Point3<S>,
pub axis: Vector3<S>, pub axis: Vector3<S>,

View file

@ -39,7 +39,7 @@ use vector::{Vector, EuclideanVector};
/// The `A*x + B*y + C*z - D = 0` form is preferred over the other common /// 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 /// alternative, `A*x + B*y + C*z + D = 0`, because it tends to avoid
/// superfluous negations (see _Real Time Collision Detection_, p. 55). /// superfluous negations (see _Real Time Collision Detection_, p. 55).
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Plane<S> { pub struct Plane<S> {
pub n: Vector3<S>, pub n: Vector3<S>,
pub d: S, pub d: S,

View file

@ -26,11 +26,11 @@ use num::{BaseNum, BaseFloat, one, zero};
use vector::*; use vector::*;
/// A point in 2-dimensional space. /// A point in 2-dimensional space.
#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)] #[deriving(PartialEq, Copy, Clone, Hash, Encodable, Decodable)]
pub struct Point2<S> { pub x: S, pub y: S } pub struct Point2<S> { pub x: S, pub y: S }
/// A point in 3-dimensional space. /// A point in 3-dimensional space.
#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)] #[deriving(PartialEq, Copy, Clone, Hash, Encodable, Decodable)]
pub struct Point3<S> { pub x: S, pub y: S, pub z: S } pub struct Point3<S> { pub x: S, pub y: S, pub z: S }

View file

@ -69,7 +69,7 @@ pub trait Projection<S>: ToMatrix4<S> {
} }
/// A perspective projection based on a vertical field-of-view angle. /// 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<S, A> { pub struct PerspectiveFov<S, A> {
pub fovy: A, pub fovy: A,
pub aspect: S, pub aspect: S,
@ -143,7 +143,7 @@ impl<S: BaseFloat, A: Angle<S>> ToMatrix4<S> for PerspectiveFov<S, A> {
} }
/// A perspective projection with arbitrary left/right/bottom/top distances /// A perspective projection with arbitrary left/right/bottom/top distances
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Perspective<S> { pub struct Perspective<S> {
pub left: S, right: S, pub left: S, right: S,
pub bottom: S, top: S, pub bottom: S, top: S,
@ -193,7 +193,7 @@ impl<S: BaseFloat + 'static> ToMatrix4<S> for Perspective<S> {
} }
/// An orthographic projection with arbitrary left/right/bottom/top distances /// An orthographic projection with arbitrary left/right/bottom/top distances
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Ortho<S> { pub struct Ortho<S> {
pub left: S, right: S, pub left: S, right: S,
pub bottom: S, top: S, pub bottom: S, top: S,

View file

@ -29,7 +29,7 @@ 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.
#[deriving(Clone, PartialEq, Encodable, Decodable, Rand)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable, Rand)]
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.

View file

@ -19,7 +19,7 @@ use vector::{Vector, Vector2, Vector3};
/// A generic ray starting at `origin` and extending infinitely in /// A generic ray starting at `origin` and extending infinitely in
/// `direction`. /// `direction`.
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Ray<P,V> { pub struct Ray<P,V> {
pub origin: P, pub origin: P,
pub direction: V, pub direction: V,

View file

@ -161,7 +161,7 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
/// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x); /// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x);
/// assert!(unit_y3.approx_eq(&unit_y2)); /// assert!(unit_y3.approx_eq(&unit_y2));
/// ``` /// ```
#[deriving(PartialEq, Clone, Encodable, Decodable)] #[deriving(PartialEq, Copy, Clone, Encodable, Decodable)]
pub struct Basis2<S> { pub struct Basis2<S> {
mat: Matrix2<S> mat: Matrix2<S>
} }
@ -239,7 +239,7 @@ impl<S: BaseFloat + 'static> Rotation2<S> for Basis2<S> {
/// inversion, can be implemented more efficiently than the implementations for /// inversion, can be implemented more efficiently than the implementations for
/// `math::Matrix3`. To ensure orthogonality is maintained, the operations have /// `math::Matrix3`. To ensure orthogonality is maintained, the operations have
/// been restricted to a subeset of those implemented on `Matrix3`. /// been restricted to a subeset of those implemented on `Matrix3`.
#[deriving(PartialEq, Clone, Encodable, Decodable)] #[deriving(PartialEq, Copy, Clone, Encodable, Decodable)]
pub struct Basis3<S> { pub struct Basis3<S> {
mat: Matrix3<S> mat: Matrix3<S>
} }

View file

@ -21,7 +21,7 @@ use point::{Point, Point3};
use ray::Ray3; use ray::Ray3;
use vector::Vector; use vector::Vector;
#[deriving(Clone, PartialEq, Encodable, Decodable)] #[deriving(Copy, Clone, PartialEq, Encodable, Decodable)]
pub struct Sphere<S> { pub struct Sphere<S> {
pub center: Point3<S>, pub center: Point3<S>,
pub radius: S, pub radius: S,

View file

@ -76,7 +76,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S,V>> {
/// A generic transformation consisting of a rotation, /// A generic transformation consisting of a rotation,
/// displacement vector and scale amount. /// displacement vector and scale amount.
#[deriving(Encodable, Decodable)] #[deriving(Copy, Clone, Encodable, Decodable)]
pub struct Decomposed<S, V, R> { pub struct Decomposed<S, V, R> {
pub scale: S, pub scale: S,
pub rot: R, pub rot: R,
@ -159,7 +159,7 @@ impl<S: BaseFloat, R: fmt::Show + Rotation3<S>> fmt::Show for Decomposed<S,Vecto
} }
/// A homogeneous transformation matrix. /// A homogeneous transformation matrix.
#[deriving(Encodable, Decodable)] #[deriving(Copy, Clone, Encodable, Decodable)]
pub struct AffineMatrix3<S> { pub struct AffineMatrix3<S> {
pub mat: Matrix4<S>, pub mat: Matrix4<S>,
} }

View file

@ -177,7 +177,7 @@ pub trait Vector<S: BaseNum>: Array1<S> + Zero + One + Neg<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) => ( ($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<S> { $(pub $field: S),+ } pub struct $Self<S> { $(pub $field: S),+ }
impl<$S> $Self<$S> { impl<$S> $Self<$S> {