Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

View File

@@ -0,0 +1,191 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.SVGArcToCubicBezier = factory());
}(this, function () { 'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var TAU = Math.PI * 2;
var mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
var x = _ref.x,
y = _ref.y;
x *= rx;
y *= ry;
var xp = cosphi * x - sinphi * y;
var yp = sinphi * x + cosphi * y;
return {
x: xp + centerx,
y: yp + centery
};
};
var approxUnitArc = function approxUnitArc(ang1, ang2) {
// If 90 degree circular arc, use a constant
// as derived from http://spencermortensen.com/articles/bezier-circle
var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
var x1 = Math.cos(ang1);
var y1 = Math.sin(ang1);
var x2 = Math.cos(ang1 + ang2);
var y2 = Math.sin(ang1 + ang2);
return [{
x: x1 - y1 * a,
y: y1 + x1 * a
}, {
x: x2 + y2 * a,
y: y2 - x2 * a
}, {
x: x2,
y: y2
}];
};
var vectorAngle = function vectorAngle(ux, uy, vx, vy) {
var sign = ux * vy - uy * vx < 0 ? -1 : 1;
var dot = ux * vx + uy * vy;
if (dot > 1) {
dot = 1;
}
if (dot < -1) {
dot = -1;
}
return sign * Math.acos(dot);
};
var getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
var rxsq = Math.pow(rx, 2);
var rysq = Math.pow(ry, 2);
var pxpsq = Math.pow(pxp, 2);
var pypsq = Math.pow(pyp, 2);
var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
if (radicant < 0) {
radicant = 0;
}
radicant /= rxsq * pypsq + rysq * pxpsq;
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
var centerxp = radicant * rx / ry * pyp;
var centeryp = radicant * -ry / rx * pxp;
var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
var vx1 = (pxp - centerxp) / rx;
var vy1 = (pyp - centeryp) / ry;
var vx2 = (-pxp - centerxp) / rx;
var vy2 = (-pyp - centeryp) / ry;
var ang1 = vectorAngle(1, 0, vx1, vy1);
var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
if (sweepFlag === 0 && ang2 > 0) {
ang2 -= TAU;
}
if (sweepFlag === 1 && ang2 < 0) {
ang2 += TAU;
}
return [centerx, centery, ang1, ang2];
};
var arcToBezier = function arcToBezier(_ref2) {
var px = _ref2.px,
py = _ref2.py,
cx = _ref2.cx,
cy = _ref2.cy,
rx = _ref2.rx,
ry = _ref2.ry,
_ref2$xAxisRotation = _ref2.xAxisRotation,
xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,
_ref2$largeArcFlag = _ref2.largeArcFlag,
largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,
_ref2$sweepFlag = _ref2.sweepFlag,
sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;
var curves = [];
if (rx === 0 || ry === 0) {
return [];
}
var sinphi = Math.sin(xAxisRotation * TAU / 360);
var cosphi = Math.cos(xAxisRotation * TAU / 360);
var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
if (pxp === 0 && pyp === 0) {
return [];
}
rx = Math.abs(rx);
ry = Math.abs(ry);
var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
if (lambda > 1) {
rx *= Math.sqrt(lambda);
ry *= Math.sqrt(lambda);
}
var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),
_getArcCenter2 = _slicedToArray(_getArcCenter, 4),
centerx = _getArcCenter2[0],
centery = _getArcCenter2[1],
ang1 = _getArcCenter2[2],
ang2 = _getArcCenter2[3];
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
// 1.0000000001. This causes `segments` to be greater than one, which is an
// unecessary split, and adds extra points to the bezier curve. To alleviate
// this issue, we round to 1.0 when the ratio is close to 1.0.
var ratio = Math.abs(ang2) / (TAU / 4);
if (Math.abs(1.0 - ratio) < 0.0000001) {
ratio = 1.0;
}
var segments = Math.max(Math.ceil(ratio), 1);
ang2 /= segments;
for (var i = 0; i < segments; i++) {
curves.push(approxUnitArc(ang1, ang2));
ang1 += ang2;
}
return curves.map(function (curve) {
var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),
x1 = _mapToEllipse.x,
y1 = _mapToEllipse.y;
var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),
x2 = _mapToEllipse2.x,
y2 = _mapToEllipse2.y;
var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),
x = _mapToEllipse3.x,
y = _mapToEllipse3.y;
return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };
});
};
return arcToBezier;
}));

View File

@@ -0,0 +1 @@
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).SVGArcToCubicBezier=r()}(this,function(){"use strict";function O(t,r,a,n,e,o,i){var h=t.x,u=t.y;return{x:n*(h*=r)-e*(u*=a)+o,y:e*h+n*u+i}}function P(t,r,a,n){var e=t*a+r*n;return 1<e&&(e=1),e<-1&&(e=-1),(t*n-r*a<0?-1:1)*Math.acos(e)}var R=function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,r){var a=[],n=!0,e=!1,o=void 0;try{for(var i,h=t[Symbol.iterator]();!(n=(i=h.next()).done)&&(a.push(i.value),!r||a.length!==r);n=!0);}catch(t){e=!0,o=t}finally{try{!n&&h.return&&h.return()}finally{if(e)throw o}}return a}(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")},V=2*Math.PI;return function(t){var r=t.px,a=t.py,n=t.cx,e=t.cy,u=t.rx,c=t.ry,o=t.xAxisRotation,i=void 0===o?0:o,h=t.largeArcFlag,f=void 0===h?0:h,s=t.sweepFlag,y=void 0===s?0:s,M=[];if(0===u||0===c)return[];var p=Math.sin(i*V/360),v=Math.cos(i*V/360),x=v*(r-n)/2+p*(a-e)/2,l=-p*(r-n)/2+v*(a-e)/2;if(0==x&&0==l)return[];u=Math.abs(u),c=Math.abs(c);var d=Math.pow(x,2)/Math.pow(u,2)+Math.pow(l,2)/Math.pow(c,2);1<d&&(u*=Math.sqrt(d),c*=Math.sqrt(d));var w=function(t,r,a,n,e,o,i,h,u,c,f,s){var y=Math.pow(e,2),M=Math.pow(o,2),p=Math.pow(f,2),v=Math.pow(s,2),x=y*M-y*v-M*p;x<0&&(x=0),x/=y*v+M*p;var l=(x=Math.sqrt(x)*(i===h?-1:1))*e/o*s,d=x*-o/e*f,w=c*l-u*d+(t+a)/2,b=u*l+c*d+(r+n)/2,m=(f-l)/e,A=(s-d)/o,g=(-f-l)/e,q=(-s-d)/o,S=P(1,0,m,A),j=P(m,A,g,q);return 0===h&&0<j&&(j-=V),1===h&&j<0&&(j+=V),[w,b,S,j]}(r,a,n,e,u,c,f,y,p,v,x,l),b=R(w,4),m=b[0],A=b[1],g=b[2],q=b[3],S=Math.abs(q)/(V/4);Math.abs(1-S)<1e-7&&(S=1);var j,F,I,T,z,B,C,E=Math.max(Math.ceil(S),1);q/=E;for(var G=0;G<E;G++)M.push((j=g,void 0,I=1.5707963267948966===(F=q)?.551915024494:-1.5707963267948966===F?-.551915024494:4/3*Math.tan(F/4),T=Math.cos(j),z=Math.sin(j),B=Math.cos(j+F),C=Math.sin(j+F),[{x:T-z*I,y:z+T*I},{x:B+C*I,y:C-B*I},{x:B,y:C}])),g+=q;return M.map(function(t){var r=O(t[0],u,c,v,p,m,A),a=r.x,n=r.y,e=O(t[1],u,c,v,p,m,A),o=e.x,i=e.y,h=O(t[2],u,c,v,p,m,A);return{x1:a,y1:n,x2:o,y2:i,x:h.x,y:h.y}})}});