utiles_core/
sibling_relationship.rs

1//! Child index as related to its parent/sibling-tiles
2use crate::tile::Tile;
3
4/// Sibling relationship for tiles
5pub enum SiblingRelationship {
6    /// `UpperLeft` sibling
7    UpperLeft = 0,
8    /// `UpperRight` sibling
9    UpperRight = 1,
10    /// `LowerLeft` sibling
11    LowerLeft = 2,
12    /// `LowerRight` sibling
13    LowerRight = 3,
14}
15
16impl From<(u32, u32)> for SiblingRelationship {
17    fn from(value: (u32, u32)) -> Self {
18        let is_left = value.0 % 2 == 0;
19        let is_top = value.1 % 2 == 0;
20        match (is_left, is_top) {
21            (true, true) => SiblingRelationship::UpperLeft,
22            (true, false) => SiblingRelationship::LowerLeft,
23            (false, true) => SiblingRelationship::UpperRight,
24            (false, false) => SiblingRelationship::LowerRight,
25        }
26    }
27}
28
29impl From<Tile> for SiblingRelationship {
30    fn from(value: Tile) -> Self {
31        let is_left = value.x % 2 == 0;
32        let is_top = value.y % 2 == 0;
33        match (is_left, is_top) {
34            (true, true) => SiblingRelationship::UpperLeft,
35            (true, false) => SiblingRelationship::LowerLeft,
36            (false, true) => SiblingRelationship::UpperRight,
37            (false, false) => SiblingRelationship::LowerRight,
38        }
39    }
40}