| 121209 | var bezierCache = {}; |
| 121210 | var join = [].join; // Copied from Inkscape svgtopdf, thanks! |
| 121211 | function segments(x2, y2, rx, ry, large, sweep, rotateX, ox, oy) { |
| 121212 | const key = join.call(arguments); |
| 121213 | if (segmentCache[key]) return segmentCache[key]; |
| 121214 | const th = rotateX * DegToRad; |
| 121215 | const sin_th = Math.sin(th); |
| 121216 | const cos_th = Math.cos(th); |
| 121217 | rx = Math.abs(rx); |
| 121218 | ry = Math.abs(ry); |
| 121219 | const px1 = cos_th * (ox - x2) * 0.5 + sin_th * (oy - y2) * 0.5; |
| 121220 | const py1 = cos_th * (oy - y2) * 0.5 - sin_th * (ox - x2) * 0.5; |
| 121221 | let pl = px1 * px1 / (rx * rx) + py1 * py1 / (ry * ry); |
| 121222 | if (pl > 1) { |
| 121223 | pl = Math.sqrt(pl); |
| 121224 | rx *= pl; |
| 121225 | ry *= pl; |
| 121226 | } |
| 121227 | const a00 = cos_th / rx; |
| 121228 | const a01 = sin_th / rx; |
| 121229 | const a10 = -sin_th / ry; |
| 121230 | const a11 = cos_th / ry; |
| 121231 | const x0 = a00 * ox + a01 * oy; |
| 121232 | const y0 = a10 * ox + a11 * oy; |
| 121233 | const x1 = a00 * x2 + a01 * y2; |
| 121234 | const y1 = a10 * x2 + a11 * y2; |
| 121235 | const d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0); |
| 121236 | let sfactor_sq = 1 / d - 0.25; |
| 121237 | if (sfactor_sq < 0) sfactor_sq = 0; |
| 121238 | let sfactor = Math.sqrt(sfactor_sq); |
| 121239 | if (sweep == large) sfactor = -sfactor; |
| 121240 | const xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0); |
| 121241 | const yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0); |
| 121242 | const th0 = Math.atan2(y0 - yc, x0 - xc); |
| 121243 | const th1 = Math.atan2(y1 - yc, x1 - xc); |
| 121244 | let th_arc = th1 - th0; |
| 121245 | if (th_arc < 0 && sweep === 1) th_arc += Tau; |
| 121246 | else if (th_arc > 0 && sweep === 0) th_arc -= Tau; |
| 121247 | const segs = Math.ceil(Math.abs(th_arc / (HalfPi + 0.001))); |
| 121248 | const result = []; |
| 121249 | for(let i = 0; i < segs; ++i){ |
| 121250 | const th2 = th0 + i * th_arc / segs; |
| 121251 | const th3 = th0 + (i + 1) * th_arc / segs; |
| 121252 | result[i] = [ |
| 121253 | xc, |
| 121254 | yc, |
| 121255 | th2, |
| 121256 | th3, |
| 121257 | rx, |
| 121258 | ry, |
| 121259 | sin_th, |
| 121260 | cos_th |
| 121261 | ]; |
| 121262 | } |
| 121263 | return segmentCache[key] = result; |
| 121264 | } |
| 121265 | function bezier(params) { |
| 121266 | const key = join.call(params); |
| 121267 | if (bezierCache[key]) return bezierCache[key]; |