diff --git a/CHANGELOG.md b/CHANGELOG.md index d4ee221b..c84dc8af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [0.16.0] - WIP ## Modified - * Adjust `UnitQuaternion`s and `Rotation3`s generated from the `Standard` distribution to be uniformly distributed. + * Adjust `UnitQuaternion`s, `Rotation3`s, and `Rotation2`s generated from the `Standard` distribution to be uniformly + distributed. ### Added * Add construction of a `Point` from an array by implementing the `From` trait. * Add support for generating uniformly distributed random unit column vectors using the `Standard` distribution. diff --git a/src/base/construction.rs b/src/base/construction.rs index 49da1d5b..787ca297 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -507,6 +507,7 @@ where DefaultAllocator: Allocator, StandardNormal: Distribution, { + /// Generate a uniformly distributed random unit vector. #[inline] fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit> { Unit::new_normalize(VectorN::from_distribution_generic(D::name(), U1, &mut StandardNormal, rng)) diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index aa156eef..c492705f 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -415,6 +415,7 @@ impl Distribution> for Standard where OpenClosed01: Distribution, { + /// Generate a uniformly distributed random rotation quaternion. #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> UnitQuaternion { // Ken Shoemake's Subgroup Algorithm diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index e5cd4b4a..0f91ee39 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -100,11 +100,12 @@ impl Rotation2 { impl Distribution> for Standard where - Standard: Distribution, + OpenClosed01: Distribution, { + /// Generate a uniformly distributed random rotation. #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Rotation2 { - Rotation2::new(rng.gen()) + Rotation2::new(rng.sample(OpenClosed01) * N::two_pi()) } } @@ -386,6 +387,7 @@ impl Distribution> for Standard where OpenClosed01: Distribution, { + /// Generate a uniformly distributed random rotation. #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation3 { // James Arvo. diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index ca4d6d21..ce10ef73 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen}; use num::One; use num_complex::Complex; -use rand::distributions::{Distribution, Standard}; +use rand::distributions::{Distribution, Standard, OpenClosed01}; use rand::Rng; use alga::general::Real; @@ -153,11 +153,12 @@ impl One for UnitComplex { impl Distribution> for Standard where - Standard: Distribution, + OpenClosed01: Distribution, { + /// Generate a uniformly distributed random `UnitComplex`. #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex { - UnitComplex::from_angle(rng.gen() * N::two_pi()) + UnitComplex::from_angle(rng.sample(OpenClosed01) * N::two_pi()) } }