Skip to content

Commit e9723d4

Browse files
committed
rename several API members
1 parent f05b0cc commit e9723d4

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

sources/noise/noise.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ public
22
protocol Noise
33
{
44
init(amplitude:Double, frequency:Double, seed:Int)
5-
65
func evaluate(_ x:Double, _ y:Double) -> Double
76
func evaluate(_ x:Double, _ y:Double, _ z:Double) -> Double
87
func evaluate(_ x:Double, _ y:Double, _ z:Double, _ w:Double) -> Double
@@ -12,17 +11,17 @@ public
1211
extension Noise
1312
{
1413
public
15-
func sample_area(width:Int, height:Int) -> [(x:Double, y:Double, z:Double)]
14+
func sample_area(width:Int, height:Int) -> [(Double, Double, Double)]
1615
{
17-
var samples:[(x:Double, y:Double, z:Double)] = []
16+
var samples:[(Double, Double, Double)] = []
1817
samples.reserveCapacity(width * height)
1918
for i in 0 ..< height
2019
{
2120
for j in 0 ..< width
2221
{
2322
let x:Double = Double(i) + 0.5,
2423
y:Double = Double(j) + 0.5
25-
samples.append((x: x, y: y, z: self.evaluate(x, y)))
24+
samples.append((x, y, self.evaluate(x, y)))
2625
}
2726
}
2827
return samples
@@ -150,7 +149,7 @@ enum Math
150149
}
151150

152151
public
153-
struct fBm<Generator:Noise>:Noise
152+
struct FBM<Generator:Noise>:Noise
154153
{
155154
private
156155
let generators:[Generator]
@@ -212,7 +211,8 @@ struct fBm<Generator:Noise>:Noise
212211
}
213212
}
214213

215-
struct RandomXORShift
214+
public
215+
struct RandomXorshift
216216
{
217217
private
218218
var state128:(UInt32, UInt32, UInt32, UInt32)
@@ -266,7 +266,7 @@ struct PermutationTable
266266
init(seed:Int)
267267
{
268268
var permutations:[UInt8] = [UInt8](0 ... 255),
269-
rng:RandomXORShift = RandomXORShift(seed: seed)
269+
rng:RandomXorshift = RandomXorshift(seed: seed)
270270
for i in 0 ..< 255 - 1
271271
{
272272
permutations.swapAt(i, Int(rng.generate()) & 255)

sources/noise/poisson.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
public
2-
struct PoissonSampler
2+
struct DiskSampler2D
33
{
44
private
55
let candidate_ring:[Math.DoubleV2]
66

77
private
8-
var rng:RandomXORShift,
8+
var rng:RandomXorshift,
99
candidate_index:Int = 0
1010

1111
private
@@ -20,14 +20,14 @@ struct PoissonSampler
2020
public
2121
init(seed:Int = 0)
2222
{
23-
self.rng = RandomXORShift(seed: seed)
23+
self.rng = RandomXorshift(seed: seed)
2424
let rand_scale:Double = 4 / Double(self.rng.max)
2525

2626
var candidates_generated:Int = 0
2727
var candidate_ring:[Math.DoubleV2] = []
28-
candidate_ring.reserveCapacity(PoissonSampler.candidate_table_bitmask + 1)
28+
candidate_ring.reserveCapacity(DiskSampler2D.candidate_table_bitmask + 1)
2929

30-
while candidates_generated <= PoissonSampler.candidate_table_bitmask
30+
while candidates_generated <= DiskSampler2D.candidate_table_bitmask
3131
{
3232
let x:Double = Double(self.rng.generate()) * rand_scale - 1,
3333
y:Double = Double(self.rng.generate()) * rand_scale - 1,
@@ -72,15 +72,15 @@ struct PoissonSampler
7272
for _ in 0 ..< k
7373
{
7474
let candidate:Math.DoubleV2 = Math.add(front, self.candidate_offset)
75-
self.candidate_index = (self.candidate_index + 1) & PoissonSampler.candidate_table_bitmask
75+
self.candidate_index = (self.candidate_index + 1) & DiskSampler2D.candidate_table_bitmask
7676

7777
guard 0 ..< normalized_width ~= candidate.x && 0 ..< normalized_height ~= candidate.y
7878
else
7979
{
8080
continue
8181
}
8282

83-
if PoissonSampler.attempt_insert(candidate: candidate, into_grid: &grid, grid_stride: grid_stride)
83+
if DiskSampler2D.attempt_insert(candidate: candidate, into_grid: &grid, grid_stride: grid_stride)
8484
{
8585
points.append((candidate.x * radius, candidate.y * radius))
8686
queue.append(candidate)

tests/LinuxMain.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let png_properties:PNGProperties = PNGProperties(width: viewer_size, height: vie
2727

2828
var t0:Int
2929

30-
var poisson = PoissonSampler(seed: 0)
30+
var poisson = DiskSampler2D(seed: 0)
3131
t0 = clock()
3232
pixbuf = [UInt8](repeating: 0, count: viewer_size * viewer_size)
3333
for point:(x:Double, y:Double) in poisson.generate(radius: 10, width: viewer_size, height: viewer_size)
@@ -104,20 +104,20 @@ try {
104104
try png_encode(path: "cells3D.png", raw_data: pixbuf_color, properties: png_color)
105105
}()
106106

107-
let S:fBm<SimplexNoise2D> = fBm<SimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
107+
let S:fBm<SimplexNoise2D> = FBM<SimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
108108
t0 = clock()
109109
pixbuf = S.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
110110
print(clock() - t0)
111111
try png_encode(path: "simplex.png", raw_data: pixbuf, properties: png_properties)
112112

113113

114-
let SS:fBm<SuperSimplexNoise2D> = fBm<SuperSimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
114+
let SS:fBm<SuperSimplexNoise2D> = FBM<SuperSimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
115115
t0 = clock()
116116
pixbuf = SS.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
117117
print(clock() - t0)
118118
try png_encode(path: "super_simplex.png", raw_data: pixbuf, properties: png_properties)
119119

120-
let SS3D:fBm<SuperSimplexNoise3D> = fBm<SuperSimplexNoise3D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
120+
let SS3D:fBm<SuperSimplexNoise3D> = FBM<SuperSimplexNoise3D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
121121
t0 = clock()
122122
pixbuf = SS3D.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
123123
print(clock() - t0)

0 commit comments

Comments
 (0)