2 // System.Drawing.Drawing2D.LinearGradientBrush unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006, 2008 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);
94 private void CheckMatrixAndRect (PointF pt1, PointF pt2, float[] testVals)
99 using (LinearGradientBrush b = new LinearGradientBrush (pt1, pt2, Color.Black, Color.White)) {
104 Assert.AreEqual (testVals[0], m.Elements[0], 0.0001, "matrix.0");
105 Assert.AreEqual (testVals[1], m.Elements[1], 0.0001, "matrix.1");
106 Assert.AreEqual (testVals[2], m.Elements[2], 0.0001, "matrix.2");
107 Assert.AreEqual (testVals[3], m.Elements[3], 0.0001, "matrix.3");
108 Assert.AreEqual (testVals[4], m.Elements[4], 0.0001, "matrix.4");
109 Assert.AreEqual (testVals[5], m.Elements[5], 0.0001, "matrix.5");
111 Assert.AreEqual (testVals[6], rect.X, 0.0001, "rect.X");
112 Assert.AreEqual (testVals[7], rect.Y, 0.0001, "rect.Y");
113 Assert.AreEqual (testVals[8], rect.Width, 0.0001, "rect.Width");
114 Assert.AreEqual (testVals[9], rect.Height, 0.0001, "rect.Height");
117 private void CheckMatrixForScalableAngle (RectangleF rect, float angle, float[] testVals)
121 using (LinearGradientBrush b = new LinearGradientBrush (rect, Color.Firebrick, Color.Lavender, angle, true)) {
125 Assert.AreEqual (testVals[0], m.Elements[0], 0.0001, "matrix.0");
126 Assert.AreEqual (testVals[1], m.Elements[1], 0.0001, "matrix.1");
127 Assert.AreEqual (testVals[2], m.Elements[2], 0.0001, "matrix.2");
128 Assert.AreEqual (testVals[3], m.Elements[3], 0.0001, "matrix.3");
129 Assert.AreEqual (testVals[4], m.Elements[4], 0.0001, "matrix.4");
130 Assert.AreEqual (testVals[5], m.Elements[5], 0.0001, "matrix.5");
134 public void Constructor_Point_Point_Color_Color ()
136 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
137 CheckBrushAt45 (lgb);
139 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
140 lgb.WrapMode = WrapMode.TileFlipX;
141 Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
142 lgb.WrapMode = WrapMode.TileFlipY;
143 Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
144 lgb.WrapMode = WrapMode.TileFlipXY;
145 Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
146 // can't set WrapMode.Clamp
150 public void Constructor_Point_Point_Color_Color_1 ()
152 PointF pt1 = new Point (100, 200);
153 PointF pt2 = new Point (200, 200);
154 CheckMatrixAndRect (pt1, pt2, new float[] { 1, 0, 0, 1, 0, 0, 100, 150, 100, 100 });
156 pt1 = new Point (100, 200);
157 pt2 = new Point (0, 200);
158 CheckMatrixAndRect (pt1, pt2, new float[] { -1, 0, 0, -1, 100, 400, 0, 150, 100, 100 });
160 pt1 = new Point (100, 200);
161 pt2 = new Point (100, 300);
162 CheckMatrixAndRect (pt1, pt2, new float[] { 0, 1, -1, 0, 350, 150, 50, 200, 100, 100 });
164 pt1 = new Point (100, 200);
165 pt2 = new Point (100, 100);
166 CheckMatrixAndRect (pt1, pt2, new float[] { 0, -1, 1, 0, -50, 250, 50, 100, 100, 100 });
168 pt1 = new Point (100, 100);
169 pt2 = new Point (150, 225);
170 CheckMatrixAndRect (pt1, pt2, new float[] { 1, 2.5f, -0.6896552f, 0.2758622f, 112.069f, -194.8276f, 100, 100, 50, 125 });
172 pt1 = new Point (100, 100);
173 pt2 = new Point (55, 200);
174 CheckMatrixAndRect (pt1, pt2, new float[] { -1, 2.222222f, -0.7484408f, -0.3367983f, 267.2661f, 28.29753f, 55, 100, 45, 100 });
176 pt1 = new Point (100, 100);
177 pt2 = new Point (150, 60);
178 CheckMatrixAndRect (pt1, pt2, new float[] { 1, -0.8000001f, 0.9756095f, 1.219512f, -78.04876f, 82.43903f, 100, 60, 50, 40 });
180 pt1 = new Point (100, 100);
181 pt2 = new Point (27, 59);
182 CheckMatrixAndRect (pt1, pt2, new float[] { -1, -0.5616435f, 0.8539224f, -1.520399f, 59.11317f, 236.0361f, 27, 59, 73, 41 });
186 public void Constructor_RectangleF_Color_Color_Single_0 ()
188 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
189 CheckDefaultRectangle ("Original", lgb.Rectangle);
190 Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
191 Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors[0]");
192 Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
193 // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
194 Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
195 Assert.AreEqual (c1.ToArgb (), lgb.LinearColors[0].ToArgb (), "LinearColors[0]");
196 Assert.AreEqual (c2.ToArgb (), lgb.LinearColors[1].ToArgb (), "LinearColors[1]");
197 Assert.AreEqual (rect, lgb.Rectangle, "Rectangle");
198 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
199 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode");
201 Matrix matrix = new Matrix (2, -1, 1, 2, 10, 10);
202 lgb.Transform = matrix;
203 Assert.AreEqual (matrix, lgb.Transform, "Transform");
207 public void Constructor_RectangleF_Color_Color_Single_22_5 ()
209 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 22.5f);
210 CheckDefaultRectangle ("Original", lgb.Rectangle);
211 float[] elements = lgb.Transform.Elements;
212 Assert.AreEqual (1.207107, elements[0], 0.0001, "matrix.0");
213 Assert.AreEqual (0.5, elements[1], 0.0001, "matrix.1");
214 Assert.AreEqual (-0.5, elements[2], 0.0001, "matrix.2");
215 Assert.AreEqual (1.207107, elements[3], 0.0001, "matrix.3");
216 Assert.AreEqual (4.686291, elements[4], 0.0001, "matrix.4");
217 Assert.AreEqual (-11.313709, elements[5], 0.0001, "matrix.5");
221 public void Constructor_RectangleF_Color_Color_Single_45 ()
223 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
224 CheckBrushAt45 (lgb);
228 public void Constructor_RectangleF_Color_Color_Single_90 ()
230 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 90f);
231 CheckDefaultRectangle ("Original", lgb.Rectangle);
232 float[] elements = lgb.Transform.Elements;
233 Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
234 Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
235 Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
236 Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
237 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
238 Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
242 public void Constructor_RectangleF_Color_Color_Single_135 ()
244 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 135f);
245 CheckDefaultRectangle ("Original", lgb.Rectangle);
246 float[] elements = lgb.Transform.Elements;
247 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
248 Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
249 Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
250 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
251 Assert.AreEqual (48, elements[4], 0.0001, "matrix.4");
252 Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
256 public void Constructor_RectangleF_Color_Color_Single_180 ()
258 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 180f);
259 CheckDefaultRectangle ("Original", lgb.Rectangle);
260 float[] elements = lgb.Transform.Elements;
261 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
262 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
263 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
264 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
265 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
266 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
270 public void Constructor_RectangleF_Color_Color_Single_270 ()
272 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 270f);
273 CheckDefaultRectangle ("Original", lgb.Rectangle);
274 float[] elements = lgb.Transform.Elements;
275 Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
276 Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
277 Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
278 Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
279 Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
280 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
284 public void Constructor_RectangleF_Color_Color_Single_315 ()
286 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 315f);
287 CheckDefaultRectangle ("Original", lgb.Rectangle);
288 float[] elements = lgb.Transform.Elements;
289 Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
290 Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
291 Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
292 Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
293 Assert.AreEqual (-16, elements[4], 0.0001, "matrix.4");
294 Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
298 public void Constructor_RectangleF_Color_Color_Single_360()
300 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f);
301 CheckDefaultRectangle ("Original", lgb.Rectangle);
302 float[] elements = lgb.Transform.Elements;
304 Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
305 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
306 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
307 Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
308 Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
309 Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
313 public void Constructor_RectangleF_Color_Color_Single_540 ()
315 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 540f);
316 CheckDefaultRectangle ("Original", lgb.Rectangle);
317 float[] elements = lgb.Transform.Elements;
319 Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
320 Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
321 Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
322 Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
323 Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
324 Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
328 [ExpectedException (typeof (ArgumentException))]
329 public void InterpolationColors_Colors_InvalidBlend ()
331 // default Blend doesn't allow getting this property
332 Assert.IsNotNull (default_brush.InterpolationColors.Colors);
336 [ExpectedException (typeof (ArgumentException))]
337 public void InterpolationColors_Positions_InvalidBlend ()
339 // default Blend doesn't allow getting this property
340 Assert.IsNotNull (default_brush.InterpolationColors.Positions);
344 [ExpectedException (typeof (IndexOutOfRangeException))]
345 public void LinearColors_Empty ()
347 default_brush.LinearColors = new Color[0];
351 [ExpectedException (typeof (IndexOutOfRangeException))]
352 public void LinearColors_One ()
354 default_brush.LinearColors = new Color[1];
358 public void LinearColors_Two ()
360 Assert.AreEqual (Color.FromArgb (255, 0, 0, 255), default_brush.LinearColors[0], "0");
361 Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), default_brush.LinearColors[1], "1");
363 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
364 lgb.LinearColors = new Color[2] { Color.Black, Color.White };
365 // not the same, the alpha is changed to 255 so they can't compare
366 Assert.AreEqual (Color.FromArgb (255, 0, 0, 0), lgb.LinearColors[0], "0");
367 Assert.AreEqual (Color.FromArgb (255, 255, 255, 255), lgb.LinearColors[1], "1");
371 public void LinearColors_Three ()
373 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
374 lgb.LinearColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
375 // not the same, the alpha is changed to 255 so they can't compare
376 Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), lgb.LinearColors[0], "0");
377 Assert.AreEqual (Color.FromArgb (255, 0, 128, 0), lgb.LinearColors[1], "1");
381 public void Rectangle ()
383 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
384 CheckDefaultRectangle ("Original", lgb.Rectangle);
385 lgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
386 CheckDefaultRectangle ("Multiply", lgb.Rectangle);
387 lgb.ResetTransform ();
388 CheckDefaultRectangle ("Reset", lgb.Rectangle);
389 lgb.RotateTransform (90);
390 CheckDefaultRectangle ("Rotate", lgb.Rectangle);
391 lgb.ScaleTransform (4, 0.25f);
392 CheckDefaultRectangle ("Scale", lgb.Rectangle);
393 lgb.TranslateTransform (-10, -20);
394 CheckDefaultRectangle ("Translate", lgb.Rectangle);
396 lgb.SetBlendTriangularShape (0.5f);
397 CheckDefaultRectangle ("SetBlendTriangularShape", lgb.Rectangle);
398 lgb.SetSigmaBellShape (0.5f);
399 CheckDefaultRectangle ("SetSigmaBellShape", lgb.Rectangle);
403 [ExpectedException (typeof (ArgumentNullException))]
404 public void Transform_Null ()
406 default_brush.Transform = null;
410 public void Transform_Empty ()
412 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
413 lgb.Transform = new Matrix ();
414 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
418 [ExpectedException (typeof (ArgumentException))]
419 public void Transform_NonInvertible ()
421 default_brush.Transform = new Matrix (123, 24, 82, 16, 47, 30);
425 public void WrapMode_AllValid ()
427 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
428 lgb.WrapMode = WrapMode.Tile;
429 Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
430 lgb.WrapMode = WrapMode.TileFlipX;
431 Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
432 lgb.WrapMode = WrapMode.TileFlipY;
433 Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
434 lgb.WrapMode = WrapMode.TileFlipXY;
435 Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
439 [ExpectedException (typeof (ArgumentException))]
440 public void WrapMode_Clamp ()
442 default_brush.WrapMode = WrapMode.Clamp;
446 [ExpectedException (typeof (InvalidEnumArgumentException))]
447 public void WrapMode_Invalid ()
449 default_brush.WrapMode = (WrapMode) Int32.MinValue;
456 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
457 LinearGradientBrush clone = (LinearGradientBrush) lgb.Clone ();
458 Assert.AreEqual (lgb.Blend.Factors.Length, clone.Blend.Factors.Length, "Blend.Factors.Length");
459 Assert.AreEqual (lgb.Blend.Positions.Length, clone.Blend.Positions.Length, "Blend.Positions.Length");
460 Assert.AreEqual (lgb.GammaCorrection, clone.GammaCorrection, "GammaCorrection");
461 Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
462 Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
463 Assert.AreEqual (lgb.Rectangle, clone.Rectangle, "Rectangle");
464 Assert.AreEqual (lgb.Transform, clone.Transform, "Transform");
465 Assert.AreEqual (lgb.WrapMode, clone.WrapMode, "WrapMode");
469 [ExpectedException (typeof (ArgumentNullException))]
470 public void MultiplyTransform1_Null ()
472 default_brush.MultiplyTransform (null);
476 [ExpectedException (typeof (ArgumentNullException))]
477 public void MultiplyTransform2_Null ()
479 default_brush.MultiplyTransform (null, MatrixOrder.Append);
483 public void MultiplyTransform2_Invalid ()
485 default_brush.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
489 [ExpectedException (typeof (ArgumentException))]
490 public void MultiplyTransform_NonInvertible ()
492 Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30);
493 default_brush.MultiplyTransform (noninvertible);
497 public void ResetTransform ()
499 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
500 Assert.IsFalse (lgb.Transform.IsIdentity, "Transform.IsIdentity");
501 lgb.ResetTransform ();
502 Assert.IsTrue (lgb.Transform.IsIdentity, "Reset.IsIdentity");
506 public void RotateTransform ()
508 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
509 lgb.RotateTransform (90);
510 float[] elements = lgb.Transform.Elements;
511 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
512 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
513 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
514 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
515 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
516 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
518 lgb.RotateTransform (270);
519 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
523 [NUnit.Framework.Category ("NotWorking")]
524 public void RotateTransform_Max ()
526 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
527 lgb.RotateTransform (Single.MaxValue);
528 float[] elements = lgb.Transform.Elements;
529 Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
530 Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
531 Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
532 Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
533 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
534 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
538 [NUnit.Framework.Category ("NotWorking")]
539 public void RotateTransform_Min ()
541 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
542 lgb.RotateTransform (Single.MinValue);
543 float[] elements = lgb.Transform.Elements;
544 Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
545 Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
546 Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
547 Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
548 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
549 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
553 [ExpectedException (typeof (ArgumentException))]
554 public void RotateTransform_InvalidOrder ()
556 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
557 lgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
561 public void ScaleTransform ()
563 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
564 lgb.ScaleTransform (2, 4);
565 float[] elements = lgb.Transform.Elements;
566 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
567 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
568 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
569 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
570 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
571 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
573 lgb.ScaleTransform (0.5f, 0.25f);
574 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
578 public void ScaleTransform_45 ()
580 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
581 lgb.ScaleTransform (3, 3);
582 float[] elements = lgb.Transform.Elements;
583 Assert.AreEqual (3, elements[0], 0.1, "matrix.0");
584 Assert.AreEqual (3, elements[1], 0.1, "matrix.1");
585 Assert.AreEqual (-3, elements[2], 0.1, "matrix.2");
586 Assert.AreEqual (3, elements[3], 0.1, "matrix.3");
587 Assert.AreEqual (16, elements[4], 0.1, "matrix.4");
588 Assert.AreEqual (-16, elements[5], 0.1, "matrix.5");
592 public void ScaleTransform_MaxMin ()
594 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
595 lgb.ScaleTransform (Single.MaxValue, Single.MinValue);
596 float[] elements = lgb.Transform.Elements;
597 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
598 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
599 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
600 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
601 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
602 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
606 [ExpectedException (typeof (ArgumentException))]
607 public void ScaleTransform_InvalidOrder ()
609 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
610 lgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
614 public void SetBlendTriangularShape_Focus ()
616 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
618 lgb.SetBlendTriangularShape (1);
619 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
621 lgb.SetBlendTriangularShape (0);
622 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
624 lgb.SetBlendTriangularShape (0.5f);
625 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
626 // no impact on matrix
630 public void SetBlendTriangularShape_Scale ()
632 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
634 lgb.SetBlendTriangularShape (0, 1);
635 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
637 lgb.SetBlendTriangularShape (1, 0);
638 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
640 lgb.SetBlendTriangularShape (0.5f, 0.5f);
641 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
642 // no impact on matrix
646 [ExpectedException (typeof (ArgumentException))]
647 public void SetBlendTriangularShape_FocusTooSmall ()
649 default_brush.SetBlendTriangularShape (-1);
653 [ExpectedException (typeof (ArgumentException))]
654 public void SetBlendTriangularShape_FocusTooBig ()
656 default_brush.SetBlendTriangularShape (1.01f);
660 [ExpectedException (typeof (ArgumentException))]
661 public void SetBlendTriangularShape_ScaleTooSmall ()
663 default_brush.SetBlendTriangularShape (1, -1);
667 [ExpectedException (typeof (ArgumentException))]
668 public void SetBlendTriangularShape_ScaleTooBig ()
670 default_brush.SetBlendTriangularShape (1, 1.01f);
674 public void SetSigmaBellShape_Focus ()
676 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
678 lgb.SetSigmaBellShape (1);
679 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
681 lgb.SetSigmaBellShape (0);
682 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
684 lgb.SetSigmaBellShape (0.5f);
685 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
686 // no impact on matrix
690 public void SetSigmaBellShape_Scale ()
692 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
694 lgb.SetSigmaBellShape (0, 1);
695 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
697 lgb.SetSigmaBellShape (1, 0);
698 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-2");
700 lgb.SetSigmaBellShape (0.5f, 0.5f);
701 Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-3");
702 // no impact on matrix
706 [ExpectedException (typeof (ArgumentException))]
707 public void SetSigmaBellShape_FocusTooSmall ()
709 default_brush.SetSigmaBellShape (-1);
713 [ExpectedException (typeof (ArgumentException))]
714 public void SetSigmaBellShape_FocusTooBig ()
716 default_brush.SetSigmaBellShape (1.01f);
720 [ExpectedException (typeof (ArgumentException))]
721 public void SetSigmaBellShape_ScaleTooSmall ()
723 default_brush.SetSigmaBellShape (1, -1);
727 [ExpectedException (typeof (ArgumentException))]
728 public void SetSigmaBellShape_ScaleTooBig ()
730 default_brush.SetSigmaBellShape (1, 1.01f);
734 public void TranslateTransform ()
736 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
737 lgb.TranslateTransform (1, 1);
738 float[] elements = lgb.Transform.Elements;
739 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
740 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
741 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
742 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
743 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
744 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
746 lgb.TranslateTransform (-1, -1);
747 // strangely lgb.Transform.IsIdentity is false
748 elements = lgb.Transform.Elements;
749 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
750 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
751 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
752 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
753 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
754 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
758 [ExpectedException (typeof (ArgumentException))]
759 public void TranslateTransform_InvalidOrder ()
761 LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
762 lgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
766 public void Transform_Operations ()
768 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
769 Matrix clone = lgb.Transform.Clone ();
770 Matrix mul = clone.Clone ();
772 clone.Multiply (mul, MatrixOrder.Append);
773 lgb.MultiplyTransform (mul, MatrixOrder.Append);
774 Assert.AreEqual (lgb.Transform, clone, "Multiply/Append");
776 clone.Multiply (mul, MatrixOrder.Prepend);
777 lgb.MultiplyTransform (mul, MatrixOrder.Prepend);
778 Assert.AreEqual (lgb.Transform, clone, "Multiply/Prepend");
780 clone.Rotate (45, MatrixOrder.Append);
781 lgb.RotateTransform (45, MatrixOrder.Append);
782 Assert.AreEqual (lgb.Transform, clone, "Rotate/Append");
784 clone.Rotate (45, MatrixOrder.Prepend);
785 lgb.RotateTransform (45, MatrixOrder.Prepend);
786 Assert.AreEqual (lgb.Transform, clone, "Rotate/Prepend");
788 clone.Scale (0.25f, 2, MatrixOrder.Append);
789 lgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
790 Assert.AreEqual (lgb.Transform, clone, "Scale/Append");
792 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
793 lgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
794 Assert.AreEqual (lgb.Transform, clone, "Scale/Prepend");
796 clone.Translate (10, 20, MatrixOrder.Append);
797 lgb.TranslateTransform (10, 20, MatrixOrder.Append);
798 Assert.AreEqual (lgb.Transform, clone, "Translate/Append");
800 clone.Translate (30, 40, MatrixOrder.Prepend);
801 lgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
802 Assert.AreEqual (lgb.Transform, clone, "Translate/Prepend");
805 lgb.ResetTransform ();
806 Assert.AreEqual (lgb.Transform, clone, "Reset");
810 public void Transform_Operations_OnScalableAngle ()
812 LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f, true);
813 Matrix clone = lgb.Transform.Clone ();
814 Matrix mul = clone.Clone ();
815 Matrix m = new Matrix ();
817 m.Translate (rect.Width, rect.Height);
820 clone.Multiply (mul, MatrixOrder.Append);
821 lgb.MultiplyTransform (mul, MatrixOrder.Append);
822 Assert.AreEqual (lgb.Transform, clone, "Multiply/Append");
824 clone.Multiply (mul, MatrixOrder.Prepend);
825 lgb.MultiplyTransform (mul, MatrixOrder.Prepend);
826 Assert.AreEqual (lgb.Transform, clone, "Multiply/Prepend");
828 clone.Rotate (45, MatrixOrder.Append);
829 lgb.RotateTransform (45, MatrixOrder.Append);
830 Assert.AreEqual (lgb.Transform, clone, "Rotate/Append");
832 clone.Rotate (45, MatrixOrder.Prepend);
833 lgb.RotateTransform (45, MatrixOrder.Prepend);
834 Assert.AreEqual (lgb.Transform, clone, "Rotate/Prepend");
836 clone.Scale (0.25f, 2, MatrixOrder.Append);
837 lgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
838 Assert.AreEqual (lgb.Transform, clone, "Scale/Append");
840 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
841 lgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
842 Assert.AreEqual (lgb.Transform, clone, "Scale/Prepend");
844 clone.Translate (10, 20, MatrixOrder.Append);
845 lgb.TranslateTransform (10, 20, MatrixOrder.Append);
846 Assert.AreEqual (lgb.Transform, clone, "Translate/Append");
848 clone.Translate (30, 40, MatrixOrder.Prepend);
849 lgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
850 Assert.AreEqual (lgb.Transform, clone, "Translate/Prepend");
853 lgb.ResetTransform ();
854 Assert.AreEqual (lgb.Transform, clone, "Reset");
858 public void Constructor_Rectangle_Angle_Scalable ()
860 CheckMatrixForScalableAngle (new RectangleF (0, 0, 10, 10), 15, new float[] { 1.183013f, 0.3169873f, -0.3169873f, 1.183012f, 0.6698728f, -2.5f });
862 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 15, new float[] { 1.183012f, 0.176104f, -0.5705772f, 1.183012f, 34.77311f, -28.76387f });
863 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 75, new float[] { 0.3169872f, 0.6572293f, -2.129423f, 0.3169873f, 232.2269f, 8.763878f });
864 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 95, new float[] { -0.09442029f, 0.599571f, -1.942611f, -0.09442017f, 247.2034f, 48.05788f });
865 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 150, new float[] { -1.183013f, 0.3794515f, -1.229423f, -1.183013f, 268.2269f, 157.0972f });
866 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 215, new float[] { -1.140856f, -0.4437979f, 1.437905f, -1.140856f, 38.34229f, 215.2576f });
867 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 50), 300, new float[] { 0.6830127f, -0.6572294f, 2.129422f, 0.6830124f, -157.2269f, 76.23613f });
869 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 15, new float[] { 1.183012f, 0.5283121f, -0.1901924f, 1.183012f, 11.95002f, -64.33012f });
870 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 75, new float[] { 0.3169872f, 1.971688f, -0.7098077f, 0.3169872f, 147.05f, -55.66987f });
871 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 95, new float[] { -0.09442029f, 1.798713f, -0.6475369f, -0.09442022f, 169.499f, 12.84323f });
872 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 150, new float[] { -1.183013f, 1.138354f, -0.4098077f, -1.183013f, 219.05f, 209.3301f });
873 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 215, new float[] { -1.140856f, -1.331394f, 0.4793016f, -1.140856f, 95.85849f, 388.8701f });
874 CheckMatrixForScalableAngle (new RectangleF (30, 60, 90, 150), 300, new float[] { 0.6830127f, -1.971688f, 0.7098075f, 0.6830125f, -72.04998f, 190.6699f });
878 [ExpectedException (typeof (NullReferenceException))]
879 public void LinearColors_Null ()
881 default_brush.LinearColors = null;
885 [ExpectedException (typeof (ArgumentException))]
886 public void InterpolationColors_Null ()
888 default_brush.InterpolationColors = null;
892 [ExpectedException (typeof (NullReferenceException))]
893 public void Blend_Null ()
895 default_brush.Blend = null;