@@ -19,8 +19,8 @@ extension Noise
19
19
{
20
20
for j in 0 ..< width
21
21
{
22
- let x : Double = Double ( i ) + 0.5 ,
23
- y : Double = Double ( j ) + 0.5
22
+ let x : Double = Double ( j ) + 0.5 ,
23
+ y : Double = Double ( i ) + 0.5
24
24
samples. append ( ( x, y, self . evaluate ( x, y) ) )
25
25
}
26
26
}
@@ -32,11 +32,55 @@ extension Noise
32
32
{
33
33
var samples : [ UInt8 ] = [ ]
34
34
samples. reserveCapacity ( width * height)
35
- for y in 0 ..< height
35
+ for i in 0 ..< height
36
+ {
37
+ for j in 0 ..< width
38
+ {
39
+ let x : Double = Double ( j) + 0.5 ,
40
+ y : Double = Double ( i) + 0.5
41
+ samples. append ( UInt8 ( max ( 0 , min ( 255 , self . evaluate ( x, y) + offset) ) ) )
42
+ }
43
+ }
44
+ return samples
45
+ }
46
+
47
+ public
48
+ func sample_volume( width: Int , height: Int , depth: Int ) -> [ ( Double , Double , Double , Double ) ]
49
+ {
50
+ var samples : [ ( Double , Double , Double , Double ) ] = [ ]
51
+ samples. reserveCapacity ( width * height * depth)
52
+ for i in 0 ..< depth
53
+ {
54
+ for j in 0 ..< height
55
+ {
56
+ for k in 0 ..< width
57
+ {
58
+ let x : Double = Double ( k) + 0.5 ,
59
+ y : Double = Double ( j) + 0.5 ,
60
+ z : Double = Double ( i) + 0.5
61
+ samples. append ( ( x, y, z, self . evaluate ( x, y, z) ) )
62
+ }
63
+ }
64
+ }
65
+ return samples
66
+ }
67
+
68
+ public
69
+ func sample_volume_saturated_to_u8( width: Int , height: Int , depth: Int , offset: Double = 0.5 ) -> [ UInt8 ]
70
+ {
71
+ var samples : [ UInt8 ] = [ ]
72
+ samples. reserveCapacity ( width * height * depth)
73
+ for i in 0 ..< depth
36
74
{
37
- for x in 0 ..< width
75
+ for j in 0 ..< height
38
76
{
39
- samples. append ( UInt8 ( max ( 0 , min ( 255 , self . evaluate ( Double ( x) , Double ( y) ) + offset) ) ) )
77
+ for k in 0 ..< width
78
+ {
79
+ let x : Double = Double ( k) + 0.5 ,
80
+ y : Double = Double ( j) + 0.5 ,
81
+ z : Double = Double ( i) + 0.5
82
+ samples. append ( UInt8 ( max ( 0 , min ( 255 , self . evaluate ( x, y, z) + offset) ) ) )
83
+ }
40
84
}
41
85
}
42
86
return samples
0 commit comments