From 1491ea8e7587a9d012daff3b6229a8e8d8cb3e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 11 Sep 2021 12:45:59 +0200 Subject: [PATCH] PI now optimal, added Zero-Check --- GlitchyEngine/src/Math/MathHelper.bf | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/GlitchyEngine/src/Math/MathHelper.bf b/GlitchyEngine/src/Math/MathHelper.bf index 05bcb64..fa8d13c 100644 --- a/GlitchyEngine/src/Math/MathHelper.bf +++ b/GlitchyEngine/src/Math/MathHelper.bf @@ -1,12 +1,21 @@ +using System; + namespace GlitchyEngine.Math { public static class MathHelper { - public const float Pi = 3.14159265359f; - public const float TwoPi = 6.28318530718f; - public const float PiOverTwo = 1.57079632679f; - public const float PiOverThree = 1.0471975511965f; - public const float PiOverFour = 0.7853981633974f; + /// An optimal representation of π. + public const float Pi = 3.141592654f; + /// An optimal representation of 2*π. + public const float TwoPi = 6.283185307f; + /// An optimal representation of 1/π. + public const float OneOverPi = 0.318309886f; + /// An optimal representation of 2/π. + public const float OneOverTwoPi = 0.159154943f; + /// An optimal representation of π/2. + public const float PiOverTwo = 1.570796327f; + /// An optimal representation of π/4. + public const float PiOverFour = 0.785398163f; /// Converts radians to degrees const float RadToDeg = 180.0f / Pi; @@ -61,5 +70,12 @@ namespace GlitchyEngine.Math { return degrees * DegToRad; } + + const float epsilon = 0.0000001f; + + public static bool IsZero(float value) + { + return Math.Abs(value) < epsilon; + } } }