use kallo_spectral::Spectrum;
use crate::spectral::{GRID_LEN, GRID_START_NM, GRID_STEP_NM};
pub(crate) use crate::emulsion::{FILM_DYES, FILM_MASK, PAPER_DYES, PAPER_LAYERS};
pub(crate) fn spectrum(values: &[f64; GRID_LEN]) -> Spectrum {
Spectrum::new(GRID_START_NM, GRID_STEP_NM, values.to_vec()).expect("the grid is a constant")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_dye_peaks_land_where_the_data_sheet_says() {
for (name, table) in ["cyan", "magenta", "yellow"].iter().zip(&FILM_DYES) {
let peak = table.iter().copied().fold(f64::NEG_INFINITY, f64::max);
assert!((peak - 1.0).abs() < 0.01, "{name} peaks at {peak}");
}
}
#[test]
fn the_tables_are_on_the_models_grid() {
let one = spectrum(&FILM_MASK);
let two = spectrum(&PAPER_DYES[0]);
assert!(one.shares_grid(&two));
assert_eq!(one.len(), GRID_LEN);
}
#[test]
fn the_mask_is_the_measured_minimum_density() {
const MEASURED: [f64; 3] = [0.1867, 0.5782, 0.8319];
let mask = spectrum(&FILM_MASK);
for (wavelength, expected) in [650.0, 550.0, 450.0].iter().zip(MEASURED) {
let at = mask.interpolate(*wavelength);
assert!(
(at - expected).abs() < 0.06,
"{wavelength} nm: mask {at:.4} against measured {expected:.4}"
);
}
}
#[test]
fn the_mask_is_orange() {
let at = |wavelength: f64| {
FILM_MASK[((wavelength - GRID_START_NM) / GRID_STEP_NM).round() as usize]
};
assert!(
at(450.0) > at(650.0),
"blue {} vs red {}",
at(450.0),
at(650.0)
);
}
}