From 0cee32837a428f282f5589a11d5b095aceff19f1 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Tue, 16 Jun 2020 23:14:26 +0200 Subject: [PATCH 1/4] Use MathUtilities in NearlyEquals. --- src/Avalonia.Visuals/Vector.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 2b5d79173b..1bd1a01b01 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -154,9 +154,7 @@ namespace Avalonia /// True if vectors are nearly equal. public bool NearlyEquals(Vector other) { - const float tolerance = float.Epsilon; - - return Math.Abs(_x - other._x) < tolerance && Math.Abs(_y - other._y) < tolerance; + return MathUtilities.AreClose(_x, other._x) && MathUtilities.AreClose(_y, other._y); } public override bool Equals(object obj) => obj is Vector other && Equals(other); From 35f5da4577e789a93107e75adc4970df2ec565dc Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Tue, 16 Jun 2020 23:14:45 +0200 Subject: [PATCH 2/4] Fix a few typos. --- src/Avalonia.Visuals/Vector.cs | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 1bd1a01b01..52bfd3ae0c 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -2,7 +2,8 @@ using System; using System.Globalization; using Avalonia.Animation.Animators; using Avalonia.Utilities; -using JetBrains.Annotations; + +#nullable enable namespace Avalonia { @@ -17,20 +18,20 @@ namespace Avalonia } /// - /// The X vector. + /// The X component. /// private readonly double _x; /// - /// The Y vector. + /// The Y component. /// private readonly double _y; /// /// Initializes a new instance of the structure. /// - /// The X vector. - /// The Y vector. + /// The X component. + /// The Y component. public Vector(double x, double y) { _x = x; @@ -38,12 +39,12 @@ namespace Avalonia } /// - /// Gets the X vector. + /// Gets the X component. /// public double X => _x; /// - /// Gets the Y vector. + /// Gets the Y component. /// public double Y => _y; @@ -57,18 +58,18 @@ namespace Avalonia } /// - /// Calculates the dot product of two vectors + /// Calculates the dot product of two vectors. /// - /// First vector - /// Second vector - /// The dot product + /// First vector. + /// Second vector. + /// The dot product. public static double operator *(Vector a, Vector b) => Dot(a, b); /// /// Scales a vector. /// - /// The vector + /// The vector. /// The scaling factor. /// The scaled vector. public static Vector operator *(Vector vector, double scale) @@ -77,7 +78,7 @@ namespace Avalonia /// /// Scales a vector. /// - /// The vector + /// The vector. /// The divisor. /// The scaled vector. public static Vector operator /(Vector vector, double scale) @@ -100,12 +101,12 @@ namespace Avalonia } /// - /// Length of the vector + /// Length of the vector. /// public double Length => Math.Sqrt(SquaredLength); /// - /// Squared Length of the vector + /// Squared Length of the vector. /// public double SquaredLength => _x * _x + _y * _y; @@ -187,9 +188,9 @@ namespace Avalonia } /// - /// Returns a new vector with the specified X coordinate. + /// Returns a new vector with the specified X component. /// - /// The X coordinate. + /// The X component. /// The new vector. public Vector WithX(double x) { @@ -197,9 +198,9 @@ namespace Avalonia } /// - /// Returns a new vector with the specified Y coordinate. + /// Returns a new vector with the specified Y component. /// - /// The Y coordinate. + /// The Y component. /// The new vector. public Vector WithY(double y) { @@ -309,25 +310,25 @@ namespace Avalonia => new Vector(-vector._x, -vector._y); /// - /// Returnes the vector (0.0, 0.0) + /// Returns the vector (0.0, 0.0). /// public static Vector Zero => new Vector(0, 0); /// - /// Returnes the vector (1.0, 1.0) + /// Returns the vector (1.0, 1.0). /// public static Vector One => new Vector(1, 1); /// - /// Returnes the vector (1.0, 0.0) + /// Returns the vector (1.0, 0.0). /// public static Vector UnitX => new Vector(1, 0); /// - /// Returnes the vector (0.0, 1.0) + /// Returns the vector (0.0, 1.0). /// public static Vector UnitY => new Vector(0, 1); From 55d9def9bc2e9ae3644b62ba3131cc783e4f1fde Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Tue, 16 Jun 2020 23:21:49 +0200 Subject: [PATCH 3/4] Add NearlyEquals for Size. --- src/Avalonia.Visuals/Size.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Size.cs b/src/Avalonia.Visuals/Size.cs index 0383094a5b..860270b346 100644 --- a/src/Avalonia.Visuals/Size.cs +++ b/src/Avalonia.Visuals/Size.cs @@ -189,7 +189,7 @@ namespace Avalonia } /// - /// Returns a boolean indicating whether the size is equal to the other given size. + /// Returns a boolean indicating whether the size is equal to the other given size (bitwise). /// /// The other size to test equality against. /// True if this size is equal to other; False otherwise. @@ -201,6 +201,16 @@ namespace Avalonia // ReSharper enable CompareOfFloatsByEqualityOperator } + /// + /// Returns a boolean indicating whether the size is equal to the other given size (numerically). + /// + /// The other size to test equality against. + /// True if this size is equal to other; False otherwise. + public bool NearlyEquals(Size other) + { + return MathUtilities.AreClose(_width, other._width) && MathUtilities.AreClose(_height, other._height); + } + /// /// Checks for equality between a size and an object. /// From 914e789114bf707ec4636d7f7800df6b82b74718 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Wed, 17 Jun 2020 10:38:10 +0200 Subject: [PATCH 4/4] Review fixes. --- src/Avalonia.Visuals/Size.cs | 3 ++- src/Avalonia.Visuals/Vector.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Visuals/Size.cs b/src/Avalonia.Visuals/Size.cs index 860270b346..f87b336b50 100644 --- a/src/Avalonia.Visuals/Size.cs +++ b/src/Avalonia.Visuals/Size.cs @@ -208,7 +208,8 @@ namespace Avalonia /// True if this size is equal to other; False otherwise. public bool NearlyEquals(Size other) { - return MathUtilities.AreClose(_width, other._width) && MathUtilities.AreClose(_height, other._height); + return MathUtilities.AreClose(_width, other._width) && + MathUtilities.AreClose(_height, other._height); } /// diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 52bfd3ae0c..6059dc3971 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -155,7 +155,8 @@ namespace Avalonia /// True if vectors are nearly equal. public bool NearlyEquals(Vector other) { - return MathUtilities.AreClose(_x, other._x) && MathUtilities.AreClose(_y, other._y); + return MathUtilities.AreClose(_x, other._x) && + MathUtilities.AreClose(_y, other._y); } public override bool Equals(object obj) => obj is Vector other && Equals(other);