2 // System.Drawing.SizeF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System
.Runtime
.InteropServices
;
36 using System
.ComponentModel
;
38 namespace System
.Drawing
44 // Private height and width fields.
47 // -----------------------
48 // Public Shared Members
49 // -----------------------
52 /// Empty Shared Field
56 /// An uninitialized SizeF Structure.
59 public static readonly SizeF Empty
;
66 /// Addition of two SizeF structures.
69 public static SizeF
operator + (SizeF sz1
, SizeF sz2
)
71 return new SizeF (sz1
.Width
+ sz2
.Width
,
72 sz1
.Height
+ sz2
.Height
);
80 /// Compares two SizeF objects. The return value is
81 /// based on the equivalence of the Width and Height
82 /// properties of the two Sizes.
85 public static bool operator == (SizeF sz_a
, SizeF sz_b
)
87 return ((sz_a
.Width
== sz_b
.Width
) &&
88 (sz_a
.Height
== sz_b
.Height
));
92 /// Inequality Operator
96 /// Compares two SizeF objects. The return value is
97 /// based on the equivalence of the Width and Height
98 /// properties of the two Sizes.
101 public static bool operator != (SizeF sz_a
, SizeF sz_b
)
103 return ((sz_a
.Width
!= sz_b
.Width
) ||
104 (sz_a
.Height
!= sz_b
.Height
));
108 /// Subtraction Operator
112 /// Subtracts two SizeF structures.
115 public static SizeF
operator - (SizeF sz1
, SizeF sz2
)
117 return new SizeF (sz1
.Width
- sz2
.Width
,
118 sz1
.Height
- sz2
.Height
);
122 /// SizeF to PointF Conversion
126 /// Returns a PointF based on the dimensions of a given
127 /// SizeF. Requires explicit cast.
130 public static explicit operator PointF (SizeF sz
)
132 return new PointF (sz
.Width
, sz
.Height
);
136 // -----------------------
137 // Public Constructors
138 // -----------------------
141 /// SizeF Constructor
145 /// Creates a SizeF from a PointF value.
148 public SizeF (PointF pt
)
155 /// SizeF Constructor
159 /// Creates a SizeF from an existing SizeF value.
162 public SizeF (SizeF sz
)
169 /// SizeF Constructor
173 /// Creates a SizeF from specified dimensions.
176 public SizeF (float width
, float height
)
182 // -----------------------
183 // Public Instance Members
184 // -----------------------
191 /// Indicates if both Width and Height are zero.
195 public bool IsEmpty
{
197 return ((wd
== 0.0) && (ht
== 0.0));
206 /// The Width coordinate of the SizeF.
223 /// The Height coordinate of the SizeF.
226 public float Height
{
240 /// Checks equivalence of this SizeF and another object.
243 public override bool Equals (object o
)
248 return (this == (SizeF
) o
);
252 /// GetHashCode Method
256 /// Calculates a hashing value.
259 public override int GetHashCode ()
261 return (int) wd ^
(int) ht
;
264 public PointF
ToPointF ()
266 return new PointF (wd
, ht
);
269 public Size
ToSize ()
277 return new Size (w
, h
);
285 /// Formats the SizeF as a string in coordinate notation.
288 public override string ToString ()
290 return String
.Format ("{{Width={0}, Height={1}}}", wd
, ht
);