chapter14_light 0.1.3

TRPL Chapter 14 - Light; instead of art
Documentation
//! # 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.
    #[derive(std::fmt::Debug)]
    pub enum PrimaryLight {
        Red,
        Green,
        Blue,
    }

    /// The secondary lights according to the RGB light model.
    #[derive(std::fmt::Debug)]
    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,
        }
    }
}