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