1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | const pi = Math.PI,
|
8 | tau = 2 * pi,
|
9 | epsilon = 1e-6,
|
10 | tauEpsilon = tau - epsilon;
|
11 |
|
12 | function Path() {
|
13 | this._x0 = this._y0 =
|
14 | this._x1 = this._y1 = null;
|
15 |
|
16 | this._ = "";
|
17 | }
|
18 |
|
19 | function path() {
|
20 | return new Path();
|
21 | }
|
22 |
|
23 | Path.prototype = path.prototype = {
|
24 | constructor: Path,
|
25 | moveTo: function (x, y) {
|
26 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
|
27 | },
|
28 | closePath: function () {
|
29 | if (this._x1 !== null) {
|
30 | this._x1 = this._x0, this._y1 = this._y0;
|
31 | this._ += "Z";
|
32 | }
|
33 | },
|
34 | lineTo: function (x, y) {
|
35 | this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
|
36 | },
|
37 | quadraticCurveTo: function (x1, y1, x, y) {
|
38 | this._ += "Q" + +x1 + "," + +y1 + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
39 | },
|
40 | bezierCurveTo: function (x1, y1, x2, y2, x, y) {
|
41 | this._ += "C" + +x1 + "," + +y1 + "," + +x2 + "," + +y2 + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
42 | },
|
43 | arcTo: function (x1, y1, x2, y2, r) {
|
44 | x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
45 | var x0 = this._x1,
|
46 | y0 = this._y1,
|
47 | x21 = x2 - x1,
|
48 | y21 = y2 - y1,
|
49 | x01 = x0 - x1,
|
50 | y01 = y0 - y1,
|
51 | l01_2 = x01 * x01 + y01 * y01;
|
52 |
|
53 | if (r < 0) throw new Error("negative radius: " + r);
|
54 |
|
55 | if (this._x1 === null) {
|
56 | this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
|
57 | }
|
58 | else if (!(l01_2 > epsilon)) ;
|
59 |
|
60 |
|
61 | else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
|
62 | this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
|
63 | }
|
64 | else {
|
65 | var x20 = x2 - x0,
|
66 | y20 = y2 - y0,
|
67 | l21_2 = x21 * x21 + y21 * y21,
|
68 | l20_2 = x20 * x20 + y20 * y20,
|
69 | l21 = Math.sqrt(l21_2),
|
70 | l01 = Math.sqrt(l01_2),
|
71 | l = r * Math.tan((pi - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
72 | t01 = l / l01,
|
73 | t21 = l / l21;
|
74 |
|
75 | if (Math.abs(t01 - 1) > epsilon) {
|
76 | this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
|
77 | }
|
78 |
|
79 | this._ += "A" + r + "," + r + ",0,0," + +(y01 * x20 > x01 * y20) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
|
80 | }
|
81 | },
|
82 | arc: function (x, y, r, a0, a1, ccw) {
|
83 | x = +x, y = +y, r = +r, ccw = !!ccw;
|
84 | var dx = r * Math.cos(a0),
|
85 | dy = r * Math.sin(a0),
|
86 | x0 = x + dx,
|
87 | y0 = y + dy,
|
88 | cw = 1 ^ ccw,
|
89 | da = ccw ? a0 - a1 : a1 - a0;
|
90 |
|
91 | if (r < 0) throw new Error("negative radius: " + r);
|
92 |
|
93 | if (this._x1 === null) {
|
94 | this._ += "M" + x0 + "," + y0;
|
95 | }
|
96 | else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
|
97 | this._ += "L" + x0 + "," + y0;
|
98 | }
|
99 |
|
100 |
|
101 | if (!r) return;
|
102 |
|
103 | if (da < 0) da = da % tau + tau;
|
104 |
|
105 | if (da > tauEpsilon) {
|
106 | this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
|
107 | }
|
108 | else if (da > epsilon) {
|
109 | this._ += "A" + r + "," + r + ",0," + +(da >= pi) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
|
110 | }
|
111 | },
|
112 | rect: function (x, y, w, h) {
|
113 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + +w + "v" + +h + "h" + -w + "Z";
|
114 | },
|
115 | toString: function () {
|
116 | return this._;
|
117 | }
|
118 | };
|
119 | var _default = path;
|
120 | exports.default = _default; |
\ | No newline at end of file |