use the new rand_macros crate

This commit is contained in:
Colin Sherratt 2015-02-08 13:25:42 -05:00
parent e712bdee7c
commit 778a3c13aa
6 changed files with 21 additions and 9 deletions

View file

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

View file

@ -24,10 +24,12 @@ use approx::ApproxEq;
use num::{BaseFloat, One, one, Zero, zero};
/// 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 }
/// 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 }
/// Create a new angle, in radians

View file

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

View file

@ -30,15 +30,18 @@ use vector::{Vector, EuclideanVector};
use vector::{Vector2, Vector3, Vector4};
/// 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> }
/// 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> }
/// 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> }

View file

@ -30,7 +30,8 @@ use vector::{Vector3, Vector, EuclideanVector};
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
/// 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> }
/// Represents types which can be expressed as a quaternion.

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
macro_rules! vec(
($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),+ }
impl<$S> $Self<$S> {