shear.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function cot(theta) {
  2. return 1 / Math.tan(theta);
  3. }
  4. /**
  5. * Applies shear transformation for the first dimension of vector2.
  6. * @param params [tx, ty]
  7. * @param x x of the the bounding box of coordinate
  8. * @param y y of the the bounding box of coordinate
  9. * @param width width of the the bounding box of coordinate
  10. * @param height height of the the bounding box of coordinate
  11. * @returns transformer
  12. */
  13. export var shearX = function (params, x, y, width, height) {
  14. var theta = params[0];
  15. var sx = cot(theta);
  16. return {
  17. transform: function (vector) {
  18. var x = vector[0], y = vector[1];
  19. var xx = x + y * sx;
  20. return [xx, y];
  21. },
  22. untransform: function (vector) {
  23. var xx = vector[0], y = vector[1];
  24. var x = xx - y * sx;
  25. return [x, y];
  26. },
  27. };
  28. };
  29. /**
  30. * Applies shear transformation for the second dimension of vector2.
  31. * @param params [tx, ty]
  32. * @param x x of the the bounding box of coordinate
  33. * @param y y of the the bounding box of coordinate
  34. * @param width width of the the bounding box of coordinate
  35. * @param height height of the the bounding box of coordinate
  36. * @returns transformer
  37. */
  38. export var shearY = function (params, x, y, width, height) {
  39. var theta = params[0];
  40. var sy = cot(theta);
  41. return {
  42. transform: function (vector) {
  43. var x = vector[0], y = vector[1];
  44. var yy = y + x * sy;
  45. return [x, yy];
  46. },
  47. untransform: function (vector) {
  48. var x = vector[0], yy = vector[1];
  49. var y = yy - x * sy;
  50. return [x, y];
  51. },
  52. };
  53. };
  54. //# sourceMappingURL=shear.js.map