#![allow(dead_code)]
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct AgingParams {
pub age: f32,
pub skin_elasticity: f32,
pub muscle_loss: f32,
pub fat_gain: f32,
pub height_change: f32,
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct BodyAging {
pub params: AgingParams,
pub label: String,
}
#[allow(dead_code)]
pub fn new_body_aging(label: &str, age: f32) -> BodyAging {
let age = age.clamp(0.0, 120.0);
BodyAging {
params: AgingParams {
age,
skin_elasticity: (1.0 - age / 120.0).clamp(0.0, 1.0),
muscle_loss: 0.0,
fat_gain: 0.0,
height_change: 0.0,
},
label: label.to_string(),
}
}
#[allow(dead_code)]
pub fn age_skin(aging: &BodyAging) -> f32 {
let age_factor = (aging.params.age / 100.0).clamp(0.0, 1.0);
1.0 - age_factor * 0.6
}
#[allow(dead_code)]
pub fn age_posture(aging: &BodyAging) -> f32 {
let over_50 = (aging.params.age - 50.0).max(0.0) / 70.0;
over_50.clamp(0.0, 1.0) * 0.3
}
#[allow(dead_code)]
pub fn age_muscle_loss(aging: &BodyAging) -> f32 {
let after_30 = (aging.params.age - 30.0).max(0.0) / 90.0;
(after_30 * 0.4).clamp(0.0, 1.0)
}
#[allow(dead_code)]
pub fn age_fat_gain(aging: &BodyAging) -> f32 {
let factor = (aging.params.age / 80.0).clamp(0.0, 1.0);
factor * 0.25
}
#[allow(dead_code)]
pub fn age_height_change(aging: &BodyAging) -> f32 {
let after_40 = (aging.params.age - 40.0).max(0.0) / 80.0;
-(after_40.clamp(0.0, 1.0) * 0.05)
}
#[allow(dead_code)]
pub fn aging_to_params(aging: &BodyAging) -> [f32; 5] {
[
age_skin(aging),
age_posture(aging),
age_muscle_loss(aging),
age_fat_gain(aging),
age_height_change(aging),
]
}
#[allow(dead_code)]
pub fn aging_preview(aging: &BodyAging, target_age: f32) -> [f32; 5] {
let preview = new_body_aging(&aging.label, target_age);
aging_to_params(&preview)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_body_aging() {
let a = new_body_aging("test", 30.0);
assert_eq!(a.label, "test");
assert!((a.params.age - 30.0).abs() < f32::EPSILON);
}
#[test]
fn test_new_body_aging_clamps() {
let a = new_body_aging("test", 200.0);
assert!((a.params.age - 120.0).abs() < f32::EPSILON);
}
#[test]
fn test_age_skin_young() {
let a = new_body_aging("young", 20.0);
let skin = age_skin(&a);
assert!(skin > 0.8);
}
#[test]
fn test_age_skin_old() {
let a = new_body_aging("old", 100.0);
let skin = age_skin(&a);
assert!(skin < 0.5);
}
#[test]
fn test_age_posture_young() {
let a = new_body_aging("young", 25.0);
assert!((age_posture(&a) - 0.0).abs() < f32::EPSILON);
}
#[test]
fn test_age_muscle_loss_young() {
let a = new_body_aging("young", 20.0);
assert!((age_muscle_loss(&a) - 0.0).abs() < f32::EPSILON);
}
#[test]
fn test_age_fat_gain() {
let a = new_body_aging("mid", 60.0);
let fat = age_fat_gain(&a);
assert!(fat > 0.0);
}
#[test]
fn test_age_height_change_young() {
let a = new_body_aging("young", 30.0);
assert!((age_height_change(&a) - 0.0).abs() < f32::EPSILON);
}
#[test]
fn test_aging_to_params() {
let a = new_body_aging("test", 50.0);
let params = aging_to_params(&a);
assert_eq!(params.len(), 5);
}
#[test]
fn test_aging_preview() {
let a = new_body_aging("test", 30.0);
let preview = aging_preview(&a, 80.0);
assert!(preview[2] > 0.0); }
}