29d0f412ad8abeab59aa1654b172ede9c99b123c.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. if (!dojo._hasResource["dojox.gfx.tests.decompose"]) { // _hasResource checks
  2. // added by build. Do
  3. // not use _hasResource
  4. // directly in your
  5. // code.
  6. dojo._hasResource["dojox.gfx.tests.decompose"] = true;
  7. dojo.provide("dojox.gfx.tests.decompose");
  8. dojo.require("dojox.gfx.decompose");
  9. (function() {
  10. var m = dojox.gfx.matrix;
  11. var eq = function(t, a, b) {
  12. t.t(2 * Math.abs(a - b) / ((a < 1 && b < 1) ? 1 : a + b) < 1e-6);
  13. };
  14. var eqM = function(t, a, b) {
  15. eq(t, a.xx, b.xx);
  16. eq(t, a.yy, b.yy);
  17. eq(t, a.xy, b.xy);
  18. eq(t, a.yx, b.yx);
  19. eq(t, a.dx, b.dx);
  20. eq(t, a.dy, b.dy);
  21. };
  22. var compose = function(r) {
  23. return m.normalize([m.translate(r.dx, r.dy), m.rotate(r.angle2),
  24. m.scale(r.sx, r.sy), m.rotate(r.angle1)]);
  25. };
  26. var reconstruct = function(a) {
  27. return compose(dojox.gfx.decompose(a));
  28. };
  29. var compare = function(t, a) {
  30. var A = m.normalize(a);
  31. eqM(t, A, reconstruct(A));
  32. };
  33. tests.register("dojox.gfx.tests.decompose", [function IdentityTest(t) {
  34. compare(t, m.identity);
  35. }, function FlipXTest(t) {
  36. compare(t, m.flipX);
  37. }, function FlipYTest(t) {
  38. compare(t, m.flipY);
  39. }, function FlipXYTest(t) {
  40. compare(t, m.flipXY);
  41. }, function TranslationTest(t) {
  42. compare(t, m.translate(45, -15));
  43. }, function RotationTest(t) {
  44. compare(t, m.rotateg(35));
  45. }, function SkewXTest(t) {
  46. compare(t, m.skewXg(35));
  47. }, function SkewYTest(t) {
  48. compare(t, m.skewYg(35));
  49. }, function ReflectTest(t) {
  50. compare(t, m.reflect(13, 27));
  51. }, function ProjectTest(t) {
  52. compare(t, m.project(13, 27));
  53. }, function ScaleTest1(t) {
  54. compare(t, m.scale(3));
  55. }, function ScaleTest2(t) {
  56. compare(t, m.scale(3, -1));
  57. }, function ScaleTest3(t) {
  58. compare(t, m.scale(-3, 1));
  59. }, function ScaleTest4(t) {
  60. compare(t, m.scale(-3, -1));
  61. }, function ScaleRotateTest1(t) {
  62. compare(t, [m.scale(3), m.rotateAt(35, 13, 27)]);
  63. }, function ScaleRotateTest2(t) {
  64. compare(t, [m.scale(3, -1), m.rotateAt(35, 13, 27)]);
  65. }, function ScaleRotateTest3(t) {
  66. compare(t, [m.scale(-3, 1), m.rotateAt(35, 13, 27)]);
  67. }, function ScaleRotateTest4(t) {
  68. compare(t,
  69. [m.scale(-3, -1), m.rotateAt(35, 13, 27)]);
  70. }, function RotateScaleTest1(t) {
  71. compare(t, [m.rotateAt(35, 13, 27), m.scale(3)]);
  72. }, function RotateScaleTest2(t) {
  73. compare(t, [m.rotateAt(35, 13, 27), m.scale(3, -1)]);
  74. }, function RotateScaleTest3(t) {
  75. compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, 1)]);
  76. }, function RotateScaleTest4(t) {
  77. compare(t,
  78. [m.rotateAt(35, 13, 27), m.scale(-3, -1)]);
  79. }, function RotateScaleRotateTest1(t) {
  80. compare(t, [m.rotateAt(35, 13, 27), m.scale(3),
  81. m.rotateAt(-15, 163, -287)]);
  82. }, function RotateScaleRotateTest2(t) {
  83. compare(t, [m.rotateAt(35, 13, 27), m.scale(3, -1),
  84. m.rotateAt(-15, 163, -287)]);
  85. }, function RotateScaleRotateTest3(t) {
  86. compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, 1),
  87. m.rotateAt(-15, 163, -287)]);
  88. }, function RotateScaleRotateTest4(t) {
  89. compare(t,
  90. [m.rotateAt(35, 13, 27), m.scale(-3, -1),
  91. m.rotateAt(-15, 163, -287)]);
  92. }]);
  93. })();
  94. }