From a21802e9f2e5c7ba677a6d945579bed9259e5cf3 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sat, 15 Feb 2020 15:14:44 -0500 Subject: [PATCH] FMath.DegToRad(): use look-up table. GitOrigin-RevId: 2dab2e175cf99448595304eeb7593bf499485273 --- Shared/Geometry.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Shared/Geometry.cs b/Shared/Geometry.cs index b5a22e5..58e1eff 100644 --- a/Shared/Geometry.cs +++ b/Shared/Geometry.cs @@ -19,8 +19,24 @@ namespace SemiColinGames { public static class FMath { public const float PI = (float) Math.PI; - public static float DegToRad(float degrees) { - return PI / 180 * degrees; + private static float[] degToRad = new float[360]; + + static FMath() { + for (int i = 0; i < degToRad.Length; i++) { + degToRad[i] = PI / 180 * i; + } + } + + // Converts degrees to radians using a look-up table. Expects the input to be near [0, 360) + // and will loop for potentially a long while if that's not the case. + public static float DegToRad(int degrees) { + while (degrees < 0) { + degrees += 360; + } + while (degrees >= 360) { + degrees -= 360; + } + return degToRad[degrees]; } public static float Sin(double degrees) {