1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! # Light
//!
//! A library for modeling artistic concepts.

pub use self::kinds::PrimaryLight;
pub use self::kinds::SecondaryLight;
pub use self::utils::mix;

pub mod kinds {
    /// The primary lights according to the RGB light mode.
    pub enum PrimaryLight {
        Red,
        Green,
        Blue,
    }

    /// The secondary lights according to the RGB light model.
    pub enum SecondaryLight {
        Undefined,
        Cyan,
        Magenta,
        Yellow,
    }
}

pub mod utils {
    use crate::kinds::*;

    /// Combines two primary lights in equal amounts to create
    /// a secondary light.
    pub fn mix(l1: PrimaryLight, l2: PrimaryLight) -> SecondaryLight {
        match (l1, l2) {
            (PrimaryLight::Red, PrimaryLight::Green) | (PrimaryLight::Green, PrimaryLight::Red) => SecondaryLight::Yellow,
            (PrimaryLight::Red, PrimaryLight::Blue) | (PrimaryLight::Blue, PrimaryLight::Red) => SecondaryLight::Magenta,
            (PrimaryLight::Green, PrimaryLight::Blue) | (PrimaryLight::Blue, PrimaryLight::Green) => SecondaryLight::Cyan,
            (_, _) => SecondaryLight::Undefined,
        }
    }
}