const C: f64 = 299792458.0;
const KB: f64 = 1.3806485279E-23;
const H: f64 = 6.6260700408181E-34;
const C1: f64 = 2. * std::f64::consts::PI * H * C * C;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SecondRadiationConstant {
Exact,
Nbs1931,
Ipts1948,
Its1968,
}
impl SecondRadiationConstant {
pub fn value(self) -> f64 {
match self {
SecondRadiationConstant::Exact => H * C / KB,
SecondRadiationConstant::Nbs1931 => 1.435e-2,
SecondRadiationConstant::Ipts1948 => 1.4380e-2,
SecondRadiationConstant::Its1968 => 1.4388e-2,
}
}
}
pub struct Planck(f64);
impl Planck {
pub fn new(temperature: f64) -> Self {
Planck(temperature)
}
pub fn at_wavelength(&self, wavelength: f64) -> f64 {
let t = self.0;
let c2 = SecondRadiationConstant::Exact.value();
C1 / wavelength.powi(5) / ((c2 / (wavelength * t)).exp() - 1.0)
}
pub fn slope_at_wavelength(&self, wavelength: f64) -> f64 {
let t = self.0;
let c2 = SecondRadiationConstant::Exact.value();
let c3 = C1 * c2 / t.powi(2);
let e = (c2 / (wavelength * t)).exp();
c3 / wavelength.powi(6) * e / (e - 1.0).powi(2)
}
pub fn planck_with_legacy_c2(&self, wavelength: f64, c2: SecondRadiationConstant) -> f64 {
let t = self.0;
let c2_value = c2.value();
C1 / wavelength.powi(5) / ((c2_value / (wavelength * t)).exp() - 1.0)
}
pub fn slope_with_legacy_c2(&self, wavelength: f64, c2: SecondRadiationConstant) -> f64 {
let t = self.0;
let c2_value = c2.value();
let c3 = C1 * c2_value / t.powi(2);
let e = (c2_value / (wavelength * t)).exp();
c3 / wavelength.powi(6) * e / (e - 1.0).powi(2)
}
pub fn curvature_with_legacy_c2(&self, wavelength: f64, c2: SecondRadiationConstant) -> f64 {
let t = self.0;
let c2_value = c2.value();
let e = (c2_value / (wavelength * t)).exp();
self.slope_with_legacy_c2(wavelength, c2) / t
* (c2_value / (wavelength * t) * (e + 1.0) / (e - 1.0) - 2.0)
}
pub fn total_radiance(&self) -> f64 {
let temperature = self.0;
const SIGMA: f64 = 5.670374419184E-8; SIGMA * temperature.powi(4)
}
}