2 // System.Drawing.SizeF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // (C) 2001 Mike Kestner
11 using System.Runtime.InteropServices;
13 namespace System.Drawing {
19 // Private height and width fields.
22 // -----------------------
23 // Public Shared Members
24 // -----------------------
27 /// Empty Shared Field
31 /// An uninitialized SizeF Structure.
34 public static readonly SizeF Empty;
41 /// Addition of two SizeF structures.
44 public static SizeF operator + (SizeF sz1, SizeF sz2)
46 return new SizeF (sz1.Width + sz2.Width,
47 sz1.Height + sz2.Height);
55 /// Compares two SizeF objects. The return value is
56 /// based on the equivalence of the Width and Height
57 /// properties of the two Sizes.
60 public static bool operator == (SizeF sz_a, SizeF sz_b)
62 return ((sz_a.Width == sz_b.Width) &&
63 (sz_a.Height == sz_b.Height));
67 /// Inequality Operator
71 /// Compares two SizeF objects. The return value is
72 /// based on the equivalence of the Width and Height
73 /// properties of the two Sizes.
76 public static bool operator != (SizeF sz_a, SizeF sz_b)
78 return ((sz_a.Width != sz_b.Width) ||
79 (sz_a.Height != sz_b.Height));
83 /// Subtraction Operator
87 /// Subtracts two SizeF structures.
90 public static SizeF operator - (SizeF sz1, SizeF sz2)
92 return new SizeF (sz1.Width - sz2.Width,
93 sz1.Height - sz2.Height);
97 /// SizeF to PointF Conversion
101 /// Returns a PointF based on the dimensions of a given
102 /// SizeF. Requires explicit cast.
105 public static explicit operator PointF (SizeF sz)
107 return new PointF (sz.Width, sz.Height);
111 // -----------------------
112 // Public Constructors
113 // -----------------------
116 /// SizeF Constructor
120 /// Creates a SizeF from a PointF value.
123 public SizeF (PointF pt)
130 /// SizeF Constructor
134 /// Creates a SizeF from an existing SizeF value.
137 public SizeF (SizeF sz)
144 /// SizeF Constructor
148 /// Creates a SizeF from specified dimensions.
151 public SizeF (float width, float height)
157 // -----------------------
158 // Public Instance Members
159 // -----------------------
166 /// Indicates if both Width and Height are zero.
169 public bool IsEmpty {
171 return ((wd == 0.0) && (ht == 0.0));
180 /// The Width coordinate of the SizeF.
197 /// The Height coordinate of the SizeF.
200 public float Height {
214 /// Checks equivalence of this SizeF and another object.
217 public override bool Equals (object o)
222 return (this == (SizeF) o);
226 /// GetHashCode Method
230 /// Calculates a hashing value.
233 public override int GetHashCode ()
235 return (int) wd ^ (int) ht;
243 /// Formats the SizeF as a string in coordinate notation.
246 public override string ToString ()
248 return String.Format ("[{0},{1}]", wd, ht);