2 // System.Drawing.Drawing2D.PathGradientBrush unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.ComponentModel;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing.Drawing2D {
39 public class PathGradientBrushTest {
41 private Point[] pts_2i;
42 private PointF[] pts_2f;
43 private Matrix empty_matrix;
45 private void CheckDefaultRectangle (string message, RectangleF rect)
47 Assert.AreEqual (1f, rect.X, message + ".Rectangle.X");
48 Assert.AreEqual (2f, rect.Y, message + ".Rectangle.Y");
49 Assert.AreEqual (19f, rect.Width, message + ".Rectangle.Width");
50 Assert.AreEqual (28f, rect.Height, message + ".Rectangle.Height");
53 private void CheckDefaults (PathGradientBrush pgb)
55 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Blend.Factors.Length");
56 Assert.AreEqual (1f, pgb.Blend.Factors[0], "Blend.Factors[0]");
57 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Blend.Positions.Length");
58 Assert.AreEqual (0f, pgb.Blend.Positions[0], 1e-30, "Blend.Positions[0]");
59 Assert.AreEqual (10.5f, pgb.CenterPoint.X, "CenterPoint.X");
60 Assert.AreEqual (16f, pgb.CenterPoint.Y, "CenterPoint.Y");
61 Assert.IsTrue (pgb.FocusScales.IsEmpty, "FocusScales");
62 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "InterpolationColors.Colors.Length");
63 Assert.AreEqual (0, pgb.InterpolationColors.Colors[0].ToArgb (), "InterpolationColors.Colors[0]");
64 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "InterpolationColors.Positions.Length");
65 Assert.AreEqual (0f, pgb.InterpolationColors.Positions[0], 1e-38, "InterpolationColors.Positions[0]");
66 CheckDefaultRectangle (String.Empty, pgb.Rectangle);
67 Assert.AreEqual (1, pgb.SurroundColors.Length, "SurroundColors.Length");
68 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors[0]");
69 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform");
72 private void CheckPointsDefaults (PathGradientBrush pgb)
75 Assert.AreEqual (-16777216, pgb.CenterColor.ToArgb (), "CenterColor");
78 private void CheckPathDefaults (PathGradientBrush pgb)
81 Assert.AreEqual (-1, pgb.CenterColor.ToArgb (), "CenterColor");
85 public void FixtureSetUp ()
87 pts_2i = new Point[2] { new Point (1, 2), new Point (20, 30) };
88 pts_2f = new PointF[2] { new PointF (1, 2), new PointF (20, 30) };
89 empty_matrix = new Matrix ();
93 public void Constructor_GraphicsPath_Null ()
95 GraphicsPath gp = null;
96 Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (gp));
100 public void Constructor_GraphicsPath_Empty ()
102 using (GraphicsPath gp = new GraphicsPath ()) {
103 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
108 public void Constructor_GraphicsPath_SinglePoint ()
110 using (GraphicsPath gp = new GraphicsPath ()) {
111 gp.AddLines (new Point[1] { new Point (1, 1) });
112 // Special case - a line with a single point is valid
113 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
118 public void Constructor_GraphicsPath_Line ()
120 using (GraphicsPath gp = new GraphicsPath ()) {
121 gp.AddLines (pts_2f);
122 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
123 CheckPathDefaults (pgb);
124 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
130 public void Constructor_Point_Null ()
133 Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
137 public void Constructor_Point_Empty ()
139 Point[] pts = new Point [0];
140 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
144 public void Constructor_Point_One ()
146 Point[] pts = new Point[1] { new Point (1, 1) };
147 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
151 public void Constructor_Point_Two ()
153 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i)) {
154 CheckPointsDefaults (pgb);
155 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
160 public void Constructor_Point_WrapMode_Clamp ()
162 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Clamp)) {
163 CheckPointsDefaults (pgb);
164 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
169 public void Constructor_Point_WrapMode_Tile ()
171 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Tile)) {
172 CheckPointsDefaults (pgb);
173 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
178 public void Constructor_Point_WrapMode_TileFlipX ()
180 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipX)) {
181 CheckPointsDefaults (pgb);
182 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
187 public void Constructor_Point_WrapMode_TileFlipY ()
189 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipY)) {
190 CheckPointsDefaults (pgb);
191 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
196 public void Constructor_Point_WrapMode_TileFlipXY ()
198 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipXY)) {
199 CheckPointsDefaults (pgb);
200 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
205 public void Constructor_PointF_Null ()
208 Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
212 public void Constructor_PointF_Empty ()
214 PointF[] pts = new PointF[0];
215 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
219 public void Constructor_PointF_One ()
221 PointF[] pts = new PointF[1] { new PointF (1, 1) };
222 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
226 public void Constructor_PointF_Two ()
228 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f)) {
229 CheckPointsDefaults (pgb);
230 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
235 public void Constructor_PointF_WrapMode_Invalid ()
237 Assert.Throws<InvalidEnumArgumentException> (() => new PathGradientBrush (pts_2f, (WrapMode)Int32.MinValue));
241 public void Constructor_PointF_WrapMode_Clamp ()
243 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
244 CheckPointsDefaults (pgb);
245 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
250 public void Constructor_PointF_WrapMode_Tile ()
252 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Tile)) {
253 CheckPointsDefaults (pgb);
254 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
259 public void Constructor_PointF_WrapMode_TileFlipX ()
261 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipX)) {
262 CheckPointsDefaults (pgb);
263 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
268 public void Constructor_PointF_WrapMode_TileFlipY ()
270 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipY)) {
271 CheckPointsDefaults (pgb);
272 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
277 public void Constructor_PointF_WrapMode_TileFlipXY ()
279 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
280 CheckPointsDefaults (pgb);
281 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
288 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
289 // change not accepted - but no exception is thrown
290 pgb.Blend.Factors = new float[0];
291 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-0");
292 pgb.Blend.Factors = new float[2];
293 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-1");
295 // change not accepted - but no exception is thrown
296 pgb.Blend.Positions = new float[0];
297 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-0");
298 pgb.Blend.Positions = new float[2];
299 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-1");
304 public void FocusScales ()
306 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
307 PointF fs = new PointF (Single.MaxValue, Single.MinValue);
308 pgb.FocusScales = fs;
309 Assert.AreEqual (Single.MaxValue, pgb.FocusScales.X, "MaxValue");
310 Assert.AreEqual (Single.MinValue, pgb.FocusScales.Y, "MinValue");
313 fs.Y = Single.NegativeInfinity;
314 pgb.FocusScales = fs;
315 Assert.AreEqual (Single.NaN, pgb.FocusScales.X, "NaN");
316 Assert.AreEqual (Single.NegativeInfinity, pgb.FocusScales.Y, "NegativeInfinity");
321 public void CenterColor ()
323 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
324 pgb.CenterColor = Color.Black;
325 Assert.AreEqual (Color.Black.ToArgb (), pgb.CenterColor.ToArgb (), "Black");
326 pgb.CenterColor = Color.Transparent;
327 Assert.AreEqual (Color.Transparent.ToArgb (), pgb.CenterColor.ToArgb (), "Transparent");
332 public void CenterPoint ()
334 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
335 PointF cp = new PointF (Single.MaxValue, Single.MinValue);
336 pgb.CenterPoint = cp;
337 Assert.AreEqual (Single.MaxValue, pgb.CenterPoint.X, "MaxValue");
338 Assert.AreEqual (Single.MinValue, pgb.CenterPoint.Y, "MinValue");
341 cp.Y = Single.NegativeInfinity;
342 pgb.CenterPoint = cp;
343 Assert.AreEqual (Single.NaN, pgb.CenterPoint.X, "NaN");
344 Assert.AreEqual (Single.NegativeInfinity, pgb.CenterPoint.Y, "NegativeInfinity");
349 public void InterpolationColors ()
351 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
352 // change not accepted - but no exception is thrown
353 pgb.InterpolationColors.Colors = new Color[0];
354 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-0");
355 pgb.InterpolationColors.Colors = new Color[2];
356 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-1");
358 // change not accepted - but no exception is thrown
359 pgb.InterpolationColors.Positions = new float[0];
360 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-0");
361 pgb.InterpolationColors.Positions = new float[2];
362 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-1");
367 public void Rectangle ()
369 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
370 CheckDefaultRectangle ("Original", pgb.Rectangle);
371 pgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
372 CheckDefaultRectangle ("Multiply", pgb.Rectangle);
373 pgb.ResetTransform ();
374 CheckDefaultRectangle ("Reset", pgb.Rectangle);
375 pgb.RotateTransform (90);
376 CheckDefaultRectangle ("Rotate", pgb.Rectangle);
377 pgb.ScaleTransform (4, 0.25f);
378 CheckDefaultRectangle ("Scale", pgb.Rectangle);
379 pgb.TranslateTransform (-10, -20);
380 CheckDefaultRectangle ("Translate", pgb.Rectangle);
382 pgb.SetBlendTriangularShape (0.5f);
383 CheckDefaultRectangle ("SetBlendTriangularShape", pgb.Rectangle);
384 pgb.SetSigmaBellShape (0.5f);
385 CheckDefaultRectangle ("SetSigmaBellShape", pgb.Rectangle);
390 public void SurroundColors_Empty ()
392 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
393 Assert.Throws<ArgumentException> (() => pgb.SurroundColors = new Color[0]);
398 public void SurroundColors_2PointF ()
400 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
402 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-0");
403 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-0");
405 // default can't be changed
406 pgb.SurroundColors[0] = Color.Gold;
407 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
409 // 2 empty color isn't valid, change isn't accepted
410 pgb.SurroundColors = new Color[2];
411 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
413 pgb.SurroundColors = new Color[2] { Color.Black, Color.White };
414 Assert.AreEqual (2, pgb.SurroundColors.Length, "Length-2");
415 Assert.AreEqual (-16777216, pgb.SurroundColors[0].ToArgb (), "SurroundColors-2");
416 Assert.AreEqual (-1, pgb.SurroundColors[1].ToArgb (), "SurroundColors-3");
421 public void SurroundColors_3PointsF ()
423 PointF[] points = new PointF[3] { new PointF (5, 50), new PointF (10, 100), new PointF (20, 75) };
424 using (PathGradientBrush pgb = new PathGradientBrush (points)) {
425 // 3 empty color isn't valid, change isn't accepted
426 pgb.SurroundColors = new Color[3] { Color.Empty, Color.Empty, Color.Empty };
427 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
429 pgb.SurroundColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
430 // change not accepted - but no exception is thrown
431 Assert.AreEqual (3, pgb.SurroundColors.Length, "Length-1");
432 Assert.AreEqual (-65536, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
433 Assert.AreEqual (-16744448, pgb.SurroundColors[1].ToArgb (), "SurroundColors-2");
434 Assert.AreEqual (-16776961, pgb.SurroundColors[2].ToArgb (), "SurroundColors-3");
439 public void Transform_Null ()
441 Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts_2f, WrapMode.Clamp).Transform = null);
445 public void Transform_Empty ()
447 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
448 pgb.Transform = new Matrix ();
449 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
454 public void Transform_NonInvertible ()
456 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
457 Assert.Throws<ArgumentException> (() => pgb.Transform = new Matrix (123, 24, 82, 16, 47, 30));
462 public void WrapMode_All ()
464 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
465 foreach (WrapMode wm in Enum.GetValues (typeof (WrapMode))) {
467 Assert.AreEqual (wm, pgb.WrapMode, wm.ToString ());
473 public void WrapMode_Invalid ()
475 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
476 Assert.Throws<InvalidEnumArgumentException> (() => pgb.WrapMode = (WrapMode) Int32.MinValue);
483 using (GraphicsPath gp = new GraphicsPath ()) {
484 gp.AddLines (pts_2f);
485 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
486 using (PathGradientBrush clone = (PathGradientBrush) pgb.Clone ()) {
487 CheckPathDefaults (clone);
488 Assert.AreEqual (WrapMode.Clamp, clone.WrapMode, "WrapMode");
495 public void MultiplyTransform1_Null ()
497 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
498 Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null));
503 public void MultiplyTransform2_Null ()
505 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
506 Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null, MatrixOrder.Append));
511 public void MultiplyTransform2_Invalid ()
513 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
514 pgb.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
519 public void MultiplyTransform_NonInvertible ()
521 using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
522 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
523 Assert.Throws<ArgumentException> (() => pgb.MultiplyTransform (noninvertible));
529 public void ResetTransform ()
531 using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
532 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
534 Assert.IsFalse (pgb.Transform.IsIdentity, "Transform.IsIdentity");
535 pgb.ResetTransform ();
536 Assert.IsTrue (pgb.Transform.IsIdentity, "Reset.IsIdentity");
542 public void RotateTransform ()
544 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
545 pgb.RotateTransform (90);
546 float[] elements = pgb.Transform.Elements;
547 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
548 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
549 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
550 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
551 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
552 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
554 pgb.RotateTransform (270);
555 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
560 [NUnit.Framework.Category ("NotWorking")]
561 public void RotateTransform_Max ()
563 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
564 pgb.RotateTransform (Single.MaxValue);
565 float[] elements = pgb.Transform.Elements;
566 Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
567 Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
568 Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
569 Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
570 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
571 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
576 [NUnit.Framework.Category ("NotWorking")]
577 public void RotateTransform_Min ()
579 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
580 pgb.RotateTransform (Single.MinValue);
581 float[] elements = pgb.Transform.Elements;
582 Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
583 Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
584 Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
585 Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
586 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
587 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
592 public void RotateTransform_InvalidOrder ()
594 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
595 Assert.Throws<ArgumentException> (() => pgb.RotateTransform (720, (MatrixOrder) Int32.MinValue));
600 public void ScaleTransform ()
602 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
603 pgb.ScaleTransform (2, 4);
604 float[] elements = pgb.Transform.Elements;
605 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
606 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
607 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
608 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
609 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
610 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
612 pgb.ScaleTransform (0.5f, 0.25f);
613 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
618 public void ScaleTransform_MaxMin ()
620 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
621 pgb.ScaleTransform (Single.MaxValue, Single.MinValue);
622 float[] elements = pgb.Transform.Elements;
623 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
624 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
625 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
626 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
627 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
628 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
633 public void ScaleTransform_InvalidOrder ()
635 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
636 Assert.Throws<ArgumentException> (() => pgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue));
641 public void SetBlendTriangularShape_Focus ()
643 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
645 pgb.SetBlendTriangularShape (1);
646 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
648 pgb.SetBlendTriangularShape (0);
649 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
651 pgb.SetBlendTriangularShape (0.5f);
652 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
653 // no impact on matrix
658 public void SetBlendTriangularShape_Scale ()
660 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
662 pgb.SetBlendTriangularShape (0, 1);
663 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
665 pgb.SetBlendTriangularShape (1, 0);
666 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
668 pgb.SetBlendTriangularShape (0.5f, 0.5f);
669 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
670 // no impact on matrix
675 public void SetBlendTriangularShape_FocusTooSmall ()
677 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
678 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (-1));
683 public void SetBlendTriangularShape_FocusTooBig ()
685 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
686 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1.01f));
691 public void SetBlendTriangularShape_ScaleTooSmall ()
693 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
694 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, -1));
699 public void SetBlendTriangularShape_ScaleTooBig ()
701 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
702 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, 1.01f));
707 public void SetSigmaBellShape_Focus ()
709 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
711 pgb.SetSigmaBellShape (1);
712 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
714 pgb.SetSigmaBellShape (0);
715 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
717 pgb.SetSigmaBellShape (0.5f);
718 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
719 // no impact on matrix
724 public void SetSigmaBellShape_Scale ()
726 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
728 pgb.SetSigmaBellShape (0, 1);
729 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
731 pgb.SetSigmaBellShape (1, 0);
732 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-2");
734 pgb.SetSigmaBellShape (0.5f, 0.5f);
735 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-3");
736 // no impact on matrix
741 public void SetSigmaBellShape_FocusTooSmall ()
743 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
744 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (-1));
749 public void SetSigmaBellShape_FocusTooBig ()
751 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
752 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1.01f));
757 public void SetSigmaBellShape_ScaleTooSmall ()
759 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
760 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, -1));
765 public void SetSigmaBellShape_ScaleTooBig ()
767 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
768 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, 1.01f));
773 public void TranslateTransform ()
775 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
776 pgb.TranslateTransform (1, 1);
777 float[] elements = pgb.Transform.Elements;
778 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
779 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
780 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
781 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
782 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
783 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
785 pgb.TranslateTransform (-1, -1);
786 // strangely lgb.Transform.IsIdentity is false
787 elements = pgb.Transform.Elements;
788 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
789 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
790 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
791 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
792 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
793 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
798 public void TranslateTransform_InvalidOrder ()
800 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
801 Assert.Throws<ArgumentException> (() => pgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue));
806 public void Transform_Operations ()
808 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
809 Matrix clone = pgb.Transform.Clone ();
810 Matrix mul = clone.Clone ();
812 clone.Multiply (mul, MatrixOrder.Append);
813 pgb.MultiplyTransform (mul, MatrixOrder.Append);
814 Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");
816 clone.Multiply (mul, MatrixOrder.Prepend);
817 pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
818 Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");
820 clone.Rotate (45, MatrixOrder.Append);
821 pgb.RotateTransform (45, MatrixOrder.Append);
822 Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");
824 clone.Rotate (45, MatrixOrder.Prepend);
825 pgb.RotateTransform (45, MatrixOrder.Prepend);
826 Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");
828 clone.Scale (0.25f, 2, MatrixOrder.Append);
829 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
830 Assert.AreEqual (pgb.Transform, clone, "Scale/Append");
832 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
833 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
834 Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");
836 clone.Translate (10, 20, MatrixOrder.Append);
837 pgb.TranslateTransform (10, 20, MatrixOrder.Append);
838 Assert.AreEqual (pgb.Transform, clone, "Translate/Append");
840 clone.Translate (30, 40, MatrixOrder.Prepend);
841 pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
842 Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");
845 pgb.ResetTransform ();
846 Assert.AreEqual (pgb.Transform, clone, "Reset");
851 public void Blend_Null ()
853 using (GraphicsPath gp = new GraphicsPath ()) {
854 gp.AddLines (pts_2f);
855 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
856 Assert.Throws<NullReferenceException> (() => pgb.Blend = null);
862 public void InterpolationColors_Null ()
864 using (GraphicsPath gp = new GraphicsPath ()) {
865 gp.AddLines (pts_2f);
866 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
867 Assert.Throws<NullReferenceException> (() => pgb.InterpolationColors = null);
873 public void SurroundColors_Null ()
875 using (GraphicsPath gp = new GraphicsPath ()) {
876 gp.AddLines (pts_2f);
877 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
878 Assert.Throws<NullReferenceException> (() => pgb.SurroundColors = null);