TestMatrix.cs 20 KB

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