use crate::core::{ storage::{Columns2, Columns3, Columns4, XY, XYZ, XYZF32A16, XYZW}, traits::{ matrix::{ FloatMatrix2x2, FloatMatrix3x3, FloatMatrix4x4, Matrix, Matrix2x2, Matrix3x3, Matrix4x4, MatrixConst, }, projection::ProjectionMatrix, scalar::{FloatEx, NumEx}, vector::*, }, }; impl MatrixConst for Columns2> { const ZERO: Self = Self { x_axis: XY::ZERO, y_axis: XY::ZERO, }; const IDENTITY: Self = Self { x_axis: XY::X, y_axis: XY::Y, }; } impl Matrix for Columns2> {} impl Matrix2x2> for Columns2> { #[inline(always)] fn from_cols(x_axis: XY, y_axis: XY) -> Self { Self { x_axis, y_axis } } #[inline(always)] fn x_axis(&self) -> &XY { &self.x_axis } #[inline(always)] fn y_axis(&self) -> &XY { &self.y_axis } } impl FloatMatrix2x2> for Columns2> {} impl MatrixConst for Columns3> { const ZERO: Self = Self { x_axis: XYZ::ZERO, y_axis: XYZ::ZERO, z_axis: XYZ::ZERO, }; const IDENTITY: Self = Self { x_axis: XYZ::X, y_axis: XYZ::Y, z_axis: XYZ::Z, }; } impl Matrix for Columns3> {} impl Matrix3x3> for Columns3> { #[inline(always)] fn from_cols(x_axis: XYZ, y_axis: XYZ, z_axis: XYZ) -> Self { Self { x_axis, y_axis, z_axis, } } #[inline(always)] fn x_axis(&self) -> &XYZ { &self.x_axis } #[inline(always)] fn y_axis(&self) -> &XYZ { &self.y_axis } #[inline(always)] fn z_axis(&self) -> &XYZ { &self.z_axis } #[inline] fn mul_vector(&self, other: XYZ) -> XYZ { // default implementation uses splat_x etc, which might not be optimal. Need to check. let mut res = self.x_axis.mul_scalar(other.x); res = self.y_axis.mul_scalar(other.y).add(res); res = self.z_axis.mul_scalar(other.z).add(res); res } } impl FloatMatrix3x3> for Columns3> { #[inline] fn transform_point2(&self, other: XY) -> XY { // TODO: This is untested, probably slower than the high level code that uses a SIMD mat2 Columns2::from_cols(self.x_axis.into(), self.y_axis.into()) .mul_vector(other) .add(self.z_axis.into()) } #[inline] fn transform_vector2(&self, other: XY) -> XY { // TODO: This is untested, probably slower than the high level code that uses a SIMD mat2 Columns2::from_cols(self.x_axis.into(), self.y_axis.into()).mul_vector(other) } } impl MatrixConst for Columns3 { const ZERO: Self = Self { x_axis: XYZF32A16::ZERO, y_axis: XYZF32A16::ZERO, z_axis: XYZF32A16::ZERO, }; const IDENTITY: Self = Self { x_axis: XYZF32A16::X, y_axis: XYZF32A16::Y, z_axis: XYZF32A16::Z, }; } impl Matrix for Columns3 {} impl Matrix3x3 for Columns3 { #[inline(always)] fn from_cols(x_axis: XYZF32A16, y_axis: XYZF32A16, z_axis: XYZF32A16) -> Self { Self { x_axis, y_axis, z_axis, } } #[inline(always)] fn x_axis(&self) -> &XYZF32A16 { &self.x_axis } #[inline(always)] fn y_axis(&self) -> &XYZF32A16 { &self.y_axis } #[inline(always)] fn z_axis(&self) -> &XYZF32A16 { &self.z_axis } } impl FloatMatrix3x3 for Columns3 { #[inline] fn transform_point2(&self, other: XY) -> XY { // TODO: This is untested, probably slower than the high level code that uses a SIMD mat2 Columns2::from_cols(self.x_axis.into_xy(), self.y_axis.into_xy()) .mul_vector(other) .add(self.z_axis.into_xy()) } #[inline] fn transform_vector2(&self, other: XY) -> XY { // TODO: This is untested, probably slower than the high level code that uses a SIMD mat2 Columns2::from_cols(self.x_axis.into_xy(), self.y_axis.into_xy()).mul_vector(other) } } impl MatrixConst for Columns4> { const ZERO: Self = Self { x_axis: XYZW::ZERO, y_axis: XYZW::ZERO, z_axis: XYZW::ZERO, w_axis: XYZW::ZERO, }; const IDENTITY: Self = Self { x_axis: XYZW::X, y_axis: XYZW::Y, z_axis: XYZW::Z, w_axis: XYZW::W, }; } impl Matrix for Columns4> {} impl Matrix4x4> for Columns4> { #[rustfmt::skip] #[inline(always)] fn from_cols(x_axis: XYZW, y_axis: XYZW, z_axis: XYZW, w_axis: XYZW) -> Self { Self { x_axis, y_axis, z_axis, w_axis } } #[inline(always)] fn x_axis(&self) -> &XYZW { &self.x_axis } #[inline(always)] fn y_axis(&self) -> &XYZW { &self.y_axis } #[inline(always)] fn z_axis(&self) -> &XYZW { &self.z_axis } #[inline(always)] fn w_axis(&self) -> &XYZW { &self.w_axis } } impl FloatMatrix4x4> for Columns4> { type SIMDVector3 = XYZ; #[inline(always)] fn transform_float4_as_point3(&self, other: XYZ) -> XYZ { self.transform_point3(other) } #[inline(always)] fn transform_float4_as_vector3(&self, other: XYZ) -> XYZ { self.transform_vector3(other) } #[inline(always)] fn project_float4_as_point3(&self, other: XYZ) -> XYZ { self.project_point3(other) } } impl ProjectionMatrix> for Columns4> {} impl From>> for Columns3 { fn from(v: Columns3>) -> Columns3 { Self { x_axis: v.x_axis.into(), y_axis: v.y_axis.into(), z_axis: v.z_axis.into(), } } } impl From> for Columns3> { fn from(v: Columns3) -> Columns3> { Self { x_axis: v.x_axis.into(), y_axis: v.y_axis.into(), z_axis: v.z_axis.into(), } } }