#![allow(dead_code)]
#[derive(Debug, Clone, Default)]
pub struct ChinRaiseState {
pub raise: f32,
pub dimple: f32,
pub lip_chin_couple: f32,
}
pub fn cr_set_raise(state: &mut ChinRaiseState, amount: f32) {
state.raise = amount.clamp(0.0, 1.0);
}
pub fn cr_set_dimple(state: &mut ChinRaiseState, amount: f32) {
state.dimple = amount.clamp(0.0, 1.0);
}
pub fn cr_lower_lip_push(state: &ChinRaiseState) -> f32 {
state.raise * state.lip_chin_couple.max(0.25)
}
pub fn cr_is_neutral(state: &ChinRaiseState) -> bool {
state.raise < 0.05 && state.dimple < 0.05
}
pub fn cr_reset(state: &mut ChinRaiseState) {
state.raise = 0.0;
state.dimple = 0.0;
}
pub fn cr_blend_toward(state: &mut ChinRaiseState, target_raise: f32, t: f32) {
let t = t.clamp(0.0, 1.0);
let target = target_raise.clamp(0.0, 1.0);
state.raise += (target - state.raise) * t;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_neutral() {
let s = ChinRaiseState::default();
assert!(cr_is_neutral(&s));
}
#[test]
fn test_set_raise() {
let mut s = ChinRaiseState::default();
cr_set_raise(&mut s, 0.7);
assert!((s.raise - 0.7).abs() < 1e-6);
}
#[test]
fn test_set_dimple() {
let mut s = ChinRaiseState::default();
cr_set_dimple(&mut s, 0.4);
assert!((s.dimple - 0.4).abs() < 1e-6);
}
#[test]
fn test_lower_lip_push_nonzero() {
let mut s = ChinRaiseState::default();
cr_set_raise(&mut s, 1.0);
assert!(cr_lower_lip_push(&s) > 0.0);
}
#[test]
fn test_not_neutral_when_raised() {
let mut s = ChinRaiseState::default();
cr_set_raise(&mut s, 0.5);
assert!(!cr_is_neutral(&s));
}
#[test]
fn test_reset() {
let mut s = ChinRaiseState::default();
cr_set_raise(&mut s, 0.8);
cr_set_dimple(&mut s, 0.5);
cr_reset(&mut s);
assert!(cr_is_neutral(&s));
}
#[test]
fn test_blend_toward() {
let mut s = ChinRaiseState::default();
cr_blend_toward(&mut s, 1.0, 0.5);
assert!(s.raise > 0.0 && s.raise < 1.0);
}
#[test]
fn test_clamp_above_one() {
let mut s = ChinRaiseState::default();
cr_set_raise(&mut s, 9.9);
assert!((s.raise - 1.0).abs() < 1e-6);
}
#[test]
fn test_lower_lip_zero_when_relaxed() {
let s = ChinRaiseState::default();
assert_eq!(cr_lower_lip_push(&s), 0.0);
}
}