Skip to main content

oxihuman_morph/
submental_morph.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5pub struct SubmentalMorph {
6    pub fat_volume: f32,
7    pub ptosis: f32,
8    pub neck_angle_deg: f32,
9}
10
11pub fn new_submental_morph() -> SubmentalMorph {
12    SubmentalMorph {
13        fat_volume: 0.0,
14        ptosis: 0.0,
15        neck_angle_deg: 0.0,
16    }
17}
18
19pub fn submental_set_fat(m: &mut SubmentalMorph, v: f32) {
20    m.fat_volume = v.clamp(0.0, 1.0);
21}
22
23pub fn submental_has_double_chin(m: &SubmentalMorph) -> bool {
24    m.fat_volume > 0.5
25}
26
27pub fn submental_overall_weight(m: &SubmentalMorph) -> f32 {
28    (m.fat_volume + m.ptosis) * 0.5
29}
30
31pub fn submental_blend(a: &SubmentalMorph, b: &SubmentalMorph, t: f32) -> SubmentalMorph {
32    let t = t.clamp(0.0, 1.0);
33    SubmentalMorph {
34        fat_volume: a.fat_volume + (b.fat_volume - a.fat_volume) * t,
35        ptosis: a.ptosis + (b.ptosis - a.ptosis) * t,
36        neck_angle_deg: a.neck_angle_deg + (b.neck_angle_deg - a.neck_angle_deg) * t,
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_new_submental_morph() {
46        /* fat_volume starts at 0 */
47        let m = new_submental_morph();
48        assert!((m.fat_volume - 0.0).abs() < 1e-6);
49    }
50
51    #[test]
52    fn test_submental_set_fat() {
53        /* set and retrieve fat */
54        let mut m = new_submental_morph();
55        submental_set_fat(&mut m, 0.7);
56        assert!((m.fat_volume - 0.7).abs() < 1e-6);
57    }
58
59    #[test]
60    fn test_submental_has_double_chin_true() {
61        /* fat > 0.5 means double chin */
62        let mut m = new_submental_morph();
63        submental_set_fat(&mut m, 0.6);
64        assert!(submental_has_double_chin(&m));
65    }
66
67    #[test]
68    fn test_submental_has_double_chin_false() {
69        /* no fat, no double chin */
70        let m = new_submental_morph();
71        assert!(!submental_has_double_chin(&m));
72    }
73
74    #[test]
75    fn test_submental_overall_weight() {
76        /* weight is average of fat and ptosis */
77        let mut m = new_submental_morph();
78        submental_set_fat(&mut m, 1.0);
79        m.ptosis = 1.0;
80        assert!((submental_overall_weight(&m) - 1.0).abs() < 1e-6);
81    }
82
83    #[test]
84    fn test_submental_blend() {
85        /* blend t=0 gives a */
86        let a = new_submental_morph();
87        let mut b = new_submental_morph();
88        b.fat_volume = 1.0;
89        let out = submental_blend(&a, &b, 0.0);
90        assert!((out.fat_volume - 0.0).abs() < 1e-6);
91    }
92}