2 // System.Drawing.Drawing2D.LinearGradientBrush 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 LinearGradientBrushTest {
46 private LinearGradientBrush default_brush;
47 private Matrix empty_matrix;
48 private RectangleF rect;
51 public void FixtureSetUp ()
53 pt1 = new Point (0, 0);
54 pt2 = new Point (32, 32);
57 default_brush = new LinearGradientBrush (pt1, pt2, c1, c2);
58 empty_matrix = new Matrix ();
59 rect = new RectangleF (0, 0, 32, 32);
62 private void CheckDefaultRectangle (string msg, RectangleF rect)
64 Assert.AreEqual (pt1.X, rect.X, msg + ".Rectangle.X");
65 Assert.AreEqual (pt1.Y, rect.Y, msg + ".Rectangle.Y");
66 Assert.AreEqual (pt2.X, rect.Width, msg + ".Rectangle.Width");
67 Assert.AreEqual (pt2.Y, rect.Height, msg + ".Rectangle.Height");
70 private void CheckDefaultMatrix (Matrix matrix)
72 float[] elements = matrix.Elements;
73 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
74 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
75 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
76 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
77 Assert.AreEqual (16, elements[4], "matrix.4");
78 Assert.AreEqual (-16, elements[5], "matrix.5");
81 private void CheckBrushAt45 (LinearGradientBrush lgb)
83 CheckDefaultRectangle ("4", lgb.Rectangle);
84 Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
85 Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors [0]");
86 Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
87 // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
88 Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
89 Assert.AreEqual (2, lgb.LinearColors.Length, "LinearColors");
90 Assert.IsNotNull (lgb.Transform, "Transform");
91 CheckDefaultMatrix (lgb.Transform);
95 [NUnit.Framework.Category ("NotWorking")]
96 public void Constructor_Point_Point_Color_Color ()
98 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
101 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
102 lgb.WrapMode = WrapMode.TileFlipX;
103 Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
104 lgb.WrapMode = WrapMode.TileFlipY;
105 Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
106 lgb.WrapMode = WrapMode.TileFlipXY;
107 Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
108 // can't set WrapMode.Clamp
112 public void Constructor_RectangleF_Color_Color_Single_0 ()
114 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
115 Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
116 Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors[0]");
117 Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
118 // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
119 Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
120 Assert.AreEqual (c1.ToArgb (), lgb.LinearColors[0].ToArgb (), "LinearColors[0]");
121 Assert.AreEqual (c2.ToArgb (), lgb.LinearColors[1].ToArgb (), "LinearColors[1]");
122 Assert.AreEqual (rect, lgb.Rectangle, "Rectangle");
123 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
124 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode");
126 Matrix matrix = new Matrix (2, -1, 1, 2, 10, 10);
127 lgb.Transform = matrix;
128 Assert.AreEqual (matrix, lgb.Transform, "Transform");
132 [NUnit.Framework.Category ("NotWorking")]
133 public void Constructor_RectangleF_Color_Color_Single_22_5 ()
135 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 22.5f);
136 float[] elements = lgb.Transform.Elements;
137 Assert.AreEqual (1.207107, elements[0], 0.0001, "matrix.0");
138 Assert.AreEqual (0.5, elements[1], 0.0001, "matrix.1");
139 Assert.AreEqual (-0.5, elements[2], 0.0001, "matrix.2");
140 Assert.AreEqual (1.207107, elements[3], 0.0001, "matrix.3");
141 Assert.AreEqual (4.686291, elements[4], 0.0001, "matrix.4");
142 Assert.AreEqual (-11.313709, elements[5], 0.0001, "matrix.5");
146 [NUnit.Framework.Category ("NotWorking")]
147 public void Constructor_RectangleF_Color_Color_Single_45 ()
149 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
150 CheckBrushAt45 (lgb);
154 [NUnit.Framework.Category ("NotWorking")]
155 public void Constructor_RectangleF_Color_Color_Single_90 ()
157 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 90f);
158 float[] elements = lgb.Transform.Elements;
159 Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
160 Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
161 Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
162 Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
163 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
164 Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
168 [NUnit.Framework.Category ("NotWorking")]
169 public void Constructor_RectangleF_Color_Color_Single_135 ()
171 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 135f);
172 float[] elements = lgb.Transform.Elements;
173 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
174 Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
175 Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
176 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
177 Assert.AreEqual (48, elements[4], 0.0001, "matrix.4");
178 Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
182 [NUnit.Framework.Category ("NotWorking")]
183 public void Constructor_RectangleF_Color_Color_Single_180 ()
185 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 180f);
186 float[] elements = lgb.Transform.Elements;
187 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
188 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
189 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
190 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
191 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
192 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
196 [NUnit.Framework.Category ("NotWorking")]
197 public void Constructor_RectangleF_Color_Color_Single_270 ()
199 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 270f);
200 float[] elements = lgb.Transform.Elements;
201 Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
202 Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
203 Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
204 Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
205 Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
206 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
210 [NUnit.Framework.Category ("NotWorking")]
211 public void Constructor_RectangleF_Color_Color_Single_315 ()
213 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 315f);
214 float[] elements = lgb.Transform.Elements;
215 Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
216 Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
217 Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
218 Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
219 Assert.AreEqual (-16, elements[4], 0.0001, "matrix.4");
220 Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
224 public void Constructor_RectangleF_Color_Color_Single_360()
226 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f);
227 float[] elements = lgb.Transform.Elements;
229 Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
230 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
231 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
232 Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
233 Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
234 Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
238 [NUnit.Framework.Category ("NotWorking")]
239 public void Constructor_RectangleF_Color_Color_Single_540 ()
241 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 540f);
242 float[] elements = lgb.Transform.Elements;
244 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
245 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
246 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
247 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
248 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
249 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
253 [ExpectedException (typeof (ArgumentException))]
254 public void InterpolationColors_Colors_InvalidBlend ()
256 // default Blend doesn't allow getting this property
257 Assert.IsNotNull (default_brush.InterpolationColors.Colors);
261 [ExpectedException (typeof (ArgumentException))]
262 public void InterpolationColors_Positions_InvalidBlend ()
264 // default Blend doesn't allow getting this property
265 Assert.IsNotNull (default_brush.InterpolationColors.Positions);
269 [ExpectedException (typeof (IndexOutOfRangeException))]
270 public void LinearColors_Empty ()
272 default_brush.LinearColors = new Color[0];
276 [ExpectedException (typeof (IndexOutOfRangeException))]
277 public void LinearColors_One ()
279 default_brush.LinearColors = new Color[1];
283 public void LinearColors_Two ()
285 Assert.AreEqual (Color.FromArgb (255, 0, 0, 255), default_brush.LinearColors[0], "0");
286 Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), default_brush.LinearColors[1], "1");
288 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
289 lgb.LinearColors = new Color[2] { Color.Black, Color.White };
290 // not the same, the alpha is changed to 255 so they can't compare
291 Assert.AreEqual (Color.FromArgb (255, 0, 0, 0), lgb.LinearColors[0], "0");
292 Assert.AreEqual (Color.FromArgb (255, 255, 255, 255), lgb.LinearColors[1], "1");
296 public void LinearColors_Three ()
298 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
299 lgb.LinearColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
300 // not the same, the alpha is changed to 255 so they can't compare
301 Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), lgb.LinearColors[0], "0");
302 Assert.AreEqual (Color.FromArgb (255, 0, 128, 0), lgb.LinearColors[1], "1");
306 [ExpectedException (typeof (ArgumentNullException))]
307 public void Transform_Null ()
309 default_brush.Transform = null;
313 public void Transform_Empty ()
315 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
316 lgb.Transform = new Matrix ();
317 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
321 [ExpectedException (typeof (ArgumentException))]
322 public void Transform_NonInvertible ()
324 default_brush.Transform = new Matrix (123, 24, 82, 16, 47, 30);
328 public void WrapMode_AllValid ()
330 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
331 lgb.WrapMode = WrapMode.Tile;
332 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
333 lgb.WrapMode = WrapMode.TileFlipX;
334 Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
335 lgb.WrapMode = WrapMode.TileFlipY;
336 Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
337 lgb.WrapMode = WrapMode.TileFlipXY;
338 Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
342 [ExpectedException (typeof (ArgumentException))]
343 public void WrapMode_Clamp ()
345 default_brush.WrapMode = WrapMode.Clamp;
349 [ExpectedException (typeof (InvalidEnumArgumentException))]
350 public void WrapMode_Invalid ()
352 default_brush.WrapMode = (WrapMode) Int32.MinValue;
359 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
360 LinearGradientBrush clone = (LinearGradientBrush) lgb.Clone ();
361 Assert.AreEqual (lgb.Blend.Factors.Length, clone.Blend.Factors.Length, "Blend.Factors.Length");
362 Assert.AreEqual (lgb.Blend.Positions.Length, clone.Blend.Positions.Length, "Blend.Positions.Length");
363 Assert.AreEqual (lgb.GammaCorrection, clone.GammaCorrection, "GammaCorrection");
364 Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
365 Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
366 Assert.AreEqual (lgb.Rectangle, clone.Rectangle, "Rectangle");
367 Assert.AreEqual (lgb.Transform, clone.Transform, "Transform");
368 Assert.AreEqual (lgb.WrapMode, clone.WrapMode, "WrapMode");
372 [ExpectedException (typeof (ArgumentNullException))]
373 public void MultiplyTransform1_Null ()
375 default_brush.MultiplyTransform (null);
379 [ExpectedException (typeof (ArgumentNullException))]
380 public void MultiplyTransform2_Null ()
382 default_brush.MultiplyTransform (null, MatrixOrder.Append);
386 public void MultiplyTransform2_Invalid ()
388 default_brush.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
392 [NUnit.Framework.Category ("NotWorking")]
393 public void ResetTransform ()
395 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
396 Assert.IsFalse (lgb.Transform.IsIdentity, "Transform.IsIdentity");
397 lgb.ResetTransform ();
398 Assert.IsTrue (lgb.Transform.IsIdentity, "Reset.IsIdentity");
402 [NUnit.Framework.Category ("NotWorking")]
403 public void RotateTransform ()
405 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
406 lgb.RotateTransform (90);
407 float[] elements = lgb.Transform.Elements;
408 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
409 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
410 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
411 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
412 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
413 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
415 lgb.RotateTransform (270);
416 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
420 [NUnit.Framework.Category ("NotWorking")]
421 public void RotateTransform_Max ()
423 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
424 lgb.RotateTransform (Single.MaxValue);
425 float[] elements = lgb.Transform.Elements;
426 Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
427 Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
428 Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
429 Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
430 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
431 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
435 [NUnit.Framework.Category ("NotWorking")]
436 public void RotateTransform_Min ()
438 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
439 lgb.RotateTransform (Single.MinValue);
440 float[] elements = lgb.Transform.Elements;
441 Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
442 Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
443 Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
444 Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
445 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
446 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
450 [ExpectedException (typeof (ArgumentException))]
451 public void RotateTransform_InvalidOrder ()
453 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
454 lgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
458 public void ScaleTransform ()
460 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
461 lgb.ScaleTransform (2, 4);
462 float[] elements = lgb.Transform.Elements;
463 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
464 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
465 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
466 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
467 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
468 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
470 lgb.ScaleTransform (0.5f, 0.25f);
471 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
475 public void ScaleTransform_MaxMin ()
477 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
478 lgb.ScaleTransform (Single.MaxValue, Single.MinValue);
479 float[] elements = lgb.Transform.Elements;
480 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
481 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
482 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
483 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
484 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
485 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
489 [ExpectedException (typeof (ArgumentException))]
490 public void ScaleTransform_InvalidOrder ()
492 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
493 lgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
497 public void SetBlendTriangularShape_Focus ()
499 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
501 lgb.SetBlendTriangularShape (1);
502 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
504 lgb.SetBlendTriangularShape (0);
505 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
507 lgb.SetBlendTriangularShape (0.5f);
508 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
509 // no impact on matrix
513 public void SetBlendTriangularShape_Scale ()
515 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
517 lgb.SetBlendTriangularShape (0, 1);
518 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
520 lgb.SetBlendTriangularShape (1, 0);
521 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
523 lgb.SetBlendTriangularShape (0.5f, 0.5f);
524 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
525 // no impact on matrix
529 [ExpectedException (typeof (ArgumentException))]
530 public void SetBlendTriangularShape_FocusTooSmall ()
532 default_brush.SetBlendTriangularShape (-1);
536 [ExpectedException (typeof (ArgumentException))]
537 public void SetBlendTriangularShape_FocusTooBig ()
539 default_brush.SetBlendTriangularShape (1.01f);
543 [ExpectedException (typeof (ArgumentException))]
544 public void SetBlendTriangularShape_ScaleTooSmall ()
546 default_brush.SetBlendTriangularShape (1, -1);
550 [ExpectedException (typeof (ArgumentException))]
551 public void SetBlendTriangularShape_ScaleTooBig ()
553 default_brush.SetBlendTriangularShape (1, 1.01f);
557 public void SetSigmaBellShape_Focus ()
559 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
561 lgb.SetSigmaBellShape (1);
562 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
564 lgb.SetSigmaBellShape (0);
565 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
567 lgb.SetSigmaBellShape (0.5f);
568 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
569 // no impact on matrix
573 public void SetSigmaBellShape_Scale ()
575 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
577 lgb.SetSigmaBellShape (0, 1);
578 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
580 lgb.SetSigmaBellShape (1, 0);
581 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-2");
583 lgb.SetSigmaBellShape (0.5f, 0.5f);
584 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-3");
585 // no impact on matrix
589 [ExpectedException (typeof (ArgumentException))]
590 public void SetSigmaBellShape_FocusTooSmall ()
592 default_brush.SetSigmaBellShape (-1);
596 [ExpectedException (typeof (ArgumentException))]
597 public void SetSigmaBellShape_FocusTooBig ()
599 default_brush.SetSigmaBellShape (1.01f);
603 [ExpectedException (typeof (ArgumentException))]
604 public void SetSigmaBellShape_ScaleTooSmall ()
606 default_brush.SetSigmaBellShape (1, -1);
610 [ExpectedException (typeof (ArgumentException))]
611 public void SetSigmaBellShape_ScaleTooBig ()
613 default_brush.SetSigmaBellShape (1, 1.01f);
617 public void TranslateTransform ()
619 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
620 lgb.TranslateTransform (1, 1);
621 float[] elements = lgb.Transform.Elements;
622 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
623 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
624 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
625 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
626 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
627 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
629 lgb.TranslateTransform (-1, -1);
630 // strangely lgb.Transform.IsIdentity is false
631 elements = lgb.Transform.Elements;
632 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
633 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
634 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
635 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
636 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
637 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
641 [ExpectedException (typeof (ArgumentException))]
642 public void TranslateTransform_InvalidOrder ()
644 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
645 lgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);