#![allow(dead_code)]
#[derive(Debug, Clone)]
pub struct AgeStage {
pub age_years: f32,
pub morph_weights: Vec<f32>,
pub label: String,
}
#[derive(Debug, Clone)]
pub struct AgeProgressionMorph {
pub stages: Vec<AgeStage>,
pub current_age: f32,
pub morph_count: usize,
pub enabled: bool,
}
impl AgeProgressionMorph {
pub fn new(morph_count: usize) -> Self {
AgeProgressionMorph {
stages: Vec::new(),
current_age: 25.0,
morph_count,
enabled: true,
}
}
}
pub fn new_age_progression_morph(morph_count: usize) -> AgeProgressionMorph {
AgeProgressionMorph::new(morph_count)
}
pub fn apm_add_stage(apm: &mut AgeProgressionMorph, stage: AgeStage) {
apm.stages.push(stage);
}
pub fn apm_set_age(apm: &mut AgeProgressionMorph, age: f32) {
apm.current_age = age.max(0.0);
}
pub fn apm_evaluate(apm: &AgeProgressionMorph) -> Vec<f32> {
vec![0.0; apm.morph_count]
}
pub fn apm_stage_count(apm: &AgeProgressionMorph) -> usize {
apm.stages.len()
}
pub fn apm_set_enabled(apm: &mut AgeProgressionMorph, enabled: bool) {
apm.enabled = enabled;
}
pub fn apm_to_json(apm: &AgeProgressionMorph) -> String {
format!(
r#"{{"morph_count":{},"stage_count":{},"current_age":{:.1},"enabled":{}}}"#,
apm.morph_count,
apm.stages.len(),
apm.current_age,
apm.enabled
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_morph_count() {
let a = new_age_progression_morph(12);
assert_eq!(a.morph_count, 12 ,);
}
#[test]
fn test_default_age() {
let a = new_age_progression_morph(4);
assert!((a.current_age - 25.0).abs() < 1e-5, );
}
#[test]
fn test_no_stages_initially() {
let a = new_age_progression_morph(4);
assert_eq!(apm_stage_count(&a), 0 ,);
}
#[test]
fn test_add_stage() {
let mut a = new_age_progression_morph(4);
apm_add_stage(
&mut a,
AgeStage {
age_years: 30.0,
morph_weights: vec![0.0; 4],
label: "adult".into(),
},
);
assert_eq!(apm_stage_count(&a), 1 ,);
}
#[test]
fn test_set_age() {
let mut a = new_age_progression_morph(4);
apm_set_age(&mut a, 60.0);
assert!((a.current_age - 60.0).abs() < 1e-5, );
}
#[test]
fn test_age_clamped_negative() {
let mut a = new_age_progression_morph(4);
apm_set_age(&mut a, -5.0);
assert!((a.current_age).abs() < 1e-6, );
}
#[test]
fn test_evaluate_length() {
let a = new_age_progression_morph(8);
let out = apm_evaluate(&a);
assert_eq!(out.len(), 8 ,);
}
#[test]
fn test_set_enabled() {
let mut a = new_age_progression_morph(2);
apm_set_enabled(&mut a, false);
assert!(!a.enabled ,);
}
#[test]
fn test_to_json_contains_current_age() {
let a = new_age_progression_morph(4);
let j = apm_to_json(&a);
assert!(j.contains("\"current_age\""), );
}
#[test]
fn test_enabled_default() {
let a = new_age_progression_morph(1);
assert!(a.enabled ,);
}
}