Skip to main content

oxihuman_morph/
depressor_anguli_morph.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5pub struct DepressorAnguliMorph {
6    pub contraction: f32,
7    pub ptosis: f32,
8}
9
10pub fn new_depressor_anguli_morph() -> DepressorAnguliMorph {
11    DepressorAnguliMorph {
12        contraction: 0.0,
13        ptosis: 0.0,
14    }
15}
16
17pub fn depressor_set_contraction(m: &mut DepressorAnguliMorph, v: f32) {
18    m.contraction = v.clamp(0.0, 1.0);
19}
20
21pub fn depressor_is_active(m: &DepressorAnguliMorph) -> bool {
22    m.contraction > 0.2
23}
24
25pub fn depressor_overall_weight(m: &DepressorAnguliMorph) -> f32 {
26    (m.contraction + m.ptosis) * 0.5
27}
28
29pub fn depressor_blend(
30    a: &DepressorAnguliMorph,
31    b: &DepressorAnguliMorph,
32    t: f32,
33) -> DepressorAnguliMorph {
34    let t = t.clamp(0.0, 1.0);
35    DepressorAnguliMorph {
36        contraction: a.contraction + (b.contraction - a.contraction) * t,
37        ptosis: a.ptosis + (b.ptosis - a.ptosis) * t,
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_new_depressor_anguli_morph() {
47        /* contraction starts at 0 */
48        let m = new_depressor_anguli_morph();
49        assert!((m.contraction - 0.0).abs() < 1e-6);
50    }
51
52    #[test]
53    fn test_depressor_set_contraction() {
54        /* set and retrieve contraction */
55        let mut m = new_depressor_anguli_morph();
56        depressor_set_contraction(&mut m, 0.3);
57        assert!((m.contraction - 0.3).abs() < 1e-6);
58    }
59
60    #[test]
61    fn test_depressor_is_active_true() {
62        /* > 0.2 is active */
63        let mut m = new_depressor_anguli_morph();
64        depressor_set_contraction(&mut m, 0.5);
65        assert!(depressor_is_active(&m));
66    }
67
68    #[test]
69    fn test_depressor_is_active_false() {
70        /* 0 not active */
71        let m = new_depressor_anguli_morph();
72        assert!(!depressor_is_active(&m));
73    }
74
75    #[test]
76    fn test_depressor_blend() {
77        /* blend midpoint */
78        let a = new_depressor_anguli_morph();
79        let mut b = new_depressor_anguli_morph();
80        b.contraction = 1.0;
81        let mid = depressor_blend(&a, &b, 0.5);
82        assert!((mid.contraction - 0.5).abs() < 1e-6);
83    }
84}