1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getTranslateDirection = exports.directionToPosition = void 0;
|
4 | var constant_1 = require("../constant");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function 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 | }
|
39 | exports.directionToPosition = directionToPosition;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function 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 | }
|
61 | function 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 | }
|
70 | function 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 |
|
81 |
|
82 |
|
83 |
|
84 | function 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 |
|
99 |
|
100 |
|
101 | function 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 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | function 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 | }
|
124 | exports.getTranslateDirection = getTranslateDirection;
|
125 |
|
\ | No newline at end of file |