binary_greedy_meshing/
quad.rs1use alloc::string::String;
2
3pub(crate) const MASK_6: u64 = 0b111111;
4
5#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
6pub struct Quad(pub u64);
7
8impl Quad {
9 #[inline]
21 pub fn pack(x: usize, y: usize, z: usize, w: usize, h: usize, v_type: usize) -> Self {
22 Quad(((v_type << 32) | (h << 24) | (w << 18) | (z << 12) | (y << 6) | x) as u64)
23 }
24
25 #[inline]
26 pub fn xyz(&self) -> [u64; 3] {
27 let x = (self.0) & MASK_6;
28 let y = (self.0 >> 6) & MASK_6;
29 let z = (self.0 >> 12) & MASK_6;
30 [x, y, z]
31 }
32
33 #[inline]
34 pub fn width(&self) -> u64 {
35 (self.0 >> 18) & MASK_6
36 }
37
38 #[inline]
39 pub fn height(&self) -> u64 {
40 (self.0 >> 24) & MASK_6
41 }
42
43 #[inline]
44 pub fn voxel_id(&self) -> u64 {
45 self.0 >> 32
46 }
47
48 #[inline]
50 pub fn debug_quad(&self) -> String {
51 let mut quad = self.0;
52 let x = quad & MASK_6;
53 quad >>= 6;
54 let y = quad & MASK_6;
55 quad >>= 6;
56 let z = quad & MASK_6;
57 quad >>= 6;
58 let w = quad & MASK_6;
59 quad >>= 6;
60 let h = quad & MASK_6;
61 quad >>= 8;
62 let v_type = quad;
63 format!("{x};{y};{z} {w}x{h} v={v_type}")
64 }
65}
66
67impl alloc::fmt::Debug for Quad {
68 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69 f.debug_struct("Quad")
70 .field("position", &self.xyz())
71 .field("width", &self.width())
72 .field("height", &self.height())
73 .field("voxel_id", &self.voxel_id())
74 .finish()
75 }
76}