2 // System.Drawing.PointF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using System.Globalization;
32 using System.Runtime.InteropServices;
33 using System.ComponentModel;
35 namespace System.Drawing
41 // Private x and y coordinate fields.
44 // -----------------------
45 // Public Shared Members
46 // -----------------------
49 /// Empty Shared Field
53 /// An uninitialized PointF Structure.
56 public static readonly PointF Empty;
63 /// Translates a PointF using the Width and Height
64 /// properties of the given Size.
67 public static PointF operator + (PointF pt, Size sz)
69 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
71 public static PointF operator + (PointF pt, SizeF sz)
73 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
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.
86 public static bool operator == (PointF left, PointF right)
88 return ((left.X == right.X) && (left.Y == right.Y));
92 /// Inequality Operator
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.
101 public static bool operator != (PointF left, PointF right)
103 return ((left.X != right.X) || (left.Y != right.Y));
107 /// Subtraction Operator
111 /// Translates a PointF using the negation of the Width
112 /// and Height properties of the given Size.
115 public static PointF operator - (PointF pt, Size sz)
117 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
119 public static PointF operator - (PointF pt, SizeF sz)
121 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
124 // -----------------------
125 // Public Constructor
126 // -----------------------
129 /// PointF Constructor
133 /// Creates a PointF from a specified x,y coordinate pair.
136 public PointF (float x, float y)
142 // -----------------------
143 // Public Instance Members
144 // -----------------------
151 /// Indicates if both X and Y are zero.
155 public bool IsEmpty {
157 return ((x == 0.0) && (y == 0.0));
166 /// The X coordinate of the PointF.
183 /// The Y coordinate of the PointF.
200 /// Checks equivalence of this PointF and another object.
203 public override bool Equals (object obj)
205 if (!(obj is PointF))
208 return (this == (PointF) obj);
212 /// GetHashCode Method
216 /// Calculates a hashing value.
219 public override int GetHashCode ()
221 return (int) x ^ (int) y;
229 /// Formats the PointF as a string in coordinate notation.
232 public override string ToString ()
234 return String.Format ("{{X={0}, Y={1}}}", x.ToString (CultureInfo.CurrentCulture),
235 y.ToString (CultureInfo.CurrentCulture));
238 public static PointF Add (PointF pt, Size sz)
240 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
243 public static PointF Add (PointF pt, SizeF sz)
245 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
248 public static PointF Subtract (PointF pt, Size sz)
250 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
253 public static PointF Subtract (PointF pt, SizeF sz)
255 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);