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