Skip to main content

swizzle

Function swizzle 

Source
pub fn swizzle(index: usize, num_steps: usize, step_length: u32) -> Coords2d
Expand description

Maps a linear index to 2D zigzag coordinates (x, y) within horizontal or vertical strips.

Each strip is made of num_steps steps, each of length step_length. Strips alternate direction: even strips go top-down, odd strips bottom-up. Steps alternate direction: even steps go left-to-right, odd steps right-to-left.

  • Prefer odd num_steps for smoother transitions between strips.
  • Prefer power-of-two step_length for better performance.

§Parameters

  • index: linear input index
  • num_steps: number of snaking steps in a strip
  • step_length: number of elements in each step (must be > 0)

§Returns

(x, y) coordinates after swizzling