2 // System.Drawing.SizeF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // (C) 2001 Mike Kestner
12 namespace System.Drawing {
16 // Private height and width fields.
19 // -----------------------
20 // Public Shared Members
21 // -----------------------
24 /// Empty Shared Field
28 /// An uninitialized SizeF Structure.
31 public static readonly SizeF Empty;
38 /// Addition of two SizeF structures.
41 public static SizeF operator + (SizeF sz1, SizeF sz2)
43 return new SizeF (sz1.Width + sz2.Width,
44 sz1.Height + sz2.Height);
52 /// Compares two SizeF objects. The return value is
53 /// based on the equivalence of the Width and Height
54 /// properties of the two Sizes.
57 public static bool operator == (SizeF sz_a, SizeF sz_b)
59 return ((sz_a.Width == sz_b.Width) &&
60 (sz_a.Height == sz_b.Height));
64 /// Inequality Operator
68 /// Compares two SizeF objects. The return value is
69 /// based on the equivalence of the Width and Height
70 /// properties of the two Sizes.
73 public static bool operator != (SizeF sz_a, SizeF sz_b)
75 return ((sz_a.Width != sz_b.Width) ||
76 (sz_a.Height != sz_b.Height));
80 /// Subtraction Operator
84 /// Subtracts two SizeF structures.
87 public static SizeF operator - (SizeF sz1, SizeF sz2)
89 return new SizeF (sz1.Width - sz2.Width,
90 sz1.Height - sz2.Height);
94 /// SizeF to PointF Conversion
98 /// Returns a PointF based on the dimensions of a given
99 /// SizeF. Requires explicit cast.
102 public static explicit operator PointF (SizeF sz)
104 return new PointF (sz.Width, sz.Height);
108 // -----------------------
109 // Public Constructors
110 // -----------------------
113 /// SizeF Constructor
117 /// Creates a SizeF from a PointF value.
120 public SizeF (PointF pt)
127 /// SizeF Constructor
131 /// Creates a SizeF from an existing SizeF value.
134 public SizeF (SizeF sz)
141 /// SizeF Constructor
145 /// Creates a SizeF from specified dimensions.
148 public SizeF (float width, float height)
154 // -----------------------
155 // Public Instance Members
156 // -----------------------
163 /// Indicates if both Width and Height are zero.
166 public bool IsEmpty {
168 return ((wd == 0.0) && (ht == 0.0));
177 /// The Width coordinate of the SizeF.
194 /// The Height coordinate of the SizeF.
197 public float Height {
211 /// Checks equivalence of this SizeF and another object.
214 public override bool Equals (object o)
219 return (this == (SizeF) o);
223 /// GetHashCode Method
227 /// Calculates a hashing value.
230 public override int GetHashCode ()
232 return (int) wd ^ (int) ht;
240 /// Formats the SizeF as a string in coordinate notation.
243 public override string ToString ()
245 return String.Format ("[{0},{1}]", wd, ht);