use crate::compiled::real::Real;
#[inline(always)]
pub fn sdf_morph(a: f32, b: f32, t: f32) -> f32 {
sdf_morph_r::<f32>(a, b, t)
}
#[inline(always)]
pub fn sdf_morph_r<R: Real>(a: R, b: R, t: f32) -> R {
a * R::splat(1.0 - t) + b * R::splat(t)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_morph_zero() {
assert!((sdf_morph(1.0, 2.0, 0.0) - 1.0).abs() < 1e-6);
}
#[test]
fn test_morph_one() {
assert!((sdf_morph(1.0, 2.0, 1.0) - 2.0).abs() < 1e-6);
}
#[test]
fn test_morph_half() {
assert!((sdf_morph(1.0, 3.0, 0.5) - 2.0).abs() < 1e-6);
}
#[test]
fn test_morph_quarter() {
assert!((sdf_morph(0.0, 4.0, 0.25) - 1.0).abs() < 1e-6);
}
}