From f0fd08ade0f355f5977838db7b0df5d58b43ec7f Mon Sep 17 00:00:00 2001 From: tomara_x <86204514+tomara-x@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:07:39 +0200 Subject: [PATCH] wrap and mirror functions --- src/math.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/math.rs b/src/math.rs index d183ada..32b7d44 100644 --- a/src/math.rs +++ b/src/math.rs @@ -758,3 +758,17 @@ pub fn fractal_ease_noise( } result / total_weight } + +/// Mirror input between the range 0...1 +#[inline] +pub fn mirror(x: T) -> T { + let x = x / T::new(2) - T::from_f32(0.5); + let x = x - x.floor(); + abs(x - T::from_f32(0.5)) * T::new(2) +} + +/// Wrap input between the range 0...1 +#[inline] +pub fn wrap(x: T) -> T { + x - x.floor() +}