terrain_forge/noise/
mod.rs

1//! Noise generation module with composable generators and modifiers
2
3mod perlin;
4mod value;
5mod fbm;
6mod modifiers;
7mod simplex;
8mod worley;
9mod ridged;
10
11pub use perlin::Perlin;
12pub use value::Value;
13pub use fbm::Fbm;
14pub use modifiers::*;
15pub use simplex::Simplex;
16pub use worley::Worley;
17pub use ridged::Ridged;
18
19/// Trait for noise sources that can be sampled at 2D coordinates
20pub trait NoiseSource {
21    /// Sample noise at 2D coordinates, returns value typically in [-1, 1]
22    fn sample(&self, x: f64, y: f64) -> f64;
23}
24
25/// Extension trait for composing noise sources
26pub trait NoiseExt: NoiseSource + Sized {
27    /// Scale output by a factor
28    fn scale(self, factor: f64) -> Scale<Self> {
29        Scale { source: self, factor }
30    }
31
32    /// Add offset to output
33    fn offset(self, amount: f64) -> Offset<Self> {
34        Offset { source: self, amount }
35    }
36
37    /// Clamp output to range
38    fn clamp(self, min: f64, max: f64) -> Clamp<Self> {
39        Clamp { source: self, min, max }
40    }
41
42    /// Take absolute value
43    fn abs(self) -> Abs<Self> {
44        Abs { source: self }
45    }
46
47    /// Apply fractal brownian motion
48    fn fbm(self, octaves: u32, lacunarity: f64, persistence: f64) -> Fbm<Self> {
49        Fbm::new(self, octaves, lacunarity, persistence)
50    }
51}
52
53impl<T: NoiseSource> NoiseExt for T {}