Browse Source

Deconstructors

pull/4589/head
GMIKE 6 years ago
parent
commit
6650407c25
  1. 87
      src/Avalonia.Visuals/Point.cs
  2. 11
      src/Avalonia.Visuals/Size.cs
  3. 16
      src/Avalonia.Visuals/Thickness.cs
  4. 11
      src/Avalonia.Visuals/Vector.cs

87
src/Avalonia.Visuals/Point.cs

@ -109,28 +109,6 @@ namespace Avalonia
return new Point(a._x + b.X, a._y + b.Y);
}
/// <summary>
/// Add a 2-tuple of double
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">2-tuple of double</param>
/// <returns>A point that is the result of the addition.</returns>
public static Point operator +(Point a, (double x, double y) b)
{
return new Point(a._x + b.x, a._y + b.y);
}
/// <summary>
/// Add a double number to both coordinates
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">double number</param>
/// <returns>A point that is the result of the addition.</returns>
public static Point operator +(Point a, double b)
{
return new Point(a._x + b, a._y + b);
}
/// <summary>
/// Subtracts two points.
/// </summary>
@ -153,28 +131,6 @@ namespace Avalonia
return new Point(a._x - b.X, a._y - b.Y);
}
/// <summary>
/// Subtracts a 2-tuple of double
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">2-tuple of double</param>
/// <returns>A point that is the result of the subtraction.</returns>
public static Point operator -(Point a, (double x, double y) b)
{
return new Point(a._x - b.x, a._y - b.y);
}
/// <summary>
/// Subtracts a double number to both coordinates
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">double number</param>
/// <returns>A point that is the result of the subtraction.</returns>
public static Point operator -(Point a, double b)
{
return new Point(a._x - b, a._y - b);
}
/// <summary>
/// Multiplies a point by a factor coordinate-wise
/// </summary>
@ -191,17 +147,6 @@ namespace Avalonia
/// <returns>Points having its coordinates multiplied</returns>
public static Point operator *(double k, Point p) => new Point(p.X * k, p.Y * k);
/// <summary>
/// Multiplies a 2-tuple of double
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">2-tuple of double</param>
/// <returns>Points having its coordinates multiplied.</returns>
public static Point operator *(Point a, (double x, double y) b)
{
return new Point(a._x * b.x, a._y * b.y);
}
/// <summary>
/// Divides a point by a factor coordinate-wise
/// </summary>
@ -210,17 +155,6 @@ namespace Avalonia
/// <returns>Points having its coordinates divided</returns>
public static Point operator /(Point p, double k) => new Point(p.X / k, p.Y / k);
/// <summary>
/// Divides a point by a 2-tuple of doubles
/// </summary>
/// <param name="a">The point.</param>
/// <param name="b">2-tuple of double</param>
/// <returns>Points having its coordinates divided</returns>
public static Point operator /(Point a, (double x, double y) b)
{
return new Point(a._x / b.x, a._y / b.y);
}
/// <summary>
/// Applies a matrix to a point.
/// </summary>
@ -344,26 +278,5 @@ namespace Avalonia
x = this._x;
y = this._y;
}
/// <summary>
/// Returns a boolean indicating whether the point coordinates are equal to 2-tuple of double
/// </summary>
/// <param name="other">2-tuple of double</param>
/// <returns>
/// True if <paramref name="other"/> is 2-tuple of double equals coordinates current point.
/// </returns>
public bool Equals((double x, double y) other)
{
return _x == other.x &&
_y == other.y;
}
/// <summary>
/// Gets a value indicating that point coordinates are zero
/// </summary>
public bool IsDefault
{
get { return (_x == 0) && (_y == 0); }
}
}
}

11
src/Avalonia.Visuals/Size.cs

@ -276,5 +276,16 @@ namespace Avalonia
{
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", _width, _height);
}
/// <summary>
/// Deconstructor for decomposition Size
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
public void Deconstruct(out double width, out double height)
{
width = this._width;
height = this._height;
}
}
}

16
src/Avalonia.Visuals/Thickness.cs

@ -272,5 +272,21 @@ namespace Avalonia
{
return $"{_left},{_top},{_right},{_bottom}";
}
/// <summary>
/// Deconstructor for decomposition Thickness
/// </summary>
/// <param name="left">The thickness on the left.</param>
/// <param name="top">The thickness on the top.</param>
/// <param name="right">The thickness on the right.</param>
/// <param name="bottom">The thickness on the bottom.</param>
public void Deconstruct(out double left, out double top, out double right, out double bottom)
{
left = this._left;
top = this._top;
right = this._right;
bottom = this._bottom;
}
}
}

11
src/Avalonia.Visuals/Vector.cs

@ -333,5 +333,16 @@ namespace Avalonia
/// </summary>
public static Vector UnitY
=> new Vector(0, 1);
/// <summary>
/// Deconstructor for decomposition Vector
/// </summary>
/// <param name="x">The X component.</param>
/// <param name="y">The Y poscomponentition.</param>
public void Deconstruct(out double x, out double y)
{
x = this._x;
y = this._y;
}
}
}

Loading…
Cancel
Save