Skip to main content

oxihuman_morph/
thigh_control.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Thigh girth and shape control.
6
7/// Side.
8#[allow(dead_code)]
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum ThighSide {
11    Left,
12    Right,
13    Both,
14}
15
16/// State.
17#[allow(dead_code)]
18#[derive(Clone, Debug)]
19pub struct ThighState {
20    /// Overall girth factor (0.5..2.0 normalised around 1.0 neutral).
21    pub girth_left: f32,
22    pub girth_right: f32,
23    /// Inner thigh fullness (0..1).
24    pub inner_left: f32,
25    pub inner_right: f32,
26    /// Outer thigh fullness (0..1).
27    pub outer_left: f32,
28    pub outer_right: f32,
29}
30
31/// Config.
32#[allow(dead_code)]
33#[derive(Clone, Debug)]
34pub struct ThighConfig {
35    pub min_girth: f32,
36    pub max_girth: f32,
37}
38
39impl Default for ThighConfig {
40    fn default() -> Self {
41        Self {
42            min_girth: 0.5,
43            max_girth: 2.0,
44        }
45    }
46}
47impl Default for ThighState {
48    fn default() -> Self {
49        Self {
50            girth_left: 1.0,
51            girth_right: 1.0,
52            inner_left: 0.0,
53            inner_right: 0.0,
54            outer_left: 0.0,
55            outer_right: 0.0,
56        }
57    }
58}
59
60#[allow(dead_code)]
61pub fn new_thigh_state() -> ThighState {
62    ThighState::default()
63}
64
65#[allow(dead_code)]
66pub fn default_thigh_config() -> ThighConfig {
67    ThighConfig::default()
68}
69
70#[allow(dead_code)]
71pub fn th_set_girth(state: &mut ThighState, cfg: &ThighConfig, side: ThighSide, v: f32) {
72    let v = v.clamp(cfg.min_girth, cfg.max_girth);
73    match side {
74        ThighSide::Left => state.girth_left = v,
75        ThighSide::Right => state.girth_right = v,
76        ThighSide::Both => {
77            state.girth_left = v;
78            state.girth_right = v;
79        }
80    }
81}
82
83#[allow(dead_code)]
84pub fn th_set_inner(state: &mut ThighState, side: ThighSide, v: f32) {
85    let v = v.clamp(0.0, 1.0);
86    match side {
87        ThighSide::Left => state.inner_left = v,
88        ThighSide::Right => state.inner_right = v,
89        ThighSide::Both => {
90            state.inner_left = v;
91            state.inner_right = v;
92        }
93    }
94}
95
96#[allow(dead_code)]
97pub fn th_set_outer(state: &mut ThighState, side: ThighSide, v: f32) {
98    let v = v.clamp(0.0, 1.0);
99    match side {
100        ThighSide::Left => state.outer_left = v,
101        ThighSide::Right => state.outer_right = v,
102        ThighSide::Both => {
103            state.outer_left = v;
104            state.outer_right = v;
105        }
106    }
107}
108
109#[allow(dead_code)]
110pub fn th_reset(state: &mut ThighState) {
111    *state = ThighState::default();
112}
113
114#[allow(dead_code)]
115pub fn th_is_neutral(state: &ThighState) -> bool {
116    (state.girth_left - 1.0).abs() < 1e-4
117        && (state.girth_right - 1.0).abs() < 1e-4
118        && state.inner_left < 1e-4
119        && state.inner_right < 1e-4
120        && state.outer_left < 1e-4
121        && state.outer_right < 1e-4
122}
123
124#[allow(dead_code)]
125pub fn th_blend(a: &ThighState, b: &ThighState, t: f32) -> ThighState {
126    let t = t.clamp(0.0, 1.0);
127    ThighState {
128        girth_left: a.girth_left + (b.girth_left - a.girth_left) * t,
129        girth_right: a.girth_right + (b.girth_right - a.girth_right) * t,
130        inner_left: a.inner_left + (b.inner_left - a.inner_left) * t,
131        inner_right: a.inner_right + (b.inner_right - a.inner_right) * t,
132        outer_left: a.outer_left + (b.outer_left - a.outer_left) * t,
133        outer_right: a.outer_right + (b.outer_right - a.outer_right) * t,
134    }
135}
136
137#[allow(dead_code)]
138pub fn th_symmetry(state: &ThighState) -> f32 {
139    1.0 - (state.girth_left - state.girth_right).abs().min(1.0)
140}
141
142#[allow(dead_code)]
143pub fn th_average_girth(state: &ThighState) -> f32 {
144    (state.girth_left + state.girth_right) * 0.5
145}
146
147#[allow(dead_code)]
148pub fn th_to_weights(state: &ThighState) -> [f32; 6] {
149    [
150        state.girth_left - 1.0,
151        state.girth_right - 1.0,
152        state.inner_left,
153        state.inner_right,
154        state.outer_left,
155        state.outer_right,
156    ]
157}
158
159#[allow(dead_code)]
160pub fn th_to_json(state: &ThighState) -> String {
161    format!(
162        "{{\"g_l\":{:.4},\"g_r\":{:.4},\"in_l\":{:.4},\"in_r\":{:.4},\"out_l\":{:.4},\"out_r\":{:.4}}}",
163        state.girth_left, state.girth_right,
164        state.inner_left, state.inner_right,
165        state.outer_left, state.outer_right
166    )
167}
168
169#[cfg(test)]
170mod tests {
171    use super::*;
172
173    #[test]
174    fn default_neutral() {
175        assert!(th_is_neutral(&new_thigh_state()));
176    }
177
178    #[test]
179    fn girth_clamps_max() {
180        let mut s = new_thigh_state();
181        let cfg = default_thigh_config();
182        th_set_girth(&mut s, &cfg, ThighSide::Left, 99.0);
183        assert!(s.girth_left <= cfg.max_girth);
184    }
185
186    #[test]
187    fn girth_clamps_min() {
188        let mut s = new_thigh_state();
189        let cfg = default_thigh_config();
190        th_set_girth(&mut s, &cfg, ThighSide::Right, 0.0);
191        assert!(s.girth_right >= cfg.min_girth);
192    }
193
194    #[test]
195    fn both_sides_girth() {
196        let mut s = new_thigh_state();
197        let cfg = default_thigh_config();
198        th_set_girth(&mut s, &cfg, ThighSide::Both, 1.5);
199        assert!((s.girth_left - s.girth_right).abs() < 1e-5);
200    }
201
202    #[test]
203    fn reset_neutral() {
204        let mut s = new_thigh_state();
205        let cfg = default_thigh_config();
206        th_set_girth(&mut s, &cfg, ThighSide::Both, 1.8);
207        th_reset(&mut s);
208        assert!(th_is_neutral(&s));
209    }
210
211    #[test]
212    fn blend_midpoint() {
213        let cfg = default_thigh_config();
214        let mut a = new_thigh_state();
215        let mut b = new_thigh_state();
216        th_set_girth(&mut a, &cfg, ThighSide::Left, 1.0);
217        th_set_girth(&mut b, &cfg, ThighSide::Left, 2.0);
218        let m = th_blend(&a, &b, 0.5);
219        assert!((m.girth_left - 1.5).abs() < 1e-4);
220    }
221
222    #[test]
223    fn symmetry_equal() {
224        let s = new_thigh_state();
225        assert!((th_symmetry(&s) - 1.0).abs() < 1e-5);
226    }
227
228    #[test]
229    fn average_girth_neutral() {
230        assert!((th_average_girth(&new_thigh_state()) - 1.0).abs() < 1e-5);
231    }
232
233    #[test]
234    fn weights_len() {
235        assert_eq!(th_to_weights(&new_thigh_state()).len(), 6);
236    }
237
238    #[test]
239    fn json_has_girth() {
240        assert!(th_to_json(&new_thigh_state()).contains("g_l"));
241    }
242
243    #[test]
244    fn inner_clamped() {
245        let mut s = new_thigh_state();
246        th_set_inner(&mut s, ThighSide::Left, 5.0);
247        assert!(s.inner_left <= 1.0);
248    }
249}