From 5dbc6510bcf98dfbd96aec302faf89f6227eef2d Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 26 Jul 2021 16:07:34 -0500 Subject: [PATCH] Add degrees getter for cardinal directions. --- src/core.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core.rs b/src/core.rs index ababec2..ed5bec8 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,5 +1,6 @@ use std::{ cmp::{max, min}, + f32::consts::PI, fmt::Display, marker::PhantomData, ops::{Add, AddAssign, Sub, SubAssign}, @@ -282,6 +283,15 @@ impl CardinalDirection { _ => 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 for CardinalDirection {