//! MatrixColumn trait for matrix column access.

use crate::math::{Matrix, Vector};
#[cfg(not(target_arch = "spirv"))]
use na::Scalar;

/// Extension trait for matrix column access (like nalgebra's `.column()`)
pub trait MatrixColumn {
    /// The column type returned by `column()`.
    type Column;
    /// Returns the i-th column of this matrix.
    fn column(&self, i: usize) -> Self::Column;
}

impl<T: Copy> MatrixColumn for [T; 2] {
    type Column = T;
    fn column(&self, i: usize) -> Self::Column {
        self[i]
    }
}

impl MatrixColumn for Matrix {
    type Column = Vector;
    #[inline]
    fn column(&self, i: usize) -> Self::Column {
        self.col(i)
    }
}

#[cfg(not(target_arch = "spirv"))]
impl<T: Scalar> MatrixColumn for na::Matrix3<T> {
    type Column = na::Vector3<T>;
    #[inline]
    fn column(&self, i: usize) -> Self::Column {
        self.column(i).into_owned()
    }
}

#[cfg(not(target_arch = "spirv"))]
impl<T: Scalar> MatrixColumn for na::Matrix2<T> {
    type Column = na::Vector2<T>;
    #[inline]
    fn column(&self, i: usize) -> Self::Column {
        self.column(i).into_owned()
    }
}
