Document distribution uniformity, fix `Rotation2` distribution
Also tweak UnitComplex distribution for consistency
This commit is contained in:
parent
8e90e2adf7
commit
aad94661c9
|
@ -6,7 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## [0.16.0] - WIP
|
## [0.16.0] - WIP
|
||||||
## Modified
|
## 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
|
### Added
|
||||||
* Add construction of a `Point` from an array by implementing the `From` trait.
|
* 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.
|
* Add support for generating uniformly distributed random unit column vectors using the `Standard` distribution.
|
||||||
|
|
|
@ -507,6 +507,7 @@ where
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
StandardNormal: Distribution<N>,
|
StandardNormal: Distribution<N>,
|
||||||
{
|
{
|
||||||
|
/// Generate a uniformly distributed random unit vector.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit<VectorN<N, D>> {
|
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit<VectorN<N, D>> {
|
||||||
Unit::new_normalize(VectorN::from_distribution_generic(D::name(), U1, &mut StandardNormal, rng))
|
Unit::new_normalize(VectorN::from_distribution_generic(D::name(), U1, &mut StandardNormal, rng))
|
||||||
|
|
|
@ -415,6 +415,7 @@ impl<N: Real> Distribution<UnitQuaternion<N>> for Standard
|
||||||
where
|
where
|
||||||
OpenClosed01: Distribution<N>,
|
OpenClosed01: Distribution<N>,
|
||||||
{
|
{
|
||||||
|
/// Generate a uniformly distributed random rotation quaternion.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> UnitQuaternion<N> {
|
fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> UnitQuaternion<N> {
|
||||||
// Ken Shoemake's Subgroup Algorithm
|
// Ken Shoemake's Subgroup Algorithm
|
||||||
|
|
|
@ -100,11 +100,12 @@ impl<N: Real> Rotation2<N> {
|
||||||
|
|
||||||
impl<N: Real> Distribution<Rotation2<N>> for Standard
|
impl<N: Real> Distribution<Rotation2<N>> for Standard
|
||||||
where
|
where
|
||||||
Standard: Distribution<N>,
|
OpenClosed01: Distribution<N>,
|
||||||
{
|
{
|
||||||
|
/// Generate a uniformly distributed random rotation.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Rotation2<N> {
|
fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Rotation2<N> {
|
||||||
Rotation2::new(rng.gen())
|
Rotation2::new(rng.sample(OpenClosed01) * N::two_pi())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,6 +387,7 @@ impl<N: Real> Distribution<Rotation3<N>> for Standard
|
||||||
where
|
where
|
||||||
OpenClosed01: Distribution<N>,
|
OpenClosed01: Distribution<N>,
|
||||||
{
|
{
|
||||||
|
/// Generate a uniformly distributed random rotation.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation3<N> {
|
fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation3<N> {
|
||||||
// James Arvo.
|
// James Arvo.
|
||||||
|
|
|
@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen};
|
||||||
|
|
||||||
use num::One;
|
use num::One;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::distributions::{Distribution, Standard, OpenClosed01};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
@ -153,11 +153,12 @@ impl<N: Real> One for UnitComplex<N> {
|
||||||
|
|
||||||
impl<N: Real> Distribution<UnitComplex<N>> for Standard
|
impl<N: Real> Distribution<UnitComplex<N>> for Standard
|
||||||
where
|
where
|
||||||
Standard: Distribution<N>,
|
OpenClosed01: Distribution<N>,
|
||||||
{
|
{
|
||||||
|
/// Generate a uniformly distributed random `UnitComplex`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex<N> {
|
fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex<N> {
|
||||||
UnitComplex::from_angle(rng.gen() * N::two_pi())
|
UnitComplex::from_angle(rng.sample(OpenClosed01) * N::two_pi())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue