Add degrees getter for cardinal directions.

This commit is contained in:
Nolan Darilek 2021-07-26 16:07:34 -05:00
parent 42513e7912
commit 5dbc6510bc

View File

@ -1,5 +1,6 @@
use std::{ use std::{
cmp::{max, min}, cmp::{max, min},
f32::consts::PI,
fmt::Display, fmt::Display,
marker::PhantomData, marker::PhantomData,
ops::{Add, AddAssign, Sub, SubAssign}, ops::{Add, AddAssign, Sub, SubAssign},
@ -282,6 +283,15 @@ impl CardinalDirection {
_ => East, _ => East,
} }
} }
pub fn angle(&self) -> Angle {
match self {
CardinalDirection::North => Angle::Radians(PI / 2.),
CardinalDirection::East => Angle::Radians(0.),
CardinalDirection::South => Angle::Radians(-PI / 2.),
CardinalDirection::West => Angle::Radians(PI),
}
}
} }
impl From<Angle> for CardinalDirection { impl From<Angle> for CardinalDirection {