2 // Region class testing unit
5 // Jordi Mas, jordi@ximian.com
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2004-2008 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Drawing.Imaging;
33 using System.Drawing.Drawing2D;
34 using System.Security.Permissions;
35 using NUnit.Framework;
37 namespace MonoTests.System.Drawing
41 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
42 public class TestRegion
45 public static void DumpRegion (Region rgn)
47 Matrix matrix = new Matrix ();
48 RectangleF [] rects = rgn.GetRegionScans (matrix);
50 for (int i = 0; i < rects.Length; i++)
51 Console.WriteLine ( rects[i]);
54 private Bitmap bitmap;
55 private Graphics graphic;
58 public void FixtureSetUp ()
60 bitmap = new Bitmap (10, 10);
61 graphic = Graphics.FromImage (bitmap);
65 public void TestBounds()
67 Bitmap bmp = new Bitmap (600, 800);
68 Graphics dc = Graphics.FromImage (bmp);
69 Rectangle rect1, rect2;
73 rect1 = new Rectangle (500, 30, 60, 80);
74 rect2 = new Rectangle (520, 40, 60, 80);
75 rgn1 = new Region(rect1);
76 rgn2 = new Region(rect2);
79 bounds = rgn1.GetBounds (dc);
81 Assert.AreEqual (500, bounds.X);
82 Assert.AreEqual (30, bounds.Y);
83 Assert.AreEqual (80, bounds.Width);
84 Assert.AreEqual (90, bounds.Height);
88 public void TestCloneAndEquals()
90 Bitmap bmp = new Bitmap (600, 800);
91 Graphics dc = Graphics.FromImage (bmp);
92 Rectangle rect1, rect2;
96 Matrix matrix = new Matrix ();
98 rect1 = new Rectangle (500, 30, 60, 80);
99 rect2 = new Rectangle (520, 40, 60, 80);
100 rgn1 = new Region (rect1);
102 rgn2 = rgn1.Clone ();
104 rects = rgn1.GetRegionScans (matrix);
105 rects2 = rgn2.GetRegionScans (matrix);
107 Assert.AreEqual (rects.Length, rects2.Length);
109 for (int i = 0; i < rects.Length; i++) {
111 Assert.AreEqual (rects[i].X, rects[i].X);
112 Assert.AreEqual (rects[i].Y, rects[i].Y);
113 Assert.AreEqual (rects[i].Width, rects[i].Width);
114 Assert.AreEqual (rects[i].Height, rects[i].Height);
117 Assert.AreEqual (true, rgn1.Equals (rgn2, dc));
120 /*Tests infinite, empty, etc*/
122 public void TestInfiniteAndEmpty()
124 Bitmap bmp = new Bitmap (600, 800);
125 Graphics dc = Graphics.FromImage (bmp);
126 Rectangle rect1, rect2;
129 Matrix matrix = new Matrix ();
131 rect1 = new Rectangle (500, 30, 60, 80);
132 rect2 = new Rectangle (520, 40, 60, 80);
133 rgn1 = new Region (rect1);
136 Assert.AreEqual (false, rgn1.IsEmpty (dc));
137 Assert.AreEqual (false, rgn1.IsInfinite (dc));
140 Assert.AreEqual (true, rgn1.IsEmpty (dc));
142 rgn1 = new Region (rect1);
144 rgn1.MakeInfinite ();
145 rects = rgn1.GetRegionScans (matrix);
147 Assert.AreEqual (1, rects.Length);
148 Assert.AreEqual (-4194304, rects[0].X);
149 Assert.AreEqual (-4194304, rects[0].Y);
150 Assert.AreEqual (8388608, rects[0].Width);
151 Assert.AreEqual (8388608, rects[0].Height);
152 Assert.AreEqual (true, rgn1.IsInfinite (dc));
157 public void TestUnionGroup1 ()
159 Bitmap bmp = new Bitmap (600, 800);
160 Graphics dc = Graphics.FromImage (bmp);
161 Matrix matrix = new Matrix ();
162 Rectangle rect1, rect2, rect3, rect4;
163 Region rgn1, rgn2, rgn3, rgn4;
166 rect1 = new Rectangle (500, 30, 60, 80);
167 rect2 = new Rectangle (520, 40, 60, 80);
168 rgn1 = new Region(rect1);
169 rgn2 = new Region(rect2);
171 rects = rgn1.GetRegionScans (matrix);
173 Assert.AreEqual (3, rects.Length);
174 Assert.AreEqual (500, rects[0].X);
175 Assert.AreEqual (30, rects[0].Y);
176 Assert.AreEqual (60, rects[0].Width);
177 Assert.AreEqual (10, rects[0].Height);
179 Assert.AreEqual (500, rects[1].X);
180 Assert.AreEqual (40, rects[1].Y);
181 Assert.AreEqual (80, rects[1].Width);
182 Assert.AreEqual (70, rects[1].Height);
184 Assert.AreEqual (520, rects[2].X);
185 Assert.AreEqual (110, rects[2].Y);
186 Assert.AreEqual (60, rects[2].Width);
187 Assert.AreEqual (10, rects[2].Height);
189 rect1 = new Rectangle (20, 180, 40, 50);
190 rect2 = new Rectangle (50, 190, 40, 50);
191 rect3 = new Rectangle (70, 210, 30, 50);
192 rgn1 = new Region (rect1);
193 rgn2 = new Region (rect2);
194 rgn3 = new Region (rect3);
198 rects = rgn1.GetRegionScans (matrix);
199 Assert.AreEqual (5, rects.Length);
201 Assert.AreEqual (20, rects[0].X);
202 Assert.AreEqual (180, rects[0].Y);
203 Assert.AreEqual (40, rects[0].Width);
204 Assert.AreEqual (10, rects[0].Height);
206 Assert.AreEqual (20, rects[1].X);
207 Assert.AreEqual (190, rects[1].Y);
208 Assert.AreEqual (70, rects[1].Width);
209 Assert.AreEqual (20, rects[1].Height);
211 Assert.AreEqual (20, rects[2].X);
212 Assert.AreEqual (210, rects[2].Y);
213 Assert.AreEqual (80, rects[2].Width);
214 Assert.AreEqual (20, rects[2].Height);
216 Assert.AreEqual (50, rects[3].X);
217 Assert.AreEqual (230, rects[3].Y);
218 Assert.AreEqual (50, rects[3].Width);
219 Assert.AreEqual (10, rects[3].Height);
221 Assert.AreEqual (70, rects[4].X);
222 Assert.AreEqual (240, rects[4].Y);
223 Assert.AreEqual (30, rects[4].Width);
224 Assert.AreEqual (20, rects[4].Height);
226 rect1 = new Rectangle (20, 330, 40, 50);
227 rect2 = new Rectangle (50, 340, 40, 50);
228 rect3 = new Rectangle (70, 360, 30, 50);
229 rect4 = new Rectangle (80, 400, 30, 10);
230 rgn1 = new Region (rect1);
231 rgn2 = new Region (rect2);
232 rgn3 = new Region (rect3);
233 rgn4 = new Region (rect4);
239 rects = rgn1.GetRegionScans (matrix);
241 Assert.AreEqual (6, rects.Length);
243 Assert.AreEqual (20, rects[0].X);
244 Assert.AreEqual (330, rects[0].Y);
245 Assert.AreEqual (40, rects[0].Width);
246 Assert.AreEqual (10, rects[0].Height);
248 Assert.AreEqual (20, rects[1].X);
249 Assert.AreEqual (340, rects[1].Y);
250 Assert.AreEqual (70, rects[1].Width);
251 Assert.AreEqual (20, rects[1].Height);
253 Assert.AreEqual (20, rects[2].X);
254 Assert.AreEqual (360, rects[2].Y);
255 Assert.AreEqual (80, rects[2].Width);
256 Assert.AreEqual (20, rects[2].Height);
258 Assert.AreEqual (50, rects[3].X);
259 Assert.AreEqual (380, rects[3].Y);
260 Assert.AreEqual (50, rects[3].Width);
261 Assert.AreEqual (10, rects[3].Height);
263 Assert.AreEqual (70, rects[4].X);
264 Assert.AreEqual (390, rects[4].Y);
265 Assert.AreEqual (30, rects[4].Width);
266 Assert.AreEqual (10, rects[4].Height);
268 Assert.AreEqual (70, rects[5].X);
269 Assert.AreEqual (400, rects[5].Y);
270 Assert.AreEqual (40, rects[5].Width);
271 Assert.AreEqual (10, rects[5].Height);
273 rect1 = new Rectangle (10, 20, 50, 50);
274 rect2 = new Rectangle (100, 100, 60, 60);
275 rect3 = new Rectangle (200, 200, 80, 80);
277 rgn1 = new Region (rect1);
281 rects = rgn1.GetRegionScans (matrix);
283 Assert.AreEqual (3, rects.Length);
285 Assert.AreEqual (10, rects[0].X);
286 Assert.AreEqual (20, rects[0].Y);
287 Assert.AreEqual (50, rects[0].Width);
288 Assert.AreEqual (50, rects[0].Height);
290 Assert.AreEqual (100, rects[1].X);
291 Assert.AreEqual (100, rects[1].Y);
292 Assert.AreEqual (60, rects[1].Width);
293 Assert.AreEqual (60, rects[1].Height);
295 Assert.AreEqual (200, rects[2].X);
296 Assert.AreEqual (200, rects[2].Y);
297 Assert.AreEqual (80, rects[2].Width);
298 Assert.AreEqual (80, rects[2].Height);
301 void AssertEqualRectangles (RectangleF rect1, RectangleF rect2, string text)
303 Assert.AreEqual (rect1.X, rect2.X, text + ".X");
304 Assert.AreEqual (rect1.Y, rect2.Y, text + ".Y");
305 Assert.AreEqual (rect1.Width, rect2.Width, text + ".Width");
306 Assert.AreEqual (rect1.Height, rect2.Height, text + ".Height");
310 public void TestUnionGroup2 ()
313 Region r1 = new Region ();
314 Rectangle rect2 = Rectangle.Empty;
315 Rectangle rect1 = Rectangle.Empty;
316 Rectangle rect3 = Rectangle.Empty;
317 Rectangle rect4 = Rectangle.Empty;
319 { // TEST1: Not intersecting rects. Union just adds them
321 rect1 = new Rectangle (20, 20, 20, 20);
322 rect2 = new Rectangle (20, 80, 20, 10);
323 rect3 = new Rectangle (60, 60, 30, 10);
325 r1 = new Region (rect1);
329 rects = r1.GetRegionScans (new Matrix ());
330 Assert.AreEqual (3, rects.Length, "TUG1Test1");
331 AssertEqualRectangles (new RectangleF (20, 20, 20, 20), rects[0], "TUG1Test2");
332 AssertEqualRectangles (new RectangleF (60, 60, 30, 10), rects[1], "TUG1Test3");
333 AssertEqualRectangles (new RectangleF (20, 80, 20, 10), rects[2], "TUG1Test4");
336 { // TEST2: Intersecting from the right
348 rect1 = new Rectangle (10, 10, 100, 100);
349 rect2 = new Rectangle (40, 60, 100, 20);
350 r1 = new Region (rect1);
353 rects = r1.GetRegionScans (new Matrix ());
354 Assert.AreEqual (3, rects.Length, "TUG2Test1");
355 AssertEqualRectangles (new RectangleF (10, 10, 100, 50), rects[0], "TUG2Test2");
356 AssertEqualRectangles (new RectangleF (10, 60, 130, 20), rects[1], "TUG2Test3");
357 AssertEqualRectangles (new RectangleF (10, 80, 100, 30), rects[2], "TUG2Test4");
360 { // TEST3: Intersecting from the right
372 rect1 = new Rectangle (70, 10, 100, 100);
373 rect2 = new Rectangle (40, 60, 100, 20);
375 r1 = new Region (rect1);
378 rects = r1.GetRegionScans (new Matrix ());
379 Assert.AreEqual (3, rects.Length, "TUG3Test1");
380 AssertEqualRectangles (new RectangleF (70, 10, 100, 50), rects[0], "TUG3Test2");
381 AssertEqualRectangles (new RectangleF (40, 60, 130, 20), rects[1], "TUG3Test3");
382 AssertEqualRectangles (new RectangleF (70, 80, 100, 30), rects[2], "TUG3Test4");
385 { // TEST4: Intersecting from the top
398 rect1 = new Rectangle (40, 100, 100, 100);
399 rect2 = new Rectangle (70, 80, 50, 40);
400 r1 = new Region (rect1);
403 rects = r1.GetRegionScans (new Matrix ());
404 Assert.AreEqual (2, rects.Length, "TUG4Test1");
405 AssertEqualRectangles (new RectangleF (70, 80, 50, 20), rects[0], "TUG4Test2");
406 AssertEqualRectangles (new RectangleF (40, 100, 100, 100), rects[1], "TUG4Test3");
409 { // TEST5: Intersecting from the bottom
422 rect1 = new Rectangle (40, 10, 100, 100);
423 rect2 = new Rectangle (70, 80, 50, 40);
425 r1 = new Region (rect1);
428 rects = r1.GetRegionScans (new Matrix ());
429 Assert.AreEqual (2, rects.Length, "TUG5Test1");
430 AssertEqualRectangles (new RectangleF (40, 10, 100, 100), rects[0], "TUG5Test2");
431 AssertEqualRectangles (new RectangleF (70, 110, 50, 10), rects[1], "TUG5Test3");
434 { // TEST6: Multiple regions, two separted by zero pixels
436 rect1 = new Rectangle (30, 30, 80, 80);
437 rect2 = new Rectangle (45, 45, 200, 200);
438 rect3 = new Rectangle (160, 260, 10, 10);
439 rect4 = new Rectangle (170, 260, 10, 10);
441 r1 = new Region (rect1);
446 rects = r1.GetRegionScans (new Matrix ());
447 Assert.AreEqual (4, rects.Length, "TUG6Test1");
448 AssertEqualRectangles (new RectangleF (30, 30, 80, 15), rects[0], "TUG6Test2");
449 AssertEqualRectangles (new RectangleF (30, 45, 215, 65), rects[1], "TUG6Test3");
450 AssertEqualRectangles (new RectangleF (45, 110, 200, 135), rects[2], "TUG6Test4");
451 AssertEqualRectangles (new RectangleF (160, 260, 20, 10), rects[3], "TUG6Test5");
457 public void TestComplementGroup1 ()
460 Region r1 = new Region ();
461 Region r2 = new Region ();
462 Rectangle rect1 = Rectangle.Empty;
463 Rectangle rect2 = Rectangle.Empty;
464 Rectangle rect3 = Rectangle.Empty;
465 Rectangle rect4 = Rectangle.Empty;
466 Rectangle rect5 = Rectangle.Empty;
467 Rectangle rect6 = Rectangle.Empty;
468 Rectangle rect7 = Rectangle.Empty;
473 rect1 = new Rectangle (20, 20, 20, 20);
474 rect2 = new Rectangle (20, 80, 20, 10);
475 rect3 = new Rectangle (60, 60, 30, 10);
477 r1 = new Region (rect1);
478 r2 = new Region (rect2);
482 rects = r1.GetRegionScans (new Matrix ());
483 Assert.AreEqual (2, rects.Length, "TCG1Test1");
484 AssertEqualRectangles (new RectangleF (60, 60, 30, 10), rects[0], "TCG1Test2");
485 AssertEqualRectangles (new RectangleF (20, 80, 20, 10), rects[1], "TCG1Test3");
491 rect1 = new Rectangle (10, 10, 100, 100);
492 rect2 = new Rectangle (40, 60, 100, 20);
494 r1 = new Region (rect1);
495 r1.Complement (rect2);
497 rects = r1.GetRegionScans (new Matrix ());
498 Assert.AreEqual (1, rects.Length, "TCG2Test1");
499 AssertEqualRectangles (new RectangleF (110, 60, 30, 20), rects[0], "TCG2Test2");
504 rect1 = new Rectangle (70, 10, 100, 100);
505 rect2 = new Rectangle (40, 60, 100, 20);
507 r1 = new Region (rect1);
508 r1.Complement (rect2);
510 rects = r1.GetRegionScans (new Matrix ());
511 Assert.AreEqual (1, rects.Length, "TCG3Test1");
512 AssertEqualRectangles (new RectangleF (40, 60, 30, 20), rects[0], "TCG3Test2");
517 rect1 = new Rectangle (40, 100, 100, 100);
518 rect2 = new Rectangle (70, 80, 50, 40);
520 r1 = new Region (rect1);
521 r1.Complement (rect2);
523 rects = r1.GetRegionScans (new Matrix ());
524 Assert.AreEqual (1, rects.Length, "TCG4Test1");
525 AssertEqualRectangles (new RectangleF (70, 80, 50, 20), rects[0], "TCG4Test2");
530 rect1 = new Rectangle (40, 10, 100, 100);
531 rect2 = new Rectangle (70, 80, 50, 40);
533 r1 = new Region (rect1);
534 r1.Complement (rect2);
536 rects = r1.GetRegionScans (new Matrix ());
537 Assert.AreEqual (1, rects.Length, "TCG5Test1");
538 AssertEqualRectangles (new RectangleF (70, 110, 50, 10), rects[0], "TCG5Test2");
541 { // TEST6: Multiple regions
543 rect1 = new Rectangle (30, 30, 80, 80);
544 rect2 = new Rectangle (45, 45, 200, 200);
545 rect3 = new Rectangle (160, 260, 10, 10);
546 rect4 = new Rectangle (170, 260, 10, 10);
548 r1 = new Region (rect1);
549 r1.Complement (rect2);
550 r1.Complement (rect3);
551 r1.Complement (rect4);
553 rects = r1.GetRegionScans (new Matrix ());
554 Assert.AreEqual (1, rects.Length, "TCG6Test1");
555 AssertEqualRectangles (new RectangleF (170, 260, 10, 10), rects[0], "TCG6Test2");
561 public void TestComplementGroup2 ()
564 Bitmap bmp = new Bitmap (600, 800);
565 Graphics dc = Graphics.FromImage (bmp);
566 Matrix matrix = new Matrix ();
567 Rectangle rect1, rect2;
571 rect1 = new Rectangle (20, 30, 60, 80);
572 rect2 = new Rectangle (50, 40, 60, 80);
573 rgn1 = new Region (rect1);
574 rgn2 = new Region (rect2);
575 dc.DrawRectangle (Pens.Green, rect1);
576 dc.DrawRectangle (Pens.Red, rect2);
577 rgn1.Complement (rgn2);
578 dc.FillRegion (Brushes.Blue, rgn1);
579 dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
581 rects = rgn1.GetRegionScans (matrix);
583 Assert.AreEqual (2, rects.Length);
585 Assert.AreEqual (80, rects[0].X);
586 Assert.AreEqual (40, rects[0].Y);
587 Assert.AreEqual (30, rects[0].Width);
588 Assert.AreEqual (70, rects[0].Height);
590 Assert.AreEqual (50, rects[1].X);
591 Assert.AreEqual (110, rects[1].Y);
592 Assert.AreEqual (60, rects[1].Width);
593 Assert.AreEqual (10, rects[1].Height);
599 public void TestExcludeGroup1 ()
602 Region r1 = new Region ();
603 Region r2 = new Region ();
604 Rectangle rect1 = Rectangle.Empty;
605 Rectangle rect2 = Rectangle.Empty;
606 Rectangle rect3 = Rectangle.Empty;
607 Rectangle rect4 = Rectangle.Empty;
608 Rectangle rect5 = Rectangle.Empty;
609 Rectangle rect6 = Rectangle.Empty;
610 Rectangle rect7 = Rectangle.Empty;
613 { // TEST1: Not intersecting rects. Exclude just adds them
615 rect1 = new Rectangle (20, 20, 20, 20);
616 rect2 = new Rectangle (20, 80, 20, 10);
617 rect3 = new Rectangle (60, 60, 30, 10);
619 r1 = new Region (rect1);
620 r2 = new Region (rect2);
624 rects = r1.GetRegionScans (new Matrix ());
625 Assert.AreEqual (1, rects.Length, "TEG1Test1");
626 AssertEqualRectangles (new RectangleF (20, 20, 20, 20), rects[0], "TEG1Test2");
629 { // TEST2: Excluding from the right
641 rect1 = new Rectangle (10, 10, 100, 100);
642 rect2 = new Rectangle (40, 60, 100, 20);
643 r1 = new Region (rect1);
646 rects = r1.GetRegionScans (new Matrix ());
647 Assert.AreEqual (3, rects.Length, "TEG2Test1");
648 AssertEqualRectangles (new RectangleF (10, 10, 100, 50), rects[0], "TEG2Test2");
649 AssertEqualRectangles (new RectangleF (10, 60, 30, 20), rects[1], "TEG2Test3");
650 AssertEqualRectangles (new RectangleF (10, 80, 100, 30), rects[2], "TEG2Test4");
654 { // TEST3: Intersecting from the right
666 rect1 = new Rectangle (70, 10, 100, 100);
667 rect2 = new Rectangle (40, 60, 100, 20);
669 r1 = new Region (rect1);
672 rects = r1.GetRegionScans (new Matrix ());
673 Assert.AreEqual (3, rects.Length, "TEG3Test1");
674 AssertEqualRectangles (new RectangleF (70, 10, 100, 50), rects[0], "TEG3Test2");
675 AssertEqualRectangles (new RectangleF (140, 60, 30, 20), rects[1], "TEG3Test3");
676 AssertEqualRectangles (new RectangleF (70, 80, 100, 30), rects[2], "TEG3Test4");
680 { // TEST4: Intersecting from the top
693 rect1 = new Rectangle (40, 100, 100, 100);
694 rect2 = new Rectangle (70, 80, 50, 40);
696 r1 = new Region (rect1);
699 rects = r1.GetRegionScans (new Matrix ());
700 Assert.AreEqual (3, rects.Length, "TEG4Test1");
701 AssertEqualRectangles (new RectangleF (40, 100, 30, 20), rects[0], "TEG4Test2");
702 AssertEqualRectangles (new RectangleF (120, 100, 20, 20), rects[1], "TEG4Test3");
703 AssertEqualRectangles (new RectangleF (40, 120, 100, 80), rects[2], "TEG4Test4");
707 { // TEST5: Intersecting from the bottom
720 rect1 = new Rectangle (40, 10, 100, 100);
721 rect2 = new Rectangle (70, 80, 50, 40);
723 r1 = new Region (rect1);
726 rects = r1.GetRegionScans (new Matrix ());
727 Assert.AreEqual (3, rects.Length, "TEG5Test1");
728 AssertEqualRectangles (new RectangleF (40, 10, 100, 70), rects[0], "TEG5Test2");
729 AssertEqualRectangles (new RectangleF (40, 80, 30, 30), rects[1], "TEG5Test3");
730 AssertEqualRectangles (new RectangleF (120, 80, 20, 30), rects[2], "TEG5Test4");
734 { // TEST6: Multiple regions
736 rect1 = new Rectangle (30, 30, 80, 80);
737 rect2 = new Rectangle (45, 45, 200, 200);
738 rect3 = new Rectangle (160, 260, 10, 10);
739 rect4 = new Rectangle (170, 260, 10, 10);
741 r1 = new Region (rect1);
746 rects = r1.GetRegionScans (new Matrix ());
747 Assert.AreEqual (2, rects.Length, "TEG6Test1");
748 AssertEqualRectangles (new RectangleF (30, 30, 80, 15), rects[0], "TEG6Test2");
749 AssertEqualRectangles (new RectangleF (30, 45, 15, 65), rects[1], "TEG6Test3");
753 { // TEST7: Intersecting from the top with a larger rect
766 rect1 = new Rectangle (50, 100, 100, 100);
767 rect2 = new Rectangle (30, 70, 150, 40);
769 r1 = new Region (rect1);
772 rects = r1.GetRegionScans (new Matrix ());
773 Assert.AreEqual (1, rects.Length, "TEG7Test1");
774 AssertEqualRectangles (new RectangleF (50, 110, 100, 90), rects[0], "TEG7Test2");
777 { // TEST8: Intersecting from the right with a larger rect
792 rect1 = new Rectangle (70, 60, 100, 70);
793 rect2 = new Rectangle (40, 10, 100, 150);
795 r1 = new Region (rect1);
798 rects = r1.GetRegionScans (new Matrix ());
799 Assert.AreEqual (1, rects.Length, "TEG8Test1");
800 AssertEqualRectangles (new RectangleF (140, 60, 30, 70), rects[0], "TEG8Test2");
804 { // TEST9: Intersecting from the left with a larger rect
821 rect1 = new Rectangle (70, 60, 100, 70);
822 rect2 = new Rectangle (100, 10, 100, 150);
824 r1 = new Region (rect1);
827 rects = r1.GetRegionScans (new Matrix ());
828 Assert.AreEqual (1, rects.Length, "TEG9Test1");
829 AssertEqualRectangles (new RectangleF (70, 60, 30, 70), rects[0], "TEG9Test2");
833 { // TEST10: Intersecting from the bottom with a larger rect
840 * --------------------
843 * |------------------|
847 rect1 = new Rectangle (20, 20, 100, 100);
848 rect2 = new Rectangle (10, 80, 140, 150);
850 r1 = new Region (rect1);
853 rects = r1.GetRegionScans (new Matrix ());
854 Assert.AreEqual (1, rects.Length, "TEG10Test1");
855 AssertEqualRectangles (new RectangleF (20, 20, 100, 60), rects[0], "TEG10Test2");
862 public void TestExcludeGroup2 ()
864 Bitmap bmp = new Bitmap (600, 800);
865 Graphics dc = Graphics.FromImage (bmp);
866 Matrix matrix = new Matrix ();
867 Rectangle rect1, rect2;
871 rect1 = new Rectangle (130, 30, 60, 80);
872 rect2 = new Rectangle (170, 40, 60, 80);
873 rgn1 = new Region (rect1);
874 rgn1.Exclude (rect2);
875 rects = rgn1.GetRegionScans (matrix);
877 Assert.AreEqual (2, rects.Length);
879 Assert.AreEqual (130, rects[0].X);
880 Assert.AreEqual (30, rects[0].Y);
881 Assert.AreEqual (60, rects[0].Width);
882 Assert.AreEqual (10, rects[0].Height);
884 Assert.AreEqual (130, rects[1].X);
885 Assert.AreEqual (40, rects[1].Y);
886 Assert.AreEqual (40, rects[1].Width);
887 Assert.AreEqual (70, rects[1].Height);
891 public void ExcludeBug402613 ()
893 Region r = new Region();
895 r.Exclude (new Rectangle (387,292,189,133));
896 r.Exclude (new Rectangle (387,66,189,133));
897 Assert.IsTrue (r.IsVisible (new Rectangle (66,292,189,133)));
901 public void TestIntersect()
905 Bitmap bmp = new Bitmap (600, 800);
906 Graphics dc = Graphics.FromImage (bmp);
907 Matrix matrix = new Matrix ();
909 RectangleF rect3, rect4;
912 /* Two simple areas */
913 Rectangle rect1 = new Rectangle (260, 30, 60, 80);
914 Rectangle rect2 = new Rectangle (290, 40, 60, 80);
915 Region rgn1 = new Region (rect1);
916 Region rgn2 = new Region (rect2);
917 rgn1.Intersect (rgn2);
919 rects = rgn1.GetRegionScans (matrix);
920 Assert.AreEqual (1, rects.Length);
922 Assert.AreEqual (290, rects[0].X);
923 Assert.AreEqual (40, rects[0].Y);
924 Assert.AreEqual (30, rects[0].Width);
925 Assert.AreEqual (70, rects[0].Height);
928 rect1 = new Rectangle (20, 330, 40, 50);
929 rect2 = new Rectangle (50, 340, 40, 50);
930 rect3 = new Rectangle (70, 360, 30, 50);
931 rect4 = new Rectangle (80, 400, 30, 10);
932 rgn1 = new Region (rect1);
933 rgn2 = new Region (rect2);
934 rgn3 = new Region (rect3);
935 rgn4 = new Region (rect4);
937 rgn1.Intersect (rgn2);
938 rgn1.Intersect (rgn3);
939 rgn1.Intersect (rgn4);
940 rects = rgn1.GetRegionScans (matrix);
941 Assert.AreEqual (0, rects.Length);
945 public void TestXor()
947 Bitmap bmp = new Bitmap (600, 800);
948 Graphics dc = Graphics.FromImage (bmp);
949 Matrix matrix = new Matrix ();
952 Rectangle rect1 = new Rectangle (380, 30, 60, 80);
953 Rectangle rect2 = new Rectangle (410, 40, 60, 80);
954 Region rgn1 = new Region (rect1);
955 Region rgn2 = new Region (rect2);
959 rects = rgn1.GetRegionScans (matrix);
961 Assert.AreEqual (4, rects.Length);
963 Assert.AreEqual (380, rects[0].X);
964 Assert.AreEqual (30, rects[0].Y);
965 Assert.AreEqual (60, rects[0].Width);
966 Assert.AreEqual (10, rects[0].Height);
968 Assert.AreEqual (380, rects[1].X);
969 Assert.AreEqual (40, rects[1].Y);
970 Assert.AreEqual (30, rects[1].Width);
971 Assert.AreEqual (70, rects[1].Height);
973 Assert.AreEqual (440, rects[2].X);
974 Assert.AreEqual (40, rects[2].Y);
975 Assert.AreEqual (30, rects[2].Width);
976 Assert.AreEqual (70, rects[2].Height);
978 Assert.AreEqual (410, rects[3].X);
979 Assert.AreEqual (110, rects[3].Y);
980 Assert.AreEqual (60, rects[3].Width);
981 Assert.AreEqual (10, rects[3].Height);
986 public void TestIsVisible()
988 Bitmap bmp = new Bitmap (600, 800);
989 Graphics dc = Graphics.FromImage (bmp);
990 Rectangle rect1, rect2;
992 Matrix matrix = new Matrix ();
994 rect1 = new Rectangle (500, 30, 60, 80);
995 rect2 = new Rectangle (520, 40, 60, 80);
997 rgn1 = new Region (new RectangleF (0, 0, 10,10));
998 Assert.AreEqual (false, rgn1.IsVisible (0,0,0,1));
1000 rgn1 = new Region (rect1);
1001 Assert.AreEqual (false, rgn1.IsVisible (500,29));
1002 Assert.AreEqual (true, rgn1.IsVisible (500,30));
1003 Assert.AreEqual (true, rgn1.IsVisible (rect1));
1004 Assert.AreEqual (true, rgn1.IsVisible (rect2));
1005 Assert.AreEqual (false, rgn1.IsVisible (new Rectangle (50,50,2,5)));
1007 Rectangle r = new Rectangle (1,1, 2,1);
1008 rgn2 = new Region (r);
1009 Assert.AreEqual (true, rgn2.IsVisible (r));
1010 Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 2,2)));
1011 Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 10,10)));
1012 Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 1,1)));
1013 Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (2,2, 1,1)));
1014 Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (0,0, 1,1)));
1015 Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (3,3, 1,1)));
1017 Assert.AreEqual (false, rgn2.IsVisible (0,0));
1018 Assert.AreEqual (false, rgn2.IsVisible (1,0));
1019 Assert.AreEqual (false, rgn2.IsVisible (2,0));
1020 Assert.AreEqual (false, rgn2.IsVisible (3,0));
1021 Assert.AreEqual (false, rgn2.IsVisible (0,1));
1022 Assert.AreEqual (true, rgn2.IsVisible (1,1));
1023 Assert.AreEqual (true, rgn2.IsVisible (2,1));
1024 Assert.AreEqual (false, rgn2.IsVisible (3,1));
1025 Assert.AreEqual (false, rgn2.IsVisible (0,2));
1026 Assert.AreEqual (false, rgn2.IsVisible (1,2));
1027 Assert.AreEqual (false, rgn2.IsVisible (2,2));
1028 Assert.AreEqual (false, rgn2.IsVisible (3,2));
1034 public void TestTranslate()
1036 Region rgn1 = new Region (new RectangleF (10, 10, 120,120));
1037 rgn1.Translate (30,20);
1038 Matrix matrix = new Matrix ();
1040 RectangleF [] rects = rgn1.GetRegionScans (matrix);
1042 Assert.AreEqual (1, rects.Length);
1044 Assert.AreEqual (40, rects[0].X);
1045 Assert.AreEqual (30, rects[0].Y);
1046 Assert.AreEqual (120, rects[0].Width);
1047 Assert.AreEqual (120, rects[0].Height);
1051 [ExpectedException (typeof (ArgumentNullException))]
1052 public void Constructor_GraphicsPath_Null ()
1054 GraphicsPath gp = null;
1055 Region r = new Region (gp);
1059 [ExpectedException (typeof (ArgumentNullException))]
1060 public void Constructor_RegionData_Null ()
1062 RegionData rd = null;
1063 Region r = new Region (rd);
1067 [ExpectedException (typeof (ArgumentNullException))]
1068 public void Union_GraphicsPath_Null ()
1070 GraphicsPath gp = null;
1071 new Region ().Union (gp);
1075 [ExpectedException (typeof (ArgumentNullException))]
1076 public void Union_Region_Null ()
1079 new Region ().Union (r);
1083 public void Union_Region_Infinite ()
1085 // default ctor creates an infinite region
1086 Region r = new Region ();
1087 CheckEmpty ("default .ctor", r);
1088 // union-ing to infinity doesn't change the results
1089 r.Union (new Rectangle (10, 10, 100, 100));
1090 CheckEmpty ("U infinity", r);
1094 [ExpectedException (typeof (ArgumentNullException))]
1095 public void Intersect_GraphicsPath_Null ()
1097 GraphicsPath gp = null;
1098 new Region ().Intersect (gp);
1102 [ExpectedException (typeof (ArgumentNullException))]
1103 public void Intersect_Region_Null ()
1106 new Region ().Intersect (r);
1110 [ExpectedException (typeof (ArgumentNullException))]
1111 public void Complement_GraphicsPath_Null ()
1113 GraphicsPath gp = null;
1114 new Region ().Complement (gp);
1118 [ExpectedException (typeof (ArgumentNullException))]
1119 public void Complement_Region_Null ()
1122 new Region ().Complement (r);
1126 [ExpectedException (typeof (ArgumentNullException))]
1127 public void Exclude_GraphicsPath_Null ()
1129 GraphicsPath gp = null;
1130 new Region ().Exclude (gp);
1134 [ExpectedException (typeof (ArgumentNullException))]
1135 public void Exclude_Region_Null ()
1138 new Region ().Exclude (r);
1142 [ExpectedException (typeof (ArgumentNullException))]
1143 public void Xor_GraphicsPath_Null ()
1145 GraphicsPath gp = null;
1146 new Region ().Xor (gp);
1150 [ExpectedException (typeof (ArgumentNullException))]
1151 public void Xor_Region_Null ()
1154 new Region ().Xor (r);
1158 [ExpectedException (typeof (ArgumentNullException))]
1159 public void GetBounds_Null ()
1161 new Region ().GetBounds (null);
1165 public void IsVisible_IntIntNull ()
1167 Assert.IsTrue (new Region ().IsVisible (0, 0, null));
1171 public void IsVisible_IntIntIntIntNull ()
1173 Assert.IsFalse (new Region ().IsVisible (0, 0, 0, 0, null));
1177 public void IsVisible_PointNull ()
1179 Point p = new Point ();
1180 Assert.IsTrue (new Region ().IsVisible (p, null));
1184 public void IsVisible_PointFNull ()
1186 PointF p = new PointF ();
1187 Assert.IsTrue (new Region ().IsVisible (p, null));
1191 public void IsVisible_RectangleNull ()
1193 Rectangle r = new Rectangle ();
1194 Assert.IsFalse (new Region ().IsVisible (r, null));
1198 public void IsVisible_RectangleFNull ()
1200 RectangleF r = new RectangleF ();
1201 Assert.IsFalse (new Region ().IsVisible (r, null));
1205 public void IsVisible_SingleSingleNull ()
1207 Assert.IsTrue (new Region ().IsVisible (0f, 0f, null));
1211 public void IsVisible_SingleSingleSingleSingleNull ()
1213 Assert.IsFalse (new Region ().IsVisible (0f, 0f, 0f, 0f, null));
1217 [ExpectedException (typeof (ArgumentNullException))]
1218 public void IsEmpty_Null ()
1220 new Region ().IsEmpty (null);
1224 [ExpectedException (typeof (ArgumentNullException))]
1225 public void IsInfinite_Null ()
1227 new Region ().IsInfinite (null);
1231 [ExpectedException (typeof (ArgumentNullException))]
1232 public void Equals_NullGraphics ()
1234 new Region ().Equals (null, Graphics.FromImage (new Bitmap (10, 10)));
1238 [ExpectedException (typeof (ArgumentNullException))]
1239 public void Equals_RegionNull ()
1241 new Region ().Equals (new Region (), null);
1245 [ExpectedException (typeof (ArgumentNullException))]
1246 [Category ("NotWorking")] // caused regression in SWF
1247 public void GetHrgn_Null ()
1249 new Region ().GetHrgn (null);
1253 [ExpectedException (typeof (ArgumentNullException))]
1254 public void GetRegionScans_Null ()
1256 new Region ().GetRegionScans (null);
1260 [ExpectedException (typeof (ArgumentNullException))]
1261 public void Transform_Null ()
1263 new Region ().Transform (null);
1266 // an "empty ctor" Region is infinite
1267 private void CheckEmpty (string prefix, Region region)
1269 Assert.IsFalse (region.IsEmpty (graphic), prefix + "IsEmpty");
1270 Assert.IsTrue (region.IsInfinite (graphic), prefix + "graphic");
1272 RectangleF rect = region.GetBounds (graphic);
1273 Assert.AreEqual (-4194304f, rect.X, prefix + "GetBounds.X");
1274 Assert.AreEqual (-4194304f, rect.Y, prefix + "GetBounds.Y");
1275 Assert.AreEqual (8388608f, rect.Width, prefix + "GetBounds.Width");
1276 Assert.AreEqual (8388608f, rect.Height, prefix + "GetBounds.Height");
1280 public void Region_Empty ()
1282 Region region = new Region ();
1283 CheckEmpty ("Empty.", region);
1285 Region clone = region.Clone ();
1286 CheckEmpty ("Clone.", region);
1288 RegionData data = region.GetRegionData ();
1289 Region r2 = new Region (data);
1290 CheckEmpty ("RegionData.", region);
1294 [Category ("NotWorking")]
1295 public void Region_Infinite_MultipleRectangles ()
1297 Region region = new Region ();
1298 Assert.IsTrue (region.IsInfinite (graphic), "Empty.IsInfinite");
1300 GraphicsPath gp = new GraphicsPath ();
1301 gp.AddRectangle (new Rectangle (-4194304, -4194304, 8388608, 8388608));
1302 region = new Region (gp);
1303 Assert.IsTrue (region.IsInfinite (graphic), "OneRectangle.IsInfinite");
1305 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1306 region = new Region (gp);
1307 Assert.IsFalse (region.IsInfinite (graphic), "TwoOverlappingRectangle.IsInfinite");
1309 gp = new GraphicsPath ();
1310 gp.AddRectangle (new Rectangle (-4194304, -4194304, 4194304, 8388608));
1311 gp.AddRectangle (new Rectangle (0, -4194304, 4194304, 8388608));
1312 Assert.IsFalse (region.IsInfinite (graphic), "TwoSideBySideRectangle.IsInfinite");
1316 public void Rectangle_GetRegionScans ()
1318 Matrix matrix = new Matrix ();
1319 GraphicsPath gp = new GraphicsPath ();
1320 gp.AddRectangle (new Rectangle (10, 10, 10, 10));
1321 Region region = new Region (gp);
1322 Assert.AreEqual (1, region.GetRegionScans (matrix).Length, "1");
1324 gp.AddRectangle (new Rectangle (20, 20, 20, 20));
1325 region = new Region (gp);
1326 Assert.AreEqual (2, region.GetRegionScans (matrix).Length, "2");
1330 public void InfinityExclude ()
1332 using (Region r = new Region ()) {
1333 Assert.IsTrue (r.IsInfinite (graphic), "before");
1334 r.Exclude (new Rectangle (5, 5, 10, 10));
1335 Assert.IsFalse (r.IsInfinite (graphic), "after");
1336 RectangleF bounds = r.GetBounds (graphic);
1337 Assert.AreEqual (-4194304, bounds.X, "X");
1338 Assert.AreEqual (-4194304, bounds.Y, "Y");
1339 Assert.AreEqual (8388608, bounds.Width, "Width");
1340 Assert.AreEqual (8388608, bounds.Height, "Height");
1345 public void InfinityIntersect ()
1347 using (Region r = new Region ()) {
1348 Assert.IsTrue (r.IsInfinite (graphic), "before");
1349 r.Intersect (new Rectangle (-10, -10, 20, 20));
1350 Assert.IsFalse (r.IsInfinite (graphic), "after");
1351 RectangleF bounds = r.GetBounds (graphic);
1352 Assert.AreEqual (-10, bounds.X, "X");
1353 Assert.AreEqual (-10, bounds.Y, "Y");
1354 Assert.AreEqual (20, bounds.Width, "Width");
1355 Assert.AreEqual (20, bounds.Height, "Height");
1360 public void InfinityIntersectTranslate ()
1362 using (Region r = new Region ()) {
1363 Assert.IsTrue (r.IsInfinite (graphic), "before");
1364 r.Intersect (new Rectangle (-10, -10, 20, 20));
1365 r.Translate (10, 10);
1366 RectangleF bounds = r.GetBounds (graphic);
1367 Assert.AreEqual (0, bounds.X, "X");
1368 Assert.AreEqual (0, bounds.Y, "Y");
1369 Assert.AreEqual (20, bounds.Width, "Width");
1370 Assert.AreEqual (20, bounds.Height, "Height");
1375 public void InfinityIntersectScale ()
1377 using (Region r = new Region ()) {
1378 Assert.IsTrue (r.IsInfinite (graphic), "before");
1379 r.Intersect (new Rectangle (-10, -10, 20, 20));
1380 using (Matrix m = new Matrix ()) {
1384 RectangleF bounds = r.GetBounds (graphic);
1385 Assert.AreEqual (-20, bounds.X, "X");
1386 Assert.AreEqual (-5, bounds.Y, "Y");
1387 Assert.AreEqual (40, bounds.Width, "Width");
1388 Assert.AreEqual (10, bounds.Height, "Height");
1393 public void InfinityIntersectTransform ()
1395 using (Region r = new Region ()) {
1396 Assert.IsTrue (r.IsInfinite (graphic), "before");
1397 r.Intersect (new Rectangle (-10, -10, 20, 20));
1398 using (Matrix m = new Matrix (2, 0, 0, 0.5f, 10, 10)) {
1401 RectangleF bounds = r.GetBounds (graphic);
1402 Assert.AreEqual (-10, bounds.X, "X");
1403 Assert.AreEqual (5, bounds.Y, "Y");
1404 Assert.AreEqual (40, bounds.Width, "Width");
1405 Assert.AreEqual (10, bounds.Height, "Height");
1410 public void InfinityTranslate ()
1412 using (Region r = new Region ()) {
1413 Assert.IsTrue (r.IsInfinite (graphic), "before");
1414 r.Translate (10, 10);
1415 Assert.IsTrue (r.IsInfinite (graphic), "after");
1416 CheckEmpty ("InfinityTranslate", r);
1421 public void InfinityScaleUp ()
1423 using (Region r = new Region ()) {
1424 Assert.IsTrue (r.IsInfinite (graphic), "before");
1425 using (Matrix m = new Matrix ()) {
1429 Assert.IsTrue (r.IsInfinite (graphic), "after");
1430 CheckEmpty ("InfinityScaleUp", r);
1435 public void InfinityScaleDown ()
1437 using (Region r = new Region ()) {
1438 Assert.IsTrue (r.IsInfinite (graphic), "before");
1439 using (Matrix m = new Matrix ()) {
1440 m.Scale (0.5f, 0.5f);
1443 Assert.IsTrue (r.IsInfinite (graphic), "after");
1444 CheckEmpty ("InfinityScaleDown", r);
1449 public void InfinityRotate ()
1451 using (Region r = new Region ()) {
1452 Assert.IsTrue (r.IsInfinite (graphic), "before");
1453 using (Matrix m = new Matrix ()) {
1457 Assert.IsTrue (r.IsInfinite (graphic), "after");
1458 CheckEmpty ("InfinityRotate", r);
1463 public void Intersect_383878 ()
1465 using (Region clipRegion = new Region ()) {
1466 clipRegion.MakeInfinite ();
1468 Rectangle smaller = new Rectangle (5, 5, -10, -10);
1470 clipRegion.Intersect (smaller);
1471 Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
1472 Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");
1474 RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
1475 Assert.AreEqual (1, rects.Length, "Length");
1476 Assert.AreEqual (new RectangleF (-5, -5, 10, 10), rects [0], "0");
1481 public void Complement_383878 ()
1483 using (Region clipRegion = new Region ()) {
1484 clipRegion.MakeInfinite ();
1486 Rectangle smaller = new Rectangle (5, 5, -10, -10);
1487 Rectangle bigger = new Rectangle (-5, -5, 12, 12);
1489 clipRegion.Intersect (smaller);
1490 clipRegion.Complement (bigger);
1492 Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
1493 Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");
1495 RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
1496 Assert.AreEqual (2, rects.Length, "Length");
1497 Assert.AreEqual (new RectangleF (5, -5, 2, 10), rects [0], "0");
1498 Assert.AreEqual (new RectangleF (-5, 5, 12, 2), rects [1], "1");
1504 // the test cases in this fixture aren't restricted wrt running unmanaged code
1505 public class RegionTestUnmanaged {
1506 private Bitmap bitmap;
1507 private Graphics graphic;
1510 public void FixtureSetUp ()
1512 bitmap = new Bitmap (10, 10);
1513 graphic = Graphics.FromImage (bitmap);
1516 // Note: Test cases calling GetHrng will leak memory unless ReleaseHrgn
1517 // (which only exists in 2.0) is called.
1520 public void GetHrgn_Infinite_MakeEmpty ()
1522 Region r = new Region ();
1523 Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
1524 Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
1525 Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
1528 Assert.IsTrue (r.IsEmpty (graphic), "Empty");
1529 Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
1530 IntPtr h = r.GetHrgn (graphic);
1531 Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
1538 public void GetHrgn_Empty_MakeInfinite ()
1540 Region r = new Region (new GraphicsPath ());
1541 Assert.IsTrue (r.IsEmpty (graphic), "Empty");
1542 Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
1543 IntPtr h = r.GetHrgn (graphic);
1544 Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
1547 Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
1548 Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
1549 Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
1556 public void GetHrgn_TwiceFromSameRegionInstance ()
1558 Region r = new Region (new GraphicsPath ());
1559 IntPtr h1 = r.GetHrgn (graphic);
1560 IntPtr h2 = r.GetHrgn (graphic);
1561 Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
1569 public void GetHrgn_FromHrgn ()
1571 Region r1 = new Region (new GraphicsPath ());
1572 IntPtr h1 = r1.GetHrgn (graphic);
1573 Assert.IsFalse (h1 == IntPtr.Zero, "Handle_1!=0");
1575 Region r2 = Region.FromHrgn (h1);
1576 IntPtr h2 = r2.GetHrgn (graphic);
1577 Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
1578 Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
1580 r1.ReleaseHrgn (h1);
1581 r2.ReleaseHrgn (h2);
1586 [ExpectedException (typeof (ArgumentException))]
1587 public void FromHrgn_Zero ()
1589 Region.FromHrgn (IntPtr.Zero);
1593 [ExpectedException (typeof (ArgumentNullException))]
1594 public void ReleaseHrng_Zero ()
1596 Region r = new Region (new GraphicsPath ());
1597 r.ReleaseHrgn (IntPtr.Zero);
1601 public void ReleaseHrng ()
1603 Region r = new Region (new GraphicsPath ());
1604 IntPtr ptr = r.GetHrgn (graphic);
1605 Assert.IsFalse (IntPtr.Zero == ptr, "ptr");
1606 r.ReleaseHrgn (ptr);