// // System.Drawing.PointF.cs // // Author: // Mike Kestner (mkestner@speakeasy.net) // // (C) Ximian, Inc. http://www.ximian.com // using System; namespace System.Drawing { public struct PointF { // Private x and y coordinate fields. float cx, cy; // ----------------------- // Public Shared Members // ----------------------- /// /// Empty Shared Field /// /// /// /// An uninitialized PointF Structure. /// public static readonly PointF Empty; /// /// Addition Operator /// /// /// /// Translates a PointF using the Width and Height /// properties of the given Size. /// public static PointF operator + (PointF pt, Size sz) { return new PointF (pt.X + sz.Width, pt.Y + sz.Height); } /// /// Equality Operator /// /// /// /// Compares two PointF objects. The return value is /// based on the equivalence of the X and Y properties /// of the two points. /// public static bool operator == (PointF pt_a, PointF pt_b) { return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y)); } /// /// Inequality Operator /// /// /// /// Compares two PointF objects. The return value is /// based on the equivalence of the X and Y properties /// of the two points. /// public static bool operator != (PointF pt_a, PointF pt_b) { return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y)); } /// /// Subtraction Operator /// /// /// /// Translates a PointF using the negation of the Width /// and Height properties of the given Size. /// public static PointF operator - (PointF pt, Size sz) { return new PointF (pt.X - sz.Width, pt.Y - sz.Height); } // ----------------------- // Public Constructor // ----------------------- /// /// PointF Constructor /// /// /// /// Creates a PointF from a specified x,y coordinate pair. /// public PointF (float x, float y) { cx = x; cy = y; } // ----------------------- // Public Instance Members // ----------------------- /// /// IsEmpty Property /// /// /// /// Indicates if both X and Y are zero. /// public bool IsEmpty { get { return ((cx == 0.0) && (cy == 0.0)); } } /// /// X Property /// /// /// /// The X coordinate of the PointF. /// public float X { get { return cx; } set { cx = value; } } /// /// Y Property /// /// /// /// The Y coordinate of the PointF. /// public float Y { get { return cy; } set { cy = value; } } /// /// Equals Method /// /// /// /// Checks equivalence of this PointF and another object. /// public override bool Equals (object o) { if (!(o is PointF)) return false; return (this == (PointF) o); } /// /// GetHashCode Method /// /// /// /// Calculates a hashing value. /// public override int GetHashCode () { return (int) cx ^ (int) cy; } /// /// ToString Method /// /// /// /// Formats the PointF as a string in coordinate notation. /// public override string ToString () { return String.Format ("[{0},{1}]", cx, cy); } } }