Skip to main content

oxihuman_morph/
cheek_fullness_control.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3
4#![allow(dead_code)]
5
6//! Cheek fullness control: adjusts the volume and projection of the cheeks.
7
8use std::f32::consts::PI;
9
10#[allow(dead_code)]
11#[derive(Debug, Clone)]
12pub struct CheekFullnessConfig {
13    pub min_fullness: f32,
14    pub max_fullness: f32,
15}
16
17#[allow(dead_code)]
18#[derive(Debug, Clone)]
19pub struct CheekFullnessState {
20    pub fullness: f32,
21    pub projection: f32,
22    pub symmetry: f32,
23}
24
25#[allow(dead_code)]
26pub fn default_cheek_fullness_config() -> CheekFullnessConfig {
27    CheekFullnessConfig {
28        min_fullness: 0.0,
29        max_fullness: 1.0,
30    }
31}
32
33#[allow(dead_code)]
34pub fn new_cheek_fullness_state() -> CheekFullnessState {
35    CheekFullnessState {
36        fullness: 0.5,
37        projection: 0.4,
38        symmetry: 1.0,
39    }
40}
41
42#[allow(dead_code)]
43pub fn cf_set_fullness(state: &mut CheekFullnessState, cfg: &CheekFullnessConfig, v: f32) {
44    state.fullness = v.clamp(cfg.min_fullness, cfg.max_fullness);
45}
46
47#[allow(dead_code)]
48pub fn cf_set_projection(state: &mut CheekFullnessState, v: f32) {
49    state.projection = v.clamp(0.0, 1.0);
50}
51
52#[allow(dead_code)]
53pub fn cf_set_symmetry(state: &mut CheekFullnessState, v: f32) {
54    state.symmetry = v.clamp(0.0, 1.0);
55}
56
57#[allow(dead_code)]
58pub fn cf_reset(state: &mut CheekFullnessState) {
59    *state = new_cheek_fullness_state();
60}
61
62#[allow(dead_code)]
63pub fn cf_volume_estimate(state: &CheekFullnessState) -> f32 {
64    (4.0 / 3.0) * PI * state.fullness * state.projection * state.fullness
65}
66
67#[allow(dead_code)]
68pub fn cf_to_weights(state: &CheekFullnessState) -> Vec<(String, f32)> {
69    vec![
70        ("cheek_fullness".to_string(), state.fullness),
71        ("cheek_projection".to_string(), state.projection),
72        ("cheek_symmetry".to_string(), state.symmetry),
73    ]
74}
75
76#[allow(dead_code)]
77pub fn cf_to_json(state: &CheekFullnessState) -> String {
78    format!(
79        r#"{{"fullness":{:.4},"projection":{:.4},"symmetry":{:.4}}}"#,
80        state.fullness, state.projection, state.symmetry
81    )
82}
83
84#[allow(dead_code)]
85pub fn cf_blend(a: &CheekFullnessState, b: &CheekFullnessState, t: f32) -> CheekFullnessState {
86    let t = t.clamp(0.0, 1.0);
87    CheekFullnessState {
88        fullness: a.fullness + (b.fullness - a.fullness) * t,
89        projection: a.projection + (b.projection - a.projection) * t,
90        symmetry: a.symmetry + (b.symmetry - a.symmetry) * t,
91    }
92}
93
94#[allow(dead_code)]
95pub fn cf_effective_left(state: &CheekFullnessState) -> f32 {
96    state.fullness * state.symmetry
97}
98
99#[allow(dead_code)]
100pub fn cf_effective_right(state: &CheekFullnessState) -> f32 {
101    state.fullness * (2.0 - state.symmetry)
102}
103
104#[cfg(test)]
105mod tests {
106    use super::*;
107
108    #[test]
109    fn test_default_config() {
110        let cfg = default_cheek_fullness_config();
111        assert!(cfg.min_fullness.abs() < 1e-6);
112        assert!((cfg.max_fullness - 1.0).abs() < 1e-6);
113    }
114
115    #[test]
116    fn test_new_state() {
117        let s = new_cheek_fullness_state();
118        assert!((s.fullness - 0.5).abs() < 1e-6);
119    }
120
121    #[test]
122    fn test_set_fullness_clamps() {
123        let cfg = default_cheek_fullness_config();
124        let mut s = new_cheek_fullness_state();
125        cf_set_fullness(&mut s, &cfg, 5.0);
126        assert!((s.fullness - 1.0).abs() < 1e-6);
127    }
128
129    #[test]
130    fn test_set_projection() {
131        let mut s = new_cheek_fullness_state();
132        cf_set_projection(&mut s, 0.8);
133        assert!((s.projection - 0.8).abs() < 1e-6);
134    }
135
136    #[test]
137    fn test_set_symmetry() {
138        let mut s = new_cheek_fullness_state();
139        cf_set_symmetry(&mut s, 0.6);
140        assert!((s.symmetry - 0.6).abs() < 1e-6);
141    }
142
143    #[test]
144    fn test_reset() {
145        let cfg = default_cheek_fullness_config();
146        let mut s = new_cheek_fullness_state();
147        cf_set_fullness(&mut s, &cfg, 0.9);
148        cf_reset(&mut s);
149        assert!((s.fullness - 0.5).abs() < 1e-6);
150    }
151
152    #[test]
153    fn test_volume_estimate() {
154        let s = new_cheek_fullness_state();
155        assert!(cf_volume_estimate(&s) > 0.0);
156    }
157
158    #[test]
159    fn test_to_weights() {
160        let s = new_cheek_fullness_state();
161        assert_eq!(cf_to_weights(&s).len(), 3);
162    }
163
164    #[test]
165    fn test_blend() {
166        let a = new_cheek_fullness_state();
167        let mut b = new_cheek_fullness_state();
168        b.fullness = 1.0;
169        let mid = cf_blend(&a, &b, 0.5);
170        assert!((mid.fullness - 0.75).abs() < 1e-6);
171    }
172
173    #[test]
174    fn test_effective_sides() {
175        let s = new_cheek_fullness_state();
176        let l = cf_effective_left(&s);
177        let r = cf_effective_right(&s);
178        assert!((l - r).abs() < 1e-6);
179    }
180}