1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#![no_std]
extern crate num;
pub mod vec1;
pub mod vec2;
pub mod vec3;
pub mod vec4;
pub mod math;
#[macro_use]
pub mod macros;
pub use vec1::Vec1;
pub use vec2::Vec2;
pub use vec3::Vec3;
pub use vec4::Vec4;
pub use math::{VecNum, VecInt, VecUnsigned, VecSigned, VecFloat, VecItemNum, VecItemInt, VecItemUnsigned, VecItemSigned, VecItemFloat};
pub trait VecItem: Copy + Clone + PartialEq {}
pub trait Vec {
type Item: VecItem;
}
impl VecItem for u8 {}
impl VecItem for u16 {}
impl VecItem for u32 {}
impl VecItem for u64 {}
impl VecItem for u128 {}
impl VecItem for i8 {}
impl VecItem for i16 {}
impl VecItem for i32 {}
impl VecItem for i64 {}
impl VecItem for i128 {}
impl VecItem for f32 {}
impl VecItem for f64 {}
pub type Vec1u = Vec1<u32>;
pub type Vec2u = Vec2<u32>;
pub type Vec3u = Vec3<u32>;
pub type Vec4u = Vec4<u32>;
pub type Vec1i = Vec1<i32>;
pub type Vec2i = Vec2<i32>;
pub type Vec3i = Vec3<i32>;
pub type Vec4i = Vec4<i32>;
pub type Vec1f = Vec1<f32>;
pub type Vec2f = Vec2<f32>;
pub type Vec3f = Vec3<f32>;
pub type Vec4f = Vec4<f32>;
pub mod prelude {
pub use super::Vec1;
pub use super::Vec2;
pub use super::Vec3;
pub use super::Vec4;
pub use super::Vec1u;
pub use super::Vec2u;
pub use super::Vec3u;
pub use super::Vec4u;
pub use super::Vec1i;
pub use super::Vec2i;
pub use super::Vec3i;
pub use super::Vec4i;
pub use super::Vec1f;
pub use super::Vec2f;
pub use super::Vec3f;
pub use super::Vec4f;
}
#[cfg(test)]
mod tests {
use super::prelude::*;
#[test]
fn basic_construction() {
let _ = Vec1::new(1u32);
let _ = Vec2::new(1u32, 2u32);
let _ = Vec3::new(1u32, 2u32, 3u32);
let _ = Vec4::new(1u32, 2u32, 3u32, 4u32);
let _ = Vec2::from((1u32, 2u32));
let _ = Vec3::from((1u32, 2u32, 3u32));
let _ = Vec4::from((1u32, 2u32, 3u32, 4u32));
}
#[test]
fn basic_operators() {
let _ = Vec1u::new(0) + Vec1u::new(3);
let _ = Vec2u::new(0, 1) + Vec2u::new(3, 2);
let _ = Vec3u::new(0, 1, 2) + Vec3u::new(3, 2, 1);
let _ = Vec4u::new(0, 1, 2, 3) + Vec4u::new(3, 2, 1, 0);
let _ = Vec1u::new(3) - Vec1u::new(3);
let _ = Vec2u::new(3, 2) - Vec2u::new(3, 2);
let _ = Vec3u::new(3, 2, 1) - Vec3u::new(3, 2, 1);
let _ = Vec4u::new(3, 2, 1, 0) - Vec4u::new(3, 2, 1, 0);
let _ = Vec1u::new(1) * Vec1u::new(4);
let _ = Vec2u::new(1, 2) * Vec2u::new(4, 3);
let _ = Vec3u::new(1, 2, 3) * Vec3u::new(4, 3, 2);
let _ = Vec4u::new(1, 2, 3, 4) * Vec4u::new(4, 3, 2, 1);
let _ = Vec1u::new(4) / Vec1u::new(5);
let _ = Vec2u::new(4, 3) / Vec2u::new(5, 4);
let _ = Vec3u::new(4, 3, 2) / Vec3u::new(5, 4, 3);
let _ = Vec4u::new(4, 3, 2, 1) / Vec4u::new(5, 4, 3, 2);
}
fn pass_vec1u(_: Vec1u) {}
fn pass_vec2u(_: Vec2u) {}
fn pass_vec3u(_: Vec3u) {}
fn pass_vec4u(_: Vec4u) {}
#[test]
fn test_pass() {
pass_vec1u(vec!(1u32));
pass_vec2u(vec!(1u32, 2u32));
pass_vec3u(vec!(1u32, 2u32, 3u32));
pass_vec4u(vec!(1u32, 2u32, 3u32, 4u32));
}
}