1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 //
6 
7 //
8 
9 using System;
10 using System.Globalization;
11 using System.Runtime.InteropServices;
12 
13 #if !FEATURE_SLJ_PROJECTION_COMPAT
14 #pragma warning disable 436   // Redefining types from Windows.Foundation
15 #endif // !FEATURE_SLJ_PROJECTION_COMPAT
16 
17 #if FEATURE_SLJ_PROJECTION_COMPAT
18 namespace System.Windows
19 #else // !FEATURE_SLJ_PROJECTION_COMPAT
20 
21 
22 namespace Windows.Foundation
23 #endif // FEATURE_SLJ_PROJECTION_COMPAT
24 {
25     //
26     // Point is the managed projection of Windows.Foundation.Point.  Any changes to the layout
27     // of this type must be exactly mirrored on the native WinRT side as well.
28     //
29     // Note that this type is owned by the Jupiter team.  Please contact them before making any
30     // changes here.
31     //
32 
33     [StructLayout(LayoutKind.Sequential)]
34     public struct Point : IFormattable
35     {
36         internal float _x;
37         internal float _y;
38 
PointSystem.Windows.Point39         public Point(double x, double y)
40         {
41             _x = (float)x;
42             _y = (float)y;
43         }
44 
45         public double X
46         {
47             get { return _x; }
48             set { _x = (float)value; }
49         }
50 
51         public double Y
52         {
53             get { return _y; }
54             set { _y = (float)value; }
55         }
56 
ToStringSystem.Windows.Point57         public override string ToString()
58         {
59             // Delegate to the internal method which implements all ToString calls.
60             return ConvertToString(null /* format string */, null /* format provider */);
61         }
62 
ToStringSystem.Windows.Point63         public string ToString(IFormatProvider provider)
64         {
65             // Delegate to the internal method which implements all ToString calls.
66             return ConvertToString(null /* format string */, provider);
67         }
68 
IFormattable.ToStringSystem.Windows.Point69         string IFormattable.ToString(string format, IFormatProvider provider)
70         {
71             // Delegate to the internal method which implements all ToString calls.
72             return ConvertToString(format, provider);
73         }
74 
ConvertToStringSystem.Windows.Point75         private string ConvertToString(string format, IFormatProvider provider)
76         {
77             // Helper to get the numeric list separator for a given culture.
78             char separator = TokenizerHelper.GetNumericListSeparator(provider);
79             return String.Format(provider,
80                                  "{1:" + format + "}{0}{2:" + format + "}",
81                                  separator,
82                                  _x,
83                                  _y);
84         }
85 
operator ==System.Windows.Point86         public static bool operator ==(Point point1, Point point2)
87         {
88             return point1.X == point2.X &&
89                    point1.Y == point2.Y;
90         }
91 
operator !=System.Windows.Point92         public static bool operator !=(Point point1, Point point2)
93         {
94             return !(point1 == point2);
95         }
96 
EqualsSystem.Windows.Point97         public override bool Equals(object o)
98         {
99             return o is Point && this == (Point)o;
100         }
101 
EqualsSystem.Windows.Point102         public bool Equals(Point value)
103         {
104             return (this == value);
105         }
106 
GetHashCodeSystem.Windows.Point107         public override int GetHashCode()
108         {
109             // Perform field-by-field XOR of HashCodes
110             return X.GetHashCode() ^
111                    Y.GetHashCode();
112         }
113     }
114 }
115 
116 #if !FEATURE_SLJ_PROJECTION_COMPAT
117 #pragma warning restore 436
118 #endif // !FEATURE_SLJ_PROJECTION_COMPAT
119 
120