Matrix.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. topSuite("Ext.draw.Matrix", function() {
  2. describe('split', function () {
  3. it("should extract transformation components properly", function () {
  4. var elements = [1.76776695, 1.76776695, -5.30330086, 5.30330086, 3, 4],
  5. matrix = Ext.draw.Matrix.fly(elements),
  6. split = matrix.split(),
  7. precision = 8;
  8. expect(split.translateX).toEqual(3);
  9. expect(split.translateY).toEqual(4);
  10. expect(split.scaleX).toBeCloseTo(2.5, precision);
  11. expect(split.scaleY).toBeCloseTo(7.5, precision);
  12. expect(split.rotate).toBeCloseTo(Math.PI / 4, precision);
  13. });
  14. });
  15. describe("isEqual", function () {
  16. it("should return 'true' for matricies with same elements", function () {
  17. var m1 = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6),
  18. m2 = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6);
  19. expect(m1.isEqual(m2)).toBe(true);
  20. m1.scale(2, 3, 4, 5, true);
  21. m2.scale(2, 3, 4, 5, true);
  22. m1.rotate(Math.PI / 3, 8, 9, true);
  23. m2.rotate(Math.PI / 3, 8, 9, true);
  24. expect(m1.isEqual(m2)).toBe(true);
  25. });
  26. it("should return 'false' for matrices with different elements", function () {
  27. var m1 = new Ext.draw.Matrix(1, 2, 3, 1, 5, 6),
  28. m2 = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6);
  29. expect(m1.isEqual(m2)).toBe(false);
  30. m1.reset();
  31. m2.reset();
  32. m1.scale(2, 3, 4, 5, true);
  33. m2.scale(2, 3, 4, 5, true);
  34. m1.rotate(Math.PI / 3, 7, 9, true);
  35. m2.rotate(Math.PI / 3, 8, 9, true);
  36. expect(m1.isEqual(m2)).toBe(false);
  37. });
  38. });
  39. describe("skewX", function () {
  40. it("should properly affect the matrix", function () {
  41. var matrix = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6),
  42. precision = 8;
  43. matrix.skewX(Math.PI / 3);
  44. expect(matrix.elements[0]).toEqual(1);
  45. expect(matrix.elements[1]).toEqual(2);
  46. expect(matrix.elements[2]).toBeCloseTo(4.73205080756888, precision);
  47. expect(matrix.elements[3]).toBeCloseTo(7.46410161513775, precision);
  48. expect(matrix.elements[4]).toEqual(5);
  49. expect(matrix.elements[5]).toEqual(6);
  50. });
  51. });
  52. describe("skewY", function () {
  53. it("should properly affect the matrix", function () {
  54. var matrix = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6),
  55. precision = 8;
  56. matrix.skewY(Math.PI / 3);
  57. expect(matrix.elements[0]).toBeCloseTo(6.19615242270663, precision);
  58. expect(matrix.elements[1]).toBeCloseTo(8.92820323027551, precision);
  59. expect(matrix.elements[2]).toEqual(3);
  60. expect(matrix.elements[3]).toEqual(4);
  61. expect(matrix.elements[4]).toEqual(5);
  62. expect(matrix.elements[5]).toEqual(6);
  63. });
  64. });
  65. describe("shearX", function () {
  66. it("should properly affect the matrix", function () {
  67. var matrix = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6);
  68. matrix.shearX(3);
  69. expect(matrix.elements).toEqual([1, 2, 6, 10, 5, 6]);
  70. });
  71. });
  72. describe("shearY", function () {
  73. it("should properly affect the matrix", function () {
  74. var matrix = new Ext.draw.Matrix(1, 2, 3, 4, 5, 6);
  75. matrix.shearY(3);
  76. expect(matrix.elements).toEqual([10, 14, 3, 4, 5, 6]);
  77. });
  78. });
  79. });