diff --git a/src/Avalonia.Visuals/Size.cs b/src/Avalonia.Visuals/Size.cs
index 0383094a5b..f87b336b50 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,17 @@ 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.
///
diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs
index 2b5d79173b..6059dc3971 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;
@@ -154,9 +155,8 @@ 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);
@@ -189,9 +189,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)
{
@@ -199,9 +199,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)
{
@@ -311,25 +311,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);