use crate::libs::cs::{
abstracts::AbstractProjectionsCs3,
model::{Cs, *},
types::Cs3,
};
impl From<CoordsXyz> for Cs3 {
#[inline]
fn from(c: CoordsXyz) -> Self { Cs([c.x, c.y, c.z]) }
}
impl From<CoordsCylindricalZ> for Cs3 {
#[inline]
fn from(c: CoordsCylindricalZ) -> Self {
let (sin_f, cos_f) = c.f_y_x.sin_cos();
Cs([c.r_d2 * cos_f, c.r_d2 * sin_f, c.z])
}
}
impl From<CoordsCylindricalY> for Cs3 {
#[inline]
fn from(c: CoordsCylindricalY) -> Self {
let (sin_f, cos_f) = c.f_z_x.sin_cos();
Cs([c.r_d2 * cos_f, c.y, c.r_d2 * sin_f])
}
}
impl From<CoordsCylindricalX> for Cs3 {
#[inline]
fn from(c: CoordsCylindricalX) -> Self {
let (sin_f, cos_f) = c.f_z_y.sin_cos();
Cs([c.x, c.r_d2 * cos_f, c.r_d2 * sin_f])
}
}
impl From<CoordsSpherical> for Cs3 {
#[inline]
fn from(c: CoordsSpherical) -> Self {
let (sin_f, cos_f) = c.f_y_x.sin_cos(); let (sin_t, cos_t) = c.t_z_r.sin_cos(); Cs([c.r_d3 * sin_t * cos_f, c.r_d3 * sin_t * sin_f, c.r_d3 * cos_t])
}
}
impl AbstractProjectionsCs3 for Cs<3> {
#[rustfmt::skip] #[inline]
fn new_from_rft(r: f64, phi_rad: f64, theta_rad: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
let (sin_theta, cos_theta) = theta_rad.sin_cos();
Cs([r * sin_theta * cos_phi, r * sin_theta * sin_phi, r * cos_theta])
}
#[rustfmt::skip] #[inline]
fn new_as_xyz_from_rft(&self) -> Cs<3> {
let (sin_phi, cos_phi) = self.0[1].sin_cos();
let (sin_theta, cos_theta) = self.0[2].sin_cos();
Cs([
self.0[0] * sin_theta * cos_phi,
self.0[0] * sin_theta * sin_phi,
self.0[0] * cos_theta
])
}
#[rustfmt::skip] #[inline]
fn new_from_rfz(r_d2: f64, phi_rad: f64, z: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([r_d2 * cos_phi, r_d2 * sin_phi, z])
}
#[rustfmt::skip] #[inline]
fn new_from_rfx(r_d2: f64, phi_rad: f64, x: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([x, r_d2 * cos_phi, r_d2 * sin_phi])
}
#[rustfmt::skip] #[inline]
fn new_from_rfy(r_d2: f64, phi_rad: f64, y: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([r_d2 * cos_phi, y, r_d2 * sin_phi])
}
}