Skip to main content

cubek_std/cube_count/hypercube/
global_order.rs

1/// The zigzag a swizzled order walks, which is a walk's own arithmetic and lives with the
2/// walk ([`cubek_tile::space::swizzle`](fn@cubek_tile::space::swizzle)). Re-exported here because [`GlobalOrder`]'s swizzle arms
3/// are its one caller in this crate.
4pub use cubek_tile::space::swizzle;
5
6#[derive(Default, Copy, Clone, Debug, Hash, PartialEq, Eq)]
7/// Describes the global traversal order as flattened cube position increases.
8///
9/// - `RowMajor`: standard row-first traversal
10/// - `ColMajor`: standard column-first traversal
11/// - `SwizzleCol(w)`: zigzag pattern down columns, with `w`-wide steps
12/// - `SwizzleRow(w)`: zigzag pattern across rows, with `w`-wide steps
13///
14/// Special cases:
15/// - `SwizzleCol(1)` is equivalent to `ColMajor`
16/// - `SwizzleRow(1)` is equivalent to `RowMajor`
17///
18/// Swizzle modes may fail if their `w` does not divide the problem well.
19#[allow(clippy::enum_variant_names)]
20pub enum GlobalOrder {
21    #[default]
22    RowMajor,
23    ColMajor,
24    SwizzleRow(u32),
25    SwizzleCol(u32),
26}
27
28impl GlobalOrder {
29    /// Since they are equivalent but the latter form will skip some calculations,
30    /// - `SwizzleColMajor(1)` becomes `ColMajor`
31    /// - `SwizzleRowMajor(1)` becomes `RowMajor`
32    pub fn canonicalize(self) -> Self {
33        match self {
34            GlobalOrder::SwizzleCol(1) => GlobalOrder::ColMajor,
35            GlobalOrder::SwizzleRow(1) => GlobalOrder::RowMajor,
36            _ => self,
37        }
38    }
39}