markuno_lib 1.2.23 → 1.2.24

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/bin/markcad.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import*as THREE from"three";import{TrianglesDrawMode,TriangleFanDrawMode,TriangleStripDrawMode,Loader,LoaderUtils,FileLoader,MeshPhysicalMaterial,Vector2,Color,LinearSRGBColorSpace,SRGBColorSpace,SpotLight,PointLight,DirectionalLight,Matrix4,Vector3,Quaternion,InstancedMesh,InstancedBufferAttribute,Object3D,TextureLoader,ImageBitmapLoader,BufferAttribute,InterleavedBuffer,InterleavedBufferAttribute,LinearMipmapLinearFilter,NearestMipmapLinearFilter,LinearMipmapNearestFilter,NearestMipmapNearestFilter,LinearFilter,NearestFilter,RepeatWrapping,MirroredRepeatWrapping,ClampToEdgeWrapping,PointsMaterial,Material,LineBasicMaterial,MeshStandardMaterial,DoubleSide,MeshBasicMaterial,PropertyBinding,BufferGeometry,SkinnedMesh,Mesh,LineSegments,Line,LineLoop,Points,Group,PerspectiveCamera,MathUtils,OrthographicCamera,Skeleton,AnimationClip,Bone,InterpolateDiscrete,InterpolateLinear,Texture,VectorKeyframeTrack,NumberKeyframeTrack,QuaternionKeyframeTrack,ColorManagement,FrontSide,Interpolant,Box3,Sphere,CompressedCubeTexture,UnsignedByteType,CompressedArrayTexture,CompressedTexture,DisplayP3ColorSpace,LinearDisplayP3ColorSpace,NoColorSpace,RGBA_ASTC_6x6_Format,RedFormat,RGFormat,RGBAFormat,HalfFloatType,FloatType,DataTexture,Data3DTexture,RGBA_S3TC_DXT1_Format,RGB_PVRTC_4BPPV1_Format,RGB_ETC2_Format,RGB_ETC1_Format,RGBA_S3TC_DXT5_Format,RGBA_PVRTC_4BPPV1_Format,RGBA_ETC2_EAC_Format,RGBA_BPTC_Format,RGBA_ASTC_4x4_Format,MeshPhongMaterial,AdditiveBlending,Float32BufferAttribute}from"three";class Matrix3D{constructor(){this.m=new Float32Array(16),this.st=[],this.init()}init(){return this.m.fill(0),this.m[0]=this.m[5]=this.m[10]=this.m[15]=1,this}atranslate(x,y,z){return this.m[12]+=x,this.m[13]+=y,this.m[14]+=z,this}translate(x,y,z){return x??=0,y??=0,z??=0,this.m[12]+=x*this.m[0]+y*this.m[4]+z*this.m[8],this.m[13]+=x*this.m[1]+y*this.m[5]+z*this.m[9],this.m[14]+=x*this.m[2]+y*this.m[6]+z*this.m[10],this.m[15]+=x*this.m[3]+y*this.m[7]+z*this.m[11],this}rotateX(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateY(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[8]*s,this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[8]=a[0]*-s+a[8]*c,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateZ(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[4]*s,this.m[1]=a[1]*c+a[5]*s,this.m[2]=a[2]*c+a[6]*s,this.m[3]=a[3]*c+a[7]*s,this.m[4]=a[0]*-s+a[4]*c,this.m[5]=a[1]*-s+a[5]*c,this.m[6]=a[2]*-s+a[6]*c,this.m[7]=a[3]*-s+a[7]*c}return this}getdati(){return Array.from(this.m)}setdati(d){if(d&&16===d.length){for(let i=0;i<16;i++)this.m[i]=Number(d[i])||0;return this}this.init()}push(){return this.st.push(new Float32Array(this.m)),this}pop(){return this.st.length>0&&(this.m=this.st.pop()),this}transform(x,y,z=0){return{x:x*this.m[0]+y*this.m[4]+z*this.m[8]+this.m[12],y:x*this.m[1]+y*this.m[5]+z*this.m[9]+this.m[13],z:x*this.m[2]+y*this.m[6]+z*this.m[10]+this.m[14]}}invert(){const m=this.m,inv=new Matrix3D,det=this.determinant();return Math.abs(det)<1e-8?null:(inv.m[0]=(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])/det,inv.m[1]=(m[1]*m[14]*m[11]+m[9]*m[2]*m[15]+m[13]*m[10]*m[3]-m[1]*m[10]*m[15]-m[9]*m[14]*m[3]-m[13]*m[2]*m[11])/det,inv.m[2]=(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])/det,inv.m[3]=(m[1]*m[10]*m[7]+m[5]*m[2]*m[11]+m[9]*m[6]*m[3]-m[1]*m[6]*m[11]-m[5]*m[10]*m[3]-m[9]*m[2]*m[7])/det,inv.m[4]=(m[4]*m[14]*m[11]+m[8]*m[6]*m[15]+m[12]*m[10]*m[7]-m[4]*m[10]*m[15]-m[8]*m[14]*m[7]-m[12]*m[6]*m[11])/det,inv.m[5]=(m[0]*m[10]*m[15]+m[8]*m[14]*m[3]+m[12]*m[2]*m[11]-m[0]*m[14]*m[11]-m[8]*m[2]*m[15]-m[12]*m[10]*m[3])/det,inv.m[6]=(m[0]*m[14]*m[7]+m[4]*m[2]*m[15]+m[12]*m[6]*m[3]-m[0]*m[6]*m[15]-m[4]*m[14]*m[3]-m[12]*m[2]*m[7])/det,inv.m[7]=(m[0]*m[6]*m[11]+m[4]*m[10]*m[3]+m[8]*m[2]*m[7]-m[0]*m[10]*m[7]-m[4]*m[2]*m[11]-m[8]*m[6]*m[3])/det,inv.m[8]=(m[4]*m[9]*m[15]+m[8]*m[13]*m[7]+m[12]*m[5]*m[11]-m[4]*m[13]*m[11]-m[8]*m[5]*m[15]-m[12]*m[9]*m[7])/det,inv.m[9]=(m[0]*m[13]*m[11]+m[8]*m[1]*m[15]+m[12]*m[9]*m[3]-m[0]*m[9]*m[15]-m[8]*m[13]*m[3]-m[12]*m[1]*m[11])/det,inv.m[10]=(m[0]*m[5]*m[15]+m[4]*m[13]*m[3]+m[12]*m[1]*m[7]-m[0]*m[13]*m[7]-m[4]*m[1]*m[15]-m[12]*m[5]*m[3])/det,inv.m[11]=(m[0]*m[9]*m[7]+m[4]*m[1]*m[11]+m[8]*m[5]*m[3]-m[0]*m[5]*m[11]-m[4]*m[9]*m[3]-m[8]*m[1]*m[7])/det,inv.m[12]=(m[4]*m[13]*m[10]+m[8]*m[5]*m[14]+m[12]*m[9]*m[6]-m[4]*m[9]*m[14]-m[8]*m[13]*m[6]-m[12]*m[5]*m[10])/det,inv.m[13]=(m[0]*m[9]*m[14]+m[8]*m[13]*m[2]+m[12]*m[1]*m[10]-m[0]*m[13]*m[10]-m[8]*m[1]*m[14]-m[12]*m[9]*m[2])/det,inv.m[14]=(m[0]*m[13]*m[6]+m[4]*m[1]*m[14]+m[12]*m[5]*m[2]-m[0]*m[5]*m[14]-m[4]*m[13]*m[2]-m[12]*m[1]*m[6])/det,inv.m[15]=(m[0]*m[5]*m[10]+m[4]*m[9]*m[2]+m[8]*m[1]*m[6]-m[0]*m[9]*m[6]-m[4]*m[1]*m[10]-m[8]*m[5]*m[2])/det,inv)}determinant(){const m=this.m;return m[0]*(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])-m[4]*(m[1]*m[10]*m[15]+m[9]*m[14]*m[3]+m[13]*m[2]*m[11]-m[1]*m[14]*m[11]-m[9]*m[2]*m[15]-m[13]*m[10]*m[3])+m[8]*(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])-m[12]*(m[1]*m[6]*m[11]+m[5]*m[10]*m[3]+m[9]*m[2]*m[7]-m[1]*m[10]*m[7]-m[5]*m[2]*m[11]-m[9]*m[6]*m[3])}multiply(matrix){const a=[...this.m],b=matrix.m;return this.m[0]=a[0]*b[0]+a[4]*b[1]+a[8]*b[2]+a[12]*b[3],this.m[1]=a[1]*b[0]+a[5]*b[1]+a[9]*b[2]+a[13]*b[3],this.m[2]=a[2]*b[0]+a[6]*b[1]+a[10]*b[2]+a[14]*b[3],this.m[3]=a[3]*b[0]+a[7]*b[1]+a[11]*b[2]+a[15]*b[3],this.m[4]=a[0]*b[4]+a[4]*b[5]+a[8]*b[6]+a[12]*b[7],this.m[5]=a[1]*b[4]+a[5]*b[5]+a[9]*b[6]+a[13]*b[7],this.m[6]=a[2]*b[4]+a[6]*b[5]+a[10]*b[6]+a[14]*b[7],this.m[7]=a[3]*b[4]+a[7]*b[5]+a[11]*b[6]+a[15]*b[7],this.m[8]=a[0]*b[8]+a[4]*b[9]+a[8]*b[10]+a[12]*b[11],this.m[9]=a[1]*b[8]+a[5]*b[9]+a[9]*b[10]+a[13]*b[11],this.m[10]=a[2]*b[8]+a[6]*b[9]+a[10]*b[10]+a[14]*b[11],this.m[11]=a[3]*b[8]+a[7]*b[9]+a[11]*b[10]+a[15]*b[11],this.m[12]=a[0]*b[12]+a[4]*b[13]+a[8]*b[14]+a[12]*b[15],this.m[13]=a[1]*b[12]+a[5]*b[13]+a[9]*b[14]+a[13]*b[15],this.m[14]=a[2]*b[12]+a[6]*b[13]+a[10]*b[14]+a[14]*b[15],this.m[15]=a[3]*b[12]+a[7]*b[13]+a[11]*b[14]+a[15]*b[15],this}}
2
2
  /** Tolleranza utilizzata per i confronti numerici */
3
- /**
3
+ /**
4
4
  * Classe che rappresenta un punto 2D con coordinate x,y
5
5
  * @class
6
6
  */
@@ -37,7 +37,7 @@ constructor(x,y){Array.isArray(x)?(this.x=x[0]||0,this.y=x[1]||0):x&&"object"==t
37
37
  /**
38
38
  * Crea una nuova linea 2D
39
39
  * @param {number|Object} p1 - Coordinata x del primo punto o oggetto {x,y}
40
- * @param {number|Object} p2 - Coordinata y del primo punto o oggetto {x,y}
40
+ * @param {number|Object} p2 - Coordinata y del primo punto o oggetto {x,y}
41
41
  * @param {number} [x2=null] - Coordinata x del secondo punto (opzionale)
42
42
  * @param {number} [y2=null] - Coordinata y del secondo punto (opzionale)
43
43
  */
@@ -66,7 +66,7 @@ constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&nul
66
66
  * Estende la linea di una certa lunghezza o fino all'intersezione con un'altra linea
67
67
  * @param {number|Linea2} l - Lunghezza di estensione o linea da intersecare
68
68
  * @returns {Linea2} Nuova linea estesa
69
- */estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.intersection(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}
69
+ */estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.interseca(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}puntot(t){return new Punto2(this.p1.x+(this.p2.x-this.p1.x)*t,this.p1.y+(this.p2.y-this.p1.y)*t)}proiezionet(p){const{p1:p1,dx:dx,dy:dy,len2:len2}=this;if(len2<.001)return;const t=((p.x-p1.x)*dx+(p.y-p1.y)*dy)/len2;return{p:new Punto2(p1.x+t*dx,p1.y+t*dy),t:t}}proiezione(p){const r=this.proiezionet(p);return r?r.p:void 0}
70
70
  /**
71
71
  * Calcola il vettore direzione normalizzato della linea
72
72
  * @returns {Punto2} Vettore direzione
@@ -74,7 +74,7 @@ constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&nul
74
74
  /**
75
75
  * Calcola il vettore normale normalizzato della linea
76
76
  * @returns {Punto2} Vettore normale
77
- */get normale(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(-dy/len,dx/len):new Punto2(0,1)}
77
+ */get normale(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(-dy/len,dx/len):new Punto2(0,1)}perpendicolare(p=null,lunghezza=0){const{normale:normale,len:len,p1:p1}=this;if(len<1e-9)return;const l=lunghezza||len,q=p?new Punto2(p):this.p1;return new Linea2(q,new Punto2(q.x+normale.x*l,q.y+normale.y*l))}perpendicolaret(t,lunghezza=0){const{normale:normale,len:len,p1:p1,p2:p2}=this;if(len<1e-9)return;const l=lunghezza||len,q=new Punto2(p1.x+(p2.x-p1.x)*t,p1.y+(p2.y-p1.y)*t);return new Linea2(q,new Punto2(q.x+normale.x*l,q.y+normale.y*l))}
78
78
  /**
79
79
  * Crea una nuova linea ruotata di un certo angolo
80
80
  * @param {number} [angle=Math.PI/2] - Angolo di rotazione in radianti
@@ -106,12 +106,12 @@ constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&nul
106
106
  * @returns {boolean} True se parallele
107
107
  */isparallela(line2){const det=this.dx*line2.dy-this.dy*line2.dx;return Math.abs(det)<1}
108
108
  /**
109
- * Restituisce alcune info sul “quadrilatero” formato da questa linea e da line2,
110
- * assumendo che siano parallele e abbiano verso invertito.
111
- * @param {Linea2} line2
112
- * @returns {Object|undefined}
113
- * { angle, aini, afin, l, distanza } oppure undefined se non parallele o degenere
114
- */infoquad(line2){if(!this.isparallela(line2))return;const{p1:p1,p2:p2,normale:normale}=this;let{p1:p3,p2:p4}=line2;const distance2=(a,b)=>(a.x-b.x)**2+(a.y-b.y)**2;function wrapToPi(theta){return theta>Math.PI?theta-=2*Math.PI:theta<-Math.PI&&(theta+=2*Math.PI),theta}function getangle(a,b){return Math.atan2(b.y-a.y,b.x-a.x)}distance2(p1,p3)>distance2(p1,p4)&&([p3,p4]=[p4,p3]);const baseAng=getangle(p1,p2);function toDeg(x){return Math.round(18e4*x/Math.PI)/1e3}const aini=toDeg(wrapToPi(getangle(p1,p3)-baseAng)),afin=toDeg(wrapToPi(getangle(p2,p4)-baseAng)),l=Math.round(100*this.len)/100,dx=p3.x-p1.x,dy=p3.y-p1.y,distanza=Math.round(100*Math.abs(dx*normale.x+dy*normale.y))/100;return{angle:toDeg(baseAng),aini:aini,afin:afin,l:l,distanza:distanza,sx:Math.round(100*p1.x)/100,sy:Math.round(100*p1.y)/100}}
109
+ * Restituisce alcune info sul “quadrilatero” formato da questa linea e da line2,
110
+ * assumendo che siano parallele e abbiano verso invertito.
111
+ * @param {Linea2} line2
112
+ * @returns {Object|undefined}
113
+ * { angle, aini, afin, l, distanza } oppure undefined se non parallele o degenere
114
+ */infoquad(line2){if(!this.isparallela(line2))return;const{p1:p1,p2:p2,normale:normale}=this;let{p1:p3,p2:p4}=line2;const distance2=(a,b)=>(a.x-b.x)**2+(a.y-b.y)**2;function wrapToPi(theta){return theta>Math.PI?theta-=2*Math.PI:theta<-Math.PI&&(theta+=2*Math.PI),theta}function getangle(a,b){return Math.atan2(b.y-a.y,b.x-a.x)}distance2(p1,p3)>distance2(p1,p4)&&([p3,p4]=[p4,p3]);const baseAng=getangle(p1,p2);function toDeg(x){return Math.round(18e4*x/Math.PI)/1e3}const aini=toDeg(wrapToPi(getangle(p1,p3)-baseAng)),afin=toDeg(wrapToPi(getangle(p2,p4)-baseAng)),l=Math.round(100*this.len)/100,dx=p3.x-p1.x,dy=p3.y-p1.y,distanza=Math.round(100*Math.abs(dx*normale.x+dy*normale.y))/100;return{angle:toDeg(baseAng),aini:aini,afin:afin,l:l,distanza:distanza,sx:Math.round(100*p1.x)/100,sy:Math.round(100*p1.y)/100}}
115
115
  /**
116
116
  * Verifica se la linea è perpendicolare a un'altra
117
117
  * @param {Linea2} line2 - Seconda linea
@@ -163,15 +163,14 @@ constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&nul
163
163
  * @param {boolean} [highestQuality=false] - Se `true`, salta il passaggio di
164
164
  * semplificazione radiale e usa solo Douglas–Peucker per massima qualità.
165
165
  * @returns {Array<{x:number,y:number}>} Nuovo array di punti semplificato.
166
- */
166
+ */function mapvertices(pat1,pat2){const dist2=(a,b)=>(a.x-b.x)**2+(a.y-b.y)**2;let n1=pat1.length,n2=pat2.length;if(n1<2||n2<2)return[];let map=[[0,0]];if(n1===n2){for(let i=1;i<n1;i++)map.push([i,i]);return map}if(n1>n2)for(let i=1,j=0;i<n1-1;i++){if(j+1<n2){const p=pat1[i],d1=dist2(p,pat2[j]);dist2(p,pat2[j+1])<=d1&&j++}map.push([i,j])}else for(let i=1,j=0;i<n2-1;i++){if(j+1<n1){const p=pat2[i],d1=dist2(p,pat1[j]);dist2(p,pat1[j+1])<=d1&&j++}map.push([j,i])}return map.push([n1-1,n2-1]),map}
167
167
  /**
168
168
  * Calcola i punti di un arco DXF dato p1, p2, bulge e n punti intermedi.
169
169
  * p1, p2: oggetti {x, y}
170
170
  * bulge: valore DXF tra p1 e p2
171
171
  * n: numero di punti INTERMEDI da inserire tra p1 e p2 (n=0 -> solo estremi)
172
172
  * Return: array di punti [{x, y}, ..., {x, y}]
173
- */
174
- function dxfbulge(p1,p2,bulge,n=0){const points=[];if(!bulge||Math.abs(bulge)<1e-10||0===n)return points;const theta=4*Math.atan(bulge);if(theta<0)return dxfbulge(p2,p1,-bulge,n).reverse();const dx=p2.x-p1.x,dy=p2.y-p1.y,chord=Math.hypot(dx,dy),r=chord/(2*Math.sin(theta/2)),mx=(p1.x+p2.x)/2,my=(p1.y+p2.y)/2,nx=-dy/chord,ny=dx/chord,d=r*Math.cos(theta/2),sign=bulge>=0?1:-1,cx=mx+sign*nx*d,cy=my+sign*ny*d;let a1=Math.atan2(p1.y-cy,p1.x-cx);for(let i=1;i<=n;i++){const a=a1+i/(n+1)*theta,x=cx+r*Math.cos(a),y=cy+r*Math.sin(a);points.push({x:x,y:y})}return points}
173
+ */function dxfbulge(p1,p2,bulge,n=0){const points=[];if(!bulge||Math.abs(bulge)<1e-10||0===n)return points;const theta=4*Math.atan(bulge);if(theta<0)return dxfbulge(p2,p1,-bulge,n).reverse();const dx=p2.x-p1.x,dy=p2.y-p1.y,chord=Math.hypot(dx,dy),r=chord/(2*Math.sin(theta/2)),mx=(p1.x+p2.x)/2,my=(p1.y+p2.y)/2,nx=-dy/chord,ny=dx/chord,d=r*Math.cos(theta/2),sign=bulge>=0?1:-1,cx=mx+sign*nx*d,cy=my+sign*ny*d;let a1=Math.atan2(p1.y-cy,p1.x-cx);for(let i=1;i<=n;i++){const a=a1+i/(n+1)*theta,x=cx+r*Math.cos(a),y=cy+r*Math.sin(a);points.push({x:x,y:y})}return points}
175
174
  /**
176
175
  * Crea una curva di Bézier quadratica tra due segmenti di linea.
177
176
  * @param {Object} a1 - Punto iniziale del primo segmento {x,y}
@@ -228,7 +227,7 @@ function raccordabezier(a1,a2,b1,b2,subdivisions=10){const intersection=function
228
227
 
229
228
  * @returns {Array<Object>} Array di punti con normali e coordinate UV
230
229
  */
231
- /**
230
+ /*
232
231
  * Crea un oggetto shape per manipolare forme 2D
233
232
  * @returns {Object} Oggetto con metodi per manipolare la forma
234
233
  * @property {string} key - Hash univoco della forma
@@ -260,7 +259,8 @@ function getshape(){let pt=[];
260
259
  /**
261
260
  * Converte i punti in array di coordinate
262
261
  * @returns {Array<number>} Array [x1,y1,x2,y2,...]
263
- */function tovec(){return pt.flatMap((p=>[p.x,p.y]))}function move(x=0,y=0){"object"==typeof x&&x.x&&(y=x.y||0,x=x.x);for(let p of pt)p.x+=x,p.y+=y;return this}
262
+ */
263
+ function tovec(){return pt.flatMap((p=>[p.x,p.y]))}function move(x=0,y=0){"object"==typeof x&&x.x&&(y=x.y||0,x=x.x);for(let p of pt)p.x+=x,p.y+=y;return this}
264
264
  /**
265
265
  * Verifica se un punto è interno al poligono usando ray casting
266
266
  * @param {Object} P - Punto da verificare {x,y}
@@ -270,7 +270,7 @@ function getshape(){let pt=[];
270
270
  * Aggiunge punti da array di coordinate
271
271
  * @param {Array<number>} aa - Array [x1,y1,x2,y2,...]
272
272
  */
273
- function _addvec(aa){for(let i=0;i<aa.length;i+=2)pt.push({x:aa[i],y:aa[i+1]})}function fromstr(str){return pt=removeduplicate(function processTokens(tokens){const points=[];for(let i=0;i<tokens.length;i++){const token=tokens[i];if("point"===token.type)points.push(token.point);else if("command"===token.type)switch(token.cmd){case"x":{const p1=points[points.length-1],p2="point"===tokens[i+1]?.type?tokens[i+1].point:points[0],bulge=parseFloat(token.params[0])||5;{const STEP=1;let dx=p2.x-p1.x,dy=p2.y-p1.y,dist=Math.hypot(dx,dy);dist>1&&points.push(...dxfbulge(p1,p2,bulge,Math.floor((dist-STEP)/(STEP+2))+1))}break}case"b":{if(points.length<2)continue;const npt=parseInt(token.params[0])||5,p1=points[points.length-2],p2=points[points.length-1];let p3="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p4="point"===tokens[i+2]?.type?tokens[i+2].point:void 0;p3?p4||(p4=points[0]):(p3=points[0],p4=points[1]);const raccordo=raccordabezier(p1,p2,p3,p4,npt);points.push(...raccordo),i+=1;break}case"r":{if(points.length<1)continue;const dist=parseFloat(token.params[0])||5,npt=parseInt(token.params[1])||10,p1=points[points.length-1];let p2="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p3="point"===tokens[i+2]?.type?tokens[i+2].point:"point"===tokens[i+3]?.type?tokens[i+3].point:void 0;p2?p3||(p3=points[0]):(p2=points[0],p3=points[1],points.splice(0,1));const raccordo=raccordabezier3(p1,p2,p3,dist,npt);points.push(...raccordo),i+=1;break}case"c":{const radius=parseFloat(token.params[0])||50,segments=parseInt(token.params[1])||12,center="point"===tokens[i+1]?.type?tokens[i+1].point:new Punto2(0,0);for(let j=0;j<segments;j++)points.push(new Punto2(center.x+radius*Math.cos(j/segments*Math.PI*2),center.y+radius*Math.sin(j/segments*Math.PI*2)));i+=1;break}case"a":{let npt,p1="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p2="point"===tokens[i+2]?.type?tokens[i+2].point:void 0,p3="point"===tokens[i+3]?.type?tokens[i+3].point:void 0;if(!p1||!p3)continue;if(p2)if(token.params[0])npt=clamp(parseInt(token.params[0]),1,24);else{const chord=Math.hypot(p3.x-p1.x,p3.y-p1.y),sagitta=Math.abs((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))/(2*chord);npt=Math.round(chord*Math.sqrt(sagitta/(chord+.1))*10),npt=clamp(npt,1,24),npt=1}else p2=p3,npt=0;const arcoPoints=arcfrom3point(npt,p1,p2,p3);points.push(...arcoPoints),i+=3;break}}}return points}(function tokenize(str){const tokens=[],values=str.replace(/[\n\r,;]/g," ").replace(/\s+/g," ").toLowerCase().trim().split(" ").filter((s=>s.length>0));let i=0;for(;i<values.length;){const val=values[i];/^[brcax]/.test(val)?(tokens.push({type:"command",cmd:val[0],params:val.slice(1).split(":")}),i++):i<values.length-1&&/^-?\d+(\.\d+)?$/.test(values[i])&&/^-?\d+(\.\d+)?$/.test(values[i+1])?(tokens.push({type:"point",point:new Punto2(parseFloat(values[i]),parseFloat(values[i+1]))}),i+=2):i++}return tokens}(str))),this}function dims(pts){let{p1:p1,p2:p2}=pts.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}),isrect=!1;if(4==pts.length){const TOLL=.001;function findpunto(x,y){let f=pts.find((p=>Math.abs(p.x-x)<TOLL&&Math.abs(p.y-y)<TOLL));return!!f}findpunto(p1.x,p1.y)&&findpunto(p1.x,p2.y)&&findpunto(p2.x,p1.y)&&findpunto(p2.x,p2.y)&&(isrect=!0)}return{p1:p1,p2:p2,isrect:isrect,width:p2.x-p1.x,height:p2.y-p1.y}}return{get key(){return hash(tovec().join("\t"))},orienta:function orienta(p0,p1){if(!p0||!p1)return null;const dx=p1.x-p0.x,dy=p1.y-p0.y,angolo=180*Math.atan2(dy,dx)/Math.PI,matrix=new Matrix3D;matrix.rotateZ(-angolo),matrix.translate(-p0.x,-p0.y,0);const ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y)));let mm=ptTrasformati.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)});return{shape:getshape().frompt(ptTrasformati),origine:new Punto2(p0.x,p0.y),angolo:angolo,mm:mm,width:mm.p2.x-mm.p1.x,height:mm.p2.y-mm.p1.y}},rebase:function rebase(angolo,forceorigin=!1,ox=0,oy=0){const matrix=new Matrix3D;matrix.rotateZ(-angolo);let ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y))),{p1:p1,p2:p2,width:width,height:height}=dims(ptTrasformati);return forceorigin||(ox=p1.x,oy=p1.y),ptTrasformati=ptTrasformati.map((p=>new Punto2(p.x-ox,p.y-oy))),{shape:getshape().frompt(ptTrasformati),origine:new Punto2(ox,oy),angolo:angolo,width:width,height:height}},fromstr:fromstr,move:move,get pt(){return pt},get vec(){return tovec()},toJSON:()=>({vec:tovec(),orient:orientation()}),get orient(){return orientation()},corners:(angolo=45)=>
273
+ function _addvec(aa){for(let i=0;i<aa.length;i+=2)pt.push({x:aa[i],y:aa[i+1]})}function fromstr(str){return pt=removeduplicate(function processTokens(tokens){const points=[];for(let i=0;i<tokens.length;i++){const token=tokens[i];if("point"===token.type)points.push(token.point);else if("command"===token.type)switch(token.cmd){case"x":{const p1=points[points.length-1],p2="point"===tokens[i+1]?.type?tokens[i+1].point:points[0],bulge=parseFloat(token.params[0])||5;{const STEP=1;let dx=p2.x-p1.x,dy=p2.y-p1.y,dist=Math.hypot(dx,dy);dist>1&&points.push(...dxfbulge(p1,p2,bulge,Math.floor((dist-STEP)/(STEP+2))+1))}break}case"b":{if(points.length<2)continue;const npt=parseInt(token.params[0])||5,p1=points[points.length-2],p2=points[points.length-1];let p3="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p4="point"===tokens[i+2]?.type?tokens[i+2].point:void 0;p3?p4||(p4=points[0]):(p3=points[0],p4=points[1]);const raccordo=raccordabezier(p1,p2,p3,p4,npt);points.push(...raccordo),i+=1;break}case"r":{if(points.length<1)continue;const dist=parseFloat(token.params[0])||5,npt=parseInt(token.params[1])||10,p1=points[points.length-1];let p2="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p3="point"===tokens[i+2]?.type?tokens[i+2].point:"point"===tokens[i+3]?.type?tokens[i+3].point:void 0;p2?p3||(p3=points[0]):(p2=points[0],p3=points[1],points.splice(0,1));const raccordo=raccordabezier3(p1,p2,p3,dist,npt);points.push(...raccordo),i+=1;break}case"c":{const radius=parseFloat(token.params[0])||50,segments=parseInt(token.params[1])||12,center="point"===tokens[i+1]?.type?tokens[i+1].point:new Punto2(0,0);for(let j=0;j<segments;j++)points.push(new Punto2(center.x+radius*Math.cos(j/segments*Math.PI*2),center.y+radius*Math.sin(j/segments*Math.PI*2)));i+=1;break}case"a":{let npt,p1="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p2="point"===tokens[i+2]?.type?tokens[i+2].point:void 0,p3="point"===tokens[i+3]?.type?tokens[i+3].point:void 0;if(!p1||!p3)continue;if(p2)if(token.params[0])npt=clamp(parseInt(token.params[0]),1,24);else{const chord=Math.hypot(p3.x-p1.x,p3.y-p1.y),sagitta=Math.abs((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))/(2*chord);npt=Math.round(chord*Math.sqrt(sagitta/(chord+.1))*10),npt=clamp(npt,1,24),npt=1}else p2=p3,npt=0;const arcoPoints=arcfrom3point(npt,p1,p2,p3);points.push(...arcoPoints),i+=3;break}}}return points}(function tokenize(str){const tokens=[],values=str.replace(/[\n\r,;]/g," ").replace(/\s+/g," ").toLowerCase().trim().split(" ").filter((s=>s.length>0));let i=0;for(;i<values.length;){const val=values[i];/^[brcax]/.test(val)?(tokens.push({type:"command",cmd:val[0],params:val.slice(1).split(":")}),i++):i<values.length-1&&/^-?\d+(\.\d+)?$/.test(values[i])&&/^-?\d+(\.\d+)?$/.test(values[i+1])?(tokens.push({type:"point",point:new Punto2(parseFloat(values[i]),parseFloat(values[i+1]))}),i+=2):i++}return tokens}(str))),this}function dims(pts){let{p1:p1,p2:p2}=pts.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}),isrect=!1;if(4==pts.length){const TOLL=.001;function findpunto(x,y){let f=pts.find((p=>Math.abs(p.x-x)<TOLL&&Math.abs(p.y-y)<TOLL));return!!f}findpunto(p1.x,p1.y)&&findpunto(p1.x,p2.y)&&findpunto(p2.x,p1.y)&&findpunto(p2.x,p2.y)&&(isrect=!0)}return{p1:p1,p2:p2,isrect:isrect,width:p2.x-p1.x,height:p2.y-p1.y}}return{get key(){return hash(tovec().join("\t"))},orienta:function orienta(p0,p1){if(!p0||!p1)return null;const dx=p1.x-p0.x,dy=p1.y-p0.y,angolo=180*Math.atan2(dy,dx)/Math.PI,matrix=new Matrix3D;matrix.rotateZ(-angolo),matrix.translate(-p0.x,-p0.y,0);const ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y)));let mm=ptTrasformati.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)});return{shape:getshape().frompt(ptTrasformati),origine:new Punto2(p0.x,p0.y),angolo:angolo,mm:mm,width:mm.p2.x-mm.p1.x,height:mm.p2.y-mm.p1.y}},rebase:function rebase(angolo,forceorigin=!1,ox=0,oy=0){const matrix=new Matrix3D;matrix.rotateZ(-angolo);let ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y))),{p1:p1,p2:p2,width:width,height:height}=dims(ptTrasformati);return forceorigin||(ox=p1.x,oy=p1.y),ptTrasformati=ptTrasformati.map((p=>new Punto2(p.x-ox,p.y-oy))),{shape:getshape().frompt(ptTrasformati),origine:new Punto2(ox,oy),angolo:angolo,width:width,height:height}},fromstr:fromstr,move:move,get pt(){return pt},set pt(val){Array.isArray(val)&&(pt=val)},get npt(){return pt?.length||0},get vec(){return tovec()},toJSON:()=>({vec:tovec(),orient:orientation()}),get orient(){return orientation()},corners:(angolo=45)=>
274
274
  /**
275
275
  * Trova i punti in cui l’angolo interno è maggiore di `thresholdDeg`.
276
276
  *
@@ -278,7 +278,7 @@ function _addvec(aa){for(let i=0;i<aa.length;i+=2)pt.push({x:aa[i],y:aa[i+1]})}f
278
278
  * @param {number} thresholdDeg - Angolo in gradi.
279
279
  * @returns {Array<{ index: number, point: {x:number,y:number}, angle: number }>}
280
280
  */
281
- function sharpCorners(path,thresholdDeg=45){const result=[],n=path.length;if(n<3)return result;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],curr=path[i],next=path[(i+1)%n],ux=curr.x-prev.x,uy=curr.y-prev.y,vx=next.x-curr.x,vy=next.y-curr.y,magU=Math.hypot(ux,uy),magV=Math.hypot(vx,vy);if(0===magU||0===magV)continue;let cosTheta=(ux*vx+uy*vy)/(magU*magV);cosTheta=Math.max(-1,Math.min(1,cosTheta));const angleDeg=180*Math.acos(cosTheta)/Math.PI;angleDeg>thresholdDeg&&result.push({i:i,x:curr.x,y:curr.y,a:angleDeg})}return result}(pt,45),clone:()=>getshape().frompt(pt),dims:()=>dims(pt),get area(){return Math.abs(pt.reduce(((acc,curr,i)=>{const next=pt[(i+1)%pt.length];return acc+(curr.x*next.y-next.x*curr.y)}),0)/2)},alignline(p1,p2){return pt=function stretchShapeToLine(shapePts,p1,p2){if(!shapePts?.length||!p1||!p2)return[];const first=shapePts[0],last=shapePts[shapePts.length-1],dx=last.x-first.x,dy=last.y-first.y,ang=Math.atan2(dy,dx);let pts0=shapePts.map((p=>({x:p.x-first.x,y:p.y-first.y}))),pts1=pts0.map((p=>({x:p.x*Math.cos(-ang)-p.y*Math.sin(-ang),y:p.x*Math.sin(-ang)+p.y*Math.cos(-ang)})));const linea={dx:p2.x-p1.x,dy:p2.y-p1.y},scaleX=Math.sqrt(linea.dx*linea.dx+linea.dy*linea.dy)/(pts1[pts1.length-1].x||1e-8);let pts2=pts1.map((p=>({x:p.x*scaleX,y:p.y})));const angDest=Math.atan2(linea.dy,linea.dx);let pts3=pts2.map((p=>({x:p.x*Math.cos(angDest)-p.y*Math.sin(angDest),y:p.x*Math.sin(angDest)+p.y*Math.cos(angDest)}))),ptsFinal=pts3.map((p=>({x:p.x+p1.x,y:p.y+p1.y})));return ptsFinal}(pt,p1,p2),this},rotate(deg){if(!deg)return this;const r=deg*Math.PI/180,cosTheta=Math.cos(r),sinTheta=Math.sin(r);for(let p of pt){const xNew=p.x*cosTheta-p.y*sinTheta,yNew=p.x*sinTheta+p.y*cosTheta;p.x=xNew,p.y=yNew}return this},selezionaprimo:selezionaprimo,
281
+ function sharpCorners(path,thresholdDeg=45){const result=[],n=path.length;if(n<3)return result;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],curr=path[i],next=path[(i+1)%n],ux=curr.x-prev.x,uy=curr.y-prev.y,vx=next.x-curr.x,vy=next.y-curr.y,magU=Math.hypot(ux,uy),magV=Math.hypot(vx,vy);if(0===magU||0===magV)continue;let cosTheta=(ux*vx+uy*vy)/(magU*magV);cosTheta=Math.max(-1,Math.min(1,cosTheta));const angleDeg=180*Math.acos(cosTheta)/Math.PI;angleDeg>thresholdDeg&&result.push({i:i,x:curr.x,y:curr.y,a:angleDeg})}return result}(pt,45),clone:()=>getshape().frompt(pt),dims:()=>dims(pt),get area(){return Math.abs(pt.reduce(((acc,curr,i)=>{const next=pt[(i+1)%pt.length];return acc+(curr.x*next.y-next.x*curr.y)}),0)/2)},pointslink(sh2){let map=mapvertices(pt,sh2.pt),plink=[];for(let m of map)plink[m[0]]=sh2.pt[m[1]];return plink},alignline(p1,p2){return pt=function stretchShapeToLine(shapePts,p1,p2){if(!shapePts?.length||!p1||!p2)return[];const first=shapePts[0],last=shapePts[shapePts.length-1],dx=last.x-first.x,dy=last.y-first.y,ang=Math.atan2(dy,dx);let pts0=shapePts.map((p=>({x:p.x-first.x,y:p.y-first.y}))),pts1=pts0.map((p=>({x:p.x*Math.cos(-ang)-p.y*Math.sin(-ang),y:p.x*Math.sin(-ang)+p.y*Math.cos(-ang)})));const linea={dx:p2.x-p1.x,dy:p2.y-p1.y},scaleX=Math.sqrt(linea.dx*linea.dx+linea.dy*linea.dy)/(pts1[pts1.length-1].x||1e-8);let pts2=pts1.map((p=>({x:p.x*scaleX,y:p.y})));const angDest=Math.atan2(linea.dy,linea.dx);let pts3=pts2.map((p=>({x:p.x*Math.cos(angDest)-p.y*Math.sin(angDest),y:p.x*Math.sin(angDest)+p.y*Math.cos(angDest)}))),ptsFinal=pts3.map((p=>({x:p.x+p1.x,y:p.y+p1.y})));return ptsFinal}(pt,p1,p2),this},rotate(deg){if(!deg)return this;const r=deg*Math.PI/180,cosTheta=Math.cos(r),sinTheta=Math.sin(r);for(let p of pt){const xNew=p.x*cosTheta-p.y*sinTheta,yNew=p.x*sinTheta+p.y*cosTheta;p.x=xNew,p.y=yNew}return this},selezionaprimo:selezionaprimo,
282
282
  /**
283
283
  * Trova i punti in cui l’angolo interno è maggiore di `thresholdDeg`.
284
284
  *
@@ -286,7 +286,7 @@ function sharpCorners(path,thresholdDeg=45){const result=[],n=path.length;if(n<3
286
286
  * @param {number} thresholdDeg - Angolo in gradi.
287
287
  * @returns {Array<{ index: number, point: {x:number,y:number}, angle: number }>}
288
288
  */
289
- segment(i,inverse=!1){let n=pt.length;return i<0&&(i+=n),new Linea2(pt[i%n],pt[(i+(inverse?-1:1))%n])},lineoffset(i1,i2,offset){if((i1=(i1||0)%pt.length)!=(i2=(i2||0)%pt.length)){let l2=new Linea2(pt[i1],pt[i2]);if(l2){return l2=l2.offsetline(-offset),this.intersectline(l2)}}},orientasplitter(){-1!=orientation()&&pt.reverse();let np=pt.length;for(let i=0;i<np;i++){let lt=new Linea2(pt[(np+i-1)%np],pt[i]);if(Math.abs(Math.abs(lt.angle)-Math.PI)<.001){i&&selezionaprimo(i);break}}return this},mirrorx(value=0){for(let p of pt)p.x=2*value-p.x;return this},mirrory(value=0){for(let p of pt)p.y=2*value-p.y;return this},simplify(tolerance,hq){return pt=function simplify(points,tolerance,highestQuality){if(points.length<=2)return points;var sqTolerance=void 0!==tolerance?tolerance*tolerance:1;return simplifyDouglasPeucker(points=highestQuality?points:function simplifyRadialDist(points,sqTolerance){for(var point,p1,p2,dx,dy,prevPoint=points[0],newPoints=[prevPoint],i=1,len=points.length;i<len;i++)p2=prevPoint,dx=void 0,dy=void 0,(dx=(p1=point=points[i]).x-p2.x)*dx+(dy=p1.y-p2.y)*dy>sqTolerance&&(newPoints.push(point),prevPoint=point);return prevPoint!==point&&newPoints.push(point),newPoints}(points,sqTolerance),sqTolerance)}(pt,tolerance,hq),this},fromclip(vv){pt=[];for(let p of vv)pt.push({x:p.x/1e3,y:p.y/1e3});return this},infosegmento(i,open=!1){const n=pt.length;function clampIndex(idx){return(idx+n)%n}function angle(p1,p2){return Math.atan2(p2.y-p1.y,p2.x-p1.x)}function angleDiff(a,b){let diff=a-b;for(;diff>Math.PI;)diff-=2*Math.PI;for(;diff<-Math.PI;)diff+=2*Math.PI;return diff}const p1=pt[i];let p0,p2,p3;if(open)if(0===i){const dx=pt[1].x-pt[0].x,dy=pt[1].y-pt[0].y;p0={x:pt[0].x-dx,y:pt[0].y-dy},p2=pt[1],p3=pt[2]}else if(i===n-1){const dx=pt[n-1].x-pt[n-2].x,dy=pt[n-1].y-pt[n-2].y;p0=pt[n-2],p2={x:pt[n-1].x+dx,y:pt[n-1].y+dy},p3={x:p2.x+dx,y:p2.y+dy}}else p0=pt[i-1],p2=pt[i+1],p3=i+2<n?pt[i+2]:{x:pt[i+1].x+(pt[i+1].x-pt[i].x),y:pt[i+1].y+(pt[i+1].y-pt[i].y)};else{const i0=clampIndex(i-1),i2=clampIndex(i+1),i3=clampIndex(i+2);p0=pt[i0],p2=pt[i2],p3=pt[i3]}const ang12=angle(p1,p2),ang01=angle(p0,p1),ang23=angle(p2,p3);return{x:p1.x,y:p1.y,l:function length(p1,p2){const dx=p2.x-p1.x,dy=p2.y-p1.y;return Math.sqrt(dx*dx+dy*dy)}(p1,p2),ang:ang12/PIF,a1:angleDiff(ang12,ang01)/PIF,a2:angleDiff(ang23,ang12)/PIF}},swapxy(){for(let i=0;i<pt.length;i++){let q=pt[i].x;pt[i].x=-pt[i].y,pt[i].y=-q}return this},fromvec(aa){return pt=[],_addvec(aa),this},addvec(vec){return _addvec(vec),this},frompt(pts){return pt=[...pts],pt=removeduplicate(pt),this},fromdxfvec(verts){let points=[];if(verts&&verts.length)for(let i=0;i<verts.length;i++){let{x:x,y:y,bulge:bulge}=verts[i];if(points.push({x:x,y:y}),bulge){const step=1;let p1={x:x,y:y},p2=verts[(i+1)%verts.length],dx=p2.x-p1.x,dy=p2.y-p1.y,dist=Math.hypot(dx,dy);dist>step&&points.push(...dxfbulge(p1,p2,bulge,Math.floor((dist-step)/step)+1))}}return pt=points.map((e=>({x:Math.round(10*e.x)/10,y:Math.round(10*e.y)/10}))),pt=removeduplicate(pt),this},monotona(){let dxd=dims(pt),pp=pt.map((e=>({x:e.x-dxd.p2.x,y:e.y}))),xp=[];xp.push(pp[0]);let lastv=pp[0].y;for(let i=1;i<pp.length;i++)if(pp[i].y>lastv+1e-4||i==pp.length-1)xp.push(pp[i]),lastv=pp[i].y;else{const newv=lastv+1e-4;xp.push({x:pp[i].x,y:newv}),lastv=newv}return{sh:getshape().frompt(xp),...dxd}},sliceony(stag){let yvalues=stag.pt.map((e=>e.y)).slice(1,-1);const res=[],n=pt.length;let imin=0,yMin=pt[0].y;for(let i=1;i<n;i++)pt[i].y<yMin&&(yMin=pt[i].y,imin=i);const pts=[...pt.slice(imin),...pt.slice(0,imin)],m=pts.length,ymap=new Map;for(let i=0;i<m;i++)for(let y of yvalues)Math.abs(pts[i].y-y)<1e-5&&(ymap.has(y)?ymap.get(y).i2=i:ymap.set(y,{i1:i,i2:i}));const pairs=yvalues.map((y=>ymap.get(y))).filter((p=>p&&p.i1>=0&&p.i2>=0));pairs.length>0&&pairs[0].i1>0&&res.push([...pts.slice(0,pairs[0].i1+1),...pts.slice(pairs[0].i2,pairs[0].length)]);for(let i=0;i<pairs.length-1;i++){const a=pairs[i],b=pairs[i+1];res.push([...pts.slice(a.i1,b.i1+1),...pts.slice(b.i2,a.i2+1)])}const last=pairs[pairs.length-1];last.i2>last.i1&&res.push(pts.slice(last.i1,last.i2+1));return res.filter((arr=>arr.length>0))},splitshape(p,verticale=!0){const p1=verticale?{x:p.x,y:p.y-100}:{x:p.x-100,y:p.y},p2=verticale?{x:p.x,y:p.y+100}:{x:p.x+100,y:p.y},linea=this.intersectline(new Linea2(p1,p2));if(!linea)return null;const pstart=linea.p1,pend=linea.p2,findIndex=pt=>this.pt.findIndex(((v,i)=>new Linea2(v,this.pt[(i+1)%this.pt.length]).onsegment(pt))),i1=findIndex(pstart),i2=findIndex(pend);if(i1<0||i2<0)return null;const n=this.pt.length,loop=(a,b,p0,p1)=>{const res=[];for(let i=a;i!==b;i=(i+1)%n)res.push(this.pt[(i+1)%n]);return res},dx=getshape().frompt(loop(i1,i2));return{sx:getshape().frompt(loop(i2,i1)),dx:dx,linea:linea}},xfromy(y,valore0=0,maggiore=!0){const res=[],n=this.pt.length;for(let i=0;i<n-1;i++){const p1=this.pt[i],p2=this.pt[i+1];if(p1.y<=y&&p2.y>=y||p2.y<=y&&p1.y>=y){const dy=p2.y-p1.y,t=dy?(y-p1.y)/dy:0,x=p1.x+t*(p2.x-p1.x);res.push(x)}else p1.y===y&&p2.y===y&&res.push(maggiore?Math.max(p1.x,p2.x):Math.min(p1.x,p2.x))}return res.length?maggiore?Math.max(...res):Math.min(...res):valore0},yfromx(x,valore0=0,maggiore=!0){const res=[],n=this.pt.length;for(let i=0;i<n-1;i++){const p1=this.pt[i],p2=this.pt[i+1];if(p1.x<=x&&p2.x>=x||p2.x<=x&&p1.x>=x){const dx=p2.x-p1.x,t=dx?(x-p1.x)/dx:0,y=p1.y+t*(p2.y-p1.y);res.push(y)}else p1.x===x&&p2.x===x&&res.push(maggiore?Math.max(p1.y,p2.y):Math.min(p1.y,p2.y))}return res.length?maggiore?Math.max(...res):Math.min(...res):valore0},forcevalues(shape,verticale=!0,delta=1e-6){const sorted=[...new Set(shape.pt.map((e=>verticale?e.y:e.x)))].sort(((a,b)=>a-b)),newpt=[],n=pt.length;for(let i=0;i<n;i++){const p1=pt[i],p2=pt[(i+1)%n];newpt.push({...p1});let v1=verticale?p1.y:p1.x,v2=verticale?p2.y:p2.x;if(v1===v2)continue;const range=v2>v1?sorted.filter((v=>v>v1+delta&&v<v2-delta)):sorted.filter((v=>v<v1-delta&&v>v2+delta)).reverse();for(const v of range){const t=(v-v1)/(v2-v1),q={x:p1.x+t*(p2.x-p1.x),y:p1.y+t*(p2.y-p1.y)};newpt.push(q)}}return pt=newpt,this},fromrrect(w,h,r=10,sx=0,sy=0){return(r>=w/2||r>=h/2&&r<=0)&&(r=Math.round(Math.min(w/3,h/3))),fromstr(`0,0,r${r},${w},0,r${r},${w},${h},r${r},0,${h},r${r}`),(sx||sy)&&move(sx,sy),this},fromrect(w,h,sx,sy,bordo){w||(w=10),h||(h=10),bordo||(bordo=0),bordo=Math.min(Math.abs(bordo),Math.abs(.4*w),Math.abs(.4*h));let b1=w>0?bordo:-bordo,b2=h>0?bordo:-bordo;return pt=bordo?[{x:b1,y:0},{x:w-b1,y:0},{x:w,y:b2},{x:w,y:h-b2},{x:w-b1,y:h},{x:b1,y:h},{x:0,y:h-b2},{x:0,y:b2}]:[{x:0,y:0},{x:w,y:0},{x:w,y:h},{x:0,y:h}],this},intersectline:l=>function _intersectline(shape,p3,p4){let n=shape.length,l=new Linea2(p3,p4);const intersezioni=[];for(let i=0;i<shape.length;i++){let l2=new Linea2(shape[i],shape[(i+1)%n]),p=l2.interseca(l);p&&l2.onsegment(p)&&intersezioni.push(p)}if(intersezioni.length<2)return null;const{dx:dx,dy:dy}=l;intersezioni.sort(((a,b)=>(a.x-p3.x)*dx+(a.y-p3.y)*dy-((b.x-p3.x)*dx+(b.y-p3.y)*dy)));let pstart=new Punto2(intersezioni[0].x,intersezioni[0].y),pend=new Punto2(intersezioni[intersezioni.length-1].x,intersezioni[intersezioni.length-1].y);const vx1=pend.x-pstart.x,vy1=pend.y-pstart.y;return vx1*dx+vy1*dy<0&&([pstart,pend]=[pend,pstart]),new Linea2(pstart,pend)}(pt,l.p1,l.p2),tostr(dec=2){let dd=10**dec,pstr=x=>String(Math.round(x*dd)/dd),cl=pt.map((e=>`${pstr(e.x)};${pstr(e.y)};`)).join("");return cl&&cl.length?cl.slice(0,-1).match(/.{1,80}(;|$)/g).map((s=>s.trim())).join("\n"):""},addpt(pts){return pts?(Array.isArray(pts)||(pts=[pts]),pt=removeduplicate([...pt,...pts]),this):this},addracc(v1,v2,suddivisioni=2,addv1v2=!0){if(Array.isArray(v1)&&(v2={x:v1[2]||0,y:v1[3]||0},v1={x:v1[0]||0,y:v1[1]||0}),pt.length>=2){let tm=raccordabezier(pt[pt.length-2],pt[pt.length-1],v1,v2,suddivisioni);pt=[...pt,...tm],addv1v2&&(pt.push(v1),pt.push(v2))}return pt=removeduplicate(pt),this},setorient(mode){let p=orientation();return(1==p&&-1==mode||-1==p&&1==mode)&&pt.reverse(),this},reverse(){return pt.reverse(),this},pointinshape:p=>function isPointInPolygon(P){let x=P.x,y=P.y,inside=!1;for(let i=0,j=pt.length-1;i<pt.length;j=i++){let xi=pt[i].x,yi=pt[i].y,xj=pt[j].x,yj=pt[j].y;yi>y!=yj>y&&x<(xj-xi)*(y-yi)/(yj-yi)+xi&&(inside=!inside)}return inside}(p),azzera(){return pt=[],this},removeduplicate(delta=.005){return pt=removeduplicate(pt,delta),this},to3d(u0,alt=0,coeffa=0,coeffb=0,open=!1,sh=null,invert=!1){let tm=function to3dcoor(path,options){let{currentU:currentU=0,c:c=0,a:a=0,b:b=0,anglemin:anglemin=30,open:open=!1,sh:sh=null,invert:invert=!1}=options;const pointsWithNormals=[],n=path.length;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],current=path[i],next=path[(i+1)%n],vPrev={x:current.x-prev.x,y:current.y-prev.y},vNext={x:next.x-current.x,y:next.y-current.y},normalPrev=normal2(prev,current),normalNext=normal2(current,next),angle=angle2vec(vPrev,vNext);let z=a*current.x+b*current.y+c;if(sh){let t=sh.xfromy(current.y,0,!0);invert?z+=t:z-=t}Math.abs(angle-180)<=anglemin?(normalPrev.nx,normalNext.nx,normalPrev.ny,normalNext.ny,pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z})):(pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}),pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}));const dx=next.x-current.x,dy=next.y-current.y;currentU+=Math.sqrt(dx*dx+dy*dy)}if(!open){let p=pointsWithNormals[0],pf=pointsWithNormals[pointsWithNormals.length-1];p.x==pf.x&&p.y==pf.y||pointsWithNormals.push({x:p.x,y:p.y,z:p.z,nx:p.nx,ny:p.ny,nz:p.nz,u:currentU,v:p.z})}return pointsWithNormals}(pt,{open:open,currentU:u0,c:alt,a:coeffa,b:coeffb,anglemin:30,sh:sh,invert:invert});return tm},getboundbox:()=>pt.length?pt.reduce(((box,p)=>(box.p1.x=Math.min(box.p1.x,p.x),box.p1.y=Math.min(box.p1.y,p.y),box.p2.x=Math.max(box.p2.x,p.x),box.p2.y=Math.max(box.p2.y,p.y),box)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}):{p1:new Punto2(0,0),p2:new Punto2(0,0)},fittobox(p1,p2){if(!pt.length)return this;const currentBox=this.getboundbox(),currentWidth=currentBox.p2.x-currentBox.p1.x,currentHeight=currentBox.p2.y-currentBox.p1.y,targetWidth=p2.x-p1.x,targetHeight=p2.y-p1.y,scale=Math.min(targetWidth/(currentWidth||1),targetHeight/(currentHeight||1));for(let p of pt)p.x=(p.x-currentBox.p1.x)*scale,p.y=(p.y-currentBox.p1.y)*scale,p.x+=p1.x,p.y+=p1.y;return this}}}
289
+ segment(i,inverse=!1){let n=pt.length;return i<0&&(i+=n),new Linea2(pt[i%n],pt[(i+(inverse?-1:1))%n])},lineoffset(i1,i2,offset){if((i1=(i1||0)%pt.length)!=(i2=(i2||0)%pt.length)){let l2=new Linea2(pt[i1],pt[i2]);if(l2){return l2=l2.offsetline(-offset),this.intersectline(l2)}}},orientasplitter(){-1!=orientation()&&pt.reverse();let np=pt.length;for(let i=0;i<np;i++){let lt=new Linea2(pt[(np+i-1)%np],pt[i]);if(Math.abs(Math.abs(lt.angle)-Math.PI)<.001){i&&selezionaprimo(i);break}}return this},mirrorx(value=0){for(let p of pt)p.x=2*value-p.x;return this},mirrory(value=0){for(let p of pt)p.y=2*value-p.y;return this},simplify(tolerance,hq){return pt=function simplify(points,tolerance,highestQuality){if(points.length<=2)return points;var sqTolerance=void 0!==tolerance?tolerance*tolerance:1;return simplifyDouglasPeucker(points=highestQuality?points:function simplifyRadialDist(points,sqTolerance){for(var point,p1,p2,dx,dy,prevPoint=points[0],newPoints=[prevPoint],i=1,len=points.length;i<len;i++)p2=prevPoint,dx=void 0,dy=void 0,(dx=(p1=point=points[i]).x-p2.x)*dx+(dy=p1.y-p2.y)*dy>sqTolerance&&(newPoints.push(point),prevPoint=point);return prevPoint!==point&&newPoints.push(point),newPoints}(points,sqTolerance),sqTolerance)}(pt,tolerance,hq),this},fromclip(vv){pt=[];for(let p of vv)pt.push({x:p.x/1e3,y:p.y/1e3});return this},infosegmento(i,open=!1){const n=pt.length;function clampIndex(idx){return(idx+n)%n}function angle(p1,p2){return Math.atan2(p2.y-p1.y,p2.x-p1.x)}function angleDiff(a,b){let diff=a-b;for(;diff>Math.PI;)diff-=2*Math.PI;for(;diff<-Math.PI;)diff+=2*Math.PI;return diff}const p1=pt[i];let p0,p2,p3;if(open)if(0===i){const dx=pt[1].x-pt[0].x,dy=pt[1].y-pt[0].y;p0={x:pt[0].x-dx,y:pt[0].y-dy},p2=pt[1],p3=pt[2]}else if(i===n-1){const dx=pt[n-1].x-pt[n-2].x,dy=pt[n-1].y-pt[n-2].y;p0=pt[n-2],p2={x:pt[n-1].x+dx,y:pt[n-1].y+dy},p3={x:p2.x+dx,y:p2.y+dy}}else p0=pt[i-1],p2=pt[i+1],p3=i+2<n?pt[i+2]:{x:pt[i+1].x+(pt[i+1].x-pt[i].x),y:pt[i+1].y+(pt[i+1].y-pt[i].y)};else{const i0=clampIndex(i-1),i2=clampIndex(i+1),i3=clampIndex(i+2);p0=pt[i0],p2=pt[i2],p3=pt[i3]}const ang12=angle(p1,p2),ang01=angle(p0,p1),ang23=angle(p2,p3);return{x:p1.x,y:p1.y,l:function length(p1,p2){const dx=p2.x-p1.x,dy=p2.y-p1.y;return Math.sqrt(dx*dx+dy*dy)}(p1,p2),ang:ang12/PIF,a1:angleDiff(ang12,ang01)/PIF,a2:angleDiff(ang23,ang12)/PIF}},swapxy(){for(let i=0;i<pt.length;i++){let q=pt[i].x;pt[i].x=-pt[i].y,pt[i].y=-q}return this},fromvec(aa){return pt=[],_addvec(aa),this},addvec(vec){return _addvec(vec),this},frompt(pts){return pt=[...pts],pt=removeduplicate(pt),this},fromdxfvec(verts){let points=[];if(verts&&verts.length)for(let i=0;i<verts.length;i++){let{x:x,y:y,bulge:bulge}=verts[i];if(points.push({x:x,y:y}),bulge){const step=1;let p1={x:x,y:y},p2=verts[(i+1)%verts.length],dx=p2.x-p1.x,dy=p2.y-p1.y,dist=Math.hypot(dx,dy);dist>step&&points.push(...dxfbulge(p1,p2,bulge,Math.floor((dist-step)/step)+1))}}return pt=points.map((e=>({x:Math.round(10*e.x)/10,y:Math.round(10*e.y)/10}))),pt=removeduplicate(pt),this},monotona(){let dxd=dims(pt),pp=pt.map((e=>({x:e.x-dxd.p2.x,y:e.y}))),xp=[];xp.push(pp[0]);let lastv=pp[0].y;for(let i=1;i<pp.length;i++)if(pp[i].y>lastv+1e-4||i==pp.length-1)xp.push(pp[i]),lastv=pp[i].y;else{const newv=lastv+1e-4;xp.push({x:pp[i].x,y:newv}),lastv=newv}return{sh:getshape().frompt(xp),...dxd}},sliceony(stag){let yvalues=stag.pt.map((e=>e.y)).slice(1,-1);const res=[],n=pt.length;let imin=0,yMin=pt[0].y;for(let i=1;i<n;i++)pt[i].y<yMin&&(yMin=pt[i].y,imin=i);const pts=[...pt.slice(imin),...pt.slice(0,imin)],m=pts.length,ymap=new Map;for(let i=0;i<m;i++)for(let y of yvalues)Math.abs(pts[i].y-y)<1e-5&&(ymap.has(y)?ymap.get(y).i2=i:ymap.set(y,{i1:i,i2:i}));const pairs=yvalues.map((y=>ymap.get(y))).filter((p=>p&&p.i1>=0&&p.i2>=0));pairs.length>0&&pairs[0].i1>0&&res.push([...pts.slice(0,pairs[0].i1+1),...pts.slice(pairs[0].i2,pairs[0].length)]);for(let i=0;i<pairs.length-1;i++){const a=pairs[i],b=pairs[i+1];res.push([...pts.slice(a.i1,b.i1+1),...pts.slice(b.i2,a.i2+1)])}const last=pairs[pairs.length-1];last.i2>last.i1&&res.push(pts.slice(last.i1,last.i2+1));return res.filter((arr=>arr.length>0))},splitshape(p,verticale=!0){const p1=verticale?{x:p.x,y:p.y-100}:{x:p.x-100,y:p.y},p2=verticale?{x:p.x,y:p.y+100}:{x:p.x+100,y:p.y},linea=this.intersectline(new Linea2(p1,p2));if(!linea)return null;const pstart=linea.p1,pend=linea.p2,findIndex=pt=>this.pt.findIndex(((v,i)=>new Linea2(v,this.pt[(i+1)%this.pt.length]).onsegment(pt))),i1=findIndex(pstart),i2=findIndex(pend);if(i1<0||i2<0)return null;const n=this.pt.length,loop=(a,b,p0,p1)=>{const res=[];for(let i=a;i!==b;i=(i+1)%n)res.push(this.pt[(i+1)%n]);return res},dx=getshape().frompt(loop(i1,i2));return{sx:getshape().frompt(loop(i2,i1)),dx:dx,linea:linea}},xfromy(y,valore0=0,maggiore=!0){const res=[],n=this.pt.length;for(let i=0;i<n-1;i++){const p1=this.pt[i],p2=this.pt[i+1];if(p1.y<=y&&p2.y>=y||p2.y<=y&&p1.y>=y){const dy=p2.y-p1.y,t=dy?(y-p1.y)/dy:0,x=p1.x+t*(p2.x-p1.x);res.push(x)}else p1.y===y&&p2.y===y&&res.push(maggiore?Math.max(p1.x,p2.x):Math.min(p1.x,p2.x))}return res.length?maggiore?Math.max(...res):Math.min(...res):valore0},yfromx(x,valore0=0,maggiore=!0){const res=[],n=this.pt.length;for(let i=0;i<n-1;i++){const p1=this.pt[i],p2=this.pt[i+1];if(p1.x<=x&&p2.x>=x||p2.x<=x&&p1.x>=x){const dx=p2.x-p1.x,t=dx?(x-p1.x)/dx:0,y=p1.y+t*(p2.y-p1.y);res.push(y)}else p1.x===x&&p2.x===x&&res.push(maggiore?Math.max(p1.y,p2.y):Math.min(p1.y,p2.y))}return res.length?maggiore?Math.max(...res):Math.min(...res):valore0},forcevalues(shape,verticale=!0,delta=1e-6){const sorted=[...new Set(shape.pt.map((e=>verticale?e.y:e.x)))].sort(((a,b)=>a-b)),newpt=[],n=pt.length;for(let i=0;i<n;i++){const p1=pt[i],p2=pt[(i+1)%n];newpt.push({...p1});let v1=verticale?p1.y:p1.x,v2=verticale?p2.y:p2.x;if(v1===v2)continue;const range=v2>v1?sorted.filter((v=>v>v1+delta&&v<v2-delta)):sorted.filter((v=>v<v1-delta&&v>v2+delta)).reverse();for(const v of range){const t=(v-v1)/(v2-v1),q={x:p1.x+t*(p2.x-p1.x),y:p1.y+t*(p2.y-p1.y)};newpt.push(q)}}return pt=newpt,this},fromrrect(w,h,r=10,sx=0,sy=0){return(r>=w/2||r>=h/2&&r<=0)&&(r=Math.round(Math.min(w/3,h/3))),fromstr(`0,0,r${r},${w},0,r${r},${w},${h},r${r},0,${h},r${r}`),(sx||sy)&&move(sx,sy),this},fromrect(w,h,sx,sy,bordo){w||(w=10),h||(h=10),bordo||(bordo=0),bordo=Math.min(Math.abs(bordo),Math.abs(.4*w),Math.abs(.4*h));let b1=w>0?bordo:-bordo,b2=h>0?bordo:-bordo;return pt=bordo?[{x:b1,y:0},{x:w-b1,y:0},{x:w,y:b2},{x:w,y:h-b2},{x:w-b1,y:h},{x:b1,y:h},{x:0,y:h-b2},{x:0,y:b2}]:[{x:0,y:0},{x:w,y:0},{x:w,y:h},{x:0,y:h}],this},intersectline:l=>function _intersectline(shape,p3,p4){let n=shape.length,l=new Linea2(p3,p4);const intersezioni=[];for(let i=0;i<shape.length;i++){let l2=new Linea2(shape[i],shape[(i+1)%n]),p=l2.interseca(l);p&&l2.onsegment(p)&&intersezioni.push(p)}if(intersezioni.length<2)return null;const{dx:dx,dy:dy}=l;intersezioni.sort(((a,b)=>(a.x-p3.x)*dx+(a.y-p3.y)*dy-((b.x-p3.x)*dx+(b.y-p3.y)*dy)));let pstart=new Punto2(intersezioni[0].x,intersezioni[0].y),pend=new Punto2(intersezioni[intersezioni.length-1].x,intersezioni[intersezioni.length-1].y);const vx1=pend.x-pstart.x,vy1=pend.y-pstart.y;return vx1*dx+vy1*dy<0&&([pstart,pend]=[pend,pstart]),new Linea2(pstart,pend)}(pt,l.p1,l.p2),tostr(dec=2){let dd=10**dec,pstr=x=>String(Math.round(x*dd)/dd),cl=pt.map((e=>`${pstr(e.x)};${pstr(e.y)};`)).join("");return cl&&cl.length?cl.slice(0,-1).match(/.{1,80}(;|$)/g).map((s=>s.trim())).join("\n"):""},addpt(pts){return pts?(Array.isArray(pts)||(pts=[pts]),pt=removeduplicate([...pt,...pts]),this):this},addracc(v1,v2,suddivisioni=2,addv1v2=!0){if(Array.isArray(v1)&&(v2={x:v1[2]||0,y:v1[3]||0},v1={x:v1[0]||0,y:v1[1]||0}),pt.length>=2){let tm=raccordabezier(pt[pt.length-2],pt[pt.length-1],v1,v2,suddivisioni);pt=[...pt,...tm],addv1v2&&(pt.push(v1),pt.push(v2))}return pt=removeduplicate(pt),this},setorient(mode){let p=orientation();return(1==p&&-1==mode||-1==p&&1==mode)&&pt.reverse(),this},reverse(){return pt.reverse(),this},pointinshape:p=>function isPointInPolygon(P){let x=P.x,y=P.y,inside=!1;for(let i=0,j=pt.length-1;i<pt.length;j=i++){let xi=pt[i].x,yi=pt[i].y,xj=pt[j].x,yj=pt[j].y;yi>y!=yj>y&&x<(xj-xi)*(y-yi)/(yj-yi)+xi&&(inside=!inside)}return inside}(p),azzera(){return pt=[],this},truncatebefore:function truncatebefore(linea){let s=new Linea2(pt[0],pt[1]),p=linea.interseca(s);if(p){let a=pt[0],b=pt[1],dx=b.x-a.x,dy=b.y-a.y,den=dx*dx+dy*dy;if(den){if(((p.x-a.x)*dx+(p.y-a.y)*dy)/den<=1)return pt[0]=p,this}}for(let i=1;i<pt.length-1;i++){let s=new Linea2(pt[i],pt[i+1]),p=linea.interseca(s);if(p&&s.onsegment(p))return pt=pt.slice(i),pt[0]=p,this}return this},truncateafter:function truncateafter(linea){let np=pt.length,s=new Linea2(pt[np-2],pt[np-1]),p=linea.interseca(s);if(p){let a=pt[np-2],b=pt[np-1],dx=b.x-a.x,dy=b.y-a.y,den=dx*dx+dy*dy;if(den){if(((p.x-a.x)*dx+(p.y-a.y)*dy)/den>=0)return pt[np-1]=p,this}}for(let i=np-3;i>=0;i--){let s=new Linea2(pt[i],pt[i+1]),p=linea.interseca(s);if(p&&s.onsegment(p))return pt=pt.slice(0,i+1),pt.push(p),this}return this},removeduplicate(delta=.005){return pt=removeduplicate(pt,delta),this},to3d(u0,alt=0,coeffa=0,coeffb=0,open=!1,sh=null,invert=!1){let tm=function to3dcoor(path,options){let{currentU:currentU=0,c:c=0,a:a=0,b:b=0,anglemin:anglemin=30,open:open=!1,sh:sh=null,invert:invert=!1}=options;const pointsWithNormals=[],n=path.length;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],current=path[i],next=path[(i+1)%n],vPrev={x:current.x-prev.x,y:current.y-prev.y},vNext={x:next.x-current.x,y:next.y-current.y},normalPrev=normal2(prev,current),normalNext=normal2(current,next),angle=angle2vec(vPrev,vNext);let z=a*current.x+b*current.y+c;if(sh){let t=sh.xfromy(current.y,0,!0);invert?z+=t:z-=t}Math.abs(angle-180)<=anglemin?(normalPrev.nx,normalNext.nx,normalPrev.ny,normalNext.ny,pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z})):(pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}),pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}));const dx=next.x-current.x,dy=next.y-current.y;currentU+=Math.sqrt(dx*dx+dy*dy)}if(!open){let p=pointsWithNormals[0],pf=pointsWithNormals[pointsWithNormals.length-1];p.x==pf.x&&p.y==pf.y||pointsWithNormals.push({x:p.x,y:p.y,z:p.z,nx:p.nx,ny:p.ny,nz:p.nz,u:currentU,v:p.z})}return pointsWithNormals}(pt,{open:open,currentU:u0,c:alt,a:coeffa,b:coeffb,anglemin:30,sh:sh,invert:invert});return tm},getboundbox:()=>pt.length?pt.reduce(((box,p)=>(box.p1.x=Math.min(box.p1.x,p.x),box.p1.y=Math.min(box.p1.y,p.y),box.p2.x=Math.max(box.p2.x,p.x),box.p2.y=Math.max(box.p2.y,p.y),box)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}):{p1:new Punto2(0,0),p2:new Punto2(0,0)},fittobox(p1,p2){if(!pt.length)return this;const currentBox=this.getboundbox(),currentWidth=currentBox.p2.x-currentBox.p1.x,currentHeight=currentBox.p2.y-currentBox.p1.y,targetWidth=p2.x-p1.x,targetHeight=p2.y-p1.y,scale=Math.min(targetWidth/(currentWidth||1),targetHeight/(currentHeight||1));for(let p of pt)p.x=(p.x-currentBox.p1.x)*scale,p.y=(p.y-currentBox.p1.y)*scale,p.x+=p1.x,p.y+=p1.y;return this}}}
290
290
  /**
291
291
  * Calcola i punti di un arco passante per tre punti
292
292
  * @param {number} segments - Numero di segmenti (punti-1)
@@ -496,7 +496,7 @@ ClipperLib.ExPolygons=function(){return[]},
496
496
  /**
497
497
  * @constructor
498
498
  */
499
- ClipperLib.ExPolygon=function(){this.outer=null,this.holes=null},ClipperLib.JS.AddOuterPolyNodeToExPolygons=function(polynode,expolygons){var ep=new ClipperLib.ExPolygon;ep.outer=polynode.Contour();var node,n,i,j,childs2,jlen,childs=polynode.Childs(),ilen=childs.length;for(ep.holes=new Array(ilen),i=0;i<ilen;i++)for(node=childs[i],ep.holes[i]=node.Contour(),j=0,jlen=(childs2=node.Childs()).length;j<jlen;j++)n=childs2[j],ClipperLib.JS.AddOuterPolyNodeToExPolygons(n,expolygons);expolygons.push(ep)},ClipperLib.JS.ExPolygonsToPaths=function(expolygons){var a,i,alen,ilen,paths=new ClipperLib.Paths;for(a=0,alen=expolygons.length;a<alen;a++)for(paths.push(expolygons[a].outer),i=0,ilen=expolygons[a].holes.length;i<ilen;i++)paths.push(expolygons[a].holes[i]);return paths},ClipperLib.JS.PolyTreeToExPolygons=function(polytree){var node,i,childs,ilen,expolygons=new ClipperLib.ExPolygons;for(i=0,ilen=(childs=polytree.Childs()).length;i<ilen;i++)node=childs[i],ClipperLib.JS.AddOuterPolyNodeToExPolygons(node,expolygons);return expolygons}}();var ClipperLib=getDefaultExportFromCjs(clipper.exports);
499
+ ClipperLib.ExPolygon=function(){this.outer=null,this.holes=null},ClipperLib.JS.AddOuterPolyNodeToExPolygons=function(polynode,expolygons){var ep=new ClipperLib.ExPolygon;ep.outer=polynode.Contour();var node,n,i,j,childs2,jlen,childs=polynode.Childs(),ilen=childs.length;for(ep.holes=new Array(ilen),i=0;i<ilen;i++)for(node=childs[i],ep.holes[i]=node.Contour(),j=0,jlen=(childs2=node.Childs()).length;j<jlen;j++)n=childs2[j],ClipperLib.JS.AddOuterPolyNodeToExPolygons(n,expolygons);expolygons.push(ep)},ClipperLib.JS.ExPolygonsToPaths=function(expolygons){var a,i,alen,ilen,paths=new ClipperLib.Paths;for(a=0,alen=expolygons.length;a<alen;a++)for(paths.push(expolygons[a].outer),i=0,ilen=expolygons[a].holes.length;i<ilen;i++)paths.push(expolygons[a].holes[i]);return paths},ClipperLib.JS.PolyTreeToExPolygons=function(polytree){var node,i,childs,ilen,expolygons=new ClipperLib.ExPolygons;for(i=0,ilen=(childs=polytree.Childs()).length;i<ilen;i++)node=childs[i],ClipperLib.JS.AddOuterPolyNodeToExPolygons(node,expolygons);return expolygons}}();var ClipperLib=getDefaultExportFromCjs(clipper.exports);function shapeclip(){function toclipformat(pts){let tm=pts.map((e=>({X:Math.round(1e4*e.x),Y:Math.round(1e4*e.y)})));return ensureOrientation(tm)}function fromclipformat(pts){return pts.map((e=>({x:e.X/1e4,y:e.Y/1e4})))}const ensureOrientation=poly=>ClipperLib.Clipper.Orientation(poly)?poly:poly.slice().reverse();function orientation(pt){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.X*next.Y-next.X*current.Y}return area>0?1:area<0?-1:0}const _inflate=(pt,delta,cut=!1)=>{const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.AddPath(pt,ClipperLib.JoinType.jtMiter,cut||2==pt.length?ClipperLib.EndType.etOpenButt:ClipperLib.EndType.etClosedPolygon);const solution=new ClipperLib.Paths;return co.Execute(solution,delta),solution};function _inflateopen(pts,delta){const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.ArcTolerance=.25;const DD=1e4*delta,pshape=toclipformat(pts);co.AddPath(pshape,ClipperLib.JoinType.jtMiter,ClipperLib.EndType.etClosedPolygon);const solution=new ClipperLib.Paths;co.Execute(solution,DD);let tm=fromclipformat(solution[0]);return getshape().frompt(tm)}return{offset(shape,delta,full=!1){const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.ArcTolerance=.25;const DD=1e4*Math.abs(delta),pshape=toclipformat(shape.pt);co.AddPath(pshape,ClipperLib.JoinType.jtMiter,ClipperLib.EndType.etOpenButt);const solution=new ClipperLib.Paths;co.Execute(solution,DD);let tm=fromclipformat(solution[0]);return full?getshape().frompt(tm):getshape().frompt(getptsoffset(shape.pt,tm,delta))},inflate:function inflate(shape,delta=2,mantainorder=!1,isopen=0){let pshape=toclipformat(shape.pt),tm=_inflate(pshape,1e4*delta);if(!tm||!tm.length)return getshape().frompt([]);let p2=getshape().frompt(fromclipformat(tm[0]));if(mantainorder){p2.orient!=shape.orient&&p2.reverse();let p3=
500
500
  /**
501
501
  * Crea un oggetto per operazioni booleane e manipolazione di forme 2D usando la libreria Clipper
502
502
  * @returns {Object} Oggetto con metodi per operazioni su forme
@@ -504,7 +504,7 @@ ClipperLib.ExPolygon=function(){this.outer=null,this.holes=null},ClipperLib.JS.A
504
504
  * @property {Function} inflate - Espande o contrae una forma
505
505
  * @property {Function} unisci - Unisce più forme con gestione di fori e tagli
506
506
  */
507
- function shapeclip(){function toclipformat(pts){let tm=pts.map((e=>({X:Math.round(1e4*e.x),Y:Math.round(1e4*e.y)})));return ensureOrientation(tm)}function fromclipformat(pts){return pts.map((e=>({x:e.X/1e4,y:e.Y/1e4})))}const ensureOrientation=poly=>ClipperLib.Clipper.Orientation(poly)?poly:poly.slice().reverse();function orientation(pt){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.X*next.Y-next.X*current.Y}return area>0?1:area<0?-1:0}const _inflate=(pt,delta,cut=!1)=>{const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.AddPath(pt,ClipperLib.JoinType.jtMiter,cut||2==pt.length?ClipperLib.EndType.etOpenButt:ClipperLib.EndType.etClosedPolygon);const solution=new ClipperLib.Paths;return co.Execute(solution,delta),solution};return{offset(shape,delta,full=!1){const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.ArcTolerance=.25;const DD=1e4*Math.abs(delta),pshape=toclipformat(shape.pt);co.AddPath(pshape,ClipperLib.JoinType.jtMiter,ClipperLib.EndType.etOpenButt);const solution=new ClipperLib.Paths;co.Execute(solution,DD);let tm=fromclipformat(solution[0]);return full?getshape().frompt(tm):getshape().frompt(getptsoffset(shape.pt,tm,delta))},inflate(shape,delta=2,mantainorder=!1,isopen=0){let pshape=toclipformat(shape.pt),tm=_inflate(pshape,1e4*delta);let p2=getshape().frompt(fromclipformat(tm[0]));if(mantainorder&&shape.pt.length==p2.pt.length){p2.orient!=shape.orient&&p2.reverse();let p3=function alignByMinDist(sag1,sag2){const N=sag1.length;let bestOffset=0,minSum=1/0;for(let k=0;k<N;k++){let sum=0;for(let i=0;i<N;i++){const p=sag1[i],q=sag2[(i+k)%N],dx=p.x-q.x,dy=p.y-q.y;sum+=dx*dx+dy*dy}sum<minSum&&(minSum=sum,bestOffset=k)}return[...sag2.slice(bestOffset),...sag2.slice(0,bestOffset)]}(shape.pt,p2.pt);if(p2.frompt(p3),isopen>0&&shape.pt.length>=3){function estendi1(sh1,sh2){let l1=sh1.segment(0).ruotata(-Math.PI/2,200,!0),l2=sh1.segment(-2).ruotata(-Math.PI/2,200),p2=sh2.segment(-2).interseca(l2),p1=sh2.segment(0).interseca(l1);p1&&(sh2.pt[0]=p1),p2&&(sh2.pt[sh2.pt.length-1]=p2)}function estendi2(sh1,sh2){let lfin=sh1.segment(-1),l2=sh2.segment(0),p1=lfin.interseca(l2);p1&&(sh2.pt[0]=p1),l2=sh2.segment(-2);let p2=lfin.interseca(l2);p2&&(sh2.pt[sh2.pt.length-1]=p2)}1==isopen?estendi1(shape,p2):estendi2(shape,p2)}}return p2},intersecasplitter(areabase,forma1){const clipper=new ClipperLib.Clipper,pt1=[toclipformat(forma1.pt)],pt2=[toclipformat(areabase.pt)];clipper.AddPaths(pt1,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(pt2,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;let res;if(clipper.Execute(ClipperLib.ClipType.ctIntersection,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)&&solution.length>0){const path=solution[0];if(1===orientation(path)){res=getshape().frompt(fromclipformat(path)),res.orient!=forma1.orient&&res.reverse();for(let iu=0;iu<forma1.pt.length;iu++){let p2=forma1.pt[iu],id=res.pt.findIndex((p=>Math.abs(p.x-p2.x)<.01&&Math.abs(p.y-p2.y)<.01));if(id>0){id-=iu,0!=id&&res.selezionaprimo(id);break}}}}return res},offsetpts(pts,delta=.01){const DELTA=1e4*delta;let tm=_inflate(toclipformat(pts),DELTA);if(tm&&tm.length)return fromclipformat(tm[0])},areesplitter(shapept,clipspt,useInflatedClipping=!0){if(!Array.isArray(shapept)||shapept.length<3)return;if(!clipspt||0==clipspt.length)return[shapept];const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;let shape_in=useInflatedClipping?_inflate(toclipformat(shapept),-100):[toclipformat(shapept)],clips_in=useInflatedClipping?clipspt.flatMap((c=>_inflate(toclipformat(c),100))):clipspt.map((c=>toclipformat(c)));for(let s of shape_in)subj.push(s);for(let c of clips_in)clip.push(c);const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(!clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero))return;let res=[];for(let x of solution)if(useInflatedClipping){const restored=_inflate(x,100);for(const r of restored)1===orientation(r)&&res.push(fromclipformat(r))}else if(x.length>4&&1==orientation(x)){const cleaned=_inflate(x,-100);if(cleaned.length>0)for(let cc of cleaned){const restored=_inflate(cc,100);for(const rr of restored)1===orientation(rr)&&res.push(fromclipformat(rr))}}else 1==orientation(x)&&res.push(fromclipformat(x));return res},unisci(shapes,holes,cuts){const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;for(let hh of shapes){let h2=[toclipformat(hh.pt)];for(let h of h2)subj.push(h)}if(holes&&holes.length)for(let hh of holes){let h1=toclipformat(hh.pt);clip.push(h1)}if(cuts&&cuts.length)for(let hh of cuts){let h1=toclipformat(hh.pt),h2=_inflate(h1,1,!0);for(let h of h2)clip.push(h)}const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)){let res=[],holes=[];for(let x of solution)if(1==orientation(x)){let yy=[x];for(let y of yy)res.push({shape:getshape().frompt(fromclipformat(y)),holes:[]})}else holes.push(getshape().frompt(fromclipformat(x)));for(let h of holes)for(let s of res)if(s.shape.pointinshape(h.pt[0])){s.holes.push(h);break}return res}return[]}}}class Vis2d{constructor(name,scalalinea=1){this.name=name,this.clear(scalalinea)}clear(scalalinea=1){return this.vec=[],this.gr={},this._sl=scalalinea,this}creategr(name="grp"){return this.gr[name]||(this.gr[name]=new Vis2d(name,this._sl)),this.gr[name]}push(x=0,y=0,op={}){"number"==typeof op&&(op={rot:op}),op||(op={}),this.vec.push({type:"push",x:x,y:y,op:op})}pop(){this.vec.push({type:"pop"})}randomcolor(transp="100%"){return`hsl(${Math.floor(360*Math.random())}, 50%, 40%,${transp})`}addgr(gr){let name=gr;gr?.name&&(name=gr.name),this.gr[name]?this.vec.push({type:"group",name:name}):this.vec.push({type:"err",err:`addgroup: ${name} => missing`})}addquota(x1,y1,x2,y2,d=0,text="",scalafont=1,spessore=.25){this.vec.push({type:"quota",x1:x1,y1:y1,x2:x2,y2:y2,d:d,text:text,spessore:spessore,color:"black",scalafont:scalafont})}addqpunto(x1,y1,x2,y2,d=0,text="",scalafont=1,spessore=.25){this.vec.push({type:"qpunto",x1:x1,y1:y1,x2:x2,y2:y2,d:d,text:text,spessore:spessore,color:"black",scalafont:scalafont})}addpoint(p,id=-1,color="red",spessore=8){return p&&this.vec.push({type:"point",p:p,id:id,color:color,spessore:spessore*this._sl}),this}addline(l,id=-1,color=void 0,spessore=1){return l&&this.vec.push({type:"line",l:l,id:id,color:color,spessore:spessore*this._sl}),this}addrect(l,id=-1,color=void 0,spessore=1){return l&&this.vec.push({type:"rect",l:l,id:id,color:color,spessore:spessore*this._sl}),this}addrecta(l,id=-1,color=void 0){return l&&this.vec.push({type:"recta",l:l,id:id,color:color,spessore:0}),this}addshape(s,color=void 0,spessore=1){return s&&this.vec.push({type:"shape",s:s,color:color||this.randomcolor(),spessore:spessore*this._sl}),this}addshapelin(s,color=void 0,spessore=1){return s&&this.vec.push({type:"shapelin",s:s,color:color||this.randomcolor(),spessore:spessore*this._sl}),this}addarea(s,color=void 0){return s&&this.vec.push({type:"area",s:s,color:color||this.randomcolor()}),this}addoffset(x,y){return this.vec.push({type:"offset",x:x||0,y:y||0}),this}}function checkoggetto(oggetti,tipo,cod){if("h"==tipo&&(tipo="o"),oggetti||(oggetti=[]),"number"==typeof cod&&!["a","as"].includes(tipo))return{cod:"__",macro:"",sps:cod};let bb=oggetti.find((e=>e.tipo.includes(tipo)&&e.cod==cod));return bb||(bb={cod:"__",macro:"",sps:0}),"a"!=tipo&&"as"!=tipo||"__"==bb.cod||bb.color||(bb.color=`hsl(${function stringToHue(str){let hash=0;for(let i=0;i<str.length;i++)hash=31*hash+str.charCodeAt(i)>>>0;return Math.floor(.6180339887*hash%1*360)}(bb.cod)}, 95%, 97%`),bb}function getbordi(oggetti,bordo){let bordi,uguali=!1;if(Array.isArray(bordo)){bordo.length=4;let b0=bordo[0]||"";bordi=bordo.map((b=>checkoggetto(oggetti,"b",b||b0))),uguali=bordi.every((b=>b.sps===bordi[0].sps))}else{let tm=checkoggetto(oggetti,"b",bordo);bordi=[tm,tm,tm,tm],uguali=!0}return{bordi:bordi,uguali:uguali,senza:!(bordi[0].sps||bordi[1].sps||bordi[2].sps||bordi[3].sps),bl:bordi[0].sps,bt:bordi[1].sps,br:bordi[2].sps,bb:bordi[3].sps}}function elaborapercorso(sh1,bordo,taglio,oggetti,countid=0){let sh2,sh3,p1h,p2h,p3h,p4h,p1v,p2v,p3v,p4v,p1s,p2s,line1,line2,i1,i2,dati=[],draws=[];function eseguipezzo(l1,l2,bordo,shape){let info=l1.infoquad(l2);if(info&&info.distanza){let s0=getshape().frompt(shape||[l1.p1,l1.p2,l2.p2,l2.p1]),s1=s0.clone();(info.sx||info.sy)&&s1.move(-info.sx||0,-info.sy||0),info.angle&&s1.rotate(-info.angle||0);let tm={id:++countid,type:`b${bordo}`,info:info};shape&&(tm.shape=s1.pt),draws.push({type:`b${bordo}`,pt:s0.pt}),dati.push(tm)}}countid=countid||0;let np=sh1.pt.length,idr=np-1;oggetti||(oggetti=[]);let{bordi:bordi,uguali:uguali,senza:senza}=getbordi(oggetti,bordo);if(uguali)if(senza||!bordi[0].sps)sh2=sh1.clone();else{let b=bordi[0].sps;sh2=shapeclip().inflate(sh1,-b,!0)}else{let b,ll=[],pp=[];for(let i=0;i<np;i++){b=0==i?bordi[0].sps:i==idr-1?bordi[2].sps:i==idr?bordi[3].sps:bordi[1].sps,"number"!=typeof b&&(b=0);let l=sh1.segment(i).offset(-b);ll.push(l)}for(let i=0;i<np;i++){let p=ll[i].interseca(ll[(i-1+np)%np]);pp.push(p)}sh2=getshape().frompt(pp)}if(!senza){p1h=sh2.segment(idr).interseca(sh1.segment(0)),p2h=sh2.segment(1).interseca(sh1.segment(0)),p3h=sh1.segment(idr-1).interseca(sh2.segment(idr-2)),p4h=sh1.segment(idr-1).interseca(sh2.segment(idr)),p1v=sh1.segment(idr).interseca(sh2.segment(0)),p2v=sh1.segment(1).interseca(sh2.segment(0)),p3v=sh1.segment(idr-2).interseca(sh2.segment(idr-1)),p4v=sh1.segment(idr).interseca(sh2.segment(idr-1)),i1=1,i2=idr-2,line1=sh2.segment(0),line2=sh2.segment(idr-1);for(let i=1;i<idr-1;i++){let l=sh1.segment(i),p=l.interseca(line1);p&&l.onsegment(p)&&(i1=i,p2v=p),p=l.interseca(line2),p&&l.onsegment(p)&&(i2=i,p3v=p)}i1-=1,i2=idr-2-i2;let p1=sh1.pt[0],p2=sh2.pt[0],p3=sh2.pt[idr],p4=sh1.pt[idr];switch(taglio[0]){case"v":eseguipezzo(new Linea2(p4v,p1v),sh2.segment(idr),3),p2=p1v,p3=p4v;break;case"o":eseguipezzo(sh1.segment(idr),new Linea2(p4h,p1h),3),p1=p1h,p4=p4h;break;default:eseguipezzo(sh1.segment(idr),sh2.segment(idr),3)}switch(p1s=sh1.pt.slice(1,idr),p2s=sh2.pt.slice(1,idr),taglio[1]){case"v":eseguipezzo(new Linea2(p1,sh1.pt[1]),new Linea2(p2,p2v),0),eseguipezzo(new Linea2(sh1.pt[idr-1],p4),new Linea2(p3v,p3),2),i1&&(p1s=p1s.slice(i1)),i2&&(p1s=p1s.slice(0,-i2)),p1s[0]=p2v,p1s[p1s.length-1]=p3v;break;case"o":eseguipezzo(new Linea2(p1,p2h),new Linea2(p2,sh2.pt[1]),0),eseguipezzo(new Linea2(p3h,p4),new Linea2(sh2.pt[idr-1],p3),2),p2s[0]=p2h,p2s[p2s.length-1]=p3h;break;default:eseguipezzo(new Linea2(p1,sh1.pt[1]),new Linea2(p2,sh2.pt[1]),0),eseguipezzo(new Linea2(sh1.pt[idr-1],p4),new Linea2(sh2.pt[idr-1],p3),2)}if(sh3=getshape().frompt(p2s),p1s.length<8&&p1s.length==p2s.length)for(let i=0;i<p1s.length-1;i++)eseguipezzo(new Linea2(p1s[i],p1s[i+1]),new Linea2(p2s[i],p2s[i+1]),1);else{let sh3=getshape().frompt([...p1s,...p2s.reverse()]),l3=new Linea2(p1s[0],p1s[p1s.length-1]),l4=l3.offset(-bordo[1]);eseguipezzo(l3,l4,1,sh3.pt)}}return{countid:countid,shape2:sh2,shapetop:sh3,bordi:bordi,dati:dati,draws:draws}}function creaprofiloesterno(ff,oggetti){let sh1,{x:x,y:y,tipo:tipo,bordo:bordo,taglio:taglio,h1:h1,h2:h2,l1:l1,l2:l2,forma:forma}=ff;x=x<50?50:x,y=y<50?50:y,l1=l1||0,l2=l2||0,h1=h1||0,h2=h2||0;let pts=[0,0];switch(tipo){case"i":case"d":pts.push(l1>0&&l1<x?l1:0,h1>0&&h1<y?y-h1:y),pts.push(l2>0&&l2<x-l1?x-l2:x,h2>0&&h2<y&&h2!=h1?y-h2:y);break;case"a":if(forma){let tm=getshape().fromstr(forma);tm.alignline({x:l1,y:y-h1},{x:x-l2,y:y-h2}),pts.push(...tm.vec)}else if((h1||h2)&&h1>=0&&h1<Math.min(y,x/2)&&h2>=0&&h2<Math.min(y,x/2)){let tm=getshape().fromstr(`a30;${l1||0};${y-h1};${x/2};${y};${x-l2};${y-h2}`);pts.push(...tm.vec)}else pts.push(0,y,x,y);break;case"s":l1>0&&h1>0?pts.push(0,y-h1,l1,y):pts.push(0,y),l2&&l2<x-l1&&h2>0&&h2<y?pts.push(x-l2,y,x,y-h2):pts.push(x,y);break;default:pts.push(0,y,x,y)}pts.push(x,0),sh1=getshape().fromvec(pts);let{countid:countid,shape2:shape2,shapetop:shapetop,bordi:bordi,dati:dati,draws:draws}=elaborapercorso(sh1,bordo,taglio,oggetti,ff.countid);return ff.countid=countid,{shape:sh1,internalshape:shape2,shape2:shape2,shapetop:shapetop,bordi:bordi,dati:dati,draws:draws}}
507
+ function alignByMinDist(sag1,sag2,isopen){const n1=sag1.length,n2=sag2.length;if(n1<1||n2<1)return sag2.slice();let bestOffset=0,minSum=1/0;for(let k=0;k<n2;k++){const p0=sag1[0],q0=sag2[k%n2],dx0=p0.x-q0.x,dy0=p0.y-q0.y,p1=sag1[n1-1],q1=sag2[isopen?Math.min(k+n1-1,n2-1):(k+n1-1)%n2],dx1=p1.x-q1.x,dy1=p1.y-q1.y,sum=dx0*dx0+dy0*dy0+dx1*dx1+dy1*dy1;sum<minSum&&(minSum=sum,bestOffset=k)}return[...sag2.slice(bestOffset),...sag2.slice(0,bestOffset)]}(shape.pt,p2.pt,isopen);if(p2.frompt(p3),isopen>0&&shape.pt.length>=3){function estendi1(sh1,sh2){let l1=sh1.segment(0).ruotata(-Math.PI/2,200,!0),l2=sh1.segment(-2).ruotata(-Math.PI/2,200),q2=sh2.segment(-2).interseca(l2),q1=sh2.segment(0).interseca(l1);q1&&(sh2.pt[0]=q1),q2&&(sh2.pt[sh2.pt.length-1]=q2)}function estendi2(sh1,sh2){let lfin=sh1.segment(-1),l2=sh2.segment(0),q1=lfin.interseca(l2);q1&&(sh2.pt[0]=q1),l2=sh2.segment(-2);let q2=lfin.interseca(l2);q2&&(sh2.pt[sh2.pt.length-1]=q2)}1==isopen?estendi1(shape,p2):estendi2(shape,p2)}}return p2},inflateopen:_inflateopen,inflatecornici(shape,delta=2,linetruncateini,linetruncateend){let l1=new Linea2(shape.pt[0],shape.pt[shape.npt-1]),len1=l1.len,l2=l1.perpendicolare(l1.p1,len1),l3=l1.perpendicolare(l1.p2,len1);l2.isparallela(shape.segment(0))&&(l2=l1.perpendicolare(l1.puntot(.1),len1)),l3.isparallela(shape.segment(shape.npt-2))&&(l3=l1.perpendicolare(l1.puntot(.9),len1));let n2=Math.floor(shape.npt/2),{t:t}=l2.proiezionet(shape.pt[n2]),t2=2*(t>0?-1:1),px2=l2.puntot(t2),px3=l3.puntot(t2),p2=_inflateopen([...shape.pt,px3,px2],delta),idx=p2.pt.reduce(((imin,p,i)=>(p.x-px2.x)**2+(p.y-px2.y)**2<(p2.pt[imin].x-px2.x)**2+(p2.pt[imin].y-px2.y)**2?i:imin),0);return p2.pt=p2.pt.slice(idx+2).concat(p2.pt.slice(0,idx)),p2.orient!=shape.orient&&p2.reverse(),linetruncateini&&(shape.truncatebefore(linetruncateini),p2.truncatebefore(linetruncateini)),linetruncateend&&(p2.truncateafter(linetruncateend),shape.truncateafter(linetruncateend)),p2},intersecasplitter(areabase,forma1){const clipper=new ClipperLib.Clipper,pt1=[toclipformat(forma1.pt)],pt2=[toclipformat(areabase.pt)];clipper.AddPaths(pt1,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(pt2,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;let res;if(clipper.Execute(ClipperLib.ClipType.ctIntersection,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)&&solution.length>0){const path=solution[0];if(1===orientation(path)){res=getshape().frompt(fromclipformat(path)),res.orient!=forma1.orient&&res.reverse();for(let iu=0;iu<forma1.pt.length;iu++){let p2=forma1.pt[iu],id=res.pt.findIndex((p=>Math.abs(p.x-p2.x)<.01&&Math.abs(p.y-p2.y)<.01));if(id>0){id-=iu,0!=id&&res.selezionaprimo(id);break}}}}return res},offsetpts(pts,delta=.01){const DELTA=1e4*delta;let tm=_inflate(toclipformat(pts),DELTA);if(tm&&tm.length)return fromclipformat(tm[0])},areesplitter(shapept,clipspt,useInflatedClipping=!0){if(!Array.isArray(shapept)||shapept.length<3)return;if(!clipspt||0==clipspt.length)return[shapept];const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;let shape_in=useInflatedClipping?_inflate(toclipformat(shapept),-100):[toclipformat(shapept)],clips_in=useInflatedClipping?clipspt.flatMap((c=>_inflate(toclipformat(c),100))):clipspt.map((c=>toclipformat(c)));for(let s of shape_in)subj.push(s);for(let c of clips_in)clip.push(c);const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(!clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero))return;let res=[];for(let x of solution)if(useInflatedClipping){const restored=_inflate(x,100);for(const r of restored)1===orientation(r)&&res.push(fromclipformat(r))}else if(x.length>4&&1==orientation(x)){const cleaned=_inflate(x,-100);if(cleaned.length>0)for(let cc of cleaned){const restored=_inflate(cc,100);for(const rr of restored)1===orientation(rr)&&res.push(fromclipformat(rr))}}else 1==orientation(x)&&res.push(fromclipformat(x));return res},unisci(shapes,holes,cuts){const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;for(let hh of shapes){let h2=[toclipformat(hh.pt)];for(let h of h2)subj.push(h)}if(holes&&holes.length)for(let hh of holes){let h1=toclipformat(hh.pt);clip.push(h1)}if(cuts&&cuts.length)for(let hh of cuts){let h1=toclipformat(hh.pt),h2=_inflate(h1,1,!0);for(let h of h2)clip.push(h)}const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)){let res=[],holes=[];for(let x of solution)if(1==orientation(x)){let yy=[x];for(let y of yy)res.push({shape:getshape().frompt(fromclipformat(y)),holes:[]})}else holes.push(getshape().frompt(fromclipformat(x)));for(let h of holes)for(let s of res)if(s.shape.pointinshape(h.pt[0])){s.holes.push(h);break}return res}return[]}}}class Vis2d{constructor(name,scalalinea=1){this.name=name,this.clear(scalalinea)}clear(scalalinea=1){return this.vec=[],this.gr={},this._sl=scalalinea,this}creategr(name="grp"){return this.gr[name]||(this.gr[name]=new Vis2d(name,this._sl)),this.gr[name]}push(x=0,y=0,op={}){"number"==typeof op&&(op={rot:op}),op||(op={}),this.vec.push({type:"push",x:x,y:y,op:op})}pop(){this.vec.push({type:"pop"})}randomcolor(transp="100%"){return`hsl(${Math.floor(360*Math.random())}, 50%, 40%,${transp})`}addgr(gr){let name=gr;gr?.name&&(name=gr.name),this.gr[name]?this.vec.push({type:"group",name:name}):this.vec.push({type:"err",err:`addgroup: ${name} => missing`})}addquota(x1,y1,x2,y2,d=0,text="",scalafont=1,spessore=.25){this.vec.push({type:"quota",x1:x1,y1:y1,x2:x2,y2:y2,d:d,text:text,spessore:spessore,color:"black",scalafont:scalafont})}addqpunto(x1,y1,x2,y2,d=0,text="",scalafont=1,spessore=.25){this.vec.push({type:"qpunto",x1:x1,y1:y1,x2:x2,y2:y2,d:d,text:text,spessore:spessore,color:"black",scalafont:scalafont})}addpoint(p,id=-1,color="red",spessore=8){return p&&this.vec.push({type:"point",p:p,id:id,color:color,spessore:spessore*this._sl}),this}addline(l,id=-1,color=void 0,spessore=1){return l&&this.vec.push({type:"line",l:l,id:id,color:color,spessore:spessore*this._sl}),this}addrect(l,id=-1,color=void 0,spessore=1){return l&&this.vec.push({type:"rect",l:l,id:id,color:color,spessore:spessore*this._sl}),this}addrecta(l,id=-1,color=void 0){return l&&this.vec.push({type:"recta",l:l,id:id,color:color,spessore:0}),this}addshape(s,color=void 0,spessore=1){return s&&this.vec.push({type:"shape",s:s,color:color||this.randomcolor(),spessore:spessore*this._sl}),this}addshapelin(s,color=void 0,spessore=1){return s&&this.vec.push({type:"shapelin",s:s,color:color||this.randomcolor(),spessore:spessore*this._sl}),this}addarea(s,color=void 0){return s&&this.vec.push({type:"area",s:s,color:color||this.randomcolor()}),this}addoffset(x,y){return this.vec.push({type:"offset",x:x||0,y:y||0}),this}}function checkoggetto(oggetti,tipo,cod){if("h"==tipo&&(tipo="o"),oggetti||(oggetti=[]),"number"==typeof cod&&!["a","as"].includes(tipo))return{cod:"__",macro:"",sps:cod};let bb=oggetti.find((e=>e.tipo.includes(tipo)&&e.cod==cod));return bb||(bb={cod:"__",macro:"",sps:0}),"a"!=tipo&&"as"!=tipo||"__"==bb.cod||bb.color||(bb.color=`hsl(${function stringToHue(str){let hash=0;for(let i=0;i<str.length;i++)hash=31*hash+str.charCodeAt(i)>>>0;return Math.floor(.6180339887*hash%1*360)}(bb.cod)}, 95%, 97%`),bb}function getbordi(oggetti,bordo){let bordi,uguali=!1;if(Array.isArray(bordo)){bordo.length=4;let b0=bordo[0]||"";bordi=bordo.map((b=>checkoggetto(oggetti,"b",b||b0))),uguali=bordi.every((b=>b.sps===bordi[0].sps))}else{let tm=checkoggetto(oggetti,"b",bordo);bordi=[tm,tm,tm,tm],uguali=!0}return{bordi:bordi,uguali:uguali,senza:!(bordi[0].sps||bordi[1].sps||bordi[2].sps||bordi[3].sps),bl:bordi[0].sps,bt:bordi[1].sps,br:bordi[2].sps,bb:bordi[3].sps}}function elaborapercorso(sh1,bordo,taglio,oggetti,countid=0){let sh2,sh3,p1h,p2h,p3h,p4h,p1v,p2v,p3v,p4v,p1s,p2s,line1,line2,i1,i2,dati=[],draws=[];function eseguipezzo(l1,l2,bordo,shape){let info=l1.infoquad(l2);if(info&&info.distanza){let s0=getshape().frompt(shape||[l1.p1,l1.p2,l2.p2,l2.p1]),s1=s0.clone();(info.sx||info.sy)&&s1.move(-info.sx||0,-info.sy||0),info.angle&&s1.rotate(-info.angle||0);let tm={id:++countid,type:`b${bordo}`,info:info};shape&&(tm.shape=s1.pt),draws.push({type:`b${bordo}`,pt:s0.pt}),dati.push(tm)}}countid=countid||0;let np=sh1.pt.length,idr=np-1;oggetti||(oggetti=[]);let{bordi:bordi,uguali:uguali,senza:senza}=getbordi(oggetti,bordo);if(uguali)if(senza||!bordi[0].sps)sh2=sh1.clone();else{let b=bordi[0].sps;sh2=shapeclip().inflate(sh1,-b,!0)}else{let b,ll=[],pp=[];for(let i=0;i<np;i++){b=0==i?bordi[0].sps:i==idr-1?bordi[2].sps:i==idr?bordi[3].sps:bordi[1].sps,"number"!=typeof b&&(b=0);let l=sh1.segment(i).offset(-b);ll.push(l)}for(let i=0;i<np;i++){let p=ll[i].interseca(ll[(i-1+np)%np]);pp.push(p)}sh2=getshape().frompt(pp)}if(!senza){p1h=sh2.segment(idr).interseca(sh1.segment(0)),p2h=sh2.segment(1).interseca(sh1.segment(0)),p3h=sh1.segment(idr-1).interseca(sh2.segment(idr-2)),p4h=sh1.segment(idr-1).interseca(sh2.segment(idr)),p1v=sh1.segment(idr).interseca(sh2.segment(0)),p2v=sh1.segment(1).interseca(sh2.segment(0)),p3v=sh1.segment(idr-2).interseca(sh2.segment(idr-1)),p4v=sh1.segment(idr).interseca(sh2.segment(idr-1)),i1=1,i2=idr-2,line1=sh2.segment(0),line2=sh2.segment(idr-1);for(let i=1;i<idr-1;i++){let l=sh1.segment(i),p=l.interseca(line1);p&&l.onsegment(p)&&(i1=i,p2v=p),p=l.interseca(line2),p&&l.onsegment(p)&&(i2=i,p3v=p)}i1-=1,i2=idr-2-i2;let p1=sh1.pt[0],p2=sh2.pt[0],p3=sh2.pt[idr],p4=sh1.pt[idr];switch(taglio[0]){case"v":eseguipezzo(new Linea2(p4v,p1v),sh2.segment(idr),3),p2=p1v,p3=p4v;break;case"o":eseguipezzo(sh1.segment(idr),new Linea2(p4h,p1h),3),p1=p1h,p4=p4h;break;default:eseguipezzo(sh1.segment(idr),sh2.segment(idr),3)}switch(p1s=sh1.pt.slice(1,idr),p2s=sh2.pt.slice(1,idr),taglio[1]){case"v":eseguipezzo(new Linea2(p1,sh1.pt[1]),new Linea2(p2,p2v),0),eseguipezzo(new Linea2(sh1.pt[idr-1],p4),new Linea2(p3v,p3),2),i1&&(p1s=p1s.slice(i1)),i2&&(p1s=p1s.slice(0,-i2)),p1s[0]=p2v,p1s[p1s.length-1]=p3v;break;case"o":eseguipezzo(new Linea2(p1,p2h),new Linea2(p2,sh2.pt[1]),0),eseguipezzo(new Linea2(p3h,p4),new Linea2(sh2.pt[idr-1],p3),2),p2s[0]=p2h,p2s[p2s.length-1]=p3h;break;default:eseguipezzo(new Linea2(p1,sh1.pt[1]),new Linea2(p2,sh2.pt[1]),0),eseguipezzo(new Linea2(sh1.pt[idr-1],p4),new Linea2(sh2.pt[idr-1],p3),2)}if(sh3=getshape().frompt(p2s),p1s.length<8&&p1s.length==p2s.length)for(let i=0;i<p1s.length-1;i++)eseguipezzo(new Linea2(p1s[i],p1s[i+1]),new Linea2(p2s[i],p2s[i+1]),1);else{let sh3=getshape().frompt([...p1s,...p2s.reverse()]),l3=new Linea2(p1s[0],p1s[p1s.length-1]),l4=l3.offset(-bordo[1]);eseguipezzo(l3,l4,1,sh3.pt)}}return{countid:countid,shape2:sh2,shapetop:sh3,bordi:bordi,dati:dati,draws:draws}}function creaprofiloesterno(ff,oggetti){let sh1,{x:x,y:y,tipo:tipo,bordo:bordo,taglio:taglio,h1:h1,h2:h2,l1:l1,l2:l2,forma:forma}=ff;x=x<50?50:x,y=y<50?50:y,l1=l1||0,l2=l2||0,h1=h1||0,h2=h2||0;let pts=[0,0];switch(tipo){case"i":case"d":pts.push(l1>0&&l1<x?l1:0,h1>0&&h1<y?y-h1:y),pts.push(l2>0&&l2<x-l1?x-l2:x,h2>0&&h2<y&&h2!=h1?y-h2:y);break;case"a":if(forma){let tm=getshape().fromstr(forma);tm.alignline({x:l1,y:y-h1},{x:x-l2,y:y-h2}),pts.push(...tm.vec)}else if((h1||h2)&&h1>=0&&h1<Math.min(y,x/2)&&h2>=0&&h2<Math.min(y,x/2)){let tm=getshape().fromstr(`a30;${l1||0};${y-h1};${x/2};${y};${x-l2};${y-h2}`);pts.push(...tm.vec)}else pts.push(0,y,x,y);break;case"s":l1>0&&h1>0?pts.push(0,y-h1,l1,y):pts.push(0,y),l2&&l2<x-l1&&h2>0&&h2<y?pts.push(x-l2,y,x,y-h2):pts.push(x,y);break;default:pts.push(0,y,x,y)}pts.push(x,0),sh1=getshape().fromvec(pts);let{countid:countid,shape2:shape2,shapetop:shapetop,bordi:bordi,dati:dati,draws:draws}=elaborapercorso(sh1,bordo,taglio,oggetti,ff.countid);return ff.countid=countid,{shape:sh1,internalshape:shape2,shape2:shape2,shapetop:shapetop,bordi:bordi,dati:dati,draws:draws}}
508
508
  /**
509
509
  * Genera segmenti basati su intervalli e punti di interruzione
510
510
  * @param {Array<{a: number, b: number}>} t1 - Array di oggetti che rappresentano intervalli con coordinate a e b
@@ -645,17 +645,7 @@ function toTrianglesDrawMode(geometry,drawMode){if(drawMode===TrianglesDrawMode)
645
645
  * @param {Array} mats - Array di materiali
646
646
  * @param {Object} options - Opzioni di configurazione
647
647
  * @returns {THREE.Group} Gruppo contenente la geometria estrusa
648
- */function estruso(gcad,orient,hshape,shape,holes,mats,options){options||(options={}),mats||(mats=[]),Array.isArray(mats)||(mats=[mats,mats,mats]);let p0=options.p0||0,coeffbase1=Math.tan(options.coeffbase1*PIF||0),coeffbase2=Math.tan(options.coeffbase2*PIF||0),p1=hshape||options.p1||20,coefftop1=Math.tan(options.coefftop1*PIF||0),coefftop2=Math.tan(options.coefftop2*PIF||0),shapetop=options.shapetop,shapebase=options.shapebase||options.shapebottom;shapetop&&(coefftop2=0),shapebase&&(coefftop2=0);let shb=shapebase?shapebase.key:"",sht=shapetop?shapetop.key:"",notopholes=options.notopholes||!1,nobottomholes=options.nobottomholes||options.nobaseholes||!1,opinvert=options.invert||!1,open=options.open||!1,grp=new THREE.Group;if(shape){if(!options.nobase){let g1=bottomgeomfromshape(gcad,!1,shape,open||nobottomholes?[]:holes,p0,coeffbase1,coeffbase2,shapebase);options.nolines||grp.add(edgesfromgeometry(g1)),grp.add(getmesh(g1,mats[0]||mwhite))}if(!options.notop){let g3=bottomgeomfromshape(gcad,!0,shape,open||notopholes?[]:holes,p1,coefftop1,coefftop2,shapetop);grp.add(getmesh(g3,mats[1]||mats[0]||mwhite)),options.nolines||grp.add(edgesfromgeometry(g3))}if(!options.nosides){let pat1=shape.to3d(0,p0,coeffbase1,-coeffbase2,open,shapebase,!opinvert),pat2=shape.to3d(1,p1,coefftop1,-coefftop2,open,shapetop,opinvert),ky=`${shape.key}${opinvert?1:0}|${p0}|${p1}|${coeffbase1}|${coeffbase2||shb}|${coefftop1}|${coefftop2||sht}|${open}`,geo1=sidegeomfromshapes(gcad,ky,pat1,pat2,!1);if(options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo1)),grp.add(getmesh(geo1,mats[2]||mats[0]||mwhite)),holes&&!open&&!nobottomholes&&!notopholes)for(var h of holes){pat1=h.to3d(0,p0,coeffbase1,coeffbase2),pat2=h.to3d(0,p1,coefftop1,coefftop2),ky=`${h.key}|${p0}|${p1}|${coeffbase1}|${coeffbase2}|${coefftop1}|${coefftop2}`;let geo2=sidegeomfromshapes(gcad,ky,pat1,pat2,!0);options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo2)),grp.add(getmesh(geo2,mats[3]||mats[0]||mwhite))}}return estrusorotate(orient,grp,hshape)}return grp}function revolve(gcad,shape,orient,mat,options){options||(options={});let segmenti=options.segmenti??12,ky=hash(`rev|${shape.key}|${orient}|${segmenti}`),geometria=gcad.geo[ky],grp=new THREE.Group;if(!geometria){const punti3D=shape.pt.map((p=>new THREE.Vector3(p.x,p.y,0)));geometria=new THREE.LatheGeometry(punti3D,segmenti,0,2*Math.PI),gcad.geo[ky]=geometria}const mesh=new THREE.Mesh(geometria,mat);return grp.add(mesh),options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geometria)),grp}
649
- /**
650
- * Crea una geometria estrusa con opzioni avanzate
651
- * @param {string} orient - Orientamento dell'estrusione
652
- * @param {number} hshape - Altezza dell'estrusione
653
- * @param {Object} shape - Forma base
654
- * @param {Array} holes - Array di fori
655
- * @param {Array} mats - Array di materiali
656
- * @param {Object} options - Opzioni di configurazione
657
- * @returns {THREE.Group} Gruppo contenente la geometria estrusa
658
- */function estrusopat(gcad,orient,pat,shape,mats,options){options||(options={});let invert=options.invert;mats||(mats=[]);let open=options.open;if(!pat.pt?.length)return;let pbase=shape.to3d(0,0,0,0,open),grp=new THREE.Group;if(!options.nobase){let gb=new THREE.Group,g1=bottomgeomfromshape(gcad,!1,shape,[],0,0,0);gb.add(getmesh(g1,mats[0]||mwhite)),gb.add(edgesfromgeometry(g1));let seg1=pat.infosegmento(0,!0);grp.add(posiziona(gb,{sl:seg1.x,sp:seg1.y,sa:0,ay:90-seg1.ang}))}if(!options.notop){let gt=new THREE.Group,g2=bottomgeomfromshape(gcad,!0,shape,[],0,0,0);gt.add(getmesh(g2,mats[1]||mats[0]||mwhite)),gt.add(edgesfromgeometry(g2));let seg1=pat.infosegmento(pat.pt.length-1,!0);grp.add(posiziona(gt,{sl:seg1.x,sp:seg1.y,sa:0,ay:90-seg1.ang}))}const geo1=function sidegeomfrompat(gcad,pbase,pat,invert){let ky=`bsg:${pbase.key}|${pat.key}|${invert}`;if(ky=hash(ky),!gcad.geo[ky]){const vertices=[],uvs=[],indices=[],np=pbase.length,lp=pat.pt.length,equalpos=(p1,p2)=>p1.x===p2.x&&p1.y===p2.y&&p1.z===p2.z;let l0=0;for(let ii=0;ii<lp;ii++){const addpts=(ss,mat,deltav)=>{for(const s of ss){let p=new THREE.Vector3(s.x,s.y,s.z);p.applyMatrix4(mat),vertices.push(p.x,p.y,p.z),uvs.push(s.u,s.v+deltav)}};let seg1=pat.infosegmento(ii,!0),obj=new THREE.Object3D;obj.position.set(seg1.x,0,seg1.y),obj.rotation.set(0,(90-seg1.ang)*PIF,0),obj.updateMatrix(),addpts(pbase,obj.matrix,l0),l0+=seg1.l}for(let li=0;li<lp-1;li++)for(let i=0;i<np-1;i++){const addindexquad=(i1,i2,i3,i4)=>{invert?indices.push(i1,i3,i2,i3,i4,i2):indices.push(i1,i2,i3,i3,i2,i4)},j=i+1;equalpos(pbase[i],pbase[j])||addindexquad(i+li*np,j+li*np,i+(li+1)*np,j+(li+1)*np)}const geometry=new THREE.BufferGeometry;geometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3)),geometry.setAttribute("uv",new THREE.Float32BufferAttribute(uvs,2)),geometry.setIndex(indices),geometry.computeVertexNormals(),gcad[ky]=geometry}return gcad[ky]}(gcad,pbase,pat,invert);return options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo1)),grp.add(getmesh(geo1,mats[2]||mats[0]||mwhite)),estrusorotate(orient,grp,0)}async function spritemat(gcad,file){try{let tm={transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1};if(file.startsWith("#"))tm.color=file;else{let tx=await gcad.tex(file,1e3,1e3);tx?tm.map=tx:tm.color="black"}return new THREE.SpriteMaterial(tm)}catch(error){return mwhite}}function getsprite0(ispunto,x,y,z,mat,options={}){options||(options={});let{size:size=50,pick:pick=!1,screen:screen=!1,sizex:sizex,sizey:sizey}=options;const sprite=new THREE.Sprite(mat);sprite.position.set(0,0,0),sprite.userData.issprite=!0,sprite.userData.ispunto=ispunto,sprite.userData.ispick=pick,sprite.userData.isScreen=screen,sprite.renderOrder=999,sprite.layers.set(29),sprite.name=ispunto?"_punto":"_sprite";let gr=new THREE.Group;return gr.position.set(x,y,z),gr.scale.set(sizex||size,sizey||sizex||size,1),gr.add(sprite),gr.traverse((obj=>{obj.material&&(obj.material.depthTest=!1,obj.material.depthWrite=!1)})),gr.renderOrder=999,gr}async function getpunto(gcad,x,y,z,color="yellow",options){options||(options={size:20}),options.screen=!0;const texture=await function createCircleTexture(gcad,size=64,color="rgba(255,0,0,1)"){const ky=`ct|${size}|${color}`;if(!gcad.textures[ky]){const canvas=document.createElement("canvas");canvas.width=canvas.height=size;const ctx=canvas.getContext("2d"),radius=size/2;ctx.clearRect(0,0,size,size),ctx.fillStyle=color,ctx.beginPath(),ctx.arc(radius,radius,radius,0,2*Math.PI),ctx.fill();const texture=new THREE.CanvasTexture(canvas);texture.needsUpdate=!0,gcad.textures[ky]=texture}return gcad.textures[ky]}(gcad,64,color);return getsprite0(!0,x,y,z,new THREE.SpriteMaterial({map:texture,transparent:!0,fog:!1,toneMapped:!1}),options)}function getsprite(gcad,x,y,z,mat,options={}){return getsprite0(!1,x,y,z,mat,options)}class GLTFLoader extends Loader{constructor(manager){super(manager),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(parser){return new GLTFMaterialsClearcoatExtension(parser)})),this.register((function(parser){return new GLTFMaterialsDispersionExtension(parser)})),this.register((function(parser){return new GLTFTextureBasisUExtension(parser)})),this.register((function(parser){return new GLTFTextureWebPExtension(parser)})),this.register((function(parser){return new GLTFTextureAVIFExtension(parser)})),this.register((function(parser){return new GLTFMaterialsSheenExtension(parser)})),this.register((function(parser){return new GLTFMaterialsTransmissionExtension(parser)})),this.register((function(parser){return new GLTFMaterialsVolumeExtension(parser)})),this.register((function(parser){return new GLTFMaterialsIorExtension(parser)})),this.register((function(parser){return new GLTFMaterialsEmissiveStrengthExtension(parser)})),this.register((function(parser){return new GLTFMaterialsSpecularExtension(parser)})),this.register((function(parser){return new GLTFMaterialsIridescenceExtension(parser)})),this.register((function(parser){return new GLTFMaterialsAnisotropyExtension(parser)})),this.register((function(parser){return new GLTFMaterialsBumpExtension(parser)})),this.register((function(parser){return new GLTFLightsExtension(parser)})),this.register((function(parser){return new GLTFMeshoptCompression(parser)})),this.register((function(parser){return new GLTFMeshGpuInstancing(parser)}))}load(url,onLoad,onProgress,onError){const scope=this;let resourcePath;if(""!==this.resourcePath)resourcePath=this.resourcePath;else if(""!==this.path){const relativeUrl=LoaderUtils.extractUrlBase(url);resourcePath=LoaderUtils.resolveURL(relativeUrl,this.path)}else resourcePath=LoaderUtils.extractUrlBase(url);this.manager.itemStart(url);const _onError=function(e){onError?onError(e):console.error(e),scope.manager.itemError(url),scope.manager.itemEnd(url)},loader=new FileLoader(this.manager);loader.setPath(this.path),loader.setResponseType("arraybuffer"),loader.setRequestHeader(this.requestHeader),loader.setWithCredentials(this.withCredentials),loader.load(url,(function(data){try{scope.parse(data,resourcePath,(function(gltf){onLoad(gltf),scope.manager.itemEnd(url)}),_onError)}catch(e){_onError(e)}}),onProgress,_onError)}setDRACOLoader(dracoLoader){return this.dracoLoader=dracoLoader,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(ktx2Loader){return this.ktx2Loader=ktx2Loader,this}setMeshoptDecoder(meshoptDecoder){return this.meshoptDecoder=meshoptDecoder,this}register(callback){return-1===this.pluginCallbacks.indexOf(callback)&&this.pluginCallbacks.push(callback),this}unregister(callback){return-1!==this.pluginCallbacks.indexOf(callback)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback),1),this}parse(data,path,onLoad,onError){let json;const extensions={},plugins={},textDecoder=new TextDecoder;if("string"==typeof data)json=JSON.parse(data);else if(data instanceof ArrayBuffer){if(textDecoder.decode(new Uint8Array(data,0,4))===BINARY_EXTENSION_HEADER_MAGIC){try{extensions[EXTENSIONS.KHR_BINARY_GLTF]=new GLTFBinaryExtension(data)}catch(error){return void(onError&&onError(error))}json=JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content)}else json=JSON.parse(textDecoder.decode(data))}else json=data;if(void 0===json.asset||json.asset.version[0]<2)return void(onError&&onError(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const parser=new GLTFParser(json,{path:path||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});parser.fileLoader.setRequestHeader(this.requestHeader);for(let i=0;i<this.pluginCallbacks.length;i++){const plugin=this.pluginCallbacks[i](parser);plugin.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),plugins[plugin.name]=plugin,extensions[plugin.name]=!0}if(json.extensionsUsed)for(let i=0;i<json.extensionsUsed.length;++i){const extensionName=json.extensionsUsed[i],extensionsRequired=json.extensionsRequired||[];switch(extensionName){case EXTENSIONS.KHR_MATERIALS_UNLIT:extensions[extensionName]=new GLTFMaterialsUnlitExtension;break;case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:extensions[extensionName]=new GLTFDracoMeshCompressionExtension(json,this.dracoLoader);break;case EXTENSIONS.KHR_TEXTURE_TRANSFORM:extensions[extensionName]=new GLTFTextureTransformExtension;break;case EXTENSIONS.KHR_MESH_QUANTIZATION:extensions[extensionName]=new GLTFMeshQuantizationExtension;break;default:extensionsRequired.indexOf(extensionName)>=0&&void 0===plugins[extensionName]&&console.warn('THREE.GLTFLoader: Unknown extension "'+extensionName+'".')}}parser.setExtensions(extensions),parser.setPlugins(plugins),parser.parse(onLoad,onError)}parseAsync(data,path){const scope=this;return new Promise((function(resolve,reject){scope.parse(data,path,resolve,reject)}))}}function GLTFRegistry(){let objects={};return{get:function(key){return objects[key]},add:function(key,object){objects[key]=object},remove:function(key){delete objects[key]},removeAll:function(){objects={}}}}
648
+ */function estruso(gcad,orient,hshape,shape,holes,mats,options){options||(options={}),mats||(mats=[]),Array.isArray(mats)||(mats=[mats,mats,mats]);let p0=options.p0||0,coeffbase1=Math.tan(options.coeffbase1*PIF||0),coeffbase2=Math.tan(options.coeffbase2*PIF||0),p1=hshape||options.p1||20,coefftop1=Math.tan(options.coefftop1*PIF||0),coefftop2=Math.tan(options.coefftop2*PIF||0),shapetop=options.shapetop,shapebase=options.shapebase||options.shapebottom;shapetop&&(coefftop2=0),shapebase&&(coefftop2=0);let shb=shapebase?shapebase.key:"",sht=shapetop?shapetop.key:"",notopholes=options.notopholes||!1,nobottomholes=options.nobottomholes||options.nobaseholes||!1,opinvert=options.invert||!1,open=options.open||!1,grp=new THREE.Group;if(shape){if(!options.nobase){let g1=bottomgeomfromshape(gcad,!1,shape,open||nobottomholes?[]:holes,p0,coeffbase1,coeffbase2,shapebase);options.nolines||grp.add(edgesfromgeometry(g1)),grp.add(getmesh(g1,mats[0]||mwhite))}if(!options.notop){let g3=bottomgeomfromshape(gcad,!0,shape,open||notopholes?[]:holes,p1,coefftop1,coefftop2,shapetop);grp.add(getmesh(g3,mats[1]||mats[0]||mwhite)),options.nolines||grp.add(edgesfromgeometry(g3))}if(!options.nosides){let pat1=shape.to3d(0,p0,coeffbase1,-coeffbase2,open,shapebase,!opinvert),pat2=shape.to3d(1,p1,coefftop1,-coefftop2,open,shapetop,opinvert),ky=`${shape.key}${opinvert?1:0}|${p0}|${p1}|${coeffbase1}|${coeffbase2||shb}|${coefftop1}|${coefftop2||sht}|${open}`,geo1=sidegeomfromshapes(gcad,ky,pat1,pat2,!1);if(options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo1)),grp.add(getmesh(geo1,mats[2]||mats[0]||mwhite)),holes&&!open&&!nobottomholes&&!notopholes)for(var h of holes){pat1=h.to3d(0,p0,coeffbase1,coeffbase2),pat2=h.to3d(0,p1,coefftop1,coefftop2),ky=`${h.key}|${p0}|${p1}|${coeffbase1}|${coeffbase2}|${coefftop1}|${coefftop2}`;let geo2=sidegeomfromshapes(gcad,ky,pat1,pat2,!0);options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo2)),grp.add(getmesh(geo2,mats[3]||mats[0]||mwhite))}}return estrusorotate(orient,grp,hshape)}return grp}function revolve(gcad,shape,orient,mat,options){options||(options={});let segmenti=options.segmenti??12,ky=hash(`rev|${shape.key}|${orient}|${segmenti}`),geometria=gcad.geo[ky],grp=new THREE.Group;if(!geometria){const punti3D=shape.pt.map((p=>new THREE.Vector3(p.x,p.y,0)));geometria=new THREE.LatheGeometry(punti3D,segmenti,0,2*Math.PI),gcad.geo[ky]=geometria}const mesh=new THREE.Mesh(geometria,mat);return grp.add(mesh),options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geometria)),grp}function estrusopat(gcad,orient,pat,plink,shape,mats,options){options||(options={});let invert=options.invert;mats||(mats=[]);let open=options.open;if(!pat.pt?.length)return;let pbase=shape.to3d(0,0,0,0,open),grp=new THREE.Group;if(!options.nobase){let gb=new THREE.Group,angolo=angle3point(plink[0],pat.pt[0],pat.pt[1])+Math.PI/2,g1=bottomgeomfromshape(gcad,!1,shape,[],0,-Math.tan(angolo));gb.add(getmesh(g1,mats[0]||mwhite)),gb.add(edgesfromgeometry(g1));let seg1=pat.infosegmento(0,!0);grp.add(posiziona(gb,{sl:seg1.x,sp:seg1.y,sa:0,ay:90-seg1.ang}))}if(!options.notop){let gt=new THREE.Group,angolo=-(angle3point(pat.pt[pat.npt-2],pat.pt[pat.npt-1],plink[pat.npt-1])+Math.PI/2),g2=bottomgeomfromshape(gcad,!0,shape,[],0,-Math.tan(angolo),0);gt.add(getmesh(g2,mats[1]||mats[0]||mwhite)),gt.add(edgesfromgeometry(g2));let seg1=pat.infosegmento(pat.pt.length-1,!0);grp.add(posiziona(gt,{sl:seg1.x,sp:seg1.y,sa:0,ay:90-seg1.ang}))}const geo1=function sidegeomfrompat(gcad,pbase,pat,plink,invert){let ky=`bsg:${pbase.key}|${pat.key}|${invert}`;if(pat.npt==plink.length){if(ky=hash(ky),!gcad.geo[ky]){const vertices=[],uvs=[],indices=[],np=pbase.length,lp=pat.pt.length,equalpos=(p1,p2)=>p1.x===p2.x&&p1.y===p2.y&&p1.z===p2.z;let l0=0,d1=0,d2=0,pt=pat.pt;new Linea2(pat.pt[0],plink[0]).len;for(let i=0;i<pt.length-1;i++)d1+=new Linea2(pt[i],pt[i+1]).len,d2+=new Linea2(plink[i],plink[i+1]).len;for(let ii=0;ii<pt.length;ii++){const addpts=(ss,mat,deltav,coeffz)=>{for(const s of ss){let p=new THREE.Vector3(s.x,s.y,s.x*coeffz);p.applyMatrix4(mat),vertices.push(p.x,p.y,p.z),uvs.push(s.u,s.v+deltav)}};let angolo=-Math.PI/2;angolo=ii<pt.length-1?angle3point(plink[ii],pt[ii],pt[ii+1])+Math.PI/2:-(angle3point(pt[ii-1],pt[ii],plink[ii])+Math.PI/2);let coefficente=-Math.tan(angolo),seg1=pat.infosegmento(ii,!0),obj=new THREE.Object3D;obj.position.set(seg1.x,0,seg1.y),obj.rotation.set(0,(90-seg1.ang)*PIF,0),obj.updateMatrix(),addpts(pbase,obj.matrix,l0,coefficente),l0+=seg1.l}for(let li=0;li<lp-1;li++)for(let i=0;i<np-1;i++){const addindexquad=(i1,i2,i3,i4)=>{invert?indices.push(i1,i3,i2,i3,i4,i2):indices.push(i1,i2,i3,i3,i2,i4)},j=i+1;equalpos(pbase[i],pbase[j])||addindexquad(i+li*np,j+li*np,i+(li+1)*np,j+(li+1)*np)}const geometry=new THREE.BufferGeometry;geometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3)),geometry.setAttribute("uv",new THREE.Float32BufferAttribute(uvs,2)),geometry.setIndex(indices),geometry.computeVertexNormals(),gcad[ky]=geometry}return gcad[ky]}}(gcad,pbase,pat,plink,invert);return geo1&&(options.nolines||options.nosidelines||grp.add(edgesfromgeometry(geo1)),grp.add(getmesh(geo1,mats[2]||mats[0]||mwhite))),estrusorotate(orient,grp,0)}async function spritemat(gcad,file){try{let tm={transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1};if(file.startsWith("#"))tm.color=file;else{let tx=await gcad.tex(file,1e3,1e3);tx?tm.map=tx:tm.color="black"}return new THREE.SpriteMaterial(tm)}catch(error){return mwhite}}function getsprite0(ispunto,x,y,z,mat,options={}){options||(options={});let{size:size=50,pick:pick=!1,screen:screen=!1,sizex:sizex,sizey:sizey}=options;const sprite=new THREE.Sprite(mat);sprite.position.set(0,0,0),sprite.userData.issprite=!0,sprite.userData.ispunto=ispunto,sprite.userData.ispick=pick,sprite.userData.isScreen=screen,sprite.renderOrder=999,sprite.layers.set(29),sprite.name=ispunto?"_punto":"_sprite";let gr=new THREE.Group;return gr.position.set(x,y,z),gr.scale.set(sizex||size,sizey||sizex||size,1),gr.add(sprite),gr.traverse((obj=>{obj.material&&(obj.material.depthTest=!1,obj.material.depthWrite=!1)})),gr.renderOrder=999,gr}async function getpunto(gcad,x,y,z,color="yellow",options){options||(options={size:20}),options.screen=!0;const texture=await function createCircleTexture(gcad,size=64,color="rgba(255,0,0,1)"){const ky=`ct|${size}|${color}`;if(!gcad.textures[ky]){const canvas=document.createElement("canvas");canvas.width=canvas.height=size;const ctx=canvas.getContext("2d"),radius=size/2;ctx.clearRect(0,0,size,size),ctx.fillStyle=color,ctx.beginPath(),ctx.arc(radius,radius,radius,0,2*Math.PI),ctx.fill();const texture=new THREE.CanvasTexture(canvas);texture.needsUpdate=!0,gcad.textures[ky]=texture}return gcad.textures[ky]}(gcad,64,color);return getsprite0(!0,x,y,z,new THREE.SpriteMaterial({map:texture,transparent:!0,fog:!1,toneMapped:!1}),options)}function getsprite(gcad,x,y,z,mat,options={}){return getsprite0(!1,x,y,z,mat,options)}class GLTFLoader extends Loader{constructor(manager){super(manager),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(parser){return new GLTFMaterialsClearcoatExtension(parser)})),this.register((function(parser){return new GLTFMaterialsDispersionExtension(parser)})),this.register((function(parser){return new GLTFTextureBasisUExtension(parser)})),this.register((function(parser){return new GLTFTextureWebPExtension(parser)})),this.register((function(parser){return new GLTFTextureAVIFExtension(parser)})),this.register((function(parser){return new GLTFMaterialsSheenExtension(parser)})),this.register((function(parser){return new GLTFMaterialsTransmissionExtension(parser)})),this.register((function(parser){return new GLTFMaterialsVolumeExtension(parser)})),this.register((function(parser){return new GLTFMaterialsIorExtension(parser)})),this.register((function(parser){return new GLTFMaterialsEmissiveStrengthExtension(parser)})),this.register((function(parser){return new GLTFMaterialsSpecularExtension(parser)})),this.register((function(parser){return new GLTFMaterialsIridescenceExtension(parser)})),this.register((function(parser){return new GLTFMaterialsAnisotropyExtension(parser)})),this.register((function(parser){return new GLTFMaterialsBumpExtension(parser)})),this.register((function(parser){return new GLTFLightsExtension(parser)})),this.register((function(parser){return new GLTFMeshoptCompression(parser)})),this.register((function(parser){return new GLTFMeshGpuInstancing(parser)}))}load(url,onLoad,onProgress,onError){const scope=this;let resourcePath;if(""!==this.resourcePath)resourcePath=this.resourcePath;else if(""!==this.path){const relativeUrl=LoaderUtils.extractUrlBase(url);resourcePath=LoaderUtils.resolveURL(relativeUrl,this.path)}else resourcePath=LoaderUtils.extractUrlBase(url);this.manager.itemStart(url);const _onError=function(e){onError?onError(e):console.error(e),scope.manager.itemError(url),scope.manager.itemEnd(url)},loader=new FileLoader(this.manager);loader.setPath(this.path),loader.setResponseType("arraybuffer"),loader.setRequestHeader(this.requestHeader),loader.setWithCredentials(this.withCredentials),loader.load(url,(function(data){try{scope.parse(data,resourcePath,(function(gltf){onLoad(gltf),scope.manager.itemEnd(url)}),_onError)}catch(e){_onError(e)}}),onProgress,_onError)}setDRACOLoader(dracoLoader){return this.dracoLoader=dracoLoader,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(ktx2Loader){return this.ktx2Loader=ktx2Loader,this}setMeshoptDecoder(meshoptDecoder){return this.meshoptDecoder=meshoptDecoder,this}register(callback){return-1===this.pluginCallbacks.indexOf(callback)&&this.pluginCallbacks.push(callback),this}unregister(callback){return-1!==this.pluginCallbacks.indexOf(callback)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback),1),this}parse(data,path,onLoad,onError){let json;const extensions={},plugins={},textDecoder=new TextDecoder;if("string"==typeof data)json=JSON.parse(data);else if(data instanceof ArrayBuffer){if(textDecoder.decode(new Uint8Array(data,0,4))===BINARY_EXTENSION_HEADER_MAGIC){try{extensions[EXTENSIONS.KHR_BINARY_GLTF]=new GLTFBinaryExtension(data)}catch(error){return void(onError&&onError(error))}json=JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content)}else json=JSON.parse(textDecoder.decode(data))}else json=data;if(void 0===json.asset||json.asset.version[0]<2)return void(onError&&onError(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const parser=new GLTFParser(json,{path:path||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});parser.fileLoader.setRequestHeader(this.requestHeader);for(let i=0;i<this.pluginCallbacks.length;i++){const plugin=this.pluginCallbacks[i](parser);plugin.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),plugins[plugin.name]=plugin,extensions[plugin.name]=!0}if(json.extensionsUsed)for(let i=0;i<json.extensionsUsed.length;++i){const extensionName=json.extensionsUsed[i],extensionsRequired=json.extensionsRequired||[];switch(extensionName){case EXTENSIONS.KHR_MATERIALS_UNLIT:extensions[extensionName]=new GLTFMaterialsUnlitExtension;break;case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:extensions[extensionName]=new GLTFDracoMeshCompressionExtension(json,this.dracoLoader);break;case EXTENSIONS.KHR_TEXTURE_TRANSFORM:extensions[extensionName]=new GLTFTextureTransformExtension;break;case EXTENSIONS.KHR_MESH_QUANTIZATION:extensions[extensionName]=new GLTFMeshQuantizationExtension;break;default:extensionsRequired.indexOf(extensionName)>=0&&void 0===plugins[extensionName]&&console.warn('THREE.GLTFLoader: Unknown extension "'+extensionName+'".')}}parser.setExtensions(extensions),parser.setPlugins(plugins),parser.parse(onLoad,onError)}parseAsync(data,path){const scope=this;return new Promise((function(resolve,reject){scope.parse(data,path,resolve,reject)}))}}function GLTFRegistry(){let objects={};return{get:function(key){return objects[key]},add:function(key,object){objects[key]=object},remove:function(key){delete objects[key]},removeAll:function(){objects={}}}}
659
649
  /*********************************/
660
650
  /********** EXTENSIONS ***********/
661
651
  /*********************************/const EXTENSIONS={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};
@@ -1119,4 +1109,4 @@ async function clear(){function destroymesh(mesh){function disposeMaterial(mater
1119
1109
  * @param {THREE.Object3D} gruppo - oggetto root
1120
1110
  * @param {Array<{ mats: string[], name?: string }>} matricole - elenco da evidenziare
1121
1111
  * @returns {Promise<File[]>}
1122
- */async function evidenziaColli(gruppo,matricole,callback){salvaMaterialiOriginali(gruppo);const SIDE=THREE.DoubleSide,mwhite=new THREE.MeshStandardMaterial({color:16777215,roughness:.5,metalness:.4,side:SIDE}),mgreen=new THREE.MeshStandardMaterial({color:36864,roughness:.5,metalness:.4,side:SIDE});let ii=0;try{for(let mts of matricole)ii++,mts.name||(mts.name=`collo_${ii}`),applicaEvidenziazione(gruppo,mts.mats,mwhite,mgreen),await callback(mts)}catch(err){console.error("Errore durante evidenzia:",err)}finally{ripristinaMaterialiOriginali()}}function TODEG(a,dec=1){let C=10**dec;return Math.round(180*a*C/Math.PI)/C}function TORAD(a,dec=3){let C=10**dec;return Math.round(a*PIF*C)/C}const blocked={window:void 0,self:void 0,globalThis:void 0,document:void 0,Function:void 0,eval:void 0,fetch:void 0,XMLHttpRequest:void 0};function getOggetto(obj,exclude=[]){if(Array.isArray(obj))return obj.map((item=>getOggetto(item,exclude)));if(obj&&"object"==typeof obj){const result={};for(const[key,value]of Object.entries(obj))"function"==typeof value||exclude&&exclude.includes(key)||(result[key]=getOggetto(value,exclude));return result}return obj}async function evalcustomfunction(amb,code,values,objects){try{values||(values={}),objects||(objects={});const params={GCAD:!1,...values,A:amb,V:amb.vari,amb:amb,log:function addlog(...pars){const sanitized=pars.map((p=>getOggetto(p)));console.log(...sanitized)},Math:Math,clean:clean,SP:SP,Punto2:Punto2,Linea2:Linea2,clamp:clamp,hash:hash,PIF:PIF,getshape:getshape,shapeclip:shapeclip,...objects},paramNames=[...Object.keys(params),...Object.keys(blocked)],paramValues=[...Object.values(params),...Object.values(blocked)],fn=new Function(...paramNames,`\n try {\n return (async () => {\n ${code}\n })();\n } catch (err) {\n err.stack = '[SCRIPT] ' + err.stack;\n throw err;\n }`);return await fn(...paramValues)}catch(error){throw console.error("Errore durante l'esecuzione:",error),error}}function setLineColorMode(white){white?(materialline1.color.set(16777215),materialline2.color.set(16777215)):(materialline1.color.set(3158064),materialline2.color.set(5263440)),materialline1.needsUpdate=!0,materialline2.needsUpdate=!0}export{Linea2,Matrix3D,PIF,Punto2,SIDE,SP,TODEG,TORAD,Vis2d,addmovpivot,angle2vec,angle3point,blocked,calcolatasks,clamp,clean,creategroup,deletegroup,dxfbulge,edgesfromgeometry,elaborapercorso,estruso,estrusopat,evalcustomfunction,evidenziaColli,extractTextures,get3dshape,getOggetto,getbordi,getbox,getcilindro,getcyl,getdumpmacro,getemitter,getface,getfakeshadow,getline,getlinesgeom,getmesh,getmovimento,getnodebyid,getpannello,getpoint,getprojectkeys,getptsoffset,getpunto,getquota,getreceiver,getriferimento,getshape,getsphere,getsprite,getsubrules,gettarghetta,groupfromgeometry,hash,infoestrudi,isfn,ismacro,materialline1,materialline2,mblack,mblue,mgray1,mgray2,mgreen,mred,mwhite,newgcad,normal2,posiziona,raccordabezier,randombasemat,revolve,ripristinaMaterialiOriginali,salvaMaterialiOriginali,scaleunit,setLineColorMode,shapeclip,smat,spritemat,svuotanodo,valutagrafica};
1112
+ */async function evidenziaColli(gruppo,matricole,callback){salvaMaterialiOriginali(gruppo);const SIDE=THREE.DoubleSide,mwhite=new THREE.MeshStandardMaterial({color:16777215,roughness:.5,metalness:.4,side:SIDE}),mgreen=new THREE.MeshStandardMaterial({color:36864,roughness:.5,metalness:.4,side:SIDE});let ii=0;try{for(let mts of matricole)ii++,mts.name||(mts.name=`collo_${ii}`),applicaEvidenziazione(gruppo,mts.mats,mwhite,mgreen),await callback(mts)}catch(err){console.error("Errore durante evidenzia:",err)}finally{ripristinaMaterialiOriginali()}}function TODEG(a,dec=1){let C=10**dec;return Math.round(180*a*C/Math.PI)/C}function TORAD(a,dec=3){let C=10**dec;return Math.round(a*PIF*C)/C}const blocked={window:void 0,self:void 0,globalThis:void 0,document:void 0,Function:void 0,eval:void 0,fetch:void 0,XMLHttpRequest:void 0};function getOggetto(obj,exclude=[]){if(Array.isArray(obj))return obj.map((item=>getOggetto(item,exclude)));if(obj&&"object"==typeof obj){const result={};for(const[key,value]of Object.entries(obj))"function"==typeof value||exclude&&exclude.includes(key)||(result[key]=getOggetto(value,exclude));return result}return obj}async function evalcustomfunction(amb,code,values,objects){try{values||(values={}),objects||(objects={});const params={GCAD:!1,...values,A:amb,V:amb.vari,amb:amb,log:function addlog(...pars){const sanitized=pars.map((p=>getOggetto(p)));console.log(...sanitized)},Math:Math,clean:clean,SP:SP,Punto2:Punto2,Linea2:Linea2,clamp:clamp,hash:hash,PIF:PIF,getshape:getshape,shapeclip:shapeclip,...objects},paramNames=[...Object.keys(params),...Object.keys(blocked)],paramValues=[...Object.values(params),...Object.values(blocked)],fn=new Function(...paramNames,`\n try {\n return (async () => {\n ${code}\n })();\n } catch (err) {\n err.stack = '[SCRIPT] ' + err.stack;\n throw err;\n }`);return await fn(...paramValues)}catch(error){throw console.error("Errore durante l'esecuzione:",error),error}}function setLineColorMode(white){white?(materialline1.color.set(16777215),materialline2.color.set(16777215)):(materialline1.color.set(3158064),materialline2.color.set(5263440)),materialline1.needsUpdate=!0,materialline2.needsUpdate=!0}export{Linea2,Matrix3D,PIF,Punto2,SIDE,SP,TODEG,TORAD,Vis2d,addmovpivot,angle2vec,angle3point,blocked,calcolatasks,clamp,clean,creategroup,deletegroup,dxfbulge,edgesfromgeometry,elaborapercorso,estruso,estrusopat,evalcustomfunction,evidenziaColli,extractTextures,get3dshape,getOggetto,getbordi,getbox,getcilindro,getcyl,getdumpmacro,getemitter,getface,getfakeshadow,getline,getlinesgeom,getmesh,getmovimento,getnodebyid,getpannello,getpoint,getprojectkeys,getptsoffset,getpunto,getquota,getreceiver,getriferimento,getshape,getsphere,getsprite,getsubrules,gettarghetta,groupfromgeometry,hash,infoestrudi,isfn,ismacro,mapvertices,materialline1,materialline2,mblack,mblue,mgray1,mgray2,mgreen,mred,mwhite,newgcad,normal2,posiziona,raccordabezier,randombasemat,revolve,ripristinaMaterialiOriginali,salvaMaterialiOriginali,scaleunit,setLineColorMode,shapeclip,smat,spritemat,svuotanodo,valutagrafica};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markuno_lib",
3
- "version": "1.2.23",
3
+ "version": "1.2.24",
4
4
  "description": "Croswil Markuno Language Lib",
5
5
  "author": "Croswil SRL",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -37,6 +37,12 @@
37
37
  * @param {number|Linea2} l - Lunghezza di estensione o linea da intersecare
38
38
  * @returns {Linea2} Nuova linea estesa
39
39
  */ estendi(l: number | Linea2): Linea2;
40
+ puntot(t: any): Punto2;
41
+ proiezionet(p: any): {
42
+ p: Punto2;
43
+ t: number;
44
+ };
45
+ proiezione(p: any): Punto2;
40
46
  /**
41
47
  * Calcola il vettore direzione normalizzato della linea
42
48
  * @returns {Punto2} Vettore direzione
@@ -45,6 +51,8 @@
45
51
  * Calcola il vettore normale normalizzato della linea
46
52
  * @returns {Punto2} Vettore normale
47
53
  */ get normale(): Punto2;
54
+ perpendicolare(p?: any, lunghezza?: number): Linea2;
55
+ perpendicolaret(t: any, lunghezza?: number): Linea2;
48
56
  /**
49
57
  * Crea una nuova linea ruotata di un certo angolo
50
58
  * @param {number} [angle=Math.PI/2] - Angolo di rotazione in radianti
@@ -78,12 +86,12 @@
78
86
  * @returns {boolean} True se parallele
79
87
  */ isparallela(line2: Linea2): boolean;
80
88
  /**
81
- * Restituisce alcune info sul “quadrilatero” formato da questa linea e da line2,
82
- * assumendo che siano parallele e abbiano verso invertito.
83
- * @param {Linea2} line2
84
- * @returns {Object|undefined}
85
- * { angle, aini, afin, l, distanza } oppure undefined se non parallele o degenere
86
- */ infoquad(line2: Linea2): any | undefined;
89
+ * Restituisce alcune info sul “quadrilatero” formato da questa linea e da line2,
90
+ * assumendo che siano parallele e abbiano verso invertito.
91
+ * @param {Linea2} line2
92
+ * @returns {Object|undefined}
93
+ * { angle, aini, afin, l, distanza } oppure undefined se non parallele o degenere
94
+ */ infoquad(line2: Linea2): any | undefined;
87
95
  /**
88
96
  * Verifica se la linea è perpendicolare a un'altra
89
97
  * @param {Linea2} line2 - Seconda linea
@@ -310,26 +318,13 @@ export function clamp(n: any, min?: number, max?: number): any;
310
318
  export function clean(k: any, locase?: boolean): any;
311
319
  export function creategroup(name: any): any;
312
320
  export function deletegroup(grpbase: any, name: any): void;
313
- /**
314
- * Esegue la semplificazione di un poligono (array di punti) combinando
315
- * l’algoritmo di distanza radiale e l’algoritmo di Ramer–Douglas–Peucker.
316
- *
317
- * @param {Array<{x:number,y:number}>} points - Array di punti {x,y} da semplificare.
318
- * @param {number} [tolerance=1] - Tolleranza di semplificazione: distanza minima consentita
319
- * (in unità lineari) tra i punti; internamente usata al quadrato per il calcolo
320
- * (`sqTolerance = tolerance * tolerance`). Valori più grandi rimuovono più punti.
321
- * @param {boolean} [highestQuality=false] - Se `true`, salta il passaggio di
322
- * semplificazione radiale e usa solo Douglas–Peucker per massima qualità.
323
- * @returns {Array<{x:number,y:number}>} Nuovo array di punti semplificato.
324
- */
325
321
  /**
326
322
  * Calcola i punti di un arco DXF dato p1, p2, bulge e n punti intermedi.
327
323
  * p1, p2: oggetti {x, y}
328
324
  * bulge: valore DXF tra p1 e p2
329
325
  * n: numero di punti INTERMEDI da inserire tra p1 e p2 (n=0 -> solo estremi)
330
326
  * Return: array di punti [{x, y}, ..., {x, y}]
331
- */
332
- export function dxfbulge(p1: any, p2: any, bulge: any, n?: number): any;
327
+ */ export function dxfbulge(p1: any, p2: any, bulge: any, n?: number): any;
333
328
  export function edgesfromgeometry(g1: any, layer?: number): any;
334
329
  export function elaborapercorso(sh1: any, bordo: any, taglio: any, oggetti: any, countid?: number): {
335
330
  countid: number;
@@ -349,16 +344,7 @@ export function elaborapercorso(sh1: any, bordo: any, taglio: any, oggetti: any,
349
344
  * @param {Object} options - Opzioni di configurazione
350
345
  * @returns {THREE.Group} Gruppo contenente la geometria estrusa
351
346
  */ export function estruso(gcad: any, orient: string, hshape: number, shape: any, holes: any[], mats: any[], options: any): THREE.Group;
352
- /**
353
- * Crea una geometria estrusa con opzioni avanzate
354
- * @param {string} orient - Orientamento dell'estrusione
355
- * @param {number} hshape - Altezza dell'estrusione
356
- * @param {Object} shape - Forma base
357
- * @param {Array} holes - Array di fori
358
- * @param {Array} mats - Array di materiali
359
- * @param {Object} options - Opzioni di configurazione
360
- * @returns {THREE.Group} Gruppo contenente la geometria estrusa
361
- */ export function estrusopat(gcad: any, orient: string, pat: any, shape: any, mats: any[], options: any): THREE.Group;
347
+ export function estrusopat(gcad: any, orient: any, pat: any, plink: any, shape: any, mats: any, options: any): any;
362
348
  export function evalcustomfunction(amb: any, code: any, values: any, objects: any): Promise<any>;
363
349
  /**
364
350
  * Applica evidenziazione multipla e salva una lista di immagini
@@ -502,31 +488,7 @@ export function getriferimento(dati: any, x?: number, y?: number, z?: number, id
502
488
 
503
489
  * @returns {Array<Object>} Array di punti con normali e coordinate UV
504
490
  */
505
- /**
506
- * Crea un oggetto shape per manipolare forme 2D
507
- * @returns {Object} Oggetto con metodi per manipolare la forma
508
- * @property {string} key - Hash univoco della forma
509
- * @property {Array<{x:number,y:number}>} pt - Array dei punti della forma
510
- * @property {Array<number>} vec - Array dei punti come vettore [x1,y1,x2,y2,...]
511
- * @property {number} orient - Orientamento della forma (1 orario, -1 antiorario, 0 degenere)
512
- * @method clone() - Crea una copia della forma
513
- * @method rotate(deg) - Ruota la forma di deg gradi
514
- * @method move(x,y) - Sposta la forma di x,y
515
- * @method fromclip(vv) - Inizializza da punti in formato clipper
516
- * @method fromvec(aa) - Inizializza da array di coordinate [x1,y1,x2,y2,...]
517
- * @method frompt(pts) - Inizializza da array di punti [{x,y},...]
518
- * @method fromdxfvec(verts) - vertici nel formato DXF LWPOLYLINE con bulge per i raccordi:
519
- * @method fromstr(str) - Inizializza da stringa con sintassi speciale
520
- * @method addpt(pts) - Aggiunge punti alla forma
521
- * @method addracc(v1,v2,suddivisioni,addv1v2) - Aggiunge raccordo tra punti
522
- * @method setorient(mode) - Imposta l'orientamento della forma
523
- * @method reverse() - Inverte l'ordine dei punti
524
- * @method pointinshape(p) - Verifica se un punto è interno alla forma
525
- * @method azzera() - Rimuove tutti i punti
526
- * @method removeduplicate(delta) - Rimuove punti duplicati
527
- * @method to3d(u0,c,a,b,shape,invert) - Converte in forma 3D con normali
528
- */
529
- export function getshape(): any;
491
+ export function getshape(): Array<any>;
530
492
  /**
531
493
  * Crea una sfera 3D come gruppo (mesh + edges opzionali).
532
494
  * @param {object} gcad - riferimento (non usato ma coerente con getbox)
@@ -579,6 +541,21 @@ export function infoestrudi(shape: any, hshape: any, pts: any, options: any, sh:
579
541
  };
580
542
  export function isfn(row: any): boolean;
581
543
  export function ismacro(row: any): any;
544
+ /**
545
+ * Esegue la semplificazione di un poligono (array di punti) combinando
546
+ * l’algoritmo di distanza radiale e l’algoritmo di Ramer–Douglas–Peucker.
547
+ *
548
+ * @param {Array<{x:number,y:number}>} points - Array di punti {x,y} da semplificare.
549
+ * @param {number} [tolerance=1] - Tolleranza di semplificazione: distanza minima consentita
550
+ * (in unità lineari) tra i punti; internamente usata al quadrato per il calcolo
551
+ * (`sqTolerance = tolerance * tolerance`). Valori più grandi rimuovono più punti.
552
+ * @param {boolean} [highestQuality=false] - Se `true`, salta il passaggio di
553
+ * semplificazione radiale e usa solo Douglas–Peucker per massima qualità.
554
+ * @returns {Array<{x:number,y:number}>} Nuovo array di punti semplificato.
555
+ */ export function mapvertices(pat1: any, pat2: any): Array<{
556
+ x: number;
557
+ y: number;
558
+ }>;
582
559
  export let materialline1: any;
583
560
  export let materialline2: any;
584
561
  export const mblack: any;
@@ -637,14 +614,19 @@ export function revolve(gcad: any, shape: any, orient: any, mat: any, options: a
637
614
  */ export function salvaMaterialiOriginali(gruppo: THREE.Object3D): void;
638
615
  export const scaleunit: 0.001;
639
616
  export function setLineColorMode(white: any): void;
640
- /**
641
- * Crea un oggetto per operazioni booleane e manipolazione di forme 2D usando la libreria Clipper
642
- * @returns {Object} Oggetto con metodi per operazioni su forme
643
- * @property {Function} offset - Crea un offset della forma
644
- * @property {Function} inflate - Espande o contrae una forma
645
- * @property {Function} unisci - Unisce più forme con gestione di fori e tagli
646
- */
647
- export function shapeclip(): any;
617
+ export function shapeclip(): {
618
+ offset(shape: any, delta: any, full?: boolean): any;
619
+ inflate: (shape: any, delta?: number, mantainorder?: boolean, isopen?: number) => any;
620
+ inflateopen: (pts: any, delta: any) => any;
621
+ inflatecornici(shape: any, delta: number, linetruncateini: any, linetruncateend: any): any;
622
+ intersecasplitter(areabase: any, forma1: any): any;
623
+ offsetpts(pts: any, delta?: number): any;
624
+ areesplitter(shapept: any, clipspt: any, useInflatedClipping?: boolean): any[];
625
+ unisci(shapes: any, holes: any, cuts: any): {
626
+ shape: any;
627
+ holes: any[];
628
+ }[];
629
+ };
648
630
  export function smat(gcad: any, file: any, op?: {}): Promise<any>;
649
631
  export function spritemat(gcad: any, file: any): Promise<any>;
650
632
  export function svuotanodo(n: any): void;