1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use math;
use modules::NoiseModule;
use num_traits::Float;
pub struct Exponent<Source, T> {
pub source: Source,
pub exponent: T,
}
impl<Source, T> Exponent<Source, T>
where T: Float,
{
pub fn new(source: Source) -> Exponent<Source, T> {
Exponent {
source: source,
exponent: T::one(),
}
}
pub fn set_exponent(self, exponent: T) -> Exponent<Source, T> {
Exponent { exponent: exponent, ..self }
}
}
impl<Source, T, U> NoiseModule<T> for Exponent<Source, U>
where Source: NoiseModule<T, Output = U>,
T: Copy,
U: Float,
{
type Output = U;
fn get(&self, point: T) -> Self::Output {
let mut value = self.source.get(point);
value = (value + U::one()) / math::cast(2.0);
value = value.abs();
value = value.powf(self.exponent);
value.mul_add(math::cast(2.0), -U::one())
}
}