bbox.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getRenderBBox = exports.BBox = void 0;
  4. var tslib_1 = require("tslib");
  5. var BBox = /** @class */ (function () {
  6. function BBox(x, y, width, height) {
  7. if (x === void 0) { x = 0; }
  8. if (y === void 0) { y = 0; }
  9. if (width === void 0) { width = 0; }
  10. if (height === void 0) { height = 0; }
  11. this.x = 0;
  12. this.y = 0;
  13. this.width = 0;
  14. this.height = 0;
  15. this.x = x;
  16. this.y = y;
  17. this.width = width;
  18. this.height = height;
  19. }
  20. Object.defineProperty(BBox.prototype, "bottom", {
  21. get: function () {
  22. return this.y + this.height;
  23. },
  24. enumerable: false,
  25. configurable: true
  26. });
  27. Object.defineProperty(BBox.prototype, "left", {
  28. get: function () {
  29. return this.x;
  30. },
  31. enumerable: false,
  32. configurable: true
  33. });
  34. Object.defineProperty(BBox.prototype, "right", {
  35. get: function () {
  36. return this.x + this.width;
  37. },
  38. enumerable: false,
  39. configurable: true
  40. });
  41. Object.defineProperty(BBox.prototype, "top", {
  42. get: function () {
  43. return this.y;
  44. },
  45. enumerable: false,
  46. configurable: true
  47. });
  48. BBox.fromRect = function (other) {
  49. return new BBox(other.x, other.y, other.width, other.height);
  50. };
  51. BBox.prototype.toJSON = function () {
  52. return {
  53. x: this.x,
  54. y: this.y,
  55. width: this.width,
  56. height: this.height,
  57. top: this.top,
  58. right: this.right,
  59. bottom: this.bottom,
  60. left: this.left,
  61. };
  62. };
  63. return BBox;
  64. }());
  65. exports.BBox = BBox;
  66. function getRenderBBox(element) {
  67. var _a = element.getRenderBounds(), _b = tslib_1.__read(_a.min, 2), minX = _b[0], minY = _b[1], _c = tslib_1.__read(_a.max, 2), maxX = _c[0], maxY = _c[1];
  68. var width = maxX - minX;
  69. var height = maxY - minY;
  70. return new BBox(minX, minY, width, height);
  71. }
  72. exports.getRenderBBox = getRenderBBox;
  73. //# sourceMappingURL=bbox.js.map