perfect-freehand
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -66,2 +66,12 @@ 'use strict'; | ||
function shortAngleDist(a0, a1) { | ||
var max = Math.PI * 2; | ||
var da = (a1 - a0) % max; | ||
return 2 * da % max - da; | ||
} | ||
function angleDelta(a0, a1) { | ||
return shortAngleDist(a0, a1); | ||
} | ||
function getPointBetween(x0, y0, x1, y1, d) { | ||
@@ -211,6 +221,3 @@ if (d === void 0) { | ||
smooth = _options3$smooth === void 0 ? 8 : _options3$smooth; | ||
var d0, | ||
d1, | ||
// first / last | ||
len = points.length, | ||
var len = points.length, | ||
p0 = points[0], | ||
@@ -225,3 +232,7 @@ p1 = points[0], | ||
prev = p1, | ||
pts = []; | ||
length = 0, | ||
leftPts = [], | ||
rightPts = [], | ||
d0, | ||
d1; | ||
@@ -240,3 +251,4 @@ if (len === 0) { | ||
angle = _points$i[3], | ||
distance = _points$i[4]; // Size | ||
distance = _points$i[4]; | ||
length += distance; // Size | ||
@@ -266,17 +278,50 @@ if (pressure) { | ||
t1 = p1; | ||
} else { | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]); | ||
if (d0 > smooth) { | ||
pts.push(m0); | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5); | ||
t0 = p0; | ||
for (var t = 0, step = 0.33; t <= 1; t += step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + t * -PI, size * 2); | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
var delta = angleDelta(angle, prev[2]); // Handle sharp corners differently | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]); | ||
if (Math.abs(delta) > PI * 0.72 && length > size * 2) { | ||
if (delta > 0) { | ||
m0 = prev; | ||
leftPts.push(m0); | ||
t0 = m0; | ||
if (d1 > smooth) { | ||
pts.unshift(m1); | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5); | ||
t1 = p1; | ||
for (var _t = 0, _step = 0.3; _t <= 1; _t += _step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + _t * -PI, size); | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
for (var _t2 = 0, _step2 = 0.3; _t2 <= 1; _t2 += _step2) { | ||
m0 = projectPoint(prev[0], prev[1], angle + TAU + _t2 * PI, size); | ||
leftPts.push(m0); | ||
t0 = m0; | ||
} | ||
m1 = prev; | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
// Project sideways | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]); | ||
if (d0 > smooth) { | ||
leftPts.push(m0); | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5); | ||
t0 = p0; | ||
} | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]); | ||
if (d1 > smooth) { | ||
rightPts.push(m1); | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5); | ||
t1 = p1; | ||
} | ||
} | ||
@@ -286,8 +331,8 @@ } | ||
pp = ip; | ||
prev = [x, y]; | ||
prev = [x, y, angle]; | ||
} | ||
pts.push(prev); | ||
pts.unshift(prev); | ||
return pts; | ||
leftPts.push(prev); | ||
rightPts.push(prev); | ||
return leftPts.concat(rightPts.reverse()); | ||
} | ||
@@ -333,7 +378,7 @@ /** | ||
for (var _iterator = _createForOfIteratorHelperLoose(poly), _step; !(_step = _iterator()).done;) { | ||
var face = _step.value; | ||
for (var _iterator = _createForOfIteratorHelperLoose(poly), _step3; !(_step3 = _iterator()).done;) { | ||
var face = _step3.value; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(face), _step2; !(_step2 = _iterator2()).done;) { | ||
var verts = _step2.value; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(face), _step4; !(_step4 = _iterator2()).done;) { | ||
var verts = _step4.value; | ||
var v0 = verts[0]; | ||
@@ -340,0 +385,0 @@ var v1 = verts[1]; |
@@ -1,2 +0,2 @@ | ||
"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,i=Math.cos,a=Math.max,u=Math.min,v=Math.sin,s=Math.atan2,l=Math.PI,f=l/2;function h(r,t,e,n){return[i(e)*n+r,v(e)*n+t]}function p(r,t,e,n,o){return void 0===o&&(o=.5),[r+(e-r)*o,t+(n-t)*o]}function d(r,t){void 0===t&&(t={});var e,n,i,a=t.streamline,u=void 0===a?.5:a,v=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),l=0,f=.01,h=v.length,p=[].concat(v[0],[0,0,0]),d=[p];if(0===h)return[];for(var c=1;c<h;c++){var m=v[c],y=m[2],g=p[0],S=p[1];i=s((n=S+(m[1]-S)*(1-u))-S,(e=g+(m[0]-g)*(1-u))-g),f=o(n-S,e-g),d.push(p=[e,n,y,i,f,l+=f])}return d.length>1&&(d[0][2]=d[1][2]),d}function c(r,t){void 0===t&&(t={});var e=t.minSize,n=void 0===e?2.5:e,o=t.maxSize,i=void 0===o?8:o,a=r.length;if(0===a)return[];var u=r[0],v=r[a-1],d=u[2]===v[2]?i:n+(i-n)*v[2],c=u===v?Math.random()*(2*l):s(v[1]-u[1],v[0]-u[0]),m=p(u[0],u[1],v[0],v[1],.5);return[h(m[0],m[1],c+f,d),h(u[0],u[1],c+l,d),h(m[0],m[1],c-f,d),h(v[0],v[1],c,d),h(m[0],m[1],c+f,d)]}function m(r,t){void 0===t&&(t={});var e=t.simulatePressure,n=void 0===e||e,o=t.pressure,i=void 0===o||o,v=t.minSize,s=void 0===v?2.5:v,l=t.maxSize,d=void 0===l?8:l,c=t.smooth,m=void 0===c?8:c,y=r.length,g=r[0],S=r[0],b=g,M=S,x=g,A=g,P=0,j=.5,z=S,O=[];if(0===y)return[];for(var I=1;I<y;I++){var k=r[I],w=k[0],Q=k[1],_=k[2],q=k[3],C=k[4];if(i){if(n){var E=u(1-C/d,1),T=u(C/d,1);_=u(1,j+T/2*(E-j))}P=a(s,u(d,s+_*(d-s)))}else P=d;g=h(w,Q,q-f,P),S=h(w,Q,q+f,P),0===I?(b=g,M=S):(Math.hypot(g[0]-b[0],g[1]-b[1])>m&&(O.push(x),x=p(b[0],b[1],g[0],g[1],.5),b=g),Math.hypot(S[0]-M[0],S[1]-M[1])>m&&(O.unshift(A),A=p(M[0],M[1],S[0],S[1],.5),M=S)),j=_,z=[w,Q]}return O.push(z),O.unshift(z),O}function y(r){return t.union([r])}exports.clipPath=y,exports.default=function(r,t){if(void 0===t&&(t={}),0===r.length)return"";var e=t.clip,o=void 0===e||e,i=t.maxSize,a=void 0===i?8:i,u=d(r,t),v=u[u.length-1][5]<2*a?c(u,t):m(u,t),s=[];if(o)for(var l,f=n(y(v));!(l=f()).done;)for(var h,g=n(l.value);!(h=g()).done;){var S=h.value,b=S[0],M=S[1];S.push(b),s.push("M "+b[0]+" "+b[1]);for(var x=1;x<S.length;x++){var A=p(b[0],b[1],M[0],M[1],.5);s.push(" Q "+b[0]+","+b[1]+" "+A[0]+","+A[1]),b=M,M=S[x+1]}}else{var P=v[0],j=v[1];v.push(P),s.push("M "+P[0]+" "+P[1]);for(var z=1;z<v.length;z++){var O=p(P[0],P[1],j[0],j[1],.5);s.push("Q "+P[0]+","+P[1]+" "+O[0]+","+O[1]),P=j,j=v[z+1]}}return s.join(" ")},exports.getShortStrokeOutlinePoints=c,exports.getStrokeOutlinePoints=m,exports.getStrokePoints=d; | ||
"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,i=Math.cos,a=Math.max,u=Math.min,v=Math.sin,s=Math.atan2,f=Math.PI,h=f/2;function l(r,t,e,n){return[i(e)*n+r,v(e)*n+t]}function p(r,t,e,n,o){return void 0===o&&(o=.5),[r+(e-r)*o,t+(n-t)*o]}function d(r,t){void 0===t&&(t={});var e,n,i,a=t.streamline,u=void 0===a?.5:a,v=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),f=0,h=.01,l=v.length,p=[].concat(v[0],[0,0,0]),d=[p];if(0===l)return[];for(var c=1;c<l;c++){var m=v[c],y=m[2],g=p[0],M=p[1];i=s((n=M+(m[1]-M)*(1-u))-M,(e=g+(m[0]-g)*(1-u))-g),h=o(n-M,e-g),d.push(p=[e,n,y,i,h,f+=h])}return d.length>1&&(d[0][2]=d[1][2]),d}function c(r,t){void 0===t&&(t={});var e=t.minSize,n=void 0===e?2.5:e,o=t.maxSize,i=void 0===o?8:o,a=r.length;if(0===a)return[];var u=r[0],v=r[a-1],d=u[2]===v[2]?i:n+(i-n)*v[2],c=u===v?Math.random()*(2*f):s(v[1]-u[1],v[0]-u[0]),m=p(u[0],u[1],v[0],v[1],.5);return[l(m[0],m[1],c+h,d),l(u[0],u[1],c+f,d),l(m[0],m[1],c-h,d),l(v[0],v[1],c,d),l(m[0],m[1],c+h,d)]}function m(r,t){void 0===t&&(t={});var e=t.simulatePressure,n=void 0===e||e,o=t.pressure,i=void 0===o||o,v=t.minSize,s=void 0===v?2.5:v,d=t.maxSize,c=void 0===d?8:d,m=t.smooth,y=void 0===m?8:m,g=r.length,M=r[0],b=r[0],S=M,x=b,A=M,P=M,j=0,z=.5,I=b,O=0,k=[],w=[];if(0===g)return[];for(var Q=1;Q<g;Q++){var _=r[Q],q=_[0],C=_[1],E=_[2],T=_[3],U=_[4];if(O+=U,i){if(n){var $=u(1-U/c,1),B=u(U/c,1);E=u(1,z+B/2*($-z))}j=a(s,u(c,s+E*(c-s)))}else j=c;if(M=l(q,C,T-h,j),b=l(q,C,T+h,j),0===Q){S=M,x=b;for(var D=0;D<=1;D+=.33)P=l(I[0],I[1],T-h+D*-f,2*j),w.push(P),x=P}else{var F=function(r,t){var e=2*Math.PI,n=(t-r)%e;return 2*n%e-n}(T,I[2]);if(Math.abs(F)>.72*f&&O>2*j)if(F>0){k.push(A=I),S=A;for(var G=0;G<=1;G+=.3)P=l(I[0],I[1],T-h+G*-f,j),w.push(P),x=P}else{for(var H=0;H<=1;H+=.3)A=l(I[0],I[1],T+h+H*f,j),k.push(A),S=A;w.push(P=I),x=P}else Math.hypot(M[0]-S[0],M[1]-S[1])>y&&(k.push(A),A=p(S[0],S[1],M[0],M[1],.5),S=M),Math.hypot(b[0]-x[0],b[1]-x[1])>y&&(w.push(P),P=p(x[0],x[1],b[0],b[1],.5),x=b)}z=E,I=[q,C,T]}return k.push(I),w.push(I),k.concat(w.reverse())}function y(r){return t.union([r])}exports.clipPath=y,exports.default=function(r,t){if(void 0===t&&(t={}),0===r.length)return"";var e=t.clip,o=void 0===e||e,i=t.maxSize,a=void 0===i?8:i,u=d(r,t),v=u[u.length-1][5]<2*a?c(u,t):m(u,t),s=[];if(o)for(var f,h=n(y(v));!(f=h()).done;)for(var l,g=n(f.value);!(l=g()).done;){var M=l.value,b=M[0],S=M[1];M.push(b),s.push("M "+b[0]+" "+b[1]);for(var x=1;x<M.length;x++){var A=p(b[0],b[1],S[0],S[1],.5);s.push(" Q "+b[0]+","+b[1]+" "+A[0]+","+A[1]),b=S,S=M[x+1]}}else{var P=v[0],j=v[1];v.push(P),s.push("M "+P[0]+" "+P[1]);for(var z=1;z<v.length;z++){var I=p(P[0],P[1],j[0],j[1],.5);s.push("Q "+P[0]+","+P[1]+" "+I[0]+","+I[1]),P=j,j=v[z+1]}}return s.join(" ")},exports.getShortStrokeOutlinePoints=c,exports.getStrokeOutlinePoints=m,exports.getStrokePoints=d; | ||
//# sourceMappingURL=perfect-freehand.cjs.production.min.js.map |
@@ -60,2 +60,12 @@ import polygonClipping from 'polygon-clipping'; | ||
function shortAngleDist(a0, a1) { | ||
var max = Math.PI * 2; | ||
var da = (a1 - a0) % max; | ||
return 2 * da % max - da; | ||
} | ||
function angleDelta(a0, a1) { | ||
return shortAngleDist(a0, a1); | ||
} | ||
function getPointBetween(x0, y0, x1, y1, d) { | ||
@@ -205,6 +215,3 @@ if (d === void 0) { | ||
smooth = _options3$smooth === void 0 ? 8 : _options3$smooth; | ||
var d0, | ||
d1, | ||
// first / last | ||
len = points.length, | ||
var len = points.length, | ||
p0 = points[0], | ||
@@ -219,3 +226,7 @@ p1 = points[0], | ||
prev = p1, | ||
pts = []; | ||
length = 0, | ||
leftPts = [], | ||
rightPts = [], | ||
d0, | ||
d1; | ||
@@ -234,3 +245,4 @@ if (len === 0) { | ||
angle = _points$i[3], | ||
distance = _points$i[4]; // Size | ||
distance = _points$i[4]; | ||
length += distance; // Size | ||
@@ -260,17 +272,50 @@ if (pressure) { | ||
t1 = p1; | ||
} else { | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]); | ||
if (d0 > smooth) { | ||
pts.push(m0); | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5); | ||
t0 = p0; | ||
for (var t = 0, step = 0.33; t <= 1; t += step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + t * -PI, size * 2); | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
var delta = angleDelta(angle, prev[2]); // Handle sharp corners differently | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]); | ||
if (Math.abs(delta) > PI * 0.72 && length > size * 2) { | ||
if (delta > 0) { | ||
m0 = prev; | ||
leftPts.push(m0); | ||
t0 = m0; | ||
if (d1 > smooth) { | ||
pts.unshift(m1); | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5); | ||
t1 = p1; | ||
for (var _t = 0, _step = 0.3; _t <= 1; _t += _step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + _t * -PI, size); | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
for (var _t2 = 0, _step2 = 0.3; _t2 <= 1; _t2 += _step2) { | ||
m0 = projectPoint(prev[0], prev[1], angle + TAU + _t2 * PI, size); | ||
leftPts.push(m0); | ||
t0 = m0; | ||
} | ||
m1 = prev; | ||
rightPts.push(m1); | ||
t1 = m1; | ||
} | ||
} else { | ||
// Project sideways | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]); | ||
if (d0 > smooth) { | ||
leftPts.push(m0); | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5); | ||
t0 = p0; | ||
} | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]); | ||
if (d1 > smooth) { | ||
rightPts.push(m1); | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5); | ||
t1 = p1; | ||
} | ||
} | ||
@@ -280,8 +325,8 @@ } | ||
pp = ip; | ||
prev = [x, y]; | ||
prev = [x, y, angle]; | ||
} | ||
pts.push(prev); | ||
pts.unshift(prev); | ||
return pts; | ||
leftPts.push(prev); | ||
rightPts.push(prev); | ||
return leftPts.concat(rightPts.reverse()); | ||
} | ||
@@ -327,7 +372,7 @@ /** | ||
for (var _iterator = _createForOfIteratorHelperLoose(poly), _step; !(_step = _iterator()).done;) { | ||
var face = _step.value; | ||
for (var _iterator = _createForOfIteratorHelperLoose(poly), _step3; !(_step3 = _iterator()).done;) { | ||
var face = _step3.value; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(face), _step2; !(_step2 = _iterator2()).done;) { | ||
var verts = _step2.value; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(face), _step4; !(_step4 = _iterator2()).done;) { | ||
var verts = _step4.value; | ||
var v0 = verts[0]; | ||
@@ -334,0 +379,0 @@ var v1 = verts[1]; |
{ | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -92,3 +92,3 @@ # Perfect Freehand | ||
export default function Example() { | ||
const [currentMark, setCurrentMark] = React.useState({}) | ||
const [currentMark, setCurrentMark] = React.useState() | ||
@@ -98,3 +98,3 @@ function handlePointerDown(e) { | ||
type: e.pointerType, | ||
point: [e.pageX, e.pageY, e.pressure], | ||
points: [[e.pageX, e.pageY, e.pressure]], | ||
}) | ||
@@ -120,8 +120,9 @@ } | ||
> | ||
<path | ||
d={getPath(currentMark, { | ||
pressure: true, | ||
simulatePressure: currentMark.type !== 'pen', | ||
})} | ||
/> | ||
{currentMark && ( | ||
<path | ||
d={getPath(currentMark.points, { | ||
simulatePressure: currentMark.type !== 'pen', | ||
})} | ||
/> | ||
)} | ||
</svg> | ||
@@ -128,0 +129,0 @@ ) |
@@ -12,2 +12,12 @@ import polygonClipping from 'polygon-clipping' | ||
function shortAngleDist(a0: number, a1: number) { | ||
var max = Math.PI * 2 | ||
var da = (a1 - a0) % max | ||
return ((2 * da) % max) - da | ||
} | ||
function angleDelta(a0: number, a1: number) { | ||
return shortAngleDist(a0, a1) | ||
} | ||
function getPointBetween( | ||
@@ -178,5 +188,3 @@ x0: number, | ||
let d0: number, | ||
d1: number, // first / last | ||
len = points.length, | ||
let len = points.length, | ||
p0 = points[0], | ||
@@ -191,3 +199,7 @@ p1 = points[0], | ||
prev = p1, | ||
pts: number[][] = [] | ||
length = 0, | ||
leftPts: number[][] = [], | ||
rightPts: number[][] = [], | ||
d0: number, | ||
d1: number | ||
@@ -203,2 +215,3 @@ if (len === 0) { | ||
let [x, y, ip, angle, distance] = points[i] | ||
length += distance | ||
@@ -227,15 +240,49 @@ // Size | ||
t1 = p1 | ||
for (let t = 0, step = 0.33; t <= 1; t += step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + t * -PI, size * 2) | ||
rightPts.push(m1) | ||
t1 = m1 | ||
} | ||
} else { | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]) | ||
if (d0 > smooth) { | ||
pts.push(m0) | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5) | ||
t0 = p0 | ||
} | ||
const delta = angleDelta(angle, prev[2]) | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]) | ||
if (d1 > smooth) { | ||
pts.unshift(m1) | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5) | ||
t1 = p1 | ||
// Handle sharp corners differently | ||
if (Math.abs(delta) > PI * 0.72 && length > size * 2) { | ||
if (delta > 0) { | ||
m0 = prev | ||
leftPts.push(m0) | ||
t0 = m0 | ||
for (let t = 0, step = 0.3; t <= 1; t += step) { | ||
m1 = projectPoint(prev[0], prev[1], angle - TAU + t * -PI, size) | ||
rightPts.push(m1) | ||
t1 = m1 | ||
} | ||
} else { | ||
for (let t = 0, step = 0.3; t <= 1; t += step) { | ||
m0 = projectPoint(prev[0], prev[1], angle + TAU + t * PI, size) | ||
leftPts.push(m0) | ||
t0 = m0 | ||
} | ||
m1 = prev | ||
rightPts.push(m1) | ||
t1 = m1 | ||
} | ||
} else { | ||
// Project sideways | ||
d0 = Math.hypot(p0[0] - t0[0], p0[1] - t0[1]) | ||
if (d0 > smooth) { | ||
leftPts.push(m0) | ||
m0 = getPointBetween(t0[0], t0[1], p0[0], p0[1], 0.5) | ||
t0 = p0 | ||
} | ||
d1 = Math.hypot(p1[0] - t1[0], p1[1] - t1[1]) | ||
if (d1 > smooth) { | ||
rightPts.push(m1) | ||
m1 = getPointBetween(t1[0], t1[1], p1[0], p1[1], 0.5) | ||
t1 = p1 | ||
} | ||
} | ||
@@ -245,9 +292,9 @@ } | ||
pp = ip | ||
prev = [x, y] | ||
prev = [x, y, angle] | ||
} | ||
pts.push(prev) | ||
pts.unshift(prev) | ||
leftPts.push(prev) | ||
rightPts.push(prev) | ||
return pts | ||
return leftPts.concat(rightPts.reverse()) | ||
} | ||
@@ -254,0 +301,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
105534
1080
151