2 // System.Drawing.GraphicsPath unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006-2007 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 public void GraphicsPath_SamePoint ()
135 Point[] points = new Point [] {
143 byte [] types = new byte [6] { 0, 1, 1, 1, 1, 1 };
144 using (GraphicsPath gp = new GraphicsPath (points, types)) {
145 Assert.AreEqual (6, gp.PointCount, "0-PointCount");
148 using (GraphicsPath gp = new GraphicsPath (points, types)) {
149 Assert.AreEqual (6, gp.PointCount, "1-PointCount");
154 public void GraphicsPath_SamePointF ()
156 PointF [] points = new PointF [] {
164 byte [] types = new byte [6] { 0, 1, 1, 1, 1, 1 };
165 using (GraphicsPath gp = new GraphicsPath (points, types)) {
166 Assert.AreEqual (6, gp.PointCount, "0-PointCount");
169 using (GraphicsPath gp = new GraphicsPath (points, types)) {
170 Assert.AreEqual (6, gp.PointCount, "1-PointCount");
175 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
176 public void FillMode_Invalid ()
178 // constructor accept an invalid FillMode
179 GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
180 Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
181 // but you can't set the FillMode property to an invalid value ;-)
182 gp.FillMode = (FillMode) Int32.MaxValue;
186 public void PathData_CannotChange ()
188 GraphicsPath gp = new GraphicsPath ();
189 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
191 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
192 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
194 // now try to change the first point
195 gp.PathData.Points[0] = new Point (0, 0);
196 // the changes isn't reflected in the property
197 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
198 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
202 public void PathPoints_CannotChange ()
204 GraphicsPath gp = new GraphicsPath ();
205 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
207 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
208 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
210 // now try to change the first point
211 gp.PathPoints[0] = new Point (0, 0);
212 // the changes isn't reflected in the property
213 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
214 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
218 public void PathTypes_CannotChange ()
220 GraphicsPath gp = new GraphicsPath ();
221 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
223 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
225 // now try to change the first type
227 // the changes isn't reflected in the property
228 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
231 private void CheckArc (GraphicsPath path)
233 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
234 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
235 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
237 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
238 RectangleF rect = path.GetBounds ();
239 Assert.AreEqual (2.99962401f, rect.X, Delta, "Bounds.X");
240 Assert.AreEqual (2.01370716f, rect.Y, Delta, "Bounds.Y");
241 Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
242 Assert.AreEqual (0.0137047768f, rect.Height, "Bounds.Height");
244 Assert.AreEqual (2.99990582f, path.PathData.Points[0].X, Delta, "Points[0].X");
245 Assert.AreEqual (2.01370716f, path.PathPoints[0].Y, Delta, "Points[0].Y");
246 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
247 Assert.AreEqual (2.99984312f, path.PathData.Points[1].X, Delta, "Points[1].X");
248 Assert.AreEqual (2.018276f, path.PathPoints[1].Y, Delta, "Points[1].Y");
249 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
250 Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, Delta, "Points[2].X");
251 Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, Delta, "Points[2].Y");
252 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
253 Assert.AreEqual (2.999624f, path.PathData.Points[3].X, Delta, "Points[3].X");
254 Assert.AreEqual (2.027412f, path.PathPoints[3].Y, Delta, "Points[3].Y");
255 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
259 public void AddArc_Rectangle ()
261 GraphicsPath gp = new GraphicsPath ();
262 gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
267 public void AddArc_RectangleF ()
269 GraphicsPath gp = new GraphicsPath ();
270 gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
275 public void AddArc_Int ()
277 GraphicsPath gp = new GraphicsPath ();
278 gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
283 public void AddArc_Float ()
285 GraphicsPath gp = new GraphicsPath ();
286 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
290 private void CheckBezier (GraphicsPath path)
292 Assert.AreEqual (4, path.PointCount, "PointCount");
293 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
294 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
295 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
297 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
298 RectangleF rect = path.GetBounds ();
299 Assert.AreEqual (1f, rect.X, "Bounds.X");
300 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
301 Assert.AreEqual (3f, rect.Width, "Bounds.Width");
302 Assert.AreEqual (3f, rect.Height, "Bounds.Height");
304 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
305 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
306 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
307 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
308 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
309 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
310 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
311 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
312 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
313 Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
314 Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
315 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
319 public void AddBezier_Point ()
321 GraphicsPath gp = new GraphicsPath ();
322 gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
327 public void AddBezier_PointF ()
329 GraphicsPath gp = new GraphicsPath ();
330 gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
335 public void AddBezier_Int ()
337 GraphicsPath gp = new GraphicsPath ();
338 gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
343 public void AddBezier_Float ()
345 GraphicsPath gp = new GraphicsPath ();
346 gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
351 public void AddBezier_SamePoint ()
353 GraphicsPath gp = new GraphicsPath ();
354 gp.AddBezier (1, 1, 1, 1, 1, 1, 1, 1);
355 // all points are present
356 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
357 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
358 Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]");
359 Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]");
360 Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]");
362 gp.AddBezier (new Point (1, 1), new Point (1, 1), new Point (1, 1), new Point (1, 1));
363 // the first point (move to) can be compressed (i.e. removed)
364 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
365 Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]");
366 Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]");
367 Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]");
371 public void AddBezier_SamePointF ()
373 GraphicsPath gp = new GraphicsPath ();
374 gp.AddBezier (new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f));
375 // all points are present
376 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
377 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
378 Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]");
379 Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]");
380 Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]");
382 gp.AddBezier (new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f));
383 // the first point (move to) can be compressed (i.e. removed)
384 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
385 Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]");
386 Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]");
387 Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]");
391 [ExpectedException (typeof (ArgumentNullException))]
392 public void AddBeziers_Point_Null ()
394 new GraphicsPath ().AddBeziers ((Point[]) null);
398 [ExpectedException (typeof (ArgumentException))]
399 public void AddBeziers_3_Points ()
401 GraphicsPath gp = new GraphicsPath ();
402 gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
406 public void AddBeziers_Point ()
408 GraphicsPath gp = new GraphicsPath ();
409 gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
414 [ExpectedException (typeof (ArgumentNullException))]
415 public void AddBeziers_PointF_Null ()
417 new GraphicsPath ().AddBeziers ((PointF[]) null);
421 [ExpectedException (typeof (ArgumentException))]
422 public void AddBeziers_3_PointFs ()
424 GraphicsPath gp = new GraphicsPath ();
425 gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
429 public void AddBeziers_PointF ()
431 GraphicsPath gp = new GraphicsPath ();
432 gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
437 public void AddBeziers_SamePoint ()
439 Point [] points = new Point [4] { new Point (1, 1), new Point (1, 1), new Point (1, 1), new Point (1, 1) };
440 GraphicsPath gp = new GraphicsPath ();
441 gp.AddBeziers (points);
442 // all points are present
443 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
444 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
445 Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]");
446 Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]");
447 Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]");
449 gp.AddBeziers (points);
450 // the first point (move to) can be compressed (i.e. removed)
451 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
452 Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]");
453 Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]");
454 Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]");
458 public void AddBeziers_SamePointF ()
460 PointF[] points = new PointF [4] { new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f) };
461 GraphicsPath gp = new GraphicsPath ();
462 gp.AddBeziers (points);
463 // all points are present
464 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
465 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
466 Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]");
467 Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]");
468 Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]");
470 gp.AddBeziers (points);
471 // the first point (move to) can be compressed (i.e. removed)
472 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
473 Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]");
474 Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]");
475 Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]");
478 private void CheckEllipse (GraphicsPath path)
480 Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
481 Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
482 Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
484 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
485 RectangleF rect = path.GetBounds ();
486 Assert.AreEqual (1f, rect.X, "Bounds.X");
487 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
488 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
489 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
491 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
492 for (int i = 1; i < 12; i++)
493 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
494 Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
498 public void AddEllipse_Rectangle ()
500 GraphicsPath gp = new GraphicsPath ();
501 gp.AddEllipse (new Rectangle (1, 1, 2, 2));
506 public void AddEllipse_RectangleF ()
508 GraphicsPath gp = new GraphicsPath ();
509 gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
514 public void AddEllipse_Int ()
516 GraphicsPath gp = new GraphicsPath ();
517 gp.AddEllipse (1, 1, 2, 2);
522 public void AddEllipse_Float ()
524 GraphicsPath gp = new GraphicsPath ();
525 gp.AddEllipse (1f, 1f, 2f, 2f);
529 private void CheckLine (GraphicsPath path)
531 Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
532 Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
533 Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
535 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
536 RectangleF rect = path.GetBounds ();
537 Assert.AreEqual (1f, rect.X, "Bounds.X");
538 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
539 Assert.AreEqual (1f, rect.Width, "Bounds.Width");
540 Assert.AreEqual (1f, rect.Height, "Bounds.Height");
542 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
543 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
544 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
545 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
546 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
547 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
551 public void AddLine_Point ()
553 GraphicsPath gp = new GraphicsPath ();
554 gp.AddLine (new Point (1, 1), new Point (2, 2));
559 public void AddLine_PointF ()
561 GraphicsPath gp = new GraphicsPath ();
562 gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
567 public void AddLine_Int ()
569 GraphicsPath gp = new GraphicsPath ();
570 gp.AddLine (1, 1, 2, 2);
575 public void AddLine_Float ()
577 GraphicsPath gp = new GraphicsPath ();
578 gp.AddLine (1f, 1f, 2f, 2f);
583 public void AddLine_SamePoint ()
585 GraphicsPath gp = new GraphicsPath ();
586 gp.AddLine (new Point (1, 1), new Point (1, 1));
587 Assert.AreEqual (2, gp.PointCount, "1-PointCount");
588 Assert.AreEqual (0, gp.PathTypes[0], "1-PathTypes[0]");
589 Assert.AreEqual (1, gp.PathTypes[1], "1-PathTypes[1]");
591 gp.AddLine (new Point (1, 1), new Point (1, 1));
592 // 3 not 4 points, the first point (only) is compressed
593 Assert.AreEqual (3, gp.PointCount, "2-PointCount");
594 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
595 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
596 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
598 gp.AddLine (new Point (1, 1), new Point (1, 1));
599 // 4 not 5 (or 6) points, the first point (only) is compressed
600 Assert.AreEqual (4, gp.PointCount, "3-PointCount");
601 Assert.AreEqual (0, gp.PathTypes [0], "3-PathTypes[0]");
602 Assert.AreEqual (1, gp.PathTypes [1], "3-PathTypes[1]");
603 Assert.AreEqual (1, gp.PathTypes [2], "3-PathTypes[2]");
604 Assert.AreEqual (1, gp.PathTypes [3], "3-PathTypes[3]");
608 public void AddLine_SamePointF ()
610 GraphicsPath gp = new GraphicsPath ();
611 gp.AddLine (new PointF (49.2f, 157f), new PointF (49.2f, 157f));
612 Assert.AreEqual (2, gp.PointCount, "PointCount");
613 Assert.AreEqual (0, gp.PathTypes [0], "PathTypes[0]");
614 Assert.AreEqual (1, gp.PathTypes [1], "PathTypes[1]");
616 gp.AddLine (new PointF (49.2f, 157f), new PointF (49.2f, 157f));
617 // 3 not 4 points, the first point (only) is compressed
618 Assert.AreEqual (3, gp.PointCount, "2-PointCount");
619 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
620 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
621 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
625 public void AddLine_SamePointsF ()
627 GraphicsPath gp = new GraphicsPath ();
628 gp.AddLine (new PointF (49.2f, 157f), new PointF (75.6f, 196f));
629 gp.AddLine (new PointF (75.6f, 196f), new PointF (102f, 209f));
630 Assert.AreEqual (3, gp.PointCount, "1-PointCount");
631 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
632 Assert.AreEqual (1, gp.PathTypes [1], "1-PathTypes[1]");
633 Assert.AreEqual (1, gp.PathTypes [2], "1-PathTypes[2]");
635 gp.AddLine (new PointF (102f, 209f), new PointF (75.6f, 196f));
636 Assert.AreEqual (4, gp.PointCount, "2-PointCount");
637 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
638 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
639 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
640 Assert.AreEqual (1, gp.PathTypes [3], "2-PathTypes[3]");
644 [ExpectedException (typeof (ArgumentNullException))]
645 public void AddLines_Point_Null ()
647 new GraphicsPath ().AddLines ((Point[])null);
651 [ExpectedException (typeof (ArgumentException))]
652 public void AddLines_Point_0 ()
654 GraphicsPath gp = new GraphicsPath ();
655 gp.AddLines (new Point[0]);
660 public void AddLines_Point_1 ()
662 GraphicsPath gp = new GraphicsPath ();
663 gp.AddLines (new Point[1] { new Point (1, 1) });
664 // Special case - a line with a single point is valid
665 Assert.AreEqual (1, gp.PointCount, "PointCount");
666 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
670 public void AddLines_Point ()
672 GraphicsPath gp = new GraphicsPath ();
673 gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
678 [ExpectedException (typeof (ArgumentNullException))]
679 public void AddLines_PointF_Null ()
681 new GraphicsPath ().AddLines ((PointF[]) null);
685 [ExpectedException (typeof (ArgumentException))]
686 public void AddLines_PointF_0 ()
688 GraphicsPath gp = new GraphicsPath ();
689 gp.AddLines (new PointF[0]);
694 public void AddLines_PointF_1 ()
696 GraphicsPath gp = new GraphicsPath ();
697 gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
698 // Special case - a line with a single point is valid
699 Assert.AreEqual (1, gp.PointCount, "PointCount");
700 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
704 public void AddLines_PointF ()
706 GraphicsPath gp = new GraphicsPath ();
707 gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
712 public void AddLines_SamePoint ()
714 Point [] points = new Point [] { new Point (1, 1), new Point (1, 1) };
715 GraphicsPath gp = new GraphicsPath ();
716 gp.AddLines (points);
717 Assert.AreEqual (2, gp.PointCount, "1-PointCount");
718 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
719 Assert.AreEqual (1, gp.PathTypes [1], "1-PathTypes[1]");
721 gp.AddLines (points);
722 // 3 not 4 points, the first point (only) is compressed
723 Assert.AreEqual (3, gp.PointCount, "2-PointCount");
724 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
725 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
726 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
728 gp.AddLines (points);
729 // 4 not 5 (or 6) points, the first point (only) is compressed
730 Assert.AreEqual (4, gp.PointCount, "3-PointCount");
731 Assert.AreEqual (0, gp.PathTypes [0], "3-PathTypes[0]");
732 Assert.AreEqual (1, gp.PathTypes [1], "3-PathTypes[1]");
733 Assert.AreEqual (1, gp.PathTypes [2], "3-PathTypes[2]");
734 Assert.AreEqual (1, gp.PathTypes [3], "3-PathTypes[3]");
738 public void AddLines_SamePointF ()
740 PointF [] points = new PointF [] { new PointF (49.2f, 157f), new PointF (49.2f, 157f), new PointF (49.2f, 157f), new PointF (49.2f, 157f) };
741 GraphicsPath gp = new GraphicsPath ();
742 gp.AddLines (points);
743 // all identical points are added
744 Assert.AreEqual (4, gp.PointCount, "PointCount");
745 Assert.AreEqual (0, gp.PathTypes [0], "PathTypes[0]");
746 Assert.AreEqual (1, gp.PathTypes [1], "PathTypes[1]");
747 Assert.AreEqual (1, gp.PathTypes [2], "PathTypes[2]");
748 Assert.AreEqual (1, gp.PathTypes [3], "PathTypes[3]");
750 gp.AddLines (points);
751 // only the first new point is compressed
752 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
753 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
754 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
755 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
756 Assert.AreEqual (1, gp.PathTypes [3], "2-PathTypes[3]");
757 Assert.AreEqual (1, gp.PathTypes [4], "2-PathTypes[4]");
758 Assert.AreEqual (1, gp.PathTypes [5], "2-PathTypes[5]");
759 Assert.AreEqual (1, gp.PathTypes [6], "2-PathTypes[6]");
762 private void CheckPie (GraphicsPath path)
764 // the number of points generated for a Pie isn't the same between Mono and MS
766 Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
767 Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
768 Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
770 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
771 RectangleF rect = path.GetBounds ();
772 Assert.AreEqual (2f, rect.X, "Bounds.X");
773 Assert.AreEqual (2f, rect.Y, "Bounds.Y");
774 Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
775 Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
777 Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
778 Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
779 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
780 Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
781 Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
782 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
783 Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
784 Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
785 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
786 Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
787 Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
788 Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
789 Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
790 Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
791 Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
796 public void AddPie_Rect ()
798 GraphicsPath gp = new GraphicsPath ();
799 gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
804 public void AddPie_Int ()
806 GraphicsPath gp = new GraphicsPath ();
807 gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
812 public void AddPie_Float ()
814 GraphicsPath gp = new GraphicsPath ();
815 gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
819 private void CheckPolygon (GraphicsPath path)
821 // an extra point is generated by Mono (libgdiplus)
823 Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
824 Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
825 Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
827 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
828 RectangleF rect = path.GetBounds ();
829 Assert.AreEqual (1f, rect.X, "Bounds.X");
830 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
831 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
832 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
834 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
835 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
836 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
837 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
838 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
839 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
840 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
841 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
842 // the extra point change the type of the last point
844 Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
849 [ExpectedException (typeof (ArgumentNullException))]
850 public void AddPolygon_Point_Null ()
852 new GraphicsPath ().AddPolygon ((Point[]) null);
856 [ExpectedException (typeof (ArgumentException))]
857 public void AddPolygon_Point_Empty ()
859 new GraphicsPath ().AddPolygon (new Point[0]);
863 [ExpectedException (typeof (ArgumentException))]
864 public void AddPolygon_Point_1 ()
866 GraphicsPath gp = new GraphicsPath ();
867 gp.AddPolygon (new Point[1] { new Point (1, 1) });
871 [ExpectedException (typeof (ArgumentException))]
872 public void AddPolygon_Point_2 ()
874 GraphicsPath gp = new GraphicsPath ();
875 gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
879 public void AddPolygon_Point_3 ()
881 GraphicsPath gp = new GraphicsPath ();
882 gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
887 [ExpectedException (typeof (ArgumentNullException))]
888 public void AddPolygon_PointF_Null ()
890 new GraphicsPath ().AddPolygon ((PointF[]) null);
894 [ExpectedException (typeof (ArgumentException))]
895 public void AddPolygon_PointF_Empty ()
897 new GraphicsPath ().AddPolygon (new PointF[0]);
901 [ExpectedException (typeof (ArgumentException))]
902 public void AddPolygon_PointF_1 ()
904 GraphicsPath gp = new GraphicsPath ();
905 gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
909 [ExpectedException (typeof (ArgumentException))]
910 public void AddPolygon_PointF_2 ()
912 GraphicsPath gp = new GraphicsPath ();
913 gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
917 public void AddPolygon_PointF_3 ()
919 GraphicsPath gp = new GraphicsPath ();
920 gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
925 public void AddPolygon_SamePoint ()
927 Point [] points = new Point [3] { new Point (1, 1), new Point (1, 1), new Point (1, 1) };
928 GraphicsPath gp = new GraphicsPath ();
929 gp.AddPolygon (points);
930 // all identical points are added
931 Assert.AreEqual (3, gp.PointCount, "PointCount");
932 Assert.AreEqual (0, gp.PathTypes [0], "PathTypes[0]");
933 Assert.AreEqual (1, gp.PathTypes [1], "PathTypes[1]");
934 Assert.AreEqual (129, gp.PathTypes [2], "PathTypes[2]");
936 gp.AddPolygon (points);
937 // all identical points are added (again)
938 Assert.AreEqual (6, gp.PointCount, "2-PointCount");
939 Assert.AreEqual (0, gp.PathTypes [3], "2-PathTypes[3]");
940 Assert.AreEqual (1, gp.PathTypes [4], "2-PathTypes[4]");
941 Assert.AreEqual (129, gp.PathTypes [5], "2-PathTypes[5]");
943 gp.AddLines (points);
944 // all identical points are added as a line (because previous point is closed)
945 Assert.AreEqual (9, gp.PointCount, "3-PointCount");
946 Assert.AreEqual (0, gp.PathTypes [6], "3-PathTypes[6]");
947 Assert.AreEqual (1, gp.PathTypes [7], "3-PathTypes[7]");
948 Assert.AreEqual (1, gp.PathTypes [8], "3-PathTypes[8]");
950 gp.AddPolygon (points);
951 // all identical points are added (again)
952 Assert.AreEqual (12, gp.PointCount, "4-PointCount");
953 Assert.AreEqual (0, gp.PathTypes [9], "4-PathTypes[9]");
954 Assert.AreEqual (1, gp.PathTypes [10], "4-PathTypes[10]");
955 Assert.AreEqual (129, gp.PathTypes [11], "4-PathTypes[11]");
959 public void AddPolygon_SamePointF ()
961 PointF [] points = new PointF [3] { new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f) };
962 GraphicsPath gp = new GraphicsPath ();
963 gp.AddPolygon (points);
964 // all identical points are added
965 Assert.AreEqual (3, gp.PointCount, "PointCount");
966 Assert.AreEqual (0, gp.PathTypes [0], "PathTypes[0]");
967 Assert.AreEqual (1, gp.PathTypes [1], "PathTypes[1]");
968 Assert.AreEqual (129, gp.PathTypes [2], "PathTypes[2]");
970 gp.AddPolygon (points);
971 // all identical points are added (again)
972 Assert.AreEqual (6, gp.PointCount, "2-PointCount");
973 Assert.AreEqual (0, gp.PathTypes [3], "2-PathTypes[3]");
974 Assert.AreEqual (1, gp.PathTypes [4], "2-PathTypes[4]");
975 Assert.AreEqual (129, gp.PathTypes [5], "2-PathTypes[5]");
977 gp.AddLines (points);
978 // all identical points are added as a line (because previous point is closed)
979 Assert.AreEqual (9, gp.PointCount, "3-PointCount");
980 Assert.AreEqual (0, gp.PathTypes [6], "3-PathTypes[6]");
981 Assert.AreEqual (1, gp.PathTypes [7], "3-PathTypes[7]");
982 Assert.AreEqual (1, gp.PathTypes [8], "3-PathTypes[8]");
984 gp.AddPolygon (points);
985 // all identical points are added (again)
986 Assert.AreEqual (12, gp.PointCount, "4-PointCount");
987 Assert.AreEqual (0, gp.PathTypes [9], "4-PathTypes[9]");
988 Assert.AreEqual (1, gp.PathTypes [10], "4-PathTypes[10]");
989 Assert.AreEqual (129, gp.PathTypes [11], "4-PathTypes[11]");
992 private void CheckRectangle (GraphicsPath path, int count)
994 Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
995 Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
996 Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
998 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
999 RectangleF rect = path.GetBounds ();
1000 Assert.AreEqual (1f, rect.X, "Bounds.X");
1001 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
1002 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
1003 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
1005 // check first four points (first rectangle)
1006 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
1007 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
1008 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
1009 Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
1010 Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
1011 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
1012 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
1013 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
1014 Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
1015 Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
1016 Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
1017 Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
1021 public void AddRectangle_Int ()
1023 GraphicsPath gp = new GraphicsPath ();
1024 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1025 CheckRectangle (gp, 4);
1029 public void AddRectangle_Float ()
1031 GraphicsPath gp = new GraphicsPath ();
1032 gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
1033 CheckRectangle (gp, 4);
1037 public void AddRectangle_SamePoint ()
1039 GraphicsPath gp = new GraphicsPath ();
1040 gp.AddRectangle (new Rectangle (1, 1, 0, 0));
1041 Assert.AreEqual (0, gp.PointCount, "0-PointCount");
1043 gp.AddRectangle (new Rectangle (1, 1, 1, 1));
1044 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
1045 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
1046 Assert.AreEqual (1, gp.PathTypes [1], "1-PathTypes[1]");
1047 Assert.AreEqual (1, gp.PathTypes [2], "1-PathTypes[2]");
1048 Assert.AreEqual (129, gp.PathTypes [3], "1-PathTypes[3]");
1049 PointF end = gp.PathPoints [3];
1051 // add rectangle at the last path point
1052 gp.AddRectangle (new Rectangle ((int)end.X, (int)end.Y, 1, 1));
1053 // no compression (different type)
1054 Assert.AreEqual (8, gp.PointCount, "2-PointCount");
1055 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
1056 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
1057 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
1058 Assert.AreEqual (129, gp.PathTypes [3], "2-PathTypes[3]");
1062 public void AddRectangle_SamePointF ()
1064 GraphicsPath gp = new GraphicsPath ();
1065 gp.AddRectangle (new RectangleF (1f, 1f, 0f, 0f));
1066 Assert.AreEqual (0, gp.PointCount, "0-PointCount");
1068 gp.AddRectangle (new RectangleF (1f, 1f, 1f, 1f));
1069 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
1070 Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
1071 Assert.AreEqual (1, gp.PathTypes [1], "1-PathTypes[1]");
1072 Assert.AreEqual (1, gp.PathTypes [2], "1-PathTypes[2]");
1073 Assert.AreEqual (129, gp.PathTypes [3], "1-PathTypes[3]");
1074 PointF end = gp.PathPoints [3];
1076 // add rectangle at the last path point
1077 gp.AddRectangle (new RectangleF (end.X, end.Y, 1f, 1f));
1078 // no compression (different type)
1079 Assert.AreEqual (8, gp.PointCount, "2-PointCount");
1080 Assert.AreEqual (0, gp.PathTypes [0], "2-PathTypes[0]");
1081 Assert.AreEqual (1, gp.PathTypes [1], "2-PathTypes[1]");
1082 Assert.AreEqual (1, gp.PathTypes [2], "2-PathTypes[2]");
1083 Assert.AreEqual (129, gp.PathTypes [3], "2-PathTypes[3]");
1087 [ExpectedException (typeof (ArgumentNullException))]
1088 public void AddRectangles_Int_Null ()
1090 GraphicsPath gp = new GraphicsPath ();
1091 gp.AddRectangles ((Rectangle[]) null);
1095 [ExpectedException (typeof (ArgumentException))]
1096 public void AddRectangles_Int_Empty ()
1098 GraphicsPath gp = new GraphicsPath ();
1099 gp.AddRectangles (new Rectangle[0]);
1100 CheckRectangle (gp, 4);
1104 public void AddRectangles_Int ()
1106 GraphicsPath gp = new GraphicsPath ();
1107 gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
1108 CheckRectangle (gp, 4);
1112 [ExpectedException (typeof (ArgumentNullException))]
1113 public void AddRectangles_Float_Null ()
1115 GraphicsPath gp = new GraphicsPath ();
1116 gp.AddRectangles ((RectangleF[]) null);
1120 [ExpectedException (typeof (ArgumentException))]
1121 public void AddRectangles_Float_Empty ()
1123 GraphicsPath gp = new GraphicsPath ();
1124 gp.AddRectangles ( new RectangleF[0]);
1125 CheckRectangle (gp, 4);
1129 public void AddRectangles_Float ()
1131 GraphicsPath gp = new GraphicsPath ();
1132 gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
1133 CheckRectangle (gp, 4);
1137 public void AddRectangles_Two ()
1139 GraphicsPath gp = new GraphicsPath ();
1140 gp.AddRectangles (new RectangleF[2] {
1141 new RectangleF (1f, 1f, 2f, 2f),
1142 new RectangleF (2f, 2f, 1f, 1f) } );
1143 RectangleF rect = gp.GetBounds ();
1144 Assert.AreEqual (1f, rect.X, "Bounds.X");
1145 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
1146 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
1147 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
1148 // second rectangle is completely within the first one
1149 CheckRectangle (gp, 8);
1153 public void AddRectangles_SamePoint ()
1155 Rectangle r1 = new Rectangle (1, 1, 0, 0);
1156 Rectangle r2 = new Rectangle (1, 1, 1, 1);
1157 Rectangle r3 = new Rectangle (1, 2, 1, 1);
1159 GraphicsPath gp = new GraphicsPath ();
1160 gp.AddRectangles (new Rectangle[] { r1, r2, r3 });
1161 Assert.AreEqual (8, gp.PointCount, "1-PointCount");
1162 // first rect is ignore, then all other 2x4 (8) points are present, no compression
1166 [ExpectedException (typeof (ArgumentNullException))]
1167 public void AddPath_Null ()
1169 new GraphicsPath ().AddPath (null, false);
1173 public void AddPath ()
1175 GraphicsPath gpr = new GraphicsPath ();
1176 gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
1177 GraphicsPath gp = new GraphicsPath ();
1178 gp.AddPath (gpr, true);
1179 CheckRectangle (gp, 4);
1182 private void CheckClosedCurve (GraphicsPath path)
1184 Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
1185 Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
1186 Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
1188 // GetBounds (well GdipGetPathWorldBounds) isn't very precise with curves
1189 RectangleF rect = path.GetBounds ();
1190 Assert.AreEqual (0.8333333f, rect.X, 0.2f, "Bounds.X");
1191 Assert.AreEqual (0.8333333f, rect.Y, 0.2f, "Bounds.Y");
1192 Assert.AreEqual (2.33333278f, rect.Width, 0.4f, "Bounds.Width");
1193 Assert.AreEqual (2.33333278f, rect.Height, 0.4f, "Bounds.Height");
1195 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
1196 for (int i = 1; i < 9; i++)
1197 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
1198 Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
1202 [ExpectedException (typeof (ArgumentNullException))]
1203 public void AddClosedCurve_Point_Null ()
1205 new GraphicsPath ().AddClosedCurve ((Point[])null);
1209 [ExpectedException (typeof (ArgumentException))]
1210 public void AddClosedCurve_Point_0 ()
1212 GraphicsPath gp = new GraphicsPath ();
1213 gp.AddClosedCurve (new Point [0]);
1217 [ExpectedException (typeof (ArgumentException))]
1218 public void AddClosedCurve_Point_1 ()
1220 GraphicsPath gp = new GraphicsPath ();
1221 gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
1225 [ExpectedException (typeof (ArgumentException))]
1226 public void AddClosedCurve_Point_2 ()
1228 GraphicsPath gp = new GraphicsPath ();
1229 gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
1233 public void AddClosedCurve_Point_3 ()
1235 GraphicsPath gp = new GraphicsPath ();
1236 gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1237 CheckClosedCurve (gp);
1241 [ExpectedException (typeof (ArgumentNullException))]
1242 public void AddClosedCurve_PointF_Null ()
1244 new GraphicsPath ().AddClosedCurve ((PointF[]) null);
1248 [ExpectedException (typeof (ArgumentException))]
1249 public void AddClosedCurve_PointF_0 ()
1251 GraphicsPath gp = new GraphicsPath ();
1252 gp.AddClosedCurve (new PointF[0]);
1256 [ExpectedException (typeof (ArgumentException))]
1257 public void AddClosedCurve_PointF_1 ()
1259 GraphicsPath gp = new GraphicsPath ();
1260 gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
1264 [ExpectedException (typeof (ArgumentException))]
1265 public void AddClosedCurve_PointF_2 ()
1267 GraphicsPath gp = new GraphicsPath ();
1268 gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
1272 public void AddClosedCurve_PointF_3 ()
1274 GraphicsPath gp = new GraphicsPath ();
1275 gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
1276 CheckClosedCurve (gp);
1280 public void AddClosedCurve_SamePoint ()
1282 Point [] points = new Point [3] { new Point (1, 1), new Point (1, 1), new Point (1, 1) };
1283 GraphicsPath gp = new GraphicsPath ();
1284 gp.AddClosedCurve (points);
1285 Assert.AreEqual (10, gp.PointCount, "1-PointCount");
1286 gp.AddClosedCurve (points);
1287 Assert.AreEqual (20, gp.PointCount, "2-PointCount");
1291 public void AddClosedCurve_SamePointF ()
1293 PointF [] points = new PointF [3] { new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f) };
1294 GraphicsPath gp = new GraphicsPath ();
1295 gp.AddClosedCurve (points);
1296 Assert.AreEqual (10, gp.PointCount, "1-PointCount");
1297 gp.AddClosedCurve (points);
1298 Assert.AreEqual (20, gp.PointCount, "2-PointCount");
1301 private void CheckCurve (GraphicsPath path)
1303 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
1304 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
1305 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
1307 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
1308 RectangleF rect = path.GetBounds ();
1309 Assert.AreEqual (1.0f, rect.X, "Bounds.X");
1310 Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
1311 Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
1312 Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
1314 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
1315 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
1316 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
1317 // Mono has wrong? results
1319 Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
1320 Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
1322 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
1323 // Mono has wrong? results
1325 Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
1326 Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
1328 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
1329 Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
1330 Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
1331 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
1335 [ExpectedException (typeof (ArgumentNullException))]
1336 public void AddCurve_Point_Null ()
1338 new GraphicsPath ().AddCurve ((Point[]) null);
1342 [ExpectedException (typeof (ArgumentException))]
1343 public void AddCurve_Point_0 ()
1345 GraphicsPath gp = new GraphicsPath ();
1346 gp.AddCurve (new Point[0]);
1350 [ExpectedException (typeof (ArgumentException))]
1351 public void AddCurve_Point_1 ()
1353 GraphicsPath gp = new GraphicsPath ();
1354 gp.AddCurve (new Point[1] { new Point (1, 1) });
1358 public void AddCurve_Point_2 ()
1360 GraphicsPath gp = new GraphicsPath ();
1361 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
1363 // note: GdipAddPathCurveI allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1368 public void AddCurve_Point_2_Tension ()
1370 GraphicsPath gp = new GraphicsPath ();
1371 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 1.0f);
1373 // note: GdipAddPathCurve2I allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1378 [ExpectedException (typeof (ArgumentException))]
1379 public void AddCurve3_Point_2 ()
1381 GraphicsPath gp = new GraphicsPath ();
1382 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 0, 2, 0.5f);
1383 // adding only two points isn't supported by GdipAddCurve3I
1387 [ExpectedException (typeof (ArgumentNullException))]
1388 public void AddCurve_PointF_Null ()
1390 new GraphicsPath ().AddCurve ((PointF[]) null);
1394 [ExpectedException (typeof (ArgumentException))]
1395 public void AddCurve_PointF_0 ()
1397 GraphicsPath gp = new GraphicsPath ();
1398 gp.AddCurve (new PointF[0]);
1402 [ExpectedException (typeof (ArgumentException))]
1403 public void AddCurve_PointF_1 ()
1405 GraphicsPath gp = new GraphicsPath ();
1406 gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
1410 public void AddCurve_PointF_2 ()
1412 GraphicsPath gp = new GraphicsPath ();
1413 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
1415 // note: GdipAddPathCurve allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1420 public void AddCurve_PoinFt_2_Tension ()
1422 GraphicsPath gp = new GraphicsPath ();
1423 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 1.0f);
1425 // note: GdipAddPathCurve2 allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1430 [ExpectedException (typeof (ArgumentException))]
1431 public void AddCurve3_PointF_2 ()
1433 GraphicsPath gp = new GraphicsPath ();
1434 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 2, 0.5f);
1435 // adding only two points isn't supported by GdipAddCurve3
1439 public void AddCurve_LargeTension ()
1441 GraphicsPath gp = new GraphicsPath ();
1442 gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 0, 2, Single.MaxValue);
1443 Assert.AreEqual (7, gp.PointCount, "PointCount");
1448 [ExpectedException (typeof (ArgumentException))]
1449 public void AddCurve_ZeroSegments ()
1451 GraphicsPath gp = new GraphicsPath ();
1452 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 0, 0.5f);
1456 [ExpectedException (typeof (ArgumentException))]
1457 public void AddCurve_NegativeSegments ()
1459 GraphicsPath gp = new GraphicsPath ();
1460 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, -1, 0.5f);
1464 [ExpectedException (typeof (ArgumentException))]
1465 public void AddCurve_OffsetTooLarge ()
1467 GraphicsPath gp = new GraphicsPath ();
1468 gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 1, 2, 0.5f);
1472 public void AddCurve_Offset ()
1474 GraphicsPath gp = new GraphicsPath ();
1475 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);
1476 Assert.AreEqual (7, gp.PointCount, "PointCount");
1481 public void AddCurve_SamePoint ()
1483 Point [] points = new Point [2] { new Point (1, 1), new Point (1, 1) };
1484 GraphicsPath gp = new GraphicsPath ();
1485 gp.AddCurve (points);
1486 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
1487 gp.AddCurve (points);
1488 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
1492 public void AddCurve_SamePointF ()
1494 PointF [] points = new PointF [2] { new PointF (1f, 1f), new PointF (1f, 1f) };
1495 GraphicsPath gp = new GraphicsPath ();
1496 gp.AddCurve (points);
1497 Assert.AreEqual (4, gp.PointCount, "1-PointCount");
1498 gp.AddCurve (points);
1499 Assert.AreEqual (7, gp.PointCount, "2-PointCount");
1503 public void AddCurve ()
1505 PointF [] points = new PointF [] {
1506 new PointF (37f, 185f),
1507 new PointF (99f, 185f),
1508 new PointF (161f, 159f),
1509 new PointF (223f, 185f),
1510 new PointF (285f, 54f),
1512 int[] count = { 4, 7, 10, 13 };
1514 using (GraphicsPath gp = new GraphicsPath ()) {
1515 for (int i = 0; i < points.Length - 1; i++) {
1516 gp.AddCurve (points, i, 1, 0.5f);
1517 // all non-curves points are compressed expect the first one (positioning)
1518 Assert.AreEqual (count [i], gp.PointCount, i.ToString ());
1521 Assert.AreEqual (0, gp.PathData.Types [0], "Types[0]");
1522 Assert.AreEqual (37f, gp.PathData.Points [0].X, 0.001, "Points[0].X");
1523 Assert.AreEqual (185f, gp.PathData.Points [1].Y, 0.001, "Points[0].Y");
1524 Assert.AreEqual (3, gp.PathData.Types [1], "Types[1]");
1525 Assert.AreEqual (47.3334f, gp.PathData.Points [1].X, 0.001, "Points[1].X");
1526 Assert.AreEqual (185f, gp.PathData.Points [1].Y, 0.001, "Points[1].Y");
1527 Assert.AreEqual (3, gp.PathData.Types [2], "Types[2]");
1528 Assert.AreEqual (78.33333f, gp.PathData.Points [2].X, 0.001, "Points[2].X");
1529 Assert.AreEqual (189.3333f, gp.PathData.Points [2].Y, 0.001, "Points[2].Y");
1530 Assert.AreEqual (3, gp.PathData.Types [3], "Types[3]");
1531 Assert.AreEqual (99f, gp.PathData.Points [3].X, 0.001, "Points[3].X");
1532 Assert.AreEqual (185f, gp.PathData.Points [3].Y, 0.001, "Points[3].Y");
1533 Assert.AreEqual (3, gp.PathData.Types [4], "Types[4]");
1534 Assert.AreEqual (119.6667f, gp.PathData.Points [4].X, 0.001, "Points[4].X");
1535 Assert.AreEqual (180.6667f, gp.PathData.Points [4].Y, 0.001, "Points[4].Y");
1536 Assert.AreEqual (3, gp.PathData.Types [5], "Types[5]");
1537 Assert.AreEqual (140.3333f, gp.PathData.Points [5].X, 0.001, "Points[5].X");
1538 Assert.AreEqual (159f, gp.PathData.Points [5].Y, 0.001, "Points[5].Y");
1539 Assert.AreEqual (3, gp.PathData.Types [6], "Types[6]");
1540 Assert.AreEqual (161f, gp.PathData.Points [6].X, 0.001, "Points[6].X");
1541 Assert.AreEqual (159f, gp.PathData.Points [6].Y, 0.001, "Points[6].Y");
1542 Assert.AreEqual (3, gp.PathData.Types [7], "Types[7]");
1543 Assert.AreEqual (181.6667f, gp.PathData.Points [7].X, 0.001, "Points[7].X");
1544 Assert.AreEqual (159f, gp.PathData.Points [7].Y, 0.001, "Points[7].Y");
1545 Assert.AreEqual (3, gp.PathData.Types [8], "Types[8]");
1546 Assert.AreEqual (202.3333f, gp.PathData.Points [8].X, 0.001, "Points[8].X");
1547 Assert.AreEqual (202.5f, gp.PathData.Points [8].Y, 0.001, "Points[8].Y");
1548 Assert.AreEqual (3, gp.PathData.Types [9], "Types[9]");
1549 Assert.AreEqual (223f, gp.PathData.Points [9].X, 0.001, "Points[9].X");
1550 Assert.AreEqual (185f, gp.PathData.Points [9].Y, 0.001, "Points[9].Y");
1551 Assert.AreEqual (3, gp.PathData.Types [10], "Types[10]");
1552 Assert.AreEqual (243.6667f, gp.PathData.Points [10].X, 0.001, "Points[10].X");
1553 Assert.AreEqual (167.5f, gp.PathData.Points [10].Y, 0.001, "Points[10].Y");
1554 Assert.AreEqual (3, gp.PathData.Types [11], "Types[11]");
1555 Assert.AreEqual (274.6667f, gp.PathData.Points [11].X, 0.001, "Points[11].X");
1556 Assert.AreEqual (75.83334f, gp.PathData.Points [11].Y, 0.001, "Points[11].Y");
1557 Assert.AreEqual (3, gp.PathData.Types [12], "Types[12]");
1558 Assert.AreEqual (285f, gp.PathData.Points [12].X, 0.001, "Points[12].X");
1559 Assert.AreEqual (54f, gp.PathData.Points [12].Y, 0.001, "Points[12].Y");
1563 private FontFamily GetFontFamily ()
1566 return FontFamily.GenericMonospace;
1568 catch (ArgumentException) {
1569 Assert.Ignore ("GenericMonospace FontFamily couldn't be found");
1575 [ExpectedException (typeof (NullReferenceException))]
1576 public void AddString_NullString ()
1578 GraphicsPath gp = new GraphicsPath ();
1579 FontFamily ff = GetFontFamily ();
1580 gp.AddString (null, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1584 public void AddString_EmptyString ()
1586 GraphicsPath gp = new GraphicsPath ();
1587 FontFamily ff = GetFontFamily ();
1588 gp.AddString (String.Empty, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1589 Assert.AreEqual (0, gp.PointCount, "PointCount");
1593 [ExpectedException (typeof (ArgumentException))]
1594 public void AddString_NullFontFamily ()
1596 GraphicsPath gp = new GraphicsPath ();
1597 gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1601 public void AddString_NegativeSize ()
1603 GraphicsPath gp = new GraphicsPath ();
1604 FontFamily ff = GetFontFamily ();
1605 gp.AddString ("mono", ff, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
1606 Assert.IsTrue (gp.PointCount > 0, "PointCount");
1610 [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
1611 public void AddString_StringFormat ()
1613 FontFamily ff = GetFontFamily ();
1615 GraphicsPath gp1 = new GraphicsPath ();
1616 gp1.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), null);
1618 // StringFormat.GenericDefault
1619 GraphicsPath gp2 = new GraphicsPath ();
1620 gp2.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
1621 Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
1623 // StringFormat.GenericTypographic
1624 GraphicsPath gp3 = new GraphicsPath ();
1625 gp3.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
1626 Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
1630 public void GetBounds_Empty_Empty ()
1632 GraphicsPath gp = new GraphicsPath ();
1633 RectangleF rect = gp.GetBounds ();
1634 Assert.AreEqual (0.0f, rect.X, "Bounds.X");
1635 Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
1636 Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
1637 Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
1640 private void CheckRectangleBounds (RectangleF rect)
1642 Assert.AreEqual (1.0f, rect.X, "Bounds.X");
1643 Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
1644 Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
1645 Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
1649 public void GetBounds_Empty_Rectangle ()
1651 GraphicsPath gp = new GraphicsPath ();
1652 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1653 CheckRectangleBounds (gp.GetBounds ());
1657 public void GetBounds_Null_Rectangle ()
1659 GraphicsPath gp = new GraphicsPath ();
1660 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1661 CheckRectangleBounds (gp.GetBounds (null));
1665 public void GetBounds_MatrixEmpty_Rectangle ()
1667 GraphicsPath gp = new GraphicsPath ();
1668 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1669 CheckRectangleBounds (gp.GetBounds (new Matrix ()));
1673 public void GetBounds_NullNull_Rectangle ()
1675 GraphicsPath gp = new GraphicsPath ();
1676 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1677 CheckRectangleBounds (gp.GetBounds (null, null));
1681 [Category ("NotWorking")] // can't/wont duplicate the lack of precision
1682 public void GetBounds_WithPen ()
1684 Rectangle rect = new Rectangle (1, 1, 2, 2);
1685 Pen p = new Pen (Color.Aqua, 0);
1686 GraphicsPath gp = new GraphicsPath ();
1687 gp.AddRectangle (rect);
1689 RectangleF bounds = gp.GetBounds (null, p);
1690 // those bounds doesn't make any sense (even visually)
1691 // probably null gets mis-interpreted ???
1692 Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
1693 Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
1694 Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
1695 Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
1697 Matrix m = new Matrix ();
1698 bounds = gp.GetBounds (m, p);
1699 Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
1700 Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
1701 Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
1702 Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
1703 // visually we can see the bounds just a pixel bigger than the rectangle
1705 gp = new GraphicsPath ();
1706 gp.AddRectangle (rect);
1708 bounds = gp.GetBounds (null);
1709 Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
1710 Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
1711 Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
1712 Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
1714 bounds = gp.GetBounds (m);
1715 Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
1716 Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
1717 Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
1718 Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
1721 private void CheckPieBounds (RectangleF rect)
1723 Assert.AreEqual (60.0f, rect.X, 1, "Bounds.X");
1724 Assert.AreEqual (60.0f, rect.Y, 1, "Bounds.Y");
1725 Assert.AreEqual (43.3f, rect.Width, 1, "Bounds.Width");
1726 Assert.AreEqual (48.3f, rect.Height, 1, "Bounds.Height");
1730 public void GetBounds_Empty_Pie ()
1732 GraphicsPath gp = new GraphicsPath ();
1733 gp.AddPie (10, 10, 100, 100, 30, 45);
1734 CheckPieBounds (gp.GetBounds ());
1739 public void GetBounds_Null_Pie ()
1741 GraphicsPath gp = new GraphicsPath ();
1742 gp.AddPie (10, 10, 100, 100, 30, 45);
1743 CheckPieBounds (gp.GetBounds (null));
1748 public void GetBounds_MatrixEmpty_Pie ()
1750 GraphicsPath gp = new GraphicsPath ();
1751 gp.AddPie (10, 10, 100, 100, 30, 45);
1752 CheckPieBounds (gp.GetBounds (new Matrix ()));
1757 public void GetBounds_NullNull_Pie ()
1759 GraphicsPath gp = new GraphicsPath ();
1760 gp.AddPie (10, 10, 100, 100, 30, 45);
1761 CheckPieBounds (gp.GetBounds (null, null));
1766 public void GetBounds_Empty_ClosedCurve ()
1768 GraphicsPath gp = new GraphicsPath ();
1769 gp.AddClosedCurve (new Point[4] { new Point (20, 100), new Point (70, 10),
1770 new Point (130, 200), new Point (180, 100) });
1772 // so far from reality that it's totally useless
1773 Assert.AreEqual (1.666666f, rect.X, 0.00001, "Bounds.X");
1774 Assert.AreEqual (-6.66666f, rect.Y, 1, "Bounds.Y");
1775 Assert.AreEqual (196.6666f, rect.Width, 1, "Bounds.Width");
1776 Assert.AreEqual (221.6666f, rect.Height, 1, "Bounds.Height");
1782 [ExpectedException (typeof (ArgumentNullException))]
1783 public void Transform_Null ()
1785 new GraphicsPath ().Transform (null);
1788 public void Transform_Empty ()
1790 // no points in path and no exception
1791 new GraphicsPath ().Transform (new Matrix ());
1794 private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
1796 Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
1797 for (int i = 0; i < expected.PointCount; i++) {
1798 Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
1799 Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
1803 private void CompareFlats (GraphicsPath flat, GraphicsPath original)
1805 Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
1806 for (int i = 0; i < flat.PointCount; i++) {
1807 Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
1812 public void Flatten_Empty ()
1814 GraphicsPath path = new GraphicsPath ();
1815 GraphicsPath clone = (GraphicsPath) path.Clone ();
1816 // this is a no-op as there's nothing in the path
1818 ComparePaths (path, clone);
1822 public void Flatten_Null ()
1824 GraphicsPath path = new GraphicsPath ();
1825 GraphicsPath clone = (GraphicsPath) path.Clone ();
1826 // this is a no-op as there's nothing in the path
1827 // an no matrix to apply
1828 path.Flatten (null);
1829 ComparePaths (path, clone);
1833 public void Flatten_NullFloat ()
1835 GraphicsPath path = new GraphicsPath ();
1836 GraphicsPath clone = (GraphicsPath) path.Clone ();
1837 // this is a no-op as there's nothing in the path
1838 // an no matrix to apply
1839 path.Flatten (null, 1f);
1840 ComparePaths (path, clone);
1844 public void Flatten_Arc ()
1846 GraphicsPath path = new GraphicsPath ();
1847 path.AddArc (0f, 0f, 100f, 100f, 30, 30);
1848 GraphicsPath clone = (GraphicsPath) path.Clone ();
1850 CompareFlats (path, clone);
1854 public void Flatten_Bezier ()
1856 GraphicsPath path = new GraphicsPath ();
1857 path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
1858 GraphicsPath clone = (GraphicsPath) path.Clone ();
1860 CompareFlats (path, clone);
1864 public void Flatten_ClosedCurve ()
1866 GraphicsPath path = new GraphicsPath ();
1867 path.AddClosedCurve (new Point[4] {
1868 new Point (0, 0), new Point (40, 20),
1869 new Point (20, 40), new Point (40, 40)
1871 GraphicsPath clone = (GraphicsPath) path.Clone ();
1873 CompareFlats (path, clone);
1877 public void Flatten_Curve ()
1879 GraphicsPath path = new GraphicsPath ();
1880 path.AddCurve (new Point[4] {
1881 new Point (0, 0), new Point (40, 20),
1882 new Point (20, 40), new Point (40, 40)
1884 GraphicsPath clone = (GraphicsPath) path.Clone ();
1886 CompareFlats (path, clone);
1890 public void Flatten_Ellipse ()
1892 GraphicsPath path = new GraphicsPath ();
1893 path.AddEllipse (10f, 10f, 100f, 100f);
1894 GraphicsPath clone = (GraphicsPath) path.Clone ();
1896 CompareFlats (path, clone);
1900 public void Flatten_Line ()
1902 GraphicsPath path = new GraphicsPath ();
1903 path.AddLine (10f, 10f, 100f, 100f);
1904 GraphicsPath clone = (GraphicsPath) path.Clone ();
1906 ComparePaths (path, clone);
1910 public void Flatten_Pie ()
1912 GraphicsPath path = new GraphicsPath ();
1913 path.AddPie (0, 0, 100, 100, 30, 30);
1914 GraphicsPath clone = (GraphicsPath) path.Clone ();
1916 CompareFlats (path, clone);
1920 public void Flatten_Polygon ()
1922 GraphicsPath path = new GraphicsPath ();
1923 path.AddPolygon (new Point[4] {
1924 new Point (0, 0), new Point (10, 10),
1925 new Point (20, 20), new Point (40, 40)
1927 GraphicsPath clone = (GraphicsPath) path.Clone ();
1929 ComparePaths (path, clone);
1933 public void Flatten_Rectangle ()
1935 GraphicsPath path = new GraphicsPath ();
1936 path.AddRectangle (new Rectangle (0, 0, 100, 100));
1937 GraphicsPath clone = (GraphicsPath) path.Clone ();
1939 ComparePaths (path, clone);
1942 private void CheckWrap (GraphicsPath path)
1944 Assert.AreEqual (3, path.PointCount, "Count");
1946 PointF[] pts = path.PathPoints;
1947 Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
1948 Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
1949 Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
1950 Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
1951 Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
1952 Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
1954 byte[] types = path.PathTypes;
1955 Assert.AreEqual (0, types[0], "0");
1956 Assert.AreEqual (1, types[1], "1");
1957 Assert.AreEqual (129, types[2], "2");
1960 private void CheckWrapNaN (GraphicsPath path, bool closed)
1962 Assert.AreEqual (3, path.PointCount, "Count");
1964 PointF[] pts = path.PathPoints;
1965 Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
1966 Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
1967 Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
1968 Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
1969 Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
1970 Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
1972 byte[] types = path.PathTypes;
1973 Assert.AreEqual (0, types[0], "0");
1974 Assert.AreEqual (1, types[1], "1");
1975 Assert.AreEqual (closed ? 129 : 1, types[2], "2");
1979 [ExpectedException (typeof (ArgumentNullException))]
1980 public void Warp_Null ()
1982 new GraphicsPath ().Warp (null, new RectangleF ());
1986 [ExpectedException (typeof (ArgumentException))]
1987 public void Warp_NoPoints ()
1989 new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
1993 public void Wrap_NoPoint ()
1995 using (GraphicsPath gp = new GraphicsPath ()) {
1996 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
1998 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1999 RectangleF r = new RectangleF (10, 20, 30, 40);
2000 gp.Warp (pts, r, new Matrix ());
2001 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2006 [Category ("NotWorking")]
2007 public void Wrap_SinglePoint ()
2009 using (GraphicsPath gp = new GraphicsPath ()) {
2010 gp.AddLines (new Point[1] { new Point (1, 1) });
2011 // Special case - a line with a single point is valid
2012 Assert.AreEqual (1, gp.PointCount, "PointCount-1");
2014 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2015 RectangleF r = new RectangleF (10, 20, 30, 40);
2016 gp.Warp (pts, r, new Matrix ());
2017 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2022 [Category ("NotWorking")]
2023 public void Wrap_Line ()
2025 using (GraphicsPath gp = new GraphicsPath ()) {
2026 gp.AddLine (new Point (1, 1), new Point (20, 20));
2027 Assert.AreEqual (2, gp.PointCount, "PointCount-1");
2029 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2030 RectangleF r = new RectangleF (10, 20, 30, 40);
2031 gp.Warp (pts, r, new Matrix ());
2032 Assert.AreEqual (2, gp.PointCount, "PointCount-2");
2037 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2038 public void Warp_NullMatrix ()
2040 PointF[] pts = new PointF[1] { new PointF (0,0) };
2041 GraphicsPath path = new GraphicsPath ();
2042 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2043 RectangleF r = new RectangleF (10, 20, 30, 40);
2044 path.Warp (pts, r, null);
2049 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2050 public void Warp_EmptyMatrix ()
2052 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2053 GraphicsPath path = new GraphicsPath ();
2054 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2055 RectangleF r = new RectangleF (10, 20, 30, 40);
2056 path.Warp (pts, r, new Matrix ());
2061 [Category ("NotWorking")]
2062 public void Warp_Rectangle_Empty ()
2064 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2065 GraphicsPath path = new GraphicsPath ();
2066 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2067 path.Warp (pts, new RectangleF (), null);
2068 CheckWrapNaN (path, true);
2072 [Category ("NotWorking")]
2073 public void Warp_Rectangle_NegativeWidthHeight ()
2075 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2076 GraphicsPath path = new GraphicsPath ();
2077 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2078 RectangleF r = new RectangleF (10, 20, -30, -40);
2079 path.Warp (pts, r, null);
2080 Assert.AreEqual (3, path.PointCount, "Count");
2082 pts = path.PathPoints;
2083 Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
2084 Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
2085 Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
2086 Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
2087 Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
2088 Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
2089 byte[] types = path.PathTypes;
2090 Assert.AreEqual (0, types[0], "0");
2091 Assert.AreEqual (1, types[1], "1");
2092 Assert.AreEqual (129, types[2], "2");
2096 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2097 public void Warp_Matrix_NonInvertible ()
2099 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
2100 Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
2101 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2102 GraphicsPath path = new GraphicsPath ();
2103 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2104 RectangleF r = new RectangleF (10, 20, 30, 40);
2105 path.Warp (pts, r, matrix);
2107 Assert.AreEqual (3, path.PointCount, "Count");
2108 pts = path.PathPoints;
2109 Assert.AreEqual (47, pts[0].X, "0.X");
2110 Assert.AreEqual (30, pts[0].Y, "0.Y");
2111 Assert.AreEqual (47, pts[1].X, "1.X");
2112 Assert.AreEqual (30, pts[1].Y, "1.Y");
2113 Assert.AreEqual (47, pts[2].X, "2.X");
2114 Assert.AreEqual (30, pts[2].Y, "2.Y");
2115 byte[] types = path.PathTypes;
2116 Assert.AreEqual (0, types[0], "0");
2117 Assert.AreEqual (1, types[1], "1");
2118 Assert.AreEqual (129, types[2], "2");
2122 [Category ("NotWorking")]
2123 public void Warp_Bilinear ()
2125 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2126 GraphicsPath path = new GraphicsPath ();
2127 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2128 RectangleF r = new RectangleF (10, 20, 30, 40);
2129 path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
2130 // note that the last point is no more closed
2131 CheckWrapNaN (path, false);
2135 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2136 public void Warp_Perspective ()
2138 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2139 GraphicsPath path = new GraphicsPath ();
2140 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2141 RectangleF r = new RectangleF (10, 20, 30, 40);
2142 path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
2147 public void Warp_Invalid ()
2149 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2150 GraphicsPath path = new GraphicsPath ();
2151 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2152 RectangleF r = new RectangleF (10, 20, 30, 40);
2153 path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
2154 Assert.AreEqual (0, path.PointCount, "Count");
2158 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2159 public void Warp_Flatness_Negative ()
2161 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2162 GraphicsPath path = new GraphicsPath ();
2163 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2164 RectangleF r = new RectangleF (10, 20, 30, 40);
2165 path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
2170 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2171 public void Warp_Flatness_OverOne ()
2173 PointF[] pts = new PointF[1] { new PointF (0, 0) };
2174 GraphicsPath path = new GraphicsPath ();
2175 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2176 RectangleF r = new RectangleF (10, 20, 30, 40);
2177 path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
2182 public void SetMarkers_EmptyPath ()
2184 new GraphicsPath ().SetMarkers ();
2188 public void ClearMarkers_EmptyPath ()
2190 new GraphicsPath ().ClearMarkers ();
2194 public void CloseFigure_EmptyPath ()
2196 new GraphicsPath ().CloseFigure ();
2200 public void CloseAllFigures_EmptyPath ()
2202 new GraphicsPath ().CloseAllFigures ();
2206 public void StartClose_AddArc ()
2208 GraphicsPath path = new GraphicsPath ();
2209 path.AddLine (1, 1, 2, 2);
2210 path.AddArc (10, 10, 100, 100, 90, 180);
2211 path.AddLine (10, 10, 20, 20);
2212 byte[] types = path.PathTypes;
2213 // check first types
2214 Assert.AreEqual (0, types[0], "start/Line");
2215 Assert.AreEqual (1, types[2], "start/Arc");
2217 Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
2218 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2222 public void StartClose_AddBezier ()
2224 GraphicsPath path = new GraphicsPath ();
2225 path.AddLine (1, 1, 2, 2);
2226 path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
2227 path.AddLine (10, 10, 20, 20);
2228 byte[] types = path.PathTypes;
2229 // check first types
2230 Assert.AreEqual (0, types[0], "start/Line");
2231 Assert.AreEqual (1, types[2], "start/Bezier");
2233 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
2234 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2238 public void StartClose_AddBeziers ()
2240 GraphicsPath path = new GraphicsPath ();
2241 path.AddLine (1, 1, 2, 2);
2242 path.AddBeziers (new Point[7] { new Point (10, 10),
2243 new Point (20, 10), new Point (20, 20), new Point (30, 20),
2244 new Point (40, 40), new Point (50, 40), new Point (50, 50)
2246 path.AddLine (10, 10, 20, 20);
2247 byte[] types = path.PathTypes;
2248 // check first types
2249 Assert.AreEqual (0, types[0], "start/Line");
2250 Assert.AreEqual (1, types[2], "start/Bezier");
2252 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
2253 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2257 public void StartClose_AddClosedCurve ()
2259 GraphicsPath path = new GraphicsPath ();
2260 path.AddLine (1, 1, 2, 2);
2261 path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
2262 path.AddLine (10, 10, 20, 20);
2263 byte[] types = path.PathTypes;
2264 // check first types
2265 Assert.AreEqual (0, types[0], "start/Line");
2266 Assert.AreEqual (0, types[2], "start/ClosedCurve");
2268 Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
2269 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
2270 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
2274 public void StartClose_AddCurve ()
2276 GraphicsPath path = new GraphicsPath ();
2277 path.AddLine (1, 1, 2, 2);
2278 path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
2279 path.AddLine (10, 10, 20, 20);
2280 byte[] types = path.PathTypes;
2281 // check first types
2282 Assert.AreEqual (0, types[0], "start/Line");
2283 Assert.AreEqual (1, types[2], "start/Curve");
2285 Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
2286 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2290 public void StartClose_AddEllipse ()
2292 GraphicsPath path = new GraphicsPath ();
2293 path.AddLine (1, 1, 2, 2);
2294 path.AddEllipse (10, 10, 100, 100);
2295 path.AddLine (10, 10, 20, 20);
2296 byte[] types = path.PathTypes;
2297 // check first types
2298 Assert.AreEqual (0, types[0], "start/Line");
2299 Assert.AreEqual (0, types[2], "start/Ellipse");
2301 Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
2302 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
2303 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
2307 public void StartClose_AddLine ()
2309 GraphicsPath path = new GraphicsPath ();
2310 path.AddLine (1, 1, 2, 2);
2311 path.AddLine (5, 5, 10, 10);
2312 path.AddLine (10, 10, 20, 20);
2313 byte[] types = path.PathTypes;
2314 // check first types
2315 Assert.AreEqual (0, types[0], "start/Line");
2316 Assert.AreEqual (1, types[2], "start/Line2");
2318 Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
2319 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2323 public void StartClose_AddLines ()
2325 GraphicsPath path = new GraphicsPath ();
2326 path.AddLine (1, 1, 2, 2);
2327 path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
2328 path.AddLine (10, 10, 20, 20);
2329 byte[] types = path.PathTypes;
2330 // check first types
2331 Assert.AreEqual (0, types[0], "start/Line");
2332 Assert.AreEqual (1, types[2], "start/Lines");
2334 Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
2335 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2339 public void StartClose_AddPath_Connect ()
2341 GraphicsPath inner = new GraphicsPath ();
2342 inner.AddArc (10, 10, 100, 100, 90, 180);
2343 GraphicsPath path = new GraphicsPath ();
2344 path.AddLine (1, 1, 2, 2);
2345 path.AddPath (inner, true);
2346 path.AddLine (10, 10, 20, 20);
2347 byte[] types = path.PathTypes;
2348 // check first types
2349 Assert.AreEqual (0, types[0], "start/Line");
2350 Assert.AreEqual (1, types[2], "start/Path");
2352 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
2353 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2357 public void StartClose_AddPath_NoConnect ()
2359 GraphicsPath inner = new GraphicsPath ();
2360 inner.AddArc (10, 10, 100, 100, 90, 180);
2361 GraphicsPath path = new GraphicsPath ();
2362 path.AddLine (1, 1, 2, 2);
2363 path.AddPath (inner, false);
2364 path.AddLine (10, 10, 20, 20);
2365 byte[] types = path.PathTypes;
2366 // check first types
2367 Assert.AreEqual (0, types[0], "start/Line");
2368 Assert.AreEqual (0, types[2], "start/Path");
2370 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
2371 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2375 public void StartClose_AddPie ()
2377 GraphicsPath path = new GraphicsPath ();
2378 path.AddLine (1, 1, 2, 2);
2379 path.AddPie (10, 10, 10, 10, 90, 180);
2380 path.AddLine (10, 10, 20, 20);
2381 byte[] types = path.PathTypes;
2382 // check first types
2383 Assert.AreEqual (0, types[0], "start/Line");
2384 Assert.AreEqual (0, types[2], "start/Pie");
2386 // libgdiplus draws pie by ending with a line (not a curve) section
2387 Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
2388 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
2389 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2393 public void StartClose_AddPolygon ()
2395 GraphicsPath path = new GraphicsPath ();
2396 path.AddLine (1, 1, 2, 2);
2397 path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
2398 path.AddLine (10, 10, 20, 20);
2399 byte[] types = path.PathTypes;
2400 // check first types
2401 Assert.AreEqual (0, types[0], "start/Line");
2402 Assert.AreEqual (0, types[2], "start/Polygon");
2404 Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
2405 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
2406 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2410 public void StartClose_AddRectangle ()
2412 GraphicsPath path = new GraphicsPath ();
2413 path.AddLine (1, 1, 2, 2);
2414 path.AddRectangle (new RectangleF (10, 10, 20, 20));
2415 path.AddLine (10, 10, 20, 20);
2416 byte[] types = path.PathTypes;
2417 // check first types
2418 Assert.AreEqual (0, types[0], "start/Line");
2419 Assert.AreEqual (0, types[2], "start/Rectangle");
2421 Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
2422 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
2423 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2427 public void StartClose_AddRectangles ()
2429 GraphicsPath path = new GraphicsPath ();
2430 path.AddLine (1, 1, 2, 2);
2431 path.AddRectangles (new RectangleF[2] {
2432 new RectangleF (10, 10, 20, 20),
2433 new RectangleF (20, 20, 10, 10) });
2434 path.AddLine (10, 10, 20, 20);
2435 byte[] types = path.PathTypes;
2436 // check first types
2437 Assert.AreEqual (0, types[0], "start/Line");
2438 Assert.AreEqual (0, types[2], "start/Rectangles");
2440 Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
2441 Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
2442 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2446 [Category ("NotWorking")]
2447 public void StartClose_AddString ()
2449 GraphicsPath path = new GraphicsPath ();
2450 path.AddLine (1, 1, 2, 2);
2451 path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
2452 path.AddLine (10, 10, 20, 20);
2453 byte[] types = path.PathTypes;
2454 // check first types
2455 Assert.AreEqual (0, types[0], "start/Line");
2456 Assert.AreEqual (0, types[2], "start/String");
2458 Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
2459 Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
2460 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2464 [ExpectedException (typeof (ArgumentNullException))]
2465 public void Widen_Pen_Null ()
2467 new GraphicsPath ().Widen (null);
2471 [Category ("NotWorking")]
2472 public void Widen_Pen ()
2474 Pen pen = new Pen (Color.Blue);
2475 GraphicsPath path = new GraphicsPath ();
2476 path.AddRectangle (new Rectangle (1, 1, 2, 2));
2477 Assert.AreEqual (4, path.PointCount, "Count-1");
2479 Assert.AreEqual (12, path.PointCount, "Count-2");
2481 PointF[] pts = path.PathPoints;
2482 Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
2483 Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
2484 Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
2485 Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
2486 Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
2487 Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
2488 Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
2489 Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
2490 Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
2491 Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
2492 Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
2493 Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
2494 Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
2495 Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
2496 Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
2497 Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
2498 Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
2499 Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
2500 Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
2501 Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
2502 Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
2503 Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
2504 Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
2505 Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
2507 byte[] types = path.PathTypes;
2508 Assert.AreEqual (0, types[0], "0");
2509 Assert.AreEqual (1, types[1], "1");
2510 Assert.AreEqual (1, types[2], "2");
2511 Assert.AreEqual (129, types[3], "3");
2512 Assert.AreEqual (0, types[4], "4");
2513 Assert.AreEqual (1, types[5], "5");
2514 Assert.AreEqual (1, types[6], "6");
2515 Assert.AreEqual (1, types[7], "7");
2516 Assert.AreEqual (1, types[8], "8");
2517 Assert.AreEqual (1, types[9], "9");
2518 Assert.AreEqual (1, types[10], "10");
2519 Assert.AreEqual (129, types[11], "11");
2523 [ExpectedException (typeof (ArgumentNullException))]
2524 public void Widen_Pen_Null_Matrix ()
2526 new GraphicsPath ().Widen (null, new Matrix ());
2531 [ExpectedException (typeof (OutOfMemoryException))]
2533 public void Widen_NoPoint ()
2535 using (GraphicsPath gp = new GraphicsPath ()) {
2536 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
2537 Pen pen = new Pen (Color.Blue);
2539 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2544 [ExpectedException (typeof (OutOfMemoryException))]
2545 public void Widen_SinglePoint ()
2547 using (GraphicsPath gp = new GraphicsPath ()) {
2548 gp.AddLines (new Point[1] { new Point (1, 1) });
2549 // Special case - a line with a single point is valid
2550 Assert.AreEqual (1, gp.PointCount, "PointCount");
2551 gp.Widen (Pens.Red);
2556 private void CheckWiden3 (GraphicsPath path)
2558 PointF[] pts = path.PathPoints;
2559 Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
2560 Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
2561 Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
2562 Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
2563 Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
2564 Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
2565 Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
2566 Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
2567 Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
2568 Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
2569 Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
2570 Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
2571 Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
2572 Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
2573 Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
2574 Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
2575 Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
2576 Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
2578 byte[] types = path.PathTypes;
2579 Assert.AreEqual (0, types[0], "0");
2580 Assert.AreEqual (1, types[1], "1");
2581 Assert.AreEqual (129, types[2], "2");
2582 Assert.AreEqual (0, types[3], "3");
2583 Assert.AreEqual (1, types[4], "4");
2584 Assert.AreEqual (1, types[5], "5");
2585 Assert.AreEqual (1, types[6], "6");
2586 Assert.AreEqual (1, types[7], "7");
2587 Assert.AreEqual (129, types[8], "8");
2591 [Category ("NotWorking")]
2592 public void Widen_Pen_Matrix_Null ()
2594 Pen pen = new Pen (Color.Blue);
2595 GraphicsPath path = new GraphicsPath ();
2596 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2597 path.Widen (pen, null);
2598 Assert.AreEqual (9, path.PointCount, "Count");
2603 [Category ("NotWorking")]
2604 public void Widen_Pen_Matrix_Empty ()
2606 Pen pen = new Pen (Color.Blue);
2607 GraphicsPath path = new GraphicsPath ();
2608 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2609 path.Widen (pen, new Matrix ());
2610 Assert.AreEqual (9, path.PointCount, "Count");
2615 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2616 public void Widen_Pen_Matrix_NonInvertible ()
2618 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
2619 Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
2620 GraphicsPath path = new GraphicsPath ();
2621 path.Widen (new Pen (Color.Blue), matrix);
2622 Assert.AreEqual (0, path.PointCount, "Points");
2625 private void CheckWidenedBounds (string message, GraphicsPath gp, Matrix m)
2627 RectangleF bounds = gp.GetBounds (m);
2628 Assert.AreEqual (0.5f, bounds.X, 0.00001f, message + ".Bounds.X");
2629 Assert.AreEqual (0.5f, bounds.Y, 0.00001f, message + ".Bounds.Y");
2630 Assert.AreEqual (3.0f, bounds.Width, 0.00001f, message + ".Bounds.Width");
2631 Assert.AreEqual (3.0f, bounds.Height, 0.00001f, message + ".Bounds.Height");
2635 [Category ("NotWorking")]
2636 public void Widen_Pen_SmallWidth ()
2638 Matrix m = new Matrix ();
2639 Rectangle rect = new Rectangle (1, 1, 2, 2);
2641 // pen's smaller than 1.0 (width) are "promoted" to 1
2642 Pen p = new Pen (Color.Aqua, 0);
2643 GraphicsPath gp = new GraphicsPath ();
2644 gp.AddRectangle (rect);
2646 CheckWidenedBounds ("Width == 0, Null matrix", gp, null);
2647 CheckWidenedBounds ("Width == 0, Empty matrix", gp, m);
2650 gp = new GraphicsPath ();
2651 gp.AddRectangle (rect);
2653 CheckWidenedBounds ("Width == 0.5, Null matrix", gp, null);
2654 CheckWidenedBounds ("Width == 0.5, Empty matrix", gp, m);
2657 gp = new GraphicsPath ();
2658 gp.AddRectangle (rect);
2660 CheckWidenedBounds ("Width == 1.0, Null matrix", gp, null);
2661 CheckWidenedBounds ("Width == 1.0, Empty matrix", gp, m);
2664 gp = new GraphicsPath ();
2665 gp.AddRectangle (rect);
2667 RectangleF bounds = gp.GetBounds (m);
2668 Assert.AreEqual (0.45f, bounds.X, 0.00001f, "1.1.Bounds.X");
2669 Assert.AreEqual (0.45f, bounds.Y, 0.00001f, "1.1.Bounds.Y");
2670 Assert.AreEqual (3.10f, bounds.Width, 0.00001f, "1.1.Bounds.Width");
2671 Assert.AreEqual (3.10f, bounds.Height, 0.00001f, "1.1.Bounds.Height");
2675 [ExpectedException (typeof (ArgumentNullException))]
2676 public void IsOutlineVisible_IntNull ()
2678 new GraphicsPath ().IsOutlineVisible (1, 1, null);
2682 [ExpectedException (typeof (ArgumentNullException))]
2683 public void IsOutlineVisible_FloatNull ()
2685 new GraphicsPath ().IsOutlineVisible (1.0f, 1.0f, null);
2689 [ExpectedException (typeof (ArgumentNullException))]
2690 public void IsOutlineVisible_PointNull ()
2692 new GraphicsPath ().IsOutlineVisible (new Point (), null);
2696 [ExpectedException (typeof (ArgumentNullException))]
2697 public void IsOutlineVisible_PointFNull ()
2699 new GraphicsPath ().IsOutlineVisible (new PointF (), null);
2702 private void IsOutlineVisible_Line (Graphics graphics)
2704 Pen p2 = new Pen (Color.Red, 3.0f);
2705 using (GraphicsPath gp = new GraphicsPath ()) {
2706 gp.AddLine (10, 1, 14, 1);
2707 Assert.IsTrue (gp.IsOutlineVisible (10, 1, Pens.Red, graphics), "Int1");
2708 Assert.IsTrue (gp.IsOutlineVisible (10, 2, p2, graphics), "Int2");
2709 Assert.IsFalse (gp.IsOutlineVisible (10, 2, Pens.Red, graphics), "Int3");
2711 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, Pens.Red, graphics), "Float1");
2712 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, p2, graphics), "Float2");
2713 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 2.0f, Pens.Red, graphics), "Float3");
2715 Point pt = new Point (12, 2);
2716 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2717 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2719 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2721 PointF pf = new PointF (13.0f, 2.0f);
2722 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2723 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2725 Assert.IsTrue (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF3");
2731 public void IsOutlineVisible_Line_WithoutGraphics ()
2733 IsOutlineVisible_Line (null);
2737 public void IsOutlineVisible_Line_WithGraphics_Inside ()
2739 using (Bitmap bitmap = new Bitmap (20, 20)) {
2740 using (Graphics g = Graphics.FromImage (bitmap)) {
2741 IsOutlineVisible_Line (g);
2747 public void IsOutlineVisible_Line_WithGraphics_Outside ()
2749 using (Bitmap bitmap = new Bitmap (5, 5)) {
2750 using (Graphics g = Graphics.FromImage (bitmap)) {
2751 IsOutlineVisible_Line (g);
2753 // graphics "seems" ignored as the line is outside the bitmap!
2757 // docs ways the point is in world coordinates and that the graphics transform
2758 // should be applied
2761 public void IsOutlineVisible_Line_WithGraphics_Transform ()
2763 using (Bitmap bitmap = new Bitmap (20, 20)) {
2764 using (Graphics g = Graphics.FromImage (bitmap)) {
2765 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2766 IsOutlineVisible_Line (g);
2768 // graphics still "seems" ignored (Transform)
2773 public void IsOutlineVisible_Line_WithGraphics_PageUnit ()
2775 using (Bitmap bitmap = new Bitmap (20, 20)) {
2776 using (Graphics g = Graphics.FromImage (bitmap)) {
2777 g.PageUnit = GraphicsUnit.Millimeter;
2778 IsOutlineVisible_Line (g);
2780 // graphics still "seems" ignored (PageUnit)
2785 public void IsOutlineVisible_Line_WithGraphics_PageScale ()
2787 using (Bitmap bitmap = new Bitmap (20, 20)) {
2788 using (Graphics g = Graphics.FromImage (bitmap)) {
2790 IsOutlineVisible_Line (g);
2792 // graphics still "seems" ignored (PageScale)
2797 [Category ("NotWorking")]
2798 public void IsOutlineVisible_Line_WithGraphics ()
2800 using (Bitmap bitmap = new Bitmap (20, 20)) {
2801 using (Graphics g = Graphics.FromImage (bitmap)) {
2802 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2803 g.PageUnit = GraphicsUnit.Millimeter;
2805 using (GraphicsPath gp = new GraphicsPath ()) {
2806 gp.AddLine (10, 1, 14, 1);
2807 Assert.IsFalse (gp.IsOutlineVisible (10, 1, Pens.Red, g), "Int1");
2810 // graphics ISN'T ignored (Transform+PageUnit+PageScale)
2815 [Category ("NotWorking")] // looks buggy - reported to MS as FDBK50868
2816 public void IsOutlineVisible_Line_End ()
2819 using (GraphicsPath gp = new GraphicsPath ()) {
2820 gp.AddLine (10, 1, 14, 1);
2821 Assert.IsFalse (gp.IsOutlineVisible (14, 1, Pens.Red, null), "Int1h");
2822 Assert.IsFalse (gp.IsOutlineVisible (13.5f, 1.0f, Pens.Red, null), "Float1h");
2823 Assert.IsTrue (gp.IsOutlineVisible (13.4f, 1.0f, Pens.Red, null), "Float2h");
2824 Assert.IsFalse (gp.IsOutlineVisible (new Point (14, 1), Pens.Red, null), "Point1h");
2825 Assert.IsFalse (gp.IsOutlineVisible (new PointF (13.5f, 1.0f), Pens.Red, null), "PointF1h");
2826 Assert.IsTrue (gp.IsOutlineVisible (new PointF (13.49f, 1.0f), Pens.Red, null), "PointF2h");
2829 using (GraphicsPath gp = new GraphicsPath ()) {
2830 gp.AddLine (1, 10, 1, 14);
2831 Assert.IsFalse (gp.IsOutlineVisible (1, 14, Pens.Red, null), "Int1v");
2832 Assert.IsFalse (gp.IsOutlineVisible (1.0f, 13.5f, Pens.Red, null), "Float1v");
2833 Assert.IsTrue (gp.IsOutlineVisible (1.0f, 13.4f, Pens.Red, null), "Float2v");
2834 Assert.IsFalse (gp.IsOutlineVisible (new Point (1, 14), Pens.Red, null), "Point1v");
2835 Assert.IsFalse (gp.IsOutlineVisible (new PointF (1.0f, 13.5f), Pens.Red, null), "PointF1v");
2836 Assert.IsTrue (gp.IsOutlineVisible (new PointF (1.0f, 13.49f), Pens.Red, null), "PointF2v");
2840 private void IsOutlineVisible_Rectangle (Graphics graphics)
2842 Pen p2 = new Pen (Color.Red, 3.0f);
2843 using (GraphicsPath gp = new GraphicsPath ()) {
2844 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2845 Assert.IsTrue (gp.IsOutlineVisible (10, 10, Pens.Red, graphics), "Int1");
2846 Assert.IsTrue (gp.IsOutlineVisible (10, 11, p2, graphics), "Int2");
2847 Assert.IsFalse (gp.IsOutlineVisible (11, 11, Pens.Red, graphics), "Int3");
2849 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 10.0f, Pens.Red, graphics), "Float1");
2850 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 11.0f, p2, graphics), "Float2");
2851 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 11.0f, Pens.Red, graphics), "Float3");
2853 Point pt = new Point (15, 10);
2854 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2855 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2857 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2859 PointF pf = new PointF (29.0f, 29.0f);
2860 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2861 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2863 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF3");
2869 public void IsOutlineVisible_Rectangle_WithoutGraphics ()
2871 IsOutlineVisible_Rectangle (null);
2874 private void IsVisible_Rectangle (Graphics graphics)
2876 using (GraphicsPath gp = new GraphicsPath ()) {
2877 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2878 Assert.IsFalse (gp.IsVisible (9, 9, graphics), "Int0");
2879 Assert.IsTrue (gp.IsVisible (10, 10, graphics), "Int1");
2880 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2881 Assert.IsTrue (gp.IsVisible (29, 29, graphics), "Int3");
2882 Assert.IsFalse (gp.IsVisible (30, 29, graphics), "Int4");
2883 Assert.IsFalse (gp.IsVisible (29, 30, graphics), "Int5");
2884 Assert.IsFalse (gp.IsVisible (30, 30, graphics), "Int6");
2886 Assert.IsFalse (gp.IsVisible (9.4f, 9.4f, graphics), "Float0");
2887 Assert.IsTrue (gp.IsVisible (9.5f, 9.5f, graphics), "Float1");
2888 Assert.IsTrue (gp.IsVisible (10f, 10f, graphics), "Float2");
2889 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2890 // the next diff is too close, so this fails with libgdiplus/cairo
2891 //Assert.IsTrue (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2892 Assert.IsFalse (gp.IsVisible (29.5f, 29.5f, graphics), "Float5");
2893 Assert.IsFalse (gp.IsVisible (29.5f, 29.4f, graphics), "Float6");
2894 Assert.IsFalse (gp.IsVisible (29.4f, 29.5f, graphics), "Float7");
2899 public void IsVisible_Rectangle_WithoutGraphics ()
2901 IsVisible_Rectangle (null);
2905 public void IsVisible_Rectangle_WithGraphics ()
2907 using (Bitmap bitmap = new Bitmap (40, 40)) {
2908 using (Graphics g = Graphics.FromImage (bitmap)) {
2909 IsVisible_Rectangle (g);
2914 // bug #325502 has shown that ellipse didn't work with earlier code
2915 private void IsVisible_Ellipse (Graphics graphics)
2917 using (GraphicsPath gp = new GraphicsPath ()) {
2918 gp.AddEllipse (new Rectangle (10, 10, 20, 20));
2919 Assert.IsFalse (gp.IsVisible (10, 10, graphics), "Int1");
2920 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2921 Assert.IsFalse (gp.IsVisible (29, 29, graphics), "Int3");
2923 Assert.IsFalse (gp.IsVisible (10f, 10f, graphics), "Float2");
2924 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2925 Assert.IsFalse (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2930 public void IsVisible_Ellipse_WithoutGraphics ()
2932 IsVisible_Ellipse (null);
2936 public void IsVisible_Ellipse_WithGraphics ()
2938 using (Bitmap bitmap = new Bitmap (40, 40)) {
2939 using (Graphics g = Graphics.FromImage (bitmap)) {
2940 IsVisible_Ellipse (g);
2945 // Reverse simple test cases
2947 private void Reverse (GraphicsPath gp)
2949 PointF[] bp = gp.PathPoints;
2950 byte[] bt = gp.PathTypes;
2953 PointF[] ap = gp.PathPoints;
2954 byte[] at = gp.PathTypes;
2956 int count = gp.PointCount;
2957 Assert.AreEqual (bp.Length, count, "PointCount");
2958 for (int i = 0; i < count; i++) {
2959 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
2960 Assert.AreEqual (bt[i], at[i], "Type" + i.ToString ());
2965 public void Reverse_Arc ()
2967 using (GraphicsPath gp = new GraphicsPath ()) {
2968 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
2974 public void Reverse_Bezier ()
2976 using (GraphicsPath gp = new GraphicsPath ()) {
2977 gp.AddBezier (1, 2, 3, 4, 5, 6, 7, 8);
2983 public void Reverse_Beziers ()
2985 using (GraphicsPath gp = new GraphicsPath ()) {
2986 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
2987 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
2988 gp.AddBeziers (beziers);
2994 public void Reverse_ClosedCurve ()
2996 using (GraphicsPath gp = new GraphicsPath ()) {
2997 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
2998 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
2999 gp.AddClosedCurve (beziers);
3005 public void Reverse_Curve ()
3007 using (GraphicsPath gp = new GraphicsPath ()) {
3008 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3009 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3010 gp.AddCurve (beziers);
3016 public void Reverse_Ellipse ()
3018 using (GraphicsPath gp = new GraphicsPath ()) {
3019 gp.AddEllipse (1, 2, 3, 4);
3025 public void Reverse_Line ()
3027 using (GraphicsPath gp = new GraphicsPath ()) {
3028 gp.AddLine (1, 2, 3, 4);
3034 public void Reverse_Line_Closed ()
3036 using (GraphicsPath gp = new GraphicsPath ()) {
3037 gp.AddLine (1, 2, 3, 4);
3044 public void Reverse_Lines ()
3046 using (GraphicsPath gp = new GraphicsPath ()) {
3047 Point[] points = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3048 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3049 gp.AddLines (points);
3055 public void Reverse_Polygon ()
3057 using (GraphicsPath gp = new GraphicsPath ()) {
3058 Point[] points = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3059 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3060 gp.AddPolygon (points);
3066 public void Reverse_Rectangle ()
3068 using (GraphicsPath gp = new GraphicsPath ()) {
3069 gp.AddRectangle (new Rectangle (1,2,3,4));
3075 public void Reverse_Rectangles ()
3077 using (GraphicsPath gp = new GraphicsPath ()) {
3078 Rectangle[] rects = new Rectangle[] { new Rectangle (1, 2, 3, 4), new Rectangle (5, 6, 7, 8) };
3079 gp.AddRectangles (rects);
3084 // Reverse complex test cases
3087 [Category ("NotWorking")] // the output differs from GDI+ and libgdiplus
3088 public void Reverse_Pie ()
3090 using (GraphicsPath gp = new GraphicsPath ()) {
3091 gp.AddPie (1, 2, 3, 4, 10, 20);
3092 PointF[] bp = gp.PathPoints;
3093 byte[] expected = new byte[] { 0, 3, 3, 3, 129 };
3096 PointF[] ap = gp.PathPoints;
3097 byte[] at = gp.PathTypes;
3098 int count = gp.PointCount;
3099 Assert.AreEqual (bp.Length, count, "PointCount");
3100 for (int i = 0; i < count; i++) {
3101 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3102 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3108 public void Reverse_Path ()
3110 using (GraphicsPath gp = new GraphicsPath ()) {
3111 GraphicsPath path = new GraphicsPath ();
3112 path.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
3113 path.AddLine (1, 2, 3, 4);
3114 gp.AddPath (path, true);
3115 PointF[] bp = gp.PathPoints;
3116 byte[] expected = new byte[] { 0, 1, 1, 3, 3, 3 };
3119 PointF[] ap = gp.PathPoints;
3120 byte[] at = gp.PathTypes;
3122 int count = gp.PointCount;
3123 Assert.AreEqual (bp.Length, count, "PointCount");
3124 for (int i = 0; i < count; i++) {
3125 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3126 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3132 public void Reverse_Path_2 ()
3134 using (GraphicsPath gp = new GraphicsPath ()) {
3135 gp.AddEllipse (50, 51, 50, 100);
3136 gp.AddRectangle (new Rectangle (200, 201, 60, 61));
3137 PointF[] bp = gp.PathPoints;
3138 byte[] expected = new byte[] { 0, 1, 1, 129, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131 };
3141 PointF[] ap = gp.PathPoints;
3142 byte[] at = gp.PathTypes;
3144 int count = gp.PointCount;
3145 Assert.AreEqual (bp.Length, count, "PointCount");
3146 for (int i = 0; i < count; i++) {
3147 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3148 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3154 [Category ("NotWorking")] // the output differs from GDI+ and libgdiplus
3155 public void Reverse_String ()
3157 using (GraphicsPath gp = new GraphicsPath ()) {
3158 FontFamily ff = GetFontFamily ();
3159 gp.AddString ("Mono::", ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
3160 PointF[] bp = gp.PathPoints;
3161 byte[] expected = new byte[] { 0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,129,0,3,3,3,
3162 3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,161,0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,
3163 3,3,3,3,3,3,3,129,0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,161,0,3,3,3,3,3,
3164 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,131,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3165 163,0,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,
3166 1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,
3167 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,161,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,131,
3168 0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,163,0,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,
3169 3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,
3170 1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,129 };
3173 PointF[] ap = gp.PathPoints;
3174 byte[] at = gp.PathTypes;
3176 int count = gp.PointCount;
3177 Assert.AreEqual (bp.Length, count, "PointCount");
3178 for (int i = 0; i < count; i++) {
3179 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3180 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3186 public void Reverse_Marker ()
3188 using (GraphicsPath gp = new GraphicsPath ()) {
3189 gp.AddRectangle (new Rectangle (200, 201, 60, 61));
3191 PointF[] bp = gp.PathPoints;
3192 byte[] expected = new byte[] { 0, 1, 1, 129 };
3195 PointF[] ap = gp.PathPoints;
3196 byte[] at = gp.PathTypes;
3198 int count = gp.PointCount;
3199 Assert.AreEqual (bp.Length, count, "PointCount");
3200 for (int i = 0; i < count; i++) {
3201 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3202 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3208 public void Reverse_Subpath_Marker ()
3210 using (GraphicsPath gp = new GraphicsPath ()) {
3211 gp.AddLine (0, 1, 2, 3);
3214 gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12);
3216 PointF[] bp = gp.PathPoints;
3217 byte[] expected = new byte[] { 0, 3, 3, 163, 0, 129 };
3220 PointF[] ap = gp.PathPoints;
3221 byte[] at = gp.PathTypes;
3223 int count = gp.PointCount;
3224 Assert.AreEqual (bp.Length, count, "PointCount");
3225 for (int i = 0; i < count; i++) {
3226 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3227 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3233 public void Reverse_Subpath_Marker_2 ()
3235 using (GraphicsPath gp = new GraphicsPath ()) {
3236 gp.AddLine (0, 1, 2, 3);
3239 gp.AddLine (20, 21, 22, 23);
3240 gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12);
3241 PointF[] bp = gp.PathPoints;
3242 byte[] expected = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 };
3245 PointF[] ap = gp.PathPoints;
3246 byte[] at = gp.PathTypes;
3248 int count = gp.PointCount;
3249 Assert.AreEqual (bp.Length, count, "PointCount");
3250 for (int i = 0; i < count; i++) {
3251 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3252 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3258 public void bug413461 ()
3262 Point[] expected_points = new Point [] {
3263 new Point(dX-64, dY-24),//start
3264 new Point(dX-59, dY-34),//focal point 1
3265 new Point(dX-52, dY-54),//focal point 2
3266 new Point(dX-18, dY-66),//top
3267 new Point(dX-34, dY-47),//focal point 1
3268 new Point(dX-43, dY-27),//focal point 2
3269 new Point(dX-44, dY-8),//end
3271 byte[] expected_types = new byte [] {
3272 (byte)PathPointType.Start,
3273 (byte)PathPointType.Bezier,
3274 (byte)PathPointType.Bezier,
3275 (byte)PathPointType.Bezier,
3276 (byte)PathPointType.Bezier,
3277 (byte)PathPointType.Bezier,
3278 (byte)PathPointType.Bezier };
3279 using (GraphicsPath path = new GraphicsPath (expected_points, expected_types)) {
3280 Assert.AreEqual (7, path.PointCount, "PathCount");
3281 byte [] actual_types = path.PathTypes;
3282 Assert.AreEqual (expected_types [0], actual_types [0], "types-0");
3283 Assert.AreEqual (expected_types [1], actual_types [1], "types-1");
3284 Assert.AreEqual (expected_types [2], actual_types [2], "types-2");
3285 Assert.AreEqual (expected_types [3], actual_types [3], "types-3");
3286 Assert.AreEqual (expected_types [4], actual_types [4], "types-4");
3287 Assert.AreEqual (expected_types [5], actual_types [5], "types-5");
3288 // path is filled like closed but this does not show on the type
3289 Assert.AreEqual (expected_types [6], actual_types [6], "types-6");