parent
41ae60efeb
commit
ea431f4190
@ -0,0 +1,32 @@
|
|||||||
|
//! Extensions
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub trait Tuple2MapExt<T>
|
||||||
|
{
|
||||||
|
fn map<F, U>(self, fun: F) -> (U, U)
|
||||||
|
where F: FnMut(T) -> U;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Tuple2MapExt<T> for (T,T)
|
||||||
|
{
|
||||||
|
fn map<F, U>(self, mut fun: F) -> (U, U)
|
||||||
|
where F: FnMut(T) -> U
|
||||||
|
{
|
||||||
|
(fun(self.0), fun(self.1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait JitterExt<T>
|
||||||
|
{
|
||||||
|
/// Produce a random value between `self.0` and `self.1` inclusive
|
||||||
|
fn jitter(self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> JitterExt<T> for (T, T)
|
||||||
|
where T: rand::distributions::uniform::SampleUniform
|
||||||
|
{
|
||||||
|
fn jitter(self) -> T
|
||||||
|
{
|
||||||
|
util::jitter(self.0, self.1)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
//! Utils
|
||||||
|
|
||||||
|
/// Get a random value between these two inclusive
|
||||||
|
pub fn jitter<T>(min: T, max: T) -> T
|
||||||
|
where T: rand::distributions::uniform::SampleUniform
|
||||||
|
{
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
let mut thread = rand::thread_rng();
|
||||||
|
let dist = rand::distributions::Uniform::new_inclusive(min, max);
|
||||||
|
|
||||||
|
thread.sample(dist)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue