2024-08-23 22:42:48 +00:00
|
|
|
// Stolen from https://github.com/c1m50c/fixed-vectors (MIT license)
|
|
|
|
|
|
|
|
/// Vector for holding two-dimensional values.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2024-08-23 23:31:25 +00:00
|
|
|
/// use fixed_wide_vectors::Vector2;
|
2024-08-23 22:42:48 +00:00
|
|
|
///
|
|
|
|
/// let mut vec2 = Vector2::new(1, 2);
|
|
|
|
/// vec2 += Vector2::new(1, 2);
|
|
|
|
///
|
|
|
|
/// assert_eq!(vec2.x, 2);
|
|
|
|
/// assert_eq!(vec2.y, 4);
|
|
|
|
/// ```
|
|
|
|
pub struct Vector2<T> {
|
2024-08-28 17:47:30 +00:00
|
|
|
pub x: T,
|
|
|
|
pub y: T,
|
2024-08-23 22:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Vector for holding three-dimensional values.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2024-08-23 23:31:25 +00:00
|
|
|
/// use fixed_wide_vectors::Vector3;
|
2024-08-23 22:42:48 +00:00
|
|
|
///
|
|
|
|
/// let mut vec3 = Vector3::new(1, 2, 3);
|
|
|
|
/// vec3 += Vector3::new(1, 2, 3);
|
|
|
|
///
|
|
|
|
/// assert_eq!(vec3.x, 2);
|
|
|
|
/// assert_eq!(vec3.y, 4);
|
|
|
|
/// assert_eq!(vec3.z, 6);
|
|
|
|
/// ```
|
|
|
|
pub struct Vector3<T> {
|
2024-08-28 17:47:30 +00:00
|
|
|
pub x: T,
|
|
|
|
pub y: T,
|
|
|
|
pub z: T,
|
2024-08-23 22:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Vector for holding four-dimensional values.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2024-08-23 23:31:25 +00:00
|
|
|
/// use fixed_wide_vectors::Vector4;
|
2024-08-23 22:42:48 +00:00
|
|
|
///
|
|
|
|
/// let mut vec4 = Vector4::new(1, 2, 3, 4);
|
|
|
|
/// vec4 += Vector4::new(1, 2, 3, 4);
|
|
|
|
///
|
|
|
|
/// assert_eq!(vec4.x, 2);
|
|
|
|
/// assert_eq!(vec4.y, 4);
|
|
|
|
/// assert_eq!(vec4.z, 6);
|
|
|
|
/// assert_eq!(vec4.w, 8);
|
|
|
|
/// ```
|
|
|
|
pub struct Vector4<T> {
|
2024-08-28 17:47:30 +00:00
|
|
|
pub x: T,
|
|
|
|
pub y: T,
|
|
|
|
pub z: T,
|
|
|
|
pub w: T,
|
2024-08-23 22:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
crate::impl_vector!(Vector2 { x, y }, (T, T), 2);
|
|
|
|
crate::impl_vector!(Vector3 { x, y, z }, (T, T, T), 3);
|
|
|
|
crate::impl_vector!(Vector4 { x, y, z, w }, (T, T, T, T), 4);
|
2024-08-30 19:06:33 +00:00
|
|
|
|
2024-08-30 19:41:25 +00:00
|
|
|
crate::impl_vector_extend!((Vector2 { x, y }), (Vector3, z));
|
|
|
|
crate::impl_vector_extend!((Vector3 { x, y, z }), (Vector4, w));
|
|
|
|
|
2024-08-30 19:06:33 +00:00
|
|
|
crate::impl_matrix!((Vector2 { x, y }, ((T, T), (T, T)), 2), (Vector2, 2), (Vector2 { x, y }) );
|
|
|
|
crate::impl_matrix!((Vector2 { x, y }, ((T, T, T), (T, T, T)), 2), (Vector3, 3), (Vector3 { x, y, z }) );
|
|
|
|
crate::impl_matrix!((Vector2 { x, y }, ((T, T, T, T), (T, T, T, T)), 2), (Vector4, 4), (Vector4 { x, y, z, w }) );
|
|
|
|
crate::impl_matrix!((Vector3 { x, y, z }, ((T, T), (T, T), (T, T)), 3), (Vector2, 2), (Vector2 { x, y }) );
|
|
|
|
crate::impl_matrix!((Vector3 { x, y, z }, ((T, T, T), (T, T, T), (T, T, T)), 3), (Vector3, 3), (Vector3 { x, y, z }) );
|
|
|
|
crate::impl_matrix!((Vector3 { x, y, z }, ((T, T, T, T), (T, T, T, T), (T, T, T, T)), 3), (Vector4, 4), (Vector4 { x, y, z, w }) );
|
|
|
|
crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T), (T, T), (T, T), (T, T)), 4), (Vector2, 2), (Vector2 { x, y }) );
|
|
|
|
crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T, T), (T, T, T), (T, T, T), (T, T, T)), 4), (Vector3, 3), (Vector3 { x, y, z }) );
|
|
|
|
crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T, T, T), (T, T, T, T), (T, T, T, T), (T, T, T, T)), 4), (Vector4, 4), (Vector4 { x, y, z, w }) );
|