Filter:   InfoImg
download Rectangle.cs
Language: C#
License: GPL
Copyright: (C) 2003 Southern Storm Software, Pty Ltd.
LOC: 326
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
 * Rectangle.cs - Implementation of the "System.Drawing.Rectangle" 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
{

using System.Runtime.InteropServices;
using System.ComponentModel;

#if !ECMA_COMPAT
[Serializable]
[ComVisible(true)]
#endif
#if CONFIG_COMPONENT_MODEL
[TypeConverter("System.Drawing.RectangleConverter")]
#endif
public struct Rectangle
{
	// Internal state.
	private int x;
	private int y;
	private int width;
	private int height;

	// The empty rectangle.
	public static readonly Rectangle Empty = new Rectangle(0, 0, 0, 0);

	// Constructors.
	public Rectangle(Point location, Size size)
			{
				x = location.X;
				y = location.Y;
				width = size.Width;
				height = size.Height;
			}
	public Rectangle(int x, int y, int width, int 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 && y == 0 && width == 0 && height == 0);
				}
			}

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

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

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

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

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

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

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

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

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

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

#if CONFIG_EXTENDED_NUMERICS

	// Convert a RectangleF object into a Rectangle by ceiling conversion.
	public static Rectangle Ceiling(RectangleF value)
			{
				return new Rectangle((int)(Math.Ceiling(value.X)),
								     (int)(Math.Ceiling(value.Y)),
								     (int)(Math.Ceiling(value.Width)),
								     (int)(Math.Ceiling(value.Height)));
			}

#endif

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

	// Determine if one rectangle contains another.
	public bool Contains(Rectangle 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 Rectangle)
				{
					Rectangle other = (Rectangle)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 Rectangle FromLTRB(int left, int top, int right, int bottom)
			{
				return new Rectangle(left, top, right - left, bottom - top);
			}

	// Get a hash code for this object.
	public override int GetHashCode()
			{
				return (x ^ y ^ width ^ height);
			}

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

	// Inflate a specific rectangle without modifying it.
	public static Rectangle Inflate(Rectangle rect, int x, int y)
			{
				return new Rectangle(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(Rectangle rect)
			{
				int 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;
					y = 0;
					width = 0;
					height = 0;
				}
			}

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

	// Determine if this rectangle intersects with another.
	public bool IntersectsWith(Rectangle 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(int x, int y)
			{
				this.x += x;
				this.y += y;
			}
	public void Offset(Point pos)
			{
				this.x += pos.X;
				this.y += pos.Y;
			}

#if CONFIG_EXTENDED_NUMERICS

	// Convert a RectangleF object into a Rectangle by rounding conversion.
	public static Rectangle Round(RectangleF value)
			{
				return new Rectangle((int)(Math.Round(value.X)),
								     (int)(Math.Round(value.Y)),
								     (int)(Math.Round(value.Width)),
								     (int)(Math.Round(value.Height)));
			}

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

#endif

	// Convert a RectangleF object into a Rectangle by truncating conversion.
	public static Rectangle Truncate(RectangleF value)
			{
				return new Rectangle((int)(value.X), (int)(value.Y),
								     (int)(value.Width), (int)(value.Height));
			}

	// Get the union of two rectangles.
	public static Rectangle Union(Rectangle a, Rectangle b)
			{
				int 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 Rectangle(left, top, right - left, bottom - top);
			}

	// Overloaded operators.
	public static bool operator==(Rectangle left, Rectangle right)
			{
				return (left.x == right.x &&
						left.y == right.y &&
						left.width == right.width &&
						left.height == right.height);
			}
	public static bool operator!=(Rectangle left, Rectangle right)
			{
				return (left.x != right.x ||
						left.y != right.y ||
						left.width != right.width ||
						left.height != right.height);
			}

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