#![allow(dead_code)]
#[derive(Debug, Clone)]
pub struct IliacCrestMorph {
pub flare: f32,
pub height: f32,
pub asis_prominence: f32,
}
pub fn new_iliac_crest_morph() -> IliacCrestMorph {
IliacCrestMorph {
flare: 0.0,
height: 0.0,
asis_prominence: 0.0,
}
}
pub fn iliac_set_flare(m: &mut IliacCrestMorph, v: f32) {
m.flare = v.clamp(0.0, 1.0);
}
pub fn iliac_set_height(m: &mut IliacCrestMorph, v: f32) {
m.height = v.clamp(0.0, 1.0);
}
pub fn iliac_set_asis_prominence(m: &mut IliacCrestMorph, v: f32) {
m.asis_prominence = v.clamp(0.0, 1.0);
}
pub fn iliac_overall_weight(m: &IliacCrestMorph) -> f32 {
(m.flare + m.height + m.asis_prominence) / 3.0
}
pub fn iliac_blend(a: &IliacCrestMorph, b: &IliacCrestMorph, t: f32) -> IliacCrestMorph {
let t = t.clamp(0.0, 1.0);
IliacCrestMorph {
flare: a.flare + (b.flare - a.flare) * t,
height: a.height + (b.height - a.height) * t,
asis_prominence: a.asis_prominence + (b.asis_prominence - a.asis_prominence) * t,
}
}
pub fn iliac_is_neutral(m: &IliacCrestMorph) -> bool {
m.flare < 1e-5 && m.height < 1e-5 && m.asis_prominence < 1e-5
}
pub fn iliac_to_json(m: &IliacCrestMorph) -> String {
format!(
r#"{{"flare":{:.4},"height":{:.4},"asis_prominence":{:.4}}}"#,
m.flare, m.height, m.asis_prominence
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_defaults() {
let m = new_iliac_crest_morph();
assert_eq!(m.flare, 0.0);
}
#[test]
fn test_set_flare() {
let mut m = new_iliac_crest_morph();
iliac_set_flare(&mut m, 0.5);
assert!((m.flare - 0.5).abs() < 1e-6);
}
#[test]
fn test_clamp_high() {
let mut m = new_iliac_crest_morph();
iliac_set_flare(&mut m, 3.0);
assert_eq!(m.flare, 1.0);
}
#[test]
fn test_clamp_low() {
let mut m = new_iliac_crest_morph();
iliac_set_height(&mut m, -0.5);
assert_eq!(m.height, 0.0);
}
#[test]
fn test_neutral_true() {
assert!(iliac_is_neutral(&new_iliac_crest_morph()));
}
#[test]
fn test_neutral_false() {
let mut m = new_iliac_crest_morph();
iliac_set_flare(&mut m, 0.3);
assert!(!iliac_is_neutral(&m));
}
#[test]
fn test_weight() {
let m = IliacCrestMorph {
flare: 0.9,
height: 0.9,
asis_prominence: 0.9,
};
assert!((iliac_overall_weight(&m) - 0.9).abs() < 1e-5);
}
#[test]
fn test_blend() {
let a = new_iliac_crest_morph();
let b = IliacCrestMorph {
flare: 1.0,
height: 0.0,
asis_prominence: 0.0,
};
let c = iliac_blend(&a, &b, 0.5);
assert!((c.flare - 0.5).abs() < 1e-5);
}
#[test]
fn test_to_json() {
assert!(iliac_to_json(&new_iliac_crest_morph()).contains("flare"));
}
#[test]
fn test_clone() {
let m = IliacCrestMorph {
flare: 0.3,
height: 0.4,
asis_prominence: 0.5,
};
let m2 = m.clone();
assert_eq!(m.height, m2.height);
}
}