fixed_vectors/lib.rs
1#![doc = include_str!("../README.MD")]
2#![no_std]
3
4mod macros;
5
6#[cfg(test)]
7mod tests;
8
9
10/// Vector for holding two-dimensional values.
11///
12/// # Example
13///
14/// ```
15/// use fixed_vectors::Vector2;
16///
17/// let mut vec2 = Vector2::new(1, 2);
18/// vec2 += Vector2::new(1, 2);
19///
20/// assert_eq!(vec2.x, 2);
21/// assert_eq!(vec2.y, 4);
22/// ```
23pub struct Vector2<T> {
24 pub x: T,
25 pub y: T,
26}
27
28
29/// Vector for holding three-dimensional values.
30///
31/// # Example
32///
33/// ```
34/// use fixed_vectors::Vector3;
35///
36/// let mut vec3 = Vector3::new(1, 2, 3);
37/// vec3 += Vector3::new(1, 2, 3);
38///
39/// assert_eq!(vec3.x, 2);
40/// assert_eq!(vec3.y, 4);
41/// assert_eq!(vec3.z, 6);
42/// ```
43pub struct Vector3<T> {
44 pub x: T,
45 pub y: T,
46 pub z: T,
47}
48
49
50/// Vector for holding four-dimensional values.
51///
52/// # Example
53///
54/// ```
55/// use fixed_vectors::Vector4;
56///
57/// let mut vec4 = Vector4::new(1, 2, 3, 4);
58/// vec4 += Vector4::new(1, 2, 3, 4);
59///
60/// assert_eq!(vec4.x, 2);
61/// assert_eq!(vec4.y, 4);
62/// assert_eq!(vec4.z, 6);
63/// assert_eq!(vec4.w, 8);
64/// ```
65pub struct Vector4<T> {
66 pub x: T,
67 pub y: T,
68 pub z: T,
69 pub w: T,
70}
71
72
73impl_vector!(Vector2 { x, y }, (T, T), 2);
74impl_vector!(Vector3 { x, y, z }, (T, T, T), 3);
75impl_vector!(Vector4 { x, y, z, w }, (T, T, T, T), 4);