perfect-freehand
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -0,1 +1,5 @@ | ||
# 0.1.3 | ||
- Removes hidden options, uses `maxSize` for velocity calculations. | ||
# 0.1.2 | ||
@@ -2,0 +6,0 @@ |
@@ -109,9 +109,3 @@ 'use strict'; | ||
_options$smooth = _options.smooth, | ||
smooth = _options$smooth === void 0 ? 8 : _options$smooth, | ||
_options$pressureChan = _options.pressureChangeRate, | ||
pressureChangeRate = _options$pressureChan === void 0 ? 0.5 : _options$pressureChan, | ||
_options$pressureMaxV = _options.pressureMaxVelocity, | ||
pressureMaxVelocity = _options$pressureMaxV === void 0 ? 8 : _options$pressureMaxV, | ||
_options$pressureVelo = _options.pressureVelocityEffect, | ||
pressureVelocityEffect = _options$pressureVelo === void 0 ? 8 : _options$pressureVelo; | ||
smooth = _options$smooth === void 0 ? 8 : _options$smooth; | ||
var aPoints = toPointsArray(points); | ||
@@ -126,3 +120,2 @@ var d0, | ||
p1 = aPoints[len - 1], | ||
prev = p0, | ||
t0 = p0, | ||
@@ -132,2 +125,3 @@ t1 = p1, | ||
m1 = p0, | ||
prev = p0, | ||
length = 0, | ||
@@ -175,3 +169,3 @@ x, | ||
// If pen, accellerate the reported pressure | ||
ip = pp + (ip - pp) * pressureChangeRate; | ||
ip = pp + (ip - pp) / 2; | ||
} else { | ||
@@ -183,5 +177,5 @@ // If too short (or if not simulating pressure), use the max size. | ||
// Calculate pressure based on velocity (slower = more pressure) | ||
var rp = 1 - distance / pressureMaxVelocity; | ||
var sp = Math.min(distance / pressureVelocityEffect, 1); | ||
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp)); | ||
var rp = 1 - distance / maxSize; | ||
var sp = min(distance / maxSize, 1); | ||
ip = min(1, pp + (rp - pp) * (sp / 2)); | ||
} | ||
@@ -188,0 +182,0 @@ } // Size is based on pressure |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("polygon-clipping"))&&"object"==typeof e&&"default"in e?e.default:e;function t(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function n(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var o=Math.hypot,a=Math.cos,i=Math.max,u=Math.min,s=Math.sin,v=Math.atan2,l=Math.PI/2;function f(e,r,t,n){return[a(t)*n+e,s(t)*n+r]}function d(e,r,t,n){return[e+(t-e)/2,r+(n-r)/2]}exports.default=function(e,t){void 0===t&&(t={});var a,s,h,p,c=t.type,y=void 0===c?"mouse":c,m=t.simulatePressure,M=void 0===m||m,b=t.streamline,g=void 0===b?.5:b,A=t.minSize,S=void 0===A?2.5:A,x=t.maxSize,j=void 0===x?8:x,I=t.smooth,w=void 0===I?8:I,O=t.pressureChangeRate,P=void 0===O?.5:O,z=t.pressureMaxVelocity,C=void 0===z?8:z,E=t.pressureVelocityEffect,V=void 0===E?8:E,_=function(e){return Array.isArray(e[0])?e.map((function(e){var r=e[2];return[e[0],e[1],void 0===r?.5:r]})):e.map((function(e){var r=e.pressure;return[e.x,e.y,void 0===r?.5:r]}))}(e),q=[],Q=_.length,R=0,T=_[0],U=_[Q-1],$=T,k=T,B=U,D=T,F=T,G=0,H="";if(0===Q)return"";if(Q<4){var J=(S+(j-S))*("pen"===y?U[2]:.44);H="\n M "+(U[0]-J)+","+U[1]+"\n a "+J+","+J+" 0 1,0 "+2*J+",0\n a "+J+","+J+" 0 1,0 -"+2*J+",0\n "}else{for(var K=0;K<_.length;K++){var L=_[K],N=L[2],W=$[0],X=$[1],Y=$[2];if(h=v((s=X+(L[1]-X)*(1-g))-X,(a=W+(L[0]-W)*(1-g))-W),G+=R=o(s-X,a-W),"pen"===y)N=Y+(N-Y)*P;else if(M){var Z=1-R/C,ee=Math.min(R/V,1);N=Math.min(1,Y+P*ee*(Z-Y))}else N=1;if(p=i(S,u(j,S+N*(j-S))),G<16){var re=G/16;p*=re*re*re}T=f(a,s,h-l,p),U=f(a,s,h+l,p),0===K?(k=T,B=U):(Math.hypot(T[0]-k[0],T[1]-k[1])>w&&(q.push(D),D=d(k[0],k[1],T[0],T[1]),k=T),Math.hypot(U[0]-B[0],U[1]-B[1])>w&&(q.unshift(F),F=d(B[0],B[1],U[0],U[1]),B=U)),$=[a,s,N]}q.push($),q.unshift($);for(var te,ne=n(r.union([q]));!(te=ne()).done;)for(var oe,ae=n(te.value);!(oe=ae()).done;){var ie=oe.value,ue=ie[0],se=ie[1];ie.push(ue),H+=" M "+ue[0]+" "+ue[1];for(var ve=1;ve<ie.length;ve++){var le=d(ue[0],ue[1],se[0],se[1]);H+=" Q "+ue[0]+","+ue[1]+" "+le[0]+","+le[1],ue=se,se=ie[ve+1]}}}return H}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,t=(r=require("polygon-clipping"))&&"object"==typeof r&&"default"in r?r.default:r;function e(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function n(r,t){var n;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(n=function(r,t){if(r){if("string"==typeof r)return e(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(r,void 0):void 0}}(r))||t&&r&&"number"==typeof r.length){n&&(r=n);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=r[Symbol.iterator]()).next.bind(n)}var o=Math.hypot,a=Math.cos,i=Math.max,u=Math.min,l=Math.sin,v=Math.atan2,f=Math.PI/2;function s(r,t,e,n){return[a(e)*n+r,l(e)*n+t]}function d(r,t,e,n){return[r+(e-r)/2,t+(n-t)/2]}exports.default=function(r,e){void 0===e&&(e={});var a,l,h,p,c=e.type,y=void 0===c?"mouse":c,m=e.simulatePressure,b=void 0===m||m,M=e.streamline,g=void 0===M?.5:M,A=e.minSize,S=void 0===A?2.5:A,x=e.maxSize,j=void 0===x?8:x,I=e.smooth,w=void 0===I?8:I,O=function(r){return Array.isArray(r[0])?r.map((function(r){var t=r[2];return[r[0],r[1],void 0===t?.5:t]})):r.map((function(r){var t=r.pressure;return[r.x,r.y,void 0===t?.5:t]}))}(r),P=[],z=O.length,_=0,q=O[0],C=O[z-1],E=q,Q=C,T=q,U=q,$=q,k=0,B="";if(0===z)return"";if(z<4){var D=(S+(j-S))*("pen"===y?C[2]:.44);B="\n M "+(C[0]-D)+","+C[1]+"\n a "+D+","+D+" 0 1,0 "+2*D+",0\n a "+D+","+D+" 0 1,0 -"+2*D+",0\n "}else{for(var F=0;F<O.length;F++){var G=O[F],H=G[2],J=$[0],K=$[1],L=$[2];if(h=v((l=K+(G[1]-K)*(1-g))-K,(a=J+(G[0]-J)*(1-g))-J),k+=_=o(l-K,a-J),"pen"===y)H=L+(H-L)/2;else if(b){var N=1-_/j,R=u(_/j,1);H=u(1,L+R/2*(N-L))}else H=1;if(p=i(S,u(j,S+H*(j-S))),k<16){var V=k/16;p*=V*V*V}q=s(a,l,h-f,p),C=s(a,l,h+f,p),0===F?(E=q,Q=C):(Math.hypot(q[0]-E[0],q[1]-E[1])>w&&(P.push(T),T=d(E[0],E[1],q[0],q[1]),E=q),Math.hypot(C[0]-Q[0],C[1]-Q[1])>w&&(P.unshift(U),U=d(Q[0],Q[1],C[0],C[1]),Q=C)),$=[a,l,H]}P.push($),P.unshift($);for(var W,X=n(t.union([P]));!(W=X()).done;)for(var Y,Z=n(W.value);!(Y=Z()).done;){var rr=Y.value,tr=rr[0],er=rr[1];rr.push(tr),B+=" M "+tr[0]+" "+tr[1];for(var nr=1;nr<rr.length;nr++){var or=d(tr[0],tr[1],er[0],er[1]);B+=" Q "+tr[0]+","+tr[1]+" "+or[0]+","+or[1],tr=er,er=rr[nr+1]}}}return B}; | ||
//# sourceMappingURL=perfect-freehand.cjs.production.min.js.map |
@@ -103,9 +103,3 @@ import polygonClipping from 'polygon-clipping'; | ||
_options$smooth = _options.smooth, | ||
smooth = _options$smooth === void 0 ? 8 : _options$smooth, | ||
_options$pressureChan = _options.pressureChangeRate, | ||
pressureChangeRate = _options$pressureChan === void 0 ? 0.5 : _options$pressureChan, | ||
_options$pressureMaxV = _options.pressureMaxVelocity, | ||
pressureMaxVelocity = _options$pressureMaxV === void 0 ? 8 : _options$pressureMaxV, | ||
_options$pressureVelo = _options.pressureVelocityEffect, | ||
pressureVelocityEffect = _options$pressureVelo === void 0 ? 8 : _options$pressureVelo; | ||
smooth = _options$smooth === void 0 ? 8 : _options$smooth; | ||
var aPoints = toPointsArray(points); | ||
@@ -120,3 +114,2 @@ var d0, | ||
p1 = aPoints[len - 1], | ||
prev = p0, | ||
t0 = p0, | ||
@@ -126,2 +119,3 @@ t1 = p1, | ||
m1 = p0, | ||
prev = p0, | ||
length = 0, | ||
@@ -169,3 +163,3 @@ x, | ||
// If pen, accellerate the reported pressure | ||
ip = pp + (ip - pp) * pressureChangeRate; | ||
ip = pp + (ip - pp) / 2; | ||
} else { | ||
@@ -177,5 +171,5 @@ // If too short (or if not simulating pressure), use the max size. | ||
// Calculate pressure based on velocity (slower = more pressure) | ||
var rp = 1 - distance / pressureMaxVelocity; | ||
var sp = Math.min(distance / pressureVelocityEffect, 1); | ||
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp)); | ||
var rp = 1 - distance / maxSize; | ||
var sp = min(distance / maxSize, 1); | ||
ip = min(1, pp + (rp - pp) * (sp / 2)); | ||
} | ||
@@ -182,0 +176,0 @@ } // Size is based on pressure |
{ | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -59,5 +59,2 @@ import polygonClipping from 'polygon-clipping' | ||
smooth = 8, | ||
pressureChangeRate = 0.5, | ||
pressureMaxVelocity = 8, | ||
pressureVelocityEffect = 8, | ||
} = options | ||
@@ -74,3 +71,2 @@ | ||
p1 = aPoints[len - 1], | ||
prev = p0, | ||
t0 = p0, | ||
@@ -80,2 +76,3 @@ t1 = p1, | ||
m1 = p0, | ||
prev = p0, | ||
length = 0, | ||
@@ -125,3 +122,3 @@ x: number, | ||
// If pen, accellerate the reported pressure | ||
ip = pp + (ip - pp) * pressureChangeRate | ||
ip = pp + (ip - pp) / 2 | ||
} else { | ||
@@ -133,5 +130,5 @@ // If too short (or if not simulating pressure), use the max size. | ||
// Calculate pressure based on velocity (slower = more pressure) | ||
let rp = 1 - distance / pressureMaxVelocity | ||
const sp = Math.min(distance / pressureVelocityEffect, 1) | ||
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp)) | ||
let rp = 1 - distance / maxSize | ||
const sp = min(distance / maxSize, 1) | ||
ip = min(1, pp + (rp - pp) * (sp / 2)) | ||
} | ||
@@ -138,0 +135,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58203
606