2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
23 /// The Rect is a struct that represent rectangluar space.
25 [StructLayout(LayoutKind.Sequential)]
26 public struct Rect : IEquatable<Rect>
29 /// Creates and initializes a new instance of the Rect class.
31 /// <param name="x">X axis value.</param>
32 /// <param name="y">Y axis value.</param>
33 /// <param name="w">Width value.</param>
34 /// <param name="h">Height value.</param>
35 public Rect(int x, int y, int w, int h)
44 /// Gets or sets the position of this Rectangle on the X axis.
46 public int X { get; set; }
49 /// Gets or sets the position of this Rectangle on the Y axis.
51 public int Y { get; set; }
54 /// Gets or sets the width of this Rectangle.
56 public int Width { get; set; }
59 /// Gets or sets the height of this Rectangle.
61 public int Height { get; set; }
64 /// Gets the position of this Rectangle on the X axis.
66 public int Left { get { return X; } }
69 /// Gets the extent along the X axis.
71 public int Right { get { return X + Width; } }
74 /// Gets the position of this Rectangle on the Y axis.
76 public int Top { get { return Y; } }
79 /// Gets the extent along the Y axis.
81 public int Bottom { get { return Y + Height; } }
84 /// Gets the Point defined by Rectangle.Left and Rectangle.Top.
86 public Point Location { get { return new Point { X = X, Y = Y }; } }
89 /// Gets the extent of the Rectangle along its X and Y axis.
91 public Size Size { get { return new Size { Width = Width, Height = Height }; } }
94 /// A human-readable representation of the <see cref="T:Tizen.UI.Rect" />.
96 /// <returns>The string is formatted as "{{X={0} Y={1} Width={2} Height={3}}}".</returns>
97 public override string ToString()
99 return string.Format("{{X={0} Y={1} Width={2} Height={3}}}", X, Y, Width, Height);
103 /// Gets the hash code.
105 /// <returns>The hash code.</returns>
106 public override int GetHashCode()
110 int hashCode = X.GetHashCode();
111 hashCode = (hashCode * 397) ^ Y.GetHashCode();
112 hashCode = (hashCode * 397) ^ Width.GetHashCode();
113 hashCode = (hashCode * 397) ^ Height.GetHashCode();
119 /// Indicates whether this instance and a specified object are equal.
121 /// <param name="obj">The object to compare with the current instance.</param>
123 /// true if obj and this instance are the same type and represent the same value.
124 /// otherwise, false.
126 public override bool Equals(object obj)
131 return Equals((Rect)obj);
135 /// Indicates whether this instance and a <see cref="Rect"/> object are equal.
137 /// <param name="other">The <see cref="Rect"/> to compare with the current instance.</param>
139 /// true if obj and this instance are the same type and represent the same value.
140 /// otherwise, false.
142 public bool Equals(Rect other)
144 return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height);
148 /// Whether the two <see cref="T:Tizen.UI.Rectangle" />s are equal.
150 /// <param name="r1">A <see cref="T:Tizen.UI.Rectangle" /> on the left hand side.</param>
151 /// <param name="r2">A <see cref="T:Tizen.UI.Rectangle" /> on the right hand side.</param>
152 /// <returns>True if the two <see cref="T:Tizen.UI.Rectangle" />s have equal values.</returns>
153 public static bool operator ==(Rect r1, Rect r2)
155 return r1.Equals(r2);
159 /// Whether two <see cref="T:Tizen.UI.Rectangle" />s are not equal.
161 /// <param name="r1">A <see cref="T:Tizen.UI.Rectangle" /> on the left hand side.</param>
162 /// <param name="r2">A <see cref="T:Tizen.UI.Rectangle" /> on the right hand side.</param>
163 /// <returns>True if the two <see cref="T:Tizen.UI.Rectangle" />s do not have equal values.</returns>
164 public static bool operator !=(Rect r1, Rect r2)
166 return !r1.Equals(r2);