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)
43 /// Gets or sets the position of this Rectangle on the X axis.
45 public int X { get; set; }
48 /// Gets or sets the position of this Rectangle on the Y axis.
50 public int Y { get; set; }
53 /// Gets or sets the width of this Rectangle.
55 public int Width { get; set; }
58 /// Gets or sets the height of this Rectangle.
60 public int Height { get; set; }
63 /// Gets the position of this Rectangle on the X axis.
65 public int Left { get { return X; } }
68 /// Gets the extent along the X axis.
70 public int Right { get { return X + Width; } }
73 /// Gets the position of this Rectangle on the Y axis.
75 public int Top { get { return Y; } }
78 /// Gets the extent along the Y axis.
80 public int Bottom { get { return Y + Height; } }
83 /// Gets the Point defined by Rectangle.Left and Rectangle.Top.
85 public Point Location { get { return new Point { X = X, Y = Y }; } }
88 /// Gets the extent of the Rectangle along its X and Y axis.
90 public Size Size { get { return new Size { Width = Width, Height = Height }; } }
92 public override string ToString()
94 return string.Format("{{X={0} Y={1} Width={2} Height={3}}}", X, Y, Width, Height);
97 public override int GetHashCode()
101 int hashCode = X.GetHashCode();
102 hashCode = (hashCode * 397) ^ Y.GetHashCode();
103 hashCode = (hashCode * 397) ^ Width.GetHashCode();
104 hashCode = (hashCode * 397) ^ Height.GetHashCode();
109 public override bool Equals(object obj)
114 return Equals((Rect)obj);
117 public bool Equals(Rect other)
119 return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height);
123 /// Whether the two <see cref="T:Tizen.UI.Rectangle" />s are equal.
125 /// <param name="r1">A <see cref="T:Tizen.UI.Rectangle" /> on the left hand side.</param>
126 /// <param name="r2">A <see cref="T:Tizen.UI.Rectangle" /> on the right hand side.</param>
127 /// <returns>True if the two <see cref="T:Tizen.UI.Rectangle" />s have equal values.</returns>
128 public static bool operator ==(Rect r1, Rect r2)
130 return r1.Equals(r2);
134 /// Whether two <see cref="T:Tizen.UI.Rectangle" />s are not equal.
136 /// <param name="r1">A <see cref="T:Tizen.UI.Rectangle" /> on the left hand side.</param>
137 /// <param name="r2">A <see cref="T:Tizen.UI.Rectangle" /> on the right hand side.</param>
138 /// <returns>True if the two <see cref="T:Tizen.UI.Rectangle" />s do not have equal values.</returns>
139 public static bool operator !=(Rect r1, Rect r2)
141 return !r1.Equals(r2);