use dim::ucum::Meter2;
use crate::Wavelength;
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct BeamWaist {
pub x: Wavelength,
pub y: Wavelength,
}
impl BeamWaist {
pub fn new(wx: Wavelength) -> Self {
Self { x: wx, y: wx }
}
#[cfg(feature = "elliptic")]
pub fn new_elliptic(wx: Wavelength, wy: Wavelength) -> Self {
Self { x: wx, y: wy }
}
#[cfg(feature = "elliptic")]
pub fn ellipticity(&self) -> f64 {
if self.x == self.y {
1.
} else if self.y < self.x {
*(self.y / self.x)
} else {
*(self.x / self.y)
}
}
pub fn x_by_y(&self) -> Meter2<f64> {
self.x * self.y
}
}
impl From<Wavelength> for BeamWaist {
fn from(wx: Wavelength) -> Self {
Self::new(wx)
}
}
#[cfg(feature = "elliptic")]
impl From<(Wavelength, Wavelength)> for BeamWaist {
fn from(wxwy: (Wavelength, Wavelength)) -> Self {
Self::new_elliptic(wxwy.0, wxwy.1)
}
}