Skip to content

Commit

Permalink
added direction_on_axis method to edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Odilf committed Aug 12, 2023
1 parent 3fa7e6a commit e1d28bc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions barbarosa/src/cube_n/pieces/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ impl Edge {
Axis::Z => Face::new(Axis::X, slice_pos[0]),
}
}

/// Gets the direction of the edge position on the given axis.
///
/// Returns `None` if the axis is the normal axis of the edge.
pub fn direction_on_axis(
&(normal, slice_pos): &<Edge as Piece>::Position,
axis: Axis,
) -> Option<Direction> {
if axis == normal {
return None;
}

let x = normal.next();
let y = x.next();

if axis == x {
Some(slice_pos[0])
} else if axis == y {
Some(slice_pos[1])
} else {
unreachable!()
}
}
}

impl std::fmt::Debug for Edge {
Expand Down

0 comments on commit e1d28bc

Please sign in to comment.