From fb48386aad9a7ae52f022b9bed9a2386b92ad1d6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 29 Dec 2019 12:05:49 +0100 Subject: [PATCH] actually use math --- MLEM/Misc/Direction2.cs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/MLEM/Misc/Direction2.cs b/MLEM/Misc/Direction2.cs index 10ad758..e4a2522 100644 --- a/MLEM/Misc/Direction2.cs +++ b/MLEM/Misc/Direction2.cs @@ -88,26 +88,8 @@ namespace MLEM.Misc { } public static float Angle(this Direction2 dir) { - switch (dir) { - case Direction2.Up: - return MathHelper.PiOver2; - case Direction2.Right: - return MathHelper.TwoPi; - case Direction2.Down: - return 3 * MathHelper.PiOver2; - case Direction2.Left: - return MathHelper.Pi; - case Direction2.UpRight: - return MathHelper.PiOver4; - case Direction2.DownRight: - return 7 * MathHelper.PiOver4; - case Direction2.DownLeft: - return 5 * MathHelper.PiOver4; - case Direction2.UpLeft: - return 3 * MathHelper.PiOver4; - default: - return -1; - } + var offset = dir.Offset(); + return (float) Math.Atan2(offset.Y, offset.X); } }