2 // System.Drawing.Point.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // (C) 2001 Mike Kestner
12 namespace System.Drawing {
17 // Private x and y coordinate fields.
20 // -----------------------
21 // Public Shared Members
22 // -----------------------
25 /// Empty Shared Field
29 /// An uninitialized Point Structure.
32 public static readonly Point Empty;
35 /// Ceiling Shared Method
39 /// Produces a Point structure from a PointF structure by
40 /// taking the ceiling of the X and Y properties.
43 public static Point Ceiling (PointF value)
47 x = (int) Math.Ceiling (value.X);
48 y = (int) Math.Ceiling (value.Y);
51 return new Point (x, y);
55 /// Round Shared Method
59 /// Produces a Point structure from a PointF structure by
60 /// rounding the X and Y properties.
63 public static Point Round (PointF value)
67 x = (int) Math.Round (value.X);
68 y = (int) Math.Round (value.Y);
71 return new Point (x, y);
75 /// Truncate Shared Method
79 /// Produces a Point structure from a PointF structure by
80 /// truncating the X and Y properties.
83 // LAMESPEC: Should this be floor, or a pure cast to int?
85 public static Point Truncate (PointF value)
93 return new Point (x, y);
101 /// Translates a Point using the Width and Height
102 /// properties of the given <typeref>Size</typeref>.
105 public static Point operator + (Point pt, Size sz)
107 return new Point (pt.X + sz.Width, pt.Y + sz.Height);
111 /// Equality Operator
115 /// Compares two Point objects. The return value is
116 /// based on the equivalence of the X and Y properties
117 /// of the two points.
120 public static bool operator == (Point pt_a, Point pt_b)
122 return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
126 /// Inequality Operator
130 /// Compares two Point objects. The return value is
131 /// based on the equivalence of the X and Y properties
132 /// of the two points.
135 public static bool operator != (Point pt_a, Point pt_b)
137 return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
141 /// Subtraction Operator
145 /// Translates a Point using the negation of the Width
146 /// and Height properties of the given Size.
149 public static Point operator - (Point pt, Size sz)
151 return new Point (pt.X - sz.Width, pt.Y - sz.Height);
155 /// Point to Size Conversion
159 /// Returns a Size based on the Coordinates of a given
160 /// Point. Requires explicit cast.
163 public static explicit operator Size (Point pt)
165 return new Size (pt.X, pt.Y);
169 /// Point to PointF Conversion
173 /// Creates a PointF based on the coordinates of a given
174 /// Point. No explicit cast is required.
177 public static implicit operator PointF (Point pt)
179 return new PointF (pt.X, pt.Y);
183 // -----------------------
184 // Public Constructors
185 // -----------------------
188 /// Point Constructor
192 /// Creates a Point from an integer which holds the X
193 /// coordinate in the high order 16 bits and the Y
194 /// coordinate in the low order 16 bits.
197 public Point (int dw)
204 /// Point Constructor
208 /// Creates a Point from a Size value.
211 public Point (Size sz)
218 /// Point Constructor
222 /// Creates a Point from a specified x,y coordinate pair.
225 public Point (int x, int y)
231 // -----------------------
232 // Public Instance Members
233 // -----------------------
240 /// Indicates if both X and Y are zero.
243 public bool IsEmpty {
245 return ((x == 0) && (y == 0));
254 /// The X coordinate of the Point.
271 /// The Y coordinate of the Point.
288 /// Checks equivalence of this Point and another object.
291 public override bool Equals (object o)
296 return (this == (Point) o);
300 /// GetHashCode Method
304 /// Calculates a hashing value.
307 public override int GetHashCode ()
317 /// Moves the Point a specified distance.
320 public void Offset (int dx, int dy)
331 /// Formats the Point as a string in coordinate notation.
334 public override string ToString ()
336 return String.Format ("[{0},{1}]", x, y);