Skip to content

Commit

Permalink
feat: add cie spectral luminous efficiency helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther committed Oct 13, 2023
1 parent 1699e60 commit 5f8fe4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clovers/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
#[allow(non_snake_case)]
pub mod D65;
pub mod photon;
pub mod photopic;

pub use photon::*;
pub use photopic::*;
22 changes: 22 additions & 0 deletions clovers/src/colors/photopic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! CIE spectral luminous efficiency for photopic vision <https://doi.org/10.25039/CIE.DS.dktna2s3>
use crate::Float;

use super::Wavelength;

#[allow(clippy::unreadable_literal)]
#[rustfmt::skip]
static CIE_SPECTRAL_LUMINOUS_EFFICIENCY: [f64; 471] = [
0.0000039170000, 0.0000043935810, 0.0000049296040, 0.0000055321360, 0.0000062082450, 0.0000069650000, 0.0000078132190, 0.0000087673360, 0.0000098398440, 0.0000110432300, 0.0000123900000, 0.0000138864100, 0.0000155572800, 0.0000174429600, 0.0000195837500, 0.0000220200000, 0.0000248396500, 0.0000280412600, 0.0000315310400, 0.0000352152100, 0.0000390000000, 0.0000428264000, 0.0000469146000, 0.0000515896000, 0.0000571764000, 0.0000640000000, 0.0000723442100, 0.0000822122400, 0.0000935081600, 0.0001061361000, 0.0001200000000, 0.0001349840000, 0.0001514920000, 0.0001702080000, 0.0001918160000, 0.0002170000000, 0.0002469067000, 0.0002812400000, 0.0003185200000, 0.0003572667000, 0.0003960000000, 0.0004337147000, 0.0004730240000, 0.0005178760000, 0.0005722187000, 0.0006400000000, 0.0007245600000, 0.0008255000000, 0.0009411600000, 0.0010698800000, 0.0012100000000, 0.0013620910000, 0.0015307520000, 0.0017203680000, 0.0019353230000, 0.0021800000000, 0.0024548000000, 0.0027640000000, 0.0031178000000, 0.0035264000000, 0.0040000000000, 0.0045462400000, 0.0051593200000, 0.0058292800000, 0.0065461600000, 0.0073000000000, 0.0080865070000, 0.0089087200000, 0.0097676800000, 0.0106644300000, 0.0116000000000, 0.0125731700000, 0.0135827200000, 0.0146296800000, 0.0157150900000, 0.0168400000000, 0.0180073600000, 0.0192144800000, 0.0204539200000, 0.0217182400000, 0.0230000000000, 0.0242946100000, 0.0256102400000, 0.0269585700000, 0.0283512500000, 0.0298000000000, 0.0313108300000, 0.0328836800000, 0.0345211200000, 0.0362257100000, 0.0380000000000, 0.0398466700000, 0.0417680000000, 0.0437660000000, 0.0458426700000, 0.0480000000000, 0.0502436800000, 0.0525730400000, 0.0549805600000, 0.0574587200000, 0.0600000000000, 0.0626019700000, 0.0652775200000, 0.0680420800000, 0.0709110900000, 0.0739000000000, 0.0770160000000, 0.0802664000000, 0.0836668000000, 0.0872328000000, 0.0909800000000, 0.0949175500000, 0.0990458400000, 0.1033674000000, 0.1078846000000, 0.1126000000000, 0.1175320000000, 0.1226744000000, 0.1279928000000, 0.1334528000000, 0.1390200000000, 0.1446764000000, 0.1504693000000, 0.1564619000000, 0.1627177000000, 0.1693000000000, 0.1762431000000, 0.1835581000000, 0.1912735000000, 0.1994180000000, 0.2080200000000, 0.2171199000000, 0.2267345000000, 0.2368571000000, 0.2474812000000, 0.2586000000000, 0.2701849000000, 0.2822939000000, 0.2950505000000, 0.3085780000000, 0.3230000000000, 0.3384021000000, 0.3546858000000, 0.3716986000000, 0.3892875000000, 0.4073000000000, 0.4256299000000, 0.4443096000000, 0.4633944000000, 0.4829395000000, 0.5030000000000, 0.5235693000000, 0.5445120000000, 0.5656900000000, 0.5869653000000, 0.6082000000000, 0.6293456000000, 0.6503068000000, 0.6708752000000, 0.6908424000000, 0.7100000000000, 0.7281852000000, 0.7454636000000, 0.7619694000000, 0.7778368000000, 0.7932000000000, 0.8081104000000, 0.8224962000000, 0.8363068000000, 0.8494916000000, 0.8620000000000, 0.8738108000000, 0.8849624000000, 0.8954936000000, 0.9054432000000, 0.9148501000000, 0.9237348000000, 0.9320924000000, 0.9399226000000, 0.9472252000000, 0.9540000000000, 0.9602561000000, 0.9660074000000, 0.9712606000000, 0.9760225000000, 0.9803000000000, 0.9840924000000, 0.9874182000000, 0.9903128000000, 0.9928116000000, 0.9949501000000, 0.9967108000000, 0.9980983000000, 0.9991120000000, 0.9997482000000, 1.0000000000000, 0.9998567000000, 0.9993046000000, 0.9983255000000, 0.9968987000000, 0.9950000000000, 0.9926005000000, 0.9897426000000, 0.9864444000000, 0.9827241000000, 0.9786000000000, 0.9740837000000, 0.9691712000000, 0.9638568000000, 0.9581349000000, 0.9520000000000, 0.9454504000000, 0.9384992000000, 0.9311628000000, 0.9234576000000, 0.9154000000000, 0.9070064000000, 0.8982772000000, 0.8892048000000, 0.8797816000000, 0.8700000000000, 0.8598613000000, 0.8493920000000, 0.8386220000000, 0.8275813000000, 0.8163000000000, 0.8047947000000, 0.7930820000000, 0.7811920000000, 0.7691547000000, 0.7570000000000, 0.7447541000000, 0.7324224000000, 0.7200036000000, 0.7074965000000, 0.6949000000000, 0.6822192000000, 0.6694716000000, 0.6566744000000, 0.6438448000000, 0.6310000000000, 0.6181555000000, 0.6053144000000, 0.5924756000000, 0.5796379000000, 0.5668000000000, 0.5539611000000, 0.5411372000000, 0.5283528000000, 0.5156323000000, 0.5030000000000, 0.4904688000000, 0.4780304000000, 0.4656776000000, 0.4534032000000, 0.4412000000000, 0.4290800000000, 0.4170360000000, 0.4050320000000, 0.3930320000000, 0.3810000000000, 0.3689184000000, 0.3568272000000, 0.3447768000000, 0.3328176000000, 0.3210000000000, 0.3093381000000, 0.2978504000000, 0.2865936000000, 0.2756245000000, 0.2650000000000, 0.2547632000000, 0.2448896000000, 0.2353344000000, 0.2260528000000, 0.2170000000000, 0.2081616000000, 0.1995488000000, 0.1911552000000, 0.1829744000000, 0.1750000000000, 0.1672235000000, 0.1596464000000, 0.1522776000000, 0.1451259000000, 0.1382000000000, 0.1315003000000, 0.1250248000000, 0.1187792000000, 0.1127691000000, 0.1070000000000, 0.1014762000000, 0.0961886400000, 0.0911229600000, 0.0862648500000, 0.0816000000000, 0.0771206400000, 0.0728255200000, 0.0687100800000, 0.0647697600000, 0.0610000000000, 0.0573962100000, 0.0539550400000, 0.0506737600000, 0.0475496500000, 0.0445800000000, 0.0417587200000, 0.0390849600000, 0.0365638400000, 0.0342004800000, 0.0320000000000, 0.0299626100000, 0.0280766400000, 0.0263293600000, 0.0247080500000, 0.0232000000000, 0.0218007700000, 0.0205011200000, 0.0192810800000, 0.0181206900000, 0.0170000000000, 0.0159037900000, 0.0148371800000, 0.0138106800000, 0.0128347800000, 0.0119200000000, 0.0110683100000, 0.0102733900000, 0.0095333110000, 0.0088461570000, 0.0082100000000, 0.0076237810000, 0.0070854240000, 0.0065914760000, 0.0061384850000, 0.0057230000000, 0.0053430590000, 0.0049957960000, 0.0046764040000, 0.0043800750000, 0.0041020000000, 0.0038384530000, 0.0035890990000, 0.0033542190000, 0.0031340930000, 0.0029290000000, 0.0027381390000, 0.0025598760000, 0.0023932440000, 0.0022372750000, 0.0020910000000, 0.0019535870000, 0.0018245800000, 0.0017035800000, 0.0015901870000, 0.0014840000000, 0.0013844960000, 0.0012912680000, 0.0012040920000, 0.0011227440000, 0.0010470000000, 0.0009765896000, 0.0009111088000, 0.0008501332000, 0.0007932384000, 0.0007400000000, 0.0006900827000, 0.0006433100000, 0.0005994960000, 0.0005584547000, 0.0005200000000, 0.0004839136000, 0.0004500528000, 0.0004183452000, 0.0003887184000, 0.0003611000000, 0.0003353835000, 0.0003114404000, 0.0002891656000, 0.0002684539000, 0.0002492000000, 0.0002313019000, 0.0002146856000, 0.0001992884000, 0.0001850475000, 0.0001719000000, 0.0001597781000, 0.0001486044000, 0.0001383016000, 0.0001287925000, 0.0001200000000, 0.0001118595000, 0.0001043224000, 0.0000973356000, 0.0000908458700, 0.0000848000000, 0.0000791466700, 0.0000738580000, 0.0000689160000, 0.0000643026700, 0.0000600000000, 0.0000559818700, 0.0000522256000, 0.0000487184000, 0.0000454474700, 0.0000424000000, 0.0000395610400, 0.0000369151200, 0.0000344486800, 0.0000321481600, 0.0000300000000, 0.0000279912500, 0.0000261135600, 0.0000243602400, 0.0000227246100, 0.0000212000000, 0.0000197785500, 0.0000184528500, 0.0000172168700, 0.0000160645900, 0.0000149900000, 0.0000139872800, 0.0000130515500, 0.0000121781800, 0.0000113625400, 0.0000106000000, 0.0000098858770, 0.0000092173040, 0.0000085923620, 0.0000080091330, 0.0000074657000, 0.0000069595670, 0.0000064879950, 0.0000060486990, 0.0000056393960, 0.0000052578000, 0.0000049017710, 0.0000045697200, 0.0000042601940, 0.0000039717390, 0.0000037029000, 0.0000034521630, 0.0000032183020, 0.0000030003000, 0.0000027971390, 0.0000026078000, 0.0000024312200, 0.0000022665310, 0.0000021130130, 0.0000019699430, 0.0000018366000, 0.0000017122300, 0.0000015962280, 0.0000014880900, 0.0000013873140, 0.0000012934000, 0.0000012058200, 0.0000011241430, 0.0000010480090, 0.0000009770578, 0.0000009109300, 0.0000008492513, 0.0000007917212, 0.0000007380904, 0.0000006881098, 0.0000006415300, 0.0000005980895, 0.0000005575746, 0.0000005198080, 0.0000004846123, 0.0000004518100,
];

/// Get the spectral luminous efficiency for photopic vision for the given wavelength in nanometers.
///
/// Input wavelenght must be between `360` and `830` inclusive.
#[must_use]
#[allow(clippy::cast_possible_truncation)]
pub fn cie_sle(lambda: Wavelength) -> Float {
assert!(lambda >= 360);
assert!(lambda <= 830);
CIE_SPECTRAL_LUMINOUS_EFFICIENCY[lambda - 360] as Float
}

0 comments on commit 5f8fe4c

Please sign in to comment.