2005-10-04 Zoltan Varga <vargaz@freemail.hu>
[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 Novell, Inc. http://www.novell.com
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.Globalization;
36 using System.Runtime.InteropServices;
37 using System.ComponentModel;
38
39 namespace System.Drawing
40 {
41         [Serializable]
42         [ComVisible (true)]
43         public struct PointF
44         {
45                 // Private x and y coordinate fields.
46                 private float x, y;
47
48                 // -----------------------
49                 // Public Shared Members
50                 // -----------------------
51
52                 /// <summary>
53                 ///     Empty Shared Field
54                 /// </summary>
55                 ///
56                 /// <remarks>
57                 ///     An uninitialized PointF Structure.
58                 /// </remarks>
59                 
60                 public static readonly PointF Empty;
61
62                 /// <summary>
63                 ///     Addition Operator
64                 /// </summary>
65                 ///
66                 /// <remarks>
67                 ///     Translates a PointF using the Width and Height
68                 ///     properties of the given Size.
69                 /// </remarks>
70
71                 public static PointF operator + (PointF pt, Size 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 pt_a, PointF pt_b)
87                 {
88                         return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.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 pt_a, PointF pt_b)
102                 {
103                         return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.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                 
120                 // -----------------------
121                 // Public Constructor
122                 // -----------------------
123
124                 /// <summary>
125                 ///     PointF Constructor
126                 /// </summary>
127                 ///
128                 /// <remarks>
129                 ///     Creates a PointF from a specified x,y coordinate pair.
130                 /// </remarks>
131                 
132                 public PointF (float x, float y)
133                 {
134                         this.x = x;
135                         this.y = y;
136                 }
137
138                 // -----------------------
139                 // Public Instance Members
140                 // -----------------------
141
142                 /// <summary>
143                 ///     IsEmpty Property
144                 /// </summary>
145                 ///
146                 /// <remarks>
147                 ///     Indicates if both X and Y are zero.
148                 /// </remarks>
149                 
150                 [Browsable (false)]
151                 public bool IsEmpty {
152                         get {
153                                 return ((x == 0.0) && (y == 0.0));
154                         }
155                 }
156
157                 /// <summary>
158                 ///     X Property
159                 /// </summary>
160                 ///
161                 /// <remarks>
162                 ///     The X coordinate of the PointF.
163                 /// </remarks>
164                 
165                 public float X {
166                         get {
167                                 return x;
168                         }
169                         set {
170                                 x = value;
171                         }
172                 }
173
174                 /// <summary>
175                 ///     Y Property
176                 /// </summary>
177                 ///
178                 /// <remarks>
179                 ///     The Y coordinate of the PointF.
180                 /// </remarks>
181                 
182                 public float Y {
183                         get {
184                                 return y;
185                         }
186                         set {
187                                 y = value;
188                         }
189                 }
190
191                 /// <summary>
192                 ///     Equals Method
193                 /// </summary>
194                 ///
195                 /// <remarks>
196                 ///     Checks equivalence of this PointF and another object.
197                 /// </remarks>
198                 
199                 public override bool Equals (object o)
200                 {
201                         if (!(o is PointF))
202                                 return false;
203
204                         return (this == (PointF) o);
205                 }
206
207                 /// <summary>
208                 ///     GetHashCode Method
209                 /// </summary>
210                 ///
211                 /// <remarks>
212                 ///     Calculates a hashing value.
213                 /// </remarks>
214                 
215                 public override int GetHashCode ()
216                 {
217                         return (int) x ^ (int) y;
218                 }
219
220                 /// <summary>
221                 ///     ToString Method
222                 /// </summary>
223                 ///
224                 /// <remarks>
225                 ///     Formats the PointF as a string in coordinate notation.
226                 /// </remarks>
227                 
228                 public override string ToString ()
229                 {
230                         return String.Format ("{{X={0}, Y={1}}}", x.ToString (CultureInfo.CurrentCulture),
231                                 y.ToString (CultureInfo.CurrentCulture));
232                 }
233         }
234 }