grafix_toolbox/kit/policies/
math.rs

1macro_rules! impl_func_cast {
2	($($t: ident),+) => {
3		$(pub fn $t<T>(v: T) -> $t
4		where
5			$t: Cast<T>,
6		{
7			$t::to(v)
8		})+
9	};
10}
11macro_rules! def_vec {
12	($n2: ident, $n3: ident, $n4: ident, $t: ty) => {
13		pub type $n2 = vec2<$t>;
14		pub type $n3 = vec3<$t>;
15		pub type $n4 = vec4<$t>;
16		impl_func_cast!($n2, $n3, $n4);
17	};
18}
19
20pub mod pre {
21	pub use super::cast::{f16, Cast};
22	impl_func_cast!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, f16, f32, f64, usize, isize);
23
24	def_vec!(hVec2, hVec3, hVec4, f16);
25	def_vec!(Vec2, Vec3, Vec4, f32);
26	def_vec!(dVec2, dVec3, dVec4, f64);
27	def_vec!(ibVec2, ibVec3, ibVec4, i8);
28	def_vec!(ubVec2, ubVec3, ubVec4, u8);
29	def_vec!(isVec2, isVec3, isVec4, i16);
30	def_vec!(usVec2, usVec3, usVec4, u16);
31	def_vec!(iVec2, iVec3, iVec4, i32);
32	def_vec!(uVec2, uVec3, uVec4, u32);
33	def_vec!(ilVec2, ilVec3, ilVec4, isize);
34	def_vec!(ulVec2, ulVec3, ulVec4, usize);
35
36	pub type Mat2 = mat2<f32>;
37	pub type Mat3 = mat3<f32>;
38	pub type Mat4 = mat4<f32>;
39	pub type Mat2x3 = mat2x3<f32>;
40	pub type Mat3x2 = mat3x2<f32>;
41	pub type Mat2x4 = mat2x4<f32>;
42	pub type Mat4x2 = mat4x2<f32>;
43	pub type Mat3x4 = mat3x4<f32>;
44	pub type Mat4x3 = mat4x3<f32>;
45	impl_func_cast!(Mat2, Mat3, Mat4, Mat2x3, Mat3x2, Mat2x4, Mat4x2, Mat3x4, Mat4x3);
46
47	pub type vec2<T> = (T, T);
48	pub type vec3<T> = (T, T, T);
49	pub type vec4<T> = (T, T, T, T);
50
51	pub type mat2<T> = (vec2<T>, vec2<T>);
52	pub type mat3<T> = (vec3<T>, vec3<T>, vec3<T>);
53	pub type mat4<T> = (vec4<T>, vec4<T>, vec4<T>, vec4<T>);
54	pub type mat2x3<T> = (vec3<T>, vec3<T>);
55	pub type mat3x2<T> = (vec2<T>, vec2<T>, vec2<T>);
56	pub type mat2x4<T> = (vec4<T>, vec4<T>);
57	pub type mat4x2<T> = (vec2<T>, vec2<T>, vec2<T>, vec2<T>);
58	pub type mat3x4<T> = (vec4<T>, vec4<T>, vec4<T>);
59	pub type mat4x3<T> = (vec3<T>, vec3<T>, vec3<T>, vec3<T>);
60}
61
62pub mod ext {
63	pub use super::{cast::matrix::*, math_ext::*, pre::*, tuple::*};
64}
65
66pub mod la;
67
68mod cast;
69mod math_ext;
70mod tuple;