using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace Microsoft.Research.DynamicDataDisplay { /// /// Represents simple rectangle with corner coordinates of specified types. /// /// The horizontal values type. /// The vertical values type. public struct GenericRect : IEquatable> { [DebuggerBrowsable(DebuggerBrowsableState.Never)] private THorizontal xMin; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private TVertical yMin; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private THorizontal xMax; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private TVertical yMax; /// /// Initializes a new instance of the struct. /// /// The minimal x value. /// The minimal y value. /// The maximal x value. /// The maximal y value. public GenericRect(THorizontal xMin, TVertical yMin, THorizontal xMax, TVertical yMax) { this.xMin = xMin; this.xMax = xMax; this.yMin = yMin; this.yMax = yMax; } /// /// Gets the minimal X value. /// /// The X min. public THorizontal XMin { get { return xMin; } } /// /// Gets the minimal Y value. /// /// The Y min. public TVertical YMin { get { return yMin; } } /// /// Gets the maximal X value. /// /// The X max. public THorizontal XMax { get { return xMax; } } /// /// Gets the maximal Y value. /// /// The Y max. public TVertical YMax { get { return yMax; } } #region Object overrides /// /// Indicates whether this instance and a specified object are equal. /// /// Another object to compare to. /// /// true if and this instance are the same type and represent the same value; otherwise, false. /// public override bool Equals(object obj) { if (obj == null) return false; if (!(obj is GenericRect)) return false; GenericRect other = (GenericRect)obj; return Equals(other); } /// /// Returns the hash code for this instance. /// /// /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { return xMin.GetHashCode() ^ xMax.GetHashCode() ^ yMin.GetHashCode() ^ yMax.GetHashCode(); } /// /// Returns the fully qualified type name of this instance. /// /// /// A containing a fully qualified type name. /// public override string ToString() { return String.Format("({0},{1}) - ({2},{3})", xMin, yMin, xMax, yMax); } #endregion #region IEquatable> Members /// /// Indicates whether the current object is equal to another object of the same type. /// /// An object to compare with this object. /// /// true if the current object is equal to the parameter; otherwise, false. /// public bool Equals(GenericRect other) { return this.xMin.Equals(other.xMin) && this.xMax.Equals(other.xMax) && this.yMin.Equals(other.yMin) && this.yMax.Equals(other.yMax); } #endregion /// /// Implements the operator ==. /// /// The rect1. /// The rect2. /// The result of the operator. public static bool operator ==(GenericRect rect1, GenericRect rect2) { return rect1.Equals(rect2); } /// /// Implements the operator !=. /// /// The rect1. /// The rect2. /// The result of the operator. public static bool operator !=(GenericRect rect1, GenericRect rect2) { return !rect1.Equals(rect2); } } }