Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Common / 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 Tizen.Multimedia
20 {
21     /// <summary>
22     /// Represents a size in 2D space.
23     /// </summary>
24     public struct Size
25     {
26         /// <summary>
27         /// Initializes a new instance of the <see cref="Size"/> with the specified values.
28         /// </summary>
29         /// <param name="width">Width of the size.</param>
30         /// <param name="height">Height of the size.</param>
31         public Size(int width, int height)
32         {
33             Width = width;
34             Height = height;
35         }
36
37         /// <summary>
38         /// Gets or sets the width.
39         /// </summary>
40         public int Width
41         {
42             get;
43             set;
44         }
45
46         /// <summary>
47         /// Gets or sets the height.
48         /// </summary>
49         public int Height
50         {
51             get;
52             set;
53         }
54
55         /// <summary>
56         /// Returns a string that represents the current object.
57         /// </summary>
58         /// <returns>A string that represents the current object.</returns>
59         public override string ToString() => $"Width={ Width.ToString() }, Height={ Height.ToString() }";
60
61         /// <summary>
62         /// Gets the hash code for this instance of <see cref="Size"/>.
63         /// </summary>
64         /// <returns>The hash code for this instance of <see cref="Size"/>.</returns>
65         public override int GetHashCode()
66         {
67             return new { Width, Height }.GetHashCode();
68         }
69
70         /// <summary>
71         /// Compares an object to an instance of <see cref="Size"/> for equality.
72         /// </summary>
73         /// <param name="obj">A <see cref="Object"/> to compare.</param>
74         /// <returns>true if the two sizes are equal; otherwise, false.</returns>
75         public override bool Equals(object obj)
76         {
77             return obj is Size && this == (Size)obj;
78         }
79
80         /// <summary>
81         /// Compares two instances of <see cref="Size"/> for equality.
82         /// </summary>
83         /// <param name="size1">A <see cref="Size"/> to compare.</param>
84         /// <param name="size2">A <see cref="Size"/> to compare.</param>
85         /// <returns>true if the two instances of <see cref="Size"/> are equal; otherwise false.</returns>
86         public static bool operator ==(Size size1, Size size2)
87         {
88             return size1.Width == size2.Width && size1.Height == size2.Height;
89         }
90
91         /// <summary>
92         /// Compares two instances of <see cref="Size"/> for inequality.
93         /// </summary>
94         /// <param name="size1">A <see cref="Size"/> to compare.</param>
95         /// <param name="size2">A <see cref="Size"/> to compare.</param>
96         /// <returns>true if the two instances of <see cref="Size"/> are not equal; otherwise false.</returns>
97         public static bool operator !=(Size size1, Size size2)
98         {
99             return !(size1 == size2);
100         }
101     }
102 }