UNPKG

3.99 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getTranslateDirection = exports.directionToPosition = void 0;
4var constant_1 = require("../constant");
5/**
6 * @ignore
7 * 方位常量转实际的 bbox 位置大小
8 * @param parentBBox
9 * @param bbox
10 * @param direction
11 */
12function directionToPosition(parentBBox, bbox, direction) {
13 if (direction === constant_1.DIRECTION.TOP) {
14 return [parentBBox.minX + parentBBox.width / 2 - bbox.width / 2, parentBBox.minY];
15 }
16 if (direction === constant_1.DIRECTION.BOTTOM) {
17 return [parentBBox.minX + parentBBox.width / 2 - bbox.width / 2, parentBBox.maxY - bbox.height];
18 }
19 if (direction === constant_1.DIRECTION.LEFT) {
20 return [parentBBox.minX, parentBBox.minY + parentBBox.height / 2 - bbox.height / 2];
21 }
22 if (direction === constant_1.DIRECTION.RIGHT) {
23 return [parentBBox.maxX - bbox.width, parentBBox.minY + parentBBox.height / 2 - bbox.height / 2];
24 }
25 if (direction === constant_1.DIRECTION.TOP_LEFT || direction === constant_1.DIRECTION.LEFT_TOP) {
26 return [parentBBox.tl.x, parentBBox.tl.y];
27 }
28 if (direction === constant_1.DIRECTION.TOP_RIGHT || direction === constant_1.DIRECTION.RIGHT_TOP) {
29 return [parentBBox.tr.x - bbox.width, parentBBox.tr.y];
30 }
31 if (direction === constant_1.DIRECTION.BOTTOM_LEFT || direction === constant_1.DIRECTION.LEFT_BOTTOM) {
32 return [parentBBox.bl.x, parentBBox.bl.y - bbox.height];
33 }
34 if (direction === constant_1.DIRECTION.BOTTOM_RIGHT || direction === constant_1.DIRECTION.RIGHT_BOTTOM) {
35 return [parentBBox.br.x - bbox.width, parentBBox.br.y - bbox.height];
36 }
37 return [0, 0];
38}
39exports.directionToPosition = directionToPosition;
40/**
41 * get direction after coordinate transpose
42 * @param direction
43 * @param coordinate
44 * @returns direction after transpose or not
45 */
46function getTransposedDirection(direction, coordinate) {
47 if (coordinate.isTransposed) {
48 switch (direction) {
49 case constant_1.DIRECTION.BOTTOM:
50 return constant_1.DIRECTION.LEFT;
51 case constant_1.DIRECTION.LEFT:
52 return constant_1.DIRECTION.BOTTOM;
53 case constant_1.DIRECTION.RIGHT:
54 return constant_1.DIRECTION.TOP;
55 case constant_1.DIRECTION.TOP:
56 return constant_1.DIRECTION.RIGHT;
57 }
58 }
59 return direction;
60}
61function reflectX(direct) {
62 if (direct === constant_1.DIRECTION.LEFT) {
63 return constant_1.DIRECTION.RIGHT;
64 }
65 if (direct === constant_1.DIRECTION.RIGHT) {
66 return constant_1.DIRECTION.LEFT;
67 }
68 return direct;
69}
70function reflectY(direct) {
71 if (direct === constant_1.DIRECTION.TOP) {
72 return constant_1.DIRECTION.BOTTOM;
73 }
74 if (direct === constant_1.DIRECTION.BOTTOM) {
75 return constant_1.DIRECTION.TOP;
76 }
77 return direct;
78}
79/**
80 * get direction after coordinate.scale
81 * @param direction
82 * @param coordinate
83 */
84function getScaleDirection(direction, coordinate) {
85 var x = coordinate.matrix[0];
86 var y = coordinate.matrix[4];
87 var d = direction;
88 if (x < 0) {
89 d = reflectX(d);
90 }
91 if (y < 0) {
92 d = reflectY(d);
93 }
94 return d;
95}
96/**
97 *
98 * @param direction
99 * @param coordinate
100 */
101function getReflectDirection(direction, coordinate) {
102 var d = direction;
103 if (coordinate.isReflect('x')) {
104 d = reflectX(d);
105 }
106 if (coordinate.isReflect('y')) {
107 d = reflectY(d);
108 }
109 return d;
110}
111/**
112 * @ignore
113 * get direction after coordinate translate
114 * @param direction
115 * @param coordinate
116 */
117function getTranslateDirection(direction, coordinate) {
118 var d = direction;
119 d = getTransposedDirection(d, coordinate);
120 d = getScaleDirection(d, coordinate);
121 d = getReflectDirection(d, coordinate);
122 return d;
123}
124exports.getTranslateDirection = getTranslateDirection;
125//# sourceMappingURL=direction.js.map
\No newline at end of file