diff --git a/src/Avalonia.Base/Point.cs b/src/Avalonia.Base/Point.cs index 331cce4a76..e3ea21d1eb 100644 --- a/src/Avalonia.Base/Point.cs +++ b/src/Avalonia.Base/Point.cs @@ -164,6 +164,19 @@ namespace Avalonia /// The resulting point. public static Point operator *(Point point, Matrix matrix) => matrix.Transform(point); + /// + /// Computes the Euclidean distance between the two given points. + /// + /// The first point. + /// The second point. + /// The Euclidean distance. + public static double Distance(Point value1, Point value2) + { + double distanceSquared = ((value2.X - value1.X) * (value2.X - value1.X)) + + ((value2.Y - value1.Y) * (value2.Y - value1.Y)); + return Math.Sqrt(distanceSquared); + } + /// /// Parses a string. /// diff --git a/src/Avalonia.Base/Vector.cs b/src/Avalonia.Base/Vector.cs index 15722901a6..fffe206835 100644 --- a/src/Avalonia.Base/Vector.cs +++ b/src/Avalonia.Base/Vector.cs @@ -359,7 +359,7 @@ namespace Avalonia internal Vector(Vector2 v) : this(v.X, v.Y) { - + } /// @@ -379,21 +379,27 @@ namespace Avalonia /// public static Vector Max(Vector left, Vector right) => new(Math.Max(left.X, right.X), Math.Max(left.Y, right.Y)); - + /// /// Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors /// public static Vector Min(Vector left, Vector right) => new(Math.Min(left.X, right.X), Math.Min(left.Y, right.Y)); - + /// /// Computes the Euclidean distance between the two given points. /// + /// The first point. + /// The second point. + /// The Euclidean distance. public static double Distance(Vector value1, Vector value2) => Math.Sqrt(DistanceSquared(value1, value2)); - + /// /// Returns the Euclidean distance squared between two specified points /// + /// The first point. + /// The second point. + /// The Euclidean distance squared. public static double DistanceSquared(Vector value1, Vector value2) { var difference = value1 - value2;