UNPKG

3.33 kBJavaScriptView Raw
1import { __read, __spreadArray } from "tslib";
2import { DIRECTION } from '../../constant';
3/** @ignore */
4var PaddingCal = /** @class */ (function () {
5 /**
6 * 初始的 padding 数据
7 * @param top
8 * @param right
9 * @param bottom
10 * @param left
11 */
12 function PaddingCal(top, right, bottom, left) {
13 if (top === void 0) { top = 0; }
14 if (right === void 0) { right = 0; }
15 if (bottom === void 0) { bottom = 0; }
16 if (left === void 0) { left = 0; }
17 this.top = top;
18 this.right = right;
19 this.bottom = bottom;
20 this.left = left;
21 }
22 /**
23 * 使用静态方法创建一个
24 * @param top
25 * @param right
26 * @param bottom
27 * @param left
28 */
29 PaddingCal.instance = function (top, right, bottom, left) {
30 if (top === void 0) { top = 0; }
31 if (right === void 0) { right = 0; }
32 if (bottom === void 0) { bottom = 0; }
33 if (left === void 0) { left = 0; }
34 return new PaddingCal(top, right, bottom, left);
35 };
36 /**
37 * 取最大区间
38 * @param padding
39 */
40 PaddingCal.prototype.max = function (padding) {
41 var _a = __read(padding, 4), top = _a[0], right = _a[1], bottom = _a[2], left = _a[3];
42 this.top = Math.max(this.top, top);
43 this.right = Math.max(this.right, right);
44 this.bottom = Math.max(this.bottom, bottom);
45 this.left = Math.max(this.left, left);
46 return this;
47 };
48 /**
49 * 四周增加 padding
50 * @param padding
51 */
52 PaddingCal.prototype.shrink = function (padding) {
53 var _a = __read(padding, 4), top = _a[0], right = _a[1], bottom = _a[2], left = _a[3];
54 this.top += top;
55 this.right += right;
56 this.bottom += bottom;
57 this.left += left;
58 return this;
59 };
60 /**
61 * 在某一个方向增加 padding
62 * @param bbox
63 * @param direction
64 */
65 PaddingCal.prototype.inc = function (bbox, direction) {
66 var width = bbox.width, height = bbox.height;
67 switch (direction) {
68 case DIRECTION.TOP:
69 case DIRECTION.TOP_LEFT:
70 case DIRECTION.TOP_RIGHT:
71 this.top += height;
72 break;
73 case DIRECTION.RIGHT:
74 case DIRECTION.RIGHT_TOP:
75 case DIRECTION.RIGHT_BOTTOM:
76 this.right += width;
77 break;
78 case DIRECTION.BOTTOM:
79 case DIRECTION.BOTTOM_LEFT:
80 case DIRECTION.BOTTOM_RIGHT:
81 this.bottom += height;
82 break;
83 case DIRECTION.LEFT:
84 case DIRECTION.LEFT_TOP:
85 case DIRECTION.LEFT_BOTTOM:
86 this.left += width;
87 break;
88 default:
89 break;
90 }
91 return this;
92 };
93 /**
94 * 获得最终的 padding
95 */
96 PaddingCal.prototype.getPadding = function () {
97 return [this.top, this.right, this.bottom, this.left];
98 };
99 /**
100 * clone 一个 padding cal
101 */
102 PaddingCal.prototype.clone = function () {
103 return new (PaddingCal.bind.apply(PaddingCal, __spreadArray([void 0], __read(this.getPadding()), false)))();
104 };
105 return PaddingCal;
106}());
107export { PaddingCal };
108//# sourceMappingURL=padding-cal.js.map
\No newline at end of file