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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use crate::noise_fns::NoiseFn;
pub struct Displace<Source, XDisplace, YDisplace, ZDisplace, UDisplace> {
pub source: Source,
pub x_displace: XDisplace,
pub y_displace: YDisplace,
pub z_displace: ZDisplace,
pub u_displace: UDisplace,
}
impl<Source, XDisplace, YDisplace, ZDisplace, UDisplace>
Displace<Source, XDisplace, YDisplace, ZDisplace, UDisplace>
{
pub fn new(
source: Source,
x_displace: XDisplace,
y_displace: YDisplace,
z_displace: ZDisplace,
u_displace: UDisplace,
) -> Self {
Self {
source,
x_displace,
y_displace,
z_displace,
u_displace,
}
}
}
impl<Source, XDisplace, YDisplace, ZDisplace, UDisplace> NoiseFn<f64, 2>
for Displace<Source, XDisplace, YDisplace, ZDisplace, UDisplace>
where
Source: NoiseFn<f64, 2>,
XDisplace: NoiseFn<f64, 2>,
YDisplace: NoiseFn<f64, 2>,
{
fn get(&self, point: [f64; 2]) -> f64 {
let x = point[0] + self.x_displace.get(point);
let y = point[1] + self.y_displace.get(point);
self.source.get([x, y])
}
}
impl<Source, XDisplace, YDisplace, ZDisplace, UDisplace> NoiseFn<f64, 3>
for Displace<Source, XDisplace, YDisplace, ZDisplace, UDisplace>
where
Source: NoiseFn<f64, 3>,
XDisplace: NoiseFn<f64, 3>,
YDisplace: NoiseFn<f64, 3>,
ZDisplace: NoiseFn<f64, 3>,
{
fn get(&self, point: [f64; 3]) -> f64 {
let x = point[0] + self.x_displace.get(point);
let y = point[1] + self.y_displace.get(point);
let z = point[2] + self.z_displace.get(point);
self.source.get([x, y, z])
}
}
impl<Source, XDisplace, YDisplace, ZDisplace, UDisplace> NoiseFn<f64, 4>
for Displace<Source, XDisplace, YDisplace, ZDisplace, UDisplace>
where
Source: NoiseFn<f64, 4>,
XDisplace: NoiseFn<f64, 4>,
YDisplace: NoiseFn<f64, 4>,
ZDisplace: NoiseFn<f64, 4>,
UDisplace: NoiseFn<f64, 4>,
{
fn get(&self, point: [f64; 4]) -> f64 {
let x = point[0] + self.x_displace.get(point);
let y = point[1] + self.y_displace.get(point);
let z = point[2] + self.z_displace.get(point);
let u = point[3] + self.u_displace.get(point);
self.source.get([x, y, z, u])
}
}