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 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40 public class PathGradientBrushTest {
42 private Point[] pts_2i;
43 private PointF[] pts_2f;
44 private Matrix empty_matrix;
46 private void CheckDefaultRectangle (string message, RectangleF rect)
48 Assert.AreEqual (1f, rect.X, message + ".Rectangle.X");
49 Assert.AreEqual (2f, rect.Y, message + ".Rectangle.Y");
50 Assert.AreEqual (19f, rect.Width, message + ".Rectangle.Width");
51 Assert.AreEqual (28f, rect.Height, message + ".Rectangle.Height");
54 private void CheckDefaults (PathGradientBrush pgb)
56 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Blend.Factors.Length");
57 Assert.AreEqual (1f, pgb.Blend.Factors[0], "Blend.Factors[0]");
58 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Blend.Positions.Length");
59 Assert.AreEqual (0f, pgb.Blend.Positions[0], 1e-30, "Blend.Positions[0]");
60 Assert.AreEqual (10.5f, pgb.CenterPoint.X, "CenterPoint.X");
61 Assert.AreEqual (16f, pgb.CenterPoint.Y, "CenterPoint.Y");
62 Assert.IsTrue (pgb.FocusScales.IsEmpty, "FocusScales");
63 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "InterpolationColors.Colors.Length");
64 Assert.AreEqual (0, pgb.InterpolationColors.Colors[0].ToArgb (), "InterpolationColors.Colors[0]");
65 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "InterpolationColors.Positions.Length");
66 Assert.AreEqual (0f, pgb.InterpolationColors.Positions[0], 1e-38, "InterpolationColors.Positions[0]");
67 CheckDefaultRectangle (String.Empty, pgb.Rectangle);
68 Assert.AreEqual (1, pgb.SurroundColors.Length, "SurroundColors.Length");
69 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors[0]");
70 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform");
73 private void CheckPointsDefaults (PathGradientBrush pgb)
76 Assert.AreEqual (-16777216, pgb.CenterColor.ToArgb (), "CenterColor");
79 private void CheckPathDefaults (PathGradientBrush pgb)
82 Assert.AreEqual (-1, pgb.CenterColor.ToArgb (), "CenterColor");
86 public void FixtureSetUp ()
88 pts_2i = new Point[2] { new Point (1, 2), new Point (20, 30) };
89 pts_2f = new PointF[2] { new PointF (1, 2), new PointF (20, 30) };
90 empty_matrix = new Matrix ();
94 [ExpectedException (typeof (ArgumentNullException))]
95 public void Constructor_GraphicsPath_Null ()
97 GraphicsPath gp = null;
98 new PathGradientBrush (gp);
102 [ExpectedException (typeof (OutOfMemoryException))]
103 public void Constructor_GraphicsPath_Empty ()
105 using (GraphicsPath gp = new GraphicsPath ()) {
106 new PathGradientBrush (gp);
111 [ExpectedException (typeof (OutOfMemoryException))]
112 public void Constructor_GraphicsPath_SinglePoint ()
114 using (GraphicsPath gp = new GraphicsPath ()) {
115 gp.AddLines (new Point[1] { new Point (1, 1) });
116 // Special case - a line with a single point is valid
117 new PathGradientBrush (gp);
122 public void Constructor_GraphicsPath_Line ()
124 using (GraphicsPath gp = new GraphicsPath ()) {
125 gp.AddLines (pts_2f);
126 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
127 CheckPathDefaults (pgb);
128 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
134 [ExpectedException (typeof (ArgumentNullException))]
135 public void Constructor_Point_Null ()
138 new PathGradientBrush (pts);
142 [ExpectedException (typeof (OutOfMemoryException))]
143 public void Constructor_Point_Empty ()
145 Point[] pts = new Point [0];
146 new PathGradientBrush (pts);
150 [ExpectedException (typeof (OutOfMemoryException))]
151 public void Constructor_Point_One ()
153 Point[] pts = new Point[1] { new Point (1, 1) };
154 new PathGradientBrush (pts);
158 public void Constructor_Point_Two ()
160 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i)) {
161 CheckPointsDefaults (pgb);
162 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
167 public void Constructor_Point_WrapMode_Clamp ()
169 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Clamp)) {
170 CheckPointsDefaults (pgb);
171 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
176 public void Constructor_Point_WrapMode_Tile ()
178 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Tile)) {
179 CheckPointsDefaults (pgb);
180 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
185 public void Constructor_Point_WrapMode_TileFlipX ()
187 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipX)) {
188 CheckPointsDefaults (pgb);
189 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
194 public void Constructor_Point_WrapMode_TileFlipY ()
196 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipY)) {
197 CheckPointsDefaults (pgb);
198 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
203 public void Constructor_Point_WrapMode_TileFlipXY ()
205 using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipXY)) {
206 CheckPointsDefaults (pgb);
207 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
212 [ExpectedException (typeof (ArgumentNullException))]
213 public void Constructor_PointF_Null ()
216 new PathGradientBrush (pts);
220 [ExpectedException (typeof (OutOfMemoryException))]
221 public void Constructor_PointF_Empty ()
223 PointF[] pts = new PointF[0];
224 new PathGradientBrush (pts);
228 [ExpectedException (typeof (OutOfMemoryException))]
229 public void Constructor_PointF_One ()
231 PointF[] pts = new PointF[1] { new PointF (1, 1) };
232 new PathGradientBrush (pts);
236 public void Constructor_PointF_Two ()
238 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f)) {
239 CheckPointsDefaults (pgb);
240 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
245 [ExpectedException (typeof (InvalidEnumArgumentException))]
246 public void Constructor_PointF_WrapMode_Invalid ()
248 PathGradientBrush pgb = new PathGradientBrush (pts_2f, (WrapMode)Int32.MinValue);
252 public void Constructor_PointF_WrapMode_Clamp ()
254 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
255 CheckPointsDefaults (pgb);
256 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
261 public void Constructor_PointF_WrapMode_Tile ()
263 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Tile)) {
264 CheckPointsDefaults (pgb);
265 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
270 public void Constructor_PointF_WrapMode_TileFlipX ()
272 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipX)) {
273 CheckPointsDefaults (pgb);
274 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
279 public void Constructor_PointF_WrapMode_TileFlipY ()
281 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipY)) {
282 CheckPointsDefaults (pgb);
283 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
288 public void Constructor_PointF_WrapMode_TileFlipXY ()
290 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
291 CheckPointsDefaults (pgb);
292 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
299 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
300 // change not accepted - but no exception is thrown
301 pgb.Blend.Factors = new float[0];
302 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-0");
303 pgb.Blend.Factors = new float[2];
304 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-1");
306 // change not accepted - but no exception is thrown
307 pgb.Blend.Positions = new float[0];
308 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-0");
309 pgb.Blend.Positions = new float[2];
310 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-1");
315 public void FocusScales ()
317 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
318 PointF fs = new PointF (Single.MaxValue, Single.MinValue);
319 pgb.FocusScales = fs;
320 Assert.AreEqual (Single.MaxValue, pgb.FocusScales.X, "MaxValue");
321 Assert.AreEqual (Single.MinValue, pgb.FocusScales.Y, "MinValue");
324 fs.Y = Single.NegativeInfinity;
325 pgb.FocusScales = fs;
326 Assert.AreEqual (Single.NaN, pgb.FocusScales.X, "NaN");
327 Assert.AreEqual (Single.NegativeInfinity, pgb.FocusScales.Y, "NegativeInfinity");
332 public void CenterColor ()
334 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
335 pgb.CenterColor = Color.Black;
336 Assert.AreEqual (Color.Black.ToArgb (), pgb.CenterColor.ToArgb (), "Black");
337 pgb.CenterColor = Color.Transparent;
338 Assert.AreEqual (Color.Transparent.ToArgb (), pgb.CenterColor.ToArgb (), "Transparent");
343 public void CenterPoint ()
345 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
346 PointF cp = new PointF (Single.MaxValue, Single.MinValue);
347 pgb.CenterPoint = cp;
348 Assert.AreEqual (Single.MaxValue, pgb.CenterPoint.X, "MaxValue");
349 Assert.AreEqual (Single.MinValue, pgb.CenterPoint.Y, "MinValue");
352 cp.Y = Single.NegativeInfinity;
353 pgb.CenterPoint = cp;
354 Assert.AreEqual (Single.NaN, pgb.CenterPoint.X, "NaN");
355 Assert.AreEqual (Single.NegativeInfinity, pgb.CenterPoint.Y, "NegativeInfinity");
360 public void InterpolationColors ()
362 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
363 // change not accepted - but no exception is thrown
364 pgb.InterpolationColors.Colors = new Color[0];
365 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-0");
366 pgb.InterpolationColors.Colors = new Color[2];
367 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-1");
369 // change not accepted - but no exception is thrown
370 pgb.InterpolationColors.Positions = new float[0];
371 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-0");
372 pgb.InterpolationColors.Positions = new float[2];
373 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-1");
378 public void Rectangle ()
380 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
381 CheckDefaultRectangle ("Original", pgb.Rectangle);
382 pgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
383 CheckDefaultRectangle ("Multiply", pgb.Rectangle);
384 pgb.ResetTransform ();
385 CheckDefaultRectangle ("Reset", pgb.Rectangle);
386 pgb.RotateTransform (90);
387 CheckDefaultRectangle ("Rotate", pgb.Rectangle);
388 pgb.ScaleTransform (4, 0.25f);
389 CheckDefaultRectangle ("Scale", pgb.Rectangle);
390 pgb.TranslateTransform (-10, -20);
391 CheckDefaultRectangle ("Translate", pgb.Rectangle);
393 pgb.SetBlendTriangularShape (0.5f);
394 CheckDefaultRectangle ("SetBlendTriangularShape", pgb.Rectangle);
395 pgb.SetSigmaBellShape (0.5f);
396 CheckDefaultRectangle ("SetSigmaBellShape", pgb.Rectangle);
401 [ExpectedException (typeof (ArgumentException))]
402 public void SurroundColors_Empty ()
404 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
405 pgb.SurroundColors = new Color[0];
410 public void SurroundColors_2PointF ()
412 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
414 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-0");
415 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-0");
417 // default can't be changed
418 pgb.SurroundColors[0] = Color.Gold;
419 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
421 // 2 empty color isn't valid, change isn't accepted
422 pgb.SurroundColors = new Color[2];
423 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
425 pgb.SurroundColors = new Color[2] { Color.Black, Color.White };
426 Assert.AreEqual (2, pgb.SurroundColors.Length, "Length-2");
427 Assert.AreEqual (-16777216, pgb.SurroundColors[0].ToArgb (), "SurroundColors-2");
428 Assert.AreEqual (-1, pgb.SurroundColors[1].ToArgb (), "SurroundColors-3");
433 public void SurroundColors_3PointsF ()
435 PointF[] points = new PointF[3] { new PointF (5, 50), new PointF (10, 100), new PointF (20, 75) };
436 using (PathGradientBrush pgb = new PathGradientBrush (points)) {
437 // 3 empty color isn't valid, change isn't accepted
438 pgb.SurroundColors = new Color[3] { Color.Empty, Color.Empty, Color.Empty };
439 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
441 pgb.SurroundColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
442 // change not accepted - but no exception is thrown
443 Assert.AreEqual (3, pgb.SurroundColors.Length, "Length-1");
444 Assert.AreEqual (-65536, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
445 Assert.AreEqual (-16744448, pgb.SurroundColors[1].ToArgb (), "SurroundColors-2");
446 Assert.AreEqual (-16776961, pgb.SurroundColors[2].ToArgb (), "SurroundColors-3");
451 [ExpectedException (typeof (ArgumentNullException))]
452 public void Transform_Null ()
454 new PathGradientBrush (pts_2f, WrapMode.Clamp).Transform = null;
458 public void Transform_Empty ()
460 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
461 pgb.Transform = new Matrix ();
462 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
467 [ExpectedException (typeof (ArgumentException))]
468 public void Transform_NonInvertible ()
470 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
471 pgb.Transform = new Matrix (123, 24, 82, 16, 47, 30);
476 public void WrapMode_All ()
478 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
479 foreach (WrapMode wm in Enum.GetValues (typeof (WrapMode))) {
481 Assert.AreEqual (wm, pgb.WrapMode, wm.ToString ());
487 [ExpectedException (typeof (InvalidEnumArgumentException))]
488 public void WrapMode_Invalid ()
490 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
491 pgb.WrapMode = (WrapMode) Int32.MinValue;
498 using (GraphicsPath gp = new GraphicsPath ()) {
499 gp.AddLines (pts_2f);
500 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
501 using (PathGradientBrush clone = (PathGradientBrush) pgb.Clone ()) {
502 CheckPathDefaults (clone);
503 Assert.AreEqual (WrapMode.Clamp, clone.WrapMode, "WrapMode");
510 [ExpectedException (typeof (ArgumentNullException))]
511 public void MultiplyTransform1_Null ()
513 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
514 pgb.MultiplyTransform (null);
519 [ExpectedException (typeof (ArgumentNullException))]
520 public void MultiplyTransform2_Null ()
522 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
523 pgb.MultiplyTransform (null, MatrixOrder.Append);
528 public void MultiplyTransform2_Invalid ()
530 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
531 pgb.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
536 [ExpectedException (typeof (ArgumentException))]
537 public void MultiplyTransform_NonInvertible ()
539 using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
540 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
541 pgb.MultiplyTransform (noninvertible);
547 public void ResetTransform ()
549 using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
550 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
552 Assert.IsFalse (pgb.Transform.IsIdentity, "Transform.IsIdentity");
553 pgb.ResetTransform ();
554 Assert.IsTrue (pgb.Transform.IsIdentity, "Reset.IsIdentity");
560 public void RotateTransform ()
562 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
563 pgb.RotateTransform (90);
564 float[] elements = pgb.Transform.Elements;
565 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
566 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
567 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
568 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
569 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
570 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
572 pgb.RotateTransform (270);
573 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
578 [NUnit.Framework.Category ("NotWorking")]
579 public void RotateTransform_Max ()
581 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
582 pgb.RotateTransform (Single.MaxValue);
583 float[] elements = pgb.Transform.Elements;
584 Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
585 Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
586 Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
587 Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
588 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
589 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
594 [NUnit.Framework.Category ("NotWorking")]
595 public void RotateTransform_Min ()
597 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
598 pgb.RotateTransform (Single.MinValue);
599 float[] elements = pgb.Transform.Elements;
600 Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
601 Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
602 Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
603 Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
604 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
605 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
610 [ExpectedException (typeof (ArgumentException))]
611 public void RotateTransform_InvalidOrder ()
613 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
614 pgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
619 public void ScaleTransform ()
621 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
622 pgb.ScaleTransform (2, 4);
623 float[] elements = pgb.Transform.Elements;
624 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
625 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
626 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
627 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
628 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
629 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
631 pgb.ScaleTransform (0.5f, 0.25f);
632 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
637 public void ScaleTransform_MaxMin ()
639 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
640 pgb.ScaleTransform (Single.MaxValue, Single.MinValue);
641 float[] elements = pgb.Transform.Elements;
642 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
643 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
644 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
645 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
646 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
647 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
652 [ExpectedException (typeof (ArgumentException))]
653 public void ScaleTransform_InvalidOrder ()
655 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
656 pgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
661 public void SetBlendTriangularShape_Focus ()
663 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
665 pgb.SetBlendTriangularShape (1);
666 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
668 pgb.SetBlendTriangularShape (0);
669 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
671 pgb.SetBlendTriangularShape (0.5f);
672 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
673 // no impact on matrix
678 public void SetBlendTriangularShape_Scale ()
680 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
682 pgb.SetBlendTriangularShape (0, 1);
683 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
685 pgb.SetBlendTriangularShape (1, 0);
686 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
688 pgb.SetBlendTriangularShape (0.5f, 0.5f);
689 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
690 // no impact on matrix
695 [ExpectedException (typeof (ArgumentException))]
696 public void SetBlendTriangularShape_FocusTooSmall ()
698 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
699 pgb.SetBlendTriangularShape (-1);
704 [ExpectedException (typeof (ArgumentException))]
705 public void SetBlendTriangularShape_FocusTooBig ()
707 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
708 pgb.SetBlendTriangularShape (1.01f);
713 [ExpectedException (typeof (ArgumentException))]
714 public void SetBlendTriangularShape_ScaleTooSmall ()
716 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
717 pgb.SetBlendTriangularShape (1, -1);
722 [ExpectedException (typeof (ArgumentException))]
723 public void SetBlendTriangularShape_ScaleTooBig ()
725 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
726 pgb.SetBlendTriangularShape (1, 1.01f);
731 public void SetSigmaBellShape_Focus ()
733 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
735 pgb.SetSigmaBellShape (1);
736 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
738 pgb.SetSigmaBellShape (0);
739 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
741 pgb.SetSigmaBellShape (0.5f);
742 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
743 // no impact on matrix
748 public void SetSigmaBellShape_Scale ()
750 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
752 pgb.SetSigmaBellShape (0, 1);
753 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
755 pgb.SetSigmaBellShape (1, 0);
756 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-2");
758 pgb.SetSigmaBellShape (0.5f, 0.5f);
759 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-3");
760 // no impact on matrix
765 [ExpectedException (typeof (ArgumentException))]
766 public void SetSigmaBellShape_FocusTooSmall ()
768 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
769 pgb.SetSigmaBellShape (-1);
774 [ExpectedException (typeof (ArgumentException))]
775 public void SetSigmaBellShape_FocusTooBig ()
777 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
778 pgb.SetSigmaBellShape (1.01f);
783 [ExpectedException (typeof (ArgumentException))]
784 public void SetSigmaBellShape_ScaleTooSmall ()
786 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
787 pgb.SetSigmaBellShape (1, -1);
792 [ExpectedException (typeof (ArgumentException))]
793 public void SetSigmaBellShape_ScaleTooBig ()
795 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
796 pgb.SetSigmaBellShape (1, 1.01f);
801 public void TranslateTransform ()
803 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
804 pgb.TranslateTransform (1, 1);
805 float[] elements = pgb.Transform.Elements;
806 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
807 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
808 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
809 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
810 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
811 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
813 pgb.TranslateTransform (-1, -1);
814 // strangely lgb.Transform.IsIdentity is false
815 elements = pgb.Transform.Elements;
816 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
817 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
818 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
819 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
820 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
821 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
826 [ExpectedException (typeof (ArgumentException))]
827 public void TranslateTransform_InvalidOrder ()
829 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
830 pgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
835 public void Transform_Operations ()
837 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
838 Matrix clone = pgb.Transform.Clone ();
839 Matrix mul = clone.Clone ();
841 clone.Multiply (mul, MatrixOrder.Append);
842 pgb.MultiplyTransform (mul, MatrixOrder.Append);
843 Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");
845 clone.Multiply (mul, MatrixOrder.Prepend);
846 pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
847 Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");
849 clone.Rotate (45, MatrixOrder.Append);
850 pgb.RotateTransform (45, MatrixOrder.Append);
851 Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");
853 clone.Rotate (45, MatrixOrder.Prepend);
854 pgb.RotateTransform (45, MatrixOrder.Prepend);
855 Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");
857 clone.Scale (0.25f, 2, MatrixOrder.Append);
858 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
859 Assert.AreEqual (pgb.Transform, clone, "Scale/Append");
861 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
862 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
863 Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");
865 clone.Translate (10, 20, MatrixOrder.Append);
866 pgb.TranslateTransform (10, 20, MatrixOrder.Append);
867 Assert.AreEqual (pgb.Transform, clone, "Translate/Append");
869 clone.Translate (30, 40, MatrixOrder.Prepend);
870 pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
871 Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");
874 pgb.ResetTransform ();
875 Assert.AreEqual (pgb.Transform, clone, "Reset");