Filter:   InfoImg
download RectangleF.cs
Language: C#
License: GPL
Copyright: (C) 2003 Southern Storm Software, Pty Ltd.
LOC: 306
Project Info
DotGNU Portable.NET(dotgnu-pnet)
Server: Savannah GNU
Type: cvs
...net\pnetlib\System.Drawing\
   .cvsignore
   Bitmap.cs
   Brush.cs
   Brushes.cs
   CharacterRange.cs
   Color.cs
   ColorConverter.cs
   ColorTranslator.cs
   ContentAlignment.cs
   Font.cs
   FontConverter.cs
   FontFamily.cs
   FontStyle.cs
   Graphics.cs
   GraphicsUnit.cs
   Icon.cs
   IconConverter.cs
   Image.cs
   ImageAnimator.cs
   ImageConverter.cs
   ImageFormatConverter.cs
   KnownColor.cs
   Makefile.am
   Pen.cs
   Pens.cs
   Point.cs
   PointConverter.cs
   PointF.cs
   Rectangle.cs
   RectangleConverter.cs
   RectangleF.cs
   Region.cs
   RotateFlipType.cs
   S.cs
   Size.cs
   SizeConverter.cs
   SizeF.cs
   SolidBrush.cs
   StringAlignment.cs
   StringDigitSubstitute.cs
   StringFormat.cs
   StringFormatFlags.cs
   StringTrimming.cs
   StringUnit.cs
   System.Drawing.build
   SystemBrushes.cs
   SystemColors.cs
   SystemIcons.cs
   SystemPens.cs
   TextureBrush.cs
   TODOAttribute.cs
   ToolboxBitmapAttribute.cs
   XorBrush.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
 * RectangleF.cs - Implementation of the "System.Drawing.RectangleF" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing
{

#if !ECMA_COMPAT
[Serializable]
#endif
public struct RectangleF
{
	// Internal state.
	private float x;
	private float y;
	private float width;
	private float height;

	// The empty rectangle.
	public static readonly RectangleF Empty
				= new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);

	// Constructors.
	public RectangleF(PointF location, SizeF size)
			{
				x = location.X;
				y = location.Y;
				width = size.Width;
				height = size.Height;
			}
	public RectangleF(float x, float y, float width, float height)
			{
				this.x = x;
				this.y = y;
				this.width = width;
				this.height = height;
			}

	// Determine if this rectangle is empty.
	public bool IsEmpty
			{
				get
				{
					return (x == 0.0f && y == 0.0f &&
							width == 0.0f && height == 0.0f);
				}
			}

	// Get or set the X co-ordinate.
	public float X
			{
				get
				{
					return x;
				}
				set
				{
					x = value;
				}
			}

	// Get or set the Y co-ordinate.
	public float Y
			{
				get
				{
					return y;
				}
				set
				{
					y = value;
				}
			}

	// Get or set the width.
	public float Width
			{
				get
				{
					return width;
				}
				set
				{
					width = value;
				}
			}

	// Get or set the height.
	public float Height
			{
				get
				{
					return height;
				}
				set
				{
					height = value;
				}
			}

	// Get the bottom edge of the rectangle.
	public float Bottom
			{
				get
				{
					return y + height;
				}
			}

	// Get the left edge of the rectangle.
	public float Left
			{
				get
				{
					return x;
				}
			}

	// Get the right edge of the rectangle.
	public float Right
			{
				get
				{
					return x + width;
				}
			}

	// Get the top edge of the rectangle.
	public float Top
			{
				get
				{
					return y;
				}
			}

	// Get or set the location of the top-left corner.
	public PointF Location
			{
				get
				{
					return new PointF(x, y);
				}
				set
				{
					x = value.X;
					y = value.Y;
				}
			}

	// Get or set the size of the rectangle.
	public SizeF Size
			{
				get
				{
					return new SizeF(width, height);
				}
				set
				{
					width = value.Width;
					height = value.Height;
				}
			}

	// Determine if a rectangle contains a point.
	public bool Contains(float x, float y)
			{
				return (x >= this.x && x < (this.x + this.width) &&
				        y >= this.y && y < (this.y + this.height));
			}
	public bool Contains(PointF pt)
			{
				return Contains(pt.X, pt.Y);
			}

	// Determine if one rectangle contains another.
	public bool Contains(RectangleF rect)
			{
				if(rect.x >= this.x &&
				   (rect.x + rect.width) <= (this.x + this.width) &&
				   rect.y >= this.y &&
				   (rect.y + rect.height) <= (this.y + this.height))
				{
					return true;
				}
				else
				{
					return false;
				}
			}

	// Determine if two rectangles are equal.
	public override bool Equals(Object obj)
			{
				if(obj is RectangleF)
				{
					RectangleF other = (RectangleF)obj;
					return (x == other.x && y == other.y &&
					        width == other.width && height == other.height);
				}
				else
				{
					return false;
				}
			}

	// Convert left, top, right, bottom values into a rectangle.
	public static RectangleF FromLTRB
				(float left, float top, float right, float bottom)
			{
				return new RectangleF(left, top, right - left, bottom - top);
			}

	// Get a hash code for this object.
	public override int GetHashCode()
			{
				return base.GetHashCode();
			}

	// Inflate this rectangle.
	public void Inflate(float width, float height)
			{
				this.x -= width;
				this.y -= height;
				this.width += width * 2;
				this.height += height * 2;
			}
	public void Inflate(SizeF size)
			{
				Inflate(size.Width, size.Height);
			}

	// Inflate a specific rectangle without modifying it.
	public static RectangleF Inflate(RectangleF rect, float x, float y)
			{
				return new RectangleF(rect.x - x, rect.y - y,
									  rect.width + x * 2, rect.height + y * 2);
			}

	// Form the intersection of another rectangle with this one.
	public void Intersect(RectangleF rect)
			{
				float left, top, right, bottom;
				left = x;
				if(left < rect.x)
				{
					left = rect.x;
				}
				top = y;
				if(top < rect.y)
				{
					top = rect.y;
				}
				right = x + width;
				if(right > (rect.x + rect.width))
				{
					right = (rect.x + rect.width);
				}
				bottom = y + height;
				if(bottom > (rect.y + rect.height))
				{
					bottom = (rect.y + rect.height);
				}
				if(left < right && top < bottom)
				{
					x = left;
					y = top;
					width = right - left;
					height = bottom - top;
				}
				else
				{
					x = 0.0f;
					y = 0.0f;
					width = 0.0f;
					height = 0.0f;
				}
			}

	// Form the intersection of two rectangles.
	public static RectangleF Intersect(RectangleF a, RectangleF b)
			{
				a.Intersect(b);
				return a;
			}

	// Determine if this rectangle intersects with another.
	public bool IntersectsWith(RectangleF rect)
			{
				return (rect.x < (x + width) &&
				        (rect.x + rect.width) >= x &&
				        rect.y < (y + height) &&
				        (rect.y + rect.height) >= y);
			}

	// Offset this rectangle by a point.
	public void Offset(float x, float y)
			{
				this.x += x;
				this.y += y;
			}
	public void Offset(PointF pos)
			{
				this.x += pos.X;
				this.y += pos.Y;
			}

#if CONFIG_EXTENDED_NUMERICS

	// Convert this object into a string.
	public override String ToString()
			{
				return "{X=" + x.ToString() +
				       ",Y=" + y.ToString() +
					   ",Width=" + width.ToString() +
					   ",Height=" + height.ToString() + "}";
			}

#endif

	// Get the union of two rectangles.
	public static RectangleF Union(RectangleF a, RectangleF b)
			{
				float left, top, right, bottom;
				left = a.x;
				if(left > b.x)
				{
					left = b.x;
				}
				top = a.y;
				if(top > b.y)
				{
					top = b.y;
				}
				right = a.x + a.width;
				if(right < (b.x + b.width))
				{
					right = b.x + b.width;
				}
				bottom = a.y + a.height;
				if(bottom < (b.y + b.height))
				{
					bottom = b.y + b.height;
				}
				return new RectangleF(left, top, right - left, bottom - top);
			}

	// Overloaded operators.
	public static bool operator==(RectangleF left, RectangleF right)
			{
				return (left.x == right.x &&
						left.y == right.y &&
						left.width == right.width &&
						left.height == right.height);
			}
	public static bool operator!=(RectangleF left, RectangleF right)
			{
				return (left.x != right.x ||
						left.y != right.y ||
						left.width != right.width ||
						left.height != right.height);
			}
	public static implicit operator RectangleF(Rectangle r)
			{
				return new RectangleF(r.X, r.Y, r.Width, r.Height);
			}

}; // struct RectangleF
		
}; // namespace System.Drawing