[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Rect.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// The Rect is a struct that represents the rectangular space.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     [StructLayout(LayoutKind.Sequential)]
27     public struct Rect : IEquatable<Rect>
28     {
29         /// <summary>
30         /// Creates and initializes a new instance of the Rect class.
31         /// </summary>
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)
38         {
39             X = x;
40             Y = y;
41             Width = w;
42             Height = h;
43         }
44
45         /// <summary>
46         /// Gets or sets the position of this rectangle on the X-axis.
47         /// </summary>
48         /// <since_tizen> preview </since_tizen>
49         public int X { get; set; }
50
51         /// <summary>
52         /// Gets or sets the position of this rectangle on the Y-axis.
53         /// </summary>
54         /// <since_tizen> preview </since_tizen>
55         public int Y { get; set; }
56
57         /// <summary>
58         /// Gets or sets the width of this rectangle.
59         /// </summary>
60         /// <since_tizen> preview </since_tizen>
61         public int Width { get; set; }
62
63         /// <summary>
64         /// Gets or sets the height of this rectangle.
65         /// </summary>
66         /// <since_tizen> preview </since_tizen>
67         public int Height { get; set; }
68
69         /// <summary>
70         /// Gets the position of this rectangle on the X-axis.
71         /// </summary>
72         /// <since_tizen> preview </since_tizen>
73         public int Left { get { return X; } }
74
75         /// <summary>
76         /// Gets the extent along the X-axis.
77         /// </summary>
78         /// <since_tizen> preview </since_tizen>
79         public int Right { get { return X + Width; } }
80
81         /// <summary>
82         /// Gets the position of this rectangle on the Y-axis.
83         /// </summary>
84         /// <since_tizen> preview </since_tizen>
85         public int Top { get { return Y; } }
86
87         /// <summary>
88         /// Gets the extent along the Y-axis.
89         /// </summary>
90         /// <since_tizen> preview </since_tizen>
91         public int Bottom { get { return Y + Height; } }
92
93         /// <summary>
94         /// Gets the point defined by Rectangle.Left and Rectangle.Top.
95         /// </summary>
96         /// <since_tizen> preview </since_tizen>
97         public Point Location { get { return new Point { X = X, Y = Y }; } }
98
99         /// <summary>
100         /// Gets the extent of the rectangle along its X-axis and Y-axis.
101         /// </summary>
102         /// <since_tizen> preview </since_tizen>
103         public Size Size { get { return new Size { Width = Width, Height = Height }; } }
104
105         /// <summary>
106         /// A human-readable representation of <see cref="Rect"/>.
107         /// </summary>
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()
111         {
112             return string.Format("{{X={0} Y={1} Width={2} Height={3}}}", X, Y, Width, Height);
113         }
114
115         /// <summary>
116         /// Gets the hash code.
117         /// </summary>
118         /// <returns>The hash code.</returns>
119         /// <since_tizen> preview </since_tizen>
120         public override int GetHashCode()
121         {
122             unchecked
123             {
124                 int hashCode = X.GetHashCode();
125                 hashCode = (hashCode * 397) ^ Y.GetHashCode();
126                 hashCode = (hashCode * 397) ^ Width.GetHashCode();
127                 hashCode = (hashCode * 397) ^ Height.GetHashCode();
128                 return hashCode;
129             }
130         }
131
132         /// <summary>
133         /// Indicates whether this instance and a specified object are equal.
134         /// </summary>
135         /// <param name="obj">The object to compare with the current instance.</param>
136         /// <returns>
137         /// true if the object and this instance are of the same type and represent the same value,
138         /// otherwise false.
139         /// </returns>
140         /// <since_tizen> preview </since_tizen>
141         public override bool Equals(object obj)
142         {
143             if (!(obj is Rect))
144                 return false;
145
146             return Equals((Rect)obj);
147         }
148
149         /// <summary>
150         /// Indicates whether this instance and a <see cref="Rect"/> object are equal.
151         /// </summary>
152         /// <param name="other">The <see cref="Rect"/> to compare with the current instance.</param>
153         /// <returns>
154         /// true if the object and this instance are of the same type and represent the same value,
155         /// otherwise, false
156         /// </returns>
157         /// <since_tizen> preview </since_tizen>
158         public bool Equals(Rect other)
159         {
160             return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height);
161         }
162
163         /// <summary>
164         /// Whether both <see cref="Rect"/>'s are equal.
165         /// </summary>
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)
171         {
172             return r1.Equals(r2);
173         }
174
175         /// <summary>
176         /// Whether both <see cref="Rect"/>'s are not equal.
177         /// </summary>
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)
183         {
184             return !r1.Equals(r2);
185         }
186     }
187 }