1 | import { __decorate } from "tslib";
|
2 | import { singleton } from 'mana-syringe';
|
3 | import { GeometryAABBUpdater } from './interfaces';
|
4 | import { Shape } from '../../types';
|
5 |
|
6 | var PathUpdater =
|
7 | /** @class */
|
8 | function () {
|
9 | function PathUpdater() {}
|
10 |
|
11 | PathUpdater.prototype.update = function (parsedStyle) {
|
12 | var path = parsedStyle.path;
|
13 | var _a = path.rect,
|
14 | width = _a.width,
|
15 | height = _a.height;
|
16 | return {
|
17 | width: width,
|
18 | height: height
|
19 | };
|
20 | };
|
21 |
|
22 | PathUpdater = __decorate([singleton({
|
23 | token: {
|
24 | token: GeometryAABBUpdater,
|
25 | named: Shape.PATH
|
26 | }
|
27 | })], PathUpdater);
|
28 | return PathUpdater;
|
29 | }();
|
30 |
|
31 | export { PathUpdater }; // function getPathBox(segments: PathSegment[], lineWidth: number) {
|
32 | // let xArr = [];
|
33 | // let yArr = [];
|
34 | // const segmentsWithAngle = [];
|
35 | // for (let i = 0; i < segments.length; i++) {
|
36 | // const segment = segments[i];
|
37 | // const { currentPoint, params, prePoint } = segment;
|
38 | // let box;
|
39 | // switch (segment.command) {
|
40 | // case 'Q':
|
41 | // box = QuadUtil.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
|
42 | // break;
|
43 | // case 'C':
|
44 | // box = CubicUtil.box(
|
45 | // prePoint[0],
|
46 | // prePoint[1],
|
47 | // params[1],
|
48 | // params[2],
|
49 | // params[3],
|
50 | // params[4],
|
51 | // params[5],
|
52 | // params[6],
|
53 | // );
|
54 | // break;
|
55 | // case 'A':
|
56 | // // eslint-disable-next-line no-case-declarations
|
57 | // const { arcParams } = segment;
|
58 | // box = EllipseArcUtil.box(
|
59 | // arcParams.cx,
|
60 | // arcParams.cy,
|
61 | // arcParams.rx,
|
62 | // arcParams.ry,
|
63 | // arcParams.xRotation,
|
64 | // arcParams.startAngle,
|
65 | // arcParams.endAngle,
|
66 | // );
|
67 | // break;
|
68 | // default:
|
69 | // xArr.push(currentPoint[0]);
|
70 | // yArr.push(currentPoint[1]);
|
71 | // break;
|
72 | // }
|
73 | // if (box) {
|
74 | // segment.box = box;
|
75 | // xArr.push(box.x, box.x + box.width);
|
76 | // yArr.push(box.y, box.y + box.height);
|
77 | // }
|
78 | // if (
|
79 | // lineWidth &&
|
80 | // (segment.command === 'L' || segment.command === 'M') &&
|
81 | // segment.prePoint &&
|
82 | // segment.nextPoint
|
83 | // ) {
|
84 | // segmentsWithAngle.push(segment);
|
85 | // }
|
86 | // }
|
87 | // // bbox calculation should ignore NaN for path attribute
|
88 | // // ref: https://github.com/antvis/g/issues/210
|
89 | // xArr = xArr.filter((item) => !Number.isNaN(item));
|
90 | // yArr = yArr.filter((item) => !Number.isNaN(item));
|
91 | // let minX = min(xArr);
|
92 | // let minY = min(yArr);
|
93 | // let maxX = max(xArr);
|
94 | // let maxY = max(yArr);
|
95 | // if (segmentsWithAngle.length === 0) {
|
96 | // return {
|
97 | // x: minX,
|
98 | // y: minY,
|
99 | // width: maxX - minX,
|
100 | // height: maxY - minY,
|
101 | // };
|
102 | // }
|
103 | // for (let i = 0; i < segmentsWithAngle.length; i++) {
|
104 | // const segment = segmentsWithAngle[i];
|
105 | // const { currentPoint } = segment;
|
106 | // let extra;
|
107 | // if (currentPoint[0] === minX) {
|
108 | // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
109 | // minX -= extra.xExtra;
|
110 | // } else if (currentPoint[0] === maxX) {
|
111 | // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
112 | // maxX += extra.xExtra;
|
113 | // }
|
114 | // if (currentPoint[1] === minY) {
|
115 | // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
116 | // minY -= extra.yExtra;
|
117 | // } else if (currentPoint[1] === maxY) {
|
118 | // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
119 | // maxY += extra.yExtra;
|
120 | // }
|
121 | // }
|
122 | // return {
|
123 | // x: minX,
|
124 | // y: minY,
|
125 | // width: maxX - minX,
|
126 | // height: maxY - minY,
|
127 | // };
|
128 | // }
|
129 | // function getExtraFromSegmentWithAngle(segment: any, lineWidth: number) {
|
130 | // const { prePoint, currentPoint, nextPoint } = segment;
|
131 | // const currentAndPre =
|
132 | // Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
|
133 | // const currentAndNext =
|
134 | // Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
|
135 | // const preAndNext =
|
136 | // Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2);
|
137 | // // 以 currentPoint 为顶点的夹角
|
138 | // const currentAngle = Math.acos(
|
139 | // (currentAndPre + currentAndNext - preAndNext) /
|
140 | // (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext)),
|
141 | // );
|
142 | // // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
|
143 | // // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
|
144 | // if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
|
145 | // return {
|
146 | // xExtra: 0,
|
147 | // yExtra: 0,
|
148 | // };
|
149 | // }
|
150 | // let xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
|
151 | // let yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1]));
|
152 | // // 将夹角转为锐角
|
153 | // xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
|
154 | // yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle;
|
155 | // // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
|
156 | // // 由于上层统一加减了二分之一线宽,这里需要进行弥补
|
157 | // const extra = {
|
158 | // // 水平方向投影
|
159 | // xExtra:
|
160 | // Math.cos(currentAngle / 2 - xAngle) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
|
161 | // lineWidth / 2 || 0,
|
162 | // // 垂直方向投影
|
163 | // yExtra:
|
164 | // Math.cos(yAngle - currentAngle / 2) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
|
165 | // lineWidth / 2 || 0,
|
166 | // };
|
167 | // return extra;
|
168 | // } |
\ | No newline at end of file |