1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getCoordinateBBox = exports.getCoordinateClipCfg = exports.getAngleByPoint = exports.isPointInCoordinate = exports.getDistanceToCenter = exports.isFullCircle = exports.getXDimensionLength = void 0;
|
4 | var graphics_1 = require("./graphics");
|
5 | var helper_1 = require("./helper");
|
6 | var bbox_1 = require("./bbox");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function getXDimensionLength(coordinate) {
|
14 | if (coordinate.isPolar && !coordinate.isTransposed) {
|
15 |
|
16 | return (coordinate.endAngle - coordinate.startAngle) * coordinate.getRadius();
|
17 | }
|
18 |
|
19 | var start = coordinate.convert({ x: 0, y: 0 });
|
20 | var end = coordinate.convert({ x: 1, y: 0 });
|
21 |
|
22 | return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
|
23 | }
|
24 | exports.getXDimensionLength = getXDimensionLength;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function isFullCircle(coordinate) {
|
32 | if (coordinate.isPolar) {
|
33 | var startAngle = coordinate.startAngle, endAngle = coordinate.endAngle;
|
34 | return endAngle - startAngle === Math.PI * 2;
|
35 | }
|
36 | return false;
|
37 | }
|
38 | exports.isFullCircle = isFullCircle;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function getDistanceToCenter(coordinate, point) {
|
47 | var center = coordinate.getCenter();
|
48 | return Math.sqrt(Math.pow((point.x - center.x), 2) + Math.pow((point.y - center.y), 2));
|
49 | }
|
50 | exports.getDistanceToCenter = getDistanceToCenter;
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function isPointInCoordinate(coordinate, point) {
|
58 | var result = false;
|
59 | if (coordinate) {
|
60 | if (coordinate.type === 'theta') {
|
61 | var start = coordinate.start, end = coordinate.end;
|
62 | result = (0, helper_1.isBetween)(point.x, start.x, end.x) && (0, helper_1.isBetween)(point.y, start.y, end.y);
|
63 | }
|
64 | else {
|
65 | var invertPoint = coordinate.invert(point);
|
66 | result = (0, helper_1.isBetween)(invertPoint.x, 0, 1) && (0, helper_1.isBetween)(invertPoint.y, 0, 1);
|
67 | }
|
68 | }
|
69 | return result;
|
70 | }
|
71 | exports.isPointInCoordinate = isPointInCoordinate;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function getAngleByPoint(coordinate, point) {
|
77 | var center = coordinate.getCenter();
|
78 | return Math.atan2(point.y - center.y, point.x - center.x);
|
79 | }
|
80 | exports.getAngleByPoint = getAngleByPoint;
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function getCoordinateClipCfg(coordinate, margin) {
|
88 | if (margin === void 0) { margin = 0; }
|
89 | var start = coordinate.start, end = coordinate.end;
|
90 | var width = coordinate.getWidth();
|
91 | var height = coordinate.getHeight();
|
92 | if (coordinate.isPolar) {
|
93 | var startAngle_1 = coordinate.startAngle, endAngle_1 = coordinate.endAngle;
|
94 | var center_1 = coordinate.getCenter();
|
95 | var radius_1 = coordinate.getRadius();
|
96 | return {
|
97 | type: 'path',
|
98 | startState: {
|
99 | path: (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, startAngle_1),
|
100 | },
|
101 | endState: function (ratio) {
|
102 | var diff = (endAngle_1 - startAngle_1) * ratio + startAngle_1;
|
103 | var path = (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, diff);
|
104 | return {
|
105 | path: path,
|
106 | };
|
107 | },
|
108 | attrs: {
|
109 | path: (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, endAngle_1),
|
110 | },
|
111 | };
|
112 | }
|
113 | var endState;
|
114 | if (coordinate.isTransposed) {
|
115 | endState = {
|
116 | height: height + margin * 2,
|
117 | };
|
118 | }
|
119 | else {
|
120 | endState = {
|
121 | width: width + margin * 2,
|
122 | };
|
123 | }
|
124 | return {
|
125 | type: 'rect',
|
126 | startState: {
|
127 | x: start.x - margin,
|
128 | y: end.y - margin,
|
129 | width: coordinate.isTransposed ? width + margin * 2 : 0,
|
130 | height: coordinate.isTransposed ? 0 : height + margin * 2,
|
131 | },
|
132 | endState: endState,
|
133 | attrs: {
|
134 | x: start.x - margin,
|
135 | y: end.y - margin,
|
136 | width: width + margin * 2,
|
137 | height: height + margin * 2,
|
138 | },
|
139 | };
|
140 | }
|
141 | exports.getCoordinateClipCfg = getCoordinateClipCfg;
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | function getCoordinateBBox(coordinate, margin) {
|
148 | if (margin === void 0) { margin = 0; }
|
149 | var start = coordinate.start, end = coordinate.end;
|
150 | var width = coordinate.getWidth();
|
151 | var height = coordinate.getHeight();
|
152 | var minX = Math.min(start.x, end.x);
|
153 | var minY = Math.min(start.y, end.y);
|
154 | return bbox_1.BBox.fromRange(minX - margin, minY - margin, minX + width + margin, minY + height + margin);
|
155 | }
|
156 | exports.getCoordinateBBox = getCoordinateBBox;
|
157 |
|
\ | No newline at end of file |