From 6251098e4a499e4030ec4ca7fdd18e9bb0a787ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Pottier?= Date: Thu, 28 Nov 2024 16:07:36 +0100 Subject: [PATCH] rename functions --- noise/noise.v | 5 +- noise/perlin.v | 126 ++++++++++++++++++++++++++++++++++++++++++ noise/perlin2d.v | 61 -------------------- noise/perlin2d_test.v | 16 ------ noise/perlin3d.v | 62 --------------------- noise/perlin3d_test.v | 16 ------ noise/perlin_test.v | 22 ++++++++ noise/simplex.v | 71 ++++++++++++------------ noise/simplex_test.v | 24 ++++---- 9 files changed, 197 insertions(+), 206 deletions(-) create mode 100644 noise/perlin.v delete mode 100644 noise/perlin2d.v delete mode 100644 noise/perlin2d_test.v delete mode 100644 noise/perlin3d.v delete mode 100644 noise/perlin3d_test.v create mode 100644 noise/perlin_test.v diff --git a/noise/noise.v b/noise/noise.v index f5c1aa994..a770fd7f9 100644 --- a/noise/noise.v +++ b/noise/noise.v @@ -14,7 +14,6 @@ pub fn Generator.new() Generator { } // randomize is a function that shuffle the permutation set inside the Generator struct -// will not shuffle if rand.seed is not changed -pub fn (mut generator Generator) randomize() { - generator.perm = rand.shuffle_clone(permutations) or { panic(err) } +pub fn (mut gen Generator) randomize() { + gen.perm = rand.shuffle_clone(permutations) or { panic(err) } } diff --git a/noise/perlin.v b/noise/perlin.v new file mode 100644 index 000000000..ca186219c --- /dev/null +++ b/noise/perlin.v @@ -0,0 +1,126 @@ +module noise + +// perlin_2d is a function that return a single value of perlin gen for a given 2d position +pub fn (gen Generator) perlin_2d(x f64, y f64) f64 { + xi := int(x) & 0xFF + yi := int(y) & 0xFF + + xf := x - int(x) + yf := y - int(y) + + u := fade(xf) + v := fade(yf) + + pxi := gen.perm[xi] + pxi1 := gen.perm[xi + 1] + + aa := gen.perm[pxi + yi] + ab := gen.perm[pxi + yi + 1] + ba := gen.perm[pxi1 + yi] + bb := gen.perm[pxi1 + yi + 1] + + x1 := lerp(perlin_grad_2d(aa, xf, yf), perlin_grad_2d(ba, xf - 1, yf), u) + x2 := lerp(perlin_grad_2d(ab, xf, yf - 1), perlin_grad_2d(bb, xf - 1, yf - 1), u) + + return (lerp(x1, x2, v) + 1) / 2 +} + +// perlin_3d is a function that return a single value of perlin gen for a given 3d position +pub fn (gen Generator) perlin_3d(x f64, y f64, z f64) f64 { + xi := int(x) & 0xFF + yi := int(y) & 0xFF + zi := int(z) & 0xFF + xf := x - int(x) + yf := y - int(y) + zf := z - int(z) + u := fade(xf) + v := fade(yf) + w := fade(zf) + + pxi := gen.perm[xi] + pxi_yi := gen.perm[pxi + yi] + pxi_yi1 := gen.perm[pxi + yi + 1] + pxi1 := gen.perm[xi + 1] + pxi1_yi := gen.perm[pxi1 + yi] + pxi1_yi1 := gen.perm[pxi1 + yi + 1] + + aaa := gen.perm[pxi_yi + zi] + aba := gen.perm[pxi_yi1 + zi] + aab := gen.perm[pxi_yi + zi + 1] + abb := gen.perm[pxi_yi1 + zi + 1] + baa := gen.perm[pxi1_yi + zi] + bba := gen.perm[pxi1_yi1 + zi] + bab := gen.perm[pxi1_yi + zi + 1] + bbb := gen.perm[pxi1_yi1 + zi + 1] + + mut x1 := lerp(perlin_grad_3d(aaa, xf, yf, zf), perlin_grad_3d(baa, xf - 1, yf, zf), + u) + mut x2 := lerp(perlin_grad_3d(aba, xf, yf - 1, zf), perlin_grad_3d(bba, xf - 1, yf - 1, + zf), u) + y1 := lerp(x1, x2, v) + x1 = lerp(perlin_grad_3d(aab, xf, yf, zf - 1), perlin_grad_3d(bab, xf - 1, yf, zf - 1), + u) + x2 = lerp(perlin_grad_3d(abb, xf, yf - 1, zf - 1), perlin_grad_3d(bbb, xf - 1, yf - 1, + zf - 1), u) + y2 := lerp(x1, x2, v) + + return (lerp(y1, y2, w) + 1) / 2 +} + +// perlin_grad_3d is a function that returns a single value of gradient gen for a given 3d position +fn perlin_grad_3d(hash int, x f64, y f64, z f64) f64 { + match hash & 0xF { + 0x0 { return x + y } + 0x1 { return -x + y } + 0x2 { return x - y } + 0x3 { return -x - y } + 0x4 { return x + z } + 0x5 { return -x + z } + 0x6 { return x - z } + 0x7 { return -x - z } + 0x8 { return y + z } + 0x9 { return -y + z } + 0xA { return y - z } + 0xB { return -y - z } + 0xC { return y + x } + 0xD { return -y + z } + 0xE { return y - x } + 0xF { return -y - z } + else { return 0 } + } +} + +// lerp is a function that return a linear interpolation value for 2 given values and a factor +@[inline] +fn lerp(a f64, b f64, x f64) f64 { + return a + x * (b - a) +} + +// fade is a function that return a fade value for a given value +@[inline] +fn fade(t f64) f64 { + return t * t * t * (t * (t * 6.0 - 15.0) + 10.0) +} + +// perlin_grad_2d is a function that return a gradient value for a given hash and 2d position +fn perlin_grad_2d(hash int, x f64, y f64) f64 { + match hash & 0xF { + 0x0 { return x + y } + 0x1 { return -x + y } + 0x2 { return x - y } + 0x3 { return -x - y } + 0x4 { return x } + 0x5 { return -x } + 0x6 { return x } + 0x7 { return -x } + 0x8 { return y } + 0x9 { return -y } + 0xA { return y } + 0xB { return -y } + 0xC { return y + x } + 0xD { return -y } + 0xE { return y - x } + 0xF { return -y } + else { return 0 } + } +} diff --git a/noise/perlin2d.v b/noise/perlin2d.v deleted file mode 100644 index 0b60ffda0..000000000 --- a/noise/perlin2d.v +++ /dev/null @@ -1,61 +0,0 @@ -module noise - -// perlin2d is a function that return a single value of perlin noise for a given 2d position -pub fn (generator Generator) perlin2d(x f64, y f64) f64 { - xi := int(x) & 0xFF - yi := int(y) & 0xFF - - xf := x - int(x) - yf := y - int(y) - - u := fade(xf) - v := fade(yf) - - pxi := generator.perm[xi] - pxi1 := generator.perm[xi + 1] - - aa := generator.perm[pxi + yi] - ab := generator.perm[pxi + yi + 1] - ba := generator.perm[pxi1 + yi] - bb := generator.perm[pxi1 + yi + 1] - - x1 := lerp(grad2d(aa, xf, yf), grad2d(ba, xf - 1, yf), u) - x2 := lerp(grad2d(ab, xf, yf - 1), grad2d(bb, xf - 1, yf - 1), u) - - return (lerp(x1, x2, v) + 1) / 2 -} - -// fade is a function that return a fade value for a given value -@[inline] -fn fade(t f64) f64 { - return t * t * t * (t * (t * 6.0 - 15.0) + 10.0) -} - -// grad2d is a function that return a gradient value for a given hash and 2d position -fn grad2d(hash int, x f64, y f64) f64 { - match hash & 0xF { - 0x0 { return x + y } - 0x1 { return -x + y } - 0x2 { return x - y } - 0x3 { return -x - y } - 0x4 { return x } - 0x5 { return -x } - 0x6 { return x } - 0x7 { return -x } - 0x8 { return y } - 0x9 { return -y } - 0xA { return y } - 0xB { return -y } - 0xC { return y + x } - 0xD { return -y } - 0xE { return y - x } - 0xF { return -y } - else { return 0 } - } -} - -// lerp is a function that return a linear interpolation value for a given 2 values and a factor -@[inline] -fn lerp(a f64, b f64, x f64) f64 { - return a + x * (b - a) -} diff --git a/noise/perlin2d_test.v b/noise/perlin2d_test.v deleted file mode 100644 index f63a5d3e2..000000000 --- a/noise/perlin2d_test.v +++ /dev/null @@ -1,16 +0,0 @@ -module noise - -import rand -import vsl.float.float64 - -fn test_perlin2d() { - rand.seed([u32(3155200429), u32(3208395956)]) - - mut gen := Generator.new() - gen.randomize() - - result := gen.perlin2d(0.125, 0.125) - expected := 0.4948387311305851 - - assert float64.tolerance(result, expected, 1.0e-6) -} diff --git a/noise/perlin3d.v b/noise/perlin3d.v deleted file mode 100644 index 9b77e820b..000000000 --- a/noise/perlin3d.v +++ /dev/null @@ -1,62 +0,0 @@ -module noise - -// perlin3d is a function that return a single value of perlin noise for a given 3d position -pub fn (generator Generator) perlin3d(x f64, y f64, z f64) f64 { - xi := int(x) & 0xFF - yi := int(y) & 0xFF - zi := int(z) & 0xFF - xf := x - int(x) - yf := y - int(y) - zf := z - int(z) - u := fade(xf) - v := fade(yf) - w := fade(zf) - - pxi := generator.perm[xi] - pxi_yi := generator.perm[pxi + yi] - pxi_yi1 := generator.perm[pxi + yi + 1] - pxi1 := generator.perm[xi + 1] - pxi1_yi := generator.perm[pxi1 + yi] - pxi1_yi1 := generator.perm[pxi1 + yi + 1] - - aaa := generator.perm[pxi_yi + zi] - aba := generator.perm[pxi_yi1 + zi] - aab := generator.perm[pxi_yi + zi + 1] - abb := generator.perm[pxi_yi1 + zi + 1] - baa := generator.perm[pxi1_yi + zi] - bba := generator.perm[pxi1_yi1 + zi] - bab := generator.perm[pxi1_yi + zi + 1] - bbb := generator.perm[pxi1_yi1 + zi + 1] - - mut x1 := lerp(grad3d(aaa, xf, yf, zf), grad3d(baa, xf - 1, yf, zf), u) - mut x2 := lerp(grad3d(aba, xf, yf - 1, zf), grad3d(bba, xf - 1, yf - 1, zf), u) - y1 := lerp(x1, x2, v) - x1 = lerp(grad3d(aab, xf, yf, zf - 1), grad3d(bab, xf - 1, yf, zf - 1), u) - x2 = lerp(grad3d(abb, xf, yf - 1, zf - 1), grad3d(bbb, xf - 1, yf - 1, zf - 1), u) - y2 := lerp(x1, x2, v) - - return (lerp(y1, y2, w) + 1) / 2 -} - -// grad3d is a function that returns a single value of gradient noise for a given 3d position -fn grad3d(hash int, x f64, y f64, z f64) f64 { - match hash & 0xF { - 0x0 { return x + y } - 0x1 { return -x + y } - 0x2 { return x - y } - 0x3 { return -x - y } - 0x4 { return x + z } - 0x5 { return -x + z } - 0x6 { return x - z } - 0x7 { return -x - z } - 0x8 { return y + z } - 0x9 { return -y + z } - 0xA { return y - z } - 0xB { return -y - z } - 0xC { return y + x } - 0xD { return -y + z } - 0xE { return y - x } - 0xF { return -y - z } - else { return 0 } - } -} diff --git a/noise/perlin3d_test.v b/noise/perlin3d_test.v deleted file mode 100644 index 0f5a67aed..000000000 --- a/noise/perlin3d_test.v +++ /dev/null @@ -1,16 +0,0 @@ -module noise - -import rand -import vsl.float.float64 - -fn test_perlin3d() { - rand.seed([u32(3155200429), u32(3208395956)]) - - mut gen := Generator.new() - gen.randomize() - - result := gen.perlin3d(0.125, 0.125, 0.125) - expected := 0.3713334855776509 - - assert float64.tolerance(result, expected, 1.0e-6) -} diff --git a/noise/perlin_test.v b/noise/perlin_test.v new file mode 100644 index 000000000..7f336d97e --- /dev/null +++ b/noise/perlin_test.v @@ -0,0 +1,22 @@ +module noise + +import rand +import vsl.float.float64 + +fn test_perlin_2d() { + rand.seed([u32(3155200429), u32(3208395956)]) + mut gen := Generator.new() + gen.randomize() + result := gen.perlin_2d(0.125, 0.125) + expected := 0.4948387311305851 + assert float64.tolerance(result, expected, 1.0e-6) +} + +fn test_perlin_3d() { + rand.seed([u32(3155200429), u32(3208395956)]) + mut gen := Generator.new() + gen.randomize() + result := gen.perlin_3d(0.125, 0.125, 0.125) + expected := 0.3713334855776509 + assert float64.tolerance(result, expected, 1.0e-6) +} diff --git a/noise/simplex.v b/noise/simplex.v index 202fe7b2b..2af1e7def 100644 --- a/noise/simplex.v +++ b/noise/simplex.v @@ -25,16 +25,16 @@ const simplex := [ ] // vfmt on -// grad_1d returns a gradient value for a given hash and x position -fn grad_1d(hash int, x f64) f64 { +// simplex_grad_1d returns a gradient value for a given hash and x position +fn simplex_grad_1d(hash int, x f64) f64 { h := hash & 15 mut grad := 1.0 + f64(h & 7) grad = if h & 8 == 0 { grad } else { -grad } return grad * x } -// grad_2d returns a gradient value for a given hash and x, y position -fn grad_2d(hash int, x f64, y f64) f64 { +// simplex_grad_2d returns a gradient value for a given hash and x, y position +fn simplex_grad_2d(hash int, x f64, y f64) f64 { h := hash & 7 u := if h < 4 { x } else { y } v := if h < 4 { y } else { x } @@ -49,8 +49,8 @@ fn grad_2d(hash int, x f64, y f64) f64 { }) } -// grad_3d returns a gradient value for a given hash and x, y, z position -fn grad_3d(hash int, x f64, y f64, z f64) f64 { +// simplex_grad_3d returns a gradient value for a given hash and x, y, z position +fn simplex_grad_3d(hash int, x f64, y f64, z f64) f64 { h := hash & 15 u := if h < 8 { x } else { y } v := if h < 4 { @@ -69,8 +69,8 @@ fn grad_3d(hash int, x f64, y f64, z f64) f64 { }) } -// grad_4d returns a gradient value for a given hash and x, y, z, t position -fn grad_4d(hash int, x f64, y f64, z f64, t f64) f64 { +// simplex_grad_4d returns a gradient value for a given hash and x, y, z, t position +fn simplex_grad_4d(hash int, x f64, y f64, z f64, t f64) f64 { h := hash & 31 u := if h < 24 { x } else { y } v := if h < 16 { y } else { z } @@ -91,7 +91,7 @@ fn grad_4d(hash int, x f64, y f64, z f64, t f64) f64 { } // simplex_1d returns a simplex noise value for a given x position -pub fn (generator Generator) simplex_1d(x f64) f64 { +pub fn (gen Generator) simplex_1d(x f64) f64 { i0 := int(x) i1 := i0 + 1 x0 := x - i0 @@ -99,17 +99,17 @@ pub fn (generator Generator) simplex_1d(x f64) f64 { mut t0 := 1.0 - x0 * x0 t0 *= t0 - n0 := t0 * t0 * grad_1d(generator.perm[i0 & 0xff], x0) + n0 := t0 * t0 * simplex_grad_1d(gen.perm[i0 & 0xff], x0) mut t1 := 1.0 - x1 * x1 t1 *= t1 - n1 := t1 * t1 * grad_1d(generator.perm[i1 & 0xff], x1) + n1 := t1 * t1 * simplex_grad_1d(gen.perm[i1 & 0xff], x1) return 0.395 * (n0 + n1) } // simplex_2d returns a simplex noise value for a given x, y position -pub fn (generator Generator) simplex_2d(x f64, y f64) f64 { +pub fn (gen Generator) simplex_2d(x f64, y f64) f64 { s := (x + y) * f2 i := int(x + s) j := int(y + s) @@ -138,7 +138,7 @@ pub fn (generator Generator) simplex_2d(x f64, y f64) f64 { n0 = 0.0 } else { t0 *= t0 - n0 = t0 * t0 * grad_2d(generator.perm[ii + generator.perm[jj]], x0, y0) + n0 = t0 * t0 * simplex_grad_2d(gen.perm[ii + gen.perm[jj]], x0, y0) } mut t1 := 0.5 - x1 * x1 - y1 * y1 @@ -147,8 +147,7 @@ pub fn (generator Generator) simplex_2d(x f64, y f64) f64 { n1 = 0.0 } else { t1 *= t1 - n1 = t1 * t1 * grad_2d(generator.perm[ii + i1 + generator.perm[jj + j1]], x1, - y1) + n1 = t1 * t1 * simplex_grad_2d(gen.perm[ii + i1 + gen.perm[jj + j1]], x1, y1) } mut t2 := 0.5 - x2 * x2 - y2 * y2 @@ -157,14 +156,14 @@ pub fn (generator Generator) simplex_2d(x f64, y f64) f64 { n2 = 0.0 } else { t2 *= t2 - n2 = t2 * t2 * grad_2d(generator.perm[ii + 1 + generator.perm[jj + 1]], x2, y2) + n2 = t2 * t2 * simplex_grad_2d(gen.perm[ii + 1 + gen.perm[jj + 1]], x2, y2) } return 40.0 * (n0 + n1 + n2) } // simplex_3d returns a simplex noise value for a given x, y, z position -pub fn (generator Generator) simplex_3d(x f64, y f64, z f64) f64 { +pub fn (gen Generator) simplex_3d(x f64, y f64, z f64) f64 { s := (x + y + z) * f3 xs := x + s ys := y + s @@ -235,8 +234,8 @@ pub fn (generator Generator) simplex_3d(x f64, y f64, z f64) f64 { n0 = 0.0 } else { t0 *= t0 - n0 = t0 * t0 * grad_3d(generator.perm[ii + generator.perm[jj + generator.perm[kk]]], - x0, y0, z0) + n0 = t0 * t0 * simplex_grad_3d(gen.perm[ii + gen.perm[jj + gen.perm[kk]]], x0, + y0, z0) } mut t1 := 0.6 - x1 * x1 - y1 * y1 - z1 * z1 @@ -245,8 +244,8 @@ pub fn (generator Generator) simplex_3d(x f64, y f64, z f64) f64 { n1 = 0.0 } else { t1 *= t1 - n1 = t1 * t1 * grad_3d(generator.perm[ii + i1 + generator.perm[jj + j1 + generator.perm[kk + - k1]]], x1, y1, z1) + n1 = t1 * t1 * simplex_grad_3d(gen.perm[ii + i1 + gen.perm[jj + j1 + gen.perm[kk + k1]]], + x1, y1, z1) } mut t2 := 0.6 - x2 * x2 - y2 * y2 - z2 * z2 @@ -255,8 +254,8 @@ pub fn (generator Generator) simplex_3d(x f64, y f64, z f64) f64 { n2 = 0.0 } else { t2 *= t2 - n2 = t2 * t2 * grad_3d(generator.perm[ii + i2 + generator.perm[jj + j2 + generator.perm[kk + - k2]]], x2, y2, z2) + n2 = t2 * t2 * simplex_grad_3d(gen.perm[ii + i2 + gen.perm[jj + j2 + gen.perm[kk + k2]]], + x2, y2, z2) } mut t3 := 0.6 - x3 * x3 - y3 * y3 - z3 * z3 @@ -265,15 +264,15 @@ pub fn (generator Generator) simplex_3d(x f64, y f64, z f64) f64 { n3 = 0.0 } else { t3 *= t3 - n3 = t3 * t3 * grad_3d(generator.perm[ii + 1 + generator.perm[jj + 1 + generator.perm[kk + - 1]]], x3, y3, z3) + n3 = t3 * t3 * simplex_grad_3d(gen.perm[ii + 1 + gen.perm[jj + 1 + gen.perm[kk + 1]]], + x3, y3, z3) } return 32.0 * (n0 + n1 + n2 + n3) } // simplex_4d returns a simplex noise value for a given x, y, z, w position -pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { +pub fn (gen Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { s := (x + y + z + w) * f4 xs := x + s ys := y + s @@ -341,8 +340,8 @@ pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { n0 = 0.0 } else { t0 *= t0 - n0 = t0 * t0 * grad_4d(generator.perm[ii + generator.perm[jj + generator.perm[kk + - generator.perm[ll]]]], x0, y0, z0, w0) + n0 = t0 * t0 * simplex_grad_4d(gen.perm[ii + gen.perm[jj + gen.perm[kk + gen.perm[ll]]]], + x0, y0, z0, w0) } mut t1 := 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1 @@ -351,8 +350,8 @@ pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { n1 = 0.0 } else { t1 *= t1 - n1 = t1 * t1 * grad_4d(generator.perm[ii + i1 + generator.perm[jj + j1 + generator.perm[kk + - k1 + generator.perm[ll + l1]]]], x1, y1, z1, w1) + n1 = t1 * t1 * simplex_grad_4d(gen.perm[ii + i1 + gen.perm[jj + j1 + gen.perm[kk + k1 + + gen.perm[ll + l1]]]], x1, y1, z1, w1) } mut t2 := 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2 @@ -361,8 +360,8 @@ pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { n2 = 0.0 } else { t2 *= t2 - n2 = t2 * t2 * grad_4d(generator.perm[ii + i2 + generator.perm[jj + j2 + generator.perm[kk + - k2 + generator.perm[ll + l2]]]], x2, y2, z2, w2) + n2 = t2 * t2 * simplex_grad_4d(gen.perm[ii + i2 + gen.perm[jj + j2 + gen.perm[kk + k2 + + gen.perm[ll + l2]]]], x2, y2, z2, w2) } mut t3 := 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3 @@ -371,8 +370,8 @@ pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { n3 = 0.0 } else { t3 *= t3 - n3 = t3 * t3 * grad_4d(generator.perm[ii + i3 + generator.perm[jj + j3 + generator.perm[kk + - k3 + generator.perm[ll + l3]]]], x3, y3, z3, w3) + n3 = t3 * t3 * simplex_grad_4d(gen.perm[ii + i3 + gen.perm[jj + j3 + gen.perm[kk + k3 + + gen.perm[ll + l3]]]], x3, y3, z3, w3) } mut t4 := 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4 @@ -381,8 +380,8 @@ pub fn (generator Generator) simplex_4d(x f64, y f64, z f64, w f64) f64 { n4 = 0.0 } else { t4 *= t4 - n4 = t4 * t4 * grad_4d(generator.perm[ii + 1 + generator.perm[jj + 1 + generator.perm[kk + - 1 + generator.perm[ll + 1]]]], x4, y4, z4, w4) + n4 = t4 * t4 * simplex_grad_4d(gen.perm[ii + 1 + gen.perm[jj + 1 + gen.perm[kk + 1 + + gen.perm[ll + 1]]]], x4, y4, z4, w4) } return 27.0 * (n0 + n1 + n2 + n3 + n4) diff --git a/noise/simplex_test.v b/noise/simplex_test.v index 66dd946a7..206511764 100644 --- a/noise/simplex_test.v +++ b/noise/simplex_test.v @@ -5,36 +5,36 @@ import vsl.float.float64 fn test_simplex_1d() { rand.seed([u32(3155200429), u32(3208395956)]) - mut generator := Generator.new() - generator.randomize() - result := generator.simplex_1d(0.287) + mut gen := Generator.new() + gen.randomize() + result := gen.simplex_1d(0.287) expected := -0.3544283326507284 assert float64.tolerance(result, expected, 1.0e-6) } fn test_simplex_2d() { rand.seed([u32(3075200429), u32(3094395956)]) - mut generator := Generator.new() - generator.randomize() - result := generator.simplex_2d(0.287, 0.475) + mut gen := Generator.new() + gen.randomize() + result := gen.simplex_2d(0.287, 0.475) expected := -0.09948661872545192 assert float64.tolerance(result, expected, 1.0e-6) } fn test_simplex_3d() { rand.seed([u32(3155200429), u32(3208395956)]) - mut generator := Generator.new() - generator.randomize() - result := generator.simplex_3d(0.287, 0.475, 1.917) + mut gen := Generator.new() + gen.randomize() + result := gen.simplex_3d(0.287, 0.475, 1.917) expected := -0.06034653476116279 assert float64.tolerance(result, expected, 1.0e-6) } fn test_simplex_4d() { rand.seed([u32(3075200429), u32(3094395956)]) - mut generator := Generator.new() - generator.randomize() - result := generator.simplex_4d(0.287, 0.475, 1.917, 0.684) + mut gen := Generator.new() + gen.randomize() + result := gen.simplex_4d(0.287, 0.475, 1.917, 0.684) expected := 0.015098415881100141 assert float64.tolerance(result, expected, 1.0e-6) }