Skip to content

Commit 03becbc

Browse files
committed
get rid of Const enum
1 parent 1c496f9 commit 03becbc

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

sources/noise/gradient.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
fileprivate
2-
enum Const
3-
{
4-
static
5-
let SQUISH_2D :Double = 0.5 * (1 / 3.squareRoot() - 1),
6-
STRETCH_2D:Double = 0.5 * (3.squareRoot() - 1)
7-
}
8-
91
fileprivate
102
protocol _ClassicNoise3D
113
{
@@ -175,6 +167,10 @@ struct TilingClassicNoise3D:_ClassicNoise3D, HashedTilingNoise
175167
public
176168
struct SimplexNoise2D:HashedNoise
177169
{
170+
private static
171+
let SQUISH_2D :Double = 0.5 * (1 / 3.squareRoot() - 1),
172+
STRETCH_2D:Double = 0.5 * (3.squareRoot() - 1)
173+
178174
private static
179175
let gradient_table32:[Math.DoubleV2] =
180176
[
@@ -234,7 +230,7 @@ struct SimplexNoise2D:HashedNoise
234230
let sample:Math.DoubleV2 = (x * self.frequency, y * self.frequency)
235231
// transform our coordinate system so that the *simplex* (x, y) forms a
236232
// rectangular grid (u, v)
237-
let squish_offset:Double = (sample.x + sample.y) * Const.SQUISH_2D,
233+
let squish_offset:Double = (sample.x + sample.y) * SimplexNoise2D.SQUISH_2D,
238234
sample_uv:Math.DoubleV2 = (sample.x + squish_offset, sample.y + squish_offset)
239235

240236
// get integral (u, v) coordinates of the rhombus and get position inside
@@ -264,7 +260,7 @@ struct SimplexNoise2D:HashedNoise
264260
// do the same in the original (x, y) coordinate space
265261

266262
// stretch back to get (x, y) coordinates of rhombus origin
267-
let stretch_offset:Double = Double(bin.a + bin.b) * Const.STRETCH_2D,
263+
let stretch_offset:Double = Double(bin.a + bin.b) * SimplexNoise2D.STRETCH_2D,
268264
origin:Math.DoubleV2 = (Double(bin.a) + stretch_offset, Double(bin.b) + stretch_offset)
269265

270266
// get relative position inside the rhombus relative to (xb, xb)
@@ -279,27 +275,27 @@ struct SimplexNoise2D:HashedNoise
279275
}
280276

281277
// contribution from (1, 0)
282-
_inspect(point_offset: (1, 0), sample_offset: (1 + Const.STRETCH_2D, Const.STRETCH_2D))
278+
_inspect(point_offset: (1, 0), sample_offset: (1 + SimplexNoise2D.STRETCH_2D, SimplexNoise2D.STRETCH_2D))
283279

284280
// contribution from (0, 1)
285-
_inspect(point_offset: (0, 1), sample_offset: (Const.STRETCH_2D, 1 + Const.STRETCH_2D))
281+
_inspect(point_offset: (0, 1), sample_offset: (SimplexNoise2D.STRETCH_2D, 1 + SimplexNoise2D.STRETCH_2D))
286282

287283
// decide which triangle we are in
288284
let uv_sum:Double = sample_uv_rel.x + sample_uv_rel.y
289285
if (uv_sum > 1) // we are to the bottom-right of the diagonal line (du = 1 - dv)
290286
{
291-
_inspect(point_offset: (1, 1), sample_offset: (1 + 2*Const.STRETCH_2D, 1 + 2*Const.STRETCH_2D))
287+
_inspect(point_offset: (1, 1), sample_offset: (1 + 2*SimplexNoise2D.STRETCH_2D, 1 + 2*SimplexNoise2D.STRETCH_2D))
292288

293289
let center_dist:Double = 2 - uv_sum
294290
if center_dist < sample_uv_rel.x || center_dist < sample_uv_rel.y
295291
{
296292
if sample_uv_rel.x > sample_uv_rel.y
297293
{
298-
_inspect(point_offset: (2, 0), sample_offset: (2 + 2*Const.STRETCH_2D, 2*Const.STRETCH_2D))
294+
_inspect(point_offset: (2, 0), sample_offset: (2 + 2*SimplexNoise2D.STRETCH_2D, 2*SimplexNoise2D.STRETCH_2D))
299295
}
300296
else
301297
{
302-
_inspect(point_offset: (0, 2), sample_offset: (2*Const.STRETCH_2D, 2 + 2*Const.STRETCH_2D))
298+
_inspect(point_offset: (0, 2), sample_offset: (2*SimplexNoise2D.STRETCH_2D, 2 + 2*SimplexNoise2D.STRETCH_2D))
303299
}
304300
}
305301
else
@@ -325,7 +321,7 @@ struct SimplexNoise2D:HashedNoise
325321
}
326322
else
327323
{
328-
_inspect(point_offset: (1, 1), sample_offset: (1 + 2*Const.STRETCH_2D, 1 + 2*Const.STRETCH_2D))
324+
_inspect(point_offset: (1, 1), sample_offset: (1 + 2*SimplexNoise2D.STRETCH_2D, 1 + 2*SimplexNoise2D.STRETCH_2D))
329325
}
330326
}
331327

@@ -351,6 +347,10 @@ typealias SuperSimplexNoise2D = GradientNoise2D
351347
public
352348
struct GradientNoise2D:HashedNoise
353349
{
350+
private static
351+
let SQUISH_2D :Double = 0.5 * (1 / 3.squareRoot() - 1),
352+
STRETCH_2D:Double = 0.5 * (3.squareRoot() - 1)
353+
354354
private static
355355
let points:[(Math.IntV2, Math.DoubleV2)] =
356356
{
@@ -360,7 +360,7 @@ struct GradientNoise2D:HashedNoise
360360
@inline(__always)
361361
func _lattice_point(at point:Math.IntV2) -> (Math.IntV2, Math.DoubleV2)
362362
{
363-
let stretch_offset:Double = Double(point.a + point.b) * Const.SQUISH_2D
363+
let stretch_offset:Double = Double(point.a + point.b) * GradientNoise2D.SQUISH_2D
364364
return (point, (Double(point.a) + stretch_offset, Double(point.b) + stretch_offset))
365365
}
366366

@@ -437,7 +437,7 @@ struct GradientNoise2D:HashedNoise
437437
{
438438
let sample:Math.DoubleV2 = (x * self.frequency, y * self.frequency)
439439
// transform our (x, y) coordinate to (u, v) space
440-
let stretch_offset:Double = (sample.x + sample.y) * Const.STRETCH_2D,
440+
let stretch_offset:Double = (sample.x + sample.y) * GradientNoise2D.STRETCH_2D,
441441
sample_uv:Math.DoubleV2 = (sample.x + stretch_offset, sample.y + stretch_offset)
442442

443443
// (0, 0) ----- (1, 0)
@@ -546,7 +546,7 @@ struct GradientNoise2D:HashedNoise
546546
*/
547547

548548
// get the relative offset from (0, 0)
549-
let squish_offset:Double = (sample_uv_rel.x + sample_uv_rel.y) * Const.SQUISH_2D,
549+
let squish_offset:Double = (sample_uv_rel.x + sample_uv_rel.y) * GradientNoise2D.SQUISH_2D,
550550
sample_rel:Math.DoubleV2 = (sample_uv_rel.x + squish_offset, sample_uv_rel.y + squish_offset)
551551

552552
var Σ:Double = 0

0 commit comments

Comments
 (0)