This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[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.Runtime.InteropServices;
36 using System.ComponentModel;
37
38 namespace System.Drawing
39 {
40         [Serializable]
41         [ComVisible (true)]
42         public struct PointF
43         {
44                 // Private x and y coordinate fields.
45                 private float cx, cy;
46
47                 // -----------------------
48                 // Public Shared Members
49                 // -----------------------
50
51                 /// <summary>
52                 ///     Empty Shared Field
53                 /// </summary>
54                 ///
55                 /// <remarks>
56                 ///     An uninitialized PointF Structure.
57                 /// </remarks>
58                 
59                 public static readonly PointF Empty;
60
61                 /// <summary>
62                 ///     Addition Operator
63                 /// </summary>
64                 ///
65                 /// <remarks>
66                 ///     Translates a PointF using the Width and Height
67                 ///     properties of the given Size.
68                 /// </remarks>
69
70                 public static PointF operator + (PointF pt, Size sz)
71                 {
72                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
73                 }
74                 
75                 /// <summary>
76                 ///     Equality Operator
77                 /// </summary>
78                 ///
79                 /// <remarks>
80                 ///     Compares two PointF objects. The return value is
81                 ///     based on the equivalence of the X and Y properties 
82                 ///     of the two points.
83                 /// </remarks>
84
85                 public static bool operator == (PointF pt_a, PointF pt_b)
86                 {
87                         return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
88                 }
89                 
90                 /// <summary>
91                 ///     Inequality Operator
92                 /// </summary>
93                 ///
94                 /// <remarks>
95                 ///     Compares two PointF objects. The return value is
96                 ///     based on the equivalence of the X and Y properties 
97                 ///     of the two points.
98                 /// </remarks>
99
100                 public static bool operator != (PointF pt_a, PointF pt_b)
101                 {
102                         return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
103                 }
104                 
105                 /// <summary>
106                 ///     Subtraction Operator
107                 /// </summary>
108                 ///
109                 /// <remarks>
110                 ///     Translates a PointF using the negation of the Width 
111                 ///     and Height properties of the given Size.
112                 /// </remarks>
113
114                 public static PointF operator - (PointF pt, Size sz)
115                 {
116                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
117                 }
118                 
119                 // -----------------------
120                 // Public Constructor
121                 // -----------------------
122
123                 /// <summary>
124                 ///     PointF Constructor
125                 /// </summary>
126                 ///
127                 /// <remarks>
128                 ///     Creates a PointF from a specified x,y coordinate pair.
129                 /// </remarks>
130                 
131                 public PointF (float x, float y)
132                 {
133                         cx = x;
134                         cy = y;
135                 }
136
137                 // -----------------------
138                 // Public Instance Members
139                 // -----------------------
140
141                 /// <summary>
142                 ///     IsEmpty Property
143                 /// </summary>
144                 ///
145                 /// <remarks>
146                 ///     Indicates if both X and Y are zero.
147                 /// </remarks>
148                 
149                 [Browsable (false)]
150                 public bool IsEmpty {
151                         get {
152                                 return ((cx == 0.0) && (cy == 0.0));
153                         }
154                 }
155
156                 /// <summary>
157                 ///     X Property
158                 /// </summary>
159                 ///
160                 /// <remarks>
161                 ///     The X coordinate of the PointF.
162                 /// </remarks>
163                 
164                 public float X {
165                         get {
166                                 return cx;
167                         }
168                         set {
169                                 cx = value;
170                         }
171                 }
172
173                 /// <summary>
174                 ///     Y Property
175                 /// </summary>
176                 ///
177                 /// <remarks>
178                 ///     The Y coordinate of the PointF.
179                 /// </remarks>
180                 
181                 public float Y {
182                         get {
183                                 return cy;
184                         }
185                         set {
186                                 cy = value;
187                         }
188                 }
189
190                 /// <summary>
191                 ///     Equals Method
192                 /// </summary>
193                 ///
194                 /// <remarks>
195                 ///     Checks equivalence of this PointF and another object.
196                 /// </remarks>
197                 
198                 public override bool Equals (object o)
199                 {
200                         if (!(o is PointF))
201                                 return false;
202
203                         return (this == (PointF) o);
204                 }
205
206                 /// <summary>
207                 ///     GetHashCode Method
208                 /// </summary>
209                 ///
210                 /// <remarks>
211                 ///     Calculates a hashing value.
212                 /// </remarks>
213                 
214                 public override int GetHashCode ()
215                 {
216                         return (int) cx ^ (int) cy;
217                 }
218
219                 /// <summary>
220                 ///     ToString Method
221                 /// </summary>
222                 ///
223                 /// <remarks>
224                 ///     Formats the PointF as a string in coordinate notation.
225                 /// </remarks>
226                 
227                 public override string ToString ()
228                 {
229                         return String.Format ("{{X={0}, Y={1}}}", cx, cy);
230                 }
231         }
232 }