wip
This commit is contained in:
parent
e475da5fb4
commit
e026f6efed
@ -1,14 +1,10 @@
|
||||
mod macros;
|
||||
mod vector;
|
||||
mod matrix;
|
||||
pub mod types;
|
||||
pub mod vector;
|
||||
pub mod matrix;
|
||||
|
||||
pub use vector::Vector2;
|
||||
pub use vector::Vector3;
|
||||
pub use vector::Vector4;
|
||||
|
||||
pub use matrix::Matrix2;
|
||||
pub use matrix::Matrix3;
|
||||
pub use matrix::Matrix4;
|
||||
#[cfg(feature="named-fields")]
|
||||
mod named;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -1 +1,50 @@
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_matrix {
|
||||
() => {
|
||||
//$crate::impl_common!();
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_matrix_named_fields_shape {
|
||||
(
|
||||
($struct_outer:ident, $size_outer: expr),
|
||||
($struct_inner:ident, $size_inner: expr)
|
||||
) => {
|
||||
impl<T> core::ops::Deref for Matrix<$size_outer,$size_inner,T>{
|
||||
type Target=$struct_outer<$struct_inner<T>>;
|
||||
fn deref(&self)->&Self::Target{
|
||||
unsafe{core::mem::transmute(&self.array)}
|
||||
}
|
||||
}
|
||||
impl<T> core::ops::DerefMut for Matrix<$size_outer,$size_inner,T>{
|
||||
fn deref_mut(&mut self)->&mut Self::Target{
|
||||
unsafe{core::mem::transmute(&mut self.array)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_matrix_named_fields_shape_shim {
|
||||
(
|
||||
($($vector_info:tt),+),
|
||||
$matrix_info:tt
|
||||
) => {
|
||||
$crate::macro_repeated!(impl_matrix_named_fields_shape,$matrix_info,$($vector_info),+);
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_matrix_named_fields {
|
||||
(
|
||||
($($matrix_info:tt),+),
|
||||
$vector_infos:tt
|
||||
) => {
|
||||
$crate::macro_repeated!(impl_matrix_named_fields_shape_shim,$vector_infos,$($matrix_info),+);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,25 @@
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector {
|
||||
() => {
|
||||
//$crate::impl_common!();
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector_named_fields {
|
||||
( $struct:ident, $size: expr ) => {
|
||||
impl<T> core::ops::Deref for Vector<$size,T>{
|
||||
type Target=$struct<T>;
|
||||
fn deref(&self)->&Self::Target{
|
||||
unsafe{core::mem::transmute(&self.array)}
|
||||
}
|
||||
}
|
||||
impl<T> core::ops::DerefMut for Vector<$size,T>{
|
||||
fn deref_mut(&mut self)->&mut Self::Target{
|
||||
unsafe{core::mem::transmute(&mut self.array)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,8 @@
|
||||
use crate::{Vector2,Vector3,Vector4};
|
||||
|
||||
pub struct Matrix2<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
}
|
||||
pub struct Matrix3<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
pub z_axis: T,
|
||||
}
|
||||
pub struct Matrix4<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
pub z_axis: T,
|
||||
pub w_axis: T,
|
||||
pub struct Matrix<const X:usize,const Y:usize,T>{
|
||||
pub(crate) array:[[T;Y];X],
|
||||
}
|
||||
|
||||
crate::impl_matrix_named_fields!(
|
||||
//outer struct
|
||||
(
|
||||
(Matrix2 { x_axis, y_axis }, 2),
|
||||
(Matrix3 { x_axis, y_axis, z_axis }, 3),
|
||||
(Matrix4 { x_axis, y_axis, z_axis, w_axis }, 4)
|
||||
),
|
||||
//inner struct
|
||||
(
|
||||
(Vector2 { x, y }, 2),
|
||||
(Vector3 { x, y, z }, 3),
|
||||
(Vector4 { x, y, z, w }, 4)
|
||||
)
|
||||
);
|
||||
crate::impl_matrix!();
|
||||
|
||||
//Special case 3x3 matrix operations because I cba to write macros for the arbitrary cases
|
||||
crate::impl_matrix_3x3!();
|
||||
//crate::impl_matrix_3x3!();
|
||||
|
59
fixed_wide_vectors/src/named.rs
Normal file
59
fixed_wide_vectors/src/named.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use crate::vector::Vector;
|
||||
use crate::matrix::Matrix;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Vector2<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct Vector3<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
pub z: T,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct Vector4<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
pub z: T,
|
||||
pub w: T,
|
||||
}
|
||||
|
||||
crate::impl_vector_named_fields!(Vector2, 2);
|
||||
crate::impl_vector_named_fields!(Vector3, 3);
|
||||
crate::impl_vector_named_fields!(Vector4, 4);
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Matrix2<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct Matrix3<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
pub z_axis: T,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct Matrix4<T> {
|
||||
pub x_axis: T,
|
||||
pub y_axis: T,
|
||||
pub z_axis: T,
|
||||
pub w_axis: T,
|
||||
}
|
||||
|
||||
crate::impl_matrix_named_fields!(
|
||||
//outer struct
|
||||
(
|
||||
(Matrix2, 2),
|
||||
(Matrix3, 3),
|
||||
(Matrix4, 4)
|
||||
),
|
||||
//inner struct
|
||||
(
|
||||
(Vector2, 2),
|
||||
(Vector3, 3),
|
||||
(Vector4, 4)
|
||||
)
|
||||
);
|
@ -1,4 +1,4 @@
|
||||
use crate::{Vector2,Vector3,Vector4,Matrix3,Matrix4};
|
||||
use crate::types::{Vector2,Vector3,Vector4,Matrix3,Matrix4};
|
||||
|
||||
type Planar64=fixed_wide::types::I32F32;
|
||||
type Planar64Wide1=fixed_wide::types::I64F64;
|
||||
|
18
fixed_wide_vectors/src/types.rs
Normal file
18
fixed_wide_vectors/src/types.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use crate::vector::Vector;
|
||||
use crate::matrix::Matrix;
|
||||
|
||||
pub type Vector2<T>=Vector<2,T>;
|
||||
pub type Vector3<T>=Vector<3,T>;
|
||||
pub type Vector4<T>=Vector<4,T>;
|
||||
|
||||
pub type Matrix2<T>=Matrix<2,2,T>;
|
||||
pub type Matrix2x3<T>=Matrix<2,3,T>;
|
||||
pub type Matrix2x4<T>=Matrix<2,4,T>;
|
||||
|
||||
pub type Matrix3x2<T>=Matrix<3,2,T>;
|
||||
pub type Matrix3<T>=Matrix<3,3,T>;
|
||||
pub type Matrix3x4<T>=Matrix<3,4,T>;
|
||||
|
||||
pub type Matrix4x2<T>=Matrix<4,2,T>;
|
||||
pub type Matrix4x3<T>=Matrix<4,3,T>;
|
||||
pub type Matrix4<T>=Matrix<4,4,T>;
|
@ -1,24 +1,8 @@
|
||||
pub struct Vector2<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
pub struct Vector<const N:usize,T>{
|
||||
pub(crate) array:[T;N],
|
||||
}
|
||||
|
||||
pub struct Vector3<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
pub z: T,
|
||||
}
|
||||
|
||||
pub struct Vector4<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
pub z: T,
|
||||
pub w: T,
|
||||
}
|
||||
|
||||
crate::impl_vector_named_fields!(Vector2 { x, y }, 2);
|
||||
crate::impl_vector_named_fields!(Vector3 { x, y, z }, 3);
|
||||
crate::impl_vector_named_fields!(Vector4 { x, y, z, w }, 4);
|
||||
crate::impl_vector!();
|
||||
|
||||
//cross product
|
||||
crate::impl_vector_3!();
|
||||
//crate::impl_vector_3!();
|
||||
|
Loading…
Reference in New Issue
Block a user