Example #1
0
func DoTestSimplexNoise() {
	var min, max float64

	min, max = 1, -1
	const iter = 1e7
	var sum float64
	for i := 0; i < iter; i++ {
		switch rnd := simplexnoise.Noise1(float64(i) * 1.827231321); {
		case rnd < min:
			min = rnd
			sum += rnd
		case rnd > max:
			max = rnd
			sum += rnd
		default:
			sum += rnd
		}
	}
	// fmt.Printf("DoTestSimplexNoise simplexnoise.Noise1 min %v, max %v, average %v\n", min, max, sum/iter)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 min=-1.0", math.Abs(min+1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 max=1.0", math.Abs(max-1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 average=0.0", math.Abs(sum/iter) < 0.04) // Not very good, off by more than 3%

	min, max = 1, -1
	sum = 0
	for i := 0; i < iter; i++ {
		switch rnd := simplexnoise.Noise2(float64(i)*1.827411321, float64(i)*7.12312781); {
		case rnd < min:
			min = rnd
			sum += rnd
		case rnd > max:
			max = rnd
			sum += rnd
		default:
			sum += rnd
		}
	}
	// fmt.Printf("DoTestSimplexNoise simplexnoise.Noise2 min %v, max %v, average %v\n", min, max, sum/iter)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 min=-1.0", math.Abs(min+1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 max=1.0", math.Abs(max-1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 average=0.0", math.Abs(sum/iter) < 1e-4)

	min, max = 1, -1
	sum = 0
	for i := 0; i < iter; i++ {
		switch rnd := simplexnoise.Noise3(float64(i)*1.827131321, float64(i)*7.12372381, float64(i)*4.923716223); {
		case rnd < min:
			min = rnd
			sum += rnd
		case rnd > max:
			max = rnd
			sum += rnd
		default:
			sum += rnd
		}
	}
	// fmt.Printf("DoTestSimplexNoise simplexnoise.Noise3 min %v, max %v, average %v\n", min, max, sum/iter)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 min=-1.0", math.Abs(min+1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 max=1.0", math.Abs(max-1) < 1e-3)
	DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 average=0.0", math.Abs(sum/iter) < 1e-4)
}
func dBdensity(xf, yf, zf float64) float64 {
	return simplexnoise.Noise3(xf*0.01, yf*0.01, zf*0.01)/2 + 0.5 // Now in range 0-1
}