Remove invalid tests for image palettes in GdiPlusTest (#5671)
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / RegionNonRectTest.cs
1 //
2 // System.Drawing.Region non-rectangular unit tests
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Drawing.Imaging;
31 using System.Drawing;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Drawing {
37
38         /* NOTE: General tests and rectangular region tests are located in TestRegion.cs */
39         /*       Here we exclusively tests non-rectangular (GraphicsPath based) regions. */
40
41         [TestFixture]
42         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
43         public class RegionNonRectTest {
44
45                 private Bitmap bitmap;
46                 private Graphics graphic;
47                 private Matrix matrix;
48                 private GraphicsPath sp1, sp2, sp3, sp4;
49
50                 [TestFixtureSetUp]
51                 public void FixtureSetUp ()
52                 {
53                         bitmap = new Bitmap (10, 10);
54                         graphic = Graphics.FromImage (bitmap);
55                         matrix = new Matrix ();
56
57                         sp1 = new GraphicsPath ();
58                         sp1.AddPolygon (new Point[4] { new Point (0, 0), new Point (3, 0), new Point (3, 3), new Point (0, 3) });
59
60                         sp2 = new GraphicsPath ();
61                         sp2.AddPolygon (new Point[4] { new Point (2, 2), new Point (5, 2), new Point (5, 5), new Point (2, 5) });
62
63                         sp3 = new GraphicsPath ();
64                         sp3.AddPolygon (new Point[4] { new Point (6, 0), new Point (9, 0), new Point (9, 3), new Point (6, 3) });
65
66                         sp4 = new GraphicsPath ();
67                         sp4.AddPolygon (new Point[4] { new Point (8, 0), new Point (11, 0), new Point (11, 3), new Point (8, 3) });
68                 }
69
70                 // a region with an "empty ctor" graphic path is "empty" (i.e. not infinite)
71                 private void CheckEmpty (string prefix, Region region)
72                 {
73                         Assert.IsTrue (region.IsEmpty (graphic), prefix + "IsEmpty");
74                         Assert.IsFalse (region.IsInfinite (graphic), prefix + "graphic");
75
76                         RectangleF rect = region.GetBounds (graphic);
77                         Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
78                         Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
79                         Assert.AreEqual (0f, rect.Width, prefix + "GetBounds.Width");
80                         Assert.AreEqual (0f, rect.Height, prefix + "GetBounds.Height");
81                 }
82
83                 [Test]
84                 public void Region_Ctor_GraphicsPath_Empty ()
85                 {
86                         Region region = new Region (new GraphicsPath ());
87                         CheckEmpty ("GraphicsPath.", region);
88
89                         Region clone = region.Clone ();
90                         CheckEmpty ("Clone.", region);
91                 }
92
93                 [Test]
94                 [Ignore ("this does not work when using MS GDI+ - with or without Mono")]
95                 public void Region_Ctor_RegionData ()
96                 {
97                         Region region = new Region (new GraphicsPath ());
98                         RegionData data = region.GetRegionData ();
99                         Region r2 = new Region (data);
100                         CheckEmpty ("RegionData.", region);
101                 }
102
103                 [Test]
104                 public void Region_Ctor_GraphicsPath ()
105                 {
106                         GraphicsPath gp = new GraphicsPath ();
107                         Region region = new Region (gp);
108                         CheckEmpty ("GraphicsPath.", region);
109
110                         Region clone = region.Clone ();
111                         CheckEmpty ("Clone.", region);
112                 }
113
114                 private void CheckInfiniteBounds (GraphicsPath path)
115                 {
116                         RectangleF rect = path.GetBounds ();
117                         Assert.AreEqual (-4194304f, rect.X, "Bounds.X");
118                         Assert.AreEqual (-4194304f, rect.Y, "Bounds.Y");
119                         Assert.AreEqual (8388608f, rect.Width, "Bounds.Width");
120                         Assert.AreEqual (8388608f, rect.Height, "Bounds.Height");
121                 }
122
123                 [Test]
124                 public void Region_Curve_IsInfinite ()
125                 {
126                         Point[] points = new Point[2] { new Point (-4194304, -4194304), new Point (4194304, 4194304) };
127                         GraphicsPath gp = new GraphicsPath ();
128                         gp.AddCurve (points);
129                         CheckInfiniteBounds (gp);
130
131                         Region region = new Region (gp);
132                         Assert.IsFalse (region.IsInfinite (graphic), "IsInfinite");
133                         // note: infinity isn't based on the bounds
134                 }
135
136                 [Test]
137                 [Category ("NotWorking")]
138                 public void Region_Polygon4_IsInfinite ()
139                 {
140                         Point[] points = new Point[4] { new Point (-4194304, -4194304), new Point (-4194304, 4194304), new Point (4194304, 4194304), new Point (4194304, -4194304) };
141                         GraphicsPath gp = new GraphicsPath ();
142                         gp.AddPolygon (points);
143                         CheckInfiniteBounds (gp);
144
145                         Region region = new Region (gp);
146                         Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
147                 }
148
149                 [Test]
150                 [Category ("NotWorking")]
151                 public void Region_Polygon5_IsInfinite ()
152                 {
153                         // overlap the first/last point
154                         Point[] points = new Point[5] { new Point (-4194304, -4194304), new Point (-4194304, 4194304), new Point (4194304, 4194304), new Point (4194304, -4194304), new Point (-4194304, -4194304) };
155                         GraphicsPath gp = new GraphicsPath ();
156                         gp.AddPolygon (points);
157                         CheckInfiniteBounds (gp);
158
159                         Region region = new Region (gp);
160                         Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
161                 }
162
163                 [Test]
164                 [Category ("NotWorking")]
165                 public void Region_Rectangle_IsInfinite ()
166                 {
167                         GraphicsPath gp = new GraphicsPath ();
168                         gp.AddRectangle (new Rectangle (-4194304, -4194304, 8388608, 8388608));
169                         CheckInfiniteBounds (gp);
170
171                         Region region = new Region (gp);
172                         Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
173                 }
174
175                 [Test]
176                 public void Curve_GetRegionScans ()
177                 {
178                         Point[] points = new Point[2] { new Point (-4194304, -4194304), new Point (4194304, 4194304) };
179                         GraphicsPath gp = new GraphicsPath ();
180                         gp.AddCurve (points);
181                         Region region = new Region (gp);
182                         // too big, returns 0
183                         Assert.AreEqual (0, region.GetRegionScans (matrix).Length, "GetRegionScans");
184                 }
185
186                 private void DisplaySmallRegion (Region region, int ox, int oy, int width, int height)
187                 {
188                         for (int y = oy ; y < height - 1; y++) {
189                                 for (int x = ox; x < width - 1; x++) {
190                                         if (region.IsVisible (x, y))
191                                                 Console.Write ("X");
192                                         else
193                                                 Console.Write (".");
194                                 }
195                                 Console.WriteLine ();
196                         }
197                 }
198
199                 private void DisplaySmallRegion (Region region, int width, int height)
200                 {
201                         DisplaySmallRegion (region, -1, -1, width, height);
202                 }
203
204
205                 private void CompareSmallRegion (Region region, bool[] expected, int ox, int oy, int width, int height)
206                 {
207                         int p = 0;
208                         for (int y = oy; y < height + oy; y++) {
209                                 for (int x = ox; x < width + ox; x++) {
210                                         Assert.AreEqual (expected[p], region.IsVisible (x, y), String.Format ("{0},{1}", x, y));
211                                         p++;
212                                 }
213                         }
214                 }
215
216                 private void CompareSmallRegion (Region region, bool[] expected, int width, int height)
217                 {
218                         CompareSmallRegion (region, expected, -1, -1, width, height);
219                 }
220
221                 private void CheckRectF (string msg, int x, int y, int w, int h, RectangleF rect)
222                 {
223                         Assert.AreEqual (x, rect.X, msg + ".X");
224                         Assert.AreEqual (y, rect.Y, msg + ".Y");
225                         Assert.AreEqual (w, rect.Width, msg + ".Width");
226                         Assert.AreEqual (h, rect.Height, msg + ".Height");
227                 }
228
229                 static bool[] sunion = new bool[49] {
230                         false, false, false, false, false, false, false, // .......
231                         false, true,  true,  true,  false, false, false, // .XXX...
232                         false, true,  true,  true,  false, false, false, // .XXX...
233                         false, true,  true,  true,  true,  true,  false, // .XXXXX.
234                         false, false, false, true,  true,  true,  false, // ...XXX.
235                         false, false, false, true,  true,  true,  false, // ...XXX.
236                         false, false, false, false, false, false, false, // .......
237                 };
238
239                 [Test]
240                 public void SmallUnion1 ()
241                 {
242                         Region region = new Region (sp1);
243                         region.Union (sp2);
244                         CompareSmallRegion (region, sunion, 7, 7);
245
246                         RectangleF[] scans = region.GetRegionScans (matrix);
247                         Assert.AreEqual (3, scans.Length, "GetRegionScans");
248                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
249                         CheckRectF ("[1]", 0, 2, 5, 1, scans[1]);
250                         CheckRectF ("[2]", 2, 3, 3, 2, scans[2]);
251                 }
252
253                 [Test]
254                 public void SmallUnion2 ()
255                 {
256                         Region region = new Region (sp2);
257                         region.Union (sp1);
258                         CompareSmallRegion (region, sunion, 7, 7);
259
260                         RectangleF[] scans = region.GetRegionScans (matrix);
261                         Assert.AreEqual (3, scans.Length, "GetRegionScans");
262                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
263                         CheckRectF ("[1]", 0, 2, 5, 1, scans[1]);
264                         CheckRectF ("[2]", 2, 3, 3, 2, scans[2]);
265                 }
266
267                 static bool[] self1 = new bool[49] {
268                         false, false, false, false, false, false, false, // .......
269                         false, true,  true,  true,  false, false, false, // .XXX...
270                         false, true,  true,  true,  false, false, false, // .XXX...
271                         false, true,  true,  true,  false, false, false, // .XXX...
272                         false, false, false, false, false, false, false, // .......
273                         false, false, false, false, false, false, false, // .......
274                         false, false, false, false, false, false, false, // .......
275                 };
276
277                 [Test]
278                 public void SmallUnion_Self1 ()
279                 {
280                         Region region = new Region (sp1);
281                         region.Union (sp1);
282                         CompareSmallRegion (region, self1, 7, 7);
283
284                         RectangleF[] scans = region.GetRegionScans (matrix);
285                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
286                         CheckRectF ("[0]", 0, 0, 3, 3, scans[0]);
287                 }
288
289                 static bool[] self2 = new bool[49] {
290                         false, false, false, false, false, false, false, // .......
291                         false, false, false, false, false, false, false, // .......
292                         false, false, false, false, false, false, false, // .......
293                         false, false, false, true,  true,  true,  false, // ...XXX.
294                         false, false, false, true,  true,  true,  false, // ...XXX.
295                         false, false, false, true,  true,  true,  false, // ...XXX.
296                         false, false, false, false, false, false, false, // .......
297                 };
298
299                 [Test]
300                 public void SmallUnion_Self2 ()
301                 {
302                         Region region = new Region (sp2);
303                         region.Union (sp2);
304                         CompareSmallRegion (region, self2, 7, 7);
305
306                         RectangleF[] scans = region.GetRegionScans (matrix);
307                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
308                         CheckRectF ("[0]", 2, 2, 3, 3, scans[0]);
309                 }
310
311                 static bool[] sintersection = new bool[49] {
312                         false, false, false, false, false, false, false, // .......
313                         false, false, false, false, false, false, false, // .......
314                         false, false, false, false, false, false, false, // .......
315                         false, false, false, true,  false, false, false, // ...X...
316                         false, false, false, false, false, false, false, // .......
317                         false, false, false, false, false, false, false, // .......
318                         false, false, false, false, false, false, false, // .......
319                 };
320
321                 [Test]
322                 public void SmallIntersection1 ()
323                 {
324                         Region region = new Region (sp1);
325                         region.Intersect (sp2);
326                         CompareSmallRegion (region, sintersection, 7, 7);
327
328                         RectangleF[] scans = region.GetRegionScans (matrix);
329                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
330                         CheckRectF ("[0]", 2, 2, 1, 1, scans[0]);
331                 }
332
333                 [Test]
334                 public void SmallIntersection2 ()
335                 {
336                         Region region = new Region (sp2);
337                         region.Intersect (sp1);
338                         CompareSmallRegion (region, sintersection, 7, 7);
339
340                         RectangleF[] scans = region.GetRegionScans (matrix);
341                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
342                         CheckRectF ("[0]", 2, 2, 1, 1, scans[0]);
343                 }
344
345                 [Test]
346                 public void SmallIntersection_Self1 ()
347                 {
348                         Region region = new Region (sp1);
349                         region.Intersect (sp1);
350                         CompareSmallRegion (region, self1, 7, 7);
351
352                         RectangleF[] scans = region.GetRegionScans (matrix);
353                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
354                         CheckRectF ("[0]", 0, 0, 3, 3, scans[0]);
355                 }
356
357                 [Test]
358                 public void SmallIntersection_Self2 ()
359                 {
360                         Region region = new Region (sp2);
361                         region.Intersect (sp2);
362                         CompareSmallRegion (region, self2, 7, 7);
363
364                         RectangleF[] scans = region.GetRegionScans (matrix);
365                         Assert.AreEqual (1, scans.Length, "GetRegionScans");
366                         CheckRectF ("[0]", 2, 2, 3, 3, scans[0]);
367                 }
368
369                 static bool[] sexclude1 = new bool[49] {
370                         false, false, false, false, false, false, false, // .......
371                         false, true,  true,  true,  false, false, false, // .XXX...
372                         false, true,  true,  true,  false, false, false, // .XXX...
373                         false, true,  true,  false, false, false, false, // .XX....
374                         false, false, false, false, false, false, false, // .......
375                         false, false, false, false, false, false, false, // .......
376                         false, false, false, false, false, false, false, // .......
377                 };
378
379                 [Test]
380                 public void SmallExclude1 ()
381                 {
382                         Region region = new Region (sp1);
383                         region.Exclude (sp2);
384                         CompareSmallRegion (region, sexclude1, 7, 7);
385
386                         RectangleF[] scans = region.GetRegionScans (matrix);
387                         Assert.AreEqual (2, scans.Length, "GetRegionScans");
388                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
389                         CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
390                 }
391
392                 static bool[] sexclude2 = new bool[49] {
393                         false, false, false, false, false, false, false, // .......
394                         false, false, false, false, false, false, false, // .......
395                         false, false, false, false, false, false, false, // .......
396                         false, false, false, false, true,  true,  false, // ....XX.
397                         false, false, false, true,  true,  true,  false, // ...XXX.
398                         false, false, false, true,  true,  true,  false, // ...XXX.
399                         false, false, false, false, false, false, false, // .......
400                 };
401
402                 [Test]
403                 public void SmallExclude2 ()
404                 {
405                         Region region = new Region (sp2);
406                         region.Exclude (sp1);
407                         CompareSmallRegion (region, sexclude2, 7, 7);
408
409                         RectangleF[] scans = region.GetRegionScans (matrix);
410                         Assert.AreEqual (2, scans.Length, "GetRegionScans");
411                         CheckRectF ("[0]", 3, 2, 2, 1, scans[0]);
412                         CheckRectF ("[1]", 2, 3, 3, 2, scans[1]);
413                 }
414
415                 static bool[] sempty = new bool[49] {
416                         false, false, false, false, false, false, false, // .......
417                         false, false, false, false, false, false, false, // .......
418                         false, false, false, false, false, false, false, // .......
419                         false, false, false, false, false, false, false, // .......
420                         false, false, false, false, false, false, false, // .......
421                         false, false, false, false, false, false, false, // .......
422                         false, false, false, false, false, false, false, // .......
423                 };
424
425                 [Test]
426                 public void SmallExclude_Self1 ()
427                 {
428                         Region region = new Region (sp1);
429                         region.Exclude (sp1);
430                         CompareSmallRegion (region, sempty, 7, 7);
431
432                         RectangleF[] scans = region.GetRegionScans (matrix);
433                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
434                 }
435
436                 [Test]
437                 public void SmallExclude_Self2 ()
438                 {
439                         Region region = new Region (sp2);
440                         region.Exclude (sp2);
441                         CompareSmallRegion (region, sempty, 7, 7);
442
443                         RectangleF[] scans = region.GetRegionScans (matrix);
444                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
445                 }
446
447                 [Test]
448                 public void SmallComplement1 ()
449                 {
450                         Region region = new Region (sp1);
451                         region.Complement (sp2);
452                         CompareSmallRegion (region, sexclude2, 7, 7);
453
454                         RectangleF[] scans = region.GetRegionScans (matrix);
455                         Assert.AreEqual (2, scans.Length, "GetRegionScans");
456                         CheckRectF ("[0]", 3, 2, 2, 1, scans[0]);
457                         CheckRectF ("[1]", 2, 3, 3, 2, scans[1]);
458                 }
459
460                 [Test]
461                 public void SmallComplement2 ()
462                 {
463                         Region region = new Region (sp2);
464                         region.Complement (sp1);
465                         CompareSmallRegion (region, sexclude1, 7, 7);
466
467                         RectangleF[] scans = region.GetRegionScans (matrix);
468                         Assert.AreEqual (2, scans.Length, "GetRegionScans");
469                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
470                         CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
471                 }
472
473                 [Test]
474                 public void SmallComplement_Self1 ()
475                 {
476                         Region region = new Region (sp1);
477                         region.Complement (sp1);
478                         CompareSmallRegion (region, sempty, 7, 7);
479
480                         RectangleF[] scans = region.GetRegionScans (matrix);
481                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
482                 }
483
484                 [Test]
485                 public void SmallComplement_Self2 ()
486                 {
487                         Region region = new Region (sp2);
488                         region.Complement (sp2);
489                         CompareSmallRegion (region, sempty, 7, 7);
490
491                         RectangleF[] scans = region.GetRegionScans (matrix);
492                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
493                 }
494
495                 static bool[] sxor = new bool[49] {
496                         false, false, false, false, false, false, false, // .......
497                         false, true,  true,  true,  false, false, false, // .XXX...
498                         false, true,  true,  true,  false, false, false, // .XXX...
499                         false, true,  true,  false, true,  true,  false, // .XX.XX.
500                         false, false, false, true,  true,  true,  false, // ...XXX.
501                         false, false, false, true,  true,  true,  false, // ...XXX.
502                         false, false, false, false, false, false, false, // .......
503                 };
504
505                 [Test]
506                 public void SmallXor1 ()
507                 {
508                         Region region = new Region (sp1);
509                         region.Xor (sp2);
510                         CompareSmallRegion (region, sxor, 7, 7);
511
512                         RectangleF[] scans = region.GetRegionScans (matrix);
513                         Assert.AreEqual (4, scans.Length, "GetRegionScans");
514                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
515                         CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
516                         CheckRectF ("[2]", 3, 2, 2, 1, scans[2]);
517                         CheckRectF ("[3]", 2, 3, 3, 2, scans[3]);
518                 }
519
520                 [Test]
521                 public void SmallXor2 ()
522                 {
523                         Region region = new Region (sp2);
524                         region.Xor (sp1);
525                         CompareSmallRegion (region, sxor, 7, 7);
526
527                         RectangleF[] scans = region.GetRegionScans (matrix);
528                         Assert.AreEqual (4, scans.Length, "GetRegionScans");
529                         CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
530                         CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
531                         CheckRectF ("[2]", 3, 2, 2, 1, scans[2]);
532                         CheckRectF ("[3]", 2, 3, 3, 2, scans[3]);
533                 }
534
535                 [Test]
536                 public void SmallXor_Self1 ()
537                 {
538                         Region region = new Region (sp1);
539                         region.Xor (sp1);
540                         CompareSmallRegion (region, sempty, 7, 7);
541
542                         RectangleF[] scans = region.GetRegionScans (matrix);
543                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
544                 }
545
546                 [Test]
547                 public void SmallXor_Self2 ()
548                 {
549                         Region region = new Region (sp2);
550                         region.Xor (sp2);
551                         CompareSmallRegion (region, sempty, 7, 7);
552
553                         RectangleF[] scans = region.GetRegionScans (matrix);
554                         Assert.AreEqual (0, scans.Length, "GetRegionScans");
555                 }
556
557                 [Test]
558                 public void NegativeXor ()
559                 {
560                         GraphicsPath neg = new GraphicsPath ();
561                         // identical result (matrix) of XOR but we're using negative coordinates
562                         neg.AddPolygon (new Point[4] { new Point (-2, -2), new Point (1, -2), new Point (1, 1), new Point (-2, 1) });
563
564                         Region region = new Region (sp1);
565                         region.Xor (neg);
566                         CompareSmallRegion (region, sxor, -3, -3, 7, 7);
567                 }
568
569                 static bool[] ni_union = new bool[55] {
570                         false, false, false, false, false, false, false, false, false, false, false, // ...........
571                         false, true,  true,  true,  false, false, false, true,  true,  true,  false, // .XXX...XXX.
572                         false, true,  true,  true,  false, false, false, true,  true,  true,  false, // .XXX...XXX.
573                         false, true,  true,  true,  false, false, false, true,  true,  true,  false, // .XXX...XXX.
574                         false, false, false, false, false, false, false, false, false, false, false, // ...........
575                 };
576
577                 [Test]
578                 public void UnionWithoutIntersection ()
579                 {
580                         Region region = new Region (sp1);
581                         region.Union (sp3);
582                         CompareSmallRegion (region, ni_union, 11,5 );
583                 }
584
585                 [Test]
586                 // libgdiplus: both region are considered inside as intersecting rectangle because
587                 // part of them co-exists in the same 8x8 bitmap. Full algorithm apply but results
588                 // in an empty bitmap
589                 public void IntersectionWithoutIntersection ()
590                 {
591                         Region region = new Region (sp1);
592                         region.Intersect (sp3);
593                         CompareSmallRegion (region, sempty, 7, 7);
594                 }
595
596                 [Test]
597                 // libgdiplus: no intersection results in an empty bitmap (optimization)
598                 public void IntersectionWithoutIntersection_Large ()
599                 {
600                         Region region = new Region (sp1);
601                         region.Intersect (sp4);
602                         CompareSmallRegion (region, sempty, 7, 7);
603                 }
604
605                 [Test]
606                 // libgdiplus: both region are considered inside as intersecting rectangle because
607                 // part of them co-exists in the same 8x8 bitmap. Full algorithm apply but results
608                 // as a copy of sp1
609                 public void ExcludeWithoutIntersection ()
610                 {
611                         Region region = new Region (sp1);
612                         region.Exclude (sp3);
613                         CompareSmallRegion (region, self1, 7, 7);
614                 }
615
616                 [Test]
617                 // libgdiplus: no intersection results in a clone of sp1 (optimization)
618                 public void ExcludeWithoutIntersection_Large ()
619                 {
620                         Region region = new Region (sp1);
621                         region.Exclude (sp4);
622                         CompareSmallRegion (region, self1, 7, 7);
623                 }
624
625                 [Test]
626                 // libgdiplus: both region are considered inside as intersecting rectangle because
627                 // part of them co-exists in the same 8x8 bitmap. Full algorithm apply but results
628                 // as a copy of sp1
629                 public void ComplementWithoutIntersection ()
630                 {
631                         Region region = new Region (sp3);
632                         region.Complement (sp1);
633                         CompareSmallRegion (region, self1, 7, 7);
634                 }
635
636                 [Test]
637                 // libgdiplus: no intersection results in a clone of sp1 (optimization)
638                 public void ComplementWithoutIntersection_Large ()
639                 {
640                         Region region = new Region (sp4);
641                         region.Complement (sp1);
642                         CompareSmallRegion (region, self1, 7, 7);
643                 }
644
645                 [Test]
646                 // libgdiplus: both region are considered inside as intersecting rectangle because
647                 // part of them co-exists in the same 8x8 bitmap.
648                 public void XorWithoutIntersection ()
649                 {
650                         Region region = new Region (sp1);
651                         region.Xor (sp3);
652                         CompareSmallRegion (region, ni_union, 11, 5);
653                 }
654
655                 static bool[] ni_xor = new bool[65] {
656                         false, false, false, false, false, false, false, false, false, false, false, false, false, // .............
657                         false, true,  true,  true,  false, false, false, false, false, true,  true,  true,  false, // .XXX.....XXX.
658                         false, true,  true,  true,  false, false, false, false, false, true,  true,  true,  false, // .XXX.....XXX.
659                         false, true,  true,  true,  false, false, false, false, false, true,  true,  true,  false, // .XXX.....XXX.
660                         false, false, false, false, false, false, false, false, false, false, false, false, false, // .............
661                 };
662
663                 [Test]
664                 // libgdiplus: both region aren't considered as an intersection because they do 
665                 // not co-exists in the same 8x8 bitmap. In this case the xor function calls the
666                 // union code (optimization).
667                 public void XorWithoutIntersection_Large ()
668                 {
669                         Region region = new Region (sp1);
670                         region.Xor (sp4);
671                         CompareSmallRegion (region, ni_xor, 13, 5);
672                 }
673
674                 [Test]
675                 public void IsEqual ()
676                 {
677                         Region r1 = new Region (sp1);
678                         Region r2 = new Region (sp2);
679                         Region r3 = new Region (sp3);
680                         Region r4 = new Region (sp4);
681                         // with self
682                         Assert.IsTrue (r1.Equals (r1, graphic), "r1-r1");
683                         Assert.IsTrue (r2.Equals (r2, graphic), "r2-r2");
684                         Assert.IsTrue (r3.Equals (r3, graphic), "r3-r3");
685                         Assert.IsTrue (r4.Equals (r4, graphic), "r4-r4");
686                         // with a different
687                         Assert.IsFalse (r1.Equals (r4, graphic), "r1-r4");
688                         Assert.IsFalse (r2.Equals (r3, graphic), "r2-r3");
689                         Assert.IsFalse (r3.Equals (r2, graphic), "r3-r2");
690                         Assert.IsFalse (r4.Equals (r1, graphic), "r4-r1");
691                         // with same (not self)
692                         Region r5 = r1.Clone ();
693                         r1.Exclude (r4);
694                         Assert.IsTrue (r1.Equals (r5, graphic), "r1-r5");
695                         Assert.IsTrue (r5.Equals (r1, graphic), "r5-r1");
696                         Assert.IsFalse (r5.Equals (r4, graphic), "r5-r4");
697                         Assert.IsFalse (r4.Equals (r5, graphic), "r4-r5");
698                 }
699
700                 [Test]
701                 public void Translate_Int ()
702                 {
703                         Region r1 = new Region (sp1);
704                         Region r2 = new Region (sp2);
705                         r2.Translate (-2, -2);
706                         r1.Intersect (r2);
707                         CompareSmallRegion (r1, self1, 7, 7);
708                 }
709
710                 [Test]
711                 public void Translate_Float ()
712                 {
713                         Region r1 = new Region (sp1);
714                         Region r2 = new Region (sp2);
715                         r2.Translate (-2.0f, -2.0f);
716                         r1.Intersect (r2);
717                         CompareSmallRegion (r1, self1, 7, 7);
718                 }
719
720                 [Test]
721                 public void EmptyPathWithInfiniteRegion ()
722                 {
723                         GraphicsPath gp = new GraphicsPath ();
724                         Region region = new Region ();
725                         Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
726
727                         region.Union (gp);
728                         Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");
729
730                         region.Xor (gp);
731                         Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");
732
733                         region.Exclude (gp);
734                         Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");
735
736                         region.Intersect (gp);
737                         Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");
738
739                         region.MakeInfinite ();
740                         region.Complement (gp);
741                         Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
742                 }
743
744                 [Test]
745                 public void EmptyRegionWithInfiniteRegion ()
746                 {
747                         Region empty = new Region ();
748                         empty.MakeEmpty ();
749                         Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");
750
751                         Region region = new Region ();
752                         Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
753
754                         region.Union (empty);
755                         Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");
756
757                         region.Xor (empty);
758                         Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");
759
760                         region.Exclude (empty);
761                         Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");
762
763                         region.Intersect (empty);
764                         Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");
765
766                         region.MakeInfinite ();
767                         region.Complement (empty);
768                         Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
769                 }
770         }
771 }