TestMatrix.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. //
  2. // Tests for System.Drawing.Drawing2D.Matrix.cs
  3. //
  4. // Authors:
  5. // Jordi Mas i Hernandez <[email protected]>
  6. // Sebastien Pouliot <[email protected]>
  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. using NUnit.Framework;
  30. using System;
  31. using System.Drawing;
  32. using System.Drawing.Drawing2D;
  33. using System.Security.Permissions;
  34. namespace MonoTests.System.Drawing.Drawing2D
  35. {
  36. [TestFixture]
  37. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  38. public class MatrixTest : Assertion {
  39. private Matrix default_matrix;
  40. private Rectangle rect;
  41. private RectangleF rectf;
  42. [TestFixtureSetUp]
  43. public void FixtureSetUp ()
  44. {
  45. default_matrix = new Matrix ();
  46. }
  47. [Test]
  48. public void Constructor_Default ()
  49. {
  50. Matrix matrix = new Matrix ();
  51. AssertEquals ("C#1", 6, matrix.Elements.Length);
  52. }
  53. [Test]
  54. public void Constructor_SixFloats ()
  55. {
  56. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  57. AssertEquals ("C#2", 6, matrix.Elements.Length);
  58. AssertEquals ("C#3", 10, matrix.Elements[0]);
  59. AssertEquals ("C#4", 20, matrix.Elements[1]);
  60. AssertEquals ("C#5", 30, matrix.Elements[2]);
  61. AssertEquals ("C#6", 40, matrix.Elements[3]);
  62. AssertEquals ("C#7", 50, matrix.Elements[4]);
  63. AssertEquals ("C#8", 60, matrix.Elements[5]);
  64. }
  65. [Test]
  66. public void Constructor_Float ()
  67. {
  68. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  69. AssertEquals ("C#2", 6, matrix.Elements.Length);
  70. AssertEquals ("C#3", 10, matrix.Elements[0]);
  71. AssertEquals ("C#4", 20, matrix.Elements[1]);
  72. AssertEquals ("C#5", 30, matrix.Elements[2]);
  73. AssertEquals ("C#6", 40, matrix.Elements[3]);
  74. AssertEquals ("C#7", 50, matrix.Elements[4]);
  75. AssertEquals ("C#8", 60, matrix.Elements[5]);
  76. }
  77. [Test]
  78. [ExpectedException (typeof (ArgumentNullException))]
  79. public void Constructor_Int_Null ()
  80. {
  81. new Matrix (rect, null);
  82. }
  83. [Test]
  84. [ExpectedException (typeof (ArgumentException))]
  85. public void Constructor_Int_Empty ()
  86. {
  87. new Matrix (rect, new Point[0]);
  88. }
  89. [Test]
  90. [ExpectedException (typeof (ArgumentNullException))]
  91. public void Constructor_Float_Null ()
  92. {
  93. new Matrix (rectf, null);
  94. }
  95. [Test]
  96. [ExpectedException (typeof (ArgumentException))]
  97. public void Constructor_Float_Empty ()
  98. {
  99. new Matrix (rectf, new PointF[0]);
  100. }
  101. // Properties
  102. [Test]
  103. public void Invertible ()
  104. {
  105. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  106. AssertEquals ("I#1", false, matrix.IsInvertible);
  107. matrix = new Matrix (156, 46, 0, 0, 106, 19);
  108. AssertEquals ("I#2", false, matrix.IsInvertible);
  109. matrix = new Matrix (146, 66, 158, 104, 42, 150);
  110. AssertEquals ("I#3", true, matrix.IsInvertible);
  111. matrix = new Matrix (119, 140, 145, 74, 102, 58);
  112. AssertEquals ("I#4", true, matrix.IsInvertible);
  113. }
  114. [Test]
  115. public void IsIdentity ()
  116. {
  117. Matrix identity = new Matrix ();
  118. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  119. AssertEquals ("N#1-identity", false, matrix.IsIdentity);
  120. Assert ("N#1-equals", !identity.Equals (matrix));
  121. matrix = new Matrix (1, 0, 0, 1, 0, 0);
  122. AssertEquals ("N#2-identity", true, matrix.IsIdentity);
  123. Assert ("N#2-equals", identity.Equals (matrix));
  124. // so what's the required precision ?
  125. matrix = new Matrix (1.1f, 0.1f, -0.1f, 0.9f, 0, 0);
  126. Assert ("N#3-identity", !matrix.IsIdentity);
  127. Assert ("N#3-equals", !identity.Equals (matrix));
  128. matrix = new Matrix (1.01f, 0.01f, -0.01f, 0.99f, 0, 0);
  129. Assert ("N#4-identity", !matrix.IsIdentity);
  130. Assert ("N#4-equals", !identity.Equals (matrix));
  131. matrix = new Matrix (1.001f, 0.001f, -0.001f, 0.999f, 0, 0);
  132. Assert ("N#5-identity", !matrix.IsIdentity);
  133. Assert ("N#5-equals", !identity.Equals (matrix));
  134. matrix = new Matrix (1.0001f, 0.0001f, -0.0001f, 0.9999f, 0, 0);
  135. Assert ("N#6-identity", matrix.IsIdentity);
  136. // note: NOT equal
  137. Assert ("N#6-equals", !identity.Equals (matrix));
  138. matrix = new Matrix (1.0009f, 0.0009f, -0.0009f, 0.99995f, 0, 0);
  139. Assert ("N#7-identity", !matrix.IsIdentity);
  140. Assert ("N#7-equals", !identity.Equals (matrix));
  141. }
  142. [Test]
  143. public void IsOffsetX ()
  144. {
  145. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  146. AssertEquals ("X#1", 47, matrix.OffsetX);
  147. }
  148. [Test]
  149. public void IsOffsetY ()
  150. {
  151. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  152. AssertEquals ("Y#1", 30, matrix.OffsetY);
  153. }
  154. // Elements Property is checked implicity in other test
  155. //
  156. // Methods
  157. //
  158. [Test]
  159. public void Clone ()
  160. {
  161. Matrix matsrc = new Matrix (10, 20, 30, 40, 50, 60);
  162. Matrix matrix = matsrc.Clone ();
  163. AssertEquals ("D#1", 6, matrix.Elements.Length);
  164. AssertEquals ("D#2", 10, matrix.Elements[0]);
  165. AssertEquals ("D#3", 20, matrix.Elements[1]);
  166. AssertEquals ("D#4", 30, matrix.Elements[2]);
  167. AssertEquals ("D#5", 40, matrix.Elements[3]);
  168. AssertEquals ("D#6", 50, matrix.Elements[4]);
  169. AssertEquals ("D#7", 60, matrix.Elements[5]);
  170. }
  171. [Test]
  172. public void HashCode ()
  173. {
  174. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  175. Matrix clone = matrix.Clone ();
  176. Assert ("HashCode/Clone", matrix.GetHashCode () != clone.GetHashCode ());
  177. Matrix matrix2 = new Matrix (10, 20, 30, 40, 50, 60);
  178. Assert ("HashCode/Identical", matrix.GetHashCode () != matrix2.GetHashCode ());
  179. }
  180. [Test]
  181. public void Reset ()
  182. {
  183. Matrix matrix = new Matrix (51, 52, 53, 54, 55, 56);
  184. matrix.Reset ();
  185. AssertEquals ("F#1", 6, matrix.Elements.Length);
  186. AssertEquals ("F#2", 1, matrix.Elements[0]);
  187. AssertEquals ("F#3", 0, matrix.Elements[1]);
  188. AssertEquals ("F#4", 0, matrix.Elements[2]);
  189. AssertEquals ("F#5", 1, matrix.Elements[3]);
  190. AssertEquals ("F#6", 0, matrix.Elements[4]);
  191. AssertEquals ("F#7", 0, matrix.Elements[5]);
  192. }
  193. [Test]
  194. public void Rotate ()
  195. {
  196. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  197. matrix.Rotate (180);
  198. AssertEquals ("H#1", -10, matrix.Elements[0]);
  199. AssertEquals ("H#2", -20, matrix.Elements[1]);
  200. AssertEquals ("H#3", -30, matrix.Elements[2]);
  201. AssertEquals ("H#4", -40, matrix.Elements[3]);
  202. AssertEquals ("H#5", 50, matrix.Elements[4]);
  203. AssertEquals ("H#6", 60, matrix.Elements[5]);
  204. }
  205. [Test]
  206. public void Rotate_45_135 ()
  207. {
  208. Matrix matrix = new Matrix ();
  209. Assert ("original.IsIdentity", matrix.IsIdentity);
  210. matrix.Rotate (45);
  211. Assert ("+45.!IsIdentity", !matrix.IsIdentity);
  212. float[] elements = matrix.Elements;
  213. AssertEquals ("45#1", 0.7071068, elements[0]);
  214. AssertEquals ("45#2", 0.7071068, elements[1]);
  215. AssertEquals ("45#3", -0.7071068, elements[2]);
  216. AssertEquals ("45#4", 0.7071068, elements[3]);
  217. AssertEquals ("45#5", 0, elements[4]);
  218. AssertEquals ("45#6", 0, elements[5]);
  219. matrix.Rotate (135);
  220. Assert ("+135.!IsIdentity", !matrix.IsIdentity);
  221. elements = matrix.Elements;
  222. AssertEquals ("180#1", -1, elements[0], 0.0001);
  223. AssertEquals ("180#2", 0, elements[1], 0.0001);
  224. AssertEquals ("180#3", 0, elements[2], 0.0001);
  225. AssertEquals ("180#4", -1, elements[3], 0.0001);
  226. AssertEquals ("180#5", 0, elements[4]);
  227. AssertEquals ("180#6", 0, elements[5]);
  228. }
  229. [Test]
  230. public void Rotate_90_270_Matrix ()
  231. {
  232. Matrix matrix = new Matrix ();
  233. Assert ("original.IsIdentity", matrix.IsIdentity);
  234. matrix.Rotate (90);
  235. Assert ("+90.!IsIdentity", !matrix.IsIdentity);
  236. float[] elements = matrix.Elements;
  237. AssertEquals ("90#1", 0, elements[0], 0.0001);
  238. AssertEquals ("90#2", 1, elements[1], 0.0001);
  239. AssertEquals ("90#3", -1, elements[2], 0.0001);
  240. AssertEquals ("90#4", 0, elements[3], 0.0001);
  241. AssertEquals ("90#5", 0, elements[4]);
  242. AssertEquals ("90#6", 0, elements[5]);
  243. matrix.Rotate (270);
  244. // this isn't a perfect 1, 0, 0, 1, 0, 0 matrix - but close enough
  245. Assert ("360.IsIdentity", matrix.IsIdentity);
  246. Assert ("360.Equals", !new Matrix ().Equals (matrix));
  247. }
  248. [Test]
  249. [ExpectedException (typeof (ArgumentException))]
  250. public void Rotate_InvalidOrder ()
  251. {
  252. new Matrix ().Rotate (180, (MatrixOrder) Int32.MinValue);
  253. }
  254. [Test]
  255. public void RotateAt ()
  256. {
  257. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  258. matrix.RotateAt (180, new PointF (10, 10));
  259. AssertEquals ("I#1", -10, matrix.Elements[0]);
  260. AssertEquals ("I#2", -20, matrix.Elements[1]);
  261. AssertEquals ("I#3", -30, matrix.Elements[2]);
  262. AssertEquals ("I#4", -40, matrix.Elements[3]);
  263. AssertEquals ("I#5", 850, matrix.Elements[4]);
  264. AssertEquals ("I#6", 1260, matrix.Elements[5]);
  265. }
  266. [Test]
  267. [ExpectedException (typeof (ArgumentException))]
  268. public void RotateAt_InvalidOrder ()
  269. {
  270. new Matrix ().RotateAt (180, new PointF (10, 10), (MatrixOrder) Int32.MinValue);
  271. }
  272. [Test]
  273. [ExpectedException (typeof (ArgumentNullException))]
  274. public void Multiply_Null ()
  275. {
  276. new Matrix (10, 20, 30, 40, 50, 60).Multiply (null);
  277. }
  278. [Test]
  279. public void Multiply ()
  280. {
  281. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  282. matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60));
  283. AssertEquals ("J#1", 700, matrix.Elements[0]);
  284. AssertEquals ("J#2", 1000, matrix.Elements[1]);
  285. AssertEquals ("J#3", 1500, matrix.Elements[2]);
  286. AssertEquals ("J#4", 2200, matrix.Elements[3]);
  287. AssertEquals ("J#5", 2350, matrix.Elements[4]);
  288. AssertEquals ("J#6", 3460, matrix.Elements[5]);
  289. }
  290. [Test]
  291. [ExpectedException (typeof (ArgumentNullException))]
  292. public void Multiply_Null_Order ()
  293. {
  294. new Matrix (10, 20, 30, 40, 50, 60).Multiply (null, MatrixOrder.Append);
  295. }
  296. [Test]
  297. public void Multiply_Append ()
  298. {
  299. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  300. matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), MatrixOrder.Append);
  301. AssertEquals ("J#1", 700, matrix.Elements[0]);
  302. AssertEquals ("J#2", 1000, matrix.Elements[1]);
  303. AssertEquals ("J#3", 1500, matrix.Elements[2]);
  304. AssertEquals ("J#4", 2200, matrix.Elements[3]);
  305. AssertEquals ("J#5", 2350, matrix.Elements[4]);
  306. AssertEquals ("J#6", 3460, matrix.Elements[5]);
  307. }
  308. [Test]
  309. public void Multiply_Prepend ()
  310. {
  311. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  312. matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), MatrixOrder.Prepend);
  313. AssertEquals ("J#1", 700, matrix.Elements[0]);
  314. AssertEquals ("J#2", 1000, matrix.Elements[1]);
  315. AssertEquals ("J#3", 1500, matrix.Elements[2]);
  316. AssertEquals ("J#4", 2200, matrix.Elements[3]);
  317. AssertEquals ("J#5", 2350, matrix.Elements[4]);
  318. AssertEquals ("J#6", 3460, matrix.Elements[5]);
  319. }
  320. [Test]
  321. [ExpectedException (typeof (ArgumentException))]
  322. public void Multiply_InvalidOrder ()
  323. {
  324. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  325. matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), (MatrixOrder)Int32.MinValue);
  326. }
  327. [Test]
  328. public void Equals ()
  329. {
  330. Matrix mat1 = new Matrix (10, 20, 30, 40, 50, 60);
  331. Matrix mat2 = new Matrix (10, 20, 30, 40, 50, 60);
  332. Matrix mat3 = new Matrix (10, 20, 30, 40, 50, 10);
  333. AssertEquals ("E#1", true, mat1.Equals (mat2));
  334. AssertEquals ("E#2", false, mat2.Equals (mat3));
  335. AssertEquals ("E#3", false, mat1.Equals (mat3));
  336. }
  337. [Test]
  338. public void Invert ()
  339. {
  340. Matrix matrix = new Matrix (1, 2, 3, 4, 5, 6);
  341. matrix.Invert ();
  342. AssertEquals ("V#1", -2, matrix.Elements[0]);
  343. AssertEquals ("V#2", 1, matrix.Elements[1]);
  344. AssertEquals ("V#3", 1.5, matrix.Elements[2]);
  345. AssertEquals ("V#4", -0.5, matrix.Elements[3]);
  346. AssertEquals ("V#5", 1, matrix.Elements[4]);
  347. AssertEquals ("V#6", -2, matrix.Elements[5]);
  348. }
  349. [Test]
  350. public void Invert_Translation ()
  351. {
  352. Matrix matrix = new Matrix (1, 0, 0, 1, 8, 8);
  353. matrix.Invert ();
  354. float[] elements = matrix.Elements;
  355. AssertEquals ("#1", 1, elements[0]);
  356. AssertEquals ("#2", 0, elements[1]);
  357. AssertEquals ("#3", 0, elements[2]);
  358. AssertEquals ("#4", 1, elements[3]);
  359. AssertEquals ("#5", -8, elements[4]);
  360. AssertEquals ("#6", -8, elements[5]);
  361. }
  362. [Test]
  363. public void Invert_Identity ()
  364. {
  365. Matrix matrix = new Matrix ();
  366. Assert ("IsIdentity", matrix.IsIdentity);
  367. Assert ("IsInvertible", matrix.IsInvertible);
  368. matrix.Invert ();
  369. Assert ("IsIdentity-2", matrix.IsIdentity);
  370. Assert ("IsInvertible-2", matrix.IsInvertible);
  371. }
  372. [Test]
  373. public void Scale ()
  374. {
  375. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  376. matrix.Scale (2, 4);
  377. AssertEquals ("S#1", 20, matrix.Elements[0]);
  378. AssertEquals ("S#2", 40, matrix.Elements[1]);
  379. AssertEquals ("S#3", 120, matrix.Elements[2]);
  380. AssertEquals ("S#4", 160, matrix.Elements[3]);
  381. AssertEquals ("S#5", 50, matrix.Elements[4]);
  382. AssertEquals ("S#6", 60, matrix.Elements[5]);
  383. matrix.Scale (0.5f, 0.25f);
  384. AssertEquals ("SB#1", 10, matrix.Elements[0]);
  385. AssertEquals ("SB#2", 20, matrix.Elements[1]);
  386. AssertEquals ("SB#3", 30, matrix.Elements[2]);
  387. AssertEquals ("SB#4", 40, matrix.Elements[3]);
  388. AssertEquals ("SB#5", 50, matrix.Elements[4]);
  389. AssertEquals ("SB#6", 60, matrix.Elements[5]);
  390. }
  391. [Test]
  392. public void Scale_Negative ()
  393. {
  394. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  395. matrix.Scale (-2, -4);
  396. AssertEquals ("S#1", -20, matrix.Elements[0]);
  397. AssertEquals ("S#2", -40, matrix.Elements[1]);
  398. AssertEquals ("S#3", -120, matrix.Elements[2]);
  399. AssertEquals ("S#4", -160, matrix.Elements[3]);
  400. AssertEquals ("S#5", 50, matrix.Elements[4]);
  401. AssertEquals ("S#6", 60, matrix.Elements[5]);
  402. }
  403. [Test]
  404. [ExpectedException (typeof (ArgumentException))]
  405. public void Scale_InvalidOrder ()
  406. {
  407. new Matrix ().Scale (2, 1, (MatrixOrder) Int32.MinValue);
  408. }
  409. [Test]
  410. public void Shear ()
  411. {
  412. Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60);
  413. matrix.Shear (2, 4);
  414. AssertEquals ("H#1", 130, matrix.Elements[0]);
  415. AssertEquals ("H#2", 180, matrix.Elements[1]);
  416. AssertEquals ("H#3", 50, matrix.Elements[2]);
  417. AssertEquals ("H#4", 80, matrix.Elements[3]);
  418. AssertEquals ("H#5", 50, matrix.Elements[4]);
  419. AssertEquals ("H#6", 60, matrix.Elements[5]);
  420. matrix = new Matrix (5, 3, 9, 2, 2, 1);
  421. matrix.Shear (10, 20);
  422. AssertEquals ("H#7", 185, matrix.Elements[0]);
  423. AssertEquals ("H#8", 43, matrix.Elements[1]);
  424. AssertEquals ("H#9", 59, matrix.Elements[2]);
  425. AssertEquals ("H#10", 32, matrix.Elements[3]);
  426. AssertEquals ("H#11", 2, matrix.Elements[4]);
  427. AssertEquals ("H#12", 1, matrix.Elements[5]);
  428. }
  429. [Test]
  430. [ExpectedException (typeof (ArgumentException))]
  431. public void Shear_InvalidOrder ()
  432. {
  433. new Matrix ().Shear (-1, 1, (MatrixOrder) Int32.MinValue);
  434. }
  435. [Test]
  436. public void TransformPoints ()
  437. {
  438. Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
  439. PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
  440. matrix.TransformPoints (pointsF);
  441. AssertEquals ("K#1", 38, pointsF[0].X);
  442. AssertEquals ("K#2", 52, pointsF[0].Y);
  443. AssertEquals ("K#3", 66, pointsF[1].X);
  444. AssertEquals ("K#4", 92, pointsF[1].Y);
  445. Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
  446. matrix.TransformPoints (points);
  447. AssertEquals ("K#5", 38, pointsF[0].X);
  448. AssertEquals ("K#6", 52, pointsF[0].Y);
  449. AssertEquals ("K#7", 66, pointsF[1].X);
  450. AssertEquals ("K#8", 92, pointsF[1].Y);
  451. }
  452. [Test]
  453. [ExpectedException (typeof (ArgumentNullException))]
  454. public void TransformPoints_Point_Null ()
  455. {
  456. new Matrix ().TransformPoints ((Point[]) null);
  457. }
  458. [Test]
  459. [ExpectedException (typeof (ArgumentNullException))]
  460. public void TransformPoints_PointF_Null ()
  461. {
  462. new Matrix ().TransformPoints ((PointF[]) null);
  463. }
  464. [Test]
  465. [ExpectedException (typeof (ArgumentException))]
  466. public void TransformPoints_Point_Empty ()
  467. {
  468. new Matrix ().TransformPoints (new Point[0]);
  469. }
  470. [Test]
  471. [ExpectedException (typeof (ArgumentException))]
  472. public void TransformPoints_PointF_Empty ()
  473. {
  474. new Matrix ().TransformPoints (new PointF[0]);
  475. }
  476. [Test]
  477. public void TransformVectors ()
  478. {
  479. Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
  480. PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
  481. matrix.TransformVectors (pointsF);
  482. AssertEquals ("N#1", 28, pointsF[0].X);
  483. AssertEquals ("N#2", 40, pointsF[0].Y);
  484. AssertEquals ("N#3", 56, pointsF[1].X);
  485. AssertEquals ("N#4", 80, pointsF[1].Y);
  486. Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
  487. matrix.TransformVectors (points);
  488. AssertEquals ("N#5", 28, pointsF[0].X);
  489. AssertEquals ("N#6", 40, pointsF[0].Y);
  490. AssertEquals ("N#7", 56, pointsF[1].X);
  491. AssertEquals ("N#8", 80, pointsF[1].Y);
  492. }
  493. [Test]
  494. [ExpectedException (typeof (ArgumentNullException))]
  495. public void TransformVectors_Point_Null ()
  496. {
  497. new Matrix ().TransformVectors ((Point[]) null);
  498. }
  499. [Test]
  500. [ExpectedException (typeof (ArgumentNullException))]
  501. public void TransformVectors_PointF_Null ()
  502. {
  503. new Matrix ().TransformVectors ((PointF[]) null);
  504. }
  505. [Test]
  506. [ExpectedException (typeof (ArgumentException))]
  507. public void TransformVectors_Point_Empty ()
  508. {
  509. new Matrix ().TransformVectors (new Point[0]);
  510. }
  511. [Test]
  512. [ExpectedException (typeof (ArgumentException))]
  513. public void TransformVectors_PointF_Empty ()
  514. {
  515. new Matrix ().TransformVectors (new PointF[0]);
  516. }
  517. [Test]
  518. public void Translate ()
  519. {
  520. Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
  521. matrix.Translate (5, 10);
  522. AssertEquals ("Y#1", 2, matrix.Elements[0]);
  523. AssertEquals ("Y#2", 4, matrix.Elements[1]);
  524. AssertEquals ("Y#3", 6, matrix.Elements[2]);
  525. AssertEquals ("Y#4", 8, matrix.Elements[3]);
  526. AssertEquals ("Y#5", 80, matrix.Elements[4]);
  527. AssertEquals ("Y#6", 112, matrix.Elements[5]);
  528. }
  529. [Test]
  530. [ExpectedException (typeof (ArgumentException))]
  531. public void Translate_InvalidOrder ()
  532. {
  533. new Matrix ().Translate (-1, 1, (MatrixOrder) Int32.MinValue);
  534. }
  535. [Test]
  536. [ExpectedException (typeof (ArgumentNullException))]
  537. public void VectorTransformPoints_Null ()
  538. {
  539. new Matrix ().VectorTransformPoints ((Point[]) null);
  540. }
  541. [Test]
  542. [ExpectedException (typeof (ArgumentException))]
  543. public void VectorTransformPoints_Empty ()
  544. {
  545. new Matrix ().VectorTransformPoints (new Point[0]);
  546. }
  547. }
  548. }