@@ -20,9 +20,9 @@ const (
20
20
type Perlin struct {
21
21
alpha float64
22
22
beta float64
23
- n int
23
+ n int32
24
24
25
- p [B + B + 2 ]int
25
+ p [B + B + 2 ]int32
26
26
g3 [B + B + 2 ][3 ]float64
27
27
g2 [B + B + 2 ][2 ]float64
28
28
g1 [B + B + 2 ]float64
@@ -33,7 +33,7 @@ type Perlin struct {
33
33
// Typically it is 2, As this approaches 1 the function is noisier.
34
34
// "beta" is the harmonic scaling/spacing, typically 2, n is the
35
35
// number of iterations and seed is the math.rand seed value to use
36
- func NewPerlin (alpha , beta float64 , n int , seed int64 ) * Perlin {
36
+ func NewPerlin (alpha , beta float64 , n int32 , seed int64 ) * Perlin {
37
37
return NewPerlinRandSource (alpha , beta , n , rand .NewSource (seed ))
38
38
}
39
39
@@ -42,9 +42,9 @@ func NewPerlin(alpha, beta float64, n int, seed int64) *Perlin {
42
42
// Typically it is 2, As this approaches 1 the function is noisier.
43
43
// "beta" is the harmonic scaling/spacing, typically 2, n is the
44
44
// number of iterations and source is source of pseudo-random int64 values
45
- func NewPerlinRandSource (alpha , beta float64 , n int , source rand.Source ) * Perlin {
45
+ func NewPerlinRandSource (alpha , beta float64 , n int32 , source rand.Source ) * Perlin {
46
46
var p Perlin
47
- var i , j , k int
47
+ var i , j , k int32
48
48
49
49
p .alpha = alpha
50
50
p .beta = beta
@@ -54,23 +54,23 @@ func NewPerlinRandSource(alpha, beta float64, n int, source rand.Source) *Perlin
54
54
55
55
for i = 0 ; i < B ; i ++ {
56
56
p .p [i ] = i
57
- p .g1 [i ] = float64 ((r .Int ()% (B + B ))- B ) / B
57
+ p .g1 [i ] = float64 ((r .Int31 ()% (B + B ))- B ) / B
58
58
59
59
for j = 0 ; j < 2 ; j ++ {
60
- p.g2 [i ][j ] = float64 ((r .Int ()% (B + B ))- B ) / B
60
+ p.g2 [i ][j ] = float64 ((r .Int31 ()% (B + B ))- B ) / B
61
61
}
62
62
63
63
normalize2 (& p .g2 [i ])
64
64
65
65
for j = 0 ; j < 3 ; j ++ {
66
- p.g3 [i ][j ] = float64 ((r .Int ()% (B + B ))- B ) / B
66
+ p.g3 [i ][j ] = float64 ((r .Int31 ()% (B + B ))- B ) / B
67
67
}
68
68
normalize3 (& p .g3 [i ])
69
69
}
70
70
71
71
for ; i > 0 ; i -- {
72
72
k = p .p [i ]
73
- j = r .Int () % B
73
+ j = r .Int31 () % B
74
74
p .p [i ] = p .p [j ]
75
75
p .p [j ] = k
76
76
}
@@ -123,9 +123,9 @@ func (p *Perlin) noise1(arg float64) float64 {
123
123
vec [0 ] = arg
124
124
125
125
t := vec [0 ] + N
126
- bx0 := int (t ) & BM
126
+ bx0 := int32 (t ) & BM
127
127
bx1 := (bx0 + 1 ) & BM
128
- rx0 := t - float64 (int (t ))
128
+ rx0 := t - float64 (int32 (t ))
129
129
rx1 := rx0 - 1.
130
130
131
131
sx := sCurve (rx0 )
@@ -137,15 +137,15 @@ func (p *Perlin) noise1(arg float64) float64 {
137
137
138
138
func (p * Perlin ) noise2 (vec [2 ]float64 ) float64 {
139
139
t := vec [0 ] + N
140
- bx0 := int (t ) & BM
140
+ bx0 := int32 (t ) & BM
141
141
bx1 := (bx0 + 1 ) & BM
142
- rx0 := t - float64 (int (t ))
142
+ rx0 := t - float64 (int32 (t ))
143
143
rx1 := rx0 - 1.
144
144
145
145
t = vec [1 ] + N
146
- by0 := int (t ) & BM
146
+ by0 := int32 (t ) & BM
147
147
by1 := (by0 + 1 ) & BM
148
- ry0 := t - float64 (int (t ))
148
+ ry0 := t - float64 (int32 (t ))
149
149
ry1 := ry0 - 1.
150
150
151
151
i := p .p [bx0 ]
@@ -176,21 +176,21 @@ func (p *Perlin) noise2(vec [2]float64) float64 {
176
176
177
177
func (p * Perlin ) noise3 (vec [3 ]float64 ) float64 {
178
178
t := vec [0 ] + N
179
- bx0 := int (t ) & BM
179
+ bx0 := int32 (t ) & BM
180
180
bx1 := (bx0 + 1 ) & BM
181
- rx0 := t - float64 (int (t ))
181
+ rx0 := t - float64 (int32 (t ))
182
182
rx1 := rx0 - 1.
183
183
184
184
t = vec [1 ] + N
185
- by0 := int (t ) & BM
185
+ by0 := int32 (t ) & BM
186
186
by1 := (by0 + 1 ) & BM
187
- ry0 := t - float64 (int (t ))
187
+ ry0 := t - float64 (int32 (t ))
188
188
ry1 := ry0 - 1.
189
189
190
190
t = vec [2 ] + N
191
- bz0 := int (t ) & BM
191
+ bz0 := int32 (t ) & BM
192
192
bz1 := (bz0 + 1 ) & BM
193
- rz0 := t - float64 (int (t ))
193
+ rz0 := t - float64 (int32 (t ))
194
194
rz1 := rz0 - 1.
195
195
196
196
i := p .p [bx0 ]
@@ -240,10 +240,10 @@ func (p *Perlin) noise3(vec [3]float64) float64 {
240
240
func (p * Perlin ) Noise1D (x float64 ) float64 {
241
241
var scale float64 = 1
242
242
var sum , val float64
243
-
243
+ var i int32
244
244
px := x
245
245
246
- for i : = 0 ; i < p .n ; i ++ {
246
+ for i = 0 ; i < p .n ; i ++ {
247
247
val = p .noise1 (px )
248
248
sum += val / scale
249
249
scale *= p .alpha
@@ -257,11 +257,12 @@ func (p *Perlin) Noise2D(x, y float64) float64 {
257
257
var scale float64 = 1
258
258
var sum , val float64
259
259
var px [2 ]float64
260
+ var i int32
260
261
261
262
px [0 ] = x
262
263
px [1 ] = y
263
264
264
- for i : = 0 ; i < p .n ; i ++ {
265
+ for i = 0 ; i < p .n ; i ++ {
265
266
val = p .noise2 (px )
266
267
sum += val / scale
267
268
scale *= p .alpha
@@ -276,6 +277,7 @@ func (p *Perlin) Noise3D(x, y, z float64) float64 {
276
277
var scale float64 = 1
277
278
var sum , val float64
278
279
var px [3 ]float64
280
+ var i int32
279
281
280
282
if z < 0.0000 {
281
283
return p .Noise2D (x , y )
@@ -285,7 +287,7 @@ func (p *Perlin) Noise3D(x, y, z float64) float64 {
285
287
px [1 ] = y
286
288
px [2 ] = z
287
289
288
- for i : = 0 ; i < p .n ; i ++ {
290
+ for i = 0 ; i < p .n ; i ++ {
289
291
val = p .noise3 (px )
290
292
sum += val / scale
291
293
scale *= p .alpha
0 commit comments