**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Drawing / System.Drawing / PointF.cs
blob0e941aa94ad17fde39ec5d84375108dd826b0d10
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 //
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:
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.
34 using System;
35 using System.Runtime.InteropServices;
36 using System.ComponentModel;
38 namespace System.Drawing
40 [Serializable]
41 [ComVisible (true)]
42 public struct PointF
44 // Private x and y coordinate fields.
45 private float cx, cy;
47 // -----------------------
48 // Public Shared Members
49 // -----------------------
51 /// <summary>
52 /// Empty Shared Field
53 /// </summary>
54 ///
55 /// <remarks>
56 /// An uninitialized PointF Structure.
57 /// </remarks>
59 public static readonly PointF Empty;
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>
70 public static PointF operator + (PointF pt, Size sz)
72 return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
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>
85 public static bool operator == (PointF pt_a, PointF pt_b)
87 return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
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>
100 public static bool operator != (PointF pt_a, PointF pt_b)
102 return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
105 /// <summary>
106 /// Subtraction Operator
107 /// </summary>
109 /// <remarks>
110 /// Translates a PointF using the negation of the Width
111 /// and Height properties of the given Size.
112 /// </remarks>
114 public static PointF operator - (PointF pt, Size sz)
116 return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
119 // -----------------------
120 // Public Constructor
121 // -----------------------
123 /// <summary>
124 /// PointF Constructor
125 /// </summary>
127 /// <remarks>
128 /// Creates a PointF from a specified x,y coordinate pair.
129 /// </remarks>
131 public PointF (float x, float y)
133 cx = x;
134 cy = y;
137 // -----------------------
138 // Public Instance Members
139 // -----------------------
141 /// <summary>
142 /// IsEmpty Property
143 /// </summary>
145 /// <remarks>
146 /// Indicates if both X and Y are zero.
147 /// </remarks>
149 [Browsable (false)]
150 public bool IsEmpty {
151 get {
152 return ((cx == 0.0) && (cy == 0.0));
156 /// <summary>
157 /// X Property
158 /// </summary>
160 /// <remarks>
161 /// The X coordinate of the PointF.
162 /// </remarks>
164 public float X {
165 get {
166 return cx;
168 set {
169 cx = value;
173 /// <summary>
174 /// Y Property
175 /// </summary>
177 /// <remarks>
178 /// The Y coordinate of the PointF.
179 /// </remarks>
181 public float Y {
182 get {
183 return cy;
185 set {
186 cy = value;
190 /// <summary>
191 /// Equals Method
192 /// </summary>
194 /// <remarks>
195 /// Checks equivalence of this PointF and another object.
196 /// </remarks>
198 public override bool Equals (object o)
200 if (!(o is PointF))
201 return false;
203 return (this == (PointF) o);
206 /// <summary>
207 /// GetHashCode Method
208 /// </summary>
210 /// <remarks>
211 /// Calculates a hashing value.
212 /// </remarks>
214 public override int GetHashCode ()
216 return (int) cx ^ (int) cy;
219 /// <summary>
220 /// ToString Method
221 /// </summary>
223 /// <remarks>
224 /// Formats the PointF as a string in coordinate notation.
225 /// </remarks>
227 public override string ToString ()
229 return String.Format ("{{X={0}, Y={1}}}", cx, cy);