From 382ce168220bf680ec4635c0f4b95339d458c795 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 29 Jun 2024 00:39:11 +0300 Subject: [PATCH] Remove the linear limiter as not smooth enough --- src/bin/flat/fns.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/bin/flat/fns.rs b/src/bin/flat/fns.rs index b1f7d7e..7c55c7b 100644 --- a/src/bin/flat/fns.rs +++ b/src/bin/flat/fns.rs @@ -5,16 +5,6 @@ pub trait Limiter { fn derivative(&self, x: f32) -> f32; } -pub struct LinearLimiter { - pub min: f32, - pub max: f32, -} - -impl Limiter for LinearLimiter { - fn value(&self, x: f32) -> f32 { (self.min, self.max).inverse_lerp(x.abs()).clamp(0.0, 1.0) } - fn derivative(&self, x: f32) -> f32 { if x.abs() > self.min && x.abs() < self.max { x.signum() / (self.max - self.min) } else { 0.0 } } -} - pub struct SmoothstepLimiter { pub min: f32, pub max: f32, @@ -100,21 +90,12 @@ mod test { assert_abs_diff_eq!(testee.value(-x), 1., epsilon = ε); } for x in itertools_num::linspace(-mul * max, mul * max, 100) { - // Currently, the derivative is discontinuous at ±min and ±max... let’s just skip these for now. - if x.abs().abs_diff_eq(&min, δ) || x.abs().abs_diff_eq(&max, δ) { - continue; - } let df_num = (testee.value(x + δ) - testee.value(x - δ)) / (2. * δ); let df_expl = testee.derivative(x); assert!(abs_diff_eq!(df_expl, df_num, epsilon = ε), "At x={x}, df/dx:\nnumerical: {df_num}\nexplicit: {df_expl}\n"); } } - #[test] - fn test_linear_limiter() { - test_limiter(LinearLimiter { min: 20.0, max: 30.0 }, 20.0, 30.0, 1.0 / 8.0); - } - #[test] fn test_smoothstep_limiter() { test_limiter(SmoothstepLimiter { min: 20.0, max: 30.0 }, 20.0, 30.0, 1.0 / 32.0);