Merge pull request #1466 from schani/stage-unified-card-table-scanning
[mono.git] / mcs / class / System.Drawing / System.Drawing / PointF.cs
1 //
2 // System.Drawing.PointF.cs
3 //
4 // Author:
5 //   Mike Kestner (mkestner@speakeasy.net)
6 //
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Globalization;
32 using System.Runtime.InteropServices;
33 using System.ComponentModel;
34
35 namespace System.Drawing
36 {
37         [Serializable]
38         [ComVisible (true)]
39         public struct PointF
40         {
41                 // Private x and y coordinate fields.
42                 private float x, y;
43
44                 // -----------------------
45                 // Public Shared Members
46                 // -----------------------
47
48                 /// <summary>
49                 ///     Empty Shared Field
50                 /// </summary>
51                 ///
52                 /// <remarks>
53                 ///     An uninitialized PointF Structure.
54                 /// </remarks>
55                 
56                 public static readonly PointF Empty;
57
58                 /// <summary>
59                 ///     Addition Operator
60                 /// </summary>
61                 ///
62                 /// <remarks>
63                 ///     Translates a PointF using the Width and Height
64                 ///     properties of the given Size.
65                 /// </remarks>
66
67                 public static PointF operator + (PointF pt, Size sz)
68                 {
69                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
70                 }
71                 public static PointF operator + (PointF pt, SizeF sz)
72                 {
73                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
74                 }
75                 
76                 /// <summary>
77                 ///     Equality Operator
78                 /// </summary>
79                 ///
80                 /// <remarks>
81                 ///     Compares two PointF objects. The return value is
82                 ///     based on the equivalence of the X and Y properties 
83                 ///     of the two points.
84                 /// </remarks>
85
86                 public static bool operator == (PointF left, PointF right)
87                 {
88                         return ((left.X == right.X) && (left.Y == right.Y));
89                 }
90                 
91                 /// <summary>
92                 ///     Inequality Operator
93                 /// </summary>
94                 ///
95                 /// <remarks>
96                 ///     Compares two PointF objects. The return value is
97                 ///     based on the equivalence of the X and Y properties 
98                 ///     of the two points.
99                 /// </remarks>
100
101                 public static bool operator != (PointF left, PointF right)
102                 {
103                         return ((left.X != right.X) || (left.Y != right.Y));
104                 }
105                 
106                 /// <summary>
107                 ///     Subtraction Operator
108                 /// </summary>
109                 ///
110                 /// <remarks>
111                 ///     Translates a PointF using the negation of the Width 
112                 ///     and Height properties of the given Size.
113                 /// </remarks>
114
115                 public static PointF operator - (PointF pt, Size sz)
116                 {
117                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
118                 }
119                 public static PointF operator - (PointF pt, SizeF sz)
120                 {
121                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
122                 }
123                 
124                 // -----------------------
125                 // Public Constructor
126                 // -----------------------
127
128                 /// <summary>
129                 ///     PointF Constructor
130                 /// </summary>
131                 ///
132                 /// <remarks>
133                 ///     Creates a PointF from a specified x,y coordinate pair.
134                 /// </remarks>
135                 
136                 public PointF (float x, float y)
137                 {
138                         this.x = x;
139                         this.y = y;
140                 }
141
142                 // -----------------------
143                 // Public Instance Members
144                 // -----------------------
145
146                 /// <summary>
147                 ///     IsEmpty Property
148                 /// </summary>
149                 ///
150                 /// <remarks>
151                 ///     Indicates if both X and Y are zero.
152                 /// </remarks>
153                 
154                 [Browsable (false)]
155                 public bool IsEmpty {
156                         get {
157                                 return ((x == 0.0) && (y == 0.0));
158                         }
159                 }
160
161                 /// <summary>
162                 ///     X Property
163                 /// </summary>
164                 ///
165                 /// <remarks>
166                 ///     The X coordinate of the PointF.
167                 /// </remarks>
168                 
169                 public float X {
170                         get {
171                                 return x;
172                         }
173                         set {
174                                 x = value;
175                         }
176                 }
177
178                 /// <summary>
179                 ///     Y Property
180                 /// </summary>
181                 ///
182                 /// <remarks>
183                 ///     The Y coordinate of the PointF.
184                 /// </remarks>
185                 
186                 public float Y {
187                         get {
188                                 return y;
189                         }
190                         set {
191                                 y = value;
192                         }
193                 }
194
195                 /// <summary>
196                 ///     Equals Method
197                 /// </summary>
198                 ///
199                 /// <remarks>
200                 ///     Checks equivalence of this PointF and another object.
201                 /// </remarks>
202                 
203                 public override bool Equals (object obj)
204                 {
205                         if (!(obj is PointF))
206                                 return false;
207
208                         return (this == (PointF) obj);
209                 }
210
211                 /// <summary>
212                 ///     GetHashCode Method
213                 /// </summary>
214                 ///
215                 /// <remarks>
216                 ///     Calculates a hashing value.
217                 /// </remarks>
218                 
219                 public override int GetHashCode ()
220                 {
221                         return (int) x ^ (int) y;
222                 }
223
224                 /// <summary>
225                 ///     ToString Method
226                 /// </summary>
227                 ///
228                 /// <remarks>
229                 ///     Formats the PointF as a string in coordinate notation.
230                 /// </remarks>
231                 
232                 public override string ToString ()
233                 {
234                         return String.Format ("{{X={0}, Y={1}}}", x.ToString (CultureInfo.CurrentCulture),
235                                 y.ToString (CultureInfo.CurrentCulture));
236                 }
237
238                 public static PointF Add (PointF pt, Size sz)
239                 {
240                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
241                 }
242                 
243                 public static PointF Add (PointF pt, SizeF sz)
244                 {
245                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
246                 }
247
248                 public static PointF Subtract (PointF pt, Size sz)
249                 {
250                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
251                 }
252
253                 public static PointF Subtract (PointF pt, SizeF sz)
254                 {
255                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
256                 }
257
258         }
259 }