diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 1de91d7..c47b6d0 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -321,7 +321,7 @@ namespace MLEM.Ui.Elements { var lowest = this.GetLowestChild(e => !e.IsHidden); if (lowest != null) { var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom) / this.Scale; - if ((int) newHeight != (int) this.size.Y) { + if (!newHeight.Equals(this.size.Y, 0.01F)) { this.size.Y = newHeight; changed = true; } @@ -331,7 +331,7 @@ namespace MLEM.Ui.Elements { var rightmost = this.GetRightmostChild(e => !e.IsHidden); if (rightmost != null) { var newWidth = (rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right) / this.Scale; - if ((int) newWidth != (int) this.size.X) { + if (!newWidth.Equals(this.size.X, 0.01F)) { this.size.X = newWidth; changed = true; } diff --git a/MLEM/Extensions/NumberExtensions.cs b/MLEM/Extensions/NumberExtensions.cs index 4fdf5a7..447304c 100644 --- a/MLEM/Extensions/NumberExtensions.cs +++ b/MLEM/Extensions/NumberExtensions.cs @@ -13,6 +13,22 @@ namespace MLEM.Extensions { return (int) Math.Ceiling(f); } + public static bool Equals(this float first, float second, float tolerance) { + return Math.Abs(first- second) <= tolerance; + } + + public static bool Equals(this Vector2 first, Vector2 second, float tolerance) { + return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance; + } + + public static bool Equals(this Vector3 first, Vector3 second, float tolerance) { + return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance && Math.Abs(first.Z - second.Z) <= tolerance; + } + + public static bool Equals(this Vector4 first, Vector4 second, float tolerance) { + return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance && Math.Abs(first.Z - second.Z) <= tolerance && Math.Abs(first.W - second.W) <= tolerance; + } + public static Vector2 Floor(this Vector2 vec) { return new Vector2(vec.X.Floor(), vec.Y.Floor()); }