forked from 088haizi/cardinal-spline-js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcurve.min.js
6 lines (6 loc) · 1.1 KB
/
curve.min.js
1
2
3
4
5
6
/* Curve extension for canvas 2.3.6
* (c) Epistemex 2013-2016
* www.epistemex.com
* License: MIT
*/
CanvasRenderingContext2D.prototype.curve=CanvasRenderingContext2D.prototype.curve||function(h,t,f,c){if(typeof h==="undefined"||h.length<2){return new Float32Array(0)}t=typeof t==="number"?t:0.5;f=typeof f==="number"?f:25;var j,d=1,e=h.length,n=0,m=(e-2)*f+2+(c?2*f:0),k=new Float32Array(m),a=new Float32Array((f+2)<<2),b=4;j=h.slice(0);if(c){j.unshift(h[e-1]);j.unshift(h[e-2]);j.push(h[0],h[1])}else{j.unshift(h[1]);j.unshift(h[0]);j.push(h[e-2],h[e-1])}a[0]=1;for(;d<f;d++){var o=d/f,p=o*o,r=p*o,q=r*2,s=p*3;a[b++]=q-s+1;a[b++]=s-q;a[b++]=r-2*p+o;a[b++]=r-p}a[++b]=1;g(j,a,e,t);if(c){j=[];j.push(h[e-4],h[e-3],h[e-2],h[e-1],h[0],h[1],h[2],h[3]);g(j,a,4,t)}function g(G,z,B,M){for(var A=2,H;A<B;A+=2){var C=G[A],D=G[A+1],E=G[A+2],F=G[A+3],I=(E-G[A-2])*M,J=(F-G[A-1])*M,K=(G[A+4]-C)*M,L=(G[A+5]-D)*M,u=0,v,w,x,y;for(H=0;H<f;H++){v=z[u++];w=z[u++];x=z[u++];y=z[u++];k[n++]=v*C+w*E+x*I+y*K;k[n++]=v*D+w*F+x*J+y*L}}}e=c?0:h.length-2;k[n++]=h[e++];k[n]=h[e];for(d=0,e=k.length;d<e;d+=2){this.lineTo(k[d],k[d+1])}return k};