diff --git a/Robust.Client/Animations/AnimationTrackProperty.cs b/Robust.Client/Animations/AnimationTrackProperty.cs index ddc378eb8..bd9be6bb6 100644 --- a/Robust.Client/Animations/AnimationTrackProperty.cs +++ b/Robust.Client/Animations/AnimationTrackProperty.cs @@ -97,15 +97,15 @@ namespace Robust.Client.Animations case Vector4 vector4: return Vector4.Lerp(vector4, (Vector4) b, t); case float f: - return FloatMath.Lerp(f, (float) b, t); + return MathHelper.Lerp(f, (float) b, t); case double d: - return FloatMath.Lerp(d, (double) b, t); + return MathHelper.Lerp(d, (double) b, t); case Angle angle: - return (Angle) FloatMath.Lerp(angle, (Angle) b, t); + return (Angle) MathHelper.Lerp(angle, (Angle) b, t); case Color color: return Color.InterpolateBetween(color, (Color) b, t); case int i: - return (int) FloatMath.Lerp((double) i, (int) b, t); + return (int) MathHelper.Lerp((double) i, (int) b, t); default: // Fall back to "previous" interpolation, treating this as a discrete value. return a; @@ -123,11 +123,11 @@ namespace Robust.Client.Animations case Vector4 vector4: return Vector4.InterpolateCubic((Vector4) preA, vector4, (Vector4) b, (Vector4) postB, t); case float f: - return FloatMath.InterpolateCubic((float) preA, f, (float) b, (float) postB, t); + return MathHelper.InterpolateCubic((float) preA, f, (float) b, (float) postB, t); case double d: - return FloatMath.InterpolateCubic((double) preA, d, (double) b, (double) postB, t); + return MathHelper.InterpolateCubic((double) preA, d, (double) b, (double) postB, t); case int i: - return (int) FloatMath.InterpolateCubic((int) preA, (double) i, (int) b, (int) postB, t); + return (int) MathHelper.InterpolateCubic((int) preA, (double) i, (int) b, (int) postB, t); default: // Fall back to "previous" interpolation, treating this as a discrete value. return a; diff --git a/Robust.Client/Debugging/DebugDrawing.cs b/Robust.Client/Debugging/DebugDrawing.cs index d403af89f..bf129c141 100644 --- a/Robust.Client/Debugging/DebugDrawing.cs +++ b/Robust.Client/Debugging/DebugDrawing.cs @@ -217,7 +217,7 @@ namespace Robust.Client.Debugging public override Color CalcWakeColor(Color color, float wakePercent) { - var percent = FloatMath.Clamp(wakePercent, 0, 1); + var percent = MathHelper.Clamp(wakePercent, 0, 1); var r = 1 - (percent * (1 - color.R)); var g = 1 - (percent * (1 - color.G)); diff --git a/Robust.Client/GameObjects/EntitySystems/EyeUpdateSystem.cs b/Robust.Client/GameObjects/EntitySystems/EyeUpdateSystem.cs index 4255d632e..58a763d4c 100644 --- a/Robust.Client/GameObjects/EntitySystems/EyeUpdateSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/EyeUpdateSystem.cs @@ -81,7 +81,7 @@ namespace Robust.Client.GameObjects.EntitySystems var currentDir = currentEye.Rotation.ToVec(); var dot = Vector2.Dot(closestDir, currentDir); - if (FloatMath.CloseTo(dot, 1, CameraSnapTolerance)) + if (MathHelper.CloseTo(dot, 1, CameraSnapTolerance)) { currentEye.Rotation = closestDir.ToAngle(); } diff --git a/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs b/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs index 977dddc1e..8476f6930 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs @@ -380,13 +380,13 @@ namespace Robust.Client.Graphics.Clyde lightShader.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0); } - if (!FloatMath.CloseTo(lastRange, component.Radius)) + if (!MathHelper.CloseTo(lastRange, component.Radius)) { lastRange = component.Radius; lightShader.SetUniformMaybe("lightRange", lastRange); } - if (!FloatMath.CloseTo(lastPower, component.Energy)) + if (!MathHelper.CloseTo(lastPower, component.Energy)) { lastPower = component.Energy; lightShader.SetUniformMaybe("lightPower", lastPower); diff --git a/Robust.Client/UserInterface/Controls/ItemList.cs b/Robust.Client/UserInterface/Controls/ItemList.cs index 0a06614b2..52a939bc8 100644 --- a/Robust.Client/UserInterface/Controls/ItemList.cs +++ b/Robust.Client/UserInterface/Controls/ItemList.cs @@ -473,7 +473,7 @@ namespace Robust.Client.UserInterface.Controls { base.MouseWheel(args); - if (FloatMath.CloseTo(0, args.Delta.Y)) + if (MathHelper.CloseTo(0, args.Delta.Y)) { return; } diff --git a/Robust.Client/UserInterface/Controls/LineEdit.cs b/Robust.Client/UserInterface/Controls/LineEdit.cs index 9775e1a72..dbb359d1d 100644 --- a/Robust.Client/UserInterface/Controls/LineEdit.cs +++ b/Robust.Client/UserInterface/Controls/LineEdit.cs @@ -126,7 +126,7 @@ namespace Robust.Client.UserInterface.Controls get => _cursorPosition; set { - _cursorPosition = FloatMath.Clamp(value, 0, _text.Length); + _cursorPosition = MathHelper.Clamp(value, 0, _text.Length); _selectionStart = _cursorPosition; } } @@ -134,7 +134,7 @@ namespace Robust.Client.UserInterface.Controls public int SelectionStart { get => _selectionStart; - set => _selectionStart = FloatMath.Clamp(value, 0, _text.Length); + set => _selectionStart = MathHelper.Clamp(value, 0, _text.Length); } public int SelectionLower => Math.Min(_selectionStart, _cursorPosition); @@ -236,7 +236,7 @@ namespace Robust.Client.UserInterface.Controls _drawOffset += (int) Math.Ceiling(args.DeltaSeconds / MouseScrollDelay); } - var index = GetIndexAtPos(FloatMath.Clamp(_lastMousePosition, contentBox.Left, contentBox.Right)); + var index = GetIndexAtPos(MathHelper.Clamp(_lastMousePosition, contentBox.Left, contentBox.Right)); _cursorPosition = index; } diff --git a/Robust.Client/UserInterface/Controls/OutputPanel.cs b/Robust.Client/UserInterface/Controls/OutputPanel.cs index ae10d867d..be9bfdab7 100644 --- a/Robust.Client/UserInterface/Controls/OutputPanel.cs +++ b/Robust.Client/UserInterface/Controls/OutputPanel.cs @@ -152,7 +152,7 @@ namespace Robust.Client.UserInterface.Controls { base.MouseWheel(args); - if (FloatMath.CloseTo(0, args.Delta.Y)) + if (MathHelper.CloseTo(0, args.Delta.Y)) { return; } diff --git a/Robust.Client/UserInterface/Controls/Range.cs b/Robust.Client/UserInterface/Controls/Range.cs index cccf438ec..7f3a93a21 100644 --- a/Robust.Client/UserInterface/Controls/Range.cs +++ b/Robust.Client/UserInterface/Controls/Range.cs @@ -76,7 +76,7 @@ namespace Robust.Client.UserInterface.Controls private void _ensureValueClamped() { var newValue = ClampValue(_value); - if (!FloatMath.CloseTo(newValue, _value)) + if (!MathHelper.CloseTo(newValue, _value)) { _value = newValue; OnValueChanged?.Invoke(this); @@ -86,7 +86,7 @@ namespace Robust.Client.UserInterface.Controls [Pure] protected float ClampValue(float value) { - return FloatMath.Clamp(value, _minValue, _maxValue-_page); + return MathHelper.Clamp(value, _minValue, _maxValue-_page); } } } diff --git a/Robust.Client/UserInterface/Controls/ScrollBar.cs b/Robust.Client/UserInterface/Controls/ScrollBar.cs index 534cef325..491650b37 100644 --- a/Robust.Client/UserInterface/Controls/ScrollBar.cs +++ b/Robust.Client/UserInterface/Controls/ScrollBar.cs @@ -51,7 +51,7 @@ namespace Robust.Client.UserInterface.Controls get { var offset = ValueTarget + Page; - return offset > MaxValue || FloatMath.CloseTo(offset, MaxValue); + return offset > MaxValue || MathHelper.CloseTo(offset, MaxValue); } } @@ -65,14 +65,14 @@ namespace Robust.Client.UserInterface.Controls { base.FrameUpdate(args); - if (!VisibleInTree || FloatMath.CloseTo(Value, ValueTarget)) + if (!VisibleInTree || MathHelper.CloseTo(Value, ValueTarget)) { Value = ValueTarget; } else { _updating = true; - Value = FloatMath.Lerp(Value, ValueTarget, args.DeltaSeconds * 15); + Value = MathHelper.Lerp(Value, ValueTarget, args.DeltaSeconds * 15); _updating = false; } } diff --git a/Robust.Client/UserInterface/Controls/SplitContainer.cs b/Robust.Client/UserInterface/Controls/SplitContainer.cs index 4b1faed95..b30910942 100644 --- a/Robust.Client/UserInterface/Controls/SplitContainer.cs +++ b/Robust.Client/UserInterface/Controls/SplitContainer.cs @@ -117,7 +117,7 @@ namespace Robust.Client.UserInterface.Controls /// private float ClampSplitCenter(float splitCenter, float? firstMinSize = null, float? secondMinSize = null) { - splitCenter = FloatMath.Clamp(splitCenter, SplitMin, SplitMax); + splitCenter = MathHelper.Clamp(splitCenter, SplitMin, SplitMax); if (ResizeMode == SplitResizeMode.RespectChildrenMinSize && ChildCount == 2) { @@ -128,7 +128,7 @@ namespace Robust.Client.UserInterface.Controls secondMinSize ??= (Vertical ? second.CombinedMinimumSize.Y : second.CombinedMinimumSize.X); var size = Vertical ? Height : Width; - splitCenter = FloatMath.Clamp(splitCenter, firstMinSize.Value, size - (secondMinSize.Value + SplitWidth)); + splitCenter = MathHelper.Clamp(splitCenter, firstMinSize.Value, size - (secondMinSize.Value + SplitWidth)); } return splitCenter; @@ -181,7 +181,7 @@ namespace Robust.Client.UserInterface.Controls _splitCenter = firstMinSize; } - _splitCenter += FloatMath.Clamp(0f, firstMinSize - _splitCenter, size - secondMinSize - SplitWidth - _splitCenter); + _splitCenter += MathHelper.Clamp(0f, firstMinSize - _splitCenter, size - secondMinSize - SplitWidth - _splitCenter); break; } } diff --git a/Robust.Client/UserInterface/CustomControls/DebugConsole.cs b/Robust.Client/UserInterface/CustomControls/DebugConsole.cs index cd043fa16..a89e1de8c 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugConsole.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugConsole.cs @@ -127,7 +127,7 @@ namespace Robust.Client.UserInterface.CustomControls } else { - posY = FloatMath.Lerp(posY, targetLocation, args.DeltaSeconds * 20); + posY = MathHelper.Lerp(posY, targetLocation, args.DeltaSeconds * 20); } LayoutContainer.SetPosition(MainControl, (posX, posY)); diff --git a/Robust.Shared.Maths/Angle.cs b/Robust.Shared.Maths/Angle.cs index cd827eb93..e787aa2b7 100644 --- a/Robust.Shared.Maths/Angle.cs +++ b/Robust.Shared.Maths/Angle.cs @@ -114,9 +114,9 @@ namespace Robust.Shared.Maths // The second two expressions cover an edge case where one number is barely non-negative while the other number is negative. // In this case, the negative number will get FlipPositived to ~2pi and the comparison will give a false negative. - return FloatMath.CloseTo(aPositive, bPositive) - || FloatMath.CloseTo(aPositive + MathHelper.TwoPi, bPositive) - || FloatMath.CloseTo(aPositive, bPositive + MathHelper.TwoPi); + return MathHelper.CloseTo(aPositive, bPositive) + || MathHelper.CloseTo(aPositive + MathHelper.TwoPi, bPositive) + || MathHelper.CloseTo(aPositive, bPositive + MathHelper.TwoPi); } private static bool EqualsApprox(Angle a, Angle b, double tolerance) @@ -130,9 +130,9 @@ namespace Robust.Shared.Maths // The second two expressions cover an edge case where one number is barely non-negative while the other number is negative. // In this case, the negative number will get FlipPositived to ~2pi and the comparison will give a false negative. - return FloatMath.CloseTo(aPositive, bPositive, tolerance) - || FloatMath.CloseTo(aPositive + MathHelper.TwoPi, bPositive, tolerance) - || FloatMath.CloseTo(aPositive, bPositive + MathHelper.TwoPi, tolerance); + return MathHelper.CloseTo(aPositive, bPositive, tolerance) + || MathHelper.CloseTo(aPositive + MathHelper.TwoPi, bPositive, tolerance) + || MathHelper.CloseTo(aPositive, bPositive + MathHelper.TwoPi, tolerance); } /// @@ -205,12 +205,12 @@ namespace Robust.Shared.Maths /// public static Angle Lerp(in Angle a, in Angle b, float factor) { - var degA = FloatMath.RadToDeg * Angle.Reduce(a); - var degB = FloatMath.RadToDeg * Angle.Reduce(b); - var delta = FloatMath.Repeat((float) (degB - degA), 360); + var degA = MathHelper.RadiansToDegrees(Reduce(a)); + var degB = MathHelper.RadiansToDegrees(Reduce(b)); + var delta = MathHelper.Mod((degB - degA), 360); if (delta > 180) delta -= 360; - return new Angle(FloatMath.DegToRad * (degA + delta * FloatMath.Clamp01(factor))); + return new Angle(MathHelper.DegreesToRadians(degA + delta * MathHelper.Clamp(factor, 0, 1))); } /// diff --git a/Robust.Shared.Maths/Box2.cs b/Robust.Shared.Maths/Box2.cs index f8fecff4d..5ab3736ae 100644 --- a/Robust.Shared.Maths/Box2.cs +++ b/Robust.Shared.Maths/Box2.cs @@ -174,7 +174,7 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsEmpty() { - return FloatMath.CloseTo(Width, 0.0f) && FloatMath.CloseTo(Height, 0.0f); + return MathHelper.CloseTo(Width, 0.0f) && MathHelper.CloseTo(Height, 0.0f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -271,10 +271,10 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Box2 a, Box2 b) { - return FloatMath.CloseTo(a.Bottom, b.Bottom) && - FloatMath.CloseTo(a.Right, b.Right) && - FloatMath.CloseTo(a.Top, b.Top) && - FloatMath.CloseTo(a.Left, b.Left); + return MathHelper.CloseTo(a.Bottom, b.Bottom) && + MathHelper.CloseTo(a.Right, b.Right) && + MathHelper.CloseTo(a.Top, b.Top) && + MathHelper.CloseTo(a.Left, b.Left); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -326,8 +326,8 @@ namespace Robust.Shared.Maths public Vector2 ClosestPoint(in Vector2 position) { // clamp the point to the border of the box - var cx = FloatMath.Clamp(position.X, Left, Right); - var cy = FloatMath.Clamp(position.Y, Bottom, Top); + var cx = MathHelper.Clamp(position.X, Left, Right); + var cy = MathHelper.Clamp(position.Y, Bottom, Top); return new Vector2(cx, cy); } diff --git a/Robust.Shared.Maths/Circle.cs b/Robust.Shared.Maths/Circle.cs index 1f760ec63..033cc195b 100644 --- a/Robust.Shared.Maths/Circle.cs +++ b/Robust.Shared.Maths/Circle.cs @@ -68,8 +68,8 @@ namespace Robust.Shared.Maths var d2 = dx * dx + dy * dy; var r2 = Radius * Radius; - // Instead of d2 <= r2, use FloatMath.CloseTo to allow for some tolerance. - return (d2 < r2) || FloatMath.CloseTo(d2, r2); + // Instead of d2 <= r2, use MathHelper.CloseTo to allow for some tolerance. + return (d2 < r2) || MathHelper.CloseTo(d2, r2); } /// diff --git a/Robust.Shared.Maths/Color.cs b/Robust.Shared.Maths/Color.cs index 0ec50c0e1..61f2117b8 100644 --- a/Robust.Shared.Maths/Color.cs +++ b/Robust.Shared.Maths/Color.cs @@ -992,10 +992,10 @@ namespace Robust.Shared.Maths public bool Equals(Color other) { return - FloatMath.CloseTo(R, other.R) && - FloatMath.CloseTo(G, other.G) && - FloatMath.CloseTo(B, other.B) && - FloatMath.CloseTo(A, other.A); + MathHelper.CloseTo(R, other.R) && + MathHelper.CloseTo(G, other.G) && + MathHelper.CloseTo(B, other.B) && + MathHelper.CloseTo(A, other.A); } [PublicAPI] diff --git a/Robust.Shared.Maths/FloatMath.cs b/Robust.Shared.Maths/FloatMath.cs index 47a23c0d6..a9c905576 100644 --- a/Robust.Shared.Maths/FloatMath.cs +++ b/Robust.Shared.Maths/FloatMath.cs @@ -3,121 +3,43 @@ using System.Runtime.CompilerServices; namespace Robust.Shared.Maths { + [Obsolete("Use MathHelper instead.")] public static class FloatMath { - public const float RadToDeg = (float) (180.0 / Math.PI); - public const float DegToRad = (float) (Math.PI / 180.0); - - /// - /// Returns the largest integer smaller to or equal to f. - /// -#if NETCOREAPP [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Floor(float f) => MathF.Floor(f); -#else - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Floor(float f) => (float)Math.Floor(f); -#endif - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T Clamp(T val, T min, T max) - where T : IComparable + public static float Clamp01(float val) { - if (val.CompareTo(min) < 0) return min; - if (val.CompareTo(max) > 0) return max; - return val; + return MathHelper.Clamp01(val); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Clamp(T val, T min, T max) where T : IComparable + { + return MathHelper.Clamp(val, min, max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Clamp(float val, float min, float max) { - return Math.Max(Math.Min(val, max), min); + return MathHelper.Clamp(val, min, max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Clamp(double val, double min, double max) { - return Math.Max(Math.Min(val, max), min); + return MathHelper.Clamp(val, min, max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool CloseTo(float a, float b, double tolerance = .00001) { - var epsilon = - Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, - tolerance); // .001% of the smaller value for the epsilon check as per MSDN reference suggestion - return Math.Abs(a - b) <= epsilon; + return MathHelper.CloseTo(a, b, tolerance); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool CloseTo(float a, double b, double tolerance = .00001) - { - var epsilon = - Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, - tolerance); // .001% of the smaller value for the epsilon check as per MSDN reference suggestion - return Math.Abs(a - b) <= epsilon; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool CloseTo(double a, float b, double tolerance = .00001) - { - var epsilon = - Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, - tolerance); // .001% of the smaller value for the epsilon check as per MSDN reference suggestion - return Math.Abs(a - b) <= epsilon; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool CloseTo(double a, double b, double tolerance = .00001) - { - var epsilon = - Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, - tolerance); // .001% of the smaller value for the epsilon check as per MSDN reference suggestion - return Math.Abs(a - b) <= epsilon; - } - - /// - /// blend 0 means a - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Lerp(double a, double b, double blend) - { - return a + (b - a) * blend; - } - - /// - /// blend 0 means a - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Lerp(float a, float b, float blend) { - return a + (b - a) * blend; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float InterpolateCubic(float preA, float a, float b, float postB, float t) - { - return a + 0.5f * t * (b - preA + t * (2.0f * preA - 5.0f * a + 4.0f * b - postB + t * (3.0f * (a - b) + postB - preA))); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double InterpolateCubic(double preA, double a, double b, double postB, double t) - { - return a + 0.5 * t * (b - preA + t * (2.0 * preA - 5.0 * a + 4.0 * b - postB + t * (3.0 * (a - b) + postB - preA))); - } - - // Clamps value between 0 and 1 and returns value - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Clamp01(float value) - { - return FloatMath.Clamp(value, 0, 1); - } - - // Loops the value t, so that it is never larger than length and never smaller than 0. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Repeat(float t, float length) - { - return Clamp(t - Floor(t / length) * length, 0.0f, length); + return MathHelper.Lerp(a, b, blend); } } } diff --git a/Robust.Shared.Maths/MathHelper.cs b/Robust.Shared.Maths/MathHelper.cs index 1e40b548c..e9946f2ec 100644 --- a/Robust.Shared.Maths/MathHelper.cs +++ b/Robust.Shared.Maths/MathHelper.cs @@ -88,7 +88,7 @@ namespace Robust.Shared.Maths public static long NextPowerOfTwo(long n) { if (n <= 0) throw new ArgumentOutOfRangeException(nameof(n), "Must be positive."); - return (long)NextPowerOfTwo((double) n); + return (long) NextPowerOfTwo((double) n); } /// @@ -100,7 +100,7 @@ namespace Robust.Shared.Maths public static int NextPowerOfTwo(int n) { if (n <= 0) throw new ArgumentOutOfRangeException(nameof(n), "Must be positive."); - return (int)NextPowerOfTwo((double) n); + return (int) NextPowerOfTwo((double) n); } /// @@ -111,9 +111,10 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float NextPowerOfTwo(float n) { - if (float.IsNaN(n) || float.IsInfinity(n)) throw new ArgumentOutOfRangeException(nameof(n), "Must be a number."); + if (float.IsNaN(n) || float.IsInfinity(n)) + throw new ArgumentOutOfRangeException(nameof(n), "Must be a number."); if (n <= 0) throw new ArgumentOutOfRangeException(nameof(n), "Must be positive."); - return (float)NextPowerOfTwo((double) n); + return (float) NextPowerOfTwo((double) n); } /// @@ -124,7 +125,8 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double NextPowerOfTwo(double n) { - if (double.IsNaN(n) || double.IsInfinity(n)) throw new ArgumentOutOfRangeException(nameof(n), "Must be a number."); + if (double.IsNaN(n) || double.IsInfinity(n)) + throw new ArgumentOutOfRangeException(nameof(n), "Must be a number."); if (n <= 0) throw new ArgumentOutOfRangeException(nameof(n), "Must be positive."); // Don't return negative powers of two, that's nonsense. @@ -254,12 +256,18 @@ namespace Robust.Shared.Maths #region MinMax + /// + /// Returns the minimum of 4 values + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Min(float a, float b, float c, float d) { return MathF.Min(a, MathF.Min(b, MathF.Min(c, d))); } + /// + /// Returns the maximum of 4 values + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Max(float a, float b, float c, float d) { @@ -269,7 +277,7 @@ namespace Robust.Shared.Maths /// /// Returns the median value out of a, b and c. /// - /// THe median. + /// The median. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Median(float a, float b, float c) { @@ -278,6 +286,8 @@ namespace Robust.Shared.Maths #endregion MinMax + #region Mod + /// /// This method provides floored modulus. /// C-like languages use truncated modulus for their '%' operator. @@ -292,6 +302,20 @@ namespace Robust.Shared.Maths return n - Math.Floor(n / d) * d; } + /// + /// This method provides floored modulus. + /// C-like languages use truncated modulus for their '%' operator. + /// + /// The dividend. + /// The divisor. + /// The remainder. + [DebuggerStepThrough] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Mod(float n, float d) + { + return n - (float) Math.Floor(n / d) * d; + } + /// /// This method provides floored modulus. /// C-like languages use truncated modulus for their '%' operator. @@ -307,6 +331,142 @@ namespace Robust.Shared.Maths return r < 0 ? r + d : r; } + #endregion Mod + + /// + /// Clamps between and . + /// + #region Clamp + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Clamp(T val, T min, T max) + where T : IComparable + { + if (val.CompareTo(min) < 0) return min; + if (val.CompareTo(max) > 0) return max; + return val; + } + + /// + /// Clamps between and . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Clamp(float val, float min, float max) + { + return Math.Max(Math.Min(val, max), min); + } + + /// + /// Clamps between and . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Clamp(double val, double min, double max) + { + return Math.Max(Math.Min(val, max), min); + } + + /// + /// Clamps between 0 and 1. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Clamp01(float val) + { + return Clamp(val, 0, 1); + } + + #endregion Clamp + + #region CloseTo + + /// + /// Returns whether two floating point numbers are within of eachother + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool CloseTo(float a, float b, double tolerance = .00001) + { + // .001% of the smaller value for the epsilon check as per MSDN reference suggestion + double epsilon = Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, tolerance); + return Math.Abs(a - b) <= epsilon; + } + + /// + /// Returns whether two floating point numbers are within of eachother + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool CloseTo(float a, double b, double tolerance = .00001) + { + // .001% of the smaller value for the epsilon check as per MSDN reference suggestion + double epsilon = Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, tolerance); + return Math.Abs(a - b) <= epsilon; + } + + /// + /// Returns whether two floating point numbers are within of eachother + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool CloseTo(double a, float b, double tolerance = .00001) + { + // .001% of the smaller value for the epsilon check as per MSDN reference suggestion + double epsilon = Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, tolerance); + return Math.Abs(a - b) <= epsilon; + } + + /// + /// Returns whether two floating point numbers are within of eachother + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool CloseTo(double a, double b, double tolerance = .00001) + { + // .001% of the smaller value for the epsilon check as per MSDN reference suggestion + double epsilon = Math.Max(Math.Max(Math.Abs(a), Math.Abs(b)) * tolerance, tolerance); + return Math.Abs(a - b) <= epsilon; + } + + #endregion CloseTo + + #region Lerp + + /// + /// Linearly interpolates between to , returning the value at . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Lerp(double a, double b, double blend) + { + return a + (b - a) * blend; + } + + /// + /// Linearly interpolates between to , returning the value at . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Lerp(float a, float b, float blend) + { + return a + (b - a) * blend; + } + + #endregion Lerp + + #region InterpolateCubic + + /// + /// Cubic interpolates form to , where and are handles and returns the position at + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float InterpolateCubic(float preA, float a, float b, float postB, float t) + { + return a + 0.5f * t * (b - preA + t * (2.0f * preA - 5.0f * a + 4.0f * b - postB + t * (3.0f * (a - b) + postB - preA))); + } + + /// + /// Cubic interpolates form to , where and are handles and returns the position at + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double InterpolateCubic(double preA, double a, double b, double postB, double t) + { + return a + 0.5 * t * (b - preA + t * (2.0 * preA - 5.0 * a + 4.0 * b - postB + t * (3.0 * (a - b) + postB - preA))); + } + + #endregion InterpolateCubic + #endregion Public Members } } diff --git a/Robust.Shared.Maths/Matrix3.cs b/Robust.Shared.Maths/Matrix3.cs index ad7243c15..abfa11955 100644 --- a/Robust.Shared.Maths/Matrix3.cs +++ b/Robust.Shared.Maths/Matrix3.cs @@ -794,7 +794,7 @@ namespace Robust.Shared.Maths //Credit: https://stackoverflow.com/a/18504573 var d = Determinant; - if (FloatMath.CloseTo(d, 0)) + if (MathHelper.CloseTo(d, 0)) throw new InvalidOperationException("Matrix is singular and cannot be inverted."); var m = this; diff --git a/Robust.Shared.Maths/UIBox2.cs b/Robust.Shared.Maths/UIBox2.cs index bf817dbae..52543e7d4 100644 --- a/Robust.Shared.Maths/UIBox2.cs +++ b/Robust.Shared.Maths/UIBox2.cs @@ -68,7 +68,7 @@ namespace Robust.Shared.Maths public bool IsEmpty() { - return FloatMath.CloseTo(Width, 0.0f) && FloatMath.CloseTo(Height, 0.0f); + return MathHelper.CloseTo(Width, 0.0f) && MathHelper.CloseTo(Height, 0.0f); } public bool Encloses(UIBox2 inner) @@ -149,10 +149,10 @@ namespace Robust.Shared.Maths /// public static bool operator ==(UIBox2 a, UIBox2 b) { - return FloatMath.CloseTo(a.Bottom, b.Bottom) && - FloatMath.CloseTo(a.Right, b.Right) && - FloatMath.CloseTo(a.Top, b.Top) && - FloatMath.CloseTo(a.Left, b.Left); + return MathHelper.CloseTo(a.Bottom, b.Bottom) && + MathHelper.CloseTo(a.Right, b.Right) && + MathHelper.CloseTo(a.Top, b.Top) && + MathHelper.CloseTo(a.Left, b.Left); } public static bool operator !=(UIBox2 a, UIBox2 b) diff --git a/Robust.Shared.Maths/Vector2.cs b/Robust.Shared.Maths/Vector2.cs index dbf9d1016..73c53b9c7 100644 --- a/Robust.Shared.Maths/Vector2.cs +++ b/Robust.Shared.Maths/Vector2.cs @@ -234,8 +234,8 @@ namespace Robust.Shared.Maths public static Vector2 Clamp(Vector2 vector, Vector2 min, Vector2 max) { return new Vector2( - FloatMath.Clamp(vector.X, min.X, max.X), - FloatMath.Clamp(vector.Y, min.Y, max.Y) + MathHelper.Clamp(vector.X, min.X, max.X), + MathHelper.Clamp(vector.Y, min.Y, max.Y) ); } @@ -259,9 +259,9 @@ namespace Robust.Shared.Maths { return new Vector2( //factor * (b.X - a.X) + a.X, - FloatMath.Lerp(a.X, b.X, factor), + MathHelper.Lerp(a.X, b.X, factor), //factor * (b.Y - a.Y) + a.Y - FloatMath.Lerp(a.Y, b.Y, factor) + MathHelper.Lerp(a.Y, b.Y, factor) ); } @@ -357,13 +357,13 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool EqualsApprox(Vector2 other) { - return FloatMath.CloseTo(X, other.X) && FloatMath.CloseTo(Y, other.Y); + return MathHelper.CloseTo(X, other.X) && MathHelper.CloseTo(Y, other.Y); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool EqualsApprox(Vector2 other, double tolerance) { - return FloatMath.CloseTo(X, other.X, tolerance) && FloatMath.CloseTo(Y, other.Y, tolerance); + return MathHelper.CloseTo(X, other.X, tolerance) && MathHelper.CloseTo(Y, other.Y, tolerance); } } } diff --git a/Robust.Shared.Maths/Vector3.cs b/Robust.Shared.Maths/Vector3.cs index 82a4a1ca7..2a778b81f 100644 --- a/Robust.Shared.Maths/Vector3.cs +++ b/Robust.Shared.Maths/Vector3.cs @@ -500,9 +500,9 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 Clamp(Vector3 vec, Vector3 min, Vector3 max) { - vec.X = FloatMath.Clamp(vec.X, min.X, max.X); - vec.Y = FloatMath.Clamp(vec.Y, min.Y, max.Y); - vec.Z = FloatMath.Clamp(vec.Z, min.Z, max.Z); + vec.X = MathHelper.Clamp(vec.X, min.X, max.X); + vec.Y = MathHelper.Clamp(vec.Y, min.Y, max.Y); + vec.Z = MathHelper.Clamp(vec.Z, min.Z, max.Z); return vec; } @@ -516,9 +516,9 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(ref Vector3 vec, ref Vector3 min, ref Vector3 max, out Vector3 result) { - result.X = FloatMath.Clamp(vec.X, min.X, max.X); - result.Y = FloatMath.Clamp(vec.Y, min.Y, max.Y); - result.Z = FloatMath.Clamp(vec.Z, min.Z, max.Z); + result.X = MathHelper.Clamp(vec.X, min.X, max.X); + result.Y = MathHelper.Clamp(vec.Y, min.Y, max.Y); + result.Z = MathHelper.Clamp(vec.Z, min.Z, max.Z); } #endregion @@ -628,9 +628,9 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) { - a.X = FloatMath.Lerp(a.X, b.X, blend); - a.Y = FloatMath.Lerp(a.Y, b.Y, blend); - a.Z = FloatMath.Lerp(a.Z, b.Z, blend); + a.X = MathHelper.Lerp(a.X, b.X, blend); + a.Y = MathHelper.Lerp(a.Y, b.Y, blend); + a.Z = MathHelper.Lerp(a.Z, b.Z, blend); return a; } @@ -644,9 +644,9 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Lerp(ref Vector3 a, ref Vector3 b, float blend, out Vector3 result) { - result.X = FloatMath.Lerp(a.X, b.X, blend); - result.Y = FloatMath.Lerp(a.Y, b.Y, blend); - result.Z = FloatMath.Lerp(a.Z, b.Z, blend); + result.X = MathHelper.Lerp(a.X, b.X, blend); + result.Y = MathHelper.Lerp(a.Y, b.Y, blend); + result.Z = MathHelper.Lerp(a.Z, b.Z, blend); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared.Maths/Vector4.cs b/Robust.Shared.Maths/Vector4.cs index 07082003b..fd331e9df 100644 --- a/Robust.Shared.Maths/Vector4.cs +++ b/Robust.Shared.Maths/Vector4.cs @@ -507,10 +507,10 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Clamp(Vector4 vec, Vector4 min, Vector4 max) { - vec.X = FloatMath.Clamp( vec.X, min.X, max.X ); - vec.Y = FloatMath.Clamp( vec.Y, min.Y, max.Y ); - vec.Z = FloatMath.Clamp( vec.Z, min.Z, max.Z ); - vec.W = FloatMath.Clamp( vec.W, min.W, max.W ); + vec.X = MathHelper.Clamp( vec.X, min.X, max.X ); + vec.Y = MathHelper.Clamp( vec.Y, min.Y, max.Y ); + vec.Z = MathHelper.Clamp( vec.Z, min.Z, max.Z ); + vec.W = MathHelper.Clamp( vec.W, min.W, max.W ); return vec; } @@ -524,10 +524,10 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(ref Vector4 vec, ref Vector4 min, ref Vector4 max, out Vector4 result) { - result.X = FloatMath.Clamp( vec.X, min.X, max.X ); - result.Y = FloatMath.Clamp( vec.Y, min.Y, max.Y ); - result.Z = FloatMath.Clamp( vec.Z, min.Z, max.Z ); - result.W = FloatMath.Clamp( vec.W, min.W, max.W ); + result.X = MathHelper.Clamp( vec.X, min.X, max.X ); + result.Y = MathHelper.Clamp( vec.Y, min.Y, max.Y ); + result.Z = MathHelper.Clamp( vec.Z, min.Z, max.Z ); + result.W = MathHelper.Clamp( vec.W, min.W, max.W ); } #endregion Clamp @@ -623,10 +623,10 @@ namespace Robust.Shared.Maths [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Lerp(ref Vector4 a, ref Vector4 b, float blend, out Vector4 result) { - result.X = FloatMath.Lerp(a.X, b.X, blend); - result.Y = FloatMath.Lerp(a.Y, b.Y, blend); - result.Z = FloatMath.Lerp(a.Z, b.Z, blend); - result.W = FloatMath.Lerp(a.W, b.W, blend); + result.X = MathHelper.Lerp(a.X, b.X, blend); + result.Y = MathHelper.Lerp(a.Y, b.Y, blend); + result.Z = MathHelper.Lerp(a.Z, b.Z, blend); + result.W = MathHelper.Lerp(a.W, b.W, blend); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 83b3187fe..ef98690cb 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -153,8 +153,8 @@ namespace Robust.Shared.GameObjects foreach (var entity in _entityTreesPerMap[mapId].Query(position, approximate)) { var transform = entity.Transform; - if (FloatMath.CloseTo(transform.GridPosition.X, position.X) && - FloatMath.CloseTo(transform.GridPosition.Y, position.Y)) + if (MathHelper.CloseTo(transform.GridPosition.X, position.X) && + MathHelper.CloseTo(transform.GridPosition.Y, position.Y)) { yield return entity; } @@ -416,8 +416,8 @@ namespace Robust.Shared.GameObjects { var transform = entity.Transform; var entPos = transform.WorldPosition; - if (FloatMath.CloseTo(entPos.X, position.X) - && FloatMath.CloseTo(entPos.Y, position.Y)) + if (MathHelper.CloseTo(entPos.X, position.X) + && MathHelper.CloseTo(entPos.Y, position.Y)) { yield return entity; } diff --git a/Robust.Shared/GameObjects/Systems/SharedPhysicsSystem.cs b/Robust.Shared/GameObjects/Systems/SharedPhysicsSystem.cs index 3f84d933a..0a2404768 100644 --- a/Robust.Shared/GameObjects/Systems/SharedPhysicsSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedPhysicsSystem.cs @@ -106,7 +106,7 @@ namespace Robust.Shared.GameObjects.Systems var multiplier = deltaTime / (1f / 60); - var divisions = FloatMath.Clamp( + var divisions = MathHelper.Clamp( MathF.Round(solveIterationsAt60 * multiplier, MidpointRounding.AwayFromZero), 1, 20 @@ -310,7 +310,7 @@ namespace Robust.Shared.GameObjects.Systems private bool FixClipping(List collisions, float divisions) { const float allowance = 1 / 128f; - var percent = FloatMath.Clamp(1f / divisions, 0.01f, 1f); + var percent = MathHelper.Clamp(1f / divisions, 0.01f, 1f); var done = true; foreach (var collision in collisions) { diff --git a/Robust.Shared/Map/MapGrid.cs b/Robust.Shared/Map/MapGrid.cs index 404da2282..bb96a977b 100644 --- a/Robust.Shared/Map/MapGrid.cs +++ b/Robust.Shared/Map/MapGrid.cs @@ -168,13 +168,13 @@ namespace Robust.Shared.Map /// public bool OnSnapCenter(Vector2 position) { - return (FloatMath.CloseTo(position.X % SnapSize, 0) && FloatMath.CloseTo(position.Y % SnapSize, 0)); + return (MathHelper.CloseTo(position.X % SnapSize, 0) && MathHelper.CloseTo(position.Y % SnapSize, 0)); } /// public bool OnSnapBorder(Vector2 position) { - return (FloatMath.CloseTo(position.X % SnapSize, SnapSize / 2) && FloatMath.CloseTo(position.Y % SnapSize, SnapSize / 2)); + return (MathHelper.CloseTo(position.X % SnapSize, SnapSize / 2) && MathHelper.CloseTo(position.Y % SnapSize, SnapSize / 2)); } #region TileAccess diff --git a/Robust.Shared/Physics/CollisionSolver.cs b/Robust.Shared/Physics/CollisionSolver.cs index b69140880..1833cdc0b 100644 --- a/Robust.Shared/Physics/CollisionSolver.cs +++ b/Robust.Shared/Physics/CollisionSolver.cs @@ -437,8 +437,8 @@ namespace Robust.Shared.Physics public Vector2 ClosestPoint(in Vector2 position) { // clamp the point to the border of the box - var cx = FloatMath.Clamp(position.X, Left, Right); - var cy = FloatMath.Clamp(position.Y, Bottom, Top); + var cx = MathHelper.Clamp(position.X, Left, Right); + var cy = MathHelper.Clamp(position.Y, Bottom, Top); return new Vector2(cx, cy); } @@ -611,8 +611,8 @@ namespace Robust.Shared.Physics var yMax = HalfExtents.Y; // clamp the point to the border of the box - var cx = FloatMath.Clamp(localPoint.X, xMin, xMax); - var cy = FloatMath.Clamp(localPoint.Y, yMin, yMax); + var cx = MathHelper.Clamp(localPoint.X, xMin, xMax); + var cy = MathHelper.Clamp(localPoint.Y, yMin, yMax); return TransformPoint(new Vector2(cx, cy)); } diff --git a/Robust.Shared/Physics/Ray.cs b/Robust.Shared/Physics/Ray.cs index 6cb4d99e0..b9a46a1c6 100644 --- a/Robust.Shared/Physics/Ray.cs +++ b/Robust.Shared/Physics/Ray.cs @@ -33,7 +33,7 @@ namespace Robust.Shared.Maths _position = position; _direction = direction; - DebugTools.Assert(FloatMath.CloseTo(_direction.LengthSquared, 1)); + DebugTools.Assert(MathHelper.CloseTo(_direction.LengthSquared, 1)); } diff --git a/Robust.Shared/Timing/GameLoop.cs b/Robust.Shared/Timing/GameLoop.cs index 5f05c154c..4d71c9aff 100644 --- a/Robust.Shared/Timing/GameLoop.cs +++ b/Robust.Shared/Timing/GameLoop.cs @@ -273,7 +273,7 @@ namespace Robust.Shared.Timing private TimeSpan CalcTickPeriod() { // ranges from -1 to 1, with 0 being 'default' - var ratio = FloatMath.Clamp(_timing.TickTimingAdjustment, -0.99f, 0.99f); + var ratio = MathHelper.Clamp(_timing.TickTimingAdjustment, -0.99f, 0.99f); var diff = TimeSpan.FromTicks((long) (_timing.TickPeriod.Ticks * ratio)); return _timing.TickPeriod - diff; } diff --git a/Robust.UnitTesting/ApproxEqualityConstraint.cs b/Robust.UnitTesting/ApproxEqualityConstraint.cs index 6a8156ab9..9935f102f 100644 --- a/Robust.UnitTesting/ApproxEqualityConstraint.cs +++ b/Robust.UnitTesting/ApproxEqualityConstraint.cs @@ -22,20 +22,20 @@ namespace Robust.UnitTesting { if (Tolerance != null) { - return new ConstraintResult(this, actual, FloatMath.CloseTo(f1, f2, Tolerance.Value)); + return new ConstraintResult(this, actual, MathHelper.CloseTo(f1, f2, Tolerance.Value)); } - return new ConstraintResult(this, actual, FloatMath.CloseTo(f1, f2)); + return new ConstraintResult(this, actual, MathHelper.CloseTo(f1, f2)); } if (Expected is double d1 && actual is float d2) { if (Tolerance != null) { - return new ConstraintResult(this, actual, FloatMath.CloseTo(d1, d2, Tolerance.Value)); + return new ConstraintResult(this, actual, MathHelper.CloseTo(d1, d2, Tolerance.Value)); } - return new ConstraintResult(this, actual, FloatMath.CloseTo(d1, d2)); + return new ConstraintResult(this, actual, MathHelper.CloseTo(d1, d2)); } return new ConstraintResult(this, actual, false); diff --git a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs index 5eb977070..2edcf0778 100644 --- a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs @@ -171,8 +171,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var result = childTrans.WorldPosition; Assert.Multiple(() => { - Assert.That(FloatMath.CloseTo(result.X, 0)); - Assert.That(FloatMath.CloseTo(result.Y, 2)); + Assert.That(MathHelper.CloseTo(result.X, 0)); + Assert.That(MathHelper.CloseTo(result.Y, 2)); }); } @@ -198,8 +198,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var result = childTrans.WorldPosition; Assert.Multiple(() => { - Assert.That(FloatMath.CloseTo(result.X, 1)); - Assert.That(FloatMath.CloseTo(result.Y, 2)); + Assert.That(MathHelper.CloseTo(result.X, 1)); + Assert.That(MathHelper.CloseTo(result.Y, 2)); }); } @@ -280,8 +280,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components // Assert Assert.Multiple(() => { - Assert.That(FloatMath.CloseTo(oldWpos.X, newWpos.Y), newWpos.ToString); - Assert.That(FloatMath.CloseTo(oldWpos.Y, newWpos.Y), newWpos.ToString); + Assert.That(MathHelper.CloseTo(oldWpos.X, newWpos.Y), newWpos.ToString); + Assert.That(MathHelper.CloseTo(oldWpos.Y, newWpos.Y), newWpos.ToString); }); } @@ -327,8 +327,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components Assert.Multiple(() => { - Assert.That(FloatMath.CloseTo(oldWpos.X, newWpos.Y)); - Assert.That(FloatMath.CloseTo(oldWpos.Y, newWpos.Y)); + Assert.That(MathHelper.CloseTo(oldWpos.X, newWpos.Y)); + Assert.That(MathHelper.CloseTo(oldWpos.Y, newWpos.Y)); }); } diff --git a/Robust.UnitTesting/Shared/Maths/Matrix3_Test.cs b/Robust.UnitTesting/Shared/Maths/Matrix3_Test.cs index ff8c5f831..b4522e998 100644 --- a/Robust.UnitTesting/Shared/Maths/Matrix3_Test.cs +++ b/Robust.UnitTesting/Shared/Maths/Matrix3_Test.cs @@ -48,8 +48,8 @@ namespace Robust.UnitTesting.Shared.Maths var control = testCase.Item1; var result = test.Xy; - Assert.That(FloatMath.CloseTo(control.X, result.X), Is.True, result.ToString); - Assert.That(FloatMath.CloseTo(control.Y, result.Y), Is.True, result.ToString); + Assert.That(MathHelper.CloseTo(control.X, result.X), Is.True, result.ToString); + Assert.That(MathHelper.CloseTo(control.Y, result.Y), Is.True, result.ToString); } [Test] @@ -114,8 +114,8 @@ namespace Robust.UnitTesting.Shared.Maths var result = test.Xy; // Assert - Assert.That(FloatMath.CloseTo(result.X, 2), result.ToString); - Assert.That(FloatMath.CloseTo(result.Y, 2), result.ToString); + Assert.That(MathHelper.CloseTo(result.X, 2), result.ToString); + Assert.That(MathHelper.CloseTo(result.Y, 2), result.ToString); } [Test] @@ -137,8 +137,8 @@ namespace Robust.UnitTesting.Shared.Maths Matrix3.Transform(in invMatrix, in localPoint, out var result); // Assert - Assert.That(FloatMath.CloseTo(startPoint.X, result.X), Is.True, result.ToString); - Assert.That(FloatMath.CloseTo(startPoint.Y, result.Y), Is.True, result.ToString); + Assert.That(MathHelper.CloseTo(startPoint.X, result.X), Is.True, result.ToString); + Assert.That(MathHelper.CloseTo(startPoint.Y, result.Y), Is.True, result.ToString); } } }