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 represents the rectangular space.
25 /// <since_tizen> preview </since_tizen>
26 [StructLayout(LayoutKind.Sequential)]
27 public struct Rect : IEquatable<Rect>
30 /// Creates and initializes a new instance of the Rect class.
32 /// <param name="x">X-axis value.</param>
33 /// <param name="y">Y-axis value.</param>
34 /// <param name="w">Width value.</param>
35 /// <param name="h">Height value.</param>
36 /// <since_tizen> preview </since_tizen>
37 public Rect(int x, int y, int w, int h)
46 /// Gets or sets the position of this rectangle on the X-axis.
48 /// <since_tizen> preview </since_tizen>
49 public int X { get; set; }
52 /// Gets or sets the position of this rectangle on the Y-axis.
54 /// <since_tizen> preview </since_tizen>
55 public int Y { get; set; }
58 /// Gets or sets the width of this rectangle.
60 /// <since_tizen> preview </since_tizen>
61 public int Width { get; set; }
64 /// Gets or sets the height of this rectangle.
66 /// <since_tizen> preview </since_tizen>
67 public int Height { get; set; }
70 /// Gets the position of this rectangle on the X-axis.
72 /// <since_tizen> preview </since_tizen>
73 public int Left { get { return X; } }
76 /// Gets the extent along the X-axis.
78 /// <since_tizen> preview </since_tizen>
79 public int Right { get { return X + Width; } }
82 /// Gets the position of this rectangle on the Y-axis.
84 /// <since_tizen> preview </since_tizen>
85 public int Top { get { return Y; } }
88 /// Gets the extent along the Y-axis.
90 /// <since_tizen> preview </since_tizen>
91 public int Bottom { get { return Y + Height; } }
94 /// Gets the point defined by Rectangle.Left and Rectangle.Top.
96 /// <since_tizen> preview </since_tizen>
97 public Point Location { get { return new Point { X = X, Y = Y }; } }
100 /// Gets the extent of the rectangle along its X-axis and Y-axis.
102 /// <since_tizen> preview </since_tizen>
103 public Size Size { get { return new Size { Width = Width, Height = Height }; } }
106 /// A human-readable representation of <see cref="Rect"/>.
108 /// <returns>The string is formatted as "{{X={0} Y={1} Width={2} Height={3}}}".</returns>
109 /// <since_tizen> preview </since_tizen>
110 public override string ToString()
112 return string.Format("{{X={0} Y={1} Width={2} Height={3}}}", X, Y, Width, Height);
116 /// Gets the hash code.
118 /// <returns>The hash code.</returns>
119 /// <since_tizen> preview </since_tizen>
120 public override int GetHashCode()
124 int hashCode = X.GetHashCode();
125 hashCode = (hashCode * 397) ^ Y.GetHashCode();
126 hashCode = (hashCode * 397) ^ Width.GetHashCode();
127 hashCode = (hashCode * 397) ^ Height.GetHashCode();
133 /// Indicates whether this instance and a specified object are equal.
135 /// <param name="obj">The object to compare with the current instance.</param>
137 /// true if the object and this instance are of the same type and represent the same value,
140 /// <since_tizen> preview </since_tizen>
141 public override bool Equals(object obj)
146 return Equals((Rect)obj);
150 /// Indicates whether this instance and a <see cref="Rect"/> object are equal.
152 /// <param name="other">The <see cref="Rect"/> to compare with the current instance.</param>
154 /// true if the object and this instance are of the same type and represent the same value,
157 /// <since_tizen> preview </since_tizen>
158 public bool Equals(Rect other)
160 return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height);
164 /// Whether both <see cref="Rect"/>'s are equal.
166 /// <param name="r1">A <see cref="Rect"/> on the left hand side.</param>
167 /// <param name="r2">A <see cref="Rect"/> on the right hand side.</param>
168 /// <returns>True if both <see cref="Rect"/>'s have equal values.</returns>
169 /// <since_tizen> preview </since_tizen>
170 public static bool operator ==(Rect r1, Rect r2)
172 return r1.Equals(r2);
176 /// Whether both <see cref="Rect"/>'s are not equal.
178 /// <param name="r1">A <see cref="Rect"/> on the left hand side.</param>
179 /// <param name="r2">A <see cref="Rect"/> on the right hand side.</param>
180 /// <returns>True if both <see cref="Rect"/>'s do not have equal values.</returns>
181 /// <since_tizen> preview </since_tizen>
182 public static bool operator !=(Rect r1, Rect r2)
184 return !r1.Equals(r2);