2006-03-30 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / TestMatrix.cs
1 //
2 // Tests for System.Drawing.Drawing2D.Matrix.cs
3 //
4 // Authors:
5 //      Jordi Mas i Hernandez <jordi@ximian.com>
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
34 using System.Security.Permissions;
35
36 namespace MonoTests.System.Drawing.Drawing2D
37 {
38         [TestFixture]
39         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40         public class MatrixTest : Assertion {
41
42                 private Matrix default_matrix;
43                 private Rectangle rect;
44                 private RectangleF rectf;
45
46                 [TestFixtureSetUp]
47                 public void FixtureSetUp ()
48                 {
49                         default_matrix = new Matrix ();
50                 }
51
52                 [Test]
53                 public void Constructor_Default ()
54                 {
55                         Matrix matrix = new Matrix ();
56                         AssertEquals ("C#1", 6, matrix.Elements.Length);
57                 }
58
59                 [Test]
60                 public void Constructor_SixFloats ()
61                 {
62                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
63                         AssertEquals ("C#2", 6, matrix.Elements.Length);
64                         AssertEquals ("C#3", 10, matrix.Elements[0]);
65                         AssertEquals ("C#4", 20, matrix.Elements[1]);
66                         AssertEquals ("C#5", 30, matrix.Elements[2]);
67                         AssertEquals ("C#6", 40, matrix.Elements[3]);
68                         AssertEquals ("C#7", 50, matrix.Elements[4]);
69                         AssertEquals ("C#8", 60, matrix.Elements[5]);
70                 }
71
72                 [Test]
73                 public void Constructor_Float ()
74                 {
75                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
76                         AssertEquals ("C#2", 6, matrix.Elements.Length);
77                         AssertEquals ("C#3", 10, matrix.Elements[0]);
78                         AssertEquals ("C#4", 20, matrix.Elements[1]);
79                         AssertEquals ("C#5", 30, matrix.Elements[2]);
80                         AssertEquals ("C#6", 40, matrix.Elements[3]);
81                         AssertEquals ("C#7", 50, matrix.Elements[4]);
82                         AssertEquals ("C#8", 60, matrix.Elements[5]);
83                 }
84
85                 [Test]
86                 [ExpectedException (typeof (ArgumentNullException))]
87                 public void Constructor_Int_Null ()
88                 {
89                         new Matrix (rect, null);
90                 }
91
92                 [Test]
93                 [ExpectedException (typeof (ArgumentException))]
94                 public void Constructor_Int_Empty ()
95                 {
96                         new Matrix (rect, new Point[0]);
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (ArgumentNullException))]
101                 public void Constructor_Float_Null ()
102                 {
103                         new Matrix (rectf, null);
104                 }
105
106                 [Test]
107                 [ExpectedException (typeof (ArgumentException))]
108                 public void Constructor_Float_Empty ()
109                 {
110                         new Matrix (rectf, new PointF[0]);
111                 }
112
113                 // Properties
114
115                 [Test]
116                 public void Invertible ()
117                 {
118                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
119                         AssertEquals ("I#1", false, matrix.IsInvertible);
120
121                         matrix = new Matrix (156, 46, 0, 0, 106, 19);
122                         AssertEquals ("I#2", false, matrix.IsInvertible);
123
124                         matrix = new Matrix (146, 66, 158, 104, 42, 150);
125                         AssertEquals ("I#3", true, matrix.IsInvertible);
126
127                         matrix = new Matrix (119, 140, 145, 74, 102, 58);
128                         AssertEquals ("I#4", true, matrix.IsInvertible);
129                 }
130                 
131                 [Test]
132                 public void IsIdentity ()
133                 {
134                         Matrix identity = new Matrix ();
135                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
136                         AssertEquals ("N#1-identity", false, matrix.IsIdentity);
137                         Assert ("N#1-equals", !identity.Equals (matrix));
138                         
139                         matrix = new Matrix (1, 0, 0, 1, 0, 0);
140                         AssertEquals ("N#2-identity", true, matrix.IsIdentity);
141                         Assert ("N#2-equals", identity.Equals (matrix));
142
143                         // so what's the required precision ?
144
145                         matrix = new Matrix (1.1f, 0.1f, -0.1f, 0.9f, 0, 0);
146                         Assert ("N#3-identity", !matrix.IsIdentity);
147                         Assert ("N#3-equals", !identity.Equals (matrix));
148
149                         matrix = new Matrix (1.01f, 0.01f, -0.01f, 0.99f, 0, 0);
150                         Assert ("N#4-identity", !matrix.IsIdentity);
151                         Assert ("N#4-equals", !identity.Equals (matrix));
152
153                         matrix = new Matrix (1.001f, 0.001f, -0.001f, 0.999f, 0, 0);
154                         Assert ("N#5-identity", !matrix.IsIdentity);
155                         Assert ("N#5-equals", !identity.Equals (matrix));
156
157                         matrix = new Matrix (1.0001f, 0.0001f, -0.0001f, 0.9999f, 0, 0);
158                         Assert ("N#6-identity", matrix.IsIdentity);
159                         // note: NOT equal
160                         Assert ("N#6-equals", !identity.Equals (matrix));
161
162                         matrix = new Matrix (1.0009f, 0.0009f, -0.0009f, 0.99995f, 0, 0);
163                         Assert ("N#7-identity", !matrix.IsIdentity);
164                         Assert ("N#7-equals", !identity.Equals (matrix));
165                 }
166                 
167                 [Test]
168                 public void IsOffsetX ()
169                 {
170                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
171                         AssertEquals ("X#1", 47, matrix.OffsetX);                       
172                 }
173                 
174                 [Test]
175                 public void IsOffsetY ()
176                 {
177                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
178                         AssertEquals ("Y#1", 30, matrix.OffsetY);                       
179                 }
180                 
181                 // Elements Property is checked implicity in other test
182
183                 //
184                 // Methods
185                 //
186                 
187
188                 [Test]
189                 public void Clone ()
190                 {
191                         Matrix matsrc = new Matrix (10, 20, 30, 40, 50, 60);
192                         Matrix matrix  = matsrc.Clone ();
193
194                         AssertEquals ("D#1", 6, matrix.Elements.Length);
195                         AssertEquals ("D#2", 10, matrix.Elements[0]);
196                         AssertEquals ("D#3", 20, matrix.Elements[1]);
197                         AssertEquals ("D#4", 30, matrix.Elements[2]);
198                         AssertEquals ("D#5", 40, matrix.Elements[3]);
199                         AssertEquals ("D#6", 50, matrix.Elements[4]);
200                         AssertEquals ("D#7", 60, matrix.Elements[5]);
201                 }
202
203                 [Test]
204                 public void HashCode ()
205                 {
206                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
207                         Matrix clone = matrix.Clone ();
208                         Assert ("HashCode/Clone", matrix.GetHashCode () != clone.GetHashCode ());
209
210                         Matrix matrix2 = new Matrix (10, 20, 30, 40, 50, 60);
211                         Assert ("HashCode/Identical", matrix.GetHashCode () != matrix2.GetHashCode ());
212                 }
213
214                 [Test]
215                 public void Reset ()
216                 {
217                         Matrix matrix = new Matrix (51, 52, 53, 54, 55, 56);
218                         matrix.Reset ();
219
220                         AssertEquals ("F#1", 6, matrix.Elements.Length);
221                         AssertEquals ("F#2", 1, matrix.Elements[0]);
222                         AssertEquals ("F#3", 0, matrix.Elements[1]);
223                         AssertEquals ("F#4", 0, matrix.Elements[2]);
224                         AssertEquals ("F#5", 1, matrix.Elements[3]);
225                         AssertEquals ("F#6", 0, matrix.Elements[4]);
226                         AssertEquals ("F#7", 0, matrix.Elements[5]);
227                 }
228
229                 [Test]
230                 public void Rotate ()
231                 {
232                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
233                         matrix.Rotate (180);
234
235                         AssertEquals ("H#1", -10, matrix.Elements[0]);
236                         AssertEquals ("H#2", -20, matrix.Elements[1]);
237                         AssertEquals ("H#3", -30, matrix.Elements[2]);
238                         AssertEquals ("H#4", -40, matrix.Elements[3]);
239                         AssertEquals ("H#5", 50, matrix.Elements[4]);
240                         AssertEquals ("H#6", 60, matrix.Elements[5]);
241                 }
242
243                 [Test]
244                 public void Rotate_45_135 ()
245                 {
246                         Matrix matrix = new Matrix ();
247                         Assert ("original.IsIdentity", matrix.IsIdentity);
248
249                         matrix.Rotate (45);
250                         Assert ("+45.!IsIdentity", !matrix.IsIdentity);
251                         float[] elements = matrix.Elements;
252                         AssertEquals ("45#1", 0.7071068, elements[0]);
253                         AssertEquals ("45#2", 0.7071068, elements[1]);
254                         AssertEquals ("45#3", -0.7071068, elements[2]);
255                         AssertEquals ("45#4", 0.7071068, elements[3]);
256                         AssertEquals ("45#5", 0, elements[4]);
257                         AssertEquals ("45#6", 0, elements[5]);
258
259                         matrix.Rotate (135);
260                         Assert ("+135.!IsIdentity", !matrix.IsIdentity);
261                         elements = matrix.Elements;
262                         AssertEquals ("180#1", -1, elements[0], 0.0001);
263                         AssertEquals ("180#2", 0, elements[1], 0.0001);
264                         AssertEquals ("180#3", 0, elements[2], 0.0001);
265                         AssertEquals ("180#4", -1, elements[3], 0.0001);
266                         AssertEquals ("180#5", 0, elements[4]);
267                         AssertEquals ("180#6", 0, elements[5]);
268                 }
269
270                 [Test]
271                 public void Rotate_90_270_Matrix ()
272                 {
273                         Matrix matrix = new Matrix ();
274                         Assert ("original.IsIdentity", matrix.IsIdentity);
275
276                         matrix.Rotate (90);
277                         Assert ("+90.!IsIdentity", !matrix.IsIdentity);
278                         float[] elements = matrix.Elements;
279                         AssertEquals ("90#1", 0, elements[0], 0.0001);
280                         AssertEquals ("90#2", 1, elements[1], 0.0001);
281                         AssertEquals ("90#3", -1, elements[2], 0.0001);
282                         AssertEquals ("90#4", 0, elements[3], 0.0001);
283                         AssertEquals ("90#5", 0, elements[4]);
284                         AssertEquals ("90#6", 0, elements[5]);
285
286                         matrix.Rotate (270);
287                         // this isn't a perfect 1, 0, 0, 1, 0, 0 matrix - but close enough
288                         Assert ("360.IsIdentity", matrix.IsIdentity);
289                         Assert ("360.Equals", !new Matrix ().Equals (matrix));
290                 }
291
292                 [Test]
293                 [ExpectedException (typeof (ArgumentException))]
294                 public void Rotate_InvalidOrder ()
295                 {
296                         new Matrix ().Rotate (180, (MatrixOrder) Int32.MinValue);
297                 }
298
299                 [Test]
300                 public void RotateAt ()
301                 {
302                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
303                         matrix.RotateAt (180, new PointF (10, 10));
304
305                         AssertEquals ("I#1", -10, matrix.Elements[0]);
306                         AssertEquals ("I#2", -20, matrix.Elements[1]);
307                         AssertEquals ("I#3", -30, matrix.Elements[2]);
308                         AssertEquals ("I#4", -40, matrix.Elements[3]);
309                         AssertEquals ("I#5", 850, matrix.Elements[4]);
310                         AssertEquals ("I#6", 1260, matrix.Elements[5]);
311                 }
312
313                 [Test]
314                 [ExpectedException (typeof (ArgumentException))]
315                 public void RotateAt_InvalidOrder ()
316                 {
317                         new Matrix ().RotateAt (180, new PointF (10, 10), (MatrixOrder) Int32.MinValue);
318                 }
319
320                 [Test]
321                 [ExpectedException (typeof (ArgumentNullException))]
322                 public void Multiply_Null ()
323                 {
324                         new Matrix (10, 20, 30, 40, 50, 60).Multiply (null);
325                 }
326
327                 [Test]
328                 public void Multiply ()
329                 {
330                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
331                         matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60));
332
333                         AssertEquals ("J#1", 700, matrix.Elements[0]);
334                         AssertEquals ("J#2", 1000, matrix.Elements[1]);
335                         AssertEquals ("J#3", 1500, matrix.Elements[2]);
336                         AssertEquals ("J#4", 2200, matrix.Elements[3]);
337                         AssertEquals ("J#5", 2350, matrix.Elements[4]);
338                         AssertEquals ("J#6", 3460, matrix.Elements[5]);
339                 }
340
341                 [Test]
342                 [ExpectedException (typeof (ArgumentNullException))]
343                 public void Multiply_Null_Order ()
344                 {
345                         new Matrix (10, 20, 30, 40, 50, 60).Multiply (null, MatrixOrder.Append);
346                 }
347
348                 [Test]
349                 public void Multiply_Append ()
350                 {
351                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
352                         matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), MatrixOrder.Append);
353
354                         AssertEquals ("J#1", 700, matrix.Elements[0]);
355                         AssertEquals ("J#2", 1000, matrix.Elements[1]);
356                         AssertEquals ("J#3", 1500, matrix.Elements[2]);
357                         AssertEquals ("J#4", 2200, matrix.Elements[3]);
358                         AssertEquals ("J#5", 2350, matrix.Elements[4]);
359                         AssertEquals ("J#6", 3460, matrix.Elements[5]);
360                 }
361
362                 [Test]
363                 public void Multiply_Prepend ()
364                 {
365                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
366                         matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), MatrixOrder.Prepend);
367
368                         AssertEquals ("J#1", 700, matrix.Elements[0]);
369                         AssertEquals ("J#2", 1000, matrix.Elements[1]);
370                         AssertEquals ("J#3", 1500, matrix.Elements[2]);
371                         AssertEquals ("J#4", 2200, matrix.Elements[3]);
372                         AssertEquals ("J#5", 2350, matrix.Elements[4]);
373                         AssertEquals ("J#6", 3460, matrix.Elements[5]);
374                 }
375
376                 [Test]
377                 [ExpectedException (typeof (ArgumentException))]
378                 public void Multiply_InvalidOrder ()
379                 {
380                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
381                         matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), (MatrixOrder)Int32.MinValue);
382                 }
383
384                 [Test]
385                 public void Equals ()
386                 {
387                         Matrix mat1 = new Matrix (10, 20, 30, 40, 50, 60);
388                         Matrix mat2 = new Matrix (10, 20, 30, 40, 50, 60);
389                         Matrix mat3 = new Matrix (10, 20, 30, 40, 50, 10);
390
391                         AssertEquals ("E#1", true, mat1.Equals (mat2));
392                         AssertEquals ("E#2", false, mat2.Equals (mat3));
393                         AssertEquals ("E#3", false, mat1.Equals (mat3));
394                 }
395                 
396                 [Test]
397                 public void Invert ()
398                 {
399                         Matrix matrix = new Matrix (1, 2, 3, 4, 5, 6);
400                         matrix.Invert ();
401                         
402                         AssertEquals ("V#1", -2, matrix.Elements[0]);
403                         AssertEquals ("V#2", 1, matrix.Elements[1]);
404                         AssertEquals ("V#3", 1.5, matrix.Elements[2]);
405                         AssertEquals ("V#4", -0.5, matrix.Elements[3]);
406                         AssertEquals ("V#5", 1, matrix.Elements[4]);
407                         AssertEquals ("V#6", -2, matrix.Elements[5]);                   
408                 }
409
410                 [Test]
411                 public void Invert_Translation ()
412                 {
413                         Matrix matrix = new Matrix (1, 0, 0, 1, 8, 8);
414                         matrix.Invert ();
415
416                         float[] elements = matrix.Elements;
417                         AssertEquals ("#1", 1, elements[0]);
418                         AssertEquals ("#2", 0, elements[1]);
419                         AssertEquals ("#3", 0, elements[2]);
420                         AssertEquals ("#4", 1, elements[3]);
421                         AssertEquals ("#5", -8, elements[4]);
422                         AssertEquals ("#6", -8, elements[5]);
423                 }
424
425                 [Test]
426                 public void Invert_Identity ()
427                 {
428                         Matrix matrix = new Matrix ();
429                         Assert ("IsIdentity", matrix.IsIdentity);
430                         Assert ("IsInvertible", matrix.IsInvertible);
431                         matrix.Invert ();
432                         Assert ("IsIdentity-2", matrix.IsIdentity);
433                         Assert ("IsInvertible-2", matrix.IsInvertible);
434                 }
435
436                 [Test]
437                 public void Scale ()
438                 {
439                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
440                         matrix.Scale (2, 4);
441
442                         AssertEquals ("S#1", 20, matrix.Elements[0]);
443                         AssertEquals ("S#2", 40, matrix.Elements[1]);
444                         AssertEquals ("S#3", 120, matrix.Elements[2]);
445                         AssertEquals ("S#4", 160, matrix.Elements[3]);
446                         AssertEquals ("S#5", 50, matrix.Elements[4]);
447                         AssertEquals ("S#6", 60, matrix.Elements[5]);
448
449                         matrix.Scale (0.5f, 0.25f);
450
451                         AssertEquals ("SB#1", 10, matrix.Elements[0]);
452                         AssertEquals ("SB#2", 20, matrix.Elements[1]);
453                         AssertEquals ("SB#3", 30, matrix.Elements[2]);
454                         AssertEquals ("SB#4", 40, matrix.Elements[3]);
455                         AssertEquals ("SB#5", 50, matrix.Elements[4]);
456                         AssertEquals ("SB#6", 60, matrix.Elements[5]);
457                 }
458
459                 [Test]
460                 public void Scale_Negative ()
461                 {
462                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
463                         matrix.Scale (-2, -4);
464
465                         AssertEquals ("S#1", -20, matrix.Elements[0]);
466                         AssertEquals ("S#2", -40, matrix.Elements[1]);
467                         AssertEquals ("S#3", -120, matrix.Elements[2]);
468                         AssertEquals ("S#4", -160, matrix.Elements[3]);
469                         AssertEquals ("S#5", 50, matrix.Elements[4]);
470                         AssertEquals ("S#6", 60, matrix.Elements[5]);
471                 }
472
473                 [Test]
474                 [ExpectedException (typeof (ArgumentException))]
475                 public void Scale_InvalidOrder ()
476                 {
477                         new Matrix ().Scale (2, 1, (MatrixOrder) Int32.MinValue);
478                 }
479                 
480                 [Test]
481                 public void Shear ()
482                 {
483                         Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
484                         matrix.Shear (2, 4);
485
486                         AssertEquals ("H#1", 130, matrix.Elements[0]);
487                         AssertEquals ("H#2", 180, matrix.Elements[1]);
488                         AssertEquals ("H#3", 50, matrix.Elements[2]);
489                         AssertEquals ("H#4", 80, matrix.Elements[3]);
490                         AssertEquals ("H#5", 50, matrix.Elements[4]);
491                         AssertEquals ("H#6", 60, matrix.Elements[5]);
492                         
493                         matrix = new Matrix (5, 3, 9, 2, 2, 1);
494                         matrix.Shear  (10, 20);                 
495                         
496                         AssertEquals ("H#7", 185, matrix.Elements[0]);
497                         AssertEquals ("H#8", 43, matrix.Elements[1]);
498                         AssertEquals ("H#9", 59, matrix.Elements[2]);
499                         AssertEquals ("H#10", 32, matrix.Elements[3]);
500                         AssertEquals ("H#11", 2, matrix.Elements[4]);
501                         AssertEquals ("H#12", 1, matrix.Elements[5]);                       
502                 }
503
504                 [Test]
505                 [ExpectedException (typeof (ArgumentException))]
506                 public void Shear_InvalidOrder ()
507                 {
508                         new Matrix ().Shear (-1, 1, (MatrixOrder) Int32.MinValue);
509                 }
510                 
511                 [Test]
512                 public void TransformPoints ()
513                 {
514                         Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
515                         PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
516                         matrix.TransformPoints (pointsF);
517                                                 
518                         AssertEquals ("K#1", 38, pointsF[0].X);
519                         AssertEquals ("K#2", 52, pointsF[0].Y);
520                         AssertEquals ("K#3", 66, pointsF[1].X);
521                         AssertEquals ("K#4", 92, pointsF[1].Y);
522                         
523                         Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
524                         matrix.TransformPoints (points);
525                         AssertEquals ("K#5", 38, pointsF[0].X);
526                         AssertEquals ("K#6", 52, pointsF[0].Y);
527                         AssertEquals ("K#7", 66, pointsF[1].X);
528                         AssertEquals ("K#8", 92, pointsF[1].Y);                                             
529                 }
530
531                 [Test]
532                 [ExpectedException (typeof (ArgumentNullException))]
533                 public void TransformPoints_Point_Null ()
534                 {
535                         new Matrix ().TransformPoints ((Point[]) null);
536                 }
537
538                 [Test]
539                 [ExpectedException (typeof (ArgumentNullException))]
540                 public void TransformPoints_PointF_Null ()
541                 {
542                         new Matrix ().TransformPoints ((PointF[]) null);
543                 }
544
545                 [Test]
546                 [ExpectedException (typeof (ArgumentException))]
547                 public void TransformPoints_Point_Empty ()
548                 {
549                         new Matrix ().TransformPoints (new Point[0]);
550                 }
551
552                 [Test]
553                 [ExpectedException (typeof (ArgumentException))]
554                 public void TransformPoints_PointF_Empty ()
555                 {
556                         new Matrix ().TransformPoints (new PointF[0]);
557                 }
558                 
559                 [Test]
560                 public void TransformVectors  ()
561                 {
562                         Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
563                         PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
564                         matrix.TransformVectors (pointsF);
565                                                 
566                         AssertEquals ("N#1", 28, pointsF[0].X);
567                         AssertEquals ("N#2", 40, pointsF[0].Y);
568                         AssertEquals ("N#3", 56, pointsF[1].X);
569                         AssertEquals ("N#4", 80, pointsF[1].Y);
570                         
571                         Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
572                         matrix.TransformVectors (points);
573                         AssertEquals ("N#5", 28, pointsF[0].X);
574                         AssertEquals ("N#6", 40, pointsF[0].Y);
575                         AssertEquals ("N#7", 56, pointsF[1].X);
576                         AssertEquals ("N#8", 80, pointsF[1].Y);                                             
577                 }
578
579                 [Test]
580                 [ExpectedException (typeof (ArgumentNullException))]
581                 public void TransformVectors_Point_Null ()
582                 {
583                         new Matrix ().TransformVectors ((Point[]) null);
584                 }
585
586                 [Test]
587                 [ExpectedException (typeof (ArgumentNullException))]
588                 public void TransformVectors_PointF_Null ()
589                 {
590                         new Matrix ().TransformVectors ((PointF[]) null);
591                 }
592
593                 [Test]
594                 [ExpectedException (typeof (ArgumentException))]
595                 public void TransformVectors_Point_Empty ()
596                 {
597                         new Matrix ().TransformVectors (new Point[0]);
598                 }
599
600                 [Test]
601                 [ExpectedException (typeof (ArgumentException))]
602                 public void TransformVectors_PointF_Empty ()
603                 {
604                         new Matrix ().TransformVectors (new PointF[0]);
605                 }
606
607                 [Test]
608                 public void Translate  ()
609                 {
610                         Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);                        
611                         matrix.Translate (5, 10);
612                                                 
613                         AssertEquals ("Y#1", 2, matrix.Elements[0]);
614                         AssertEquals ("Y#2", 4, matrix.Elements[1]);
615                         AssertEquals ("Y#3", 6, matrix.Elements[2]);
616                         AssertEquals ("Y#4", 8, matrix.Elements[3]);
617                         AssertEquals ("Y#5", 80, matrix.Elements[4]);
618                         AssertEquals ("Y#6", 112, matrix.Elements[5]);  
619                 }
620
621                 [Test]
622                 [ExpectedException (typeof (ArgumentException))]
623                 public void Translate_InvalidOrder ()
624                 {
625                         new Matrix ().Translate (-1, 1, (MatrixOrder) Int32.MinValue);
626                 }
627
628                 [Test]
629                 [ExpectedException (typeof (ArgumentNullException))]
630                 public void VectorTransformPoints_Null ()
631                 {
632                         new Matrix ().VectorTransformPoints ((Point[]) null);
633                 }
634
635                 [Test]
636                 [ExpectedException (typeof (ArgumentException))]
637                 public void VectorTransformPoints_Empty ()
638                 {
639                         new Matrix ().VectorTransformPoints (new Point[0]);
640                 }
641         }
642 }