From 631ee0ea9298900c818317359520f43024b6daff Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Sun, 6 Aug 2023 19:16:30 -0400 Subject: [PATCH] Added coterminal angles. --- Nerd_STF/Mathematics/Angle.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Nerd_STF/Mathematics/Angle.cs b/Nerd_STF/Mathematics/Angle.cs index b68b885..f9233c5 100644 --- a/Nerd_STF/Mathematics/Angle.cs +++ b/Nerd_STF/Mathematics/Angle.cs @@ -119,6 +119,31 @@ public struct Angle : IAbsolute, IAverage, IClamp, ICloneab public object Clone() => new Angle(p_deg); + public Angle[] GetCoterminalAngles() => GetCoterminalAngles(Zero, Full); + public Angle[] GetCoterminalAngles(Angle lowerBound, Angle upperBound) + { + List values = new(); + + Angle active = this; + + // A little bit redundant but it's a fairly easy way to guarentee + // all coterminal angles are between the lower and upper bounds. + // Definitely not the most efficient approach. + while (active < upperBound) active += Full; + active -= Full; + + while (active > lowerBound) active -= Full; + active += Full; + + while (active < upperBound) + { + values.Add(active); + active += Full; + } + + return values.ToArray(); + } + public float ValueFromType(Type type) => type switch { Type.Degrees => Degrees,