use crate::libs::cs::model::{Cs, Cs2, Cs3};
use crate::libs::cs::model_coords::*;
impl From<Coords2dXy> for Cs2 {
#[inline] fn from(c: Coords2dXy) -> Self { Cs([c.x, c.y]) }
}
impl From<Coords2dXyPolar> for Cs2 {
#[inline] fn from(c: Coords2dXyPolar) -> Self {
let (sin_f, cos_f) = c.f_yx.sin_cos();
Cs([c.r_xy * cos_f, c.r_xy * sin_f])
}
}
impl From<Coords3dXyCylindricalZ> for Cs3 {
#[inline] fn from(c: Coords3dXyCylindricalZ) -> Self {
let (sin_f, cos_f) = c.f_yx.sin_cos();
Cs([c.r_xy * cos_f, c.r_xy * sin_f, c.z])
}
}
impl From<Coords2dXz> for Cs2 {
#[inline] fn from(c: Coords2dXz) -> Self { Cs([c.x, c.z]) }
}
impl From<Coords2dXzPolar> for Cs2 {
#[inline] fn from(c: Coords2dXzPolar) -> Self {
let (sin_f, cos_f) = c.f_zx.sin_cos();
Cs([c.r_xz * cos_f, c.r_xz * sin_f])
}
}
impl From<Coords3dXzCylindricalY> for Cs3 {
#[inline] fn from(c: Coords3dXzCylindricalY) -> Self {
let (sin_f, cos_f) = c.f_zx.sin_cos();
Cs([c.r_xz * cos_f, c.y, c.r_xz * sin_f])
}
}
impl From<Coords2dYz> for Cs2 {
#[inline] fn from(c: Coords2dYz) -> Self { Cs([c.y, c.z]) }
}
impl From<Coords2dYzPolar> for Cs2 {
#[inline] fn from(c: Coords2dYzPolar) -> Self {
let (sin_f, cos_f) = c.f_zy.sin_cos();
Cs([c.r_yz * cos_f, c.r_yz * sin_f])
}
}
impl From<Coords3dYzCylindricalX> for Cs3 {
#[inline] fn from(c: Coords3dYzCylindricalX) -> Self {
let (sin_f, cos_f) = c.f_zy.sin_cos();
Cs([c.x, c.r_yz * cos_f, c.r_yz * sin_f])
}
}
impl From<Coords3dXyz> for Cs3 {
#[inline] fn from(c: Coords3dXyz) -> Self { Cs([c.x, c.y, c.z]) }
}
impl From<Coords3dXyzSpherical> for Cs3 {
#[inline] fn from(c: Coords3dXyzSpherical) -> Self {
let (sin_f, cos_f) = c.f_yx.sin_cos(); let (sin_t, cos_t) = c.t_zr.sin_cos(); Cs([
c.r_xyz * sin_t * cos_f,
c.r_xyz * sin_t * sin_f,
c.r_xyz * cos_t
])
}
}
impl Cs<2>{
#[rustfmt::skip] #[inline]
pub fn new_from_rf(r: f64, phi_rad: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([r * cos_phi, r * sin_phi])
}
#[rustfmt::skip] #[inline] pub fn new_as_xy(&self) -> Cs<3> { Cs([self.0[0], self.0[1], 0.0]) }
#[rustfmt::skip] #[inline] pub fn new_as_xz(&self) -> Cs<3> { Cs([self.0[0], 0.0, self.0[1]]) }
#[rustfmt::skip] #[inline] pub fn new_as_yz(&self) -> Cs<3> { Cs([0.0, self.0[0], self.0[1]]) }
#[rustfmt::skip] #[inline]
pub fn new_as_xy_from_rf(&self) -> Cs<2> {
let (sin_phi, cos_phi) = self.0[1].sin_cos();
Cs([self.0[0] * cos_phi, self.0[0] * sin_phi])
}
#[rustfmt::skip] #[inline]
pub fn new_as_xyz_from_rf_with_z(&self, z: f64) -> Cs<3> {
let (sin_phi, cos_phi) = self.0[1].sin_cos();
Cs([self.0[0] * cos_phi, self.0[0] * sin_phi, z])
}
#[rustfmt::skip] #[inline]
pub fn new_as_xyz_from_rf_with_x(&self, x: f64) -> Cs<3> {
let (sin_phi, cos_phi) = self.0[1].sin_cos();
Cs([x, self.0[0] * cos_phi, self.0[0] * sin_phi])
}
#[rustfmt::skip] #[inline]
pub fn new_as_xyz_from_rf_with_y(&self, y: f64) -> Cs<3> {
let (sin_phi, cos_phi) = self.0[1].sin_cos();
Cs([self.0[0] * cos_phi, y, self.0[0] * sin_phi])
}
}
impl Cs<3> {
#[rustfmt::skip] #[inline]
pub 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]
pub fn new_from_rfz(r_xy: f64, phi_rad: f64, z: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([r_xy * cos_phi, r_xy * sin_phi, z])
}
#[rustfmt::skip] #[inline]
pub fn new_from_rfx(r_yz: f64, phi_rad: f64, x: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([x, r_yz * cos_phi, r_yz * sin_phi])
}
#[rustfmt::skip] #[inline]
pub fn new_from_rfy(r_xz: f64, phi_rad: f64, y: f64) -> Self {
let (sin_phi, cos_phi) = phi_rad.sin_cos();
Cs([r_xz * cos_phi, y, r_xz * sin_phi])
}
#[rustfmt::skip] #[inline]
pub 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
])
}
}