normal_map/lib.rs
1//! A helper that maps a range of values to and from the normalized
2//! range `[0.0, 1.0]` using various gradients, useful for DSP applications.
3//!
4//! (currently in beta)
5//!
6//! ## Installation
7//! Add `normal_map` as a dependency in your `Cargo.toml`:
8//! ```text
9//! normal_map = 0.2
10//! ```
11//!
12//! ## Example
13//! ```
14//! // Import normal mappers that use internal f32 values.
15//! // (f64 is available as well)
16//! use normal_map::f32::*;
17//!
18//! // Linear mapper
19//! let lin_map = LinearMap::new(-50.0, 50.0, Unit::Generic);
20//!
21//! assert!((lin_map.normalize(25.0) - 0.75).abs() <= 0.0001);
22//! assert!((lin_map.denormalize(0.25) - (-25.0)).abs() <= 0.0001);
23//!
24//! // Efficiently map an array/slice of values.
25//! let in_normals = [0.0f32, 1.0, 0.25, -0.25];
26//! let mut out_values = [0.0f32; 4];
27//!
28//! lin_map.denormalize_array(&in_normals, &mut out_values);
29//!
30//! // Generic type for any mapper
31//! let normal_map = NormalMap::discrete::<isize>(-5, 5);
32//!
33//! assert!((normal_map.normalize(3 as f32) - 0.8).abs() <= 0.0001);
34//! ```
35
36#[cfg(test)]
37mod tests;
38
39pub mod f32;
40pub mod f64;