[bcl] Remove ONLY_1_1 defines from class libs
[mono-project.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / GraphicsPathTest.cs
blob1d44f318763de5d215b9aaed666c3b779e3f5df9
1 //
2 // System.Drawing.GraphicsPath unit tests
3 //
4 // Authors:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
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.
29 using System;
30 using SC = System.ComponentModel;
31 using System.Drawing;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing.Drawing2D {
38 [TestFixture]
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");
53 [Test]
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);
61 [Test]
62 [ExpectedException (typeof (ArgumentNullException))]
63 public void Constructor_Point_Null_Byte ()
65 new GraphicsPath ((Point[]) null, new byte[1]);
68 [Test]
69 [ExpectedException (typeof (NullReferenceException))]
70 public void Constructor_Point_Byte_Null ()
72 new GraphicsPath (new Point[1], null);
75 [Test]
76 [ExpectedException (typeof (ArgumentException))]
77 public void Constructor_Point_Byte_LengthMismatch ()
79 new GraphicsPath (new Point[1], new byte [2]);
82 [Test]
83 [ExpectedException (typeof (ArgumentNullException))]
84 public void Constructor_PointF_Null_Byte ()
86 new GraphicsPath ((PointF[])null, new byte [1]);
89 [Test]
90 [ExpectedException (typeof (NullReferenceException))]
91 public void Constructor_PointF_Byte_Null ()
93 new GraphicsPath ( new PointF[1], null);
96 [Test]
97 [ExpectedException (typeof (ArgumentException))]
98 public void Constructor_PointF_Byte_LengthMismatch ()
100 new GraphicsPath (new PointF[2], new byte [1]);
103 [Test]
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);
114 gp.Reverse ();
115 CheckEmpty ("Reverse.", gp);
118 [Test]
119 [ExpectedException (typeof (ArgumentException))]
120 public void GraphicsPath_Empty_PathPoints ()
122 Assert.IsNull (new GraphicsPath ().PathPoints);
125 [Test]
126 [ExpectedException (typeof (ArgumentException))]
127 public void GraphicsPath_Empty_PathTypes ()
129 Assert.IsNull (new GraphicsPath ().PathTypes);
132 [Test]
133 public void GraphicsPath_SamePoint ()
135 Point[] points = new Point [] {
136 new Point (1, 1),
137 new Point (1, 1),
138 new Point (1, 1),
139 new Point (1, 1),
140 new Point (1, 1),
141 new Point (1, 1),
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");
147 types [0] = 1;
148 using (GraphicsPath gp = new GraphicsPath (points, types)) {
149 Assert.AreEqual (6, gp.PointCount, "1-PointCount");
153 [Test]
154 public void GraphicsPath_SamePointF ()
156 PointF [] points = new PointF [] {
157 new PointF (1f, 1f),
158 new PointF (1f, 1f),
159 new PointF (1f, 1f),
160 new PointF (1f, 1f),
161 new PointF (1f, 1f),
162 new PointF (1f, 1f),
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");
168 types [0] = 1;
169 using (GraphicsPath gp = new GraphicsPath (points, types)) {
170 Assert.AreEqual (6, gp.PointCount, "1-PointCount");
174 [Test]
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;
185 [Test]
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");
201 [Test]
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");
217 [Test]
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
226 gp.PathTypes[0] = 1;
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]");
258 [Test]
259 public void AddArc_Rectangle ()
261 GraphicsPath gp = new GraphicsPath ();
262 gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
263 CheckArc (gp);
266 [Test]
267 public void AddArc_RectangleF ()
269 GraphicsPath gp = new GraphicsPath ();
270 gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
271 CheckArc (gp);
274 [Test]
275 public void AddArc_Int ()
277 GraphicsPath gp = new GraphicsPath ();
278 gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
279 CheckArc (gp);
282 [Test]
283 public void AddArc_Float ()
285 GraphicsPath gp = new GraphicsPath ();
286 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
287 CheckArc (gp);
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]");
318 [Test]
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));
323 CheckBezier (gp);
326 [Test]
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));
331 CheckBezier (gp);
334 [Test]
335 public void AddBezier_Int ()
337 GraphicsPath gp = new GraphicsPath ();
338 gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
339 CheckBezier (gp);
342 [Test]
343 public void AddBezier_Float ()
345 GraphicsPath gp = new GraphicsPath ();
346 gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
347 CheckBezier (gp);
350 [Test]
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]");
370 [Test]
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]");
390 [Test]
391 [ExpectedException (typeof (ArgumentNullException))]
392 public void AddBeziers_Point_Null ()
394 new GraphicsPath ().AddBeziers ((Point[]) null);
397 [Test]
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) });
405 [Test]
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) });
410 CheckBezier (gp);
413 [Test]
414 [ExpectedException (typeof (ArgumentNullException))]
415 public void AddBeziers_PointF_Null ()
417 new GraphicsPath ().AddBeziers ((PointF[]) null);
420 [Test]
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) });
428 [Test]
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) });
433 CheckBezier (gp);
436 [Test]
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]");
457 [Test]
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]");
497 [Test]
498 public void AddEllipse_Rectangle ()
500 GraphicsPath gp = new GraphicsPath ();
501 gp.AddEllipse (new Rectangle (1, 1, 2, 2));
502 CheckEllipse (gp);
505 [Test]
506 public void AddEllipse_RectangleF ()
508 GraphicsPath gp = new GraphicsPath ();
509 gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
510 CheckEllipse (gp);
513 [Test]
514 public void AddEllipse_Int ()
516 GraphicsPath gp = new GraphicsPath ();
517 gp.AddEllipse (1, 1, 2, 2);
518 CheckEllipse (gp);
521 [Test]
522 public void AddEllipse_Float ()
524 GraphicsPath gp = new GraphicsPath ();
525 gp.AddEllipse (1f, 1f, 2f, 2f);
526 CheckEllipse (gp);
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]");
550 [Test]
551 public void AddLine_Point ()
553 GraphicsPath gp = new GraphicsPath ();
554 gp.AddLine (new Point (1, 1), new Point (2, 2));
555 CheckLine (gp);
558 [Test]
559 public void AddLine_PointF ()
561 GraphicsPath gp = new GraphicsPath ();
562 gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
563 CheckLine (gp);
566 [Test]
567 public void AddLine_Int ()
569 GraphicsPath gp = new GraphicsPath ();
570 gp.AddLine (1, 1, 2, 2);
571 CheckLine (gp);
574 [Test]
575 public void AddLine_Float ()
577 GraphicsPath gp = new GraphicsPath ();
578 gp.AddLine (1f, 1f, 2f, 2f);
579 CheckLine (gp);
582 [Test]
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]");
607 [Test]
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]");
624 [Test]
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]");
643 [Test]
644 [ExpectedException (typeof (ArgumentNullException))]
645 public void AddLines_Point_Null ()
647 new GraphicsPath ().AddLines ((Point[])null);
650 [Test]
651 [ExpectedException (typeof (ArgumentException))]
652 public void AddLines_Point_0 ()
654 GraphicsPath gp = new GraphicsPath ();
655 gp.AddLines (new Point[0]);
656 CheckLine (gp);
659 [Test]
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]");
669 [Test]
670 public void AddLines_Point ()
672 GraphicsPath gp = new GraphicsPath ();
673 gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
674 CheckLine (gp);
677 [Test]
678 [ExpectedException (typeof (ArgumentNullException))]
679 public void AddLines_PointF_Null ()
681 new GraphicsPath ().AddLines ((PointF[]) null);
684 [Test]
685 [ExpectedException (typeof (ArgumentException))]
686 public void AddLines_PointF_0 ()
688 GraphicsPath gp = new GraphicsPath ();
689 gp.AddLines (new PointF[0]);
690 CheckLine (gp);
693 [Test]
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]");
703 [Test]
704 public void AddLines_PointF ()
706 GraphicsPath gp = new GraphicsPath ();
707 gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
708 CheckLine (gp);
711 [Test]
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]");
737 [Test]
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
765 #if false
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]");
792 #endif
795 [Test]
796 public void AddPie_Rect ()
798 GraphicsPath gp = new GraphicsPath ();
799 gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
800 CheckPie (gp);
803 [Test]
804 public void AddPie_Int ()
806 GraphicsPath gp = new GraphicsPath ();
807 gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
808 CheckPie (gp);
811 [Test]
812 public void AddPie_Float ()
814 GraphicsPath gp = new GraphicsPath ();
815 gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
816 CheckPie (gp);
819 private void CheckPolygon (GraphicsPath path)
821 // an extra point is generated by Mono (libgdiplus)
822 #if false
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");
826 #endif
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
843 #if false
844 Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
845 #endif
848 [Test]
849 [ExpectedException (typeof (ArgumentNullException))]
850 public void AddPolygon_Point_Null ()
852 new GraphicsPath ().AddPolygon ((Point[]) null);
855 [Test]
856 [ExpectedException (typeof (ArgumentException))]
857 public void AddPolygon_Point_Empty ()
859 new GraphicsPath ().AddPolygon (new Point[0]);
862 [Test]
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) });
870 [Test]
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) });
878 [Test]
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) });
883 CheckPolygon (gp);
886 [Test]
887 [ExpectedException (typeof (ArgumentNullException))]
888 public void AddPolygon_PointF_Null ()
890 new GraphicsPath ().AddPolygon ((PointF[]) null);
893 [Test]
894 [ExpectedException (typeof (ArgumentException))]
895 public void AddPolygon_PointF_Empty ()
897 new GraphicsPath ().AddPolygon (new PointF[0]);
900 [Test]
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) });
908 [Test]
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) });
916 [Test]
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) });
921 CheckPolygon (gp);
924 [Test]
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]");
958 [Test]
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]");
1020 [Test]
1021 public void AddRectangle_Int ()
1023 GraphicsPath gp = new GraphicsPath ();
1024 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1025 CheckRectangle (gp, 4);
1028 [Test]
1029 public void AddRectangle_Float ()
1031 GraphicsPath gp = new GraphicsPath ();
1032 gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
1033 CheckRectangle (gp, 4);
1036 [Test]
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]");
1061 [Test]
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]");
1086 [Test]
1087 [ExpectedException (typeof (ArgumentNullException))]
1088 public void AddRectangles_Int_Null ()
1090 GraphicsPath gp = new GraphicsPath ();
1091 gp.AddRectangles ((Rectangle[]) null);
1094 [Test]
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);
1103 [Test]
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);
1111 [Test]
1112 [ExpectedException (typeof (ArgumentNullException))]
1113 public void AddRectangles_Float_Null ()
1115 GraphicsPath gp = new GraphicsPath ();
1116 gp.AddRectangles ((RectangleF[]) null);
1119 [Test]
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);
1128 [Test]
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);
1136 [Test]
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);
1152 [Test]
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
1165 [Test]
1166 [ExpectedException (typeof (ArgumentNullException))]
1167 public void AddPath_Null ()
1169 new GraphicsPath ().AddPath (null, false);
1172 [Test]
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]");
1201 [Test]
1202 [ExpectedException (typeof (ArgumentNullException))]
1203 public void AddClosedCurve_Point_Null ()
1205 new GraphicsPath ().AddClosedCurve ((Point[])null);
1208 [Test]
1209 [ExpectedException (typeof (ArgumentException))]
1210 public void AddClosedCurve_Point_0 ()
1212 GraphicsPath gp = new GraphicsPath ();
1213 gp.AddClosedCurve (new Point [0]);
1216 [Test]
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) });
1224 [Test]
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) });
1232 [Test]
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);
1240 [Test]
1241 [ExpectedException (typeof (ArgumentNullException))]
1242 public void AddClosedCurve_PointF_Null ()
1244 new GraphicsPath ().AddClosedCurve ((PointF[]) null);
1247 [Test]
1248 [ExpectedException (typeof (ArgumentException))]
1249 public void AddClosedCurve_PointF_0 ()
1251 GraphicsPath gp = new GraphicsPath ();
1252 gp.AddClosedCurve (new PointF[0]);
1255 [Test]
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) });
1263 [Test]
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) });
1271 [Test]
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);
1279 [Test]
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");
1290 [Test]
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
1318 #if false
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");
1321 #endif
1322 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
1323 // Mono has wrong? results
1324 #if false
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");
1327 #endif
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]");
1334 [Test]
1335 [ExpectedException (typeof (ArgumentNullException))]
1336 public void AddCurve_Point_Null ()
1338 new GraphicsPath ().AddCurve ((Point[]) null);
1341 [Test]
1342 [ExpectedException (typeof (ArgumentException))]
1343 public void AddCurve_Point_0 ()
1345 GraphicsPath gp = new GraphicsPath ();
1346 gp.AddCurve (new Point[0]);
1349 [Test]
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) });
1357 [Test]
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) });
1362 CheckCurve (gp);
1363 // note: GdipAddPathCurveI allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1364 gp.Dispose ();
1367 [Test]
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);
1372 CheckCurve (gp);
1373 // note: GdipAddPathCurve2I allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1374 gp.Dispose ();
1377 [Test]
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
1386 [Test]
1387 [ExpectedException (typeof (ArgumentNullException))]
1388 public void AddCurve_PointF_Null ()
1390 new GraphicsPath ().AddCurve ((PointF[]) null);
1393 [Test]
1394 [ExpectedException (typeof (ArgumentException))]
1395 public void AddCurve_PointF_0 ()
1397 GraphicsPath gp = new GraphicsPath ();
1398 gp.AddCurve (new PointF[0]);
1401 [Test]
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) });
1409 [Test]
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) });
1414 CheckCurve (gp);
1415 // note: GdipAddPathCurve allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1416 gp.Dispose ();
1419 [Test]
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);
1424 CheckCurve (gp);
1425 // note: GdipAddPathCurve2 allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1426 gp.Dispose ();
1429 [Test]
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
1438 [Test]
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");
1444 gp.Dispose ();
1447 [Test]
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);
1455 [Test]
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);
1463 [Test]
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);
1471 [Test]
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");
1477 gp.Dispose ();
1480 [Test]
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");
1491 [Test]
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");
1502 [Test]
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 ()
1565 try {
1566 return FontFamily.GenericMonospace;
1568 catch (ArgumentException) {
1569 Assert.Ignore ("GenericMonospace FontFamily couldn't be found");
1570 return null;
1574 [Test]
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);
1583 [Test]
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");
1592 [Test]
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);
1600 [Test]
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");
1609 [Test]
1610 [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
1611 public void AddString_StringFormat ()
1613 FontFamily ff = GetFontFamily ();
1614 // null maps to ?
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");
1629 [Test]
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");
1648 [Test]
1649 public void GetBounds_Empty_Rectangle ()
1651 GraphicsPath gp = new GraphicsPath ();
1652 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1653 CheckRectangleBounds (gp.GetBounds ());
1656 [Test]
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));
1664 [Test]
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 ()));
1672 [Test]
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));
1680 [Test]
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);
1707 gp.Widen (p);
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");
1729 [Test]
1730 public void GetBounds_Empty_Pie ()
1732 GraphicsPath gp = new GraphicsPath ();
1733 gp.AddPie (10, 10, 100, 100, 30, 45);
1734 CheckPieBounds (gp.GetBounds ());
1735 gp.Dispose ();
1738 [Test]
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));
1744 gp.Dispose ();
1747 [Test]
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 ()));
1753 gp.Dispose ();
1756 [Test]
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));
1762 gp.Dispose ();
1765 [Test]
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) });
1771 #if false
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");
1777 #endif
1778 gp.Dispose ();
1781 [Test]
1782 [ExpectedException (typeof (ArgumentNullException))]
1783 public void Transform_Null ()
1785 new GraphicsPath ().Transform (null);
1787 [Test]
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 ());
1811 [Test]
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
1817 path.Flatten ();
1818 ComparePaths (path, clone);
1821 [Test]
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);
1832 [Test]
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);
1843 [Test]
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 ();
1849 path.Flatten ();
1850 CompareFlats (path, clone);
1853 [Test]
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 ();
1859 path.Flatten ();
1860 CompareFlats (path, clone);
1863 [Test]
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 ();
1872 path.Flatten ();
1873 CompareFlats (path, clone);
1876 [Test]
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 ();
1885 path.Flatten ();
1886 CompareFlats (path, clone);
1889 [Test]
1890 public void Flatten_Ellipse ()
1892 GraphicsPath path = new GraphicsPath ();
1893 path.AddEllipse (10f, 10f, 100f, 100f);
1894 GraphicsPath clone = (GraphicsPath) path.Clone ();
1895 path.Flatten ();
1896 CompareFlats (path, clone);
1899 [Test]
1900 public void Flatten_Line ()
1902 GraphicsPath path = new GraphicsPath ();
1903 path.AddLine (10f, 10f, 100f, 100f);
1904 GraphicsPath clone = (GraphicsPath) path.Clone ();
1905 path.Flatten ();
1906 ComparePaths (path, clone);
1909 [Test]
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 ();
1915 path.Flatten ();
1916 CompareFlats (path, clone);
1919 [Test]
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 ();
1928 path.Flatten ();
1929 ComparePaths (path, clone);
1932 [Test]
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 ();
1938 path.Flatten ();
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");
1978 [Test]
1979 [ExpectedException (typeof (ArgumentNullException))]
1980 public void Warp_Null ()
1982 new GraphicsPath ().Warp (null, new RectangleF ());
1985 [Test]
1986 [ExpectedException (typeof (ArgumentException))]
1987 public void Warp_NoPoints ()
1989 new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
1992 [Test]
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");
2005 [Test]
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");
2021 [Test]
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");
2036 [Test]
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);
2045 CheckWrap (path);
2048 [Test]
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 ());
2057 CheckWrap (path);
2060 [Test]
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);
2071 [Test]
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");
2095 [Test]
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");
2121 [Test]
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);
2134 [Test]
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);
2143 CheckWrap (path);
2146 [Test]
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");
2157 [Test]
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);
2166 CheckWrap (path);
2169 [Test]
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);
2178 CheckWrap (path);
2181 [Test]
2182 public void SetMarkers_EmptyPath ()
2184 new GraphicsPath ().SetMarkers ();
2187 [Test]
2188 public void ClearMarkers_EmptyPath ()
2190 new GraphicsPath ().ClearMarkers ();
2193 [Test]
2194 public void CloseFigure_EmptyPath ()
2196 new GraphicsPath ().CloseFigure ();
2199 [Test]
2200 public void CloseAllFigures_EmptyPath ()
2202 new GraphicsPath ().CloseAllFigures ();
2205 [Test]
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");
2216 // check last types
2217 Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
2218 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2221 [Test]
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");
2232 // check last types
2233 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
2234 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2237 [Test]
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");
2251 // check last types
2252 Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
2253 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2256 [Test]
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");
2267 // check last types
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");
2273 [Test]
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");
2284 // check last types
2285 Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
2286 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2289 [Test]
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");
2300 // check last types
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");
2306 [Test]
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");
2317 // check last types
2318 Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
2319 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2322 [Test]
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");
2333 // check last types
2334 Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
2335 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2338 [Test]
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");
2351 // check last types
2352 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
2353 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2356 [Test]
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");
2369 // check last types
2370 Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
2371 Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
2374 [Test]
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");
2385 // check last types
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");
2392 [Test]
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");
2403 // check last types
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");
2409 [Test]
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");
2420 // check last types
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");
2426 [Test]
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");
2439 // check last types
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");
2445 [Test]
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");
2457 // check last types
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");
2463 [Test]
2464 [ExpectedException (typeof (ArgumentNullException))]
2465 public void Widen_Pen_Null ()
2467 new GraphicsPath ().Widen (null);
2470 [Test]
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");
2478 path.Widen (pen);
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");
2522 [Test]
2523 [ExpectedException (typeof (ArgumentNullException))]
2524 public void Widen_Pen_Null_Matrix ()
2526 new GraphicsPath ().Widen (null, new Matrix ());
2529 [Test]
2530 public void Widen_NoPoint ()
2532 using (GraphicsPath gp = new GraphicsPath ()) {
2533 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
2534 Pen pen = new Pen (Color.Blue);
2535 gp.Widen (pen);
2536 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2540 [Test]
2541 [ExpectedException (typeof (OutOfMemoryException))]
2542 public void Widen_SinglePoint ()
2544 using (GraphicsPath gp = new GraphicsPath ()) {
2545 gp.AddLines (new Point[1] { new Point (1, 1) });
2546 // Special case - a line with a single point is valid
2547 Assert.AreEqual (1, gp.PointCount, "PointCount");
2548 gp.Widen (Pens.Red);
2549 // oops ;-)
2553 private void CheckWiden3 (GraphicsPath path)
2555 PointF[] pts = path.PathPoints;
2556 Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
2557 Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
2558 Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
2559 Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
2560 Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
2561 Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
2562 Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
2563 Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
2564 Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
2565 Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
2566 Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
2567 Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
2568 Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
2569 Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
2570 Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
2571 Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
2572 Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
2573 Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
2575 byte[] types = path.PathTypes;
2576 Assert.AreEqual (0, types[0], "0");
2577 Assert.AreEqual (1, types[1], "1");
2578 Assert.AreEqual (129, types[2], "2");
2579 Assert.AreEqual (0, types[3], "3");
2580 Assert.AreEqual (1, types[4], "4");
2581 Assert.AreEqual (1, types[5], "5");
2582 Assert.AreEqual (1, types[6], "6");
2583 Assert.AreEqual (1, types[7], "7");
2584 Assert.AreEqual (129, types[8], "8");
2587 [Test]
2588 [Category ("NotWorking")]
2589 public void Widen_Pen_Matrix_Null ()
2591 Pen pen = new Pen (Color.Blue);
2592 GraphicsPath path = new GraphicsPath ();
2593 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2594 path.Widen (pen, null);
2595 Assert.AreEqual (9, path.PointCount, "Count");
2596 CheckWiden3 (path);
2599 [Test]
2600 [Category ("NotWorking")]
2601 public void Widen_Pen_Matrix_Empty ()
2603 Pen pen = new Pen (Color.Blue);
2604 GraphicsPath path = new GraphicsPath ();
2605 path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2606 path.Widen (pen, new Matrix ());
2607 Assert.AreEqual (9, path.PointCount, "Count");
2608 CheckWiden3 (path);
2611 [Test]
2612 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2613 public void Widen_Pen_Matrix_NonInvertible ()
2615 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
2616 Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
2617 GraphicsPath path = new GraphicsPath ();
2618 path.Widen (new Pen (Color.Blue), matrix);
2619 Assert.AreEqual (0, path.PointCount, "Points");
2622 private void CheckWidenedBounds (string message, GraphicsPath gp, Matrix m)
2624 RectangleF bounds = gp.GetBounds (m);
2625 Assert.AreEqual (0.5f, bounds.X, 0.00001f, message + ".Bounds.X");
2626 Assert.AreEqual (0.5f, bounds.Y, 0.00001f, message + ".Bounds.Y");
2627 Assert.AreEqual (3.0f, bounds.Width, 0.00001f, message + ".Bounds.Width");
2628 Assert.AreEqual (3.0f, bounds.Height, 0.00001f, message + ".Bounds.Height");
2631 [Test]
2632 [Category ("NotWorking")]
2633 public void Widen_Pen_SmallWidth ()
2635 Matrix m = new Matrix ();
2636 Rectangle rect = new Rectangle (1, 1, 2, 2);
2638 // pen's smaller than 1.0 (width) are "promoted" to 1
2639 Pen p = new Pen (Color.Aqua, 0);
2640 GraphicsPath gp = new GraphicsPath ();
2641 gp.AddRectangle (rect);
2642 gp.Widen (p);
2643 CheckWidenedBounds ("Width == 0, Null matrix", gp, null);
2644 CheckWidenedBounds ("Width == 0, Empty matrix", gp, m);
2646 p.Width = 0.5f;
2647 gp = new GraphicsPath ();
2648 gp.AddRectangle (rect);
2649 gp.Widen (p);
2650 CheckWidenedBounds ("Width == 0.5, Null matrix", gp, null);
2651 CheckWidenedBounds ("Width == 0.5, Empty matrix", gp, m);
2653 p.Width = 1.0f;
2654 gp = new GraphicsPath ();
2655 gp.AddRectangle (rect);
2656 gp.Widen (p);
2657 CheckWidenedBounds ("Width == 1.0, Null matrix", gp, null);
2658 CheckWidenedBounds ("Width == 1.0, Empty matrix", gp, m);
2660 p.Width = 1.1f;
2661 gp = new GraphicsPath ();
2662 gp.AddRectangle (rect);
2663 gp.Widen (p);
2664 RectangleF bounds = gp.GetBounds (m);
2665 Assert.AreEqual (0.45f, bounds.X, 0.00001f, "1.1.Bounds.X");
2666 Assert.AreEqual (0.45f, bounds.Y, 0.00001f, "1.1.Bounds.Y");
2667 Assert.AreEqual (3.10f, bounds.Width, 0.00001f, "1.1.Bounds.Width");
2668 Assert.AreEqual (3.10f, bounds.Height, 0.00001f, "1.1.Bounds.Height");
2671 [Test]
2672 [ExpectedException (typeof (ArgumentNullException))]
2673 public void IsOutlineVisible_IntNull ()
2675 new GraphicsPath ().IsOutlineVisible (1, 1, null);
2678 [Test]
2679 [ExpectedException (typeof (ArgumentNullException))]
2680 public void IsOutlineVisible_FloatNull ()
2682 new GraphicsPath ().IsOutlineVisible (1.0f, 1.0f, null);
2685 [Test]
2686 [ExpectedException (typeof (ArgumentNullException))]
2687 public void IsOutlineVisible_PointNull ()
2689 new GraphicsPath ().IsOutlineVisible (new Point (), null);
2692 [Test]
2693 [ExpectedException (typeof (ArgumentNullException))]
2694 public void IsOutlineVisible_PointFNull ()
2696 new GraphicsPath ().IsOutlineVisible (new PointF (), null);
2699 private void IsOutlineVisible_Line (Graphics graphics)
2701 Pen p2 = new Pen (Color.Red, 3.0f);
2702 using (GraphicsPath gp = new GraphicsPath ()) {
2703 gp.AddLine (10, 1, 14, 1);
2704 Assert.IsTrue (gp.IsOutlineVisible (10, 1, Pens.Red, graphics), "Int1");
2705 Assert.IsTrue (gp.IsOutlineVisible (10, 2, p2, graphics), "Int2");
2706 Assert.IsFalse (gp.IsOutlineVisible (10, 2, Pens.Red, graphics), "Int3");
2708 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, Pens.Red, graphics), "Float1");
2709 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, p2, graphics), "Float2");
2710 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 2.0f, Pens.Red, graphics), "Float3");
2712 Point pt = new Point (12, 2);
2713 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2714 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2715 pt.Y = 1;
2716 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2718 PointF pf = new PointF (13.0f, 2.0f);
2719 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2720 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2721 pf.Y = 1;
2722 Assert.IsTrue (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF3");
2724 p2.Dispose ();
2727 [Test]
2728 public void IsOutlineVisible_Line_WithoutGraphics ()
2730 IsOutlineVisible_Line (null);
2733 [Test]
2734 public void IsOutlineVisible_Line_WithGraphics_Inside ()
2736 using (Bitmap bitmap = new Bitmap (20, 20)) {
2737 using (Graphics g = Graphics.FromImage (bitmap)) {
2738 IsOutlineVisible_Line (g);
2743 [Test]
2744 public void IsOutlineVisible_Line_WithGraphics_Outside ()
2746 using (Bitmap bitmap = new Bitmap (5, 5)) {
2747 using (Graphics g = Graphics.FromImage (bitmap)) {
2748 IsOutlineVisible_Line (g);
2750 // graphics "seems" ignored as the line is outside the bitmap!
2754 // docs ways the point is in world coordinates and that the graphics transform
2755 // should be applied
2757 [Test]
2758 public void IsOutlineVisible_Line_WithGraphics_Transform ()
2760 using (Bitmap bitmap = new Bitmap (20, 20)) {
2761 using (Graphics g = Graphics.FromImage (bitmap)) {
2762 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2763 IsOutlineVisible_Line (g);
2765 // graphics still "seems" ignored (Transform)
2769 [Test]
2770 public void IsOutlineVisible_Line_WithGraphics_PageUnit ()
2772 using (Bitmap bitmap = new Bitmap (20, 20)) {
2773 using (Graphics g = Graphics.FromImage (bitmap)) {
2774 g.PageUnit = GraphicsUnit.Millimeter;
2775 IsOutlineVisible_Line (g);
2777 // graphics still "seems" ignored (PageUnit)
2781 [Test]
2782 public void IsOutlineVisible_Line_WithGraphics_PageScale ()
2784 using (Bitmap bitmap = new Bitmap (20, 20)) {
2785 using (Graphics g = Graphics.FromImage (bitmap)) {
2786 g.PageScale = 2.0f;
2787 IsOutlineVisible_Line (g);
2789 // graphics still "seems" ignored (PageScale)
2793 [Test]
2794 [Category ("NotWorking")]
2795 public void IsOutlineVisible_Line_WithGraphics ()
2797 using (Bitmap bitmap = new Bitmap (20, 20)) {
2798 using (Graphics g = Graphics.FromImage (bitmap)) {
2799 g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2800 g.PageUnit = GraphicsUnit.Millimeter;
2801 g.PageScale = 2.0f;
2802 using (GraphicsPath gp = new GraphicsPath ()) {
2803 gp.AddLine (10, 1, 14, 1);
2804 Assert.IsFalse (gp.IsOutlineVisible (10, 1, Pens.Red, g), "Int1");
2807 // graphics ISN'T ignored (Transform+PageUnit+PageScale)
2811 [Test]
2812 [Category ("NotWorking")] // looks buggy - reported to MS as FDBK50868
2813 public void IsOutlineVisible_Line_End ()
2815 // horizontal line
2816 using (GraphicsPath gp = new GraphicsPath ()) {
2817 gp.AddLine (10, 1, 14, 1);
2818 Assert.IsFalse (gp.IsOutlineVisible (14, 1, Pens.Red, null), "Int1h");
2819 Assert.IsFalse (gp.IsOutlineVisible (13.5f, 1.0f, Pens.Red, null), "Float1h");
2820 Assert.IsTrue (gp.IsOutlineVisible (13.4f, 1.0f, Pens.Red, null), "Float2h");
2821 Assert.IsFalse (gp.IsOutlineVisible (new Point (14, 1), Pens.Red, null), "Point1h");
2822 Assert.IsFalse (gp.IsOutlineVisible (new PointF (13.5f, 1.0f), Pens.Red, null), "PointF1h");
2823 Assert.IsTrue (gp.IsOutlineVisible (new PointF (13.49f, 1.0f), Pens.Red, null), "PointF2h");
2825 // vertical line
2826 using (GraphicsPath gp = new GraphicsPath ()) {
2827 gp.AddLine (1, 10, 1, 14);
2828 Assert.IsFalse (gp.IsOutlineVisible (1, 14, Pens.Red, null), "Int1v");
2829 Assert.IsFalse (gp.IsOutlineVisible (1.0f, 13.5f, Pens.Red, null), "Float1v");
2830 Assert.IsTrue (gp.IsOutlineVisible (1.0f, 13.4f, Pens.Red, null), "Float2v");
2831 Assert.IsFalse (gp.IsOutlineVisible (new Point (1, 14), Pens.Red, null), "Point1v");
2832 Assert.IsFalse (gp.IsOutlineVisible (new PointF (1.0f, 13.5f), Pens.Red, null), "PointF1v");
2833 Assert.IsTrue (gp.IsOutlineVisible (new PointF (1.0f, 13.49f), Pens.Red, null), "PointF2v");
2837 private void IsOutlineVisible_Rectangle (Graphics graphics)
2839 Pen p2 = new Pen (Color.Red, 3.0f);
2840 using (GraphicsPath gp = new GraphicsPath ()) {
2841 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2842 Assert.IsTrue (gp.IsOutlineVisible (10, 10, Pens.Red, graphics), "Int1");
2843 Assert.IsTrue (gp.IsOutlineVisible (10, 11, p2, graphics), "Int2");
2844 Assert.IsFalse (gp.IsOutlineVisible (11, 11, Pens.Red, graphics), "Int3");
2846 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 10.0f, Pens.Red, graphics), "Float1");
2847 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 11.0f, p2, graphics), "Float2");
2848 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 11.0f, Pens.Red, graphics), "Float3");
2850 Point pt = new Point (15, 10);
2851 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2852 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2853 pt.Y = 15;
2854 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2856 PointF pf = new PointF (29.0f, 29.0f);
2857 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2858 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2859 pf.Y = 31.0f;
2860 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF3");
2862 p2.Dispose ();
2865 [Test]
2866 public void IsOutlineVisible_Rectangle_WithoutGraphics ()
2868 IsOutlineVisible_Rectangle (null);
2871 private void IsVisible_Rectangle (Graphics graphics)
2873 using (GraphicsPath gp = new GraphicsPath ()) {
2874 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2875 Assert.IsFalse (gp.IsVisible (9, 9, graphics), "Int0");
2876 Assert.IsTrue (gp.IsVisible (10, 10, graphics), "Int1");
2877 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2878 Assert.IsTrue (gp.IsVisible (29, 29, graphics), "Int3");
2879 Assert.IsFalse (gp.IsVisible (30, 29, graphics), "Int4");
2880 Assert.IsFalse (gp.IsVisible (29, 30, graphics), "Int5");
2881 Assert.IsFalse (gp.IsVisible (30, 30, graphics), "Int6");
2883 Assert.IsFalse (gp.IsVisible (9.4f, 9.4f, graphics), "Float0");
2884 Assert.IsTrue (gp.IsVisible (9.5f, 9.5f, graphics), "Float1");
2885 Assert.IsTrue (gp.IsVisible (10f, 10f, graphics), "Float2");
2886 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2887 // the next diff is too close, so this fails with libgdiplus/cairo
2888 //Assert.IsTrue (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2889 Assert.IsFalse (gp.IsVisible (29.5f, 29.5f, graphics), "Float5");
2890 Assert.IsFalse (gp.IsVisible (29.5f, 29.4f, graphics), "Float6");
2891 Assert.IsFalse (gp.IsVisible (29.4f, 29.5f, graphics), "Float7");
2895 [Test]
2896 public void IsVisible_Rectangle_WithoutGraphics ()
2898 IsVisible_Rectangle (null);
2901 [Test]
2902 public void IsVisible_Rectangle_WithGraphics ()
2904 using (Bitmap bitmap = new Bitmap (40, 40)) {
2905 using (Graphics g = Graphics.FromImage (bitmap)) {
2906 IsVisible_Rectangle (g);
2911 // bug #325502 has shown that ellipse didn't work with earlier code
2912 private void IsVisible_Ellipse (Graphics graphics)
2914 using (GraphicsPath gp = new GraphicsPath ()) {
2915 gp.AddEllipse (new Rectangle (10, 10, 20, 20));
2916 Assert.IsFalse (gp.IsVisible (10, 10, graphics), "Int1");
2917 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2918 Assert.IsFalse (gp.IsVisible (29, 29, graphics), "Int3");
2920 Assert.IsFalse (gp.IsVisible (10f, 10f, graphics), "Float2");
2921 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2922 Assert.IsFalse (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2926 [Test]
2927 public void IsVisible_Ellipse_WithoutGraphics ()
2929 IsVisible_Ellipse (null);
2932 [Test]
2933 public void IsVisible_Ellipse_WithGraphics ()
2935 using (Bitmap bitmap = new Bitmap (40, 40)) {
2936 using (Graphics g = Graphics.FromImage (bitmap)) {
2937 IsVisible_Ellipse (g);
2942 // Reverse simple test cases
2944 private void Reverse (GraphicsPath gp)
2946 PointF[] bp = gp.PathPoints;
2947 byte[] bt = gp.PathTypes;
2949 gp.Reverse ();
2950 PointF[] ap = gp.PathPoints;
2951 byte[] at = gp.PathTypes;
2953 int count = gp.PointCount;
2954 Assert.AreEqual (bp.Length, count, "PointCount");
2955 for (int i = 0; i < count; i++) {
2956 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
2957 Assert.AreEqual (bt[i], at[i], "Type" + i.ToString ());
2961 [Test]
2962 public void Reverse_Arc ()
2964 using (GraphicsPath gp = new GraphicsPath ()) {
2965 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
2966 Reverse (gp);
2970 [Test]
2971 public void Reverse_Bezier ()
2973 using (GraphicsPath gp = new GraphicsPath ()) {
2974 gp.AddBezier (1, 2, 3, 4, 5, 6, 7, 8);
2975 Reverse (gp);
2979 [Test]
2980 public void Reverse_Beziers ()
2982 using (GraphicsPath gp = new GraphicsPath ()) {
2983 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
2984 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
2985 gp.AddBeziers (beziers);
2986 Reverse (gp);
2990 [Test]
2991 public void Reverse_ClosedCurve ()
2993 using (GraphicsPath gp = new GraphicsPath ()) {
2994 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
2995 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
2996 gp.AddClosedCurve (beziers);
2997 Reverse (gp);
3001 [Test]
3002 public void Reverse_Curve ()
3004 using (GraphicsPath gp = new GraphicsPath ()) {
3005 Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3006 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3007 gp.AddCurve (beziers);
3008 Reverse (gp);
3012 [Test]
3013 public void Reverse_Ellipse ()
3015 using (GraphicsPath gp = new GraphicsPath ()) {
3016 gp.AddEllipse (1, 2, 3, 4);
3017 Reverse (gp);
3021 [Test]
3022 public void Reverse_Line ()
3024 using (GraphicsPath gp = new GraphicsPath ()) {
3025 gp.AddLine (1, 2, 3, 4);
3026 Reverse (gp);
3030 [Test]
3031 public void Reverse_Line_Closed ()
3033 using (GraphicsPath gp = new GraphicsPath ()) {
3034 gp.AddLine (1, 2, 3, 4);
3035 gp.CloseFigure ();
3036 Reverse (gp);
3040 [Test]
3041 public void Reverse_Lines ()
3043 using (GraphicsPath gp = new GraphicsPath ()) {
3044 Point[] points = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3045 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3046 gp.AddLines (points);
3047 Reverse (gp);
3051 [Test]
3052 public void Reverse_Polygon ()
3054 using (GraphicsPath gp = new GraphicsPath ()) {
3055 Point[] points = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6),
3056 new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) };
3057 gp.AddPolygon (points);
3058 Reverse (gp);
3062 [Test]
3063 public void Reverse_Rectangle ()
3065 using (GraphicsPath gp = new GraphicsPath ()) {
3066 gp.AddRectangle (new Rectangle (1,2,3,4));
3067 Reverse (gp);
3071 [Test]
3072 public void Reverse_Rectangles ()
3074 using (GraphicsPath gp = new GraphicsPath ()) {
3075 Rectangle[] rects = new Rectangle[] { new Rectangle (1, 2, 3, 4), new Rectangle (5, 6, 7, 8) };
3076 gp.AddRectangles (rects);
3077 Reverse (gp);
3081 // Reverse complex test cases
3083 [Test]
3084 [Category ("NotWorking")] // the output differs from GDI+ and libgdiplus
3085 public void Reverse_Pie ()
3087 using (GraphicsPath gp = new GraphicsPath ()) {
3088 gp.AddPie (1, 2, 3, 4, 10, 20);
3089 PointF[] bp = gp.PathPoints;
3090 byte[] expected = new byte[] { 0, 3, 3, 3, 129 };
3092 gp.Reverse ();
3093 PointF[] ap = gp.PathPoints;
3094 byte[] at = gp.PathTypes;
3095 int count = gp.PointCount;
3096 Assert.AreEqual (bp.Length, count, "PointCount");
3097 for (int i = 0; i < count; i++) {
3098 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3099 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3104 [Test]
3105 public void Reverse_Path ()
3107 using (GraphicsPath gp = new GraphicsPath ()) {
3108 GraphicsPath path = new GraphicsPath ();
3109 path.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
3110 path.AddLine (1, 2, 3, 4);
3111 gp.AddPath (path, true);
3112 PointF[] bp = gp.PathPoints;
3113 byte[] expected = new byte[] { 0, 1, 1, 3, 3, 3 };
3115 gp.Reverse ();
3116 PointF[] ap = gp.PathPoints;
3117 byte[] at = gp.PathTypes;
3119 int count = gp.PointCount;
3120 Assert.AreEqual (bp.Length, count, "PointCount");
3121 for (int i = 0; i < count; i++) {
3122 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3123 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3128 [Test]
3129 public void Reverse_Path_2 ()
3131 using (GraphicsPath gp = new GraphicsPath ()) {
3132 gp.AddEllipse (50, 51, 50, 100);
3133 gp.AddRectangle (new Rectangle (200, 201, 60, 61));
3134 PointF[] bp = gp.PathPoints;
3135 byte[] expected = new byte[] { 0, 1, 1, 129, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131 };
3137 gp.Reverse ();
3138 PointF[] ap = gp.PathPoints;
3139 byte[] at = gp.PathTypes;
3141 int count = gp.PointCount;
3142 Assert.AreEqual (bp.Length, count, "PointCount");
3143 for (int i = 0; i < count; i++) {
3144 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3145 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3150 [Test]
3151 [Category ("NotWorking")] // the output differs from GDI+ and libgdiplus
3152 public void Reverse_String ()
3154 using (GraphicsPath gp = new GraphicsPath ()) {
3155 FontFamily ff = GetFontFamily ();
3156 gp.AddString ("Mono::", ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
3157 PointF[] bp = gp.PathPoints;
3158 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,
3159 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,
3160 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,
3161 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,
3162 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,
3163 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,
3164 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,
3165 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,
3166 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,
3167 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 };
3169 gp.Reverse ();
3170 PointF[] ap = gp.PathPoints;
3171 byte[] at = gp.PathTypes;
3173 int count = gp.PointCount;
3174 Assert.AreEqual (bp.Length, count, "PointCount");
3175 for (int i = 0; i < count; i++) {
3176 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3177 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3182 [Test]
3183 public void Reverse_Marker ()
3185 using (GraphicsPath gp = new GraphicsPath ()) {
3186 gp.AddRectangle (new Rectangle (200, 201, 60, 61));
3187 gp.SetMarkers ();
3188 PointF[] bp = gp.PathPoints;
3189 byte[] expected = new byte[] { 0, 1, 1, 129 };
3191 gp.Reverse ();
3192 PointF[] ap = gp.PathPoints;
3193 byte[] at = gp.PathTypes;
3195 int count = gp.PointCount;
3196 Assert.AreEqual (bp.Length, count, "PointCount");
3197 for (int i = 0; i < count; i++) {
3198 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3199 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3204 [Test]
3205 public void Reverse_Subpath_Marker ()
3207 using (GraphicsPath gp = new GraphicsPath ()) {
3208 gp.AddLine (0, 1, 2, 3);
3209 gp.SetMarkers ();
3210 gp.CloseFigure ();
3211 gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12);
3212 gp.CloseFigure ();
3213 PointF[] bp = gp.PathPoints;
3214 byte[] expected = new byte[] { 0, 3, 3, 163, 0, 129 };
3216 gp.Reverse ();
3217 PointF[] ap = gp.PathPoints;
3218 byte[] at = gp.PathTypes;
3220 int count = gp.PointCount;
3221 Assert.AreEqual (bp.Length, count, "PointCount");
3222 for (int i = 0; i < count; i++) {
3223 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3224 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3229 [Test]
3230 public void Reverse_Subpath_Marker_2 ()
3232 using (GraphicsPath gp = new GraphicsPath ()) {
3233 gp.AddLine (0, 1, 2, 3);
3234 gp.SetMarkers ();
3235 gp.StartFigure ();
3236 gp.AddLine (20, 21, 22, 23);
3237 gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12);
3238 PointF[] bp = gp.PathPoints;
3239 byte[] expected = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 };
3241 gp.Reverse ();
3242 PointF[] ap = gp.PathPoints;
3243 byte[] at = gp.PathTypes;
3245 int count = gp.PointCount;
3246 Assert.AreEqual (bp.Length, count, "PointCount");
3247 for (int i = 0; i < count; i++) {
3248 Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
3249 Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
3254 [Test]
3255 public void bug413461 ()
3257 int dX = 520;
3258 int dY = 320;
3259 Point[] expected_points = new Point [] {
3260 new Point(dX-64, dY-24),//start
3261 new Point(dX-59, dY-34),//focal point 1
3262 new Point(dX-52, dY-54),//focal point 2
3263 new Point(dX-18, dY-66),//top
3264 new Point(dX-34, dY-47),//focal point 1
3265 new Point(dX-43, dY-27),//focal point 2
3266 new Point(dX-44, dY-8),//end
3268 byte[] expected_types = new byte [] {
3269 (byte)PathPointType.Start,
3270 (byte)PathPointType.Bezier,
3271 (byte)PathPointType.Bezier,
3272 (byte)PathPointType.Bezier,
3273 (byte)PathPointType.Bezier,
3274 (byte)PathPointType.Bezier,
3275 (byte)PathPointType.Bezier };
3276 using (GraphicsPath path = new GraphicsPath (expected_points, expected_types)) {
3277 Assert.AreEqual (7, path.PointCount, "PathCount");
3278 byte [] actual_types = path.PathTypes;
3279 Assert.AreEqual (expected_types [0], actual_types [0], "types-0");
3280 Assert.AreEqual (expected_types [1], actual_types [1], "types-1");
3281 Assert.AreEqual (expected_types [2], actual_types [2], "types-2");
3282 Assert.AreEqual (expected_types [3], actual_types [3], "types-3");
3283 Assert.AreEqual (expected_types [4], actual_types [4], "types-4");
3284 Assert.AreEqual (expected_types [5], actual_types [5], "types-5");
3285 // path is filled like closed but this does not show on the type
3286 Assert.AreEqual (expected_types [6], actual_types [6], "types-6");