Skip to main content

hexga_graphics/mesh/
mesh_geometry.rs

1use super::*;
2
3pub type TriangleVertex<const V: usize> = GeometryTriangle<VertexOf<V>>;
4pub type GeometryVertex<const V: usize, const N: usize> = Geometry<VertexOf<V>, N>;
5
6pub type GeometryTriangle<T> = Geometry<T, 3>;
7pub type TriangleVertexIndex = GeometryTriangle<VertexIndex>;
8
9impl<T> Geometry<T, 2>
10{
11    pub const fn new(a: T, b: T) -> Self { Self::from_array([a, b]) }
12}
13impl<T> Geometry<T, 3>
14{
15    pub const fn new(a: T, b: T, c: T) -> Self { Self::from_array([a, b, c]) }
16}
17
18#[repr(C)]
19#[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd, Hash)]
20pub struct Geometry<T, const N: usize>
21{
22    pub points: [T; N],
23}
24impl<T, const N: usize> Geometry<T, N>
25{
26    pub const fn from_array(points: [T; N]) -> Self { Self { points } }
27}
28
29impl<T, const N: usize> From<[T; N]> for Geometry<T, N>
30{
31    fn from(value: [T; N]) -> Self { Self::from_array(value) }
32}
33
34impl<T, const N: usize> IntoIterator for Geometry<T, N>
35{
36    type Item = <[T; N] as IntoIterator>::Item;
37    type IntoIter = <[T; N] as IntoIterator>::IntoIter;
38    fn into_iter(self) -> Self::IntoIter { self.points.into_iter() }
39}
40impl<'a, T, const N: usize> IntoIterator for &'a Geometry<T, N>
41{
42    type Item = <&'a [T; N] as IntoIterator>::Item;
43    type IntoIter = <&'a [T; N] as IntoIterator>::IntoIter;
44    fn into_iter(self) -> Self::IntoIter { (&self.points).into_iter() }
45}
46impl<'a, T, const N: usize> IntoIterator for &'a mut Geometry<T, N>
47{
48    type Item = <&'a mut [T; N] as IntoIterator>::Item;
49    type IntoIter = <&'a mut [T; N] as IntoIterator>::IntoIter;
50    fn into_iter(self) -> Self::IntoIter { (&mut self.points).into_iter() }
51}