2 // System.Drawing.PointF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
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.
35 using System.Globalization;
36 using System.Runtime.InteropServices;
37 using System.ComponentModel;
39 namespace System.Drawing
45 // Private x and y coordinate fields.
48 // -----------------------
49 // Public Shared Members
50 // -----------------------
53 /// Empty Shared Field
57 /// An uninitialized PointF Structure.
60 public static readonly PointF Empty;
67 /// Translates a PointF using the Width and Height
68 /// properties of the given Size.
71 public static PointF operator + (PointF pt, Size 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 pt_a, PointF pt_b)
88 return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.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 pt_a, PointF pt_b)
103 return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.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);
120 // -----------------------
121 // Public Constructor
122 // -----------------------
125 /// PointF Constructor
129 /// Creates a PointF from a specified x,y coordinate pair.
132 public PointF (float x, float y)
138 // -----------------------
139 // Public Instance Members
140 // -----------------------
147 /// Indicates if both X and Y are zero.
151 public bool IsEmpty {
153 return ((x == 0.0) && (y == 0.0));
162 /// The X coordinate of the PointF.
179 /// The Y coordinate of the PointF.
196 /// Checks equivalence of this PointF and another object.
199 public override bool Equals (object o)
204 return (this == (PointF) o);
208 /// GetHashCode Method
212 /// Calculates a hashing value.
215 public override int GetHashCode ()
217 return (int) x ^ (int) y;
225 /// Formats the PointF as a string in coordinate notation.
228 public override string ToString ()
230 return String.Format ("{{X={0}, Y={1}}}", x.ToString (CultureInfo.CurrentCulture),
231 y.ToString (CultureInfo.CurrentCulture));
235 public static PointF Add (PointF pt, Size sz)
237 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
240 public static PointF Add (PointF pt, SizeF sz)
242 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
245 public static PointF Subtract (PointF pt, Size sz)
247 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
250 public static PointF Subtract (PointF pt, SizeF sz)
252 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);