Skip to main content

oxihuman_morph/
rosacea_morph.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Rosacea redness pattern morph stub.
6
7/// Rosacea subtype.
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum RosaceaSubtype {
10    Erythematotelangiectatic,
11    Papulopustular,
12    Phymatous,
13    Ocular,
14}
15
16/// Rosacea morph controller.
17#[derive(Debug, Clone)]
18pub struct RosaceaMorph {
19    pub subtype: RosaceaSubtype,
20    pub redness: f32,
21    pub telangiectasia: f32,
22    pub morph_count: usize,
23    pub enabled: bool,
24}
25
26impl RosaceaMorph {
27    pub fn new(morph_count: usize) -> Self {
28        RosaceaMorph {
29            subtype: RosaceaSubtype::Erythematotelangiectatic,
30            redness: 0.3,
31            telangiectasia: 0.2,
32            morph_count,
33            enabled: true,
34        }
35    }
36}
37
38/// Create a new rosacea morph.
39pub fn new_rosacea_morph(morph_count: usize) -> RosaceaMorph {
40    RosaceaMorph::new(morph_count)
41}
42
43/// Set subtype.
44pub fn rsm_set_subtype(morph: &mut RosaceaMorph, subtype: RosaceaSubtype) {
45    morph.subtype = subtype;
46}
47
48/// Set redness level.
49pub fn rsm_set_redness(morph: &mut RosaceaMorph, redness: f32) {
50    morph.redness = redness.clamp(0.0, 1.0);
51}
52
53/// Set telangiectasia (visible blood vessel) density.
54pub fn rsm_set_telangiectasia(morph: &mut RosaceaMorph, density: f32) {
55    morph.telangiectasia = density.clamp(0.0, 1.0);
56}
57
58/// Evaluate morph weights (stub: uniform from redness).
59pub fn rsm_evaluate(morph: &RosaceaMorph) -> Vec<f32> {
60    /* Stub: uniform weight from redness */
61    if !morph.enabled || morph.morph_count == 0 {
62        return vec![];
63    }
64    vec![morph.redness; morph.morph_count]
65}
66
67/// Enable or disable.
68pub fn rsm_set_enabled(morph: &mut RosaceaMorph, enabled: bool) {
69    morph.enabled = enabled;
70}
71
72/// Serialize to JSON-like string.
73pub fn rsm_to_json(morph: &RosaceaMorph) -> String {
74    let sub = match morph.subtype {
75        RosaceaSubtype::Erythematotelangiectatic => "erythematotelangiectatic",
76        RosaceaSubtype::Papulopustular => "papulopustular",
77        RosaceaSubtype::Phymatous => "phymatous",
78        RosaceaSubtype::Ocular => "ocular",
79    };
80    format!(
81        r#"{{"subtype":"{}","redness":{},"telangiectasia":{},"morph_count":{},"enabled":{}}}"#,
82        sub, morph.redness, morph.telangiectasia, morph.morph_count, morph.enabled
83    )
84}
85
86#[cfg(test)]
87mod tests {
88    use super::*;
89
90    #[test]
91    fn test_default_subtype() {
92        let m = new_rosacea_morph(4);
93        assert_eq!(
94            m.subtype,
95            RosaceaSubtype::Erythematotelangiectatic /* default must be Erythematotelangiectatic */
96        );
97    }
98
99    #[test]
100    fn test_set_subtype() {
101        let mut m = new_rosacea_morph(4);
102        rsm_set_subtype(&mut m, RosaceaSubtype::Phymatous);
103        assert_eq!(
104            m.subtype,
105            RosaceaSubtype::Phymatous /* subtype must be set */
106        );
107    }
108
109    #[test]
110    fn test_redness_clamp() {
111        let mut m = new_rosacea_morph(4);
112        rsm_set_redness(&mut m, 2.0);
113        assert!((m.redness - 1.0).abs() < 1e-6 /* redness clamped to 1.0 */);
114    }
115
116    #[test]
117    fn test_telangiectasia_clamp() {
118        let mut m = new_rosacea_morph(4);
119        rsm_set_telangiectasia(&mut m, -0.1);
120        assert!(m.telangiectasia.abs() < 1e-6 /* telangiectasia clamped to 0.0 */);
121    }
122
123    #[test]
124    fn test_evaluate_length() {
125        let m = new_rosacea_morph(5);
126        assert_eq!(
127            rsm_evaluate(&m).len(),
128            5 /* output must match morph_count */
129        );
130    }
131
132    #[test]
133    fn test_evaluate_disabled() {
134        let mut m = new_rosacea_morph(4);
135        rsm_set_enabled(&mut m, false);
136        assert!(rsm_evaluate(&m).is_empty() /* disabled must return empty */);
137    }
138
139    #[test]
140    fn test_to_json_has_subtype() {
141        let m = new_rosacea_morph(4);
142        let j = rsm_to_json(&m);
143        assert!(j.contains("\"subtype\"") /* JSON must have subtype */);
144    }
145
146    #[test]
147    fn test_enabled_default() {
148        let m = new_rosacea_morph(4);
149        assert!(m.enabled /* must be enabled by default */);
150    }
151
152    #[test]
153    fn test_evaluate_matches_redness() {
154        let mut m = new_rosacea_morph(3);
155        rsm_set_redness(&mut m, 0.6);
156        let out = rsm_evaluate(&m);
157        assert!((out[0] - 0.6).abs() < 1e-5 /* evaluate must match redness */);
158    }
159}