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
59
60
use modules::NoiseModule;
use num_traits::Float;
pub struct ScaleBias<Source, T> {
pub source: Source,
pub scale: T,
pub bias: T,
}
impl<Source, T> ScaleBias<Source, T>
where T: Float,
{
pub fn new(source: Source) -> ScaleBias<Source, T> {
ScaleBias {
source: source,
scale: T::one(),
bias: T::zero(),
}
}
pub fn set_scale(self, scale: T) -> ScaleBias<Source, T> {
ScaleBias { scale: scale, ..self }
}
pub fn set_bias(self, bias: T) -> ScaleBias<Source, T> {
ScaleBias { bias: bias, ..self }
}
}
impl<Source, T, U> NoiseModule<T> for ScaleBias<Source, U>
where Source: NoiseModule<T, Output = U>,
T: Copy,
U: Float,
{
type Output = U;
fn get(&self, point: T) -> Self::Output {
(self.source.get(point)).mul_add(self.scale, self.bias)
}
}