From e1d28bcea818201276b30d20c0df6dd052b12375 Mon Sep 17 00:00:00 2001 From: Odilf Date: Sat, 12 Aug 2023 15:32:13 +0200 Subject: [PATCH] added `direction_on_axis` method to edge --- barbarosa/src/cube_n/pieces/edge.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/barbarosa/src/cube_n/pieces/edge.rs b/barbarosa/src/cube_n/pieces/edge.rs index 773550c..47de9c1 100644 --- a/barbarosa/src/cube_n/pieces/edge.rs +++ b/barbarosa/src/cube_n/pieces/edge.rs @@ -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): &::Position, + axis: Axis, + ) -> Option { + 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 {