use crate::V3X;
use itertools::zip;
use na::{MatrixSlice3xX, RealField, U1, U10};

/// Component-wise cartesian to spherical conversion.
pub fn cart_to_sph<T>(matrix: &MatrixSlice3xX<T, U1, U10>) -> V3X<T>
where
    T: RealField,
{
    let mut sphericals = V3X::zeros(matrix.ncols());
    for (mut spherical, cartesian) in zip(sphericals.column_iter_mut(), matrix.column_iter()) {
        spherical.copy_from_slice(&[
            cartesian[1].atan2(cartesian[0]),
            (cartesian[2] / cartesian.norm()).asin(),
            cartesian.norm(),
        ]);
    }
    sphericals
}
