Razaekel / noise-rs

Procedural noise generation library for Rust.
Apache License 2.0
854 stars 120 forks source link

Fix Negative Range of Perlin1D #352

Closed ToroidalFox closed 5 months ago

ToroidalFox commented 5 months ago

While making toy project, found out 1-dimensional Perlin noise was broken in negative range.

example:

#[test]
fn perlin_test() {
    let perlin = Perlin::new(69420);

    for i in -9..10 {
        let t = i as f64 / 10.0;
        let val = perlin.get([t]);
        println!("{:.2}: {:.2}", t, val);
    }
}

before fix:

-0.90: 1.00
-0.80: 1.00
-0.70: 1.00
-0.60: 1.00
-0.50: 1.00
-0.40: 0.80
-0.30: 0.60
-0.20: 0.40
-0.10: 0.20
0.00: -0.00
0.10: -0.21
0.20: -0.47
0.30: -0.73
0.40: -0.93
0.50: -1.00
0.60: -0.93
0.70: -0.73
0.80: -0.47
0.90: -0.2

after fix:

-0.90: 0.21
-0.80: 0.47
-0.70: 0.73
-0.60: 0.93
-0.50: 1.00
-0.40: 0.93
-0.30: 0.73
-0.20: 0.47
-0.10: 0.21
0.00: -0.00
0.10: -0.21
0.20: -0.47
0.30: -0.73
0.40: -0.93
0.50: -1.00
0.60: -0.93
0.70: -0.73
0.80: -0.47
0.90: -0.21

perlin_test_stacked