Skip to main content

oxihuman_morph/
endomorph_morph.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Endomorph body type morph — rounder, higher body-fat build.
6
7/// Configuration for the endomorph morph.
8#[derive(Debug, Clone)]
9pub struct EndomorphConfig {
10    pub belly_fullness: f32,
11    pub limb_girth: f32,
12    pub face_roundness: f32,
13}
14
15impl Default for EndomorphConfig {
16    fn default() -> Self {
17        EndomorphConfig {
18            belly_fullness: 0.8,
19            limb_girth: 0.6,
20            face_roundness: 0.7,
21        }
22    }
23}
24
25/// State for the endomorph morph.
26#[derive(Debug, Clone)]
27pub struct EndomorphMorph {
28    pub intensity: f32,
29    pub config: EndomorphConfig,
30    pub enabled: bool,
31}
32
33/// Create a new endomorph morph.
34pub fn new_endomorph_morph() -> EndomorphMorph {
35    EndomorphMorph {
36        intensity: 0.0,
37        config: EndomorphConfig::default(),
38        enabled: true,
39    }
40}
41
42/// Set intensity [0, 1].
43pub fn endo_set_intensity(m: &mut EndomorphMorph, v: f32) {
44    m.intensity = v.clamp(0.0, 1.0);
45}
46
47/// Belly fullness weight.
48pub fn endo_belly_weight(m: &EndomorphMorph) -> f32 {
49    m.intensity * m.config.belly_fullness
50}
51
52/// Limb girth weight.
53pub fn endo_limb_girth(m: &EndomorphMorph) -> f32 {
54    m.intensity * m.config.limb_girth
55}
56
57/// Face roundness weight.
58pub fn endo_face_roundness(m: &EndomorphMorph) -> f32 {
59    m.intensity * m.config.face_roundness
60}
61
62/// Serialise to JSON.
63pub fn endo_to_json(m: &EndomorphMorph) -> String {
64    format!(
65        r#"{{"intensity":{:.3},"belly":{:.3},"enabled":{}}}"#,
66        m.intensity,
67        endo_belly_weight(m),
68        m.enabled
69    )
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[test]
77    fn default_zero() {
78        let m = new_endomorph_morph();
79        assert!((m.intensity - 0.0).abs() < 1e-6 /* zero */);
80    }
81
82    #[test]
83    fn clamp_to_one() {
84        let mut m = new_endomorph_morph();
85        endo_set_intensity(&mut m, 2.0);
86        assert!((m.intensity - 1.0).abs() < 1e-6 /* clamped */);
87    }
88
89    #[test]
90    fn belly_weight_at_full() {
91        let mut m = new_endomorph_morph();
92        endo_set_intensity(&mut m, 1.0);
93        assert!((endo_belly_weight(&m) - m.config.belly_fullness).abs() < 1e-6 /* correct */);
94    }
95
96    #[test]
97    fn limb_girth_zero_at_zero() {
98        let m = new_endomorph_morph();
99        assert!((endo_limb_girth(&m) - 0.0).abs() < 1e-6 /* zero */);
100    }
101
102    #[test]
103    fn face_roundness_increasing() {
104        let mut m = new_endomorph_morph();
105        endo_set_intensity(&mut m, 0.5);
106        let r5 = endo_face_roundness(&m);
107        endo_set_intensity(&mut m, 1.0);
108        let r10 = endo_face_roundness(&m);
109        assert!(r10 > r5 /* more round at higher intensity */);
110    }
111
112    #[test]
113    fn json_has_belly() {
114        let mut m = new_endomorph_morph();
115        endo_set_intensity(&mut m, 0.6);
116        assert!(endo_to_json(&m).contains("belly") /* json has belly key */);
117    }
118
119    #[test]
120    fn enabled_default() {
121        let m = new_endomorph_morph();
122        assert!(m.enabled /* enabled */);
123    }
124
125    #[test]
126    fn config_limb_girth_positive() {
127        let m = new_endomorph_morph();
128        assert!(m.config.limb_girth > 0.0 /* valid */);
129    }
130}