2001-12-15 Mike Kestner <mkestner@speakeasy.net>
[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 // (C) 2001 Mike Kestner
8 //
9
10 using System;
11
12 namespace System.Drawing {
13         
14         public struct PointF { 
15                 
16                 // Private x and y coordinate fields.
17                 float cx, cy;
18
19                 // -----------------------
20                 // Public Shared Members
21                 // -----------------------
22
23                 /// <summary>
24                 ///     Empty Shared Field
25                 /// </summary>
26                 ///
27                 /// <remarks>
28                 ///     An uninitialized PointF Structure.
29                 /// </remarks>
30                 
31                 public static readonly PointF Empty;
32
33                 /// <summary>
34                 ///     Addition Operator
35                 /// </summary>
36                 ///
37                 /// <remarks>
38                 ///     Translates a PointF using the Width and Height
39                 ///     properties of the given Size.
40                 /// </remarks>
41
42                 public static PointF operator + (PointF pt, Size sz)
43                 {
44                         return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
45                 }
46                 
47                 /// <summary>
48                 ///     Equality Operator
49                 /// </summary>
50                 ///
51                 /// <remarks>
52                 ///     Compares two PointF objects. The return value is
53                 ///     based on the equivalence of the X and Y properties 
54                 ///     of the two points.
55                 /// </remarks>
56
57                 public static bool operator == (PointF pt_a, PointF pt_b)
58                 {
59                         return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
60                 }
61                 
62                 /// <summary>
63                 ///     Inequality Operator
64                 /// </summary>
65                 ///
66                 /// <remarks>
67                 ///     Compares two PointF objects. The return value is
68                 ///     based on the equivalence of the X and Y properties 
69                 ///     of the two points.
70                 /// </remarks>
71
72                 public static bool operator != (PointF pt_a, PointF pt_b)
73                 {
74                         return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
75                 }
76                 
77                 /// <summary>
78                 ///     Subtraction Operator
79                 /// </summary>
80                 ///
81                 /// <remarks>
82                 ///     Translates a PointF using the negation of the Width 
83                 ///     and Height properties of the given Size.
84                 /// </remarks>
85
86                 public static PointF operator - (PointF pt, Size sz)
87                 {
88                         return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
89                 }
90                 
91                 // -----------------------
92                 // Public Constructor
93                 // -----------------------
94
95                 /// <summary>
96                 ///     PointF Constructor
97                 /// </summary>
98                 ///
99                 /// <remarks>
100                 ///     Creates a PointF from a specified x,y coordinate pair.
101                 /// </remarks>
102                 
103                 public PointF (float x, float y)
104                 {
105                         cx = x;
106                         cy = y;
107                 }
108
109                 // -----------------------
110                 // Public Instance Members
111                 // -----------------------
112
113                 /// <summary>
114                 ///     IsEmpty Property
115                 /// </summary>
116                 ///
117                 /// <remarks>
118                 ///     Indicates if both X and Y are zero.
119                 /// </remarks>
120                 
121                 public bool IsEmpty {
122                         get {
123                                 return ((cx == 0.0) && (cy == 0.0));
124                         }
125                 }
126
127                 /// <summary>
128                 ///     X Property
129                 /// </summary>
130                 ///
131                 /// <remarks>
132                 ///     The X coordinate of the PointF.
133                 /// </remarks>
134                 
135                 public float X {
136                         get {
137                                 return cx;
138                         }
139                         set {
140                                 cx = value;
141                         }
142                 }
143
144                 /// <summary>
145                 ///     Y Property
146                 /// </summary>
147                 ///
148                 /// <remarks>
149                 ///     The Y coordinate of the PointF.
150                 /// </remarks>
151                 
152                 public float Y {
153                         get {
154                                 return cy;
155                         }
156                         set {
157                                 cy = value;
158                         }
159                 }
160
161                 /// <summary>
162                 ///     Equals Method
163                 /// </summary>
164                 ///
165                 /// <remarks>
166                 ///     Checks equivalence of this PointF and another object.
167                 /// </remarks>
168                 
169                 public override bool Equals (object o)
170                 {
171                         if (!(o is PointF))
172                                 return false;
173
174                         return (this == (PointF) o);
175                 }
176
177                 /// <summary>
178                 ///     GetHashCode Method
179                 /// </summary>
180                 ///
181                 /// <remarks>
182                 ///     Calculates a hashing value.
183                 /// </remarks>
184                 
185                 public override int GetHashCode ()
186                 {
187                         return (int) cx ^ (int) cy;
188                 }
189
190                 /// <summary>
191                 ///     ToString Method
192                 /// </summary>
193                 ///
194                 /// <remarks>
195                 ///     Formats the PointF as a string in coordinate notation.
196                 /// </remarks>
197                 
198                 public override string ToString ()
199                 {
200                         return String.Format ("[{0},{1}]", cx, cy);
201                 }
202
203         }
204 }