-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9ec36e
commit e492574
Showing
12 changed files
with
83 additions
and
75 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod cardinal; | ||
pub mod ordinal; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use nd_vec::{vector, Vec2}; | ||
use num_traits::Num; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum Direction { | ||
North, | ||
NorthEast, | ||
East, | ||
SouthEast, | ||
South, | ||
SouthWest, | ||
West, | ||
NorthWest, | ||
} | ||
|
||
impl Direction { | ||
pub const ALL: [Direction; 8] = [ | ||
Direction::North, | ||
Direction::NorthEast, | ||
Direction::East, | ||
Direction::SouthEast, | ||
Direction::South, | ||
Direction::SouthWest, | ||
Direction::West, | ||
Direction::NorthWest, | ||
]; | ||
|
||
pub fn try_advance<T: Num + Copy + PartialOrd>(&self, pos: Vec2<T>) -> Option<Vec2<T>> { | ||
Some(match self { | ||
Self::North => vector!(pos.x(), pos.y() + T::one()), | ||
Self::NorthEast => vector!(pos.x() + T::one(), pos.y() + T::one()), | ||
Self::East => vector!(pos.x() + T::one(), pos.y()), | ||
Self::SouthEast if pos.y() > T::zero() => { | ||
vector!(pos.x() + T::one(), pos.y() - T::one()) | ||
} | ||
Self::South if pos.y() > T::zero() => vector!(pos.x(), pos.y() - T::one()), | ||
Self::SouthWest if pos.x() > T::zero() && pos.y() > T::zero() => { | ||
vector!(pos.x() - T::one(), pos.y() - T::one()) | ||
} | ||
Self::West if pos.x() > T::zero() => vector!(pos.x() - T::one(), pos.y()), | ||
Self::NorthWest if pos.x() > T::zero() => { | ||
vector!(pos.x() - T::one(), pos.y() + T::one()) | ||
} | ||
_ => return None, | ||
}) | ||
} | ||
} |
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