Razaekel / noise-rs

Procedural noise generation library for Rust.
Apache License 2.0
842 stars 118 forks source link

Exact value to get() always return 0 #354

Closed BobG1983 closed 3 months ago

BobG1983 commented 3 months ago

Given the following:

pub struct Position {
    pub x: i32,
    pub y: i32,
}

let pos = Position { x: 0, y:0 }
let perlin = Perlin::new(0.0);
let terrace: Terrace<f64, Perlin, 2> = Terrace::new(perlin)
  .add_control_point(-1.0)
  .add_control_point(0.0)
  .add_control_point(0.5)
  .add_control_point(0.8)
  .add_control_point(0.9)
  .add_control_point(1.0);

let height = terrace.get([pos.x as f64, pos.y as f64]);

Regardless of the values for pos.x and pos.y get() always returns 0.0

The following works however:

let height = terrace.get([pos.x as f64 + 0.0001, pos.y as f64 + 0.0001])
amaranth commented 3 months ago

It's expected for perlin noise to return 0 when you pass in integer coordinates. With your control points this results in alpha being (1/1)^2 which is just 1 and then linear interpolation between -1 and 0 with an alpha of 1 results in 0.

BobG1983 commented 3 months ago

I am an idiot and you are correct.