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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright (c) 2024-2025, Harbers Bik LLC
//! # Functions and Constants from Physics
//!
//! This module provides core physical constants and spectral‐generation functions
//! used throughout the library to build illuminants, LEDs, black‐body radiators,
//! and band-pass filters.
//!
//! ## Wavelength Conversions
//! - `wavelength(i)` — Map an index or meter‐value `i` to meters (handles both raw nm and index → nm).
//! - `to_wavelength(x, xmin, xmax)` — Linearly interpolate a domain value `x ∈ [xmin, xmax]` to the
//! spectrum range [380 nm … 780 nm].
//!
//! ## Usage
//! Use these primitives to generate accurate spectral power distributions for illuminants,
//! stimuli, colorants, and to perform photometric and radiometric calculations.
//!
use crateSPECTRUM_WAVELENGTH_RANGE;
use f64;
use ToPrimitive;
/// Map a value x, in a domain from xmin to xmax to a wavelength in the domain
/// from 380E-9 to 780E-9 meter.
/// ```
/// // Wavelength from an index value in the domain from 0 to 400:
/// use colorimetry::spectrum::to_wavelength;
///
/// let l = to_wavelength(200, 0, 400);
/// approx::assert_ulps_eq!(l, 580E-9);
///
/// // Wavelength from from a function defined over a domain from 0.0 to 1.0:
/// let l = to_wavelength(0.0, 0.0, 1.0);
/// approx::assert_ulps_eq!(l, 380E-9);
///
/// // Wavelength defined in integer nanometer values, to floating point meters
/// let l = to_wavelength(780, 380, 780);
/// approx::assert_ulps_eq!(l, 780E-9);
/// ```
/// Convenience function for specifying wavelengths in nanometers or meters.
///
/// This accepts integer and float values.
/// Wwavelength values larger than 1E-3 are assumed to have the unit nanometer
/// and are converted to a unit of meters.
/// All integer values are nanometaer values.