2 // System.Drawing.GraphicsPath unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using SC = System.ComponentModel;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing.Drawing2D {
39 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40 public class GraphicsPathTest {
42 private const float Pi4 = (float) (Math.PI / 4);
43 // let's tolerate a few differences
44 private const float Delta = 0.0003f;
46 private void CheckEmpty (string prefix, GraphicsPath gp)
48 Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
49 Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
50 Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
54 public void Constructor_InvalidFillMode ()
56 GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
57 Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
58 CheckEmpty ("InvalidFillMode.", gp);
62 [ExpectedException (typeof (ArgumentNullException))]
63 public void Constructor_Point_Null_Byte ()
65 new GraphicsPath ((Point[]) null, new byte[1]);
69 [ExpectedException (typeof (NullReferenceException))]
70 public void Constructor_Point_Byte_Null ()
72 new GraphicsPath (new Point[1], null);
76 [ExpectedException (typeof (ArgumentException))]
77 public void Constructor_Point_Byte_LengthMismatch ()
79 new GraphicsPath (new Point[1], new byte [2]);
83 [ExpectedException (typeof (ArgumentNullException))]
84 public void Constructor_PointF_Null_Byte ()
86 new GraphicsPath ((PointF[])null, new byte [1]);
90 [ExpectedException (typeof (NullReferenceException))]
91 public void Constructor_PointF_Byte_Null ()
93 new GraphicsPath ( new PointF[1], null);
97 [ExpectedException (typeof (ArgumentException))]
98 public void Constructor_PointF_Byte_LengthMismatch ()
100 new GraphicsPath (new PointF[2], new byte [1]);
104 public void GraphicsPath_Empty ()
106 GraphicsPath gp = new GraphicsPath ();
107 Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
108 CheckEmpty ("Empty.", gp);
110 GraphicsPath clone = (GraphicsPath) gp.Clone ();
111 Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
112 CheckEmpty ("Clone.", gp);
115 CheckEmpty ("Reverse.", gp);
119 [ExpectedException (typeof (ArgumentException))]
120 public void GraphicsPath_Empty_PathPoints ()
122 Assert.IsNull (new GraphicsPath ().PathPoints);
126 [ExpectedException (typeof (ArgumentException))]
127 public void GraphicsPath_Empty_PathTypes ()
129 Assert.IsNull (new GraphicsPath ().PathTypes);
133 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
134 public void FillMode_Invalid ()
136 // constructor accept an invalid FillMode
137 GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
138 Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
139 // but you can't set the FillMode property to an invalid value ;-)
140 gp.FillMode = (FillMode) Int32.MaxValue;
144 public void PathData_CannotChange ()
146 GraphicsPath gp = new GraphicsPath ();
147 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
149 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
150 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
152 // now try to change the first point
153 gp.PathData.Points[0] = new Point (0, 0);
154 // the changes isn't reflected in the property
155 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
156 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
160 public void PathPoints_CannotChange ()
162 GraphicsPath gp = new GraphicsPath ();
163 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
165 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
166 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
168 // now try to change the first point
169 gp.PathPoints[0] = new Point (0, 0);
170 // the changes isn't reflected in the property
171 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
172 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
176 public void PathTypes_CannotChange ()
178 GraphicsPath gp = new GraphicsPath ();
179 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
181 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
183 // now try to change the first type
185 // the changes isn't reflected in the property
186 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
189 private void CheckArc (GraphicsPath path)
191 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
192 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
193 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
195 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
196 RectangleF rect = path.GetBounds ();
197 Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
198 Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
199 Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
200 Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
202 Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
203 Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
204 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
205 Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
206 Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
207 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
208 Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
209 Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
210 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
211 Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
212 Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
213 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
217 public void AddArc_Rectangle ()
219 GraphicsPath gp = new GraphicsPath ();
220 gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
225 public void AddArc_RectangleF ()
227 GraphicsPath gp = new GraphicsPath ();
228 gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
233 public void AddArc_Int ()
235 GraphicsPath gp = new GraphicsPath ();
236 gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
241 public void AddArc_Float ()
243 GraphicsPath gp = new GraphicsPath ();
244 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
248 private void CheckBezier (GraphicsPath path)
250 Assert.AreEqual (4, path.PointCount, "PointCount");
251 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
252 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
253 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
255 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
256 RectangleF rect = path.GetBounds ();
257 Assert.AreEqual (1f, rect.X, "Bounds.X");
258 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
259 Assert.AreEqual (3f, rect.Width, "Bounds.Width");
260 Assert.AreEqual (3f, rect.Height, "Bounds.Height");
262 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
263 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
264 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
265 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
266 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
267 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
268 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
269 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
270 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
271 Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
272 Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
273 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
277 public void AddBezier_Point ()
279 GraphicsPath gp = new GraphicsPath ();
280 gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
285 public void AddBezier_PointF ()
287 GraphicsPath gp = new GraphicsPath ();
288 gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
293 public void AddBezier_Int ()
295 GraphicsPath gp = new GraphicsPath ();
296 gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
301 public void AddBezier_Float ()
303 GraphicsPath gp = new GraphicsPath ();
304 gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
309 [ExpectedException (typeof (ArgumentNullException))]
310 public void AddBeziers_Point_Null ()
312 new GraphicsPath ().AddBeziers ((Point[]) null);
316 [ExpectedException (typeof (ArgumentException))]
317 public void AddBeziers_3_Points ()
319 GraphicsPath gp = new GraphicsPath ();
320 gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
324 public void AddBeziers_Point ()
326 GraphicsPath gp = new GraphicsPath ();
327 gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
332 [ExpectedException (typeof (ArgumentNullException))]
333 public void AddBeziers_PointF_Null ()
335 new GraphicsPath ().AddBeziers ((PointF[]) null);
339 [ExpectedException (typeof (ArgumentException))]
340 public void AddBeziers_3_PointFs ()
342 GraphicsPath gp = new GraphicsPath ();
343 gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
347 public void AddBeziers_PointF ()
349 GraphicsPath gp = new GraphicsPath ();
350 gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
354 private void CheckEllipse (GraphicsPath path)
356 Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
357 Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
358 Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
360 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
361 RectangleF rect = path.GetBounds ();
362 Assert.AreEqual (1f, rect.X, "Bounds.X");
363 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
364 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
365 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
367 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
368 for (int i = 1; i < 12; i++)
369 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
370 Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
374 public void AddEllipse_Rectangle ()
376 GraphicsPath gp = new GraphicsPath ();
377 gp.AddEllipse (new Rectangle (1, 1, 2, 2));
382 public void AddEllipse_RectangleF ()
384 GraphicsPath gp = new GraphicsPath ();
385 gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
390 public void AddEllipse_Int ()
392 GraphicsPath gp = new GraphicsPath ();
393 gp.AddEllipse (1, 1, 2, 2);
398 public void AddEllipse_Float ()
400 GraphicsPath gp = new GraphicsPath ();
401 gp.AddEllipse (1f, 1f, 2f, 2f);
405 private void CheckLine (GraphicsPath path)
407 Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
408 Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
409 Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
411 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
412 RectangleF rect = path.GetBounds ();
413 Assert.AreEqual (1f, rect.X, "Bounds.X");
414 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
415 Assert.AreEqual (1f, rect.Width, "Bounds.Width");
416 Assert.AreEqual (1f, rect.Height, "Bounds.Height");
418 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
419 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
420 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
421 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
422 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
423 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
427 public void AddLine_Point ()
429 GraphicsPath gp = new GraphicsPath ();
430 gp.AddLine (new Point (1, 1), new Point (2, 2));
435 public void AddLine_PointF ()
437 GraphicsPath gp = new GraphicsPath ();
438 gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
443 public void AddLine_Int ()
445 GraphicsPath gp = new GraphicsPath ();
446 gp.AddLine (1, 1, 2, 2);
451 public void AddLine_Float ()
453 GraphicsPath gp = new GraphicsPath ();
454 gp.AddLine (1f, 1f, 2f, 2f);
459 public void AddLine_SamePoint ()
461 GraphicsPath gp = new GraphicsPath ();
462 gp.AddLine (new Point (1, 1), new Point (1, 1));
463 Assert.AreEqual (2, gp.PointCount, "PointCount");
464 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
465 Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
469 [ExpectedException (typeof (ArgumentNullException))]
470 public void AddLines_Point_Null ()
472 new GraphicsPath ().AddLines ((Point[])null);
476 [ExpectedException (typeof (ArgumentException))]
477 public void AddLines_Point_0 ()
479 GraphicsPath gp = new GraphicsPath ();
480 gp.AddLines (new Point[0]);
485 public void AddLines_Point_1 ()
487 GraphicsPath gp = new GraphicsPath ();
488 gp.AddLines (new Point[1] { new Point (1, 1) });
489 // Special case - a line with a single point is valid
490 Assert.AreEqual (1, gp.PointCount, "PointCount");
491 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
495 public void AddLines_Point ()
497 GraphicsPath gp = new GraphicsPath ();
498 gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
503 [ExpectedException (typeof (ArgumentNullException))]
504 public void AddLines_PointF_Null ()
506 new GraphicsPath ().AddLines ((PointF[]) null);
510 [ExpectedException (typeof (ArgumentException))]
511 public void AddLines_PointF_0 ()
513 GraphicsPath gp = new GraphicsPath ();
514 gp.AddLines (new PointF[0]);
519 public void AddLines_PointF_1 ()
521 GraphicsPath gp = new GraphicsPath ();
522 gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
523 // Special case - a line with a single point is valid
524 Assert.AreEqual (1, gp.PointCount, "PointCount");
525 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
529 public void AddLines_PointF ()
531 GraphicsPath gp = new GraphicsPath ();
532 gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
536 private void CheckPie (GraphicsPath path)
538 // the number of points generated for a Pie isn't the same between Mono and MS
540 Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
541 Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
542 Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
544 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
545 RectangleF rect = path.GetBounds ();
546 Assert.AreEqual (2f, rect.X, "Bounds.X");
547 Assert.AreEqual (2f, rect.Y, "Bounds.Y");
548 Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
549 Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
551 Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
552 Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
553 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
554 Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
555 Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
556 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
557 Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
558 Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
559 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
560 Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
561 Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
562 Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
563 Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
564 Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
565 Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
570 public void AddPie_Rect ()
572 GraphicsPath gp = new GraphicsPath ();
573 gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
578 public void AddPie_Int ()
580 GraphicsPath gp = new GraphicsPath ();
581 gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
586 public void AddPie_Float ()
588 GraphicsPath gp = new GraphicsPath ();
589 gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
593 private void CheckPolygon (GraphicsPath path)
595 // an extra point is generated by Mono (libgdiplus)
597 Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
598 Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
599 Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
601 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
602 RectangleF rect = path.GetBounds ();
603 Assert.AreEqual (1f, rect.X, "Bounds.X");
604 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
605 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
606 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
608 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
609 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
610 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
611 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
612 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
613 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
614 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
615 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
616 // the extra point change the type of the last point
618 Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
623 [ExpectedException (typeof (ArgumentNullException))]
624 public void AddPolygon_Point_Null ()
626 new GraphicsPath ().AddPolygon ((Point[]) null);
630 [ExpectedException (typeof (ArgumentException))]
631 public void AddPolygon_Point_Empty ()
633 new GraphicsPath ().AddPolygon (new Point[0]);
637 [ExpectedException (typeof (ArgumentException))]
638 public void AddPolygon_Point_1 ()
640 GraphicsPath gp = new GraphicsPath ();
641 gp.AddPolygon (new Point[1] { new Point (1, 1) });
645 [ExpectedException (typeof (ArgumentException))]
646 public void AddPolygon_Point_2 ()
648 GraphicsPath gp = new GraphicsPath ();
649 gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
653 public void AddPolygon_Point_3 ()
655 GraphicsPath gp = new GraphicsPath ();
656 gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
661 [ExpectedException (typeof (ArgumentNullException))]
662 public void AddPolygon_PointF_Null ()
664 new GraphicsPath ().AddPolygon ((PointF[]) null);
668 [ExpectedException (typeof (ArgumentException))]
669 public void AddPolygon_PointF_Empty ()
671 new GraphicsPath ().AddPolygon (new PointF[0]);
675 [ExpectedException (typeof (ArgumentException))]
676 public void AddPolygon_PointF_1 ()
678 GraphicsPath gp = new GraphicsPath ();
679 gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
683 [ExpectedException (typeof (ArgumentException))]
684 public void AddPolygon_PointF_2 ()
686 GraphicsPath gp = new GraphicsPath ();
687 gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
691 public void AddPolygon_PointF_3 ()
693 GraphicsPath gp = new GraphicsPath ();
694 gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
698 private void CheckRectangle (GraphicsPath path, int count)
700 Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
701 Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
702 Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
704 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
705 RectangleF rect = path.GetBounds ();
706 Assert.AreEqual (1f, rect.X, "Bounds.X");
707 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
708 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
709 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
711 // check first four points (first rectangle)
712 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
713 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
714 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
715 Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
716 Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
717 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
718 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
719 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
720 Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
721 Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
722 Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
723 Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
727 public void AddRectangle_Int ()
729 GraphicsPath gp = new GraphicsPath ();
730 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
731 CheckRectangle (gp, 4);
735 public void AddRectangle_Float ()
737 GraphicsPath gp = new GraphicsPath ();
738 gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
739 CheckRectangle (gp, 4);
743 [ExpectedException (typeof (ArgumentNullException))]
744 public void AddRectangles_Int_Null ()
746 GraphicsPath gp = new GraphicsPath ();
747 gp.AddRectangles ((Rectangle[]) null);
751 [ExpectedException (typeof (ArgumentException))]
752 public void AddRectangles_Int_Empty ()
754 GraphicsPath gp = new GraphicsPath ();
755 gp.AddRectangles (new Rectangle[0]);
756 CheckRectangle (gp, 4);
760 public void AddRectangles_Int ()
762 GraphicsPath gp = new GraphicsPath ();
763 gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
764 CheckRectangle (gp, 4);
768 [ExpectedException (typeof (ArgumentNullException))]
769 public void AddRectangles_Float_Null ()
771 GraphicsPath gp = new GraphicsPath ();
772 gp.AddRectangles ((RectangleF[]) null);
776 [ExpectedException (typeof (ArgumentException))]
777 public void AddRectangles_Float_Empty ()
779 GraphicsPath gp = new GraphicsPath ();
780 gp.AddRectangles ( new RectangleF[0]);
781 CheckRectangle (gp, 4);
785 public void AddRectangles_Float ()
787 GraphicsPath gp = new GraphicsPath ();
788 gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
789 CheckRectangle (gp, 4);
793 public void AddRectangles_Two ()
795 GraphicsPath gp = new GraphicsPath ();
796 gp.AddRectangles (new RectangleF[2] {
797 new RectangleF (1f, 1f, 2f, 2f),
798 new RectangleF (2f, 2f, 1f, 1f) } );
799 RectangleF rect = gp.GetBounds ();
800 Assert.AreEqual (1f, rect.X, "Bounds.X");
801 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
802 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
803 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
804 // second rectangle is completely within the first one
805 CheckRectangle (gp, 8);
809 [ExpectedException (typeof (ArgumentNullException))]
810 public void AddPath_Null ()
812 new GraphicsPath ().AddPath (null, false);
816 public void AddPath ()
818 GraphicsPath gpr = new GraphicsPath ();
819 gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
820 GraphicsPath gp = new GraphicsPath ();
821 gp.AddPath (gpr, true);
822 CheckRectangle (gp, 4);
825 private void CheckClosedCurve (GraphicsPath path)
827 Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
828 Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
829 Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
831 // GetBounds (well GdipGetPathWorldBounds) isn't very precise with curves
832 RectangleF rect = path.GetBounds ();
833 Assert.AreEqual (0.8333333f, rect.X, 0.2f, "Bounds.X");
834 Assert.AreEqual (0.8333333f, rect.Y, 0.2f, "Bounds.Y");
835 Assert.AreEqual (2.33333278f, rect.Width, 0.4f, "Bounds.Width");
836 Assert.AreEqual (2.33333278f, rect.Height, 0.4f, "Bounds.Height");
838 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
839 for (int i = 1; i < 9; i++)
840 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
841 Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
845 [ExpectedException (typeof (ArgumentNullException))]
846 public void AddClosedCurve_Point_Null ()
848 new GraphicsPath ().AddClosedCurve ((Point[])null);
852 [ExpectedException (typeof (ArgumentException))]
853 public void AddClosedCurve_Point_0 ()
855 GraphicsPath gp = new GraphicsPath ();
856 gp.AddClosedCurve (new Point [0]);
860 [ExpectedException (typeof (ArgumentException))]
861 public void AddClosedCurve_Point_1 ()
863 GraphicsPath gp = new GraphicsPath ();
864 gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
868 [ExpectedException (typeof (ArgumentException))]
869 public void AddClosedCurve_Point_2 ()
871 GraphicsPath gp = new GraphicsPath ();
872 gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
876 public void AddClosedCurve_Point_3 ()
878 GraphicsPath gp = new GraphicsPath ();
879 gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
880 CheckClosedCurve (gp);
884 [ExpectedException (typeof (ArgumentNullException))]
885 public void AddClosedCurve_PointF_Null ()
887 new GraphicsPath ().AddClosedCurve ((PointF[]) null);
891 [ExpectedException (typeof (ArgumentException))]
892 public void AddClosedCurve_PointF_0 ()
894 GraphicsPath gp = new GraphicsPath ();
895 gp.AddClosedCurve (new PointF[0]);
899 [ExpectedException (typeof (ArgumentException))]
900 public void AddClosedCurve_PointF_1 ()
902 GraphicsPath gp = new GraphicsPath ();
903 gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
907 [ExpectedException (typeof (ArgumentException))]
908 public void AddClosedCurve_PointF_2 ()
910 GraphicsPath gp = new GraphicsPath ();
911 gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
915 public void AddClosedCurve_PointF_3 ()
917 GraphicsPath gp = new GraphicsPath ();
918 gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
919 CheckClosedCurve (gp);
922 private void CheckCurve (GraphicsPath path)
924 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
925 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
926 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
928 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
929 RectangleF rect = path.GetBounds ();
930 Assert.AreEqual (1.0f, rect.X, "Bounds.X");
931 Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
932 Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
933 Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
935 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
936 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
937 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
938 // Mono has wrong? results
940 Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
941 Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
943 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
944 // Mono has wrong? results
946 Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
947 Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
949 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
950 Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
951 Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
952 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
956 [ExpectedException (typeof (ArgumentNullException))]
957 public void AddCurve_Point_Null ()
959 new GraphicsPath ().AddCurve ((Point[]) null);
963 [ExpectedException (typeof (ArgumentException))]
964 public void AddCurve_Point_0 ()
966 GraphicsPath gp = new GraphicsPath ();
967 gp.AddCurve (new Point[0]);
971 [ExpectedException (typeof (ArgumentException))]
972 public void AddCurve_Point_1 ()
974 GraphicsPath gp = new GraphicsPath ();
975 gp.AddCurve (new Point[1] { new Point (1, 1) });
979 public void AddCurve_Point_2 ()
981 GraphicsPath gp = new GraphicsPath ();
982 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
984 // note: GdipAddPathCurveI allows adding a "curve" with only 2 points (a.k.a. a line ;-)
989 public void AddCurve_Point_2_Tension ()
991 GraphicsPath gp = new GraphicsPath ();
992 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 1.0f);
994 // note: GdipAddPathCurve2I allows adding a "curve" with only 2 points (a.k.a. a line ;-)
999 [ExpectedException (typeof (ArgumentException))]
1000 public void AddCurve3_Point_2 ()
1002 GraphicsPath gp = new GraphicsPath ();
1003 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 0, 2, 0.5f);
1004 // adding only two points isn't supported by GdipAddCurve3I
1008 [ExpectedException (typeof (ArgumentNullException))]
1009 public void AddCurve_PointF_Null ()
1011 new GraphicsPath ().AddCurve ((PointF[]) null);
1015 [ExpectedException (typeof (ArgumentException))]
1016 public void AddCurve_PointF_0 ()
1018 GraphicsPath gp = new GraphicsPath ();
1019 gp.AddCurve (new PointF[0]);
1023 [ExpectedException (typeof (ArgumentException))]
1024 public void AddCurve_PointF_1 ()
1026 GraphicsPath gp = new GraphicsPath ();
1027 gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
1031 public void AddCurve_PointF_2 ()
1033 GraphicsPath gp = new GraphicsPath ();
1034 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
1036 // note: GdipAddPathCurve allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1041 public void AddCurve_PoinFt_2_Tension ()
1043 GraphicsPath gp = new GraphicsPath ();
1044 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 1.0f);
1046 // note: GdipAddPathCurve2 allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1051 [ExpectedException (typeof (ArgumentException))]
1052 public void AddCurve3_PointF_2 ()
1054 GraphicsPath gp = new GraphicsPath ();
1055 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 2, 0.5f);
1056 // adding only two points isn't supported by GdipAddCurve3
1060 public void AddCurve_LargeTension ()
1062 GraphicsPath gp = new GraphicsPath ();
1063 gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 0, 2, Single.MaxValue);
1064 Assert.AreEqual (7, gp.PointCount, "PointCount");
1069 [ExpectedException (typeof (ArgumentException))]
1070 public void AddCurve_ZeroSegments ()
1072 GraphicsPath gp = new GraphicsPath ();
1073 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 0, 0.5f);
1077 [ExpectedException (typeof (ArgumentException))]
1078 public void AddCurve_NegativeSegments ()
1080 GraphicsPath gp = new GraphicsPath ();
1081 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, -1, 0.5f);
1085 [ExpectedException (typeof (ArgumentException))]
1086 public void AddCurve_OffsetTooLarge ()
1088 GraphicsPath gp = new GraphicsPath ();
1089 gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 1, 2, 0.5f);
1093 public void AddCurve_Offset ()
1095 GraphicsPath gp = new GraphicsPath ();
1096 gp.AddCurve (new PointF[4] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f), new PointF (0f, 10f) }, 1, 2, 0.5f);
1097 Assert.AreEqual (7, gp.PointCount, "PointCount");
1101 private FontFamily GetFontFamily ()
1104 return FontFamily.GenericMonospace;
1106 catch (ArgumentException) {
1107 Assert.Ignore ("GenericMonospace FontFamily couldn't be found");
1113 [ExpectedException (typeof (NullReferenceException))]
1114 public void AddString_NullString ()
1116 GraphicsPath gp = new GraphicsPath ();
1117 FontFamily ff = GetFontFamily ();
1118 gp.AddString (null, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1122 public void AddString_EmptyString ()
1124 GraphicsPath gp = new GraphicsPath ();
1125 FontFamily ff = GetFontFamily ();
1126 gp.AddString (String.Empty, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1127 Assert.AreEqual (0, gp.PointCount, "PointCount");
1131 [ExpectedException (typeof (ArgumentException))]
1132 public void AddString_NullFontFamily ()
1134 GraphicsPath gp = new GraphicsPath ();
1135 gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1139 public void AddString_NegativeSize ()
1141 GraphicsPath gp = new GraphicsPath ();
1142 FontFamily ff = GetFontFamily ();
1143 gp.AddString ("mono", ff, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
1144 Assert.IsTrue (gp.PointCount > 0, "PointCount");
1148 [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
1149 public void AddString_StringFormat ()
1151 FontFamily ff = GetFontFamily ();
1153 GraphicsPath gp1 = new GraphicsPath ();
1154 gp1.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), null);
1156 // StringFormat.GenericDefault
1157 GraphicsPath gp2 = new GraphicsPath ();
1158 gp2.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
1159 Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
1161 // StringFormat.GenericTypographic
1162 GraphicsPath gp3 = new GraphicsPath ();
1163 gp3.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
1164 Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
1168 public void GetBounds_Empty_Empty ()
1170 GraphicsPath gp = new GraphicsPath ();
1171 RectangleF rect = gp.GetBounds ();
1172 Assert.AreEqual (0.0f, rect.X, "Bounds.X");
1173 Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
1174 Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
1175 Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
1178 private void CheckRectangleBounds (RectangleF rect)
1180 Assert.AreEqual (1.0f, rect.X, "Bounds.X");
1181 Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
1182 Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
1183 Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
1187 public void GetBounds_Empty_Rectangle ()
1189 GraphicsPath gp = new GraphicsPath ();
1190 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1191 CheckRectangleBounds (gp.GetBounds ());
1195 public void GetBounds_Null_Rectangle ()
1197 GraphicsPath gp = new GraphicsPath ();
1198 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1199 CheckRectangleBounds (gp.GetBounds (null));
1203 public void GetBounds_MatrixEmpty_Rectangle ()
1205 GraphicsPath gp = new GraphicsPath ();
1206 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1207 CheckRectangleBounds (gp.GetBounds (new Matrix ()));
1211 public void GetBounds_NullNull_Rectangle ()
1213 GraphicsPath gp = new GraphicsPath ();
1214 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1215 CheckRectangleBounds (gp.GetBounds (null, null));
1219 [Category ("NotWorking")] // can't/wont duplicate the lack of precision
1220 public void GetBounds_WithPen ()
1222 Rectangle rect = new Rectangle (1, 1, 2, 2);
1223 Pen p = new Pen (Color.Aqua, 0);
1224 GraphicsPath gp = new GraphicsPath ();
1225 gp.AddRectangle (rect);
1227 RectangleF bounds = gp.GetBounds (null, p);
1228 // those bounds doesn't make any sense (even visually)
1229 // probably null gets mis-interpreted ???
1230 Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
1231 Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
1232 Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
1233 Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
1235 Matrix m = new Matrix ();
1236 bounds = gp.GetBounds (m, p);
1237 Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
1238 Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
1239 Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
1240 Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
1241 // visually we can see the bounds just a pixel bigger than the rectangle
1243 gp = new GraphicsPath ();
1244 gp.AddRectangle (rect);
1246 bounds = gp.GetBounds (null);
1247 Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
1248 Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
1249 Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
1250 Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
1252 bounds = gp.GetBounds (m);
1253 Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
1254 Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
1255 Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
1256 Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
1259 private void CheckPieBounds (RectangleF rect)
1261 Assert.AreEqual (60.0f, rect.X, 1, "Bounds.X");
1262 Assert.AreEqual (60.0f, rect.Y, 1, "Bounds.Y");
1263 Assert.AreEqual (43.3f, rect.Width, 1, "Bounds.Width");
1264 Assert.AreEqual (48.3f, rect.Height, 1, "Bounds.Height");
1268 public void GetBounds_Empty_Pie ()
1270 GraphicsPath gp = new GraphicsPath ();
1271 gp.AddPie (10, 10, 100, 100, 30, 45);
1272 CheckPieBounds (gp.GetBounds ());
1277 public void GetBounds_Null_Pie ()
1279 GraphicsPath gp = new GraphicsPath ();
1280 gp.AddPie (10, 10, 100, 100, 30, 45);
1281 CheckPieBounds (gp.GetBounds (null));
1286 public void GetBounds_MatrixEmpty_Pie ()
1288 GraphicsPath gp = new GraphicsPath ();
1289 gp.AddPie (10, 10, 100, 100, 30, 45);
1290 CheckPieBounds (gp.GetBounds (new Matrix ()));
1295 public void GetBounds_NullNull_Pie ()
1297 GraphicsPath gp = new GraphicsPath ();
1298 gp.AddPie (10, 10, 100, 100, 30, 45);
1299 CheckPieBounds (gp.GetBounds (null, null));
1304 public void GetBounds_Empty_ClosedCurve ()
1306 GraphicsPath gp = new GraphicsPath ();
1307 gp.AddClosedCurve (new Point[4] { new Point (20, 100), new Point (70, 10),
1308 new Point (130, 200), new Point (180, 100) });
1310 // so far from reality that it's totally useless
1311 Assert.AreEqual (1.666666f, rect.X, 0.00001, "Bounds.X");
1312 Assert.AreEqual (-6.66666f, rect.Y, 1, "Bounds.Y");
1313 Assert.AreEqual (196.6666f, rect.Width, 1, "Bounds.Width");
1314 Assert.AreEqual (221.6666f, rect.Height, 1, "Bounds.Height");
1320 [ExpectedException (typeof (ArgumentNullException))]
1321 public void Transform_Null ()
1323 new GraphicsPath ().Transform (null);
1327 public void Transform_Empty ()
1329 // no points in path and no exception
1330 new GraphicsPath ().Transform (new Matrix ());
1333 private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
1335 Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
1336 for (int i = 0; i < expected.PointCount; i++) {
1337 Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
1338 Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
1342 private void CompareFlats (GraphicsPath flat, GraphicsPath original)
1344 Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
1345 for (int i = 0; i < flat.PointCount; i++) {
1346 Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
1351 public void Flatten_Empty ()
1353 GraphicsPath path = new GraphicsPath ();
1354 GraphicsPath clone = (GraphicsPath) path.Clone ();
1355 // this is a no-op as there's nothing in the path
1357 ComparePaths (path, clone);
1361 public void Flatten_Null ()
1363 GraphicsPath path = new GraphicsPath ();
1364 GraphicsPath clone = (GraphicsPath) path.Clone ();
1365 // this is a no-op as there's nothing in the path
1366 // an no matrix to apply
1367 path.Flatten (null);
1368 ComparePaths (path, clone);
1372 public void Flatten_NullFloat ()
1374 GraphicsPath path = new GraphicsPath ();
1375 GraphicsPath clone = (GraphicsPath) path.Clone ();
1376 // this is a no-op as there's nothing in the path
1377 // an no matrix to apply
1378 path.Flatten (null, 1f);
1379 ComparePaths (path, clone);
1383 public void Flatten_Arc ()
1385 GraphicsPath path = new GraphicsPath ();
1386 path.AddArc (0f, 0f, 100f, 100f, 30, 30);
1387 GraphicsPath clone = (GraphicsPath) path.Clone ();
1389 CompareFlats (path, clone);
1393 public void Flatten_Bezier ()
1395 GraphicsPath path = new GraphicsPath ();
1396 path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
1397 GraphicsPath clone = (GraphicsPath) path.Clone ();
1399 CompareFlats (path, clone);
1403 public void Flatten_ClosedCurve ()
1405 GraphicsPath path = new GraphicsPath ();
1406 path.AddClosedCurve (new Point[4] {
1407 new Point (0, 0), new Point (40, 20),
1408 new Point (20, 40), new Point (40, 40)
1410 GraphicsPath clone = (GraphicsPath) path.Clone ();
1412 CompareFlats (path, clone);
1416 public void Flatten_Curve ()
1418 GraphicsPath path = new GraphicsPath ();
1419 path.AddCurve (new Point[4] {
1420 new Point (0, 0), new Point (40, 20),
1421 new Point (20, 40), new Point (40, 40)
1423 GraphicsPath clone = (GraphicsPath) path.Clone ();
1425 CompareFlats (path, clone);
1429 public void Flatten_Ellipse ()
1431 GraphicsPath path = new GraphicsPath ();
1432 path.AddEllipse (10f, 10f, 100f, 100f);
1433 GraphicsPath clone = (GraphicsPath) path.Clone ();
1435 CompareFlats (path, clone);
1439 public void Flatten_Line ()
1441 GraphicsPath path = new GraphicsPath ();
1442 path.AddLine (10f, 10f, 100f, 100f);
1443 GraphicsPath clone = (GraphicsPath) path.Clone ();
1445 ComparePaths (path, clone);
1449 public void Flatten_Pie ()
1451 GraphicsPath path = new GraphicsPath ();
1452 path.AddPie (0, 0, 100, 100, 30, 30);
1453 GraphicsPath clone = (GraphicsPath) path.Clone ();
1455 CompareFlats (path, clone);
1459 public void Flatten_Polygon ()
1461 GraphicsPath path = new GraphicsPath ();
1462 path.AddPolygon (new Point[4] {
1463 new Point (0, 0), new Point (10, 10),
1464 new Point (20, 20), new Point (40, 40)
1466 GraphicsPath clone = (GraphicsPath) path.Clone ();
1468 ComparePaths (path, clone);
1472 public void Flatten_Rectangle ()
1474 GraphicsPath path = new GraphicsPath ();
1475 path.AddRectangle (new Rectangle (0, 0, 100, 100));
1476 GraphicsPath clone = (GraphicsPath) path.Clone ();
1478 ComparePaths (path, clone);
1481 private void CheckWrap (GraphicsPath path)
1483 Assert.AreEqual (3, path.PointCount, "Count");
1485 PointF[] pts = path.PathPoints;
1486 Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
1487 Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
1488 Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
1489 Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
1490 Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
1491 Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
1493 byte[] types = path.PathTypes;
1494 Assert.AreEqual (0, types[0], "0");
1495 Assert.AreEqual (1, types[1], "1");
1496 Assert.AreEqual (129, types[2], "2");
1499 private void CheckWrapNaN (GraphicsPath path, bool closed)
1501 Assert.AreEqual (3, path.PointCount, "Count");
1503 PointF[] pts = path.PathPoints;
1504 Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
1505 Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
1506 Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
1507 Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
1508 Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
1509 Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
1511 byte[] types = path.PathTypes;
1512 Assert.AreEqual (0, types[0], "0");
1513 Assert.AreEqual (1, types[1], "1");
1514 Assert.AreEqual (closed ? 129 : 1, types[2], "2");
1518 [ExpectedException (typeof (ArgumentNullException))]
1519 public void Warp_Null ()
1521 new GraphicsPath ().Warp (null, new RectangleF ());
1525 [ExpectedException (typeof (ArgumentException))]
1526 public void Warp_NoPoints ()
1528 new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
1532 public void Wrap_NoPoint ()
1534 using (GraphicsPath gp = new GraphicsPath ()) {
1535 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
1537 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1538 RectangleF r = new RectangleF (10, 20, 30, 40);
1539 gp.Warp (pts, r, new Matrix ());
1540 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
1545 [Category ("NotWorking")]
1546 public void Wrap_SinglePoint ()
1548 using (GraphicsPath gp = new GraphicsPath ()) {
1549 gp.AddLines (new Point[1] { new Point (1, 1) });
1550 // Special case - a line with a single point is valid
1551 Assert.AreEqual (1, gp.PointCount, "PointCount-1");
1553 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1554 RectangleF r = new RectangleF (10, 20, 30, 40);
1555 gp.Warp (pts, r, new Matrix ());
1556 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
1561 [Category ("NotWorking")]
1562 public void Wrap_Line ()
1564 using (GraphicsPath gp = new GraphicsPath ()) {
1565 gp.AddLine (new Point (1, 1), new Point (20, 20));
1566 Assert.AreEqual (2, gp.PointCount, "PointCount-1");
1568 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1569 RectangleF r = new RectangleF (10, 20, 30, 40);
1570 gp.Warp (pts, r, new Matrix ());
1571 Assert.AreEqual (2, gp.PointCount, "PointCount-2");
1576 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1577 public void Warp_NullMatrix ()
1579 PointF[] pts = new PointF[1] { new PointF (0,0) };
1580 GraphicsPath path = new GraphicsPath ();
1581 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1582 RectangleF r = new RectangleF (10, 20, 30, 40);
1583 path.Warp (pts, r, null);
1588 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1589 public void Warp_EmptyMatrix ()
1591 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1592 GraphicsPath path = new GraphicsPath ();
1593 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1594 RectangleF r = new RectangleF (10, 20, 30, 40);
1595 path.Warp (pts, r, new Matrix ());
1600 [Category ("NotWorking")]
1601 public void Warp_Rectangle_Empty ()
1603 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1604 GraphicsPath path = new GraphicsPath ();
1605 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1606 path.Warp (pts, new RectangleF (), null);
1607 CheckWrapNaN (path, true);
1611 [Category ("NotWorking")]
1612 public void Warp_Rectangle_NegativeWidthHeight ()
1614 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1615 GraphicsPath path = new GraphicsPath ();
1616 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1617 RectangleF r = new RectangleF (10, 20, -30, -40);
1618 path.Warp (pts, r, null);
1619 Assert.AreEqual (3, path.PointCount, "Count");
1621 pts = path.PathPoints;
1622 Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
1623 Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
1624 Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
1625 Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
1626 Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
1627 Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
1628 byte[] types = path.PathTypes;
1629 Assert.AreEqual (0, types[0], "0");
1630 Assert.AreEqual (1, types[1], "1");
1631 Assert.AreEqual (129, types[2], "2");
1635 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1636 public void Warp_Matrix_NonInvertible ()
1638 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
1639 Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
1640 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1641 GraphicsPath path = new GraphicsPath ();
1642 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1643 RectangleF r = new RectangleF (10, 20, 30, 40);
1644 path.Warp (pts, r, matrix);
1646 Assert.AreEqual (3, path.PointCount, "Count");
1647 pts = path.PathPoints;
1648 Assert.AreEqual (47, pts[0].X, "0.X");
1649 Assert.AreEqual (30, pts[0].Y, "0.Y");
1650 Assert.AreEqual (47, pts[1].X, "1.X");
1651 Assert.AreEqual (30, pts[1].Y, "1.Y");
1652 Assert.AreEqual (47, pts[2].X, "2.X");
1653 Assert.AreEqual (30, pts[2].Y, "2.Y");
1654 byte[] types = path.PathTypes;
1655 Assert.AreEqual (0, types[0], "0");
1656 Assert.AreEqual (1, types[1], "1");
1657 Assert.AreEqual (129, types[2], "2");
1661 [Category ("NotWorking")]
1662 public void Warp_Bilinear ()
1664 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1665 GraphicsPath path = new GraphicsPath ();
1666 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1667 RectangleF r = new RectangleF (10, 20, 30, 40);
1668 path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
1669 // note that the last point is no more closed
1670 CheckWrapNaN (path, false);
1674 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1675 public void Warp_Perspective ()
1677 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1678 GraphicsPath path = new GraphicsPath ();
1679 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1680 RectangleF r = new RectangleF (10, 20, 30, 40);
1681 path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
1686 public void Warp_Invalid ()
1688 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1689 GraphicsPath path = new GraphicsPath ();
1690 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1691 RectangleF r = new RectangleF (10, 20, 30, 40);
1692 path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
1693 Assert.AreEqual (0, path.PointCount, "Count");
1697 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1698 public void Warp_Flatness_Negative ()
1700 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1701 GraphicsPath path = new GraphicsPath ();
1702 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1703 RectangleF r = new RectangleF (10, 20, 30, 40);
1704 path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
1709 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1710 public void Warp_Flatness_OverOne ()
1712 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1713 GraphicsPath path = new GraphicsPath ();
1714 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1715 RectangleF r = new RectangleF (10, 20, 30, 40);
1716 path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
1721 public void SetMarkers_EmptyPath ()
1723 new GraphicsPath ().SetMarkers ();
1727 public void ClearMarkers_EmptyPath ()
1729 new GraphicsPath ().ClearMarkers ();
1733 public void CloseFigure_EmptyPath ()
1735 new GraphicsPath ().CloseFigure ();
1739 public void CloseAllFigures_EmptyPath ()
1741 new GraphicsPath ().CloseAllFigures ();
1745 public void StartClose_AddArc ()
1747 GraphicsPath path = new GraphicsPath ();
1748 path.AddLine (1, 1, 2, 2);
1749 path.AddArc (10, 10, 100, 100, 90, 180);
1750 path.AddLine (10, 10, 20, 20);
1751 byte[] types = path.PathTypes;
1752 // check first types
1753 Assert.AreEqual (0, types[0], "start/Line");
1754 Assert.AreEqual (1, types[2], "start/Arc");
1756 Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
1757 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1761 public void StartClose_AddBezier ()
1763 GraphicsPath path = new GraphicsPath ();
1764 path.AddLine (1, 1, 2, 2);
1765 path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
1766 path.AddLine (10, 10, 20, 20);
1767 byte[] types = path.PathTypes;
1768 // check first types
1769 Assert.AreEqual (0, types[0], "start/Line");
1770 Assert.AreEqual (1, types[2], "start/Bezier");
1772 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1773 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1777 public void StartClose_AddBeziers ()
1779 GraphicsPath path = new GraphicsPath ();
1780 path.AddLine (1, 1, 2, 2);
1781 path.AddBeziers (new Point[7] { new Point (10, 10),
1782 new Point (20, 10), new Point (20, 20), new Point (30, 20),
1783 new Point (40, 40), new Point (50, 40), new Point (50, 50)
1785 path.AddLine (10, 10, 20, 20);
1786 byte[] types = path.PathTypes;
1787 // check first types
1788 Assert.AreEqual (0, types[0], "start/Line");
1789 Assert.AreEqual (1, types[2], "start/Bezier");
1791 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1792 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1796 public void StartClose_AddClosedCurve ()
1798 GraphicsPath path = new GraphicsPath ();
1799 path.AddLine (1, 1, 2, 2);
1800 path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1801 path.AddLine (10, 10, 20, 20);
1802 byte[] types = path.PathTypes;
1803 // check first types
1804 Assert.AreEqual (0, types[0], "start/Line");
1805 Assert.AreEqual (0, types[2], "start/ClosedCurve");
1807 Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
1808 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1809 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1813 public void StartClose_AddCurve ()
1815 GraphicsPath path = new GraphicsPath ();
1816 path.AddLine (1, 1, 2, 2);
1817 path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1818 path.AddLine (10, 10, 20, 20);
1819 byte[] types = path.PathTypes;
1820 // check first types
1821 Assert.AreEqual (0, types[0], "start/Line");
1822 Assert.AreEqual (1, types[2], "start/Curve");
1824 Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
1825 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1829 public void StartClose_AddEllipse ()
1831 GraphicsPath path = new GraphicsPath ();
1832 path.AddLine (1, 1, 2, 2);
1833 path.AddEllipse (10, 10, 100, 100);
1834 path.AddLine (10, 10, 20, 20);
1835 byte[] types = path.PathTypes;
1836 // check first types
1837 Assert.AreEqual (0, types[0], "start/Line");
1838 Assert.AreEqual (0, types[2], "start/Ellipse");
1840 Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
1841 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1842 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1846 public void StartClose_AddLine ()
1848 GraphicsPath path = new GraphicsPath ();
1849 path.AddLine (1, 1, 2, 2);
1850 path.AddLine (5, 5, 10, 10);
1851 path.AddLine (10, 10, 20, 20);
1852 byte[] types = path.PathTypes;
1853 // check first types
1854 Assert.AreEqual (0, types[0], "start/Line");
1855 Assert.AreEqual (1, types[2], "start/Line2");
1857 Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
1858 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1862 public void StartClose_AddLines ()
1864 GraphicsPath path = new GraphicsPath ();
1865 path.AddLine (1, 1, 2, 2);
1866 path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
1867 path.AddLine (10, 10, 20, 20);
1868 byte[] types = path.PathTypes;
1869 // check first types
1870 Assert.AreEqual (0, types[0], "start/Line");
1871 Assert.AreEqual (1, types[2], "start/Lines");
1873 Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
1874 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1878 public void StartClose_AddPath_Connect ()
1880 GraphicsPath inner = new GraphicsPath ();
1881 inner.AddArc (10, 10, 100, 100, 90, 180);
1882 GraphicsPath path = new GraphicsPath ();
1883 path.AddLine (1, 1, 2, 2);
1884 path.AddPath (inner, true);
1885 path.AddLine (10, 10, 20, 20);
1886 byte[] types = path.PathTypes;
1887 // check first types
1888 Assert.AreEqual (0, types[0], "start/Line");
1889 Assert.AreEqual (1, types[2], "start/Path");
1891 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1892 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1896 public void StartClose_AddPath_NoConnect ()
1898 GraphicsPath inner = new GraphicsPath ();
1899 inner.AddArc (10, 10, 100, 100, 90, 180);
1900 GraphicsPath path = new GraphicsPath ();
1901 path.AddLine (1, 1, 2, 2);
1902 path.AddPath (inner, false);
1903 path.AddLine (10, 10, 20, 20);
1904 byte[] types = path.PathTypes;
1905 // check first types
1906 Assert.AreEqual (0, types[0], "start/Line");
1907 Assert.AreEqual (0, types[2], "start/Path");
1909 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1910 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1914 public void StartClose_AddPie ()
1916 GraphicsPath path = new GraphicsPath ();
1917 path.AddLine (1, 1, 2, 2);
1918 path.AddPie (10, 10, 10, 10, 90, 180);
1919 path.AddLine (10, 10, 20, 20);
1920 byte[] types = path.PathTypes;
1921 // check first types
1922 Assert.AreEqual (0, types[0], "start/Line");
1923 Assert.AreEqual (0, types[2], "start/Pie");
1925 // libgdiplus draws pie by ending with a line (not a curve) section
1926 Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
1927 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1928 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1932 public void StartClose_AddPolygon ()
1934 GraphicsPath path = new GraphicsPath ();
1935 path.AddLine (1, 1, 2, 2);
1936 path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1937 path.AddLine (10, 10, 20, 20);
1938 byte[] types = path.PathTypes;
1939 // check first types
1940 Assert.AreEqual (0, types[0], "start/Line");
1941 Assert.AreEqual (0, types[2], "start/Polygon");
1943 Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
1944 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1945 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1949 public void StartClose_AddRectangle ()
1951 GraphicsPath path = new GraphicsPath ();
1952 path.AddLine (1, 1, 2, 2);
1953 path.AddRectangle (new RectangleF (10, 10, 20, 20));
1954 path.AddLine (10, 10, 20, 20);
1955 byte[] types = path.PathTypes;
1956 // check first types
1957 Assert.AreEqual (0, types[0], "start/Line");
1958 Assert.AreEqual (0, types[2], "start/Rectangle");
1960 Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
1961 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1962 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1966 public void StartClose_AddRectangles ()
1968 GraphicsPath path = new GraphicsPath ();
1969 path.AddLine (1, 1, 2, 2);
1970 path.AddRectangles (new RectangleF[2] {
1971 new RectangleF (10, 10, 20, 20),
1972 new RectangleF (20, 20, 10, 10) });
1973 path.AddLine (10, 10, 20, 20);
1974 byte[] types = path.PathTypes;
1975 // check first types
1976 Assert.AreEqual (0, types[0], "start/Line");
1977 Assert.AreEqual (0, types[2], "start/Rectangles");
1979 Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
1980 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1981 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1985 [Category ("NotWorking")]
1986 public void StartClose_AddString ()
1988 GraphicsPath path = new GraphicsPath ();
1989 path.AddLine (1, 1, 2, 2);
1990 path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
1991 path.AddLine (10, 10, 20, 20);
1992 byte[] types = path.PathTypes;
1993 // check first types
1994 Assert.AreEqual (0, types[0], "start/Line");
1995 Assert.AreEqual (0, types[2], "start/String");
1997 Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
1998 Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
1999 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2003 [ExpectedException (typeof (ArgumentNullException))]
2004 public void Widen_Pen_Null ()
2006 new GraphicsPath ().Widen (null);
2010 [Category ("NotWorking")]
2011 public void Widen_Pen ()
2013 Pen pen = new Pen (Color.Blue);
2014 GraphicsPath path = new GraphicsPath ();
2015 path.AddRectangle (new Rectangle (1, 1, 2, 2));
2016 Assert.AreEqual (4, path.PointCount, "Count-1");
2018 Assert.AreEqual (12, path.PointCount, "Count-2");
2020 PointF[] pts = path.PathPoints;
2021 Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
2022 Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
2023 Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
2024 Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
2025 Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
2026 Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
2027 Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
2028 Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
2029 Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
2030 Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
2031 Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
2032 Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
2033 Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
2034 Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
2035 Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
2036 Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
2037 Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
2038 Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
2039 Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
2040 Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
2041 Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
2042 Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
2043 Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
2044 Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
2046 byte[] types = path.PathTypes;
2047 Assert.AreEqual (0, types[0], "0");
2048 Assert.AreEqual (1, types[1], "1");
2049 Assert.AreEqual (1, types[2], "2");
2050 Assert.AreEqual (129, types[3], "3");
2051 Assert.AreEqual (0, types[4], "4");
2052 Assert.AreEqual (1, types[5], "5");
2053 Assert.AreEqual (1, types[6], "6");
2054 Assert.AreEqual (1, types[7], "7");
2055 Assert.AreEqual (1, types[8], "8");
2056 Assert.AreEqual (1, types[9], "9");
2057 Assert.AreEqual (1, types[10], "10");
2058 Assert.AreEqual (129, types[11], "11");
2062 [ExpectedException (typeof (ArgumentNullException))]
2063 public void Widen_Pen_Null_Matrix ()
2065 new GraphicsPath ().Widen (null, new Matrix ());
2070 [ExpectedException (typeof (OutOfMemoryException))]
2072 public void Widen_NoPoint ()
2074 using (GraphicsPath gp = new GraphicsPath ()) {
2075 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
2076 Pen pen = new Pen (Color.Blue);
2078 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2083 [ExpectedException (typeof (OutOfMemoryException))]
2084 public void Widen_SinglePoint ()
2086 using (GraphicsPath gp = new GraphicsPath ()) {
2087 gp.AddLines (new Point[1] { new Point (1, 1) });
2088 // Special case - a line with a single point is valid
2089 Assert.AreEqual (1, gp.PointCount, "PointCount");
2090 gp.Widen (Pens.Red);
2095 private void CheckWiden3 (GraphicsPath path)
2097 PointF[] pts = path.PathPoints;
2098 Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
2099 Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
2100 Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
2101 Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
2102 Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
2103 Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
2104 Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
2105 Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
2106 Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
2107 Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
2108 Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
2109 Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
2110 Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
2111 Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
2112 Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
2113 Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
2114 Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
2115 Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
2117 byte[] types = path.PathTypes;
2118 Assert.AreEqual (0, types[0], "0");
2119 Assert.AreEqual (1, types[1], "1");
2120 Assert.AreEqual (129, types[2], "2");
2121 Assert.AreEqual (0, types[3], "3");
2122 Assert.AreEqual (1, types[4], "4");
2123 Assert.AreEqual (1, types[5], "5");
2124 Assert.AreEqual (1, types[6], "6");
2125 Assert.AreEqual (1, types[7], "7");
2126 Assert.AreEqual (129, types[8], "8");
2130 [Category ("NotWorking")]
2131 public void Widen_Pen_Matrix_Null ()
2133 Pen pen = new Pen (Color.Blue);
2134 GraphicsPath path = new GraphicsPath ();
2135 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2136 path.Widen (pen, null);
2137 Assert.AreEqual (9, path.PointCount, "Count");
2142 [Category ("NotWorking")]
2143 public void Widen_Pen_Matrix_Empty ()
2145 Pen pen = new Pen (Color.Blue);
2146 GraphicsPath path = new GraphicsPath ();
2147 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2148 path.Widen (pen, new Matrix ());
2149 Assert.AreEqual (9, path.PointCount, "Count");
2154 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2155 public void Widen_Pen_Matrix_NonInvertible ()
2157 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
2158 Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
2159 GraphicsPath path = new GraphicsPath ();
2160 path.Widen (new Pen (Color.Blue), matrix);
2161 Assert.AreEqual (0, path.PointCount, "Points");
2164 private void CheckWidenedBounds (string message, GraphicsPath gp, Matrix m)
2166 RectangleF bounds = gp.GetBounds (m);
2167 Assert.AreEqual (0.5f, bounds.X, 0.00001f, message + ".Bounds.X");
2168 Assert.AreEqual (0.5f, bounds.Y, 0.00001f, message + ".Bounds.Y");
2169 Assert.AreEqual (3.0f, bounds.Width, 0.00001f, message + ".Bounds.Width");
2170 Assert.AreEqual (3.0f, bounds.Height, 0.00001f, message + ".Bounds.Height");
2174 [Category ("NotWorking")]
2175 public void Widen_Pen_SmallWidth ()
2177 Matrix m = new Matrix ();
2178 Rectangle rect = new Rectangle (1, 1, 2, 2);
2180 // pen's smaller than 1.0 (width) are "promoted" to 1
2181 Pen p = new Pen (Color.Aqua, 0);
2182 GraphicsPath gp = new GraphicsPath ();
2183 gp.AddRectangle (rect);
2185 CheckWidenedBounds ("Width == 0, Null matrix", gp, null);
2186 CheckWidenedBounds ("Width == 0, Empty matrix", gp, m);
2189 gp = new GraphicsPath ();
2190 gp.AddRectangle (rect);
2192 CheckWidenedBounds ("Width == 0.5, Null matrix", gp, null);
2193 CheckWidenedBounds ("Width == 0.5, Empty matrix", gp, m);
2196 gp = new GraphicsPath ();
2197 gp.AddRectangle (rect);
2199 CheckWidenedBounds ("Width == 1.0, Null matrix", gp, null);
2200 CheckWidenedBounds ("Width == 1.0, Empty matrix", gp, m);
2203 gp = new GraphicsPath ();
2204 gp.AddRectangle (rect);
2206 RectangleF bounds = gp.GetBounds (m);
2207 Assert.AreEqual (0.45f, bounds.X, 0.00001f, "1.1.Bounds.X");
2208 Assert.AreEqual (0.45f, bounds.Y, 0.00001f, "1.1.Bounds.Y");
2209 Assert.AreEqual (3.10f, bounds.Width, 0.00001f, "1.1.Bounds.Width");
2210 Assert.AreEqual (3.10f, bounds.Height, 0.00001f, "1.1.Bounds.Height");
2214 [ExpectedException (typeof (ArgumentNullException))]
2215 public void IsOutlineVisible_IntNull ()
2217 new GraphicsPath ().IsOutlineVisible (1, 1, null);
2221 [ExpectedException (typeof (ArgumentNullException))]
2222 public void IsOutlineVisible_FloatNull ()
2224 new GraphicsPath ().IsOutlineVisible (1.0f, 1.0f, null);
2228 [ExpectedException (typeof (ArgumentNullException))]
2229 public void IsOutlineVisible_PointNull ()
2231 new GraphicsPath ().IsOutlineVisible (new Point (), null);
2235 [ExpectedException (typeof (ArgumentNullException))]
2236 public void IsOutlineVisible_PointFNull ()
2238 new GraphicsPath ().IsOutlineVisible (new PointF (), null);
2241 private void IsOutlineVisible_Line (Graphics graphics)
2243 Pen p2 = new Pen (Color.Red, 3.0f);
2244 using (GraphicsPath gp = new GraphicsPath ()) {
2245 gp.AddLine (10, 1, 14, 1);
2246 Assert.IsTrue (gp.IsOutlineVisible (10, 1, Pens.Red, graphics), "Int1");
2247 Assert.IsTrue (gp.IsOutlineVisible (10, 2, p2, graphics), "Int2");
2248 Assert.IsFalse (gp.IsOutlineVisible (10, 2, Pens.Red, graphics), "Int3");
2250 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, Pens.Red, graphics), "Float1");
2251 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, p2, graphics), "Float2");
2252 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 2.0f, Pens.Red, graphics), "Float3");
2254 Point pt = new Point (12, 2);
2255 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2256 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2258 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2260 PointF pf = new PointF (13.0f, 2.0f);
2261 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2262 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2264 Assert.IsTrue (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF3");
2270 public void IsOutlineVisible_Line_WithoutGraphics ()
2272 IsOutlineVisible_Line (null);
2276 public void IsOutlineVisible_Line_WithGraphics_Inside ()
2278 using (Bitmap bitmap = new Bitmap (20, 20)) {
2279 using (Graphics g = Graphics.FromImage (bitmap)) {
2280 IsOutlineVisible_Line (g);
2286 public void IsOutlineVisible_Line_WithGraphics_Outside ()
2288 using (Bitmap bitmap = new Bitmap (5, 5)) {
2289 using (Graphics g = Graphics.FromImage (bitmap)) {
2290 IsOutlineVisible_Line (g);
2292 // graphics "seems" ignored as the line is outside the bitmap!
2296 // docs ways the point is in world coordinates and that the graphics transform
2297 // should be applied
2300 public void IsOutlineVisible_Line_WithGraphics_Transform ()
2302 using (Bitmap bitmap = new Bitmap (20, 20)) {
2303 using (Graphics g = Graphics.FromImage (bitmap)) {
2304 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2305 IsOutlineVisible_Line (g);
2307 // graphics still "seems" ignored (Transform)
2312 public void IsOutlineVisible_Line_WithGraphics_PageUnit ()
2314 using (Bitmap bitmap = new Bitmap (20, 20)) {
2315 using (Graphics g = Graphics.FromImage (bitmap)) {
2316 g.PageUnit = GraphicsUnit.Millimeter;
2317 IsOutlineVisible_Line (g);
2319 // graphics still "seems" ignored (PageUnit)
2324 public void IsOutlineVisible_Line_WithGraphics_PageScale ()
2326 using (Bitmap bitmap = new Bitmap (20, 20)) {
2327 using (Graphics g = Graphics.FromImage (bitmap)) {
2329 IsOutlineVisible_Line (g);
2331 // graphics still "seems" ignored (PageScale)
2336 [Category ("NotWorking")]
2337 public void IsOutlineVisible_Line_WithGraphics ()
2339 using (Bitmap bitmap = new Bitmap (20, 20)) {
2340 using (Graphics g = Graphics.FromImage (bitmap)) {
2341 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2342 g.PageUnit = GraphicsUnit.Millimeter;
2344 using (GraphicsPath gp = new GraphicsPath ()) {
2345 gp.AddLine (10, 1, 14, 1);
2346 Assert.IsFalse (gp.IsOutlineVisible (10, 1, Pens.Red, g), "Int1");
2349 // graphics ISN'T ignored (Transform+PageUnit+PageScale)
2354 [Category ("NotWorking")] // looks buggy - reported to MS as FDBK50868
2355 public void IsOutlineVisible_Line_End ()
2358 using (GraphicsPath gp = new GraphicsPath ()) {
2359 gp.AddLine (10, 1, 14, 1);
2360 Assert.IsFalse (gp.IsOutlineVisible (14, 1, Pens.Red, null), "Int1h");
2361 Assert.IsFalse (gp.IsOutlineVisible (13.5f, 1.0f, Pens.Red, null), "Float1h");
2362 Assert.IsTrue (gp.IsOutlineVisible (13.4f, 1.0f, Pens.Red, null), "Float2h");
2363 Assert.IsFalse (gp.IsOutlineVisible (new Point (14, 1), Pens.Red, null), "Point1h");
2364 Assert.IsFalse (gp.IsOutlineVisible (new PointF (13.5f, 1.0f), Pens.Red, null), "PointF1h");
2365 Assert.IsTrue (gp.IsOutlineVisible (new PointF (13.49f, 1.0f), Pens.Red, null), "PointF2h");
2368 using (GraphicsPath gp = new GraphicsPath ()) {
2369 gp.AddLine (1, 10, 1, 14);
2370 Assert.IsFalse (gp.IsOutlineVisible (1, 14, Pens.Red, null), "Int1v");
2371 Assert.IsFalse (gp.IsOutlineVisible (1.0f, 13.5f, Pens.Red, null), "Float1v");
2372 Assert.IsTrue (gp.IsOutlineVisible (1.0f, 13.4f, Pens.Red, null), "Float2v");
2373 Assert.IsFalse (gp.IsOutlineVisible (new Point (1, 14), Pens.Red, null), "Point1v");
2374 Assert.IsFalse (gp.IsOutlineVisible (new PointF (1.0f, 13.5f), Pens.Red, null), "PointF1v");
2375 Assert.IsTrue (gp.IsOutlineVisible (new PointF (1.0f, 13.49f), Pens.Red, null), "PointF2v");
2379 private void IsOutlineVisible_Rectangle (Graphics graphics)
2381 Pen p2 = new Pen (Color.Red, 3.0f);
2382 using (GraphicsPath gp = new GraphicsPath ()) {
2383 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2384 Assert.IsTrue (gp.IsOutlineVisible (10, 10, Pens.Red, graphics), "Int1");
2385 Assert.IsTrue (gp.IsOutlineVisible (10, 11, p2, graphics), "Int2");
2386 Assert.IsFalse (gp.IsOutlineVisible (11, 11, Pens.Red, graphics), "Int3");
2388 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 10.0f, Pens.Red, graphics), "Float1");
2389 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 11.0f, p2, graphics), "Float2");
2390 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 11.0f, Pens.Red, graphics), "Float3");
2392 Point pt = new Point (15, 10);
2393 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2394 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2396 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2398 PointF pf = new PointF (29.0f, 29.0f);
2399 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2400 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2402 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF3");
2408 public void IsOutlineVisible_Rectangle_WithoutGraphics ()
2410 IsOutlineVisible_Rectangle (null);
2413 private void IsVisible_Rectangle (Graphics graphics)
2415 using (GraphicsPath gp = new GraphicsPath ()) {
2416 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2417 Assert.IsFalse (gp.IsVisible (9, 9, graphics), "Int0");
2418 Assert.IsTrue (gp.IsVisible (10, 10, graphics), "Int1");
2419 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2420 Assert.IsTrue (gp.IsVisible (29, 29, graphics), "Int3");
2421 Assert.IsFalse (gp.IsVisible (30, 29, graphics), "Int4");
2422 Assert.IsFalse (gp.IsVisible (29, 30, graphics), "Int5");
2423 Assert.IsFalse (gp.IsVisible (30, 30, graphics), "Int6");
2425 Assert.IsFalse (gp.IsVisible (9.4f, 9.4f, graphics), "Float0");
2426 Assert.IsTrue (gp.IsVisible (9.5f, 9.5f, graphics), "Float1");
2427 Assert.IsTrue (gp.IsVisible (10f, 10f, graphics), "Float2");
2428 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2429 Assert.IsTrue (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2430 Assert.IsFalse (gp.IsVisible (29.5f, 29.5f, graphics), "Float5");
2431 Assert.IsFalse (gp.IsVisible (29.5f, 29.4f, graphics), "Float6");
2432 Assert.IsFalse (gp.IsVisible (29.4f, 29.5f, graphics), "Float7");
2437 public void IsVisible_Rectangle_WithoutGraphics ()
2439 IsVisible_Rectangle (null);
2443 public void IsVisible_Rectangle_WithGraphics ()
2445 using (Bitmap bitmap = new Bitmap (40, 40)) {
2446 using (Graphics g = Graphics.FromImage (bitmap)) {
2447 IsVisible_Rectangle (g);
2453 public void Reverse_Arc ()
2455 using (GraphicsPath gp = new GraphicsPath ()) {
2456 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
2457 PointF[] bp = gp.PathPoints;
2458 byte[] bt = gp.PathTypes;
2461 PointF[] ap = gp.PathPoints;
2462 byte[] at = gp.PathTypes;
2464 int count = gp.PointCount;
2465 Assert.AreEqual (bp.Length, count, "PointCount");
2466 for (int i = 0; i < count; i++) {
2467 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
2468 // PathTypes are NOT reversed
2469 Assert.AreEqual (bt[i], at[i], "Type" + i.ToString ());