diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index a324a6e5..0ce391d6 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -1,4 +1,5 @@ use core::num::{One, Zero}; // , Trigonometric}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::workarounds::rlmul::{RMul, LMul}; use traits::workarounds::trigonometric::Trigonometric; @@ -56,6 +57,20 @@ pub fn Rotmat3 + One + Sub + Add + } } +impl> Rand for Rotmat> +{ + fn rand(rng: &R) -> Rotmat> + { Rotmat2(rng.gen()) } +} + +impl + One + Sub + Add + + Mul> +Rand for Rotmat> +{ + fn rand(rng: &R) -> Rotmat> + { Rotmat3(&rng.gen(), rng.gen()) } +} + impl Dim for Rotmat { fn dim() -> uint diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 9d1354cb..a2161c78 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -1,4 +1,5 @@ use core::num::{One, Zero}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dim::Dim; use traits::inv::Inv; @@ -91,6 +92,12 @@ impl, V:FuzzyEq> FuzzyEq for Transform } } +impl Rand for Transform +{ + fn rand(rng: &R) -> Transform + { Transform(&rng.gen(), &rng.gen()) } +} + impl ToStr for Transform { fn to_str(&self) -> ~str diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 9c4c98eb..8348af18 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -1,4 +1,5 @@ use core::num::{One, Zero}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dim::Dim; use traits::inv::Inv; @@ -93,6 +94,12 @@ impl> FuzzyEq for Mat1 { self.m11.fuzzy_eq_eps(&other.m11, epsilon) } } +impl Rand for Mat1 +{ + fn rand(rng: &R) -> Mat1 + { Mat1(rng.gen()) } +} + impl ToStr for Mat1 { fn to_str(&self) -> ~str diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index c8ad1be1..0bd2ad2e 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -1,4 +1,5 @@ use core::num::{Zero, Algebraic}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dot::Dot; use traits::dim::Dim; @@ -67,6 +68,12 @@ impl> FuzzyEq for Vec1 { self.x.fuzzy_eq_eps(&other.x, epsilon) } } +impl Rand for Vec1 +{ + fn rand(rng: &R) -> Vec1 + { Vec1(rng.gen()) } +} + impl ToStr for Vec1 { fn to_str(&self) -> ~str diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index 2f21a31d..6d2e6603 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -1,4 +1,5 @@ use core::num::{One, Zero}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dim::Dim; use traits::inv::Inv; @@ -144,6 +145,12 @@ impl> FuzzyEq for Mat2 } } +impl Rand for Mat2 +{ + fn rand(rng: &R) -> Mat2 + { Mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } +} + impl ToStr for Mat2 { fn to_str(&self) -> ~str diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index 00b2fbf6..1a603200 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -1,4 +1,5 @@ use core::num::{Zero, Algebraic}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dot::Dot; use traits::dim::Dim; @@ -81,6 +82,12 @@ impl> FuzzyEq for Vec2 } } +impl Rand for Vec2 +{ + fn rand(rng: &R) -> Vec2 + { Vec2(rng.gen(), rng.gen()) } +} + impl ToStr for Vec2 { fn to_str(&self) -> ~str diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 357491f2..d86a5e43 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -1,4 +1,5 @@ use core::num::{One, Zero}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dim::Dim; use traits::inv::Inv; @@ -195,6 +196,16 @@ impl> FuzzyEq for Mat3 } } +impl Rand for Mat3 +{ + fn rand(rng: &R) -> Mat3 + { + Mat3(rng.gen(), rng.gen(), rng.gen(), + rng.gen(), rng.gen(), rng.gen(), + rng.gen(), rng.gen(), rng.gen()) + } +} + impl ToStr for Mat3 { fn to_str(&self) -> ~str diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index edb18fdc..1cfc5875 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -1,4 +1,5 @@ use core::num::{Zero, Algebraic}; +use core::rand::{Rand, Rng, RngUtil}; use std::cmp::FuzzyEq; use traits::dim::Dim; use traits::dot::Dot; @@ -92,6 +93,12 @@ impl> FuzzyEq for Vec3 } } +impl Rand for Vec3 +{ + fn rand(rng: &R) -> Vec3 + { Vec3(rng.gen(), rng.gen(), rng.gen()) } +} + impl ToStr for Vec3 { fn to_str(&self) -> ~str