oxihuman_morph/
sternocleidomastoid_morph.rs1#![allow(dead_code)]
4
5pub struct ScmMorph {
6 pub definition: f32,
7 pub length: f32,
8 pub prominence: f32,
9}
10
11pub fn new_scm_morph() -> ScmMorph {
12 ScmMorph {
13 definition: 0.0,
14 length: 0.5,
15 prominence: 0.0,
16 }
17}
18
19pub fn scm_set_definition(m: &mut ScmMorph, v: f32) {
20 m.definition = v.clamp(0.0, 1.0);
21}
22
23pub fn scm_is_defined(m: &ScmMorph) -> bool {
24 m.definition > 0.4
25}
26
27pub fn scm_overall_weight(m: &ScmMorph) -> f32 {
28 (m.definition + m.prominence) * 0.5
29}
30
31pub fn scm_blend(a: &ScmMorph, b: &ScmMorph, t: f32) -> ScmMorph {
32 let t = t.clamp(0.0, 1.0);
33 ScmMorph {
34 definition: a.definition + (b.definition - a.definition) * t,
35 length: a.length + (b.length - a.length) * t,
36 prominence: a.prominence + (b.prominence - a.prominence) * t,
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_new_scm_morph() {
46 let m = new_scm_morph();
48 assert!((m.definition - 0.0).abs() < 1e-6);
49 }
50
51 #[test]
52 fn test_scm_set_definition() {
53 let mut m = new_scm_morph();
55 scm_set_definition(&mut m, 0.5);
56 assert!((m.definition - 0.5).abs() < 1e-6);
57 }
58
59 #[test]
60 fn test_scm_is_defined_true() {
61 let mut m = new_scm_morph();
63 scm_set_definition(&mut m, 0.6);
64 assert!(scm_is_defined(&m));
65 }
66
67 #[test]
68 fn test_scm_is_defined_false() {
69 let m = new_scm_morph();
71 assert!(!scm_is_defined(&m));
72 }
73
74 #[test]
75 fn test_scm_blend() {
76 let a = new_scm_morph();
78 let mut b = new_scm_morph();
79 b.definition = 1.0;
80 let mid = scm_blend(&a, &b, 0.5);
81 assert!((mid.definition - 0.5).abs() < 1e-6);
82 }
83}