[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Size.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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Size is a struct defining the height and width as a pair of generic type.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public struct Size : IEquatable<Size>
26     {
27         /// <summary>
28         /// Magnitude along the horizontal axis, in platform-defined units.
29         /// </summary>
30         /// <since_tizen> preview </since_tizen>
31         public int Width;
32
33         /// <summary>
34         /// Magnitude along the vertical axis, in platform-specific units.
35         /// </summary>
36         /// <since_tizen> preview </since_tizen>
37         public int Height;
38
39         /// <summary>
40         /// Initializes a new instance of the size structure from specified dimensions.
41         /// </summary>
42         /// <param name="width">The width to set.</param>
43         /// <param name="height">The height to set.</param>
44         /// <since_tizen> preview </since_tizen>
45         public Size(int width, int height)
46         {
47             Width = width;
48             Height = height;
49         }
50
51         /// <summary>
52         /// A human-readable representation of <see cref="Size"/>.
53         /// </summary>
54         /// <returns>The string is formatted as "{{Width={0} Height={1}}}".</returns>
55         /// <since_tizen> preview </since_tizen>
56         public override string ToString()
57         {
58             return string.Format("{{Width={0} Height={1}}}", Width, Height);
59         }
60
61         /// <summary>
62         /// Gets the hash code.
63         /// </summary>
64         /// <returns>The hash code.</returns>
65         /// <since_tizen> preview </since_tizen>
66         public override int GetHashCode()
67         {
68             unchecked
69             {
70                 return Width.GetHashCode() ^ (Height.GetHashCode() * 397);
71             }
72         }
73
74         /// <summary>
75         /// Indicates whether this instance and a specified object are equal.
76         /// </summary>
77         /// <param name="obj">The object to compare with the current instance.</param>
78         /// <returns>
79         /// true if the object and this instance are of the same type and represent the same value,
80         /// otherwise false.
81         /// </returns>
82         /// <since_tizen> preview </since_tizen>
83         public override bool Equals(object obj)
84         {
85             if (!(obj is Size))
86                 return false;
87
88             return Equals((Size)obj);
89         }
90
91         /// <summary>
92         /// Indicates whether this instance and a <see cref="Size"/> object are equal.
93         /// </summary>
94         /// <param name="other">The <see cref="Size"/> to compare with the current instance.</param>
95         /// <returns>
96         /// true if the object and this instance are of the same type and represent the same value,
97         /// otherwise false.
98         /// </returns>
99         /// <since_tizen> preview </since_tizen>
100         public bool Equals(Size other)
101         {
102             return Width.Equals(other.Width) && Height.Equals(other.Height);
103         }
104
105         /// <summary>
106         /// Whether both <see cref="Size"/>s are equal.
107         /// </summary>
108         /// <param name="s1">A <see cref="Size"/> on the left hand side.</param>
109         /// <param name="s2">A <see cref="Size"/> on the right hand side.</param>
110         /// <returns>True if both <see cref="Size"/>s have equal values.</returns>
111         /// <since_tizen> preview </since_tizen>
112         public static bool operator ==(Size s1, Size s2)
113         {
114             return s1.Equals(s2);
115         }
116
117         /// <summary>
118         /// Whether both <see cref="Size"/>s are not equal.
119         /// </summary>
120         /// <param name="s1">A <see cref="Size"/> on the left hand side.</param>
121         /// <param name="s2">A <see cref="Size"/> on the right hand side.</param>
122         /// <returns>True if both <see cref="Size"/>s do not have equal values.</returns>
123         /// <since_tizen> preview </since_tizen>
124         public static bool operator !=(Size s1, Size s2)
125         {
126             return !s1.Equals(s2);
127         }
128     }
129 }