Last active
September 4, 2017 21:37
-
-
Save jsimmons/d5950421c76ed8b894493bf18cec380a to your computer and use it in GitHub Desktop.
Does it Pack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Copy, Clone, Debug)] | |
struct Tile { | |
/// A - B - C | |
/// | | | |
/// H D | |
/// | | | |
/// G - F - E | |
/// | |
/// A = 0 | |
/// H = 7 | |
/// | |
/// CounterClockwise winding | |
/// | |
/// Packs into 8 bits? | |
/// 7 0 | |
/// c c s s s e e e | |
/// | |
/// c: edge curve | |
/// 0 = linear | |
/// 1 = concave | |
/// 2 = convex | |
/// | |
/// s: start point | |
/// e: end point | |
/// | |
/// EMPTY: | |
/// start = 0 | |
/// end = 0 | |
/// curve = 0 | |
/// | |
/// FULL: | |
/// sentinel? | |
/// c = 3? | |
/// | |
/// or | |
/// | |
/// start = 7 | |
/// end = 7 | |
/// | |
/// both! | |
/// | |
/// full = 0xff | |
/// | |
packed: u8 | |
} | |
impl Tile { | |
fn empty() -> Tile { | |
Self { | |
packed: 0 | |
} | |
} | |
fn full() -> Tile { | |
Self { | |
packed: 0xff | |
} | |
} | |
fn invert(&self) -> Tile { | |
let t = self.packed; | |
Self { | |
packed: t & 0xc | (((t >> 3) & 0x7) | ((t << 3) & 0x38)) | |
} | |
} | |
fn rot(&self, d: i32) -> Tile { | |
let t = self.packed; | |
let start = (((t & 0x38) >> 3) as i32 + d * 2) % 8; | |
let end = ((t & 0x7) as i32 + d * 2) % 8; | |
Self { | |
packed: t & 0xc | (start << 3) as u8 | end as u8 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment