use crate::PhysicsError;
use deep_causality_num::RealField;
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct IndexOfRefraction<R: RealField>(R);
impl<R: RealField> Default for IndexOfRefraction<R> {
fn default() -> Self {
Self(R::zero())
}
}
impl<R: RealField> IndexOfRefraction<R> {
pub fn new(val: R) -> Result<Self, PhysicsError> {
if val == R::zero() {
return Err(PhysicsError::PhysicalInvariantBroken(
"Index of Refraction cannot be zero".into(),
));
}
Ok(Self(val))
}
pub fn value(&self) -> R {
self.0
}
}
impl<R: RealField + Into<f64>> From<IndexOfRefraction<R>> for f64 {
fn from(val: IndexOfRefraction<R>) -> Self {
val.0.into()
}
}