Skip to main content

oxihuman_morph/
arm_muscle_morph.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5pub struct ArmMuscleMorph {
6    pub bicep: f32,
7    pub tricep: f32,
8    pub forearm: f32,
9    pub definition: f32,
10}
11
12pub fn new_arm_muscle_morph() -> ArmMuscleMorph {
13    ArmMuscleMorph {
14        bicep: 0.0,
15        tricep: 0.0,
16        forearm: 0.0,
17        definition: 0.0,
18    }
19}
20
21pub fn arm_set_bicep(m: &mut ArmMuscleMorph, v: f32) {
22    m.bicep = v.clamp(0.0, 1.0);
23}
24
25pub fn arm_is_muscular(m: &ArmMuscleMorph) -> bool {
26    (m.bicep + m.tricep) * 0.5 > 0.5
27}
28
29pub fn arm_overall_weight(m: &ArmMuscleMorph) -> f32 {
30    (m.bicep + m.tricep + m.forearm + m.definition) / 4.0
31}
32
33pub fn arm_blend(a: &ArmMuscleMorph, b: &ArmMuscleMorph, t: f32) -> ArmMuscleMorph {
34    let t = t.clamp(0.0, 1.0);
35    ArmMuscleMorph {
36        bicep: a.bicep + (b.bicep - a.bicep) * t,
37        tricep: a.tricep + (b.tricep - a.tricep) * t,
38        forearm: a.forearm + (b.forearm - a.forearm) * t,
39        definition: a.definition + (b.definition - a.definition) * t,
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_new_zero() {
49        /* all zero */
50        let m = new_arm_muscle_morph();
51        assert!((m.bicep + m.tricep).abs() < 1e-5);
52    }
53
54    #[test]
55    fn test_set_bicep_clamped() {
56        /* bicep clamped */
57        let mut m = new_arm_muscle_morph();
58        arm_set_bicep(&mut m, 0.8);
59        assert!((m.bicep - 0.8).abs() < 1e-5);
60    }
61
62    #[test]
63    fn test_not_muscular_by_default() {
64        /* not muscular */
65        let m = new_arm_muscle_morph();
66        assert!(!arm_is_muscular(&m));
67    }
68
69    #[test]
70    fn test_overall_weight_zero() {
71        /* zero */
72        let m = new_arm_muscle_morph();
73        assert!((arm_overall_weight(&m)).abs() < 1e-5);
74    }
75
76    #[test]
77    fn test_blend() {
78        /* midpoint */
79        let a = new_arm_muscle_morph();
80        let b = ArmMuscleMorph {
81            bicep: 1.0,
82            tricep: 1.0,
83            forearm: 1.0,
84            definition: 1.0,
85        };
86        let c = arm_blend(&a, &b, 0.5);
87        assert!((c.bicep - 0.5).abs() < 1e-5);
88    }
89}