oxihuman_morph/
skin_translucency_morph.rs1#![allow(dead_code)]
4
5#[derive(Debug, Clone)]
9pub struct SkinTranslucencyMorph {
10 pub translucency: f32,
11 pub thin_skin_factor: f32,
12 pub vein_visibility: f32,
13}
14
15impl SkinTranslucencyMorph {
16 pub fn new() -> Self {
17 Self {
18 translucency: 0.4,
19 thin_skin_factor: 0.3,
20 vein_visibility: 0.1,
21 }
22 }
23}
24
25impl Default for SkinTranslucencyMorph {
26 fn default() -> Self {
27 Self::new()
28 }
29}
30
31pub fn new_skin_translucency_morph() -> SkinTranslucencyMorph {
33 SkinTranslucencyMorph::new()
34}
35
36pub fn skin_trans_set_translucency(morph: &mut SkinTranslucencyMorph, translucency: f32) {
38 morph.translucency = translucency.clamp(0.0, 1.0);
39}
40
41pub fn skin_trans_set_thin_skin(morph: &mut SkinTranslucencyMorph, factor: f32) {
43 morph.thin_skin_factor = factor.clamp(0.0, 1.0);
44}
45
46pub fn skin_trans_set_vein_visibility(morph: &mut SkinTranslucencyMorph, visibility: f32) {
48 morph.vein_visibility = visibility.clamp(0.0, 1.0);
49}
50
51pub fn skin_trans_light_bleed(morph: &SkinTranslucencyMorph) -> f32 {
53 (morph.translucency * 0.7 + morph.thin_skin_factor * 0.3).clamp(0.0, 1.0)
54}
55
56pub fn skin_translucency_morph_to_json(morph: &SkinTranslucencyMorph) -> String {
58 format!(
59 r#"{{"translucency":{:.4},"thin_skin_factor":{:.4},"vein_visibility":{:.4}}}"#,
60 morph.translucency, morph.thin_skin_factor, morph.vein_visibility
61 )
62}
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_defaults() {
70 let m = new_skin_translucency_morph();
71 assert!((m.translucency - 0.4).abs() < 1e-6);
72 }
73
74 #[test]
75 fn test_translucency_clamp() {
76 let mut m = new_skin_translucency_morph();
77 skin_trans_set_translucency(&mut m, 2.0);
78 assert_eq!(m.translucency, 1.0);
79 }
80
81 #[test]
82 fn test_thin_skin_set() {
83 let mut m = new_skin_translucency_morph();
84 skin_trans_set_thin_skin(&mut m, 0.7);
85 assert!((m.thin_skin_factor - 0.7).abs() < 1e-6);
86 }
87
88 #[test]
89 fn test_vein_visibility() {
90 let mut m = new_skin_translucency_morph();
91 skin_trans_set_vein_visibility(&mut m, 0.5);
92 assert!((m.vein_visibility - 0.5).abs() < 1e-6);
93 }
94
95 #[test]
96 fn test_light_bleed_range() {
97 let m = new_skin_translucency_morph();
98 let lb = skin_trans_light_bleed(&m);
99 assert!((0.0..=1.0).contains(&lb));
100 }
101
102 #[test]
103 fn test_json() {
104 let m = new_skin_translucency_morph();
105 let s = skin_translucency_morph_to_json(&m);
106 assert!(s.contains("thin_skin_factor"));
107 }
108
109 #[test]
110 fn test_clone() {
111 let m = new_skin_translucency_morph();
112 let m2 = m.clone();
113 assert!((m2.vein_visibility - m.vein_visibility).abs() < 1e-6);
114 }
115
116 #[test]
117 fn test_vein_clamp_low() {
118 let mut m = new_skin_translucency_morph();
119 skin_trans_set_vein_visibility(&mut m, -0.5);
120 assert_eq!(m.vein_visibility, 0.0);
121 }
122
123 #[test]
124 fn test_default_trait() {
125 let m: SkinTranslucencyMorph = Default::default();
126 assert!((m.thin_skin_factor - 0.3).abs() < 1e-6);
127 }
128}