poly-extrude 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/poly-extrude.js +132 -62
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +132 -62
- package/package.json +3 -2
- package/src/polyline.js +100 -20
package/dist/poly-extrude.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/*!
|
2
|
-
* poly-extrude v0.
|
2
|
+
* poly-extrude v0.4.0
|
3
3
|
*/
|
4
|
-
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).polyextrude=t.polyextrude||{})}(this,(function(t){"use strict";var n={exports:{}};function r(t,n,r){r=r||2;var e,o,h,a,u,x,p,f=n&&n.length,y=f?n[0]*r:t.length,d=i(t,0,y,r,!0),g=[];if(!d||d.next===d.prev)return g;if(f&&(d=function(t,n,r,e){var s,o,h,a=[];for(s=0,o=n.length;s<o;s++)(h=i(t,n[s]*e,s<o-1?n[s+1]*e:t.length,e,!1))===h.next&&(h.steiner=!0),a.push(v(h));for(a.sort(c),s=0;s<a.length;s++)r=l(a[s],r);return r}(t,n,d,r)),t.length>80*r){e=h=t[0],o=a=t[1];for(var z=r;z<y;z+=r)(u=t[z])<e&&(e=u),(x=t[z+1])<o&&(o=x),u>h&&(h=u),x>a&&(a=x);p=0!==(p=Math.max(h-e,a-o))?32767/p:0}return s(d,g,r,e,o,p,0),g}function i(t,n,r,i,e){var s,o;if(e===V(t,n,r,i)>0)for(s=n;s<r;s+=i)o=P(s,t[s],t[s+1],o);else for(s=r-i;s>=n;s-=i)o=P(s,t[s],t[s+1],o);return o&&g(o,o.next)&&(S(o),o=o.next),o}function e(t,n){if(!t)return t;n||(n=t);var r,i=t;do{if(r=!1,i.steiner||!g(i,i.next)&&0!==d(i.prev,i,i.next))i=i.next;else{if(S(i),(i=n=i.prev)===i.next)break;r=!0}}while(r||i!==n);return n}function s(t,n,r,i,c,l,x){if(t){!x&&l&&function(t,n,r,i){var e=t;do{0===e.z&&(e.z=p(e.x,e.y,n,r,i)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next}while(e!==t);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,r,i,e,s,o,h,a,u=1;do{for(r=t,t=null,s=null,o=0;r;){for(o++,i=r,h=0,n=0;n<u&&(h++,i=i.nextZ);n++);for(a=u;h>0||a>0&&i;)0!==h&&(0===a||!i||r.z<=i.z)?(e=r,r=r.nextZ,h--):(e=i,i=i.nextZ,a--),s?s.nextZ=e:t=e,e.prevZ=s,s=e;r=i}s.nextZ=null,u*=2}while(o>1)}(e)}(t,i,c,l);for(var v,f,y=t;t.prev!==t.next;)if(v=t.prev,f=t.next,l?h(t,i,c,l):o(t))n.push(v.i/r|0),n.push(t.i/r|0),n.push(f.i/r|0),S(t),t=f.next,y=f.next;else if((t=f)===y){x?1===x?s(t=a(e(t),n,r),n,r,i,c,l,2):2===x&&u(t,n,r,i,c,l):s(e(t),n,r,i,c,l,1);break}}}function o(t){var n=t.prev,r=t,i=t.next;if(d(n,r,i)>=0)return!1;for(var e=n.x,s=r.x,o=i.x,h=n.y,a=r.y,u=i.y,c=e<s?e<o?e:o:s<o?s:o,l=h<a?h<u?h:u:a<u?a:u,x=e>s?e>o?e:o:s>o?s:o,p=h>a?h>u?h:u:a>u?a:u,v=i.next;v!==n;){if(v.x>=c&&v.x<=x&&v.y>=l&&v.y<=p&&f(e,h,s,a,o,u,v.x,v.y)&&d(v.prev,v,v.next)>=0)return!1;v=v.next}return!0}function h(t,n,r,i){var e=t.prev,s=t,o=t.next;if(d(e,s,o)>=0)return!1;for(var h=e.x,a=s.x,u=o.x,c=e.y,l=s.y,x=o.y,v=h<a?h<u?h:u:a<u?a:u,y=c<l?c<x?c:x:l<x?l:x,g=h>a?h>u?h:u:a>u?a:u,z=c>l?c>x?c:x:l>x?l:x,m=p(v,y,n,r,i),M=p(g,z,n,r,i),w=t.prevZ,b=t.nextZ;w&&w.z>=m&&b&&b.z<=M;){if(w.x>=v&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,b.x>=v&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;w&&w.z>=m;){if(w.x>=v&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;b&&b.z<=M;){if(b.x>=v&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function a(t,n,r){var i=t;do{var s=i.prev,o=i.next.next;!g(s,o)&&z(s,i,i.next,o)&&w(s,o)&&w(o,s)&&(n.push(s.i/r|0),n.push(i.i/r|0),n.push(o.i/r|0),S(i),S(i.next),i=t=o),i=i.next}while(i!==t);return e(i)}function u(t,n,r,i,o,h){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&y(a,u)){var c=b(a,u);return a=e(a,a.next),c=e(c,c.next),s(a,n,r,i,o,h,0),void s(c,n,r,i,o,h,0)}u=u.next}a=a.next}while(a!==t)}function c(t,n){return t.x-n.x}function l(t,n){var r=function(t,n){var r,i=n,e=t.x,s=t.y,o=-1/0;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){var h=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(h<=e&&h>o&&(o=h,r=i.x<i.next.x?i:i.next,h===e))return r}i=i.next}while(i!==n);if(!r)return null;var a,u=r,c=r.x,l=r.y,p=1/0;i=r;do{e>=i.x&&i.x>=c&&e!==i.x&&f(s<l?e:o,s,c,l,s<l?o:e,s,i.x,i.y)&&(a=Math.abs(s-i.y)/(e-i.x),w(i,t)&&(a<p||a===p&&(i.x>r.x||i.x===r.x&&x(r,i)))&&(r=i,p=a)),i=i.next}while(i!==u);return r}(t,n);if(!r)return n;var i=b(r,t);return e(i,i.next),e(r,r.next)}function x(t,n){return d(t.prev,t,n.prev)<0&&d(n.next,t,t.next)<0}function p(t,n,r,i,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*e|0)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=(n-i)*e|0)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function v(t){var n=t,r=t;do{(n.x<r.x||n.x===r.x&&n.y<r.y)&&(r=n),n=n.next}while(n!==t);return r}function f(t,n,r,i,e,s,o,h){return(e-o)*(n-h)>=(t-o)*(s-h)&&(t-o)*(i-h)>=(r-o)*(n-h)&&(r-o)*(s-h)>=(e-o)*(i-h)}function y(t,n){return t.next.i!==n.i&&t.prev.i!==n.i&&!function(t,n){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==n.i&&r.next.i!==n.i&&z(r,r.next,t,n))return!0;r=r.next}while(r!==t);return!1}(t,n)&&(w(t,n)&&w(n,t)&&function(t,n){var r=t,i=!1,e=(t.x+n.x)/2,s=(t.y+n.y)/2;do{r.y>s!=r.next.y>s&&r.next.y!==r.y&&e<(r.next.x-r.x)*(s-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,n)&&(d(t.prev,t,n.prev)||d(t,n.prev,n))||g(t,n)&&d(t.prev,t,t.next)>0&&d(n.prev,n,n.next)>0)}function d(t,n,r){return(n.y-t.y)*(r.x-n.x)-(n.x-t.x)*(r.y-n.y)}function g(t,n){return t.x===n.x&&t.y===n.y}function z(t,n,r,i){var e=M(d(t,n,r)),s=M(d(t,n,i)),o=M(d(r,i,t)),h=M(d(r,i,n));return e!==s&&o!==h||(!(0!==e||!m(t,r,n))||(!(0!==s||!m(t,i,n))||(!(0!==o||!m(r,t,i))||!(0!==h||!m(r,n,i)))))}function m(t,n,r){return n.x<=Math.max(t.x,r.x)&&n.x>=Math.min(t.x,r.x)&&n.y<=Math.max(t.y,r.y)&&n.y>=Math.min(t.y,r.y)}function M(t){return t>0?1:t<0?-1:0}function w(t,n){return d(t.prev,t,t.next)<0?d(t,n,t.next)>=0&&d(t,t.prev,n)>=0:d(t,n,t.prev)<0||d(t,t.next,n)<0}function b(t,n){var r=new A(t.i,t.x,t.y),i=new A(n.i,n.x,n.y),e=t.next,s=n.prev;return t.next=n,n.prev=t,r.next=e,e.prev=r,i.next=r,r.prev=i,s.next=i,i.prev=s,i}function P(t,n,r,i){var e=new A(t,n,r);return i?(e.next=i.next,e.prev=i,i.next.prev=e,i.next=e):(e.prev=e,e.next=e),e}function S(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function A(t,n,r){this.i=t,this.x=n,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function V(t,n,r,i){for(var e=0,s=n,o=r-i;s<r;s+=i)e+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return e}n.exports=r,n.exports.default=r,r.deviation=function(t,n,r,i){var e=n&&n.length,s=e?n[0]*r:t.length,o=Math.abs(V(t,0,s,r));if(e)for(var h=0,a=n.length;h<a;h++){var u=n[h]*r,c=h<a-1?n[h+1]*r:t.length;o-=Math.abs(V(t,u,c,r))}var l=0;for(h=0;h<i.length;h+=3){var x=i[h]*r,p=i[h+1]*r,v=i[h+2]*r;l+=Math.abs((t[x]-t[v])*(t[p+1]-t[x+1])-(t[x]-t[p])*(t[v+1]-t[x+1]))}return 0===o&&0===l?0:Math.abs((l-o)/o)},r.flatten=function(t){for(var n=t[0][0].length,r={vertices:[],holes:[],dimensions:n},i=0,e=0;e<t.length;e++){for(var s=0;s<t[e].length;s++)for(var o=0;o<n;o++)r.vertices.push(t[e][s][o]);e>0&&(i+=t[e-1].length,r.holes.push(i))}return r};var Z=n.exports;function _(t){for(var n,r,i=0,e=1,s=t.length;e<s;)n=r||t[0],i+=((r=t[e])[0]-n[0])*(r[1]+n[1]),e++;return i>0}function L(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t}function F(t,n){var r=n[0],i=n[1],e=n[2],s=Math.sqrt(r*r+i*i+e*e)||1;return t[0]=r/s,t[1]=i/s,t[2]=e/s,t}function O(t,n){function r(t,n,r,i){t[0]=n,t[1]=r,t[2]=i}for(var i,e,s,o,h,a,u,c,l,x=[],p=[],v=[],f=[],y=[],d=[],g=t.length,z=new Float32Array(n.length),m=0;m<g;){var M=3*t[m],w=3*t[m+1],b=3*t[m+2];r(x,n[M],n[M+1],n[M+2]),r(p,n[w],n[w+1],n[w+2]),r(v,n[b],n[b+1],n[b+2]),L(y,v,p),L(f,x,p),i=d,s=f,o=void 0,h=void 0,a=void 0,u=void 0,c=void 0,l=void 0,o=(e=y)[0],h=e[1],a=e[2],u=s[0],c=s[1],l=s[2],i[0]=h*l-a*c,i[1]=a*u-o*l,i[2]=o*c-h*u;for(var P=0;P<3;P++)z[M+P]+=d[P],z[w+P]+=d[P],z[b+P]+=d[P];m+=3}for(var S=0,A=z.length;S<A;)r(d,z[S],z[S+1],z[S+2]),F(d,d),z[S]=d[0]||0,z[S+1]=d[1]||0,z[S+2]=d[2]||0,S+=3;return z}function I(t){if(1===t.length)return{position:t[0].position,normal:t[0].normal,uv:t[0].uv,indices:t[0].indices,results:t};for(var n=0,r=0,i=0,e=t.length;i<e;i++){var s=t[i],o=s.position,h=s.indices;n+=o.length,r+=h.length}for(var a={position:new Float32Array(n),normal:new Float32Array(n),uv:new Float32Array(n/3*2),indices:new Uint32Array(r),results:t},u=0,c=0,l=0,x=0,p=0,v=t.length;p<v;p++){var f=t[p],y=f.position,d=f.indices,g=f.normal,z=f.uv;a.position.set(y,u),a.normal.set(g,u),a.uv.set(z,x);for(var m=0,M=d.length;m<M;){var w=d[m]+c;a.indices[l]=w,l++,m++}x+=z.length,u+=y.length,c+=y.length/3}return a}function q(t){return 180*t/Math.PI}function U(t){return t/180*Math.PI}function j(t,n,r,i,e,s){var o=3*r,h=3*i,a=3*e,u=3*s,c=n[o],l=n[o+1],x=n[o+2],p=n[h],v=n[h+1],f=n[h+2],y=n[a],d=n[a+1],g=n[a+2],z=n[u],m=n[u+1],M=n[u+2];Math.abs(l-v)<Math.abs(c-p)?(t.push(c,1-x),t.push(p,1-f),t.push(y,1-g),t.push(z,1-M)):(t.push(l,1-x),t.push(v,1-f),t.push(d,1-g),t.push(m,1-M))}function C(t){T(t)||t.push(t[0])}function T(t){var n=t.length,r=t[0],i=r[0],e=r[1],s=t[n-1],o=s[0],h=s[1];return i===o&&e===h}var k={x:0,y:0},B={x:0,y:0};function R(t,n){for(var r=0,i=n.lineWidth/2,e=[],s=[],o=[],h=t.length,a=0;a<h-1;){var u=t[a],c=t[a+1],l=c[1]-u[1],x=c[0]-u[0],p=0,v=q(Math.atan(l/x));if(r=v,0===a)p=v,p-=90;else{var f=t[a-1];k.x=f[0]-u[0],k.y=f[1]-u[1],B.x=c[0]-u[0],B.y=c[1]-u[1],p=v-N(k,B)/2}var y=E(U(p),i,u),d=y[0],g=y[1];e.push(d,g),W(d,u,c)?(s.push(d),o.push(g)):(s.push(g),o.push(d)),a++}var z=r,m=U(z-=90),M=t[h-2],w=t[h-1],b=E(m,i,w),P=b[0],S=b[1];return e.push(P,S),W(P,M,w)?(s.push(P),o.push(S)):(s.push(S),o.push(P)),{offsetPoints:e,leftPoints:s,rightPoints:o}}function E(t,n,r){var i=r[0],e=r[1],s=r[2]||0,o=[i+Math.cos(t)*n,e+Math.sin(t)*n,s],h=t+=Math.PI;return[o,[i+Math.cos(h)*n,e+Math.sin(h)*n,s]]}var N=function(t,n){var r=t.x,i=t.y,e=n.x,s=n.y,o=r*e+i*s,h=r*s-i*e;return(Math.atan2(h,o)/Math.PI*180+360)%360};function W(t,n,r){var i=n[0],e=n[1],s=r[0],o=r[1];return(e-o)*t[0]+(s-i)*t[1]+i*o-s*e>0}var D=function(){function t(t,n,r){void 0===t&&(t=0),void 0===n&&(n=0),void 0===r&&(r=0),this.x=t,this.y=n,this.z=r}var n=t.prototype;return n.set=function(t,n,r){return void 0===r&&(r=this.z),this.x=t,this.y=n,this.z=r,this},n.clone=function(){return new this.constructor(this.x,this.y,this.z)},n.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},n.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},n.addScalar=function(t){return this.x+=t,this.y+=t,this.z+=t,this},n.addVectors=function(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this},n.addScaledVector=function(t,n){return this.x+=t.x*n,this.y+=t.y*n,this.z+=t.z*n,this},n.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},n.subScalar=function(t){return this.x-=t,this.y-=t,this.z-=t,this},n.subVectors=function(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this},n.multiply=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},n.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},n.multiplyVectors=function(t,n){return this.x=t.x*n.x,this.y=t.y*n.y,this.z=t.z*n.z,this},n.applyMatrix4=function(t){var n=this.x,r=this.y,i=this.z,e=t.elements,s=1/(e[3]*n+e[7]*r+e[11]*i+e[15]);return this.x=(e[0]*n+e[4]*r+e[8]*i+e[12])*s,this.y=(e[1]*n+e[5]*r+e[9]*i+e[13])*s,this.z=(e[2]*n+e[6]*r+e[10]*i+e[14])*s,this},n.divide=function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},n.divideScalar=function(t){return this.multiplyScalar(1/t)},n.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},n.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},n.clamp=function(t,n){return this.x=Math.max(t.x,Math.min(n.x,this.x)),this.y=Math.max(t.y,Math.min(n.y,this.y)),this.z=Math.max(t.z,Math.min(n.z,this.z)),this},n.clampScalar=function(t,n){return this.x=Math.max(t,Math.min(n,this.x)),this.y=Math.max(t,Math.min(n,this.y)),this.z=Math.max(t,Math.min(n,this.z)),this},n.clampLength=function(t,n){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(n,r)))},n.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.lengthSq=function(){return this.x*this.x+this.y*this.y+this.z*this.z},n.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.normalize=function(){return this.divideScalar(this.length()||1)},n.setLength=function(t){return this.normalize().multiplyScalar(t)},n.lerp=function(t,n){return this.x+=(t.x-this.x)*n,this.y+=(t.y-this.y)*n,this.z+=(t.z-this.z)*n,this},n.lerpVectors=function(t,n,r){return this.x=t.x+(n.x-t.x)*r,this.y=t.y+(n.y-t.y)*r,this.z=t.z+(n.z-t.z)*r,this},n.cross=function(t){return this.crossVectors(this,t)},n.crossVectors=function(t,n){var r=t.x,i=t.y,e=t.z,s=n.x,o=n.y,h=n.z;return this.x=i*h-e*o,this.y=e*s-r*h,this.z=r*o-i*s,this},n.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},n.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},n.fromArray=function(t,n){return void 0===n&&(n=0),this.x=t[n],this.y=t[n+1],this.z=t[n+2],this},n.random=function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this},t}(),Q=function(){function t(){this.pos=new D,this.dir=new D,this.right=new D,this.up=new D,this.dist=0,this.widthScale=1,this.sharp=!1}var n=t.prototype;return n.lerpPathPoints=function(t,n,r){this.pos.lerpVectors(t.pos,n.pos,r),this.dir.lerpVectors(t.dir,n.dir,r),this.up.lerpVectors(t.up,n.up,r),this.right.lerpVectors(t.right,n.right,r),this.dist=(n.dist-t.dist)*r+t.dist,this.widthScale=(n.widthScale-t.widthScale)*r+t.widthScale},n.copy=function(t){this.pos.copy(t.pos),this.dir.copy(t.dir),this.up.copy(t.up),this.right.copy(t.right),this.dist=t.dist,this.widthScale=t.widthScale},t}(),H=function(){function t(t,n,r,i,e,s,o,h,a,u,c,l,x,p,v,f){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,n,r,i,e,s,o,h,a,u,c,l,x,p,v,f)}var n=t.prototype;return n.set=function(t,n,r,i,e,s,o,h,a,u,c,l,x,p,v,f){var y=this.elements;return y[0]=t,y[4]=n,y[8]=r,y[12]=i,y[1]=e,y[5]=s,y[9]=o,y[13]=h,y[2]=a,y[6]=u,y[10]=c,y[14]=l,y[3]=x,y[7]=p,y[11]=v,y[15]=f,this},n.multiply=function(t){return this.multiplyMatrices(this,t)},n.makeRotationAxis=function(t,n){var r=Math.cos(n),i=Math.sin(n),e=1-r,s=t.x,o=t.y,h=t.z,a=e*s,u=e*o;return this.set(a*s+r,a*o-i*h,a*h+i*o,0,a*o+i*h,u*o+r,u*h-i*s,0,a*h-i*o,u*h+i*s,e*h*h+r,0,0,0,0,1),this},n.equals=function(t){for(var n=this.elements,r=t.elements,i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0},t}();function X(t,n){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},X(t,n)}function G(t,n,r,i){return function(t,n){var r=1-t;return r*r*n}(t,n)+function(t,n){return 2*(1-t)*t*n}(t,r)+function(t,n){return t*t*n}(t,i)}var J=function(t){var n,r;function i(n,r,i){var e;return void 0===n&&(n=new D),void 0===r&&(r=new D),void 0===i&&(i=new D),(e=t.call(this)||this).isQuadraticBezierCurve3=!0,e.type="QuadraticBezierCurve3",e.v0=n,e.v1=r,e.v2=i,e}return r=t,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,X(n,r),i.prototype.getPoint=function(t,n){void 0===n&&(n=new D);var r=n,i=this.v0,e=this.v1,s=this.v2;return r.set(G(t,i.x,e.x,s.x),G(t,i.y,e.y,s.y),G(t,i.z,e.z,s.z)),r},i}(function(){function t(){this.type="Curve",this.arcLengthDivisions=200}var n=t.prototype;return n.getPoint=function(){return console.warn("THREE.Curve: .getPoint() not implemented."),null},n.getPointAt=function(t,n){var r=this.getUtoTmapping(t);return this.getPoint(r,n)},n.getPoints=function(t){void 0===t&&(t=5);for(var n=[],r=0;r<=t;r++)n.push(this.getPoint(r/t));return n},n.getLength=function(){var t=this.getLengths();return t[t.length-1]},n.getLengths=function(t){if(void 0===t&&(t=this.arcLengthDivisions),this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var n,r=[],i=this.getPoint(0),e=0;r.push(0);for(var s=1;s<=t;s++)e+=(n=this.getPoint(s/t)).distanceTo(i),r.push(e),i=n;return this.cacheArcLengths=r,r},n.getUtoTmapping=function(t,n){var r,i=this.getLengths(),e=0,s=i.length;r=n||t*i[s-1];for(var o,h=0,a=s-1;h<=a;)if((o=i[e=Math.floor(h+(a-h)/2)]-r)<0)h=e+1;else{if(!(o>0)){a=e;break}a=e-1}if(i[e=a]===r)return e/(s-1);var u=i[e];return(e+(r-u)/(i[e+1]-u))/(s-1)},t}()),K=new D,Y=new D,$=new D,tt=new H,nt=new J;var rt=function(){function t(){this.array=[],this.count=0}var n=t.prototype;return n.set=function(t,n,r,i,e){if(void 0===n&&(n=.1),void 0===r&&(r=10),void 0===i&&(i=null),void 0===e&&(e=!1),(t=t.slice(0)).length<2)return console.warn("PathPointList: points length less than 2."),void(this.count=0);e&&!t[0].equals(t[t.length-1])&&t.push((new D).copy(t[0]));for(var s=0,o=t.length;s<o;s++)if(0===s)this._start(t[s],t[s+1],i);else if(s===o-1)if(e){this._corner(t[s],t[1],n,r,i);var h=this.array[0].dist;this.array[0].copy(this.array[this.count-1]),this.array[0].dist=h}else this._end(t[s]);else this._corner(t[s],t[s+1],n,r,i)},n.distance=function(){return this.count>0?this.array[this.count-1].dist:0},n._getByIndex=function(t){return this.array[t]||(this.array[t]=new Q),this.array[t]},n._start=function(t,n,r){this.count=0;var i=this._getByIndex(this.count);if(i.pos.copy(t),i.dir.subVectors(n,t),r)i.up.copy(r);else{var e=Number.MAX_VALUE,s=Math.abs(i.dir.x),o=Math.abs(i.dir.y),h=Math.abs(i.dir.z);s<e&&(e=s,i.up.set(1,0,0)),o<e&&(e=o,i.up.set(0,1,0)),h<e&&i.up.set(0,0,1)}i.right.crossVectors(i.dir,i.up).normalize(),i.up.crossVectors(i.right,i.dir).normalize(),i.dist=0,i.widthScale=1,i.sharp=!1,i.dir.normalize(),this.count++},n._end=function(t){var n=this.array[this.count-1],r=this._getByIndex(this.count);r.pos.copy(t),r.dir.subVectors(t,n.pos);var i=r.dir.length();r.dir.normalize(),r.up.copy(n.up);var e=K.crossVectors(n.dir,r.dir);if(e.length()>Number.EPSILON){e.normalize();var s=Math.acos(Math.min(Math.max(n.dir.dot(r.dir),-1),1));r.up.applyMatrix4(tt.makeRotationAxis(e,s))}r.right.crossVectors(r.dir,r.up).normalize(),r.dist=n.dist+i,r.widthScale=1,r.sharp=!1,this.count++},n._corner=function(t,n,r,i,e){if(r>0&&i>0){for(var s=function(t,n,r,i,e,s){var o=K.subVectors(n,t),h=Y.subVectors(r,n),a=o.length(),u=h.length();o.normalize(),h.normalize();var c=Math.min(.999999*(e?a/2:a),i);s.v0.copy(n).sub(o.multiplyScalar(c)),s.v1.copy(n);var l=Math.min(u/2*.999999,i);return s.v2.copy(n).add(h.multiplyScalar(l)),s}(this.array[this.count-1].pos,t,n,r,this.count-1==0,nt),o=s.getPoints(i),h=0;h<i;h++)this._sharpCorner(o[h],o[h+1],e,0===h?1:0);o[i].equals(n)||this._sharpCorner(o[i],n,e,2)}else this._sharpCorner(t,n,e,0,!0)},n._sharpCorner=function(t,n,r,i,e){void 0===i&&(i=0),void 0===e&&(e=!1);var s=this.array[this.count-1],o=this._getByIndex(this.count),h=K.subVectors(t,s.pos),a=Y.subVectors(n,t),u=h.length();if(h.normalize(),a.normalize(),o.pos.copy(t),1===i?o.dir.copy(h):2===i?o.dir.copy(a):(o.dir.addVectors(h,a),o.dir.normalize()),r)1===o.dir.dot(r)?o.right.crossVectors(a,r).normalize():o.right.crossVectors(o.dir,r).normalize(),o.up.crossVectors(o.right,o.dir).normalize();else{o.up.copy(s.up);var c=$.crossVectors(s.dir,o.dir);if(c.length()>Number.EPSILON){c.normalize();var l=Math.acos(Math.min(Math.max(s.dir.dot(o.dir),-1),1));o.up.applyMatrix4(tt.makeRotationAxis(c,l))}o.right.crossVectors(o.dir,o.up).normalize()}o.dist=s.dist+u;var x=h.dot(a);o.widthScale=Math.min(1/Math.sqrt((1+x)/2),1.415)||1,o.sharp=Math.abs(x-1)>.05&&e,this.count++},t}(),it=new D(0,0,1);t.cylinder=function(t,n){void 0===n&&(n={}),n=Object.assign({},{radius:1,height:2,radialSegments:6},n);for(var r=Math.round(Math.max(4,n.radialSegments)),i=n,e=i.radius,s=i.height,o=360/r/360*Math.PI*2,h=r+1,a=new Float32Array(3*h*2),u=t[0],c=t[1],l=0,x=0,p=3*h,v=2*h,f=[],y=[],d=-1;d<r;d++){var g=o*d,z=Math.cos(g)*e+u,m=Math.sin(g)*e+c;a[l]=z,a[l+1]=m,a[l+2]=0,a[l+p]=z,a[l+1+p]=m,a[l+2+p]=s;var M,w;M=.5+z/e/2,w=.5+m/e/2,y[x]=M,y[x+1]=w,y[x+v]=M,y[x+1+v]=w,l+=3,x+=2,d>1&&f.push(0,d-1,d)}a[l-=3]=a[0],a[l+1]=a[1],a[l+2]=a[2];var b=a.length;a[b-3]=a[0],a[b-2]=a[1],a[b-1]=s;for(var P=f.length,S=0;S<P;S++){var A=f[S];f.push(A+h)}var V=new Float32Array(2*(3*h*2-6)),Z=-1;l=2*h,x=0;for(var _=0,L=a.length/2;_<L-3;_+=3){var F=a[_],I=a[_+1],q=a[_+3],U=a[_+4];V[++Z]=F,V[++Z]=I,V[++Z]=s,V[++Z]=q,V[++Z]=U,V[++Z]=s,V[++Z]=F,V[++Z]=I,V[++Z]=0,V[++Z]=q,V[++Z]=U,V[++Z]=0;var j=l+2,C=l+3,T=l,k=l+1;f.push(T,j,k,j,C,k),l+=4;var B=x/h,R=(x+1)/h;y.push(B,s/e/2,R,s/e/2,B,0,R,0),x++}var E=new Float32Array(a.length+V.length);E.set(a,0),E.set(V,a.length);var N=O(f,E);return{points:a,indices:new Uint32Array(f),position:E,normal:N,uv:new Float32Array(y)}},t.expandLine=R,t.expandPaths=function(t,n){n=Object.assign({},{lineWidth:1,cornerRadius:0,cornerSplit:10},n);var r=t.map((function(t){var r=t.map((function(t){var n=t[0],r=t[1],i=t[2];return new D(n,r,i||0)})),i=new rt;i.set(r,n.cornerRadius,n.cornerSplit,it);var e=function(t,n){var r=n.lineWidth||.1,i=1,e=r/2,s=r,o=t.distance(),h=i*o;if(0===o)return null;var a,u=e/s,c=0,l=[],x=[],p=[],v=[],f=0,y=new D,d=new D,g=new D,z=new D,m=new D,M=new D;function w(t){var n=0===l.length,r=t.sharp&&!n,i=t.dist/s,o=t.dir,h=t.up,a=t.right;if(y.copy(a).multiplyScalar(e*t.widthScale),d.copy(a).multiplyScalar(-e*t.widthScale),y.add(t.pos),d.add(t.pos),r){g.fromArray(l,l.length-6).sub(d),z.fromArray(l,l.length-3).sub(y);var w,b,P=g.length()-z.length();P>0?(w=g,b=d):(w=z,b=y),m.copy(w).setLength(Math.abs(P)).add(b);var S=M.copy(b).sub(m).normalize().dot(o)*M.copy(b).sub(m).length()*2;M.copy(o).setLength(S).add(m),P>0?(l.push(m.x,m.y,m.z,y.x,y.y,y.z,d.x,d.y,d.z,y.x,y.y,y.z,M.x,M.y,M.z,y.x,y.y,y.z),f+=6,v.push(f-6,f-8,f-7,f-6,f-7,f-5,f-4,f-6,f-5,f-2,f-4,f-1),c+=12):(l.push(d.x,d.y,d.z,m.x,m.y,m.z,d.x,d.y,d.z,y.x,y.y,y.z,d.x,d.y,d.z,M.x,M.y,M.z),f+=6,v.push(f-6,f-8,f-7,f-6,f-7,f-5,f-6,f-5,f-3,f-2,f-3,f-1),c+=12),x.push(h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z),p.push(i-u,0,i-u,1,i,0,i,1,i+u,0,i+u,1)}else l.push(d.x,d.y,d.z,y.x,y.y,y.z),x.push(h.x,h.y,h.z,h.x,h.y,h.z),p.push(i,0,i,1),f+=2,n||(v.push(f-2,f-4,f-3,f-2,f-3,f-1),c+=6)}if(h>0)for(var b=0;b<t.count;b++){var P=t.array[b];if(P.dist>h){var S=t.array[b-1];a=new Q;var A=(h-S.dist)/(P.dist-S.dist);a.lerpPathPoints(S,P,A),w(a);break}w(P)}else a=t.array[0];return{points:l,normal:x,uvs:p,index:v,count:c}}(i,n);return e.line=t,e.position=new Float32Array(e.points),e.indices=new Uint32Array(e.index),e.uv=new Float32Array(e.uvs),e.normal=new Float32Array(e.normal),e})),i=I(r);return i.lines=t,i},t.extrudePolygons=function(t,n){n=Object.assign({},{depth:2},n);var r=t.map((function(t){for(var r=0,i=t.length;r<i;r++){var e=t[r];C(e),0===r?_(e)||(t[r]=e.reverse()):_(e)&&(t[r]=e.reverse()),T(e)&&e.splice(e.length-1,1)}var s=function(t,n){for(var r=function(t){var n=0,r=0,i=t.length;for(;r<i;)n+=t[r].length,r++;return n}(t),i=t.length,e=[],s=new Float32Array(2*r),o=[],h=[],a=3*r,u=2*r,c=n.depth,l=0,x=0,p=0,v=0;v<i;v++){var f=t[v];v>0&&e.push(l/2);for(var y=0,d=f.length;y<d;){var g=f[y],z=g[0],m=g[1];s[l++]=z,s[l++]=m,o[x]=z,o[x+1]=m,o[x+2]=c,o[a+x]=z,o[a+x+1]=m,o[a+x+2]=0,h[p]=z,h[p+1]=m,h[u+p]=z,h[u+p+1]=m,x+=3,p+=2,y++}}return{flatVertices:s,holes:e,points:o,count:r,uvs:h}}(t,n);return s.polygon=t,function(t,n){for(var r=[],i=t.count,e=0,s=n.length;e<s;e+=3){var o=n[e],h=n[e+1],a=n[e+2];r[e]=o,r[e+1]=h,r[e+2]=a;var u=s+e,c=i+o,l=i+h,x=i+a;r[u]=c,r[u+1]=l,r[u+2]=x}t.index=r}(s,Z(s.flatVertices,s.holes,2)),function(t,n){for(var r=t.points,i=t.index,e=t.polygon,s=t.uvs,o=n.depth,h=0,a=e.length;h<a;h++)for(var u=e[h],c=0,l=u.length;c<l;){var x=u[c],p=u[c+1];c===l-1&&(p=u[0]);var v=r.length/3,f=x[0],y=x[1],d=p[0],g=p[1];r.push(f,y,o,d,g,o,f,y,0,d,g,0);var z=v+2,m=v+3,M=v,w=v+1;i.push(z,M,m,M,w,m),j(s,r,z,m,M,w),c++}}(s,n),s.position=new Float32Array(s.points),s.indices=new Uint32Array(s.index),s.uv=new Float32Array(s.uvs),s.normal=O(s.indices,s.position),s})),i=I(r);return i.polygons=t,i},t.extrudePolylines=function(t,n){n=Object.assign({},{depth:2,lineWidth:1},n);var r=t.map((function(t){var r=R(t,n);return r.line=t,function(t,n){var r=n.depth,i=[],e=[],s=[],o=t.leftPoints,h=t.rightPoints,a=0,u=o.length;for(;a<u;){var c=3*a,l=o[a],x=l[0],p=l[1],v=l[2];i[c]=x,i[c+1]=p,i[c+2]=r+v;var f=h[a],y=f[0],d=f[1],g=f[2],z=3*u+c;i[z]=y,i[z+1]=d,i[z+2]=r+g;var m=2*u*3+c;i[m]=x,i[m+1]=p,i[m+2]=v;var M=2*u*3+3*u+c;i[M]=y,i[M+1]=d,i[M+2]=g,a++}a=0,u=i.length;for(;a<u;){var w=i[a],b=i[a+1];s.push(w,b),a+=3}a=0,u=o.length;for(;a<u-1;){var P=a,S=a+1,A=P+u,V=S+u;e.push(P,A,S),e.push(A,V,S);var Z=a+2*u,_=Z+1,L=Z+u,F=_+u;e.push(Z,L,_),e.push(L,F,_),a++}t.index=e,t.points=i,t.uvs=s}(r,n),function(t,n){var r=t.points,i=t.index,e=t.leftPoints,s=t.rightPoints,o=t.uvs,h=n.depth,a=[e,s];function u(t,n){var e=r.length/3;r.push(t[0],t[1],h+t[2],n[0],n[1],h+n[2],t[0],t[1],t[2],n[0],n[1],n[2]);var s=e+2,a=e+3,u=e,c=e+1;i.push(s,u,a,u,c,a),j(o,r,s,a,u,c)}for(var c=0,l=a.length;c<l;c++){var x=a[c];c>0&&(x=(x=x.map((function(t){return t}))).reverse());for(var p=0,v=x.length-1;p<v;){u(x[p],x[p+1]),p++}}for(var f=e.length,y=[s[0],e[0],e[f-1],s[f-1]],d=0;d<y.length;d+=2){u(y[d],y[d+1])}}(r,n),r.position=new Float32Array(r.points),r.indices=new Uint32Array(r.index),r.uv=new Float32Array(r.uvs),r.normal=O(r.indices,r.position),r})),i=I(r);return i.lines=t,i},Object.defineProperty(t,"__esModule",{value:!0})}));
|
4
|
+
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).polyextrude=t.polyextrude||{})}(this,(function(t){"use strict";var n={exports:{}};function r(t,n,r){r=r||2;var e,o,h,a,u,x,v,f=n&&n.length,y=f?n[0]*r:t.length,d=i(t,0,y,r,!0),g=[];if(!d||d.next===d.prev)return g;if(f&&(d=function(t,n,r,e){var s,o,h,a=[];for(s=0,o=n.length;s<o;s++)(h=i(t,n[s]*e,s<o-1?n[s+1]*e:t.length,e,!1))===h.next&&(h.steiner=!0),a.push(p(h));for(a.sort(c),s=0;s<a.length;s++)r=l(a[s],r);return r}(t,n,d,r)),t.length>80*r){e=h=t[0],o=a=t[1];for(var z=r;z<y;z+=r)(u=t[z])<e&&(e=u),(x=t[z+1])<o&&(o=x),u>h&&(h=u),x>a&&(a=x);v=0!==(v=Math.max(h-e,a-o))?32767/v:0}return s(d,g,r,e,o,v,0),g}function i(t,n,r,i,e){var s,o;if(e===V(t,n,r,i)>0)for(s=n;s<r;s+=i)o=P(s,t[s],t[s+1],o);else for(s=r-i;s>=n;s-=i)o=P(s,t[s],t[s+1],o);return o&&g(o,o.next)&&(S(o),o=o.next),o}function e(t,n){if(!t)return t;n||(n=t);var r,i=t;do{if(r=!1,i.steiner||!g(i,i.next)&&0!==d(i.prev,i,i.next))i=i.next;else{if(S(i),(i=n=i.prev)===i.next)break;r=!0}}while(r||i!==n);return n}function s(t,n,r,i,c,l,x){if(t){!x&&l&&function(t,n,r,i){var e=t;do{0===e.z&&(e.z=v(e.x,e.y,n,r,i)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next}while(e!==t);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,r,i,e,s,o,h,a,u=1;do{for(r=t,t=null,s=null,o=0;r;){for(o++,i=r,h=0,n=0;n<u&&(h++,i=i.nextZ);n++);for(a=u;h>0||a>0&&i;)0!==h&&(0===a||!i||r.z<=i.z)?(e=r,r=r.nextZ,h--):(e=i,i=i.nextZ,a--),s?s.nextZ=e:t=e,e.prevZ=s,s=e;r=i}s.nextZ=null,u*=2}while(o>1)}(e)}(t,i,c,l);for(var p,f,y=t;t.prev!==t.next;)if(p=t.prev,f=t.next,l?h(t,i,c,l):o(t))n.push(p.i/r|0),n.push(t.i/r|0),n.push(f.i/r|0),S(t),t=f.next,y=f.next;else if((t=f)===y){x?1===x?s(t=a(e(t),n,r),n,r,i,c,l,2):2===x&&u(t,n,r,i,c,l):s(e(t),n,r,i,c,l,1);break}}}function o(t){var n=t.prev,r=t,i=t.next;if(d(n,r,i)>=0)return!1;for(var e=n.x,s=r.x,o=i.x,h=n.y,a=r.y,u=i.y,c=e<s?e<o?e:o:s<o?s:o,l=h<a?h<u?h:u:a<u?a:u,x=e>s?e>o?e:o:s>o?s:o,v=h>a?h>u?h:u:a>u?a:u,p=i.next;p!==n;){if(p.x>=c&&p.x<=x&&p.y>=l&&p.y<=v&&f(e,h,s,a,o,u,p.x,p.y)&&d(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function h(t,n,r,i){var e=t.prev,s=t,o=t.next;if(d(e,s,o)>=0)return!1;for(var h=e.x,a=s.x,u=o.x,c=e.y,l=s.y,x=o.y,p=h<a?h<u?h:u:a<u?a:u,y=c<l?c<x?c:x:l<x?l:x,g=h>a?h>u?h:u:a>u?a:u,z=c>l?c>x?c:x:l>x?l:x,m=v(p,y,n,r,i),M=v(g,z,n,r,i),w=t.prevZ,b=t.nextZ;w&&w.z>=m&&b&&b.z<=M;){if(w.x>=p&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,b.x>=p&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;w&&w.z>=m;){if(w.x>=p&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;b&&b.z<=M;){if(b.x>=p&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function a(t,n,r){var i=t;do{var s=i.prev,o=i.next.next;!g(s,o)&&z(s,i,i.next,o)&&w(s,o)&&w(o,s)&&(n.push(s.i/r|0),n.push(i.i/r|0),n.push(o.i/r|0),S(i),S(i.next),i=t=o),i=i.next}while(i!==t);return e(i)}function u(t,n,r,i,o,h){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&y(a,u)){var c=b(a,u);return a=e(a,a.next),c=e(c,c.next),s(a,n,r,i,o,h,0),void s(c,n,r,i,o,h,0)}u=u.next}a=a.next}while(a!==t)}function c(t,n){return t.x-n.x}function l(t,n){var r=function(t,n){var r,i=n,e=t.x,s=t.y,o=-1/0;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){var h=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(h<=e&&h>o&&(o=h,r=i.x<i.next.x?i:i.next,h===e))return r}i=i.next}while(i!==n);if(!r)return null;var a,u=r,c=r.x,l=r.y,v=1/0;i=r;do{e>=i.x&&i.x>=c&&e!==i.x&&f(s<l?e:o,s,c,l,s<l?o:e,s,i.x,i.y)&&(a=Math.abs(s-i.y)/(e-i.x),w(i,t)&&(a<v||a===v&&(i.x>r.x||i.x===r.x&&x(r,i)))&&(r=i,v=a)),i=i.next}while(i!==u);return r}(t,n);if(!r)return n;var i=b(r,t);return e(i,i.next),e(r,r.next)}function x(t,n){return d(t.prev,t,n.prev)<0&&d(n.next,t,t.next)<0}function v(t,n,r,i,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*e|0)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=(n-i)*e|0)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function p(t){var n=t,r=t;do{(n.x<r.x||n.x===r.x&&n.y<r.y)&&(r=n),n=n.next}while(n!==t);return r}function f(t,n,r,i,e,s,o,h){return(e-o)*(n-h)>=(t-o)*(s-h)&&(t-o)*(i-h)>=(r-o)*(n-h)&&(r-o)*(s-h)>=(e-o)*(i-h)}function y(t,n){return t.next.i!==n.i&&t.prev.i!==n.i&&!function(t,n){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==n.i&&r.next.i!==n.i&&z(r,r.next,t,n))return!0;r=r.next}while(r!==t);return!1}(t,n)&&(w(t,n)&&w(n,t)&&function(t,n){var r=t,i=!1,e=(t.x+n.x)/2,s=(t.y+n.y)/2;do{r.y>s!=r.next.y>s&&r.next.y!==r.y&&e<(r.next.x-r.x)*(s-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,n)&&(d(t.prev,t,n.prev)||d(t,n.prev,n))||g(t,n)&&d(t.prev,t,t.next)>0&&d(n.prev,n,n.next)>0)}function d(t,n,r){return(n.y-t.y)*(r.x-n.x)-(n.x-t.x)*(r.y-n.y)}function g(t,n){return t.x===n.x&&t.y===n.y}function z(t,n,r,i){var e=M(d(t,n,r)),s=M(d(t,n,i)),o=M(d(r,i,t)),h=M(d(r,i,n));return e!==s&&o!==h||(!(0!==e||!m(t,r,n))||(!(0!==s||!m(t,i,n))||(!(0!==o||!m(r,t,i))||!(0!==h||!m(r,n,i)))))}function m(t,n,r){return n.x<=Math.max(t.x,r.x)&&n.x>=Math.min(t.x,r.x)&&n.y<=Math.max(t.y,r.y)&&n.y>=Math.min(t.y,r.y)}function M(t){return t>0?1:t<0?-1:0}function w(t,n){return d(t.prev,t,t.next)<0?d(t,n,t.next)>=0&&d(t,t.prev,n)>=0:d(t,n,t.prev)<0||d(t,t.next,n)<0}function b(t,n){var r=new A(t.i,t.x,t.y),i=new A(n.i,n.x,n.y),e=t.next,s=n.prev;return t.next=n,n.prev=t,r.next=e,e.prev=r,i.next=r,r.prev=i,s.next=i,i.prev=s,i}function P(t,n,r,i){var e=new A(t,n,r);return i?(e.next=i.next,e.prev=i,i.next.prev=e,i.next=e):(e.prev=e,e.next=e),e}function S(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function A(t,n,r){this.i=t,this.x=n,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function V(t,n,r,i){for(var e=0,s=n,o=r-i;s<r;s+=i)e+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return e}n.exports=r,n.exports.default=r,r.deviation=function(t,n,r,i){var e=n&&n.length,s=e?n[0]*r:t.length,o=Math.abs(V(t,0,s,r));if(e)for(var h=0,a=n.length;h<a;h++){var u=n[h]*r,c=h<a-1?n[h+1]*r:t.length;o-=Math.abs(V(t,u,c,r))}var l=0;for(h=0;h<i.length;h+=3){var x=i[h]*r,v=i[h+1]*r,p=i[h+2]*r;l+=Math.abs((t[x]-t[p])*(t[v+1]-t[x+1])-(t[x]-t[v])*(t[p+1]-t[x+1]))}return 0===o&&0===l?0:Math.abs((l-o)/o)},r.flatten=function(t){for(var n=t[0][0].length,r={vertices:[],holes:[],dimensions:n},i=0,e=0;e<t.length;e++){for(var s=0;s<t[e].length;s++)for(var o=0;o<n;o++)r.vertices.push(t[e][s][o]);e>0&&(i+=t[e-1].length,r.holes.push(i))}return r};var Z=n.exports;function _(t){for(var n,r,i=0,e=1,s=t.length;e<s;)n=r||t[0],i+=((r=t[e])[0]-n[0])*(r[1]+n[1]),e++;return i>0}function L(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t}function F(t,n){var r=n[0],i=n[1],e=n[2],s=Math.sqrt(r*r+i*i+e*e)||1;return t[0]=r/s,t[1]=i/s,t[2]=e/s,t}function I(t,n){function r(t,n,r,i){t[0]=n,t[1]=r,t[2]=i}for(var i,e,s,o,h,a,u,c,l,x=[],v=[],p=[],f=[],y=[],d=[],g=t.length,z=new Float32Array(n.length),m=0;m<g;){var M=3*t[m],w=3*t[m+1],b=3*t[m+2];r(x,n[M],n[M+1],n[M+2]),r(v,n[w],n[w+1],n[w+2]),r(p,n[b],n[b+1],n[b+2]),L(y,p,v),L(f,x,v),i=d,s=f,o=void 0,h=void 0,a=void 0,u=void 0,c=void 0,l=void 0,o=(e=y)[0],h=e[1],a=e[2],u=s[0],c=s[1],l=s[2],i[0]=h*l-a*c,i[1]=a*u-o*l,i[2]=o*c-h*u;for(var P=0;P<3;P++)z[M+P]+=d[P],z[w+P]+=d[P],z[b+P]+=d[P];m+=3}for(var S=0,A=z.length;S<A;)r(d,z[S],z[S+1],z[S+2]),F(d,d),z[S]=d[0]||0,z[S+1]=d[1]||0,z[S+2]=d[2]||0,S+=3;return z}function O(t){if(1===t.length)return{position:t[0].position,normal:t[0].normal,uv:t[0].uv,indices:t[0].indices,results:t};for(var n=0,r=0,i=0,e=t.length;i<e;i++){var s=t[i],o=s.position,h=s.indices;n+=o.length,r+=h.length}for(var a={position:new Float32Array(n),normal:new Float32Array(n),uv:new Float32Array(n/3*2),indices:new Uint32Array(r),results:t},u=0,c=0,l=0,x=0,v=0,p=t.length;v<p;v++){var f=t[v],y=f.position,d=f.indices,g=f.normal,z=f.uv;a.position.set(y,u),a.normal.set(g,u),a.uv.set(z,x);for(var m=0,M=d.length;m<M;){var w=d[m]+c;a.indices[l]=w,l++,m++}x+=z.length,u+=y.length,c+=y.length/3}return a}function q(t){return 180*t/Math.PI}function U(t){return t/180*Math.PI}function j(t,n,r,i,e,s){var o=3*r,h=3*i,a=3*e,u=3*s,c=n[o],l=n[o+1],x=n[o+2],v=n[h],p=n[h+1],f=n[h+2],y=n[a],d=n[a+1],g=n[a+2],z=n[u],m=n[u+1],M=n[u+2];Math.abs(l-p)<Math.abs(c-v)?(t.push(c,1-x),t.push(v,1-f),t.push(y,1-g),t.push(z,1-M)):(t.push(l,1-x),t.push(p,1-f),t.push(d,1-g),t.push(m,1-M))}function C(t){T(t)||t.push(t[0])}function T(t){var n=t.length,r=t[0],i=r[0],e=r[1],s=t[n-1],o=s[0],h=s[1];return i===o&&e===h}var k={x:0,y:0},B={x:0,y:0};function R(t,n){for(var r=n.lineWidth/2,i=[],e=[],s=[],o=t.length,h=0;h<o;){var a=t[h],u=t[h+1],c=t[h];h===o-1&&(a=t[o-2],u=t[o-1]);var l=u[1]-a[1],x=u[0]-a[0],v=0,p=q(Math.atan(l/x));if(0===h||h===o-1)v=p,v-=90;else{var f=t[h-1];k.x=f[0]-a[0],k.y=f[1]-a[1],B.x=u[0]-a[0],B.y=u[1]-a[1],v=p-E(k,B)/2}var y=U(v),d=c,g=[Math.cos(y)+d[0],Math.sin(y)+d[1]],z=W(a,u,r),m=z[0],M=z[1],w=D(m[0],m[1],d,g),b=D(M[0],M[1],d,g);if(!w||!b){var P=i.length,S=i[P-2],A=i[P-1];if(!S||!A)continue;w=[S[0],S[1]],b=[A[0],A[1]]}w[2]=c[2]||0,b[2]=c[2]||0,i.push(w,b),N(w,a,u)?(e.push(w),s.push(b)):(e.push(b),s.push(w)),h++}return{offsetPoints:i,leftPoints:e,rightPoints:s}}var E=function(t,n){var r=t.x,i=t.y,e=n.x,s=n.y,o=r*e+i*s,h=r*s-i*e;return(Math.atan2(h,o)/Math.PI*180+360)%360};function N(t,n,r){var i=n[0],e=n[1],s=r[0],o=r[1];return(e-o)*t[0]+(s-i)*t[1]+i*o-s*e>0}function W(t,n,r){var i=n[1]-t[1],e=n[0]-t[0],s=Math.atan2(i,e),o=s+Math.PI/2,h=Math.cos(o)*r,a=Math.sin(o)*r,u=[t[0]+h,t[1]+a],c=[n[0]+h,n[1]+a],l=s-Math.PI/2;return h=Math.cos(l)*r,a=Math.sin(l)*r,[[u,c],[[t[0]+h,t[1]+a],[n[0]+h,n[1]+a]]]}function D(t,n,r,i){var e=n[0]-t[0],s=n[1]-t[1],o=i[0]-r[0],h=i[1]-r[1];if(0===e&&0===o)return null;if(0===s&&0===h)return null;var a,u,c=s/e,l=h/o,x=t[1]-c*t[0],v=r[1]-l*r[0];return 0===e?u=l*(a=t[0])+v:0===o?u=c*(a=r[0])+x:0===s?a=((u=t[1])-v)/l:0===h?a=((u=r[1])-x)/c:u=c*(a=(v-x)/(c-l))+x,[a,u]}var Q=function(){function t(t,n,r){void 0===t&&(t=0),void 0===n&&(n=0),void 0===r&&(r=0),this.x=t,this.y=n,this.z=r}var n=t.prototype;return n.set=function(t,n,r){return void 0===r&&(r=this.z),this.x=t,this.y=n,this.z=r,this},n.clone=function(){return new this.constructor(this.x,this.y,this.z)},n.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},n.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},n.addScalar=function(t){return this.x+=t,this.y+=t,this.z+=t,this},n.addVectors=function(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this},n.addScaledVector=function(t,n){return this.x+=t.x*n,this.y+=t.y*n,this.z+=t.z*n,this},n.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},n.subScalar=function(t){return this.x-=t,this.y-=t,this.z-=t,this},n.subVectors=function(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this},n.multiply=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},n.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},n.multiplyVectors=function(t,n){return this.x=t.x*n.x,this.y=t.y*n.y,this.z=t.z*n.z,this},n.applyMatrix4=function(t){var n=this.x,r=this.y,i=this.z,e=t.elements,s=1/(e[3]*n+e[7]*r+e[11]*i+e[15]);return this.x=(e[0]*n+e[4]*r+e[8]*i+e[12])*s,this.y=(e[1]*n+e[5]*r+e[9]*i+e[13])*s,this.z=(e[2]*n+e[6]*r+e[10]*i+e[14])*s,this},n.divide=function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},n.divideScalar=function(t){return this.multiplyScalar(1/t)},n.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},n.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},n.clamp=function(t,n){return this.x=Math.max(t.x,Math.min(n.x,this.x)),this.y=Math.max(t.y,Math.min(n.y,this.y)),this.z=Math.max(t.z,Math.min(n.z,this.z)),this},n.clampScalar=function(t,n){return this.x=Math.max(t,Math.min(n,this.x)),this.y=Math.max(t,Math.min(n,this.y)),this.z=Math.max(t,Math.min(n,this.z)),this},n.clampLength=function(t,n){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(n,r)))},n.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.lengthSq=function(){return this.x*this.x+this.y*this.y+this.z*this.z},n.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.normalize=function(){return this.divideScalar(this.length()||1)},n.setLength=function(t){return this.normalize().multiplyScalar(t)},n.lerp=function(t,n){return this.x+=(t.x-this.x)*n,this.y+=(t.y-this.y)*n,this.z+=(t.z-this.z)*n,this},n.lerpVectors=function(t,n,r){return this.x=t.x+(n.x-t.x)*r,this.y=t.y+(n.y-t.y)*r,this.z=t.z+(n.z-t.z)*r,this},n.cross=function(t){return this.crossVectors(this,t)},n.crossVectors=function(t,n){var r=t.x,i=t.y,e=t.z,s=n.x,o=n.y,h=n.z;return this.x=i*h-e*o,this.y=e*s-r*h,this.z=r*o-i*s,this},n.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},n.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},n.fromArray=function(t,n){return void 0===n&&(n=0),this.x=t[n],this.y=t[n+1],this.z=t[n+2],this},n.random=function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this},t}(),H=function(){function t(){this.pos=new Q,this.dir=new Q,this.right=new Q,this.up=new Q,this.dist=0,this.widthScale=1,this.sharp=!1}var n=t.prototype;return n.lerpPathPoints=function(t,n,r){this.pos.lerpVectors(t.pos,n.pos,r),this.dir.lerpVectors(t.dir,n.dir,r),this.up.lerpVectors(t.up,n.up,r),this.right.lerpVectors(t.right,n.right,r),this.dist=(n.dist-t.dist)*r+t.dist,this.widthScale=(n.widthScale-t.widthScale)*r+t.widthScale},n.copy=function(t){this.pos.copy(t.pos),this.dir.copy(t.dir),this.up.copy(t.up),this.right.copy(t.right),this.dist=t.dist,this.widthScale=t.widthScale},t}(),X=function(){function t(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f)}var n=t.prototype;return n.set=function(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f){var y=this.elements;return y[0]=t,y[4]=n,y[8]=r,y[12]=i,y[1]=e,y[5]=s,y[9]=o,y[13]=h,y[2]=a,y[6]=u,y[10]=c,y[14]=l,y[3]=x,y[7]=v,y[11]=p,y[15]=f,this},n.multiply=function(t){return this.multiplyMatrices(this,t)},n.makeRotationAxis=function(t,n){var r=Math.cos(n),i=Math.sin(n),e=1-r,s=t.x,o=t.y,h=t.z,a=e*s,u=e*o;return this.set(a*s+r,a*o-i*h,a*h+i*o,0,a*o+i*h,u*o+r,u*h-i*s,0,a*h-i*o,u*h+i*s,e*h*h+r,0,0,0,0,1),this},n.equals=function(t){for(var n=this.elements,r=t.elements,i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0},t}();function G(t,n){return G=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},G(t,n)}function J(t,n,r,i){return function(t,n){var r=1-t;return r*r*n}(t,n)+function(t,n){return 2*(1-t)*t*n}(t,r)+function(t,n){return t*t*n}(t,i)}var K=function(t){var n,r;function i(n,r,i){var e;return void 0===n&&(n=new Q),void 0===r&&(r=new Q),void 0===i&&(i=new Q),(e=t.call(this)||this).isQuadraticBezierCurve3=!0,e.type="QuadraticBezierCurve3",e.v0=n,e.v1=r,e.v2=i,e}return r=t,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,G(n,r),i.prototype.getPoint=function(t,n){void 0===n&&(n=new Q);var r=n,i=this.v0,e=this.v1,s=this.v2;return r.set(J(t,i.x,e.x,s.x),J(t,i.y,e.y,s.y),J(t,i.z,e.z,s.z)),r},i}(function(){function t(){this.type="Curve",this.arcLengthDivisions=200}var n=t.prototype;return n.getPoint=function(){return console.warn("THREE.Curve: .getPoint() not implemented."),null},n.getPointAt=function(t,n){var r=this.getUtoTmapping(t);return this.getPoint(r,n)},n.getPoints=function(t){void 0===t&&(t=5);for(var n=[],r=0;r<=t;r++)n.push(this.getPoint(r/t));return n},n.getLength=function(){var t=this.getLengths();return t[t.length-1]},n.getLengths=function(t){if(void 0===t&&(t=this.arcLengthDivisions),this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var n,r=[],i=this.getPoint(0),e=0;r.push(0);for(var s=1;s<=t;s++)e+=(n=this.getPoint(s/t)).distanceTo(i),r.push(e),i=n;return this.cacheArcLengths=r,r},n.getUtoTmapping=function(t,n){var r,i=this.getLengths(),e=0,s=i.length;r=n||t*i[s-1];for(var o,h=0,a=s-1;h<=a;)if((o=i[e=Math.floor(h+(a-h)/2)]-r)<0)h=e+1;else{if(!(o>0)){a=e;break}a=e-1}if(i[e=a]===r)return e/(s-1);var u=i[e];return(e+(r-u)/(i[e+1]-u))/(s-1)},t}()),Y=new Q,$=new Q,tt=new Q,nt=new X,rt=new K;var it=function(){function t(){this.array=[],this.count=0}var n=t.prototype;return n.set=function(t,n,r,i,e){if(void 0===n&&(n=.1),void 0===r&&(r=10),void 0===i&&(i=null),void 0===e&&(e=!1),(t=t.slice(0)).length<2)return console.warn("PathPointList: points length less than 2."),void(this.count=0);e&&!t[0].equals(t[t.length-1])&&t.push((new Q).copy(t[0]));for(var s=0,o=t.length;s<o;s++)if(0===s)this._start(t[s],t[s+1],i);else if(s===o-1)if(e){this._corner(t[s],t[1],n,r,i);var h=this.array[0].dist;this.array[0].copy(this.array[this.count-1]),this.array[0].dist=h}else this._end(t[s]);else this._corner(t[s],t[s+1],n,r,i)},n.distance=function(){return this.count>0?this.array[this.count-1].dist:0},n._getByIndex=function(t){return this.array[t]||(this.array[t]=new H),this.array[t]},n._start=function(t,n,r){this.count=0;var i=this._getByIndex(this.count);if(i.pos.copy(t),i.dir.subVectors(n,t),r)i.up.copy(r);else{var e=Number.MAX_VALUE,s=Math.abs(i.dir.x),o=Math.abs(i.dir.y),h=Math.abs(i.dir.z);s<e&&(e=s,i.up.set(1,0,0)),o<e&&(e=o,i.up.set(0,1,0)),h<e&&i.up.set(0,0,1)}i.right.crossVectors(i.dir,i.up).normalize(),i.up.crossVectors(i.right,i.dir).normalize(),i.dist=0,i.widthScale=1,i.sharp=!1,i.dir.normalize(),this.count++},n._end=function(t){var n=this.array[this.count-1],r=this._getByIndex(this.count);r.pos.copy(t),r.dir.subVectors(t,n.pos);var i=r.dir.length();r.dir.normalize(),r.up.copy(n.up);var e=Y.crossVectors(n.dir,r.dir);if(e.length()>Number.EPSILON){e.normalize();var s=Math.acos(Math.min(Math.max(n.dir.dot(r.dir),-1),1));r.up.applyMatrix4(nt.makeRotationAxis(e,s))}r.right.crossVectors(r.dir,r.up).normalize(),r.dist=n.dist+i,r.widthScale=1,r.sharp=!1,this.count++},n._corner=function(t,n,r,i,e){if(r>0&&i>0){for(var s=function(t,n,r,i,e,s){var o=Y.subVectors(n,t),h=$.subVectors(r,n),a=o.length(),u=h.length();o.normalize(),h.normalize();var c=Math.min(.999999*(e?a/2:a),i);s.v0.copy(n).sub(o.multiplyScalar(c)),s.v1.copy(n);var l=Math.min(u/2*.999999,i);return s.v2.copy(n).add(h.multiplyScalar(l)),s}(this.array[this.count-1].pos,t,n,r,this.count-1==0,rt),o=s.getPoints(i),h=0;h<i;h++)this._sharpCorner(o[h],o[h+1],e,0===h?1:0);o[i].equals(n)||this._sharpCorner(o[i],n,e,2)}else this._sharpCorner(t,n,e,0,!0)},n._sharpCorner=function(t,n,r,i,e){void 0===i&&(i=0),void 0===e&&(e=!1);var s=this.array[this.count-1],o=this._getByIndex(this.count),h=Y.subVectors(t,s.pos),a=$.subVectors(n,t),u=h.length();if(h.normalize(),a.normalize(),o.pos.copy(t),1===i?o.dir.copy(h):2===i?o.dir.copy(a):(o.dir.addVectors(h,a),o.dir.normalize()),r)1===o.dir.dot(r)?o.right.crossVectors(a,r).normalize():o.right.crossVectors(o.dir,r).normalize(),o.up.crossVectors(o.right,o.dir).normalize();else{o.up.copy(s.up);var c=tt.crossVectors(s.dir,o.dir);if(c.length()>Number.EPSILON){c.normalize();var l=Math.acos(Math.min(Math.max(s.dir.dot(o.dir),-1),1));o.up.applyMatrix4(nt.makeRotationAxis(c,l))}o.right.crossVectors(o.dir,o.up).normalize()}o.dist=s.dist+u;var x=h.dot(a);o.widthScale=Math.min(1/Math.sqrt((1+x)/2),1.415)||1,o.sharp=Math.abs(x-1)>.05&&e,this.count++},t}(),et=new Q(0,0,1);t.cylinder=function(t,n){void 0===n&&(n={}),n=Object.assign({},{radius:1,height:2,radialSegments:6},n);for(var r=Math.round(Math.max(4,n.radialSegments)),i=n,e=i.radius,s=i.height,o=360/r/360*Math.PI*2,h=r+1,a=new Float32Array(3*h*2),u=t[0],c=t[1],l=0,x=0,v=3*h,p=2*h,f=[],y=[],d=-1;d<r;d++){var g=o*d,z=Math.cos(g)*e+u,m=Math.sin(g)*e+c;a[l]=z,a[l+1]=m,a[l+2]=0,a[l+v]=z,a[l+1+v]=m,a[l+2+v]=s;var M,w;M=.5+z/e/2,w=.5+m/e/2,y[x]=M,y[x+1]=w,y[x+p]=M,y[x+1+p]=w,l+=3,x+=2,d>1&&f.push(0,d-1,d)}a[l-=3]=a[0],a[l+1]=a[1],a[l+2]=a[2];var b=a.length;a[b-3]=a[0],a[b-2]=a[1],a[b-1]=s;for(var P=f.length,S=0;S<P;S++){var A=f[S];f.push(A+h)}var V=new Float32Array(2*(3*h*2-6)),Z=-1;l=2*h,x=0;for(var _=0,L=a.length/2;_<L-3;_+=3){var F=a[_],O=a[_+1],q=a[_+3],U=a[_+4];V[++Z]=F,V[++Z]=O,V[++Z]=s,V[++Z]=q,V[++Z]=U,V[++Z]=s,V[++Z]=F,V[++Z]=O,V[++Z]=0,V[++Z]=q,V[++Z]=U,V[++Z]=0;var j=l+2,C=l+3,T=l,k=l+1;f.push(T,j,k,j,C,k),l+=4;var B=x/h,R=(x+1)/h;y.push(B,s/e/2,R,s/e/2,B,0,R,0),x++}var E=new Float32Array(a.length+V.length);E.set(a,0),E.set(V,a.length);var N=I(f,E);return{points:a,indices:new Uint32Array(f),position:E,normal:N,uv:new Float32Array(y)}},t.expandLine=R,t.expandPaths=function(t,n){n=Object.assign({},{lineWidth:1,cornerRadius:0,cornerSplit:10},n);var r=t.map((function(t){var r=t.map((function(t){var n=t[0],r=t[1],i=t[2];return new Q(n,r,i||0)})),i=new it;i.set(r,n.cornerRadius,n.cornerSplit,et);var e=function(t,n){var r=n.lineWidth||.1,i=1,e=r/2,s=r,o=t.distance(),h=i*o;if(0===o)return null;var a,u=e/s,c=0,l=[],x=[],v=[],p=[],f=0,y=new Q,d=new Q,g=new Q,z=new Q,m=new Q,M=new Q;function w(t){var n=0===l.length,r=t.sharp&&!n,i=t.dist/s,o=t.dir,h=t.up,a=t.right;if(y.copy(a).multiplyScalar(e*t.widthScale),d.copy(a).multiplyScalar(-e*t.widthScale),y.add(t.pos),d.add(t.pos),r){g.fromArray(l,l.length-6).sub(d),z.fromArray(l,l.length-3).sub(y);var w,b,P=g.length()-z.length();P>0?(w=g,b=d):(w=z,b=y),m.copy(w).setLength(Math.abs(P)).add(b);var S=M.copy(b).sub(m).normalize().dot(o)*M.copy(b).sub(m).length()*2;M.copy(o).setLength(S).add(m),P>0?(l.push(m.x,m.y,m.z,y.x,y.y,y.z,d.x,d.y,d.z,y.x,y.y,y.z,M.x,M.y,M.z,y.x,y.y,y.z),f+=6,p.push(f-6,f-8,f-7,f-6,f-7,f-5,f-4,f-6,f-5,f-2,f-4,f-1),c+=12):(l.push(d.x,d.y,d.z,m.x,m.y,m.z,d.x,d.y,d.z,y.x,y.y,y.z,d.x,d.y,d.z,M.x,M.y,M.z),f+=6,p.push(f-6,f-8,f-7,f-6,f-7,f-5,f-6,f-5,f-3,f-2,f-3,f-1),c+=12),x.push(h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z),v.push(i-u,0,i-u,1,i,0,i,1,i+u,0,i+u,1)}else l.push(d.x,d.y,d.z,y.x,y.y,y.z),x.push(h.x,h.y,h.z,h.x,h.y,h.z),v.push(i,0,i,1),f+=2,n||(p.push(f-2,f-4,f-3,f-2,f-3,f-1),c+=6)}if(h>0)for(var b=0;b<t.count;b++){var P=t.array[b];if(P.dist>h){var S=t.array[b-1];a=new H;var A=(h-S.dist)/(P.dist-S.dist);a.lerpPathPoints(S,P,A),w(a);break}w(P)}else a=t.array[0];return{points:l,normal:x,uvs:v,index:p,count:c}}(i,n);return e.line=t,e.position=new Float32Array(e.points),e.indices=new Uint32Array(e.index),e.uv=new Float32Array(e.uvs),e.normal=new Float32Array(e.normal),e})),i=O(r);return i.lines=t,i},t.extrudePolygons=function(t,n){n=Object.assign({},{depth:2},n);var r=t.map((function(t){for(var r=0,i=t.length;r<i;r++){var e=t[r];C(e),0===r?_(e)||(t[r]=e.reverse()):_(e)&&(t[r]=e.reverse()),T(e)&&e.splice(e.length-1,1)}var s=function(t,n){for(var r=function(t){var n=0,r=0,i=t.length;for(;r<i;)n+=t[r].length,r++;return n}(t),i=t.length,e=[],s=new Float32Array(2*r),o=[],h=[],a=3*r,u=2*r,c=n.depth,l=0,x=0,v=0,p=0;p<i;p++){var f=t[p];p>0&&e.push(l/2);for(var y=0,d=f.length;y<d;){var g=f[y],z=g[0],m=g[1];s[l++]=z,s[l++]=m,o[x]=z,o[x+1]=m,o[x+2]=c,o[a+x]=z,o[a+x+1]=m,o[a+x+2]=0,h[v]=z,h[v+1]=m,h[u+v]=z,h[u+v+1]=m,x+=3,v+=2,y++}}return{flatVertices:s,holes:e,points:o,count:r,uvs:h}}(t,n);return s.polygon=t,function(t,n){for(var r=[],i=t.count,e=0,s=n.length;e<s;e+=3){var o=n[e],h=n[e+1],a=n[e+2];r[e]=o,r[e+1]=h,r[e+2]=a;var u=s+e,c=i+o,l=i+h,x=i+a;r[u]=c,r[u+1]=l,r[u+2]=x}t.index=r}(s,Z(s.flatVertices,s.holes,2)),function(t,n){for(var r=t.points,i=t.index,e=t.polygon,s=t.uvs,o=n.depth,h=0,a=e.length;h<a;h++)for(var u=e[h],c=0,l=u.length;c<l;){var x=u[c],v=u[c+1];c===l-1&&(v=u[0]);var p=r.length/3,f=x[0],y=x[1],d=v[0],g=v[1];r.push(f,y,o,d,g,o,f,y,0,d,g,0);var z=p+2,m=p+3,M=p,w=p+1;i.push(z,M,m,M,w,m),j(s,r,z,m,M,w),c++}}(s,n),s.position=new Float32Array(s.points),s.indices=new Uint32Array(s.index),s.uv=new Float32Array(s.uvs),s.normal=I(s.indices,s.position),s})),i=O(r);return i.polygons=t,i},t.extrudePolylines=function(t,n){n=Object.assign({},{depth:2,lineWidth:1},n);var r=t.map((function(t){var r=R(t,n);return r.line=t,function(t,n){var r=n.depth,i=[],e=[],s=[],o=t.leftPoints,h=t.rightPoints,a=0,u=o.length;for(;a<u;){var c=3*a,l=o[a],x=l[0],v=l[1],p=l[2];i[c]=x,i[c+1]=v,i[c+2]=r+p;var f=h[a],y=f[0],d=f[1],g=f[2],z=3*u+c;i[z]=y,i[z+1]=d,i[z+2]=r+g;var m=2*u*3+c;i[m]=x,i[m+1]=v,i[m+2]=p;var M=2*u*3+3*u+c;i[M]=y,i[M+1]=d,i[M+2]=g,a++}a=0,u=i.length;for(;a<u;){var w=i[a],b=i[a+1];s.push(w,b),a+=3}a=0,u=o.length;for(;a<u-1;){var P=a,S=a+1,A=P+u,V=S+u;e.push(P,A,S),e.push(A,V,S);var Z=a+2*u,_=Z+1,L=Z+u,F=_+u;e.push(Z,L,_),e.push(L,F,_),a++}t.index=e,t.points=i,t.uvs=s}(r,n),function(t,n){var r=t.points,i=t.index,e=t.leftPoints,s=t.rightPoints,o=t.uvs,h=n.depth,a=[e,s];function u(t,n){var e=r.length/3;r.push(t[0],t[1],h+t[2],n[0],n[1],h+n[2],t[0],t[1],t[2],n[0],n[1],n[2]);var s=e+2,a=e+3,u=e,c=e+1;i.push(s,u,a,u,c,a),j(o,r,s,a,u,c)}for(var c=0,l=a.length;c<l;c++){var x=a[c];c>0&&(x=(x=x.map((function(t){return t}))).reverse());for(var v=0,p=x.length-1;v<p;){u(x[v],x[v+1]),v++}}for(var f=e.length,y=[s[0],e[0],e[f-1],s[f-1]],d=0;d<y.length;d+=2){u(y[d],y[d+1])}}(r,n),r.position=new Float32Array(r.points),r.indices=new Uint32Array(r.index),r.uv=new Float32Array(r.uvs),r.normal=I(r.indices,r.position),r})),i=O(r);return i.lines=t,i},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/poly-extrude.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* poly-extrude v0.
|
2
|
+
* poly-extrude v0.4.0
|
3
3
|
*/
|
4
4
|
var earcut$2 = {exports: {}};
|
5
5
|
|
@@ -1227,7 +1227,7 @@ var TEMPV1 = {
|
|
1227
1227
|
y: 0
|
1228
1228
|
};
|
1229
1229
|
function expandLine(line, options) {
|
1230
|
-
|
1230
|
+
// let preAngle = 0;
|
1231
1231
|
var radius = options.lineWidth / 2;
|
1232
1232
|
var points = [],
|
1233
1233
|
leftPoints = [],
|
@@ -1235,66 +1235,76 @@ function expandLine(line, options) {
|
|
1235
1235
|
var len = line.length;
|
1236
1236
|
var i = 0;
|
1237
1237
|
|
1238
|
-
while (i < len
|
1239
|
-
var
|
1240
|
-
|
1241
|
-
var
|
1242
|
-
|
1243
|
-
|
1238
|
+
while (i < len) {
|
1239
|
+
var p1 = line[i],
|
1240
|
+
p2 = line[i + 1];
|
1241
|
+
var currentp = line[i]; // last vertex
|
1242
|
+
|
1243
|
+
if (i === len - 1) {
|
1244
|
+
p1 = line[len - 2];
|
1245
|
+
p2 = line[len - 1];
|
1246
|
+
}
|
1247
|
+
|
1248
|
+
var dy = p2[1] - p1[1],
|
1249
|
+
dx = p2[0] - p1[0];
|
1250
|
+
var rAngle = 0;
|
1244
1251
|
var rad = Math.atan(dy / dx);
|
1245
|
-
var angle = radToDeg(rad);
|
1246
|
-
preAngle = angle;
|
1252
|
+
var angle = radToDeg(rad); // preAngle = angle;
|
1247
1253
|
|
1248
|
-
if (i === 0) {
|
1249
|
-
|
1250
|
-
|
1254
|
+
if (i === 0 || i === len - 1) {
|
1255
|
+
rAngle = angle;
|
1256
|
+
rAngle -= 90;
|
1251
1257
|
} else {
|
1258
|
+
// 至少3个顶点才会触发
|
1252
1259
|
var p0 = line[i - 1];
|
1253
|
-
TEMPV1.x = p0[0] -
|
1254
|
-
TEMPV1.y = p0[1] -
|
1255
|
-
TEMPV2.x =
|
1256
|
-
TEMPV2.y =
|
1260
|
+
TEMPV1.x = p0[0] - p1[0];
|
1261
|
+
TEMPV1.y = p0[1] - p1[1];
|
1262
|
+
TEMPV2.x = p2[0] - p1[0];
|
1263
|
+
TEMPV2.y = p2[1] - p1[1];
|
1257
1264
|
var vAngle = getAngle(TEMPV1, TEMPV2);
|
1258
|
-
|
1265
|
+
rAngle = angle - vAngle / 2;
|
1259
1266
|
}
|
1260
1267
|
|
1261
|
-
var
|
1268
|
+
var rRad = degToRad(rAngle);
|
1269
|
+
var p3 = currentp;
|
1270
|
+
var x = Math.cos(rRad) + p3[0],
|
1271
|
+
y = Math.sin(rRad) + p3[1];
|
1272
|
+
var p4 = [x, y];
|
1262
1273
|
|
1263
|
-
var
|
1264
|
-
|
1265
|
-
|
1274
|
+
var _translateLine = translateLine(p1, p2, radius),
|
1275
|
+
line1 = _translateLine[0],
|
1276
|
+
line2 = _translateLine[1];
|
1266
1277
|
|
1267
|
-
|
1278
|
+
var op1 = lineIntersection(line1[0], line1[1], p3, p4);
|
1279
|
+
var op2 = lineIntersection(line2[0], line2[1], p3, p4); // 平行,回头路
|
1268
1280
|
|
1269
|
-
if (
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
leftPoints.push(_op2);
|
1274
|
-
rightPoints.push(_op);
|
1275
|
-
}
|
1281
|
+
if (!op1 || !op2) {
|
1282
|
+
var len1 = points.length;
|
1283
|
+
var point1 = points[len1 - 2];
|
1284
|
+
var point2 = points[len1 - 1];
|
1276
1285
|
|
1277
|
-
|
1278
|
-
|
1286
|
+
if (!point1 || !point2) {
|
1287
|
+
continue;
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
op1 = [point1[0], point1[1]];
|
1291
|
+
op2 = [point2[0], point2[1]];
|
1292
|
+
}
|
1279
1293
|
|
1280
|
-
|
1281
|
-
|
1282
|
-
var rRad = degToRad(rAngle);
|
1283
|
-
var p1 = line[len - 2];
|
1284
|
-
var p2 = line[len - 1];
|
1294
|
+
op1[2] = currentp[2] || 0;
|
1295
|
+
op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
|
1285
1296
|
|
1286
|
-
|
1287
|
-
op1 = _calOffsetPoint2[0],
|
1288
|
-
op2 = _calOffsetPoint2[1];
|
1297
|
+
points.push(op1, op2);
|
1289
1298
|
|
1290
|
-
|
1299
|
+
if (leftOnLine(op1, p1, p2)) {
|
1300
|
+
leftPoints.push(op1);
|
1301
|
+
rightPoints.push(op2);
|
1302
|
+
} else {
|
1303
|
+
leftPoints.push(op2);
|
1304
|
+
rightPoints.push(op1);
|
1305
|
+
}
|
1291
1306
|
|
1292
|
-
|
1293
|
-
leftPoints.push(op1);
|
1294
|
-
rightPoints.push(op2);
|
1295
|
-
} else {
|
1296
|
-
leftPoints.push(op2);
|
1297
|
-
rightPoints.push(op1);
|
1307
|
+
i++;
|
1298
1308
|
}
|
1299
1309
|
|
1300
1310
|
return {
|
@@ -1302,21 +1312,7 @@ function expandLine(line, options) {
|
|
1302
1312
|
leftPoints: leftPoints,
|
1303
1313
|
rightPoints: rightPoints
|
1304
1314
|
};
|
1305
|
-
}
|
1306
|
-
|
1307
|
-
function calOffsetPoint(rad, radius, p) {
|
1308
|
-
var x = p[0],
|
1309
|
-
y = p[1];
|
1310
|
-
var z = p[2] || 0;
|
1311
|
-
var x1 = Math.cos(rad) * radius,
|
1312
|
-
y1 = Math.sin(rad) * radius;
|
1313
|
-
var p1 = [x + x1, y + y1, z];
|
1314
|
-
var rad1 = rad += Math.PI;
|
1315
|
-
var x2 = Math.cos(rad1) * radius,
|
1316
|
-
y2 = Math.sin(rad1) * radius;
|
1317
|
-
var p2 = [x + x2, y + y2, z];
|
1318
|
-
return [p1, p2];
|
1319
|
-
}
|
1315
|
+
} // eslint-disable-next-line no-unused-vars
|
1320
1316
|
|
1321
1317
|
var getAngle = function getAngle(_ref, _ref2) {
|
1322
1318
|
var x1 = _ref.x,
|
@@ -1338,6 +1334,80 @@ function leftOnLine(p, p1, p2) {
|
|
1338
1334
|
y = p[1];
|
1339
1335
|
return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
|
1340
1336
|
}
|
1337
|
+
/**
|
1338
|
+
* 平移线
|
1339
|
+
* @param {*} p1
|
1340
|
+
* @param {*} p2
|
1341
|
+
* @param {*} distance
|
1342
|
+
* @returns
|
1343
|
+
*/
|
1344
|
+
|
1345
|
+
|
1346
|
+
function translateLine(p1, p2, distance) {
|
1347
|
+
var dy = p2[1] - p1[1],
|
1348
|
+
dx = p2[0] - p1[0];
|
1349
|
+
var rad = Math.atan2(dy, dx);
|
1350
|
+
var rad1 = rad + Math.PI / 2;
|
1351
|
+
var offsetX = Math.cos(rad1) * distance,
|
1352
|
+
offsetY = Math.sin(rad1) * distance;
|
1353
|
+
var tp1 = [p1[0] + offsetX, p1[1] + offsetY];
|
1354
|
+
var tp2 = [p2[0] + offsetX, p2[1] + offsetY];
|
1355
|
+
var rad2 = rad - Math.PI / 2;
|
1356
|
+
offsetX = Math.cos(rad2) * distance;
|
1357
|
+
offsetY = Math.sin(rad2) * distance;
|
1358
|
+
var tp3 = [p1[0] + offsetX, p1[1] + offsetY];
|
1359
|
+
var tp4 = [p2[0] + offsetX, p2[1] + offsetY];
|
1360
|
+
return [[tp1, tp2], [tp3, tp4]];
|
1361
|
+
}
|
1362
|
+
/**
|
1363
|
+
* 直线交点
|
1364
|
+
* @param {*} p1
|
1365
|
+
* @param {*} p2
|
1366
|
+
* @param {*} p3
|
1367
|
+
* @param {*} p4
|
1368
|
+
* @returns
|
1369
|
+
*/
|
1370
|
+
|
1371
|
+
|
1372
|
+
function lineIntersection(p1, p2, p3, p4) {
|
1373
|
+
var dx1 = p2[0] - p1[0],
|
1374
|
+
dy1 = p2[1] - p1[1];
|
1375
|
+
var dx2 = p4[0] - p3[0],
|
1376
|
+
dy2 = p4[1] - p3[1];
|
1377
|
+
|
1378
|
+
if (dx1 === 0 && dx2 === 0) {
|
1379
|
+
return null;
|
1380
|
+
}
|
1381
|
+
|
1382
|
+
if (dy1 === 0 && dy2 === 0) {
|
1383
|
+
return null;
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
var k1 = dy1 / dx1;
|
1387
|
+
var k2 = dy2 / dx2;
|
1388
|
+
var b1 = p1[1] - k1 * p1[0];
|
1389
|
+
var b2 = p3[1] - k2 * p3[0];
|
1390
|
+
var x, y;
|
1391
|
+
|
1392
|
+
if (dx1 === 0) {
|
1393
|
+
x = p1[0];
|
1394
|
+
y = k2 * x + b2;
|
1395
|
+
} else if (dx2 === 0) {
|
1396
|
+
x = p3[0];
|
1397
|
+
y = k1 * x + b1;
|
1398
|
+
} else if (dy1 === 0) {
|
1399
|
+
y = p1[1];
|
1400
|
+
x = (y - b2) / k2;
|
1401
|
+
} else if (dy2 === 0) {
|
1402
|
+
y = p3[1];
|
1403
|
+
x = (y - b1) / k1;
|
1404
|
+
} else {
|
1405
|
+
x = (b2 - b1) / (k1 - k2);
|
1406
|
+
y = k1 * x + b1;
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
return [x, y];
|
1410
|
+
}
|
1341
1411
|
|
1342
1412
|
function cylinder(point, options) {
|
1343
1413
|
if (options === void 0) {
|
package/package.json
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "poly-extrude",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/poly-extrude.js",
|
6
6
|
"module": "dist/poly-extrude.mjs",
|
7
7
|
"scripts": {
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
9
9
|
"lint": "eslint src/**/*.js",
|
10
|
-
"build": "npm run lint && cross-env NODE_ENV=dev rollup -c"
|
10
|
+
"build": "npm run lint && cross-env NODE_ENV=dev rollup -c",
|
11
|
+
"dev": "npm run lint && cross-env NODE_ENV=dev rollup -c -w"
|
11
12
|
},
|
12
13
|
"repository": {
|
13
14
|
"type": "git",
|
package/src/polyline.js
CHANGED
@@ -122,24 +122,31 @@ function generateSides(result, options) {
|
|
122
122
|
const TEMPV1 = { x: 0, y: 0 }, TEMPV2 = { x: 0, y: 0 };
|
123
123
|
|
124
124
|
export function expandLine(line, options) {
|
125
|
-
let preAngle = 0;
|
125
|
+
// let preAngle = 0;
|
126
126
|
const radius = options.lineWidth / 2;
|
127
127
|
const points = [], leftPoints = [], rightPoints = [];
|
128
128
|
const len = line.length;
|
129
129
|
let i = 0;
|
130
|
-
while (i < len
|
131
|
-
|
130
|
+
while (i < len) {
|
131
|
+
let p1 = line[i],
|
132
132
|
p2 = line[i + 1];
|
133
|
+
const currentp = line[i];
|
134
|
+
// last vertex
|
135
|
+
if (i === len - 1) {
|
136
|
+
p1 = line[len - 2];
|
137
|
+
p2 = line[len - 1];
|
138
|
+
}
|
133
139
|
const dy = p2[1] - p1[1],
|
134
140
|
dx = p2[0] - p1[0];
|
135
141
|
let rAngle = 0;
|
136
142
|
const rad = Math.atan(dy / dx);
|
137
143
|
const angle = radToDeg(rad);
|
138
|
-
preAngle = angle;
|
139
|
-
if (i === 0) {
|
144
|
+
// preAngle = angle;
|
145
|
+
if (i === 0 || i === len - 1) {
|
140
146
|
rAngle = angle;
|
141
147
|
rAngle -= 90;
|
142
148
|
} else {
|
149
|
+
// 至少3个顶点才会触发
|
143
150
|
const p0 = line[i - 1];
|
144
151
|
TEMPV1.x = p0[0] - p1[0];
|
145
152
|
TEMPV1.y = p0[1] - p1[1];
|
@@ -149,7 +156,26 @@ export function expandLine(line, options) {
|
|
149
156
|
rAngle = angle - vAngle / 2;
|
150
157
|
}
|
151
158
|
const rRad = degToRad(rAngle);
|
152
|
-
const
|
159
|
+
const p3 = currentp;
|
160
|
+
const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
|
161
|
+
const p4 = [x, y];
|
162
|
+
const [line1, line2] = translateLine(p1, p2, radius);
|
163
|
+
let op1 = lineIntersection(line1[0], line1[1], p3, p4);
|
164
|
+
let op2 = lineIntersection(line2[0], line2[1], p3, p4);
|
165
|
+
// 平行,回头路
|
166
|
+
if (!op1 || !op2) {
|
167
|
+
const len1 = points.length;
|
168
|
+
const point1 = points[len1 - 2];
|
169
|
+
const point2 = points[len1 - 1];
|
170
|
+
if (!point1 || !point2) {
|
171
|
+
continue;
|
172
|
+
}
|
173
|
+
op1 = [point1[0], point1[1]];
|
174
|
+
op2 = [point2[0], point2[1]];
|
175
|
+
}
|
176
|
+
op1[2] = currentp[2] || 0;
|
177
|
+
op2[2] = currentp[2] || 0;
|
178
|
+
// const [op1, op2] = calOffsetPoint(rRad, radius, p1);
|
153
179
|
points.push(op1, op2);
|
154
180
|
if (leftOnLine(op1, p1, p2)) {
|
155
181
|
leftPoints.push(op1);
|
@@ -160,24 +186,11 @@ export function expandLine(line, options) {
|
|
160
186
|
}
|
161
187
|
i++;
|
162
188
|
}
|
163
|
-
let rAngle = preAngle;
|
164
|
-
rAngle -= 90;
|
165
|
-
const rRad = degToRad(rAngle);
|
166
|
-
const p1 = line[len - 2];
|
167
|
-
const p2 = line[len - 1];
|
168
|
-
const [op1, op2] = calOffsetPoint(rRad, radius, p2);
|
169
|
-
points.push(op1, op2);
|
170
|
-
if (leftOnLine(op1, p1, p2)) {
|
171
|
-
leftPoints.push(op1);
|
172
|
-
rightPoints.push(op2);
|
173
|
-
} else {
|
174
|
-
leftPoints.push(op2);
|
175
|
-
rightPoints.push(op1);
|
176
|
-
}
|
177
189
|
|
178
190
|
return { offsetPoints: points, leftPoints, rightPoints };
|
179
191
|
}
|
180
192
|
|
193
|
+
// eslint-disable-next-line no-unused-vars
|
181
194
|
function calOffsetPoint(rad, radius, p) {
|
182
195
|
const [x, y] = p;
|
183
196
|
const z = p[2] || 0;
|
@@ -202,3 +215,70 @@ function leftOnLine(p, p1, p2) {
|
|
202
215
|
const [x, y] = p;
|
203
216
|
return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
|
204
217
|
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* 平移线
|
221
|
+
* @param {*} p1
|
222
|
+
* @param {*} p2
|
223
|
+
* @param {*} distance
|
224
|
+
* @returns
|
225
|
+
*/
|
226
|
+
function translateLine(p1, p2, distance) {
|
227
|
+
const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
228
|
+
const rad = Math.atan2(dy, dx);
|
229
|
+
const rad1 = rad + Math.PI / 2;
|
230
|
+
let offsetX = Math.cos(rad1) * distance, offsetY = Math.sin(rad1) * distance;
|
231
|
+
const tp1 = [p1[0] + offsetX, p1[1] + offsetY];
|
232
|
+
const tp2 = [p2[0] + offsetX, p2[1] + offsetY];
|
233
|
+
const rad2 = rad - Math.PI / 2;
|
234
|
+
offsetX = Math.cos(rad2) * distance;
|
235
|
+
offsetY = Math.sin(rad2) * distance;
|
236
|
+
const tp3 = [p1[0] + offsetX, p1[1] + offsetY];
|
237
|
+
const tp4 = [p2[0] + offsetX, p2[1] + offsetY];
|
238
|
+
return [[tp1, tp2], [tp3, tp4]];
|
239
|
+
}
|
240
|
+
|
241
|
+
/**
|
242
|
+
* 直线交点
|
243
|
+
* @param {*} p1
|
244
|
+
* @param {*} p2
|
245
|
+
* @param {*} p3
|
246
|
+
* @param {*} p4
|
247
|
+
* @returns
|
248
|
+
*/
|
249
|
+
function lineIntersection(p1, p2, p3, p4) {
|
250
|
+
const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1];
|
251
|
+
const dx2 = p4[0] - p3[0], dy2 = p4[1] - p3[1];
|
252
|
+
if (dx1 === 0 && dx2 === 0) {
|
253
|
+
return null;
|
254
|
+
}
|
255
|
+
if (dy1 === 0 && dy2 === 0) {
|
256
|
+
return null;
|
257
|
+
}
|
258
|
+
|
259
|
+
const k1 = dy1 / dx1;
|
260
|
+
const k2 = dy2 / dx2;
|
261
|
+
|
262
|
+
const b1 = p1[1] - k1 * p1[0];
|
263
|
+
const b2 = p3[1] - k2 * p3[0];
|
264
|
+
|
265
|
+
let x, y;
|
266
|
+
|
267
|
+
if (dx1 === 0) {
|
268
|
+
x = p1[0];
|
269
|
+
y = k2 * x + b2;
|
270
|
+
} else if (dx2 === 0) {
|
271
|
+
x = p3[0];
|
272
|
+
y = k1 * x + b1;
|
273
|
+
} else if (dy1 === 0) {
|
274
|
+
y = p1[1];
|
275
|
+
x = (y - b2) / k2;
|
276
|
+
} else if (dy2 === 0) {
|
277
|
+
y = p3[1];
|
278
|
+
x = (y - b1) / k1;
|
279
|
+
} else {
|
280
|
+
x = (b2 - b1) / (k1 - k2);
|
281
|
+
y = k1 * x + b1;
|
282
|
+
}
|
283
|
+
return [x, y];
|
284
|
+
}
|