Release 4.0.0-preview1-00051
[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 that defining height and width as a pair of generic type.
23     /// </summary>
24     public struct Size : IEquatable<Size>
25     {
26         /// <summary>
27         /// Magnitude along the horizontal axis, in platform-defined units.
28         /// </summary>
29         public int Width;
30
31         /// <summary>
32         /// Magnitude along the vertical axis, in platform-specific units.
33         /// </summary>
34         public int Height;
35
36         /// <summary>
37         /// Initializes a new instance of the Size structure from the specified dimensions.
38         /// </summary>
39         /// <param name="width">The width to set</param>
40         /// <param name="height">The height to set</param>
41         public Size(int width, int height)
42         {
43             Width = width;
44             Height = height;
45         }
46
47         /// <summary>
48         /// A human-readable representation of the <see cref="T:Tizen.UI.Size" />.
49         /// </summary>
50         /// <returns>The string is formatted as "{{Width={0} Height={1}}}".</returns>
51         public override string ToString()
52         {
53             return string.Format("{{Width={0} Height={1}}}", Width, Height);
54         }
55
56         public override int GetHashCode()
57         {
58             unchecked
59             {
60                 return Width.GetHashCode() ^ (Height.GetHashCode() * 397);
61             }
62         }
63
64         public override bool Equals(object obj)
65         {
66             if (!(obj is Size))
67                 return false;
68
69             return Equals((Size)obj);
70         }
71
72         public bool Equals(Size other)
73         {
74             return Width.Equals(other.Width) && Height.Equals(other.Height);
75         }
76
77         /// <summary>
78         /// Whether the two <see cref="T:Tizen.UI.Size" />s are equal.
79         /// </summary>
80         /// <param name="s1">A <see cref="T:Tizen.UI.Size" /> on the left hand side.</param>
81         /// <param name="s2">A <see cref="T:Tizen.UI.Size" /> on the right hand side.</param>
82         /// <returns>True if the two <see cref="T:Tizen.UI.Size" />s have equal values.</returns>
83         public static bool operator ==(Size s1, Size s2)
84         {
85             return s1.Equals(s2);
86         }
87
88         /// <summary>
89         /// Whether two <see cref="T:Tizen.UI.Size" />s are not equal.
90         /// </summary>
91         /// <param name="s1">A <see cref="T:Tizen.UI.Size" /> on the left hand side.</param>
92         /// <param name="s2">A <see cref="T:Tizen.UI.Size" /> on the right hand side.</param>
93         /// <returns>True if the two <see cref="T:Tizen.UI.Size" />s do not have equal values.</returns>
94         public static bool operator !=(Size s1, Size s2)
95         {
96             return !s1.Equals(s2);
97         }
98     }
99 }