1 line
4.4 KiB
Plaintext
1 line
4.4 KiB
Plaintext
{"version":3,"file":"svgarc.min.js","sources":["../../src/util/svgarc.js"],"sourcesContent":["/*\nCopyright © 2020 Xah Lee, © 2023 P.M Kuipers\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the “Software”),\nto deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\nTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\nURL: SVG Circle Arc http://xahlee.info/js/svg_circle_arc.html\n*/\n\nconst cos = Math.cos;\nconst sin = Math.sin;\nconst π = Math.PI;\n\nconst fMatrixTimes = (([[a, b], [c, d]], [x, y]) => [a * x + b * y, c * x + d * y]);\nconst fRotateMatrix = (x => [[cos(x), -sin(x)], [sin(x), cos(x)]]);\nconst fVecAdd = (([a1, a2], [b1, b2]) => [a1 + b1, a2 + b2]);\n\n// Function modified by pmkuipers for text params\n/**\n * Create svg path text for an arc\n * @param {*} center [cx,cy] center of ellipse\n * @param {*} radius [rx,ry] major minor radius\n * @param {*} angle [t1, Δ] start angle, in radian, angle to sweep, in radian. positive.\n * @param {*} φ rotation on the whole, in radian\n * @returns {string} a SVG path description that represent a ellipse. Text describing the arc path in an svg path element\n */\nconst svgarcpath = (([cx, cy], [rx, ry], [t1, Δ], φ) => {\n Δ = Δ % (2 * π);\n const rotMatrix = fRotateMatrix(φ);\n const [sX, sY] = (fVecAdd(fMatrixTimes(rotMatrix, [rx * cos(t1), ry * sin(t1)]), [cx, cy]));\n const [eX, eY] = (fVecAdd(fMatrixTimes(rotMatrix, [rx * cos(t1 + Δ), ry * sin(t1 + Δ)]), [cx, cy]));\n const fA = ((Δ > π) ? 1 : 0);\n const fS = ((Δ > 0) ? 1 : 0);\n if (isNaN(eY) || isNaN(eX)) {\n return \"\";\n } else {\n return \"M \" + sX + \" \" + sY + \" A \" + [rx, ry, φ / (2 * π) * 360, fA, fS, eX, eY].join(\" \");\n }\n});\n\n/**\n * Create an svg arc element\n * @param {*} center [cx,cy] center of ellipse\n * @param {*} radius [rx,ry] major minor radius\n * @param {*} angle [t1, Δ] start angle, in radian, angle to sweep, in radian. positive.\n * @param {*} φ rotation on the whole, in radian\n * @returns {string} a SVG path element that represent a ellipse.\n */\nconst svgarc = (([cx, cy], [rx, ry], [t1, Δ], φ) => {\n const path2wk2r = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n const d = svgarcpath([cx, cy], [rx, ry], [t1, Δ], φ);\n path2wk2r.setAttribute(\"d\", d);\n return path2wk2r;\n});\n\nexport {svgarc, svgarcpath};"],"names":["cos","Math","sin","π","PI","fMatrixTimes","a","b","c","d","x","y","fVecAdd","a1","a2","b1","b2","svgarcpath","φ","cx","cy","rx","ry","t1","Δ","rotMatrix","sX","sY","eX","eY","fA","fS","isNaN","join","path2wk2r","document","createElementNS","setAttribute"],"mappings":"kLAoBMA,IAAMC,KAAKD,IACXE,IAAMD,KAAKC,IACXC,EAAIF,KAAKG,GAETC,aAAgB,oBAAGC,EAAGC,IAAKC,EAAGC,UAAMC,EAAGC,eAAO,CAACL,EAAII,EAAIH,EAAII,EAAGH,EAAIE,EAAID,EAAIE,EAA1D,EAEhBC,QAAW,oBAAEC,GAAIC,WAAMC,GAA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