Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/GenericRect.cs @ 13037

Last change on this file since 13037 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 4.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Diagnostics;
6
7namespace Microsoft.Research.DynamicDataDisplay
8{
9  /// <summary>
10  /// Represents simple rectangle with corner coordinates of specified types.
11  /// </summary>
12  /// <typeparam name="THorizontal">The horizontal values type.</typeparam>
13  /// <typeparam name="TVertical">The vertical values type.</typeparam>
14  public struct GenericRect<THorizontal, TVertical> : IEquatable<GenericRect<THorizontal, TVertical>>
15  {
16    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
17    private THorizontal xMin;
18    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
19    private TVertical yMin;
20
21    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
22    private THorizontal xMax;
23    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
24    private TVertical yMax;
25
26    /// <summary>
27    /// Initializes a new instance of the <see cref="GenericRect&lt;THorizontal, TVertical&gt;"/> struct.
28    /// </summary>
29    /// <param name="xMin">The minimal x value.</param>
30    /// <param name="yMin">The minimal y value.</param>
31    /// <param name="xMax">The maximal x value.</param>
32    /// <param name="yMax">The maximal y value.</param>
33    public GenericRect(THorizontal xMin, TVertical yMin, THorizontal xMax, TVertical yMax)
34    {
35      this.xMin = xMin;
36      this.xMax = xMax;
37      this.yMin = yMin;
38      this.yMax = yMax;
39    }
40
41    /// <summary>
42    /// Gets the minimal X value.
43    /// </summary>
44    /// <value>The X min.</value>
45    public THorizontal XMin { get { return xMin; } }
46    /// <summary>
47    /// Gets the minimal Y value.
48    /// </summary>
49    /// <value>The Y min.</value>
50    public TVertical YMin { get { return yMin; } }
51    /// <summary>
52    /// Gets the maximal X value.
53    /// </summary>
54    /// <value>The X max.</value>
55    public THorizontal XMax { get { return xMax; } }
56    /// <summary>
57    /// Gets the maximal Y value.
58    /// </summary>
59    /// <value>The Y max.</value>
60    public TVertical YMax { get { return yMax; } }
61
62    #region Object overrides
63
64    /// <summary>
65    /// Indicates whether this instance and a specified object are equal.
66    /// </summary>
67    /// <param name="obj">Another object to compare to.</param>
68    /// <returns>
69    /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
70    /// </returns>
71    public override bool Equals(object obj)
72    {
73      if (obj == null) return false;
74
75      if (!(obj is GenericRect<THorizontal, TVertical>))
76        return false;
77
78      GenericRect<THorizontal, TVertical> other = (GenericRect<THorizontal, TVertical>)obj;
79
80      return Equals(other);
81    }
82
83    /// <summary>
84    /// Returns the hash code for this instance.
85    /// </summary>
86    /// <returns>
87    /// A 32-bit signed integer that is the hash code for this instance.
88    /// </returns>
89    public override int GetHashCode()
90    {
91      return
92        xMin.GetHashCode() ^
93        xMax.GetHashCode() ^
94        yMin.GetHashCode() ^
95        yMax.GetHashCode();
96    }
97
98    /// <summary>
99    /// Returns the fully qualified type name of this instance.
100    /// </summary>
101    /// <returns>
102    /// A <see cref="T:System.String"/> containing a fully qualified type name.
103    /// </returns>
104    public override string ToString()
105    {
106      return String.Format("({0},{1}) - ({2},{3})", xMin, yMin, xMax, yMax);
107    }
108
109    #endregion
110
111    #region IEquatable<GenericRect<THorizontal,TVertical>> Members
112
113    /// <summary>
114    /// Indicates whether the current object is equal to another object of the same type.
115    /// </summary>
116    /// <param name="other">An object to compare with this object.</param>
117    /// <returns>
118    /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
119    /// </returns>
120    public bool Equals(GenericRect<THorizontal, TVertical> other)
121    {
122      return
123        this.xMin.Equals(other.xMin) &&
124        this.xMax.Equals(other.xMax) &&
125        this.yMin.Equals(other.yMin) &&
126        this.yMax.Equals(other.yMax);
127    }
128
129    #endregion
130
131    /// <summary>
132    /// Implements the operator ==.
133    /// </summary>
134    /// <param name="rect1">The rect1.</param>
135    /// <param name="rect2">The rect2.</param>
136    /// <returns>The result of the operator.</returns>
137    public static bool operator ==(GenericRect<THorizontal, TVertical> rect1, GenericRect<THorizontal, TVertical> rect2)
138    {
139      return rect1.Equals(rect2);
140    }
141
142    /// <summary>
143    /// Implements the operator !=.
144    /// </summary>
145    /// <param name="rect1">The rect1.</param>
146    /// <param name="rect2">The rect2.</param>
147    /// <returns>The result of the operator.</returns>
148    public static bool operator !=(GenericRect<THorizontal, TVertical> rect1, GenericRect<THorizontal, TVertical> rect2)
149    {
150      return !rect1.Equals(rect2);
151    }
152  }
153}
Note: See TracBrowser for help on using the repository browser.