bbox.js 2.0 KB

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