#![allow(dead_code)]
#[derive(Debug, Clone, PartialEq)]
pub struct MentolabialMorph {
pub depth: f32,
pub width: f32,
pub position: f32,
}
pub fn new_mentolabial_morph() -> MentolabialMorph {
MentolabialMorph {
depth: 0.0,
width: 0.5,
position: 0.5,
}
}
pub fn mentolabial_set_depth(m: &mut MentolabialMorph, v: f32) {
m.depth = v.clamp(0.0, 1.0);
}
pub fn mentolabial_is_deep(m: &MentolabialMorph) -> bool {
m.depth > 0.5
}
pub fn mentolabial_overall_weight(m: &MentolabialMorph) -> f32 {
(m.depth + m.width + m.position) / 3.0
}
pub fn mentolabial_blend(a: &MentolabialMorph, b: &MentolabialMorph, t: f32) -> MentolabialMorph {
let t = t.clamp(0.0, 1.0);
MentolabialMorph {
depth: a.depth + (b.depth - a.depth) * t,
width: a.width + (b.width - a.width) * t,
position: a.position + (b.position - a.position) * t,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_defaults() {
let m = new_mentolabial_morph();
assert!((m.depth - 0.0).abs() < 1e-6);
}
#[test]
fn test_set_depth_clamps() {
let mut m = new_mentolabial_morph();
mentolabial_set_depth(&mut m, 2.0);
assert!((m.depth - 1.0).abs() < 1e-6);
}
#[test]
fn test_is_deep_true() {
let mut m = new_mentolabial_morph();
mentolabial_set_depth(&mut m, 0.7);
assert!(mentolabial_is_deep(&m));
}
#[test]
fn test_is_deep_false() {
let m = new_mentolabial_morph();
assert!(!mentolabial_is_deep(&m));
}
#[test]
fn test_overall_weight_range() {
let m = new_mentolabial_morph();
let w = mentolabial_overall_weight(&m);
assert!((0.0..=1.0).contains(&w));
}
#[test]
fn test_blend_at_one() {
let a = new_mentolabial_morph();
let mut b = new_mentolabial_morph();
mentolabial_set_depth(&mut b, 1.0);
let r = mentolabial_blend(&a, &b, 1.0);
assert!((r.depth - 1.0).abs() < 1e-6);
}
}