2 // Tests for System.Drawing.Drawing2D.Matrix.cs
5 // Jordi Mas i Hernandez <jordi@ximian.com>
7 // Copyright (C) 2005 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.
29 using NUnit.Framework;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
35 namespace MonoTests.System.Drawing.Drawing2D
38 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
39 public class MatrixTest : Assertion
42 public void TearDown () { }
45 public void SetUp () { }
48 public void Constructors ()
51 Matrix matrix = new Matrix ();
52 AssertEquals ("C#1", 6, matrix.Elements.Length);
57 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
58 AssertEquals ("C#2", 6, matrix.Elements.Length);
59 AssertEquals ("C#3", 10, matrix.Elements[0]);
60 AssertEquals ("C#4", 20, matrix.Elements[1]);
61 AssertEquals ("C#5", 30, matrix.Elements[2]);
62 AssertEquals ("C#6", 40, matrix.Elements[3]);
63 AssertEquals ("C#7", 50, matrix.Elements[4]);
64 AssertEquals ("C#8", 60, matrix.Elements[5]);
71 public void Invertible ()
73 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
74 AssertEquals ("I#1", false, matrix.IsInvertible);
76 matrix = new Matrix (156, 46, 0, 0, 106, 19);
77 AssertEquals ("I#2", false, matrix.IsInvertible);
79 matrix = new Matrix (146, 66, 158, 104, 42, 150);
80 AssertEquals ("I#3", true, matrix.IsInvertible);
82 matrix = new Matrix (119, 140, 145, 74, 102, 58);
83 AssertEquals ("I#4", true, matrix.IsInvertible);
87 public void IsIdentity ()
89 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
90 AssertEquals ("N#1", false, matrix.IsIdentity);
92 matrix = new Matrix (1, 0, 0, 1, 0, 0);
93 AssertEquals ("N#2", true, matrix.IsIdentity);
97 public void IsOffsetX ()
99 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
100 AssertEquals ("X#1", 47, matrix.OffsetX);
104 public void IsOffsetY ()
106 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
107 AssertEquals ("Y#1", 30, matrix.OffsetY);
110 // Elements Property is checked implicity in other test
120 Matrix matsrc = new Matrix (10, 20, 30, 40, 50, 60);
121 Matrix matrix = matsrc.Clone ();
123 AssertEquals ("D#1", 6, matrix.Elements.Length);
124 AssertEquals ("D#2", 10, matrix.Elements[0]);
125 AssertEquals ("D#3", 20, matrix.Elements[1]);
126 AssertEquals ("D#4", 30, matrix.Elements[2]);
127 AssertEquals ("D#5", 40, matrix.Elements[3]);
128 AssertEquals ("D#6", 50, matrix.Elements[4]);
129 AssertEquals ("D#7", 60, matrix.Elements[5]);
135 Matrix matrix = new Matrix (51, 52, 53, 54, 55, 56);
138 AssertEquals ("F#1", 6, matrix.Elements.Length);
139 AssertEquals ("F#2", 1, matrix.Elements[0]);
140 AssertEquals ("F#3", 0, matrix.Elements[1]);
141 AssertEquals ("F#4", 0, matrix.Elements[2]);
142 AssertEquals ("F#5", 1, matrix.Elements[3]);
143 AssertEquals ("F#6", 0, matrix.Elements[4]);
144 AssertEquals ("F#7", 0, matrix.Elements[5]);
148 public void Rotate ()
150 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
153 AssertEquals ("H#1", -10, matrix.Elements[0]);
154 AssertEquals ("H#2", -20, matrix.Elements[1]);
155 AssertEquals ("H#3", -30, matrix.Elements[2]);
156 AssertEquals ("H#4", -40, matrix.Elements[3]);
157 AssertEquals ("H#5", 50, matrix.Elements[4]);
158 AssertEquals ("H#6", 60, matrix.Elements[5]);
162 public void RotateAt ()
164 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
165 matrix.RotateAt (180, new PointF (10, 10));
167 AssertEquals ("I#1", -10, matrix.Elements[0]);
168 AssertEquals ("I#2", -20, matrix.Elements[1]);
169 AssertEquals ("I#3", -30, matrix.Elements[2]);
170 AssertEquals ("I#4", -40, matrix.Elements[3]);
171 AssertEquals ("I#5", 850, matrix.Elements[4]);
172 AssertEquals ("I#6", 1260, matrix.Elements[5]);
176 public void Multiply ()
178 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
179 matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60));
181 AssertEquals ("J#1", 700, matrix.Elements[0]);
182 AssertEquals ("J#2", 1000, matrix.Elements[1]);
183 AssertEquals ("J#3", 1500, matrix.Elements[2]);
184 AssertEquals ("J#4", 2200, matrix.Elements[3]);
185 AssertEquals ("J#5", 2350, matrix.Elements[4]);
186 AssertEquals ("J#6", 3460, matrix.Elements[5]);
190 public void Equals ()
192 Matrix mat1 = new Matrix (10, 20, 30, 40, 50, 60);
193 Matrix mat2 = new Matrix (10, 20, 30, 40, 50, 60);
194 Matrix mat3 = new Matrix (10, 20, 30, 40, 50, 10);
196 AssertEquals ("E#1", true, mat1.Equals (mat2));
197 AssertEquals ("E#2", false, mat2.Equals (mat3));
198 AssertEquals ("E#3", false, mat1.Equals (mat3));
202 public void Invert ()
204 Matrix matrix = new Matrix (1, 2, 3, 4, 5, 6);
207 AssertEquals ("V#1", -2, matrix.Elements[0]);
208 AssertEquals ("V#2", 1, matrix.Elements[1]);
209 AssertEquals ("V#3", 1.5, matrix.Elements[2]);
210 AssertEquals ("V#4", -0.5, matrix.Elements[3]);
211 AssertEquals ("V#5", 1, matrix.Elements[4]);
212 AssertEquals ("V#6", -2, matrix.Elements[5]);
218 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
221 AssertEquals ("S#1", 20, matrix.Elements[0]);
222 AssertEquals ("S#2", 40, matrix.Elements[1]);
223 AssertEquals ("S#3", 120, matrix.Elements[2]);
224 AssertEquals ("S#4", 160, matrix.Elements[3]);
225 AssertEquals ("S#5", 50, matrix.Elements[4]);
226 AssertEquals ("S#6", 60, matrix.Elements[5]);
232 Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
235 AssertEquals ("H#1", 130, matrix.Elements[0]);
236 AssertEquals ("H#2", 180, matrix.Elements[1]);
237 AssertEquals ("H#3", 50, matrix.Elements[2]);
238 AssertEquals ("H#4", 80, matrix.Elements[3]);
239 AssertEquals ("H#5", 50, matrix.Elements[4]);
240 AssertEquals ("H#6", 60, matrix.Elements[5]);
242 matrix = new Matrix (5, 3, 9, 2, 2, 1);
243 matrix.Shear (10, 20);
245 AssertEquals ("H#7", 185, matrix.Elements[0]);
246 AssertEquals ("H#8", 43, matrix.Elements[1]);
247 AssertEquals ("H#9", 59, matrix.Elements[2]);
248 AssertEquals ("H#10", 32, matrix.Elements[3]);
249 AssertEquals ("H#11", 2, matrix.Elements[4]);
250 AssertEquals ("H#12", 1, matrix.Elements[5]);
254 public void TransformPoints ()
256 Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
257 PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
258 matrix.TransformPoints (pointsF);
260 AssertEquals ("K#1", 38, pointsF[0].X);
261 AssertEquals ("K#2", 52, pointsF[0].Y);
262 AssertEquals ("K#3", 66, pointsF[1].X);
263 AssertEquals ("K#4", 92, pointsF[1].Y);
265 Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
266 matrix.TransformPoints (points);
267 AssertEquals ("K#5", 38, pointsF[0].X);
268 AssertEquals ("K#6", 52, pointsF[0].Y);
269 AssertEquals ("K#7", 66, pointsF[1].X);
270 AssertEquals ("K#8", 92, pointsF[1].Y);
274 public void TransformVectors ()
276 Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
277 PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
278 matrix.TransformVectors (pointsF);
280 AssertEquals ("N#1", 28, pointsF[0].X);
281 AssertEquals ("N#2", 40, pointsF[0].Y);
282 AssertEquals ("N#3", 56, pointsF[1].X);
283 AssertEquals ("N#4", 80, pointsF[1].Y);
285 Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
286 matrix.TransformVectors (points);
287 AssertEquals ("N#5", 28, pointsF[0].X);
288 AssertEquals ("N#6", 40, pointsF[0].Y);
289 AssertEquals ("N#7", 56, pointsF[1].X);
290 AssertEquals ("N#8", 80, pointsF[1].Y);
294 public void Translate ()
296 Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
297 matrix.Translate (5, 10);
299 AssertEquals ("Y#1", 2, matrix.Elements[0]);
300 AssertEquals ("Y#2", 4, matrix.Elements[1]);
301 AssertEquals ("Y#3", 6, matrix.Elements[2]);
302 AssertEquals ("Y#4", 8, matrix.Elements[3]);
303 AssertEquals ("Y#5", 80, matrix.Elements[4]);
304 AssertEquals ("Y#6", 112, matrix.Elements[5]);