// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System.Diagnostics; namespace RGB.NET.Core { /// /// Represents a point consisting of a X- and a Y-position. /// [DebuggerDisplay("[X: {X}, Y: {Y}]")] public class Point : AbstractBindable { #region Properties & Fields private double _x; /// /// Gets or sets the X-position of this . /// public double X { get => _x; set => SetProperty(ref _x, value); } private double _y; /// /// Gets or sets the Y-position of this . /// public double Y { get => _y; set => SetProperty(ref _y, value); } #endregion #region Constructors /// /// Initializes a new instance of the class. /// public Point() { } /// /// Initializes a new instance of the class using the provided values. /// /// The value used for the X-position. /// The value used for the Y-position. public Point(double x, double y) { this.X = x; this.Y = y; } #endregion #region Methods /// /// Converts the - and -position of this to a human-readable string. /// /// A string that contains the and of this . For example "[X: 100, Y: 20]". public override string ToString() { return $"[X: {X}, Y: {Y}]"; } /// /// Tests whether the specified object is a and is equivalent to this . /// /// The object to test. /// true if is a equivalent to this ; otherwise, false. public override bool Equals(object obj) { Point comparePoint = obj as Point; if (ReferenceEquals(comparePoint, null)) return false; if (ReferenceEquals(this, comparePoint)) return true; if (GetType() != comparePoint.GetType()) return false; return X.EqualsInTolerance(comparePoint.X) && Y.EqualsInTolerance(comparePoint.Y); } /// /// Returns a hash code for this . /// /// An integer value that specifies the hash code for this . public override int GetHashCode() { unchecked { int hashCode = X.GetHashCode(); hashCode = (hashCode * 397) ^ Y.GetHashCode(); return hashCode; } } #endregion #region Operators /// /// Returns a value that indicates whether two specified are equal. /// /// The first to compare. /// The second to compare. /// true if and are equal; otherwise, false. public static bool operator ==(Point point1, Point point2) { return ReferenceEquals(point1, null) ? ReferenceEquals(point2, null) : point1.Equals(point2); } /// /// Returns a value that indicates whether two specified are equal. /// /// The first to compare. /// The second to compare. /// true if and are not equal; otherwise, false. public static bool operator !=(Point point1, Point point2) { return !(point1 == point2); } /// /// Returns a new representing the addition of the two provided . /// /// The first . /// The second . /// A new representing the addition of the two provided . public static Point operator +(Point point1, Point point2) { return new Point(point1.X + point2.X, point1.Y + point2.Y); } /// /// Returns a new representing the substraction of the two provided . /// /// The first . /// The second . /// A new representing the substraction of the two provided . public static Point operator -(Point point1, Point point2) { return new Point(point1.X - point2.X, point1.Y - point2.Y); } /// /// Returns a new representing the multiplication of the two provided . /// /// The first . /// The second . /// A new representing the multiplication of the two provided . public static Point operator *(Point point1, Point point2) { return new Point(point1.X * point2.X, point1.Y * point2.Y); } /// /// Returns a new representing the division of the two provided . /// /// The first . /// The second . /// A new representing the division of the two provided . public static Point operator /(Point point1, Point point2) { if (point2.X.EqualsInTolerance(0) || point2.Y.EqualsInTolerance(0)) return new Point(); return new Point(point1.X / point2.X, point1.Y / point2.Y); } #endregion } }