UNPKG

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