/// <summary> /// Wraps an angle in [0, 360) range. Values lower than zero, or higher or equal to 360 /// will get wrapped around back into [0, 360) range. /// </summary> /// <param name="angle">Angle to wrap.</param> /// <returns>Angle in [0, 360) range.</returns> public static Degree WrapAngle(Degree angle) { const float inv360 = 1.0f / 360.0f; float angleVal = angle.Degrees; float wrapCount = (float)MathEx.Floor(MathEx.Abs(angleVal) * inv360); if (angleVal > 0.0f) { angleVal -= 360.0f * wrapCount; } else if (angleVal < 0.0f) { angleVal += 360.0f * (wrapCount + 1); } return(new Degree(angleVal)); }