colr 0.2.0

A general purpose, extensible color type unifying color models and their operations at the type level.
#![no_std]
#![warn(missing_docs)]
#![doc = include_str!("../../../../README.md")]

#[cfg(feature = "std")]
extern crate std;

mod operations;

use core::marker::PhantomData;

pub use colr_types::*;

/// A color value in color model `M` backed by raw type `S`.
///
/// `M: BackingStore<S>` is the only construction gate. For RGB spaces the
/// layout is encoded in `M` as `RgbSpace<P, TF, L>`.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color<S, M>
where
    S: Copy,
    M: BackingStore<S>,
{
    storage: S,
    _model: PhantomData<M>,
}

/// Spectral radiance on the 31-band ICC grid (400-700 nm, 10 nm).
pub type SpectralColor31Radiance = Color<[f32; 31], model::Spectral31Radiance>;
/// Spectral reflectance on the 31-band ICC grid (400-700 nm, 10 nm).
pub type SpectralColor31Reflectance = Color<[f32; 31], model::Spectral31Reflectance>;
/// Spectral transmittance on the 31-band ICC grid (400-700 nm, 10 nm).
pub type SpectralColor31Transmittance = Color<[f32; 31], model::Spectral31Transmittance>;

/// Spectral radiance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
pub type SpectralColor36Radiance = Color<[f32; 36], model::Spectral36Radiance>;
/// Spectral reflectance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
pub type SpectralColor36Reflectance = Color<[f32; 36], model::Spectral36Reflectance>;
/// Spectral transmittance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
pub type SpectralColor36Transmittance = Color<[f32; 36], model::Spectral36Transmittance>;

/// Spectral radiance on the 41-band full-visible grid (380-780 nm, 10 nm).
pub type SpectralColor41Radiance = Color<[f32; 41], model::Spectral41Radiance>;
/// Spectral reflectance on the 41-band full-visible grid (380-780 nm, 10 nm).
pub type SpectralColor41Reflectance = Color<[f32; 41], model::Spectral41Reflectance>;
/// Spectral transmittance on the 41-band full-visible grid (380-780 nm, 10 nm).
pub type SpectralColor41Transmittance = Color<[f32; 41], model::Spectral41Transmittance>;

/// Spectral radiance on the 81-band CIE standard grid (380-780 nm, 5 nm).
pub type SpectralColor81Radiance = Color<[f32; 81], model::Spectral81Radiance>;
/// Spectral reflectance on the 81-band CIE standard grid (380-780 nm, 5 nm).
pub type SpectralColor81Reflectance = Color<[f32; 81], model::Spectral81Reflectance>;
/// Spectral transmittance on the 81-band CIE standard grid (380-780 nm, 5 nm).
pub type SpectralColor81Transmittance = Color<[f32; 81], model::Spectral81Transmittance>;

impl<S, M> Color<S, M>
where
    S: Copy,
    M: BackingStore<S>,
{
    /// Construct without bounds checking.
    #[inline(always)]
    pub fn new(storage: S) -> Self {
        Self {
            storage,
            _model: PhantomData,
        }
    }

    /// Returns the underlying storage value.
    #[inline(always)]
    pub fn inner(&self) -> S {
        self.storage
    }
}