-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clockwise
and counterclockwise
methods to Direction
#13
Labels
Milestone
Comments
alice-i-cecile
added
enhancement
New feature or request
good first issue
Good for newcomers
labels
Feb 2, 2023
Initial external draft and tests. These should take /// Rotates a hex [`Direction`] one step clockwise.
#[must_use]
pub fn clockwise(direction: Direction) -> Direction {
use Direction::*;
match direction {
BottomRight => Bottom,
TopRight => BottomRight,
Top => TopRight,
TopLeft => Top,
BottomLeft => TopLeft,
Bottom => BottomLeft,
}
}
/// Rotates a hex [`Direction`] one step counterclockwise.
#[must_use]
pub fn counterclockwise(direction: Direction) -> Direction {
use Direction::*;
match direction {
BottomRight => TopRight,
TopRight => Top,
Top => TopLeft,
TopLeft => BottomLeft,
BottomLeft => Bottom,
Bottom => BottomRight,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn rotations_reverse_each_other() {
for direction in Direction::ALL_DIRECTIONS {
assert_eq!(direction, counterclockwise(clockwise(direction)));
assert_eq!(direction, clockwise(counterclockwise(direction)));
}
}
#[test]
fn six_rotations_comes_home() {
for direction in Direction::ALL_DIRECTIONS {
let mut cw_direction = direction;
let mut ccw_direction = direction;
for _ in 0..6 {
cw_direction = clockwise(cw_direction);
ccw_direction = counterclockwise(ccw_direction);
}
assert_eq!(direction, cw_direction);
assert_eq!(direction, ccw_direction);
}
}
} |
Great suggestion ! Since
I think Feel free to open a MR ! |
Yep, I'm fine with making these match :) |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This enables easy rotation code for both cameras and object positioning.
The text was updated successfully, but these errors were encountered: