Skip to main content

oxihuman_morph/
leg_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 LegMuscleMorph {
6    pub quadricep: f32,
7    pub hamstring: f32,
8    pub calf: f32,
9    pub definition: f32,
10}
11
12pub fn new_leg_muscle_morph() -> LegMuscleMorph {
13    LegMuscleMorph {
14        quadricep: 0.0,
15        hamstring: 0.0,
16        calf: 0.0,
17        definition: 0.0,
18    }
19}
20
21pub fn leg_set_quad(m: &mut LegMuscleMorph, v: f32) {
22    m.quadricep = v.clamp(0.0, 1.0);
23}
24
25pub fn leg_is_muscular(m: &LegMuscleMorph) -> bool {
26    (m.quadricep + m.hamstring + m.calf) / 3.0 > 0.5
27}
28
29pub fn leg_overall_weight(m: &LegMuscleMorph) -> f32 {
30    (m.quadricep + m.hamstring + m.calf + m.definition) / 4.0
31}
32
33pub fn leg_blend(a: &LegMuscleMorph, b: &LegMuscleMorph, t: f32) -> LegMuscleMorph {
34    let t = t.clamp(0.0, 1.0);
35    LegMuscleMorph {
36        quadricep: a.quadricep + (b.quadricep - a.quadricep) * t,
37        hamstring: a.hamstring + (b.hamstring - a.hamstring) * t,
38        calf: a.calf + (b.calf - a.calf) * 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_leg_muscle_morph();
51        assert!((m.quadricep).abs() < 1e-5);
52    }
53
54    #[test]
55    fn test_set_quad_clamp() {
56        /* quad clamped */
57        let mut m = new_leg_muscle_morph();
58        leg_set_quad(&mut m, 0.7);
59        assert!((m.quadricep - 0.7).abs() < 1e-5);
60    }
61
62    #[test]
63    fn test_not_muscular_by_default() {
64        /* not muscular */
65        let m = new_leg_muscle_morph();
66        assert!(!leg_is_muscular(&m));
67    }
68
69    #[test]
70    fn test_overall_weight_zero() {
71        /* zero */
72        let m = new_leg_muscle_morph();
73        assert!((leg_overall_weight(&m)).abs() < 1e-5);
74    }
75
76    #[test]
77    fn test_blend() {
78        /* midpoint */
79        let a = new_leg_muscle_morph();
80        let b = LegMuscleMorph {
81            quadricep: 1.0,
82            hamstring: 1.0,
83            calf: 1.0,
84            definition: 1.0,
85        };
86        let c = leg_blend(&a, &b, 0.5);
87        assert!((c.quadricep - 0.5).abs() < 1e-5);
88    }
89}