rm-graphical-computing 1.0.64 → 1.0.65

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.
Files changed (3) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +1775 -1680
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var Zn=Object.defineProperty;var Kn=(n,t,e)=>t in n?Zn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Oe=(n,t,e)=>Kn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function Qn(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const y=Qn(lt);function Jn(n,t=!1){const e=n[0].index!==null,o=new Set(Object.keys(n[0].attributes)),i=new Set(Object.keys(n[0].morphAttributes)),r={},s={},a=n[0].morphTargetsRelative,l=new lt.BufferGeometry;let u=0;for(let h=0;h<n.length;++h){const g=n[h];let c=0;if(e!==(g.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const m in g.attributes){if(!o.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.'),null;r[m]===void 0&&(r[m]=[]),r[m].push(g.attributes[m]),c++}if(c!==o.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==g.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const m in g.morphAttributes){if(!i.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[m]===void 0&&(s[m]=[]),s[m].push(g.morphAttributes[m])}if(t){let m;if(e)m=g.index.count;else if(g.attributes.position!==void 0)m=g.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(u,m,h),u+=m}}if(e){let h=0;const g=[];for(let c=0;c<n.length;++c){const m=n[c].index;for(let w=0;w<m.count;++w)g.push(m.getX(w)+h);h+=n[c].attributes.position.count}l.setIndex(g)}for(const h in r){const g=tn(r[h]);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,g)}for(const h in s){const g=s[h][0].length;if(g===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let c=0;c<g;++c){const m=[];for(let x=0;x<s[h].length;++x)m.push(s[h][x][c]);const w=tn(m);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(w)}}return l}function tn(n){let t,e,o,i=-1,r=0;for(let u=0;u<n.length;++u){const h=n[u];if(t===void 0&&(t=h.array.constructor),t!==h.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=h.itemSize),e!==h.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(o===void 0&&(o=h.normalized),o!==h.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=h.gpuType),i!==h.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=h.count*e}const s=new t(r),a=new lt.BufferAttribute(s,e,o);let l=0;for(let u=0;u<n.length;++u){const h=n[u];if(h.isInterleavedBufferAttribute){const g=l/e;for(let c=0,m=h.count;c<m;c++)for(let w=0;w<e;w++){const x=h.getComponent(c,w);a.setComponent(c+g,w,x)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const to=(n,t,e)=>{let o=new y.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(n),i.push(t);let r=new y.BufferGeometry;r.setFromPoints(i),r.rotateX(-Math.PI/2),e.add(new y.Line(r,o))},te=(n,t,e,o,i=1e-8)=>{const r=t.x-n.x,s=t.y-n.y,a=o.x-e.x,l=o.y-e.y,u=r*l-s*a;if(Math.abs(u)<i)return null;const h=((e.x-n.x)*l-(e.y-n.y)*a)/u,g=((e.x-n.x)*s-(e.y-n.y)*r)/u;return h<-i||h>1+i||g<-i||g>1+i?null:{point:new y.Vector3(n.x+h*r,n.y+h*s,n.z)}},eo=(n,t,e={})=>{const{fontSize:o=36,fontFamily:i="sans-serif",backgroundColor:r="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=e,h=document.createElement("canvas").getContext("2d");h.font=`bold ${o}px ${i}`;const c=h.measureText(n).width;let m=Math.min(c+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=m,x.height=w;const P=x.getContext("2d");P.fillStyle=r,P.fillRect(0,0,m,w),P.fillStyle=s,P.font=`bold ${o}px ${i}`,P.textAlign="center",P.textBaseline="middle",c>l-a*2?no(P,n,m/2,w/2,l,o):P.fillText(n,m/2,w/2);const M=new y.CanvasTexture(x),d=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),f=new y.Sprite(d);f.position.set(t.x,t.y,t.z);const p=.005;return f.scale.set(m*p,w*p,1),f};function no(n,t,e,o,i,r){const s=t.split("");let a="",l=r*1.2,u=o;for(let h=0;h<s.length;h++){const g=a+s[h];n.measureText(g).width>i&&h>0?(n.fillText(a,e,u),a=s[h],u+=l):a=g}n.fillText(a,e,u)}const oe=(n,t,e=.01)=>{const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(o<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const r={x:n.x/o,y:n.y/o,z:n.z/o},s={x:t.x/i,y:t.y/i,z:t.z/i};let a=r.x*s.x+r.y*s.y+r.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),u=l<=e;return{parallel:u,sameDirection:u?a>0:null,angle:l}},oo=(n,t,e,o)=>{const i=n;let r=[];if(o&&o.length&&(r=o.map(V=>V.clone())),!i||i.length<4)return{};const s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let u=1/0,h=-1/0,g=1/0,c=-1/0;for(const V of i){const v=V.dot(s),S=V.dot(a);v<u&&(u=v),v>h&&(h=v),S<g&&(g=S),S>c&&(c=S)}const m=i[0].dot(l),w=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(g)).add(l.clone().multiplyScalar(m)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(g)).add(l.clone().multiplyScalar(m)),P=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(m)),M=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(m));let d=[w,x,P,M],f=oe(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));f&&f.parallel&&(d=[w,M,P,x]);let p=0;if(o.length>0){const V=new y.Vector3().subVectors(d[1],d[0]).normalize(),v=V.clone().negate(),S=new y.Vector3().subVectors(d[3],d[0]).normalize(),z=S.clone().negate();let D=d[0].distanceTo(d[1]),_=d[0].distanceTo(d[3]),T=D/t,E=_/e,A=.001;for(let F=0;F<T;F++){let I=d[0],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(V,t),C=W.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=R}if(B>=E/2)break;p+=B,d[0]=d[0].addScaledVector(V,t),d[3]=d[3].addScaledVector(V,t)}D=d[0].distanceTo(d[1]),T=D/t;for(let F=0;F<T;F++){let I=d[1],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(v,t),C=W.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=R}if(B>=E/2)break;p+=B,d[1]=d[1].addScaledVector(v,t),d[2]=d[2].addScaledVector(v,t)}D=d[0].distanceTo(d[1]),T=D/t;for(let F=0;F<E;F++){let I=d[3],B=0;for(let L=0;L<T;L++){let W=I.clone().addScaledVector(V,t),C=W.clone().addScaledVector(z,e),R=I.clone().addScaledVector(z,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=W}if(B>=T/2)break;p+=B,d[2]=d[2].addScaledVector(z,e),d[3]=d[3].addScaledVector(z,e)}}const b=d[0].distanceTo(d[1])*d[0].distanceTo(d[3]);return{facePoints:d,boxArea:b,totalInPlaneNum:p}},Jt=(n,t,e,o,i=y.MathUtils.degToRad(8))=>{const r=new y.Vector3,s=new y.Vector3;r.subVectors(new y.Vector3(t.x,t.y,0),new y.Vector3(n.x,n.y,0)).normalize(),s.subVectors(new y.Vector3(o.x,o.y,0),new y.Vector3(e.x,e.y,0)).normalize();const a=r.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),u=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:u,angle:l,angleDeg:y.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},re=(n,t,e,o)=>{const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=i.length(),a=r.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),r.normalize();const l=Math.abs(i.dot(r)),u=Math.min(1,Math.max(0,l)),h=Math.acos(u),g=y.MathUtils.radToDeg(h),c=1-u;return{rate:c,percent:`${(c*100).toFixed(2)}%`,angle:g,isPerpendicular:Math.abs(g-90)<.01,isParallel:g<.01}},ee=(n,t,e=!1)=>new y.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),ne=(n,t,e,o,i={})=>{const{parallelAngleMax:r=y.MathUtils.degToRad(10),collinearAngleMax:s=y.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,u=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),g=u.clone().normalize(),c=h.clone().normalize();let m=y.MathUtils.clamp(g.dot(c),-1,1);const w=Math.acos(Math.abs(m)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};m<0&&c.negate();const P=new y.Vector3().addVectors(g,c).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),d=en(e,M,g),f=en(o,M,g),p=(d+f)/2,b=Math.max(d,f),V=n.dot(P),v=t.dot(P),S=e.dot(P),z=o.dot(P),D=Math.min(V,v),_=Math.max(V,v),T=Math.min(S,z),E=Math.max(S,z),A=_-D,F=E-T,I=Math.min(A,F),B=Math.min(_,E)-Math.max(D,T),L=B<0?-B:0,W=B>0?B:0,C=I>0?W/I:0,R=ro(n,t,e,o),H=w<=s&&p<a;let X;return H?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:x,avgPerpendicularDistance:p,maxPerpendicularDistance:b,gap:L,overlap:W,closestDistance:R}};function en(n,t,e){const o=new y.Vector3().subVectors(n,t),i=o.dot(e),r=e.clone().multiplyScalar(i);return new y.Vector3().subVectors(o,r).length()}function ro(n,t,e,o){const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=new y.Vector3().subVectors(e,n),a=i.dot(i),l=i.dot(r),u=r.dot(r),h=i.dot(s),g=r.dot(s),c=a*u-l*l;let m,w;c<1e-10?(m=0,w=u!==0?g/u:0):(m=(l*g-u*h)/c,w=(a*g-l*h)/c),m=y.MathUtils.clamp(m,0,1),w=u!==0?y.MathUtils.clamp((l*m+g)/u,0,1):0,m=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(m)),P=e.clone().add(r.clone().multiplyScalar(w));return x.distanceTo(P)}const nn=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),io=n=>{let t=new y.Vector3(n.start.x,n.start.y,n.start.z),e=new y.Vector3(n.end.x,n.end.y,n.end.z),o=t.distanceTo(e),i=n.rooftopPz-n.start.z,r=nn(o,100),s=nn(i,70),a=i/s,l=new Map;for(let x=0;x<s;x++)l.set((x+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let u=new y.Line3(t,e);const h=n.originalPoints,g=new y.Vector3;for(let x=0;x<h.length;x++){const P=h[x];let d=u.closestPointToPoint(P,!0,g).distanceTo(P);const f=Math.floor(d/a);if(f<s){const p=l.get((f+1)*a);p.count++,P.z<p.minZ&&(p.minZ=P.z),P.z>p.maxZ&&(p.maxZ=P.z)}}let c,m,w=r/2;for(const[x,P]of l)if(P.count>=w){c=P.minZ;break}for(const[x,P]of[...l.entries()].reverse())if(P.count>=w){m=P.maxZ;break}return{minZ:c,maxZ:m}},Ve=(n,t,e)=>{let o=new y.Plane;const i=new y.Vector3(n.x,n.y,n.z),r=new y.Vector3(t.x,t.y,t.z),s=new y.Vector3(t.x,t.y,t.z+5);o.setFromCoplanarPoints(i,r,s);const a=[],l=[];e.forEach(P=>{const M=new y.Vector3;o.projectPoint(P,M),l.push(M.clone()),M.z=i.z,a.push(M)});let u=new y.Vector3,h=new y.Vector3;o.projectPoint(i,u),o.projectPoint(r,h);const g=new y.Line3(u,h),c=[],m=[],w=[];let x=new y.Vector3;return a.forEach((P,M)=>{g.closestPointToPoint(P,!0,x).distanceTo(P)<.001?(c.push(e[M]),m.push(l[M])):w.push(P)}),{newOriginalPoints:c,newProjectPoints:w,newOnLinePoints:m}},so=n=>{function t(e,o,i,r,s,a,l,u,h){let g=new y.Line3(e,o),c=new Map,m=new y.Vector3,w=e.clone(),x=o.clone(),P=0;for(;;){let M=new Map,d=0;for(let f=0;f<h.checkResults.length;f++)if(!(h.checkResults[f].allCenterPoints.length/u*100<1))for(let b=0;b<h.checkResults[f].allCenterPoints.length;b++){if(c.has(f)&&c.get(f).removePtsIndex.includes(b))continue;let V=h.checkResults[f].allCenterPoints[b];V=new y.Vector3(V.x,V.y,V.z);let v=g.closestPointToPoint(V,!0,m),S=V.distanceTo(v);Math.abs(S-s)<.01&&(d++,M.has(f)?M.get(f).removePtsIndex.push(b):M.set(f,{index:f,removePtsIndex:[b]}))}if(P==l){e=w,o=x;break}if(d<a/20*18||d==0){M.clear(),l-P<5&&(e=w,o=x,c.clear());break}else{P++;for(const[f,p]of M)c.has(f)?c.get(f).removePtsIndex.push(...p.removePtsIndex):c.set(f,p);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),g.set(e,o)}}if(c.size>0&&P!=l)for(const[M,d]of c){let f=[],p=[];for(let b=0;b<h.checkResults[M].allCenterPoints.length;b++)d.removePtsIndex.includes(b)||(f.push(h.checkResults[M].allCenterPoints[b]),p.push(h.checkResults[M].originalVertices[b]));h.checkResults[M].allCenterPoints=f,h.checkResults[M].originalVertices=p}}for(let e=0;e<n.length;e++){const o=n[e];if(o.length<.5)continue;let i=-1,r=-1;if(!o.checkResults||o.checkResults.length<=0)continue;if(o.checkResults[0].originalVertices&&o.checkResults[0].originalVertices.length>0){const S=o.checkResults[0].originalVertices[0];let[z,D,_,T]=S;z=new y.Vector3(z.x,z.y,z.z),D=new y.Vector3(D.x,D.y,D.z),_=new y.Vector3(_.x,_.y,_.z),T=new y.Vector3(T.x,T.y,T.z),i=z.distanceTo(D),r=z.distanceTo(T);let E=new y.Vector3().subVectors(z,D).normalize(),A=oe(E,new y.Vector3(0,0,1));A&&A.parallel&&([r,i]=[i,r])}if(i<0||r<0)continue;let s=new y.Vector3(o.start.x,o.start.y,o.start.z),a=new y.Vector3(o.end.x,o.end.y,o.end.z);const l=s.distanceTo(a),u=o.rooftopPz-o.start.z,h=Math.ceil(l/i),g=Math.ceil(u/r);let c=s.clone(),m=a.clone(),w=m.clone().add(new y.Vector3(0,0,u)),x=c.clone().add(new y.Vector3(0,0,u)),P=new y.Vector3().subVectors(m,c).normalize(),M=P.clone().negate();new y.Vector3().subVectors(w,c).normalize().clone().negate();let f=i/2,p=l*u,b=i*r,V=p/b;t(c,x,P,i,f,g,h,V,o),t(m,w,M,i,f,g,h,V,o),o.start=c,o.end=m;const{newOriginalPoints:v}=Ve(c,m,o.originalPoints);o.originalPoints=v}},Lt=(n,t)=>new y.Vector3(n.x,n.y,0).distanceTo(new y.Vector3(t.x,t.y,0)),ao=(n,t,e=1e-6)=>{const o=new y.Vector3;return n.closestPointToPoint(t,!0,o),o.distanceTo(t)<e},Se=n=>{let t=0,e=[];for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o].distanceTo(n[i]);r>t&&(t=r,e=[n[o],n[i]])}return e},kt=(n,t,e=.03)=>Math.abs(n.x-t.x)<e&&Math.abs(n.y-t.y)<e&&Math.abs(n.z-t.z)<e,lo=()=>{const n=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),t=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),e=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0");return`#${n}${t}${e}`},co=(n,t=.001)=>{const e=new Map,o=[];for(const i of n){const r=Math.round(i.x/t),s=Math.round(i.y/t),a=Math.round(i.z/t),l=`${r},${s},${a}`;e.has(l)||(e.set(l,!0),o.push(i))}return o};class uo{constructor(){Oe(this,"results");Oe(this,"clusterResults");this.results=null}initLimits1(t,e){let o,i;return t<.3?o=5:t<.5?o=8:t<.8?o=10:t<1?o=15:t<2?o=30:t<3?o=35:t<4?o=40:t<5?o=45:t<6?o=50:t<7?o=60:t<8.5?o=70:t<10?o=80:t<15?o=100:t<20?o=120:t<25?o=140:t<30?o=160:t<35?o=180:t<40?o=200:t<45?o=230:t<50?o=250:o=350,e<1?i=30:e<2?i=40:e<2.5?i=45:e<3?i=60:e<3.6?i=70:e<4&&(i=80),{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits2(t,e){const r=Math.round(Math.max(5,Math.min(350,t/.08))),s=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(t,e){const o=Math.round(Math.max(5,Math.min(350,65*Math.sqrt(t))))*1,i=Math.round(Math.max(30,Math.min(80,15*Math.sqrt(e))))*1;return{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits3(t,e){let o;t<2?o=.06:t<10?o=.1:o=.15;const i=Math.round(Math.max(5,Math.min(350,t/o))),r=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:i,verticalSubdivisions:r}}createWallPlaneMeshFromFourPoints(t,e,o,i,r,s,a=16777215){const l=[t,e,o,i];for(let P=0;P<l.length;P++)this.isValidVector3(l[P])||(console.error(`点${P+1}包含无效数据:`,l[P]),l[P]=new y.Vector3(P,0,P));const u=new y.BufferGeometry,h=new Float32Array([l[0].x,l[0].y,l[0].z,l[1].x,l[1].y,l[1].z,l[2].x,l[2].y,l[2].z,l[3].x,l[3].y,l[3].z]),g=[0,1,2,0,2,3],c=new Float32Array([0,0,1,0,1,1,0,1]);u.setAttribute("position",new y.BufferAttribute(h,3)),u.setAttribute("uv",new y.BufferAttribute(c,2)),u.setIndex(g),u.computeVertexNormals();const m=new y.Mesh(u,r),w=new y.EdgesGeometry(u),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),m}createSubdividedWallPlane(t,e,o,i,r){const s=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return s;const a=new y.Vector3(t.start.x,t.start.y,t.start.z),l=new y.Vector3(t.end.x,t.end.y,t.end.z),u=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),g=[a,l,u,h];for(let d=0;d<g.length;d++)if(!this.isValidVector3(g[d]))return console.error(`墙体基础点${d}无效:`,g[d]),s;const c=a.distanceTo(l),m=Math.abs(t.rooftopPz-t.start.z);if(c===0||m===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",l),console.log(t.length),s;const w=c/o,x=m/e,P=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let d=0;d<e;d++)for(let f=0;f<o;f++)try{const p=new y.Vector3().copy(a).add(P.clone().multiplyScalar(f*w)).add(M.clone().multiplyScalar(d*x)),b=new y.Vector3().copy(a).add(P.clone().multiplyScalar((f+1)*w)).add(M.clone().multiplyScalar(d*x)),V=new y.Vector3().copy(a).add(P.clone().multiplyScalar((f+1)*w)).add(M.clone().multiplyScalar((d+1)*x)),v=new y.Vector3().copy(a).add(P.clone().multiplyScalar(f*w)).add(M.clone().multiplyScalar((d+1)*x)),S={points:[p,b,V,v],userData:{}};S.userData={type:"wallSegment",row:d,col:f,originalMaterial:i,width:w,height:x},s.push(S)}catch(p){console.error(`创建墙体小平面(${d}, ${f})时出错:`,p)}return s}calculateMinRequiredPoints(t){const i=Math.floor(Math.log1p(t)*.5);return Math.max(1,i)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,o,i){if(e===0)return!1;const r=t.area,s=t.minRequiredPoints,a=t.expectedDensity,l=e/Math.max(r,.001),u=e>=s,h=l>=a*.3;let g=!0;return r<.5&&e>0&&(g=this.checkSmallAreaDistribution(t,o,i)),u&&h&&g}checkSmallAreaDistribution(t,e,o){if(e.length<2)return!0;const i=e.map(l=>o[l]);t.bounds;const r=t.center;let s=0;const a=Math.sqrt(t.area)*.3;return i.forEach(l=>{l.distanceTo(r)<=a&&s++}),s/i.length>=.3}getFailureReason(t,e){const o=t.area,i=t.minRequiredPoints,r=t.expectedDensity,s=e/Math.max(o,.001),a=[];return e===0?a.push("无点"):(e<i&&a.push(`点数不足: ${e}/${i}`),s<r*.3&&a.push(`密度不足: ${s.toFixed(2)}/${r.toFixed(2)}`),o<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((i,r)=>i-r),o=Math.floor(e.length/2);return e.length%2!==0?e[o]:(e[o-1]+e[o])/2}isPointInBoundingBox(t,e,o=.1){return t.x>=e.min[0]-o&&t.x<=e.max[0]+o&&t.y>=e.min[1]-o&&t.y<=e.max[1]+o&&t.z>=e.min[2]-o&&t.z<=e.max[2]+o}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const o=e.attributes.position;if(o.count<3)return null;const i=new y.Vector3().fromBufferAttribute(o,0),r=new y.Vector3().fromBufferAttribute(o,1),s=new y.Vector3().fromBufferAttribute(o,2);i.applyMatrix4(t.matrixWorld),r.applyMatrix4(t.matrixWorld),s.applyMatrix4(t.matrixWorld);const a=new y.Plane;return a.setFromCoplanarPoints(i,r,s),a}analyzePointDistribution(t,e,o=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};const i=performance.now(),r=[];t.forEach(s=>{if(s.userData&&s.userData.type==="wallSegment"){const a=this.getWorldVerticesNew(s.points);if(a.length<4)return;const l=new y.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);s.userData.center=l,s.vertices=a,r.push(s)}}),this.results.totalSegments=r.length;for(const s of r){if(s.vertices.length<4)continue;const a=s.userData.center,l=`row${s.userData.row}_col${s.userData.col}`,[u,h,g,c]=s.vertices,m=new y.Vector3().subVectors(h,u).normalize(),w=new y.Vector3().subVectors(c,u).normalize(),x=u.distanceTo(h),P=u.distanceTo(c),M=new y.Plane;M.setFromCoplanarPoints(u,h,c);const d=x/2,f=P/2;for(let p=0;p<e.length;p++)this.isPointInWallSegmentOptimized(e[p],a,M,u,m,w,x,P,d,f,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(p))}return r.forEach(s=>{const a=`row${s.userData.row}_col${s.userData.col}`,l=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;l>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:s.userData.row,col:s.userData.col,width:s.userData.width,height:s.userData.height,segmentKey:a,vertices:s.vertices,center:s.userData.center,mesh:s,pointCount:l,hasPointsButNotEnough:l>0&&l<1}))}),this.results.analysisTime=performance.now()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,o,i,r,s,a,l,u,h,g){if(Math.abs(o.distanceToPoint(t))>g)return!1;const m=new y.Vector3().subVectors(t,e),w=Math.abs(m.dot(r)),x=Math.abs(m.dot(s));if(w>u&&x>h)return!1;const P=new y.Vector3().subVectors(t,i),M=P.dot(r),d=P.dot(s),f=M>=-g&&M<=a+g,p=d>=-g&&d<=l+g;return f&&p}isPointInWallSegment(t,e,o,i=.1){if(!t.geometry)return!1;try{const r=this.getWorldVertices(t);return r.length<4?!1:this.isPointInRotatedWall(r,e,o,i)}catch(r){return console.error("判断点是否在墙体平面内时出错:",r),!1}}isPointInRotatedWall(t,e,o,i=.1){const[r,s,a,l]=t,u=new y.Plane;if(u.setFromCoplanarPoints(r,s,l),Math.abs(u.distanceToPoint(e))>i)return!1;const g=new y.Vector3().subVectors(s,r).normalize(),c=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(g,c).normalize();const m=new y.Vector3().subVectors(e,r),w=m.dot(g),x=m.dot(c),P=r.distanceTo(s),M=r.distanceTo(l),d=w>=-i&&w<=P+i,f=x>=-i&&x<=M+i;return d&&f&&o.distanceTo(e)<P/2&&o.distanceTo(e)<M/2}getWorldVertices(t){if(t._cachedWorldVertices&&t.matrixWorld.equals(t._cachedMatrixWorld))return t._cachedWorldVertices;const e=t.geometry.getAttribute("position"),o=[];for(let i=0;i<Math.min(4,e.count);i++){const r=new y.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.push(r)}return t._cachedWorldVertices=o,t._cachedMatrixWorld=t.matrixWorld.clone(),o}getWorldVerticesNew(t){const e=[];for(let o=0;o<t.length;o++){const i=t[o].clone();e.push(i)}return e}getWallSegmentBounds(t){if(!t.geometry)return null;const e=t.geometry.getAttribute("position"),o=new y.Box3;for(let i=0;i<e.count;i++){const r=new y.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.expandByPoint(r)}return{min:o.min.toArray(),max:o.max.toArray(),center:o.getCenter(new y.Vector3).toArray(),size:o.getSize(new y.Vector3).toArray()}}highlightEmptySegments(t,e,o,i=1){var g;if(!this.results){console.warn("请先运行分析函数");return}const r=new Map,s=new Map;this.results.missingSegments.forEach(c=>{r.set(c.segmentKey,c),s.has(c.row)||s.set(c.row,new Map),s.get(c.row).set(c.col,{segmentKey:c.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(c=>{if(c.userData&&c.userData.type==="wallSegment"){const m=`row${c.userData.row}_col${c.userData.col}`,w=r.has(m);s.has(c.userData.row)||s.set(c.userData.row,new Map),s.get(c.userData.row).has(c.userData.col)||s.get(c.userData.row).set(c.userData.col,{segmentKey:m,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[c,m]of r){const w=(g=s.get(m.row))==null?void 0:g.get(m.col);if(w&&!w.visited){const x=[],P=[[m.row,m.col]];for(w.visited=!0;P.length>0;){const[M,d]=P.shift(),f=`row${M}_col${d}`;r.has(f)&&x.push(r.get(f));for(const[p,b]of l){const V=M+p,v=d+b;if(s.has(V)&&s.get(V).has(v)){const S=s.get(V).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,P.push([V,v]))}}}x.length>=i&&a.push(x)}}const u=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((c,m)=>m.length-c.length),highlightedMeshes:h,clusterMaterials:u,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,o,i,r){let s=0;const a=e;let l=!0;for(let x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const u=o;let h=!0;for(let x=i;x<=r;x++)t.has(u)&&t.get(u).has(x)||(h=!1);h&&s++;const g=i;let c=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(g)||(c=!1);c&&s++;const m=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(m)||(w=!1);return w&&s++,s/4}calculateClusterQualityScore(t){const r=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+r*.2}calculateStrictClusterBounds(t){var g,c;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(m=>{m.vertices&&m.vertices.length>0&&e.push(...m.vertices)}),e.length===0){const m=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((g=t[0].bounds)==null?void 0:g.width)||1),height:m.length*(((c=t[0].bounds)==null?void 0:c.height)||1)}}const o=Math.min(...e.map(m=>m.x)),i=Math.max(...e.map(m=>m.x)),r=Math.min(...e.map(m=>m.y)),s=Math.max(...e.map(m=>m.y)),a=Math.min(...e.map(m=>m.z)),l=Math.max(...e.map(m=>m.z)),u=Math.abs(i-o),h=Math.max(Math.abs(s-r),Math.abs(l-a));return{width:u,height:h}}createClusterMaterials(t){const e=[],o=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let i=0;i<t;i++){const r=o[i%o.length],s=new y.MeshBasicMaterial({color:r,transparent:!0,opacity:.6,side:y.DoubleSide});e.push(s)}return e}clearHighlights(t){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(e=>{t.remove(e),e.material&&e.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,o)=>{e.mesh&&e.mesh.userData.originalMaterial&&(e.mesh.material=e.mesh.userData.originalMaterial)}),this.clusterResults.highlightedMeshes=[])}getClusterInfo(){return this.clusterResults?{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((t,e)=>({clusterIndex:e,size:t.length,segments:t.map(o=>o.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(t=>t.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(t=>t.length))}:null}restoreOriginalMaterials(t){let e=0;t.traverse(o=>{o.userData&&o.userData.originalMaterial&&(o.material=o.userData.originalMaterial,delete o.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new y.Group;return t.traverse(o=>{if(o.userData&&o.userData.type==="wallSegment"){const i=this.getWorldVertices(o);if(i.length<4)return;const r=new y.Vector3().add(i[0]).add(i[1]).add(i[2]).add(i[3]).multiplyScalar(.25),s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=new y.Vector3().crossVectors(s,a).normalize(),u=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),g=new y.ArrowHelper(a,r,.2,255);e.add(u),e.add(h),e.add(g)}}),e}printAnalysisResults(){if(!this.results){console.warn("没有可用的分析结果");return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(t=>{}),this.results.pointsInSegments.forEach((t,e)=>{})}isValidVector3(t){return t&&!isNaN(t.x)&&!isNaN(t.y)&&!isNaN(t.z)&&isFinite(t.x)&&isFinite(t.y)&&isFinite(t.z)}mergeWallGroupMeshes(t){const e=[];if(t.traverse(o=>{o.isMesh&&o.geometry&&e.push(o)}),e.length===0)return null;try{const o=e.map(a=>a.geometry);o.forEach((a,l)=>{a.applyMatrix4(e[l].matrixWorld)});const i=Jn(o),r=e[0].material.clone(),s=new y.Mesh(i,r);return s.name="mergedWalls",s}catch(o){return console.error("合并网格时出错:",o),null}}}const ho=n=>{let t={};const e=[],o=[],i=[];return n[0].width,n[0].height,n.forEach(r=>{o.push(...r.vertices),i.push(r.center),e.push(r.vertices)}),t.originalVertices=e,t.allCenterPoints=i,t},fo=n=>{const t=new lt.Vector3().copy(n.start).add(n.end).multiplyScalar(.5),e=new lt.Vector3().subVectors(new lt.Vector3(t.x,t.y,t.z+1),t).normalize(),o=new lt.Vector3(n.direction.x,n.direction.y,0);o.applyAxisAngle(e,Math.PI/2);const i=new lt.Vector3().copy(t).add(o.clone().multiplyScalar(n.length)),r=new lt.Vector3().copy(t).sub(o.clone().multiplyScalar(n.length));return t.z=n.start.z,i.z=n.start.z,r.z=n.start.z,{start:i,end:r,center:t,direction:o}},mo=(n,t,e=!0)=>{let o=[];if(!n)return[];for(let i=0;i<n.length;i++){const r=n[i];if(!r)continue;let s=new y.Vector3(r.start.x,r.start.y,r.start.z);s.applyEuler(new y.Euler(-Math.PI/2,0,0));let a=new y.Vector3(r.end.x,r.end.y,r.end.z);if(a.applyEuler(new y.Euler(-Math.PI/2,0,0)),t.add(eo(String(i),new y.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(r.isBayWindow||r.isWindow)&&e)continue;const l=new lt.Plane().setFromCoplanarPoints(new lt.Vector3(r.start.x,r.start.y,r.start.z),new lt.Vector3(r.end.x,r.end.y,r.end.z),new lt.Vector3(r.start.x,r.start.y,r.rooftopPz)),u=[];r.originalPoints.forEach((v,S)=>{const z=new lt.Vector3;l.projectPoint(v,z),u.push(z)});const h=new lt.Vector3(r.start.x,r.start.y,r.start.z).distanceTo(new lt.Vector3(r.end.x,r.end.y,r.end.z)),g=Math.abs(r.rooftopPz-r.start.z),c=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),m=new y.Group,w=new uo,{horizontalSubdivisions:x,verticalSubdivisions:P}=w.initLimits4(h,g),M=w.createSubdividedWallPlane(r,P,x,c,m);w.analyzePointDistribution(M,u,.01);const d=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),f=w.highlightEmptySegments(M,d,m),p=[];for(const v of f.clusters){const S=ho(v);S&&p.push(S)}const V=fo(r).direction;r.checkResults=p,r.verticalDirection=V,r.originaIndex=i,o.push(r)}return o},go=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(f=>{let p=new y.Vector3(f.x,f.y,0),b=!1;for(let V=0;V<i.length;V++)if(kt(p,i[V],.01)){b=!0;break}b||i.push(p)});const r=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),s=1;let a=new y.Vector3(o.start.x,o.start.y,o.start.z),l=new y.Vector3(o.end.x,o.end.y,o.end.z),u=new y.Vector3().subVectors(l,a).normalize(),h=u.clone().cross(new y.Vector3(0,0,1)).normalize(),g=h.clone().negate(),c=[];const m=[];let w=o.length/r;console.log(w);for(let f=0;f<r;f++){const p=[];p.push(a.clone().addScaledVector(h,s)),p.push(p[0].clone().addScaledVector(u,w)),p.push(p[1].clone().addScaledVector(g,s*2)),p.push(a.clone().addScaledVector(g,w));let b=[];for(let V=0;V<i.length;V++)c.includes(V)||yo(i[V],p)&&(c.push(V),b.push(i[V]));b.length>0&&m.push(xo(b)),a=a.addScaledVector(u,w)}const x=new Float32Array(i.length*3);i.forEach((f,p)=>{x[p*3]=f.x,x[p*3+1]=f.y,x[p*3+2]=f.z});const P=new y.BufferGeometry;P.setAttribute("position",new y.BufferAttribute(x,3)),P.rotateX(-Math.PI/2),t.add(new y.Points(P,new y.PointsMaterial({color:lo(),size:.02})));const[M,d]=Mo(m,{plane:"xy",trimRatio:0});to(M,d,t)}};function on(n,t="xy"){if(t==="xy")return{x:n.x,y:n.y};if(t==="xz")return{x:n.x,y:n.z};if(t==="yz")return{x:n.y,y:n.z};throw new Error(`Unsupported plane: ${t}`)}function po(n,t,e){const o=t.x-n.x,i=t.y-n.y,r=e.x-n.x,s=e.y-n.y;return o*s-i*r}function yo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=on(n,e),i=t.map(a=>on(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],u=i[(a+1)%4],h=po(l,u,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function xo(n){if(!n||n.length===0)return null;const t=new y.Vector3(0,0,0);for(const e of n)Array.isArray(e)?(t.x+=e[0],t.y+=e[1],t.z+=e[2]):(t.x+=e.x,t.y+=e.y,t.z+=e.z);return t.divideScalar(n.length),t}function wo(n){return n instanceof y.Vector3?n.clone():Array.isArray(n)?new y.Vector3(n[0],n[1],n[2]):new y.Vector3(n.x,n.y,n.z)}function bo(n,t="xy"){const e=wo(n);if(t==="xy")return{x:e.x,y:e.y,up:e.z};if(t==="xz")return{x:e.x,y:e.z,up:e.y};if(t==="yz")return{x:e.y,y:e.z,up:e.x};throw new Error(`Unsupported plane: ${t}`)}function rn(n,t,e,o="xy"){if(o==="xy")return new y.Vector3(n,t,e);if(o==="xz")return new y.Vector3(n,e,t);if(o==="yz")return new y.Vector3(e,n,t);throw new Error(`Unsupported plane: ${o}`)}function Po(n,t,e){if(Math.abs(t)<1e-12)return n>=e?{x:1,y:0}:{x:0,y:1};const i=n+e,r=n*e-t*t,s=Math.sqrt(Math.max(0,i*i*.25-r)),a=i*.5+s;let l=t,u=a-n;const h=Math.hypot(l,u);return h<1e-12?{x:1,y:0}:{x:l/h,y:u/h}}function Mo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>bo(B,e));let r=0,s=0,a=0;for(const B of i)r+=B.x,s+=B.y,a+=B.up;r/=i.length,s/=i.length,a/=i.length;let l=0,u=0,h=0;for(const B of i){const L=B.x-r,W=B.y-s;l+=L*L,u+=L*W,h+=W*W}l/=i.length,u/=i.length,h/=i.length;const g=Po(l,u,h),c={x:-g.y,y:g.x},m=[];for(const B of i){const L=B.x-r,W=B.y-s,C=L*g.x+W*g.y,R=L*c.x+W*c.y;m.push({s:C,t:R,up:B.up})}m.sort((B,L)=>B.s-L.s);const w=m.length;let x=Math.floor(w*o),P=Math.ceil(w*(1-o))-1;x=Math.max(0,Math.min(w-1,x)),P=Math.max(0,Math.min(w-1,P));const M=m[x],d=m[P],f=(()=>{const B=m.map(W=>W.t).sort((W,C)=>W-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),p=(()=>{const B=m.map(W=>W.up).sort((W,C)=>W-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),b=M.s,V=d.s,v=f,S=f,z=p,D=p,_=r+g.x*b+c.x*v,T=s+g.y*b+c.y*v,E=r+g.x*V+c.x*S,A=s+g.y*V+c.y*S,F=rn(_,T,z,e),I=rn(E,A,D,e);return[F,I]}const Vo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let f=0;f<o.length;f++){const p=o[f];p.isLine2=!0,n.push(p)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const f of n){let p=[];if(!(!f.checkResults||f.checkResults.length<=0)){for(let b=0;b<f.checkResults.length;b++){let D=function(A){for(;z[A]!==A;)z[A]=z[z[A]],A=z[A];return A};const V=f.checkResults[b];if(V.isDoor=!1,!V.originalVertices||V.originalVertices.length==0)continue;const v=[];V.originalVertices.forEach(A=>{let F=[];A.forEach(I=>{F.push(new y.Vector3(I.x,I.y,I.z))}),v.push(F)});const S=v.length,z=Array.from({length:S},(A,F)=>F);for(let A=0;A<S;A++)for(let F=A+1;F<S;F++){const I=v[A],B=v[F];if(I.some(W=>B.some(C=>W.equals(C)))){const W=D(A),C=D(F);W!==C&&(z[W]=C)}}const _=new Map;let T=-1,E=-1;for(let A=0;A<S;A++){const F=D(A);_.has(F)||_.set(F,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const I=_.get(F);let[B,L,W,C]=v[A];const R=new y.Vector3().add(B).add(L).add(W).add(C).multiplyScalar(.25);if(I.points.push(...v[A]),I.area+=B.distanceTo(L)*B.distanceTo(C),I.originalVertices.push(v[A]),I.index=b,I.centerPts.push(R),T==-1||E==-1){let H=new y.Vector3().subVectors(B,L).normalize();E=B.distanceTo(C),T=B.distanceTo(L);let X=oe(H,new y.Vector3(0,0,1));X&&X.parallel&&([E,T]=[T,E])}I.gridWidth=T,I.gridHeight=E}p.push(..._.values())}f.mergeCheckRegion=p}}let r=new Map;for(const f of n){if(f.length<.3)continue;let p=f.rooftopPz-f.start.z,b=Math.floor(f.rooftopPz-f.start.z);r.has(b)?r.set(b,{num:r.get(b).num+1,totalHeight:r.get(b).totalHeight+p}):r.set(b,{num:1,totalHeight:p})}let s=[...r.entries()].reduce((f,p)=>p[1].num>f[1].num?p:f);s[0],s[1].totalHeight/s[1].num;const a=[];for(let f=0;f<e.length;f++){const p=e[f];if(p.isFindBeam=!1,p.category=="door"){let b=[];p.coordinatesByArea.coordinates.forEach(D=>{b.push(new y.Vector3(D.x,D.y,D.z))}),b[0].equals(b[b.length-1])&&b.pop();let V=b[0].distanceTo(b[1]),v=b[0].distanceTo(b[3]);v>V&&([V,v]=[v,V],b=[b[0],b[3],b[2],b[1]]);let S=ee(b[0],b[3],!0),z=ee(b[1],b[2],!0);a.push({doorStartPt:S,doorEndPt:z,boxPoints:b,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:f,isFind:!1,inWall:!1})}}for(let f=0;f<a.length;f++){const p=a[f];for(let b=0;b<n.length;b++){if(n[b].length<.5)continue;let V=[];const v=ee(n[b].start,n[b].end,!0);V.push(v),V.push(ee(v,n[b].start,!0)),V.push(ee(v,n[b].end,!0));let S=!1;const z=p.boxPoints.length;for(let D=0;D<V.length;D++){const _=V[D].x,T=V[D].y;for(let E=0,A=z-1;E<z;A=E++){const F=p.boxPoints[E].x,I=p.boxPoints[E].y,B=p.boxPoints[A].x,L=p.boxPoints[A].y;I>T!=L>T&&_<(B-F)*(T-I)/(L-I)+F&&(S=!S)}if(S)break}if(S){let D=new y.Vector3(n[b].start.x,n[b].start.y,0),_=new y.Vector3(n[b].end.x,n[b].end.y,0),T=p.doorStartPt.distanceTo(p.doorEndPt),E=D.distanceTo(_),A=Jt(p.doorStartPt,p.doorEndPt,D,_);if(Math.abs(E-T)<.5&&A&&A.angleDeg<15){p.doorStartPt=new y.Vector3(n[b].start.x,n[b].start.y,0),p.doorEndPt=new y.Vector3(n[b].end.x,n[b].end.y,0);break}else if(Math.abs(E-T)>1.3&&A&&A.angleDeg<15){let F=ne(p.doorStartPt,p.doorEndPt,D,_,{parallelAngleMax:y.MathUtils.degToRad(15)}),I=p.doorStartPt.distanceTo(D),B=p.doorStartPt.distanceTo(_),L=p.doorEndPt.distanceTo(D),W=p.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||W<.2;if(F&&F.type=="collinear_overlap"&&F.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let R=new y.Line3(D,_),H=R.closestPointToPoint(p.doorStartPt,!0,new y.Vector3),X=R.closestPointToPoint(p.doorEndPt,!0,new y.Vector3),ot=H.distanceTo(p.doorStartPt),K=X.distanceTo(p.doorEndPt);if(ot<.1||K<.1){p.inWall=!0;break}}}}else continue}}let l=0,u=[],h=[],g=[];const c=[];let m=.15;for(let f=0;f<n.length;f++){const p=n[f];if(p.noDetection||(p.doorAndBeamData=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0))continue;p.completePointAreaPercentage=-1;let b=new y.Box3;b.setFromPoints(p.originalPoints);let V=b.max.z;b.min.z;const v=new y.Vector3(p.start.x,p.start.y,p.start.z),S=new y.Vector3(p.end.x,p.end.y,p.end.z);let z=p.rooftopPz-p.start.z,D=0;for(const T of p.mergeCheckRegion){const{facePoints:E,boxArea:A,totalInPlaneNum:F}=oo(T.points,T.gridWidth,T.gridHeight,T.centerPts);if(!E||E.length<=0)continue;E[0].distanceTo(E[1]);let I=E[0].distanceTo(E[3]);const B=T.gridHeight*(I/T.gridHeight/3*2)+T.gridHeight/2;let L=new y.Vector3(E[0].x,E[0].y,E[0].z+B),W=new y.Vector3(E[1].x,E[1].y,E[1].z+B);const C=new y.Line3(L,W),R=[];let H=new y.Vector3;T.points.forEach(rt=>{C.closestPointToPoint(rt,!0,H).distanceTo(rt)<T.gridHeight+.01&&R.push(rt)});let X=[],ot=[];for(;;){let rt=[];for(let O=0;O<R.length;O++)ot.includes(O)||rt.length==0&&(rt.push(R[O]),ot.push(O));for(let O=0;O<R.length;O++)if(!ot.includes(O)){for(let Y=0;Y<rt.length;Y++)if(R[O].distanceTo(rt[Y])<T.gridWidth+.01){rt.push(R[O]),ot.push(O),O=-1;break}}if(rt.length==0)break;X.push(rt)}const K=[];for(let rt=0;rt<X.length;rt++){const O={lineSt:new y.Vector3,lineEd:new y.Vector3,facePoints:[]};let Y=Se(X[rt]);Array.isArray(Y)&&Y.length==2&&(O.lineSt=Y[0],O.lineEd=Y[1],O.facePoints.push(new y.Vector3(Y[0].x,Y[0].y,E[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,E[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,E[2].z)),O.facePoints.push(new y.Vector3(Y[0].x,Y[0].y,E[2].z)),K.push(O))}D+=T.area;let G=0;if(F!=0&&(G=T.gridHeight*T.gridWidth*F),(T.area-G)/A*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const O=K[rt];let Y=O.facePoints[0].distanceTo(O.facePoints[1]),Vt=O.facePoints[0].distanceTo(O.facePoints[3]),Zt=Y/p.length*100,Nt=p.rooftopPz-O.facePoints[2].z;if(Vt<1.5||V<O.facePoints[2].z||Nt>z/3*2)continue;let Rt=!1,_t=!1,Tt=!1,Ot=[],tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone(),q=O.facePoints[0].clone(),j=O.facePoints[1].clone(),Wt=!1,Et=-1;if(Math.abs(O.facePoints[0].z-p.start.z)<.25){if(Y>.17&&p.length>.5){let qt=Lt(v,q),J=Lt(v,j),ut=Lt(S,q),N=Lt(S,j);const Pt=.1,zt=10;if(qt<Pt||J<Pt){const{newOriginalPoints:Ut}=Ve(q,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=q.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(Q,pt).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==f)continue;const it=new y.Vector3(n[U].start.x,n[U].start.y,0),mt=new y.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85){let At=Ct.point.distanceTo(Q);if(Ct.point.distanceTo(pt),At<.3){dt=!0,ft=1/0,Z=-1;break}}continue}if(St&&St.angle>85){const $=new y.Line3(it,mt).closestPointToPoint(Q,!0,Gt);let yt=Jt(Q,pt,$,Q);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt,zt),st=pt.clone().addScaledVector(Mt.clone().negate(),zt);let wt=new y.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=Q.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new y.Vector3(q.x,q.y,0),$=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt($,it),wt=Lt($,mt),vt=Jt(Q,pt,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let Ht=Se(Xt);if(Ht.length==2){let Kt=Lt(At,Ht[0]),Ce=Lt(At,Ht[1]),Le=Lt($,Ht[0]),Re=Lt($,Ht[1]);if(Kt<.2||Ce<.2||Le<.2||Re<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-Y>.2||p.length-Y<.02)&&ft<Y*3)n[Z].length>.25&&Y+ft>.5&&(Wt=!0,qt<Pt?(ct=ct.addScaledVector(Mt,ft),q=q.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-Y>.1)continue;if(!k&&!dt&&p.length-Y<.1&&p.length<1.8)continue}}else continue}if(ut<Pt||N<Pt){const{newOriginalPoints:Ut}=Ve(q,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=q.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(pt,Q).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==f)continue;const it=new y.Vector3(n[U].start.x,n[U].start.y,0),mt=new y.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85&&(Ct.point.distanceTo(Q),Ct.point.distanceTo(pt)<.3)){dt=!0,ft=1/0,Z=-1;break}continue}if(St&&St.angle>85){const $=new y.Line3(it,mt).closestPointToPoint(pt,!0,Gt);let yt=Jt(pt,Q,$,pt);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt.clone().negate(),zt),st=pt.clone().addScaledVector(Mt,zt);let wt=new y.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=pt.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new y.Vector3(q.x,q.y,0),$=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt($,it),wt=Lt($,mt),vt=Jt(pt,Q,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let Ht=Se(Xt);if(Ht.length==2){let Kt=Lt(At,Ht[0]),Ce=Lt(At,Ht[1]),Le=Lt($,Ht[0]),Re=Lt($,Ht[1]);if(Kt<.2||Ce<.2||Le<.2||Re<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-Y>.2||p.length-Y<.02)&&ft<Y*3)n[Z].length>.25&&Y+ft>.5&&(Wt=!0,ut<Pt?(ct=ct.addScaledVector(Mt,ft),q=q.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-Y>.1)continue;if(!k&&!dt&&p.length-Y<.1&&p.length<1.8)continue}}else continue}Y=ct.distanceTo(tt)}if(Zt<85&&Y>.3||Y>.7&&Vt>z-z/3){let qt=!1;for(let J=0;J<t.length;J++){let ut=J+1;if(ut>=t.length)continue;let N=new y.Vector3(t[J].x,t[J].y,t[J].z),Pt=new y.Vector3(t[ut].x,t[ut].y,t[ut].z);if(te(new y.Vector3(N.x,N.y,0),new y.Vector3(Pt.x,Pt.y,0),new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),.1)!=null){qt=!0;break}}for(let J=0;J<a.length;J++){let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),N=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),zt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Ut=O.facePoints[2].z<a[J].maxZ||Math.abs(O.facePoints[2].z-a[J].maxZ)<.3;if(Math.abs(O.facePoints[2].z-a[J].maxZ)>.2,Ut){let at=ne(ut.clone(),N.clone(),Pt.clone(),zt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let Q=ee(ut,N),pt=new y.Line3(new y.Vector3(p.start.x,p.start.y,0),new y.Vector3(p.end.x,p.end.y,0)),Mt=new y.Vector3,Gt=pt.closestPointToPoint(Q,!0,Mt);if(Q.distanceTo(Gt)<.15){let Z=Pt.distanceTo(ut),k=zt.distanceTo(ut);if(Z>.25&&k>.25){let it=Pt.distanceTo(N),mt=zt.distanceTo(N);if(it>.2&&mt>.2)continue}_t=!0,Tt=!0,Ot.push(a[J].index),a[J].isFind=!0,Et=J,e[a[J].index].isFindBeam=!0;let dt=new y.Vector3().subVectors(Pt,zt).normalize(),U=ut.distanceTo(N)-at.overlap;k<Z&&dt.negate(),Z>k?(tt=O.facePoints[2].clone().addScaledVector(dt,U),ct=O.facePoints[3].clone(),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z):(tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(dt,U),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let Q=Pt.distanceTo(zt),pt=N.distanceTo(ut);if(Math.abs(Q-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>Q&&Math.abs(pt-at.overlap)>1){let Mt=Pt.distanceTo(ut),Gt=Pt.distanceTo(N),ft=zt.distanceTo(ut),Z=zt.distanceTo(N),k=Mt<Gt?Mt:Gt,dt=ft<Z?ft:Z,U=new y.Vector3().subVectors(Pt,zt).normalize(),it=pt-at.overlap;k<dt?(U.negate(),tt=O.facePoints[2].clone().addScaledVector(U,it),ct=O.facePoints[3].clone(),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z):(tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(U,it),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z)}_t=!0,Tt=!0,Ot.push(a[J].index),a[J].isFind=!0,e[a[J].index].isFindBeam=!0,Et=J}}}}if(!Tt&&Y<1.5)for(let J=0;J<a.length;J++){if(a[J].inWall)continue;let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),N=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),zt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Ut=new y.Vector3().subVectors(ut,N).normalize(),at=new y.Vector3().subVectors(Pt,zt).normalize(),Q=.25,pt=ut.clone().addScaledVector(Ut,Q),Mt=N.clone().addScaledVector(Ut.clone().negate(),Q),Gt=Pt.clone().addScaledVector(at,Q),ft=zt.clone().addScaledVector(at.clone().negate(),Q),Z=te(pt,Mt,Gt,ft),k=!0,dt=ut.distanceTo(Pt),U=ut.distanceTo(zt),it=N.distanceTo(Pt),mt=N.distanceTo(zt);(dt<m||U<m||it<m||mt<m||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Et=J)}(_t||qt||Math.abs(Vt-z)>.1&&Vt>z/2&&Y>.3)&&(Rt=!0)}}if(Rt){let qt=!1;for(let Z=0;Z<g.length;Z++){let k=ne(g[Z].start,g[Z].end,q,j);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){qt=!0;break}}if(qt){Et!=-1&&(e[a[Et].index].isFindBeam=!1,a[Et].isFind=!1);continue}g.push({start:q,end:j});{new y.PointsMaterial({color:65535,size:.01});let Z=new y.Vector3().subVectors(q,j),k=new y.Vector3().subVectors(j,q),dt=1/0,U=1/0,it=q.clone(),mt=j.clone();const Ct=[],St=[];let At=new y.Line3(tt,ct),$=new y.Vector3,yt=999999;if(p.originalPoints.forEach(et=>{if(et.z-q.z<Vt/2+.1&&et.z-q.z>Vt/2-.1&&Ct.push(et),et.z>tt.z){let st=At.closestPointToPoint(et,!0,$),wt=new y.Vector3().subVectors(st,tt),vt=new y.Vector3().subVectors(st,ct),Bt=oe(Z,vt),bt=oe(k,wt);Bt&&Bt.parallel&&!Bt.sameDirection&&bt&&bt.parallel&&!bt.sameDirection&&St.push(et)}}),Ct.length>0){const{newProjectPoints:et}=Ve(q,j,Ct);for(const st of et)st.z=q.z;et.forEach(st=>{let wt=new y.Vector3(st.x,st.y,q.z),vt=new y.Vector3().subVectors(wt,j),Bt=new y.Vector3().subVectors(wt,q),bt=oe(Z,Bt),Xt=oe(k,vt);if(bt&&bt.parallel&&bt.sameDirection){let Ht=wt.distanceTo(q);Ht<dt&&(dt=Ht,it=wt)}else if(Xt&&Xt.parallel&&Xt.sameDirection){let Ht=wt.distanceTo(j);Ht<U&&(U=Ht,mt=wt)}})}if(it.equals(q)||(q=it,ct=new y.Vector3(q.x,q.y,ct.z)),mt.equals(j)||(j=mt,tt=new y.Vector3(j.x,j.y,tt.z)),St.length>10){const{newOnLinePoints:et}=Ve(ct,tt,St);for(let st=0;st<et.length;st++){let vt=At.closestPointToPoint(et[st],!0,$).distanceTo(et[st]);vt>.02&&yt>vt&&(yt=vt)}tt.z+=yt,ct.z+=yt,Vt+=yt}}let J=j.distanceTo(q);if(J<.4&&!_t||J<.3&&_t)continue;h.includes(f)||h.push(f),p.checkResults[T.index].isDoor=!0;let ut="",N={id:l,beamStart:tt,beamEnd:ct,beamHeight:p.rooftopPz-tt.z,doorStart:q,doorEnd:j,doorHeight:Vt,nearId:-1,type:ut,isExtend:Wt,isDoor:_t,isPullOutDoor:Tt,pcbDoorIndexs:Ot,beamNearWallVec:new y.Vector3(0,0,0)},Pt=!1,zt=new y.Vector3,Ut=new y.Vector3,at=-1,Q=-1,pt=-1;for(let Z=0;Z<u.length;Z++){const k=n[u[Z].linesIndex].doorAndBeamData[u[Z].doorIndex];if(k.nearId!=-1)continue;let dt=Jt(tt.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let U=tt.distanceTo(ct),it=k.beamStart.distanceTo(k.beamEnd),mt=new y.Line3(tt.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let Ct=ee(k.beamStart,k.beamEnd,!0);it>U&&(mt.start=new y.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new y.Vector3(k.beamEnd.x,k.beamEnd.y,0),Ct=ee(tt,ct,!0));let St=new y.Vector3,At=mt.closestPointToPoint(Ct,!0,St),$=At.distanceTo(Ct),yt=new y.Vector3().subVectors(Ct,At).normalize(),et=yt.clone().negate(),st=Ct.clone().addScaledVector(et,$+.1),wt=te(mt.start,mt.end,Ct,st),vt=!_t&&!k.isDoor&&(U>it*2||it>U*2);if($<.4&&wt!=null&&!vt){k.nearId=l,N.nearId=k.id;let Bt=.8;(k.isDoor||N.isDoor)&&(k.isDoor=!0,N.isDoor=!0);const bt=Ot.some(Xt=>k.pcbDoorIndexs.includes(Xt));U<it?U>Bt&&!k.isPullOutDoor?(k.beamStart=tt.clone().addScaledVector(et,$),k.beamEnd=ct.clone().addScaledVector(et,$),k.doorStart=q.clone().addScaledVector(et,$),k.doorEnd=j.clone().addScaledVector(et,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Tt||Tt&&k.isPullOutDoor&&bt?(N.beamStart=k.beamStart.clone().addScaledVector(yt,$),N.beamEnd=k.beamEnd.clone().addScaledVector(yt,$),N.doorStart=k.doorStart.clone().addScaledVector(yt,$),N.doorEnd=k.doorEnd.clone().addScaledVector(yt,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):(k.beamStart=tt.clone().addScaledVector(et,$),k.beamEnd=ct.clone().addScaledVector(et,$),k.doorStart=q.clone().addScaledVector(et,$),k.doorEnd=j.clone().addScaledVector(et,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):U>it&&(it>Bt&&!Tt?(N.beamStart=k.beamStart.clone().addScaledVector(et,$),N.beamEnd=k.beamEnd.clone().addScaledVector(et,$),N.doorStart=k.doorStart.clone().addScaledVector(et,$),N.doorEnd=k.doorEnd.clone().addScaledVector(et,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):!k.isPullOutDoor||Tt&&k.isPullOutDoor&&bt?(k.beamStart=tt.clone().addScaledVector(yt,$),k.beamEnd=ct.clone().addScaledVector(yt,$),k.doorStart=q.clone().addScaledVector(yt,$),k.doorEnd=j.clone().addScaledVector(yt,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(N.beamStart=k.beamStart.clone().addScaledVector(et,$),N.beamEnd=k.beamEnd.clone().addScaledVector(et,$),N.doorStart=k.doorStart.clone().addScaledVector(et,$),N.doorEnd=k.doorEnd.clone().addScaledVector(et,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight)),at=N.nearId,zt=k.beamStart.clone(),Ut=k.beamEnd.clone(),Pt=!0,Q=u[Z].linesIndex,pt=u[Z].doorIndex;break}}}let Mt=!1;if(!Pt){let Z=new y.Line3(q.clone(),j.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==f)continue;let dt=new y.Vector3(n[k].start.x,n[k].start.y,n[k].start.z),U=new y.Vector3(n[k].end.x,n[k].end.y,n[k].end.z),it=ne(dt,U,q,j),mt=Jt(dt,U,q,j);const Ct=io(n[k]);if(it&&it.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let st=new y.Line3(dt,U),wt=new y.Vector3(q.x,q.y,dt.z),vt=st.closestPointToPoint(wt,!0,new y.Vector3),Bt=re(vt,wt,q,j);Bt&&Bt.angle>85&&(N.beamNearWallVec=new y.Vector3().subVectors(vt,wt).normalize())}const St=[];n[k].originalPoints.forEach(st=>{st.z>q.z+.2&&st.z<q.z+Vt/2&&St.push(new y.Vector3(st.x,st.y,q.z))});const At=new y.Vector3;let $=[],yt=[];for(let st=0;st<St.length;st++){let wt=Z.closestPointToPoint(St[st],!0,At);wt.distanceTo(St[st])<.15&&($.push(St[st]),yt.push(wt.clone()))}for(let st=0;st<yt.length;st++)ao(Z,yt[st])&&$.push(yt[st]);if($=yt,$=co($),$.length<150)continue;let et=Se($);if(et.length==2){let st=et[0].distanceTo(et[1]);if(Math.abs(st-Z.distance())<.3){let wt=new y.Line3(dt,U),vt=new y.Vector3(q.x,q.y,dt.z),Bt=wt.closestPointToPoint(vt,!0,new y.Vector3);if(N.beamNearWallVec=new y.Vector3().subVectors(Bt,vt).normalize(),N.beamStart.z>Ct.maxZ-.03&&Y>1)Mt=!0;else if(qt=!0,Et!=-1&&(e[a[Et].index].isFindBeam=!1,a[Et].isFind=!1),Q!=-1&&pt!=-1){const bt=n[Q].doorAndBeamData[pt];bt.nearId=-1}break}}if(qt)break}else it&&it.type=="collinear_overlap"&&it.maxPerpendicularDistance>.3&&it.maxPerpendicularDistance<.7&&(Mt=!0)}if(qt){if(Y<1.8)continue;Mt=!0}}let Gt=!1;if(at!=-1)for(let Z=0;Z<c.length&&!(c[Z].length==1&&(c[Z][0].id==l?(c[Z].push({id:at,beamStart:zt,beamEnd:Ut}),Gt=!0):c[Z][0].id==at&&(c[Z].push({id:l,beamStart:tt,beamEnd:ct}),Gt=!0),Gt));Z++);Gt||c.push([{id:l,beamStart:tt,beamEnd:ct}]);const ft=N.doorStart.distanceTo(N.doorEnd);if(_t?ut="door":ft>1.8?ut="beam":ut=Mt&&ft>1?"beam":"hole",N.type=ut,N.nearId!=-1&&ut=="hole"){let Z=!1;for(let k=0;k<n.length;k++)if(n[k].doorAndBeamData){for(let dt=0;dt<n[k].doorAndBeamData.length;dt++)if(n[k].doorAndBeamData[dt].nearId==l&&n[k].doorAndBeamData[dt].type=="beam"){n[k].doorAndBeamData[dt].type=ut,Z=!0;break}if(Z)break}}if(p.doorAndBeamData.push(N),u.push({linesIndex:f,doorIndex:p.doorAndBeamData.length-1}),l++,Tt&&Y<2)break}}}let _=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=D/_*100}if(h.length>1)for(let f=0;f<h.length;f++){let p=[];for(let b=0;b<n[h[f]].doorAndBeamData.length;b++){let V=!1;if(n[h[f]].doorAndBeamData[b].type==="beam"&&n[h[f]].doorAndBeamData[b].beamNearWallVec.x==0&&n[h[f]].doorAndBeamData[b].beamNearWallVec.y==0&&n[h[f]].doorAndBeamData[b].beamNearWallVec.z==0&&n[h[f]].doorAndBeamData[b].nearId==-1&&(V=!0),!V){let v=n[h[f]].doorAndBeamData[b].doorStart.clone(),S=n[h[f]].doorAndBeamData[b].doorEnd.clone();v.z=S.z=0;let z=v.distanceTo(S);for(let D=0;D<h.length;D++)if(f!=D)for(let _=0;_<n[h[D]].doorAndBeamData.length;_++){let T=n[h[D]].doorAndBeamData[_].doorStart.clone(),E=n[h[D]].doorAndBeamData[_].doorEnd.clone();T.z=E.z=0,T.distanceTo(E);let A=ne(v,S,T,E);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let F=new y.Line3(T,E),I=ee(v,S),B=F.closestPointToPoint(I,!0,new y.Vector3),L=I.distanceTo(B);if(Math.abs(z-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[f]].doorAndBeamData[b].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),V=!0;break}}}}V||p.push(n[h[f]].doorAndBeamData[b])}p.length!=n[h[f]].doorAndBeamData.length&&(n[h[f]].doorAndBeamData=p)}let w=.65,x=2,P=[],M=[];for(let f=0;f<a.length;f++){if(a[f].isFind||a[f].inWall)continue;let p=new y.Vector3(a[f].doorStartPt.x,a[f].doorStartPt.y,0),b=new y.Vector3(a[f].doorEndPt.x,a[f].doorEndPt.y,0),V=new y.Vector3().subVectors(p,b).normalize();for(let v=0;v<n.length;v++){if(n[v].length<.7||n[v].completePointAreaPercentage>60)continue;let S=new y.Vector3(n[v].start.x,n[v].start.y,0),z=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,z).normalize(),_=.3,T=p.clone().addScaledVector(V,_),E=b.clone().addScaledVector(V.clone().negate(),_),A=S.clone().addScaledVector(D,_),F=z.clone().addScaledVector(D.clone().negate(),_);te(T,E,A,F);let I=Jt(T,E,A,F),B=p.distanceTo(S)>b.distanceTo(S)?b:p,L=B.distanceTo(S),W=B.distanceTo(z);if((L<m||W<m)&&I&&!I.isParallel){let R=p.distanceTo(S),H=p.distanceTo(z),X=R<H?S:z,ot=!1;for(let K=0;K<n.length;K++){if(K==v||P.includes(K)||n[K].length<.7)continue;let G=new y.Vector3(n[K].start.x,n[K].start.y,0),ht=new y.Vector3(n[K].end.x,n[K].end.y,0),rt=new y.Vector3().subVectors(G,ht).normalize(),O=rt.clone().negate(),Y=G.clone().addScaledVector(rt,5),Vt=ht.clone().addScaledVector(O,5),Zt=re(S,z,G,ht),Nt=ne(S,z,G,ht),Rt=te(S,z,Y,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<m||Rt.point.distanceTo(z)<m),(Zt&&Zt.angle>85||Nt&&Nt.type=="collinear_gap")&&_t){let Tt=new y.Line3(S,z),Ot=new y.Vector3,tt=Tt.closestPointToPoint(G,!0,Ot),ct=Tt.closestPointToPoint(ht,!0,Ot),q=tt.distanceTo(G),j=ct.distanceTo(ht),Wt,Et;if(q>j&&j>w)Wt=ht,Et=ct;else if(q<j&&q>w)Wt=G,Et=tt;else continue;if(q=X.distanceTo(G),j=X.distanceTo(ht),q>x&&j>x)continue;let qt=Jt(Wt,Et,G,ht),J=Jt(Wt,Et,T,E);if(J&&J.isParallel||!qt||!qt.isParallel)continue;let ut=ne(p,b,Wt,Et);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Wt.z=Et.z=n[K].start.z;let N=!1;for(let at=0;at<M.length;at++){let Q=ne(M[at].start,M[at].end,Wt,Et);if(Q&&Q.type=="collinear_overlap"&&Q.maxPerpendicularDistance<.2){N=!0;break}}if(N)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let Q=new y.Vector3(n[at].start.x,n[at].start.y,n[at].start.z),pt=new y.Vector3(n[at].end.x,n[at].end.y,n[at].end.z),Mt=ne(Q,pt,Wt,Et);if(Mt&&Mt.type=="collinear_overlap"&&Mt.maxPerpendicularDistance<.1){N=!0;break}}if(N)continue;M.push({start:Wt,end:Et}),P.push(K);let Pt=n[K].rooftopPz-n[K].start.z,zt=n[v].rooftopPz-n[v].start.z,Ut=Pt<zt?Pt:zt;n[K].doorAndBeamData||(n[K].doorAndBeamData=[]),n[K].doorAndBeamData.push({id:l,beamStart:Wt,beamEnd:Et,beamHeight:Ut,doorStart:Wt,doorEnd:Et,doorHeight:Ut,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new y.Vector3(0,0,0)}),e[a[f].index].isFindBeam=!0,e[a[f].index].isFindOnlyDoor=!0,c.push([{id:l,beamStart:Wt,beamEnd:Et}]),l++,ot=!0;break}}if(ot)break}}}let d=[];for(let f=0;f<n.length;f++)n[f].isLine2||d.push(n[f]),n[f].isLine2&&n[f].doorAndBeamData.length!=0&&d.push(n[f]);return n.length=0,n.push(...d),{lines:n,beamGroup:c}},zo=(n,t)=>{if(!n||n.length<=0)return;let e={rectangles:[],threeEdgeRect:[]},o=new Set,i=.2,r=1.5,s=.15,a=2;if(!n[0].uuid){let l=1e4;for(let u=0;u<n.length;u++)n[u].uuid=l++}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h=[],g=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(c,g).normalize().clone().negate(),x=new y.Vector3,P=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let d=0;d<n.length;d++){let f=n[d].length;if(d==l||f<i||f>r)continue;let p=new y.Vector3(n[d].start.x,n[d].start.y,n[d].start.z),b=new y.Vector3(n[d].end.x,n[d].end.y,n[d].end.z),V=re(g,c,p,b);if(!V||V.angle<85)continue;let v=kt(p,g),S=kt(p,c),z=kt(b,g),D=kt(b,c);if(!(!v&&!S&&!z&&!D)){v||S?(x=p.clone(),P=b.clone()):(x=b.clone(),P=p.clone()),M=new y.Vector3().subVectors(P,x).normalize(),M.clone().negate();for(let _=0;_<n.length;_++){let T=n[_].length;if(_==l||_==d||T<i||T>r)continue;let E=new y.Vector3(n[_].start.x,n[_].start.y,n[_].start.z),A=new y.Vector3(n[_].end.x,n[_].end.y,n[_].end.z),F=re(p,b,E,A);if(!F||F.angle<85)continue;let I=kt(E,P),B=kt(A,P);if(!I&&!B)continue;new y.Vector3;let L=new y.Vector3,W=new y.Vector3;I?(W=new y.Vector3().subVectors(A,E).normalize(),E.clone(),L=A.clone()):(W=new y.Vector3().subVectors(E,A).normalize(),A.clone(),L=E.clone());let C=oe(w,W,.1);if(!(!C||!C.parallel||!C.sameDirection)){for(let R=0;R<n.length;R++){let H=n[R].length;if(R==l||R==d||R==_||H<i||H>r)continue;let X=new y.Vector3(n[R].start.x,n[R].start.y,n[R].start.z),ot=new y.Vector3(n[R].end.x,n[R].end.y,n[R].end.z),K=re(X,ot,E,A);if(!K||K.angle<85)continue;let G=kt(X,L),ht=kt(ot,L);if(!G&&!ht)continue;new y.Vector3;let rt=new y.Vector3;G?(X.clone(),rt=ot.clone()):(ot.clone(),rt=X.clone());let O=kt(rt,g),Y=kt(rt,c);if(!O&&!Y)continue;let Vt=u*f;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[d].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(d=>o.add(d)),e.rectangles.push(h))}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h={indexs:[],missingEdge:{start:new y.Vector3,end:new y.Vector3}},g=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),m=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let d=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),f=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),p=kt(d,g),b=kt(f,g),V=kt(d,c),v=kt(f,c);if(p||b?m=!1:(V||v)&&(w=!1),!m&&!w)break}if(!m&&!w)continue;let x=new y.Vector3;m||([g,c]=[c,g]),x=new y.Vector3().subVectors(c,g).normalize();let P=x.clone().negate();for(let M=0;M<n.length;M++){let d=n[M].length;if(M==l||o.has(M)||d<i||d>r)continue;let f=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),p=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),b=re(g,c,f,p);if(!b||b.angle<85)continue;let V=kt(f,c),v=kt(p,c);if(!V&&!v)continue;new y.Vector3;let S=new y.Vector3;V?(f.clone(),S=p.clone()):(p.clone(),S=f.clone());for(let z=0;z<n.length;z++){let D=n[z].length;if(z==l||z==M||o.has(z)||D<i||D>r)continue;let _=new y.Vector3(n[z].start.x,n[z].start.y,n[z].start.z),T=new y.Vector3(n[z].end.x,n[z].end.y,n[z].end.z),E=re(f,p,_,T);if(!E||E.angle<85)continue;let A=kt(_,S),F=kt(T,S);if(!A&&!F)continue;let I=new y.Vector3,B=new y.Vector3;A?(I=_.clone(),B=T.clone()):(I=T.clone(),B=_.clone());let L=new y.Vector3().subVectors(B,I).normalize(),W=oe(P,L,.1);if(!W||!W.parallel||!W.sameDirection)continue;let C=!0,R=!0;for(let X=0;X<n.length;X++){if(X==z||n[X].length<i)continue;let ot=new y.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),K=new y.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),G=kt(ot,_),ht=kt(K,_),rt=kt(ot,T),O=kt(K,T);if(G||ht?C=!1:(rt||O)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let H=u*d;if(!(H<s||H>a)){h.indexs=[n[l].uuid,n[M].uuid,n[z].uuid],h.missingEdge.start=B,h.missingEdge.end=g;break}}if(h.indexs.length==3)break}h.indexs.length==3&&(h.indexs.forEach(M=>o.add(M)),e.threeEdgeRect.push(h))}return e},ae=11102230246251565e-32,$t=134217729,So=(3+8*ae)*ae;function Fe(n,t,e,o,i){let r,s,a,l,u=t[0],h=o[0],g=0,c=0;h>u==h>-u?(r=u,u=t[++g]):(r=h,h=o[++c]);let m=0;if(g<n&&c<e)for(h>u==h>-u?(s=u+r,a=r-(s-u),u=t[++g]):(s=h+r,a=r-(s-h),h=o[++c]),r=s,a!==0&&(i[m++]=a);g<n&&c<e;)h>u==h>-u?(s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++g]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c]),r=s,a!==0&&(i[m++]=a);for(;g<n;)s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++g],r=s,a!==0&&(i[m++]=a);for(;c<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c],r=s,a!==0&&(i[m++]=a);return(r!==0||m===0)&&(i[m++]=r),m}function vo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function ze(n){return new Float64Array(n)}const Do=(3+16*ae)*ae,_o=(2+12*ae)*ae,To=(9+64*ae)*ae*ae,me=ze(4),sn=ze(8),an=ze(12),ln=ze(16),jt=ze(4);function Eo(n,t,e,o,i,r,s){let a,l,u,h,g,c,m,w,x,P,M,d,f,p,b,V,v,S;const z=n-i,D=e-i,_=t-r,T=o-r;p=z*T,c=$t*z,m=c-(c-z),w=z-m,c=$t*T,x=c-(c-T),P=T-x,b=w*P-(p-m*x-w*x-m*P),V=_*D,c=$t*_,m=c-(c-_),w=_-m,c=$t*D,x=c-(c-D),P=D-x,v=w*P-(V-m*x-w*x-m*P),M=b-v,g=b-M,me[0]=b-(M+g)+(g-v),d=p+M,g=d-p,f=p-(d-g)+(M-g),M=f-V,g=f-M,me[1]=f-(M+g)+(g-V),S=d+M,g=S-d,me[2]=d-(S-g)+(M-g),me[3]=S;let E=vo(4,me),A=_o*s;if(E>=A||-E>=A||(g=n-z,a=n-(z+g)+(g-i),g=e-D,u=e-(D+g)+(g-i),g=t-_,l=t-(_+g)+(g-r),g=o-T,h=o-(T+g)+(g-r),a===0&&l===0&&u===0&&h===0)||(A=To*s+So*Math.abs(E),E+=z*h+T*a-(_*u+D*l),E>=A||-E>=A))return E;p=a*T,c=$t*a,m=c-(c-a),w=a-m,c=$t*T,x=c-(c-T),P=T-x,b=w*P-(p-m*x-w*x-m*P),V=l*D,c=$t*l,m=c-(c-l),w=l-m,c=$t*D,x=c-(c-D),P=D-x,v=w*P-(V-m*x-w*x-m*P),M=b-v,g=b-M,jt[0]=b-(M+g)+(g-v),d=p+M,g=d-p,f=p-(d-g)+(M-g),M=f-V,g=f-M,jt[1]=f-(M+g)+(g-V),S=d+M,g=S-d,jt[2]=d-(S-g)+(M-g),jt[3]=S;const F=Fe(4,me,4,jt,sn);p=z*h,c=$t*z,m=c-(c-z),w=z-m,c=$t*h,x=c-(c-h),P=h-x,b=w*P-(p-m*x-w*x-m*P),V=_*u,c=$t*_,m=c-(c-_),w=_-m,c=$t*u,x=c-(c-u),P=u-x,v=w*P-(V-m*x-w*x-m*P),M=b-v,g=b-M,jt[0]=b-(M+g)+(g-v),d=p+M,g=d-p,f=p-(d-g)+(M-g),M=f-V,g=f-M,jt[1]=f-(M+g)+(g-V),S=d+M,g=S-d,jt[2]=d-(S-g)+(M-g),jt[3]=S;const I=Fe(F,sn,4,jt,an);p=a*h,c=$t*a,m=c-(c-a),w=a-m,c=$t*h,x=c-(c-h),P=h-x,b=w*P-(p-m*x-w*x-m*P),V=l*u,c=$t*l,m=c-(c-l),w=l-m,c=$t*u,x=c-(c-u),P=u-x,v=w*P-(V-m*x-w*x-m*P),M=b-v,g=b-M,jt[0]=b-(M+g)+(g-v),d=p+M,g=d-p,f=p-(d-g)+(M-g),M=f-V,g=f-M,jt[1]=f-(M+g)+(g-V),S=d+M,g=S-d,jt[2]=d-(S-g)+(M-g),jt[3]=S;const B=Fe(I,an,4,jt,ln);return ln[B-1]}function ve(n,t,e,o,i,r){const s=(t-r)*(e-i),a=(n-i)*(o-r),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=Do*u?l:-Eo(n,t,e,o,i,r,u)}const cn=Math.pow(2,-52),De=new Uint32Array(512);class Be{static from(t,e=Co,o=Lo){const i=t.length,r=new Float64Array(i*2);for(let s=0;s<i;s++){const a=t[s];r[2*s]=e(a),r[2*s+1]=o(a)}return new Be(r)}constructor(t){const e=t.length>>1;if(e>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const o=Math.max(2*e-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:o,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let a=1/0,l=1/0,u=-1/0,h=-1/0;for(let z=0;z<s;z++){const D=t[2*z],_=t[2*z+1];D<a&&(a=D),_<l&&(l=_),D>u&&(u=D),_>h&&(h=_),this._ids[z]=z}const g=(a+u)/2,c=(l+h)/2;let m=0,w=0,x=0;for(let z=0,D=1/0;z<s;z++){const _=We(g,c,t[2*z],t[2*z+1]);_<D&&(m=z,D=_)}const P=t[2*m],M=t[2*m+1];for(let z=0,D=1/0;z<s;z++){if(z===m)continue;const _=We(P,M,t[2*z],t[2*z+1]);_<D&&_>0&&(w=z,D=_)}let d=t[2*w],f=t[2*w+1],p=1/0;for(let z=0;z<s;z++){if(z===m||z===w)continue;const D=Io(P,M,d,f,t[2*z],t[2*z+1]);D<p&&(x=z,p=D)}let b=t[2*x],V=t[2*x+1];if(p===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ye(this._ids,this._dists,0,s-1);const z=new Uint32Array(s);let D=0;for(let _=0,T=-1/0;_<s;_++){const E=this._ids[_],A=this._dists[E];A>T&&(z[D++]=E,T=A)}this.hull=z.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(P,M,d,f,b,V)<0){const z=w,D=d,_=f;w=x,d=b,f=V,x=z,b=D,V=_}const v=ko(P,M,d,f,b,V);this._cx=v.x,this._cy=v.y;for(let z=0;z<s;z++)this._dists[z]=We(t[2*z],t[2*z+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=m;let S=3;o[m]=e[x]=w,o[w]=e[m]=x,o[x]=e[w]=m,i[m]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(P,M)]=m,r[this._hashKey(d,f)]=w,r[this._hashKey(b,V)]=x,this.trianglesLen=0,this._addTriangle(m,w,x,-1,-1,-1);for(let z=0,D=0,_=0;z<this._ids.length;z++){const T=this._ids[z],E=t[2*T],A=t[2*T+1];if(z>0&&Math.abs(E-D)<=cn&&Math.abs(A-_)<=cn||(D=E,_=A,T===m||T===w||T===x))continue;let F=0;for(let C=0,R=this._hashKey(E,A);C<this._hashSize&&(F=r[(R+C)%this._hashSize],!(F!==-1&&F!==o[F]));C++);F=e[F];let I=F,B;for(;B=o[I],ve(E,A,t[2*I],t[2*I+1],t[2*B],t[2*B+1])>=0;)if(I=B,I===F){I=-1;break}if(I===-1)continue;let L=this._addTriangle(I,T,o[I],-1,-1,i[I]);i[T]=this._legalize(L+2),i[I]=L,S++;let W=o[I];for(;B=o[W],ve(E,A,t[2*W],t[2*W+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(W,T,B,i[T],-1,i[W]),i[T]=this._legalize(L+2),o[W]=W,S--,W=B;if(I===F)for(;B=e[I],ve(E,A,t[2*B],t[2*B+1],t[2*I],t[2*I+1])<0;)L=this._addTriangle(B,T,I,-1,i[I],i[B]),this._legalize(L+2),i[B]=L,o[I]=I,S--,I=B;this._hullStart=e[T]=I,o[I]=e[W]=T,o[T]=W,r[this._hashKey(E,A)]=T,r[this._hashKey(t[2*I],t[2*I+1])]=I}this.hull=new Uint32Array(S);for(let z=0,D=this._hullStart;z<S;z++)this.hull[z]=D,D=o[D];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(Ao(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:o,coords:i}=this;let r=0,s=0;for(;;){const a=o[t],l=t-t%3;if(s=l+(t+2)%3,a===-1){if(r===0)break;t=De[--r];continue}const u=a-a%3,h=l+(t+1)%3,g=u+(a+2)%3,c=e[s],m=e[t],w=e[h],x=e[g];if(Bo(i[2*c],i[2*c+1],i[2*m],i[2*m+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=c;const M=o[g];if(M===-1){let f=this._hullStart;do{if(this._hullTri[f]===g){this._hullTri[f]=t;break}f=this._hullPrev[f]}while(f!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,g);const d=u+(a+1)%3;r<De.length&&(De[r++]=d)}else{if(r===0)break;t=De[--r]}}return s}_link(t,e){this._halfedges[t]=e,e!==-1&&(this._halfedges[e]=t)}_addTriangle(t,e,o,i,r,s){const a=this.trianglesLen;return this._triangles[a]=t,this._triangles[a+1]=e,this._triangles[a+2]=o,this._link(a,i),this._link(a+1,r),this._link(a+2,s),this.trianglesLen+=3,a}}function Ao(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function We(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function Bo(n,t,e,o,i,r,s,a){const l=n-s,u=t-a,h=e-s,g=o-a,c=i-s,m=r-a,w=l*l+u*u,x=h*h+g*g,P=c*c+m*m;return l*(g*P-x*m)-u*(h*P-x*c)+w*(h*m-g*c)<0}function Io(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,g=l*l+u*u,c=.5/(s*u-a*l),m=(u*h-a*g)*c,w=(s*g-l*h)*c;return m*m+w*w}function ko(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,g=l*l+u*u,c=.5/(s*u-a*l),m=n+(u*h-a*g)*c,w=t+(s*g-l*h)*c;return{x:m,y:w}}function ye(n,t,e,o){if(o-e<=20)for(let i=e+1;i<=o;i++){const r=n[i],s=t[r];let a=i-1;for(;a>=e&&t[n[a]]>s;)n[a+1]=n[a--];n[a+1]=r}else{const i=e+o>>1;let r=e+1,s=o;Me(n,i,r),t[n[e]]>t[n[o]]&&Me(n,e,o),t[n[r]]>t[n[o]]&&Me(n,r,o),t[n[e]]>t[n[r]]&&Me(n,e,r);const a=n[r],l=t[a];for(;;){do r++;while(t[n[r]]<l);do s--;while(t[n[s]]>l);if(s<r)break;Me(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ye(n,t,r,o),ye(n,t,e,s-1)):(ye(n,t,e,s-1),ye(n,t,r,o))}}function Me(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Co(n){return n[0]}function Lo(n){return n[1]}const un=1e-6;class de{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,o){t=+t,e=+e,o=+o;const i=t+o,r=e;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>un||Math.abs(this._y1-r)>un)&&(this._+="L"+i+","+r),o&&(this._+=`A${o},${o},0,1,1,${t-o},${e}A${o},${o},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,o,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+o}v${+i}h${-o}Z`}value(){return this._||null}}class $e{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class Ro{constructor(t,[e,o,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e))||!((r=+r)>=(o=+o)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:o},vectors:i}=this;let r,s;const a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let x=0,P=0,M=o.length,d,f;x<M;x+=3,P+=2){const p=o[x]*2,b=o[x+1]*2,V=o[x+2]*2,v=t[p],S=t[p+1],z=t[b],D=t[b+1],_=t[V],T=t[V+1],E=z-v,A=D-S,F=_-v,I=T-S,B=(E*I-A*F)*2;if(Math.abs(B)<1e-9){if(r===void 0){r=s=0;for(const W of e)r+=t[W*2],s+=t[W*2+1];r/=e.length,s/=e.length}const L=1e9*Math.sign((r-v)*I-(s-S)*F);d=(v+_)/2-L*I,f=(S+T)/2+L*F}else{const L=1/B,W=E*E+A*A,C=F*F+I*I;d=v+(I*W-A*C)*L,f=S+(E*C-F*W)*L}a[P]=d,a[P+1]=f}let l=e[e.length-1],u,h=l*4,g,c=t[2*l],m,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],u=h,g=c,m=w,h=l*4,c=t[2*l],w=t[2*l+1],i[u+2]=i[h]=m-w,i[u+3]=i[h+1]=c-g}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,g=o.length;h<g;++h){const c=o[h];if(c<h)continue;const m=Math.floor(h/3)*2,w=Math.floor(c/3)*2,x=s[m],P=s[m+1],M=s[w],d=s[w+1];this._renderSegment(x,P,M,d,t)}let l,u=r[r.length-1];for(let h=0;h<r.length;++h){l=u,u=r[h];const g=Math.floor(i[u]/3)*2,c=s[g],m=s[g+1],w=l*4,x=this._project(c,m,a[w+2],a[w+3]);x&&this._renderSegment(c,m,x[0],x[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new de:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const o=e==null?e=new de:void 0,i=this._clip(t);if(i===null||!i.length)return;e.moveTo(i[0],i[1]);let r=i.length;for(;i[0]===i[r-2]&&i[1]===i[r-1]&&r>1;)r-=2;for(let s=2;s<r;s+=2)(i[s]!==i[s-2]||i[s+1]!==i[s-1])&&e.lineTo(i[s],i[s+1]);return e.closePath(),o&&o.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,o=t.length/2;e<o;++e){const i=this.cellPolygon(e);i&&(i.index=e,yield i)}}cellPolygon(t){const e=new $e;return this.renderCell(t,e),e.value()}_renderSegment(t,e,o,i,r){let s;const a=this._regioncode(t,e),l=this._regioncode(o,i);a===0&&l===0?(r.moveTo(t,e),r.lineTo(o,i)):(s=this._clipSegment(t,e,o,i,a,l))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,o){return e=+e,e!==e||(o=+o,o!==o)?!1:this.delaunay._step(t,e,o)===t}*neighbors(t){const e=this._clip(t);if(e)for(const o of this.delaunay.neighbors(t)){const i=this._clip(o);if(i){t:for(let r=0,s=e.length;r<s;r+=2)for(let a=0,l=i.length;a<l;a+=2)if(e[r]===i[a]&&e[r+1]===i[a+1]&&e[(r+2)%s]===i[(a+l-2)%l]&&e[(r+3)%s]===i[(a+l-1)%l]){yield o;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:o,halfedges:i,triangles:r}}=this,s=o[t];if(s===-1)return null;const a=[];let l=s;do{const u=Math.floor(l/3);if(a.push(e[u*2],e[u*2+1]),l=l%3===2?l-2:l+1,r[l]!==t)break;l=i[l]}while(l!==s&&l!==-1);return a}_clip(t){if(t===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(e===null)return null;const{vectors:o}=this,i=t*4;return this._simplify(o[i]||o[i+1]?this._clipInfinite(t,e,o[i],o[i+1],o[i+2],o[i+3]):this._clipFinite(t,e))}_clipFinite(t,e){const o=e.length;let i=null,r,s,a=e[o-2],l=e[o-1],u,h=this._regioncode(a,l),g,c=0;for(let m=0;m<o;m+=2)if(r=a,s=l,a=e[m],l=e[m+1],u=h,h=this._regioncode(a,l),u===0&&h===0)g=c,c=0,i?i.push(a,l):i=[a,l];else{let w,x,P,M,d;if(u===0){if((w=this._clipSegment(r,s,a,l,u,h))===null)continue;[x,P,M,d]=w}else{if((w=this._clipSegment(a,l,r,s,h,u))===null)continue;[M,d,x,P]=w,g=c,c=this._edgecode(x,P),g&&c&&this._edge(t,g,c,i,i.length),i?i.push(x,P):i=[x,P]}g=c,c=this._edgecode(M,d),g&&c&&this._edge(t,g,c,i,i.length),i?i.push(M,d):i=[M,d]}if(i)g=c,c=this._edgecode(i[0],i[1]),g&&c&&this._edge(t,g,c,i,i.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(t,e,o,i,r,s){const a=r<s;for(a&&([t,e,o,i,r,s]=[o,i,t,e,s,r]);;){if(r===0&&s===0)return a?[o,i,t,e]:[t,e,o,i];if(r&s)return null;let l,u,h=r||s;h&8?(l=t+(o-t)*(this.ymax-e)/(i-e),u=this.ymax):h&4?(l=t+(o-t)*(this.ymin-e)/(i-e),u=this.ymin):h&2?(u=e+(i-e)*(this.xmax-t)/(o-t),l=this.xmax):(u=e+(i-e)*(this.xmin-t)/(o-t),l=this.xmin),r?(t=l,e=u,r=this._regioncode(t,e)):(o=l,i=u,s=this._regioncode(o,i))}}_clipInfinite(t,e,o,i,r,s){let a=Array.from(e),l;if((l=this._project(a[0],a[1],o,i))&&a.unshift(l[0],l[1]),(l=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(l[0],l[1]),a=this._clipFinite(t,a))for(let u=0,h=a.length,g,c=this._edgecode(a[h-2],a[h-1]);u<h;u+=2)g=c,c=this._edgecode(a[u],a[u+1]),g&&c&&(u=this._edge(t,g,c,a,u),h=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,o,i,r){for(;e!==o;){let s,a;switch(e){case 5:e=4;continue;case 4:e=6,s=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,s=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,s=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,s=this.xmin,a=this.ymin;break}(i[r]!==s||i[r+1]!==a)&&this.contains(t,s,a)&&(i.splice(r,0,s,a),r+=2)}return r}_project(t,e,o,i){let r=1/0,s,a,l;if(i<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/i)<r&&(l=this.ymin,a=t+(r=s)*o)}else if(i>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/i)<r&&(l=this.ymax,a=t+(r=s)*o)}if(o>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/o)<r&&(a=this.xmax,l=e+(r=s)*i)}else if(o<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/o)<r&&(a=this.xmin,l=e+(r=s)*i)}return[a,l]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let e=0;e<t.length;e+=2){const o=(e+2)%t.length,i=(e+4)%t.length;(t[e]===t[o]&&t[o]===t[i]||t[e+1]===t[o+1]&&t[o+1]===t[i+1])&&(t.splice(o,2),e-=2)}t.length||(t=null)}return t}}const Oo=2*Math.PI,ge=Math.pow;function Fo(n){return n[0]}function Wo(n){return n[1]}function No(n){const{triangles:t,coords:e}=n;for(let o=0;o<t.length;o+=3){const i=2*t[o],r=2*t[o+1],s=2*t[o+2];if((e[s]-e[i])*(e[r+1]-e[i+1])-(e[r]-e[i])*(e[s+1]-e[i+1])>1e-10)return!1}return!0}function qo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class Ue{static from(t,e=Fo,o=Wo,i){return new Ue("length"in t?Xo(t,e,o,i):Float64Array.from(Ho(t,e,o,i)))}constructor(t){this._delaunator=new Be(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&No(t)){this.collinear=Int32Array.from({length:e.length/2},(c,m)=>m).sort((c,m)=>e[2*c]-e[2*m]||e[2*c+1]-e[2*m+1]);const l=this.collinear[0],u=this.collinear[this.collinear.length-1],h=[e[2*l],e[2*l+1],e[2*u],e[2*u+1]],g=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let c=0,m=e.length/2;c<m;++c){const w=qo(e[2*c],e[2*c+1],g);e[2*c]=w[0],e[2*c+1]=w[1]}this._delaunator=new Be(e)}else delete this.collinear;const o=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,u=o.length;l<u;++l){const h=r[l%3===2?l-2:l+1];(o[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,u=i.length;l<u;++l)a[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new Ro(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const g=a.indexOf(t);g>0&&(yield a[g-1]),g<a.length-1&&(yield a[g+1]);return}const l=e[t];if(l===-1)return;let u=l,h=-1;do{if(yield h=s[u],u=u%3===2?u-2:u+1,s[u]!==t)return;if(u=r[u],u===-1){const g=o[(i[t]+1)%o.length];g!==h&&(yield g);return}}while(u!==l)}find(t,e,o=0){if(t=+t,t!==t||(e=+e,e!==e))return-1;const i=o;let r;for(;(r=this._step(o,t,e))>=0&&r!==o&&r!==i;)o=r;return r}_step(t,e,o){const{inedges:i,hull:r,_hullIndex:s,halfedges:a,triangles:l,points:u}=this;if(i[t]===-1||!u.length)return(t+1)%(u.length>>1);let h=t,g=ge(e-u[t*2],2)+ge(o-u[t*2+1],2);const c=i[t];let m=c;do{let w=l[m];const x=ge(e-u[w*2],2)+ge(o-u[w*2+1],2);if(x<g&&(g=x,h=w),m=m%3===2?m-2:m+1,l[m]!==t)break;if(m=a[m],m===-1){if(m=r[(s[t]+1)%r.length],m!==w&&ge(e-u[m*2],2)+ge(o-u[m*2+1],2)<g)return m;break}}while(m!==c);return h}render(t){const e=t==null?t=new de:void 0,{points:o,halfedges:i,triangles:r}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const u=r[s]*2,h=r[l]*2;t.moveTo(o[u],o[u+1]),t.lineTo(o[h],o[h+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){e===void 0&&(!t||typeof t.moveTo!="function")&&(e=t,t=null),e=e==null?2:+e;const o=t==null?t=new de:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const a=i[r],l=i[r+1];t.moveTo(a+e,l),t.arc(a,l,e,0,Oo)}return o&&o.value()}renderHull(t){const e=t==null?t=new de:void 0,{hull:o,points:i}=this,r=o[0]*2,s=o.length;t.moveTo(i[r],i[r+1]);for(let a=1;a<s;++a){const l=2*o[a];t.lineTo(i[l],i[l+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new $e;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new de:void 0,{points:i,triangles:r}=this,s=r[t*=3]*2,a=r[t+1]*2,l=r[t+2]*2;return e.moveTo(i[s],i[s+1]),e.lineTo(i[a],i[a+1]),e.lineTo(i[l],i[l+1]),e.closePath(),o&&o.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,o=t.length/3;e<o;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new $e;return this.renderTriangle(t,e),e.value()}}function Xo(n,t,e,o){const i=n.length,r=new Float64Array(i*2);for(let s=0;s<i;++s){const a=n[s];r[s*2]=t.call(o,a,s,n),r[s*2+1]=e.call(o,a,s,n)}return r}function*Ho(n,t,e,o){let i=0;for(const r of n)yield t.call(o,r,i,n),yield e.call(o,r,i,n),++i}function Yo(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function $o(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),u=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return u===0?1/0:s*a*l/(4*u)}function Ge(n){if(!n||n.length<3)return[];const t=new Set,e=[];for(const w of n){const x=`${w[0]}_${w[1]}`;t.has(x)||(t.add(x),e.push(w))}if(e.length<3)return[];const o=new Ue(Float64Array.from(e.flat())),{triangles:i}=o;if(!i.length)return[];const r=new Map,s=(w,x)=>w<x?`${w}_${x}`:`${x}_${w}`;for(let w=0;w<i.length;w+=3){const x=i[w],P=i[w+1],M=i[w+2],[d,f]=e[x],[p,b]=e[P],[V,v]=e[M],S=$o(d,f,p,b,V,v),z=Yo(e,x,P,M);if(S<=1/z)for(const[D,_]of[[x,P],[P,M],[M,x]]){const T=s(D,_);r.set(T,(r.get(T)||0)+1)}}const a=[];for(const[w,x]of r)x===1&&a.push(w.split("_").map(Number));if(!a.length)return[];const l=new Map;for(const[w,x]of a)(l.get(w)||l.set(w,[]).get(w)).push(x),(l.get(x)||l.set(x,[]).get(x)).push(w);const u=a[0][0],h=[],g=new Set;let c=u,m=-1;do{h.push(e[c]),g.add(c);const w=l.get(c)||[];let x=w.find(P=>P!==m&&!g.has(P));if(x===void 0&&(x=w.find(P=>P!==m)),x===void 0)break;m=c,c=x}while(c!==u&&h.length<=a.length+1);return h}const gt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},xt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},It=[[],[],[]],nt=[[],[],[]],Dt=[],ce=new lt.Vector3,ue=new lt.Vector3,he=new lt.Vector3,Ft=new lt.Vector3,hn=new lt.Vector3,fn=new lt.Vector3,Qt=new lt.Matrix3,dn=new lt.Box3,_e=new lt.Matrix4,mn=new lt.Matrix4,gn=new lt.Ray;let En=class{constructor(t=new lt.Vector3,e=new lt.Vector3,o=new lt.Matrix3){this.center=t,this.halfSize=e,this.rotation=o}set(t,e,o){return this.center=t,this.halfSize=e,this.rotation=o,this}copy(t){return this.center.copy(t.center),this.halfSize.copy(t.halfSize),this.rotation.copy(t.rotation),this}clone(){return new this.constructor().copy(this)}getSize(t){return t.copy(this.halfSize).multiplyScalar(2)}clampPoint(t,e){const o=this.halfSize;Ft.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const i=lt.MathUtils.clamp(Ft.dot(ce),-o.x,o.x);e.add(ce.multiplyScalar(i));const r=lt.MathUtils.clamp(Ft.dot(ue),-o.y,o.y);e.add(ue.multiplyScalar(r));const s=lt.MathUtils.clamp(Ft.dot(he),-o.z,o.z);return e.add(he.multiplyScalar(s)),e}containsPoint(t){return Ft.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),Math.abs(Ft.dot(ce))<=this.halfSize.x&&Math.abs(Ft.dot(ue))<=this.halfSize.y&&Math.abs(Ft.dot(he))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Go.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,fn),fn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){gt.c=this.center,gt.e[0]=this.halfSize.x,gt.e[1]=this.halfSize.y,gt.e[2]=this.halfSize.z,this.rotation.extractBasis(gt.u[0],gt.u[1],gt.u[2]),xt.c=t.center,xt.e[0]=t.halfSize.x,xt.e[1]=t.halfSize.y,xt.e[2]=t.halfSize.z,t.rotation.extractBasis(xt.u[0],xt.u[1],xt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)It[r][s]=gt.u[r].dot(xt.u[s]);Ft.subVectors(xt.c,gt.c),Dt[0]=Ft.dot(gt.u[0]),Dt[1]=Ft.dot(gt.u[1]),Dt[2]=Ft.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)nt[r][s]=Math.abs(It[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*nt[r][0]+xt.e[1]*nt[r][1]+xt.e[2]*nt[r][2],Math.abs(Dt[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*nt[0][r]+gt.e[1]*nt[1][r]+gt.e[2]*nt[2][r],i=xt.e[r],Math.abs(Dt[0]*It[0][r]+Dt[1]*It[1][r]+Dt[2]*It[2][r])>o+i)return!1;return o=gt.e[1]*nt[2][0]+gt.e[2]*nt[1][0],i=xt.e[1]*nt[0][2]+xt.e[2]*nt[0][1],!(Math.abs(Dt[2]*It[1][0]-Dt[1]*It[2][0])>o+i||(o=gt.e[1]*nt[2][1]+gt.e[2]*nt[1][1],i=xt.e[0]*nt[0][2]+xt.e[2]*nt[0][0],Math.abs(Dt[2]*It[1][1]-Dt[1]*It[2][1])>o+i)||(o=gt.e[1]*nt[2][2]+gt.e[2]*nt[1][2],i=xt.e[0]*nt[0][1]+xt.e[1]*nt[0][0],Math.abs(Dt[2]*It[1][2]-Dt[1]*It[2][2])>o+i)||(o=gt.e[0]*nt[2][0]+gt.e[2]*nt[0][0],i=xt.e[1]*nt[1][2]+xt.e[2]*nt[1][1],Math.abs(Dt[0]*It[2][0]-Dt[2]*It[0][0])>o+i)||(o=gt.e[0]*nt[2][1]+gt.e[2]*nt[0][1],i=xt.e[0]*nt[1][2]+xt.e[2]*nt[1][0],Math.abs(Dt[0]*It[2][1]-Dt[2]*It[0][1])>o+i)||(o=gt.e[0]*nt[2][2]+gt.e[2]*nt[0][2],i=xt.e[0]*nt[1][1]+xt.e[1]*nt[1][0],Math.abs(Dt[0]*It[2][2]-Dt[2]*It[0][2])>o+i)||(o=gt.e[0]*nt[1][0]+gt.e[1]*nt[0][0],i=xt.e[1]*nt[2][2]+xt.e[2]*nt[2][1],Math.abs(Dt[1]*It[0][0]-Dt[0]*It[1][0])>o+i)||(o=gt.e[0]*nt[1][1]+gt.e[1]*nt[0][1],i=xt.e[0]*nt[2][2]+xt.e[2]*nt[2][0],Math.abs(Dt[1]*It[0][1]-Dt[0]*It[1][1])>o+i)||(o=gt.e[0]*nt[1][2]+gt.e[1]*nt[0][2],i=xt.e[0]*nt[2][1]+xt.e[1]*nt[2][0],Math.abs(Dt[1]*It[0][2]-Dt[0]*It[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ce,ue,he);const e=this.halfSize.x*Math.abs(t.normal.dot(ce))+this.halfSize.y*Math.abs(t.normal.dot(ue))+this.halfSize.z*Math.abs(t.normal.dot(he)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(hn),dn.setFromCenterAndSize(Ft.set(0,0,0),hn),_e.setFromMatrix3(this.rotation),_e.setPosition(this.center),mn.copy(_e).invert(),gn.copy(t).applyMatrix4(mn),gn.intersectBox(dn,e)?e.applyMatrix4(_e):null}intersectsRay(t){return this.intersectRay(t,Ft)!==null}fromBox3(t){return t.getCenter(this.center),t.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(t){return t.center.equals(this.center)&&t.halfSize.equals(this.halfSize)&&t.rotation.equals(this.rotation)}applyMatrix4(t){const e=t.elements;let o=Ft.set(e[0],e[1],e[2]).length();const i=Ft.set(e[4],e[5],e[6]).length(),r=Ft.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Qt.setFromMatrix4(t);const a=1/o,l=1/i,u=1/r;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[3]*=l,Qt.elements[4]*=l,Qt.elements[5]*=l,Qt.elements[6]*=u,Qt.elements[7]*=u,Qt.elements[8]*=u,this.rotation.multiply(Qt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ft.setFromMatrixPosition(t),this.center.add(Ft),this}};const Go=new En;var Yt=63710088e-1,An={centimeters:Yt*100,centimetres:Yt*100,degrees:360/(2*Math.PI),feet:Yt*3.28084,inches:Yt*39.37,kilometers:Yt/1e3,kilometres:Yt/1e3,meters:Yt,metres:Yt,miles:Yt/1609.344,millimeters:Yt*1e3,millimetres:Yt*1e3,nauticalmiles:Yt/1852,radians:1,yards:Yt*1.0936};function Bn(n,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=n,o}function In(n,t,e={}){if(!n)throw new Error("coordinates is required");if(!Array.isArray(n))throw new Error("coordinates must be an Array");if(n.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!pn(n[0])||!pn(n[1]))throw new Error("coordinates must contain numbers");return Bn({type:"Point",coordinates:n},t,e)}function kn(n,t,e={}){for(const i of n){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<i[i.length-1].length;r++)if(i[i.length-1][r]!==i[0][r])throw new Error("First and last Position are not equivalent.")}return Bn({type:"Polygon",coordinates:n},t,e)}function jo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Uo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n/e}function Cn(n){return n%(2*Math.PI)*180/Math.PI}function ie(n){return n%360*Math.PI/180}function Ln(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return jo(Uo(n,t),e)}function pn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function Zo(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function Pe(n,t,e){if(n!==null)for(var o,i,r,s,a,l,u,h=0,g=0,c,m=n.type,w=m==="FeatureCollection",x=m==="Feature",P=w?n.features.length:1,M=0;M<P;M++){u=w?n.features[M].geometry:x?n.geometry:n,c=u?u.type==="GeometryCollection":!1,a=c?u.geometries.length:1;for(var d=0;d<a;d++){var f=0,p=0;if(s=c?u.geometries[d]:u,s!==null){l=s.coordinates;var b=s.type;switch(h=e&&(b==="Polygon"||b==="MultiPolygon")?1:0,b){case null:break;case"Point":if(t(l,g,M,f,p)===!1)return!1;g++,f++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],g,M,f,p)===!1)return!1;g++,b==="MultiPoint"&&f++}b==="LineString"&&f++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-h;i++){if(t(l[o][i],g,M,f,p)===!1)return!1;g++}b==="MultiLineString"&&f++,b==="Polygon"&&p++}b==="Polygon"&&f++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(p=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],g,M,f,p)===!1)return!1;g++}p++}f++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(Pe(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ko(n){var t=[];return Pe(n,function(e){t.push(e)}),t}function Qo(n,t){var e,o,i,r,s,a,l,u,h,g,c=0,m=n.type==="FeatureCollection",w=n.type==="Feature",x=m?n.features.length:1;for(e=0;e<x;e++){for(a=m?n.features[e].geometry:w?n.geometry:n,u=m?n.features[e].properties:w?n.properties:{},h=m?n.features[e].bbox:w?n.bbox:void 0,g=m?n.features[e].id:w?n.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(r=l?a.geometries[i]:a,r===null){if(t(null,c,u,h,g)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,c,u,h,g)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],c,u,h,g)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}c++}}function Jo(n,t,e){var o=e;return Qo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function er(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function o(){return this instanceof o?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(o){var i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:function(){return n[o]}})}),e}var Ze={exports:{}},On={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(d,f,p,b,V){(function v(S,z,D,_,T){for(;_>D;){if(_-D>600){var E=_-D+1,A=z-D+1,F=Math.log(E),I=.5*Math.exp(2*F/3),B=.5*Math.sqrt(F*I*(E-I)/E)*(A-E/2<0?-1:1),L=Math.max(D,Math.floor(z-A*I/E+B)),W=Math.min(_,Math.floor(z+(E-A)*I/E+B));v(S,z,L,W,T)}var C=S[z],R=D,H=_;for(o(S,D,z),T(S[_],C)>0&&o(S,D,_);R<H;){for(o(S,R,H),R++,H--;T(S[R],C)<0;)R++;for(;T(S[H],C)>0;)H--}T(S[D],C)===0?o(S,D,H):o(S,++H,_),H<=z&&(D=H+1),z<=H&&(_=H-1)}})(d,f,p||0,b||d.length-1,V||i)}function o(d,f,p){var b=d[f];d[f]=d[p],d[p]=b}function i(d,f){return d<f?-1:d>f?1:0}var r=function(d){d===void 0&&(d=9),this._maxEntries=Math.max(4,d),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(d,f,p){if(!p)return f.indexOf(d);for(var b=0;b<f.length;b++)if(p(d,f[b]))return b;return-1}function a(d,f){l(d,0,d.children.length,f,d)}function l(d,f,p,b,V){V||(V=P(null)),V.minX=1/0,V.minY=1/0,V.maxX=-1/0,V.maxY=-1/0;for(var v=f;v<p;v++){var S=d.children[v];u(V,d.leaf?b(S):S)}return V}function u(d,f){return d.minX=Math.min(d.minX,f.minX),d.minY=Math.min(d.minY,f.minY),d.maxX=Math.max(d.maxX,f.maxX),d.maxY=Math.max(d.maxY,f.maxY),d}function h(d,f){return d.minX-f.minX}function g(d,f){return d.minY-f.minY}function c(d){return(d.maxX-d.minX)*(d.maxY-d.minY)}function m(d){return d.maxX-d.minX+(d.maxY-d.minY)}function w(d,f){return d.minX<=f.minX&&d.minY<=f.minY&&f.maxX<=d.maxX&&f.maxY<=d.maxY}function x(d,f){return f.minX<=d.maxX&&f.minY<=d.maxY&&f.maxX>=d.minX&&f.maxY>=d.minY}function P(d){return{children:d,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(d,f,p,b,V){for(var v=[f,p];v.length;)if(!((p=v.pop())-(f=v.pop())<=b)){var S=f+Math.ceil((p-f)/b/2)*b;e(d,S,f,p,V),v.push(f,S,S,p)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(d){var f=this.data,p=[];if(!x(d,f))return p;for(var b=this.toBBox,V=[];f;){for(var v=0;v<f.children.length;v++){var S=f.children[v],z=f.leaf?b(S):S;x(d,z)&&(f.leaf?p.push(S):w(d,z)?this._all(S,p):V.push(S))}f=V.pop()}return p},r.prototype.collides=function(d){var f=this.data;if(!x(d,f))return!1;for(var p=[];f;){for(var b=0;b<f.children.length;b++){var V=f.children[b],v=f.leaf?this.toBBox(V):V;if(x(d,v)){if(f.leaf||w(d,v))return!0;p.push(V)}}f=p.pop()}return!1},r.prototype.load=function(d){if(!d||!d.length)return this;if(d.length<this._minEntries){for(var f=0;f<d.length;f++)this.insert(d[f]);return this}var p=this._build(d.slice(),0,d.length-1,0);if(this.data.children.length)if(this.data.height===p.height)this._splitRoot(this.data,p);else{if(this.data.height<p.height){var b=this.data;this.data=p,p=b}this._insert(p,this.data.height-p.height-1,!0)}else this.data=p;return this},r.prototype.insert=function(d){return d&&this._insert(d,this.data.height-1),this},r.prototype.clear=function(){return this.data=P([]),this},r.prototype.remove=function(d,f){if(!d)return this;for(var p,b,V,v=this.data,S=this.toBBox(d),z=[],D=[];v||z.length;){if(v||(v=z.pop(),b=z[z.length-1],p=D.pop(),V=!0),v.leaf){var _=s(d,v.children,f);if(_!==-1)return v.children.splice(_,1),z.push(v),this._condense(z),this}V||v.leaf||!w(v,S)?b?(p++,v=b.children[p],V=!1):v=null:(z.push(v),D.push(p),p=0,b=v,v=v.children[0])}return this},r.prototype.toBBox=function(d){return d},r.prototype.compareMinX=function(d,f){return d.minX-f.minX},r.prototype.compareMinY=function(d,f){return d.minY-f.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(d){return this.data=d,this},r.prototype._all=function(d,f){for(var p=[];d;)d.leaf?f.push.apply(f,d.children):p.push.apply(p,d.children),d=p.pop();return f},r.prototype._build=function(d,f,p,b){var V,v=p-f+1,S=this._maxEntries;if(v<=S)return a(V=P(d.slice(f,p+1)),this.toBBox),V;b||(b=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,b-1))),(V=P([])).leaf=!1,V.height=b;var z=Math.ceil(v/S),D=z*Math.ceil(Math.sqrt(S));M(d,f,p,D,this.compareMinX);for(var _=f;_<=p;_+=D){var T=Math.min(_+D-1,p);M(d,_,T,z,this.compareMinY);for(var E=_;E<=T;E+=z){var A=Math.min(E+z-1,T);V.children.push(this._build(d,E,A,b-1))}}return a(V,this.toBBox),V},r.prototype._chooseSubtree=function(d,f,p,b){for(;b.push(f),!f.leaf&&b.length-1!==p;){for(var V=1/0,v=1/0,S=void 0,z=0;z<f.children.length;z++){var D=f.children[z],_=c(D),T=(E=d,A=D,(Math.max(A.maxX,E.maxX)-Math.min(A.minX,E.minX))*(Math.max(A.maxY,E.maxY)-Math.min(A.minY,E.minY))-_);T<v?(v=T,V=_<V?_:V,S=D):T===v&&_<V&&(V=_,S=D)}f=S||f.children[0]}var E,A;return f},r.prototype._insert=function(d,f,p){var b=p?d:this.toBBox(d),V=[],v=this._chooseSubtree(b,this.data,f,V);for(v.children.push(d),u(v,b);f>=0&&V[f].children.length>this._maxEntries;)this._split(V,f),f--;this._adjustParentBBoxes(b,V,f)},r.prototype._split=function(d,f){var p=d[f],b=p.children.length,V=this._minEntries;this._chooseSplitAxis(p,V,b);var v=this._chooseSplitIndex(p,V,b),S=P(p.children.splice(v,p.children.length-v));S.height=p.height,S.leaf=p.leaf,a(p,this.toBBox),a(S,this.toBBox),f?d[f-1].children.push(S):this._splitRoot(p,S)},r.prototype._splitRoot=function(d,f){this.data=P([d,f]),this.data.height=d.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(d,f,p){for(var b,V,v,S,z,D,_,T=1/0,E=1/0,A=f;A<=p-f;A++){var F=l(d,0,A,this.toBBox),I=l(d,A,p,this.toBBox),B=(V=F,v=I,S=void 0,z=void 0,D=void 0,_=void 0,S=Math.max(V.minX,v.minX),z=Math.max(V.minY,v.minY),D=Math.min(V.maxX,v.maxX),_=Math.min(V.maxY,v.maxY),Math.max(0,D-S)*Math.max(0,_-z)),L=c(F)+c(I);B<T?(T=B,b=A,E=L<E?L:E):B===T&&L<E&&(E=L,b=A)}return b||p-f},r.prototype._chooseSplitAxis=function(d,f,p){var b=d.leaf?this.compareMinX:h,V=d.leaf?this.compareMinY:g;this._allDistMargin(d,f,p,b)<this._allDistMargin(d,f,p,V)&&d.children.sort(b)},r.prototype._allDistMargin=function(d,f,p,b){d.children.sort(b);for(var V=this.toBBox,v=l(d,0,f,V),S=l(d,p-f,p,V),z=m(v)+m(S),D=f;D<p-f;D++){var _=d.children[D];u(v,d.leaf?V(_):_),z+=m(v)}for(var T=p-f-1;T>=f;T--){var E=d.children[T];u(S,d.leaf?V(E):E),z+=m(S)}return z},r.prototype._adjustParentBBoxes=function(d,f,p){for(var b=p;b>=0;b--)u(f[b],d)},r.prototype._condense=function(d){for(var f=d.length-1,p=void 0;f>=0;f--)d[f].children.length===0?f>0?(p=d[f-1].children).splice(p.indexOf(d[f]),1):this.clear():a(d[f],this.toBBox)},r})})(On);var nr=On.exports;class or{constructor(t=[],e=rr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let o=(this.length>>1)-1;o>=0;o--)this._down(o)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:o}=this,i=e[t];for(;t>0;){const r=t-1>>1,s=e[r];if(o(i,s)>=0)break;e[t]=s,t=r}e[t]=i}_down(t){const{data:e,compare:o}=this,i=this.length>>1,r=e[t];for(;t<i;){let s=(t<<1)+1,a=e[s];const l=s+1;if(l<this.length&&o(e[l],a)<0&&(s=l,a=e[l]),o(a,r)>=0)break;e[t]=a,t=s}e[t]=r}}function rr(n,t){return n<t?-1:n>t?1:0}const ir=Object.freeze(Object.defineProperty({__proto__:null,default:or},Symbol.toStringTag,{value:"Module"})),sr=er(ir);var ke={exports:{}},ar=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=(i-o)/2,u=0,h=l-1;u<l;h=u++){var g=e[o+u*2+0],c=e[o+u*2+1],m=e[o+h*2+0],w=e[o+h*2+1],x=c>s!=w>s&&r<(m-g)*(s-c)/(w-c)+g;x&&(a=!a)}return a},lr=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=i-o,u=0,h=l-1;u<l;h=u++){var g=e[u+o][0],c=e[u+o][1],m=e[h+o][0],w=e[h+o][1],x=c>s!=w>s&&r<(m-g)*(s-c)/(w-c)+g;x&&(a=!a)}return a},Fn=ar,Wn=lr;ke.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Wn(t,e,o,i):Fn(t,e,o,i)};ke.exports.nested=Wn;ke.exports.flat=Fn;var cr=ke.exports,je={exports:{}};(function(n,t){(function(e,o){o(t)})(Rn,function(e){const i=33306690738754706e-32;function r(x,P,M,d,f){let p,b,V,v,S=P[0],z=d[0],D=0,_=0;z>S==z>-S?(p=S,S=P[++D]):(p=z,z=d[++_]);let T=0;if(D<x&&_<M)for(z>S==z>-S?(V=p-((b=S+p)-S),S=P[++D]):(V=p-((b=z+p)-z),z=d[++_]),p=b,V!==0&&(f[T++]=V);D<x&&_<M;)z>S==z>-S?(V=p-((b=p+S)-(v=b-p))+(S-v),S=P[++D]):(V=p-((b=p+z)-(v=b-p))+(z-v),z=d[++_]),p=b,V!==0&&(f[T++]=V);for(;D<x;)V=p-((b=p+S)-(v=b-p))+(S-v),S=P[++D],p=b,V!==0&&(f[T++]=V);for(;_<M;)V=p-((b=p+z)-(v=b-p))+(z-v),z=d[++_],p=b,V!==0&&(f[T++]=V);return p===0&&T!==0||(f[T++]=p),T}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,u=11093356479670487e-47,h=s(4),g=s(8),c=s(12),m=s(16),w=s(4);e.orient2d=function(x,P,M,d,f,p){const b=(P-p)*(M-f),V=(x-f)*(d-p),v=b-V;if(b===0||V===0||b>0!=V>0)return v;const S=Math.abs(b+V);return Math.abs(v)>=a*S?v:-function(z,D,_,T,E,A,F){let I,B,L,W,C,R,H,X,ot,K,G,ht,rt,O,Y,Vt,Zt,Nt;const Rt=z-E,_t=_-E,Tt=D-A,Ot=T-A;C=(Y=(X=Rt-(H=(R=134217729*Rt)-(R-Rt)))*(K=Ot-(ot=(R=134217729*Ot)-(R-Ot)))-((O=Rt*Ot)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=Tt-(H=(R=134217729*Tt)-(R-Tt)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=Tt*_t)-H*ot-X*ot-H*K))),h[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),h[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,h[2]=ht-(Nt-C)+(G-C),h[3]=Nt;let tt=function(Et,qt){let J=qt[0];for(let ut=1;ut<Et;ut++)J+=qt[ut];return J}(4,h),ct=l*F;if(tt>=ct||-tt>=ct||(I=z-(Rt+(C=z-Rt))+(C-E),L=_-(_t+(C=_-_t))+(C-E),B=D-(Tt+(C=D-Tt))+(C-A),W=T-(Ot+(C=T-Ot))+(C-A),I===0&&B===0&&L===0&&W===0)||(ct=u*F+i*Math.abs(tt),(tt+=Rt*W+Ot*I-(Tt*L+_t*B))>=ct||-tt>=ct))return tt;C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(K=Ot-(ot=(R=134217729*Ot)-(R-Ot)))-((O=I*Ot)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=B-(H=(R=134217729*B)-(R-B)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=B*_t)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const q=r(4,h,4,w,g);C=(Y=(X=Rt-(H=(R=134217729*Rt)-(R-Rt)))*(K=W-(ot=(R=134217729*W)-(R-W)))-((O=Rt*W)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=Tt-(H=(R=134217729*Tt)-(R-Tt)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=Tt*L)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const j=r(q,g,4,w,c);C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(K=W-(ot=(R=134217729*W)-(R-W)))-((O=I*W)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=B-(H=(R=134217729*B)-(R-B)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=B*L)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const Wt=r(j,c,4,w,m);return m[Wt-1]}(x,P,M,d,f,p,S)},e.orient2dfast=function(x,P,M,d,f,p){return(P-p)*(M-f)-(x-f)*(d-p)},Object.defineProperty(e,"__esModule",{value:!0})})})(je,je.exports);var ur=je.exports,yn=nr,Ae=sr,hr=cr,fr=ur.orient2d;Ae.default&&(Ae=Ae.default);Ze.exports=Nn;Ze.exports.default=Nn;function Nn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=yr(n),i=new yn(16);i.toBBox=function(d){return{minX:d[0],minY:d[1],maxX:d[0],maxY:d[1]}},i.compareMinX=function(d,f){return d[0]-f[0]},i.compareMinY=function(d,f){return d[1]-f[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=bn(l,a),r.push(a)}var u=new yn(16);for(s=0;s<r.length;s++)u.insert(Ne(r[s]));for(var h=t*t,g=e*e;r.length;){var c=r.shift(),m=c.p,w=c.next.p,x=qe(m,w);if(!(x<g)){var P=x/h;l=dr(i,c.prev.p,m,w,c.next.next.p,P,u),l&&Math.min(qe(l,m),qe(l,w))<=P&&(r.push(c),r.push(bn(l,c)),i.remove(l),u.remove(c),u.insert(Ne(c)),u.insert(Ne(c.next)))}}c=a;var M=[];do M.push(c.p),c=c.next;while(c!==a);return M.push(c.p),M}function dr(n,t,e,o,i,r,s){for(var a=new Ae([],mr),l=n.data;l;){for(var u=0;u<l.children.length;u++){var h=l.children[u],g=l.leaf?Xe(h,e,o):gr(e,o,h);g>r||a.push({node:h,dist:g})}for(;a.length&&!a.peek().node.children;){var c=a.pop(),m=c.node,w=Xe(m,t,e),x=Xe(m,o,i);if(c.dist<w&&c.dist<x&&wn(e,m,s)&&wn(o,m,s))return m}l=a.pop(),l&&(l=l.node)}return null}function mr(n,t){return n.dist-t.dist}function gr(n,t,e){if(xn(n,e)||xn(t,e))return 0;var o=Te(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=Te(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=Te(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=Te(n[0],n[1],t[0],t[1],e.minX,e.maxY,e.maxX,e.maxY);return s===0?0:Math.min(o,i,r,s)}function xn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function wn(n,t,e){for(var o=Math.min(n[0],t[0]),i=Math.min(n[1],t[1]),r=Math.max(n[0],t[0]),s=Math.max(n[1],t[1]),a=e.search({minX:o,minY:i,maxX:r,maxY:s}),l=0;l<a.length;l++)if(pr(a[l].p,a[l].next.p,n,t))return!1;return!0}function xe(n,t,e){return fr(n[0],n[1],t[0],t[1],e[0],e[1])}function pr(n,t,e,o){return n!==o&&t!==e&&xe(n,t,e)>0!=xe(n,t,o)>0&&xe(e,o,n)>0!=xe(e,o,t)>0}function Ne(n){var t=n.p,e=n.next.p;return n.minX=Math.min(t[0],e[0]),n.minY=Math.min(t[1],e[1]),n.maxX=Math.max(t[0],e[0]),n.maxY=Math.max(t[1],e[1]),n}function yr(n){for(var t=n[0],e=n[0],o=n[0],i=n[0],r=0;r<n.length;r++){var s=n[r];s[0]<t[0]&&(t=s),s[0]>o[0]&&(o=s),s[1]<e[1]&&(e=s),s[1]>i[1]&&(i=s)}var a=[t,e,o,i],l=a.slice();for(r=0;r<n.length;r++)hr(n[r],a)||l.push(n[r]);return wr(l)}function bn(n,t){var e={p:n,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e):(e.prev=e,e.next=e),e}function qe(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function Xe(n,t,e){var o=t[0],i=t[1],r=e[0]-o,s=e[1]-i;if(r!==0||s!==0){var a=((n[0]-o)*r+(n[1]-i)*s)/(r*r+s*s);a>1?(o=e[0],i=e[1]):a>0&&(o+=r*a,i+=s*a)}return r=n[0]-o,s=n[1]-i,r*r+s*s}function Te(n,t,e,o,i,r,s,a){var l=e-n,u=o-t,h=s-i,g=a-r,c=n-i,m=t-r,w=l*l+u*u,x=l*h+u*g,P=h*h+g*g,M=l*c+u*m,d=h*c+g*m,f=w*P-x*x,p,b,V,v,S=f,z=f;f===0?(b=0,S=1,v=d,z=P):(b=x*d-P*M,v=w*d-x*M,b<0?(b=0,v=d,z=P):b>S&&(b=S,v=d+x,z=P)),v<0?(v=0,-M<0?b=0:-M>w?b=S:(b=-M,S=w)):v>z&&(v=z,-M+x<0?b=0:-M+x>w?b=S:(b=-M+x,S=w)),p=b===0?0:b/S,V=v===0?0:v/z;var D=(1-p)*n+p*e,_=(1-p)*t+p*o,T=(1-V)*i+V*s,E=(1-V)*r+V*a,A=T-D,F=E-_;return A*A+F*F}function xr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function wr(n){n.sort(xr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&xe(t[t.length-2],t[t.length-1],n[e])<=0;)t.pop();t.push(n[e])}for(var o=[],i=n.length-1;i>=0;i--){for(;o.length>=2&&xe(o[o.length-2],o[o.length-1],n[i])<=0;)o.pop();o.push(n[i])}return o.pop(),t.pop(),t.concat(o)}var br=Ze.exports;const Pr=tr(br);function Mr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(Pe(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=Pr(e,t.concavity);return o.length>3?kn([o]):null}function qn(n,t={}){let e=0,o=0,i=0;return Pe(n,function(r){e+=r[0],o+=r[1],i++},!0),In([e/i,o/i],t.properties)}function se(n){if(!n)throw new Error("coord is required");if(!Array.isArray(n)){if(n.type==="Feature"&&n.geometry!==null&&n.geometry.type==="Point")return[...n.geometry.coordinates];if(n.type==="Point")return[...n.coordinates]}if(Array.isArray(n)&&n.length>=2&&!Array.isArray(n[0])&&!Array.isArray(n[1]))return[...n];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Vr(n){if(Array.isArray(n))return n;if(n.type==="Feature"){if(n.geometry!==null)return n.geometry.coordinates}else if(n.coordinates)return n.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function zr(n,t,e={}){let o;return e.final?o=Pn(se(t),se(n)):o=Pn(se(n),se(t)),o>180?-(360-o):o}function Pn(n,t){const e=ie(n[1]),o=ie(t[1]);let i=ie(t[0]-n[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(i,r);return(Cn(s)+360)%360}function Sr(n,t,e={}){const o=se(n),i=se(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=vr(o,i);return Ln(r,"meters",e.units)}function vr(n,t,e){e=e===void 0?Yt:Number(e);const o=e,i=n[1]*Math.PI/180,r=t[1]*Math.PI/180,s=r-i;let a=Math.abs(t[0]-n[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),u=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+u*u*a*a)*o}function Dr(n,t,e,o={}){const i=t<0;let r=Ln(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=se(n),a=_r(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,In(a,o.properties)}function _r(n,t,e,o){o=o===void 0?Yt:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ie(n[1]),a=ie(e),l=i*Math.cos(a);let u=s+l;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);const h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),g=Math.abs(h)>1e-11?l/h:Math.cos(s),c=i*Math.sin(a)/g;return[((r+c)*180/Math.PI+540)%360-180,u*180/Math.PI]}function Tr(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Xn(n);case"FeatureCollection":return Er(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ke(n);default:throw new Error("unknown GeoJSON type")}}function Xn(n){const t={type:"Feature"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=n[e]}}),t.properties=Hn(n.properties),n.geometry==null?t.geometry=null:t.geometry=Ke(n.geometry),t}function Hn(n){const t={};return n&&Object.keys(n).forEach(e=>{const o=n[e];typeof o=="object"?o===null?t[e]=null:Array.isArray(o)?t[e]=o.map(i=>i):t[e]=Hn(o):t[e]=o}),t}function Er(n){const t={type:"FeatureCollection"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=n[e]}}),t.features=n.features.map(e=>Xn(e)),t}function Ke(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>Ke(e)),t):(t.coordinates=Yn(n.coordinates),t)}function Yn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Yn(e))}function Mn(n,t,e){if(e=e||{},!Zo(e))throw new Error("options is invalid");const o=e.pivot,i=e.mutate;if(!n)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("angle is required");if(t===0)return n;const r=o??qn(n);return(i===!1||i===void 0)&&(n=Tr(n)),Pe(n,function(s){const l=zr(r,s)+t,u=Sr(r,s),h=Vr(Dr(r,u,l));s[0]=h[0],s[1]=h[1]}),n}function $n(n,t,e={}){if(e.final===!0)return Ar(n,t);const o=se(n),i=se(t),r=ie(o[0]),s=ie(i[0]),a=ie(o[1]),l=ie(i[1]),u=Math.sin(s-r)*Math.cos(l),h=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-r);return Cn(Math.atan2(u,h))}function Ar(n,t){let e=$n(t,n);return e=(e+180)%360,e}function Br(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return Pe(n,o=>{e[0]>o[0]&&(e[0]=o[0]),e[1]>o[1]&&(e[1]=o[1]),e[2]<o[0]&&(e[2]=o[0]),e[3]<o[1]&&(e[3]=o[1])}),e}function Ir(n,t={}){const e=Number(n[0]),o=Number(n[1]),i=Number(n[2]),r=Number(n[3]);if(n.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[e,o];return kn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function kr(n){return Ir(Br(n))}function Cr(n){return Jo(n,(t,e)=>t+Lr(e),0)}function Lr(n){let t=0,e;switch(n.type){case"Polygon":return Vn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=Vn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function Vn(n){let t=0;if(n&&n.length>0){t+=Math.abs(zn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(zn(n[e]))}return t}var Rr=Yt*Yt/2,He=Math.PI/180;function zn(n){const t=n.length-1;if(t<=2)return 0;let e=0,o=0;for(;o<t;){const i=n[o],r=n[o+1===t?0:o+1],s=n[o+2>=t?(o+2)%t:o+2],a=i[0]*He,l=r[1]*He,u=s[0]*He;e+=(u-a)*Math.sin(l),o++}return e*Rr}function Or(n){const t=Mr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=qn(t),o=Ko(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=$n(o[s],o[s+1]),l=Mn(t,-1*a,{pivot:e}),u=kr(l),h=Cr(u);h<i&&(i=h,r=Mn(u,a,{pivot:e}))}return r}function Sn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Fr(n){let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const[r,s]of n)r<t&&(t=r),r>e&&(e=r),s<o&&(o=s),s>i&&(i=s);return[(e+t)*.5,(i+o)*.5]}class Ie extends En{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new y.Vector3);const t=this.halfSize.clone().multiplyScalar(2),e=new y.Mesh(new y.BoxGeometry(t.x,t.y,t.z));return e.position.copy(this.center),e.rotation.setFromQuaternion(fe),e}getBoxEdge(t=16776960){const e=this.getBoxMesh();Nr.setFromObject(e);const o=new y.EdgesGeometry(e.geometry.clone().applyMatrix4(e.matrixWorld));return new y.LineSegments(o,new y.LineBasicMaterial({color:t,toneMapped:!1}))}toJson(){return le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new y.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:fe.toArray()}}static from(t,e,o,i=new Ie){if(o instanceof y.Euler)fe.setFromEuler(o);else if(o instanceof y.Quaternion)fe.copy(o);else throw new Error("传入的旋转不是欧拉角或者四元数");return le.compose(e,fe,Wr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(t,e,o,i=new Ie){const r=Or({type:"Polygon",coordinates:[t.map(m=>[m.x,m.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Sn(s[0],s[1]),l=Sn(s[1],s[2]),u=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Ee.set(a,l,o),vn.set(0,0,u);const[h,g]=Fr(s);return e.x=h,e.y=g,this.from(Ee,e,vn,i)}}const le=new y.Matrix4,fe=new y.Quaternion,vn=new y.Euler,Wr=new y.Vector3(1,1,1),Ee=new y.Vector3,Nr=new y.Box3;function qr(n,t,e=.005,o=.2){if(!n.length||!t.length)return 0;const i=Math.max(e,.03),r=e*e,s=new Map,a=(g,c,m)=>`${Math.floor(g/i)},${Math.floor(c/i)},${Math.floor(m/i)}`;for(const g of t){const c=a(g.x,g.y,g.z);s.has(c)||s.set(c,[]),s.get(c).push(g)}let l=0;const u=Math.ceil(e/i)+1,h=[];for(let g=-u;g<=u;g++)for(let c=-u;c<=u;c++)for(let m=-u;m<=u;m++)g*g+c*c+m*m<=u*u&&h.push([g,c,m]);for(const g of n){const c=Math.floor(g.x/i),m=Math.floor(g.y/i),w=Math.floor(g.z/i);let x=!1;for(const[P,M,d]of h){const f=`${c+P},${m+M},${w+d}`;if(s.has(f)){for(const p of s.get(f))if(g.distanceToSquared(p)<r){x=!0;break}if(x)break}}if(x&&(l++,l/n.length>o))return l/n.length}return l/n.length}function pe(n,t,e=.5){let o=0,i=0;for(const r of n)if(t.containsPoint(r)&&(o++,i=o/n.length,i>e))break;return i}function Ye(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=we(n,o),s=we(t,e);if(r||s)return!0}return!1}function Dn(n,t){const e=new y.Vector3,o=new y.Vector3;n.getSize(e),t.getSize(o);const i=e.x*e.y*e.z,r=o.x*o.y*o.z;return i>r?1:i<r?-1:0}function we(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function _n(n){if(n.length===0)return{x:0,y:0,z:0,h:0};let t=0,e=0,o=-1/0,i=1/0;for(const r of n)t+=r.x,e+=r.y,o=Math.max(o,r.z),i=Math.min(i,r.z);return{x:t/n.length,y:e/n.length,z:0,maxz:o,minz:i,h:o-i}}function Tn(n,t,e,o){const i=[];for(let s=0;s<n.length;s++)i.push(new y.Vector3(n[s][0],n[s][1],0));if(i.length==0)return null;const r=Ie.fromByPath2D(i,t,e);return r.center.z=o,r}const Xr=n=>{if(n.length==0)return[];const t=[],e=new Map;for(let r=0;r<n.length;r++){let s=n[r].points.map(P=>[P.x,P.y]),a=n[r].obj_id;a=a.replace(/calcony railing/g,"balcony railing").replace(/glass balcony railing/g,"balcony railing").replace(/metal balcony railing/g,"balcony railing").replace(/temporary construction guardrail/g,"balcony railing").replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor"),a.split("_").slice(1,3).join("_").split(".")[0].split("_")[0];const l=a.indexOf("_")+1,u=a.lastIndexOf("_"),h=a.substring(l,u);if(h==="wall")continue;let g=[];for(let P=0;P<n[r].points.length;P++)g.push(new y.Vector3(n[r].points[P].x,n[r].points[P].y,n[r].points[P].z));let c=-99999;if(h==="floor"){let P=new Map;for(let d=0;d<n[r].points.length;d++){let f=n[r].points[d].z;if(f=Math.floor(f*10)/10,P.has(f)){const p=P.get(f);p.num+=1,p.points.push(n[r].points[d]),P.set(f,p)}else P.set(f,{num:1,points:[n[r].points[d]]})}let M=[...P.entries()].reduce((d,f)=>f[1].num>d[1].num?f:d);s=[],s=M[1].points.map(d=>[d.x,d.y]),g=[],g=M[1].points.map(d=>new y.Vector3(d.x,d.y,d.z)),c=M[0]}const m=_n(g),w={points:g,path:Ge(s),h:m.h,minz:m.minz,maxz:m.maxz,center:{x:m.x,y:m.y,z:m.z},obj_id:n[r].obj_id,type:h,averagePz:n[r].averagePz,obb:null,isDel:!1,obj_id:a,positionArr:[n[r].position]};if(w.obb=Tn(w.path,w.center,w.h,(w.maxz+w.minz)/2),w.obb==null)continue;let x=-1;for(let P=0;P<t.length;P++)if(t[P].type==h){x=P;break}if(x!=-1?t[x].array.push(w):t.push({type:h,array:[w]}),h=="floor"&&c!=-99999)if(e.has(c)){const P=e.get(c);P.num+=w.points.length,P.datas.push(w),e.set(c,P)}else e.set(c,{num:w.points.length,datas:[w]})}let o=-1/0;if(e.size>0){let r=[];for(const[s,a]of e.entries()){const{num:l,datas:u}=a;l>3e3&&(s>o&&(o=s),r.push(...u))}for(let s=0;s<t.length;s++)if(t[s].type=="floor"){t[s].array=r;break}}for(let r=0;r<t.length;r++){const s=t[r].array,a=[],l=[];for(let h=0;h<s.length;h++){if(s[h].obb==null||a.includes(h))continue;const g={...s[h],obb:s[h].obb.clone()};for(let c=h+1;c<s.length;c++){if(s[c].obb==null||a.includes(c))continue;if(g.obb.intersectsOBB(s[c].obb)){a.push(c);for(let P=0;P<s[c].points.length;P++)(s[c].points[P].z>o&&s[c].points[P].z-o>.1||g.type=="floor")&&g.points.push(s[c].points[P]);const w=g.points.map(P=>[P.x,P.y]);g.path=Ge(w);const x=_n(g.points);g.h=x.h,g.minz=x.minz,g.maxz=x.maxz,g.center={x:x.x,y:x.y,z:x.z},g.obb=Tn(g.path,g.center,g.h,(g.maxz+g.minz)/2),g.positionArr.push(...s[c].positionArr),c=h}}g.path.length>s[h].path.length&&(a.push(h),l.push(g))}const u=[];for(let h=0;h<s.length;h++)a.includes(h)||u.push(s[h]);u.push(...l),t[r].array=u}for(let r=0;r<t.length;r++){const s=t[r].type;if(s==="people"||s==="floor")continue;const a=t[r].array;for(let l=0;l<a.length;l++){const u=a[l].obb,h=a[l].minz;a[l].maxz;const g=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const c=new y.Vector3;u.getSize(c);const m=[c.x,c.y,c.z];let w=0;for(const x of m)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let c=r+1;c<t.length;c++){const m=t[c].type;if(m==="people"||m==="floor")continue;const w=t[c].array;for(let x=0;x<w.length;x++){if(w[x].isDel)continue;const P=w[x].obb,M=w[x].minz;if(w[x].maxz,u.intersectsOBB(P)){pe(w[x].points,u);const d=pe(a[l].points,P),f=Dn(u,P);if(d>=.3&&f==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(m==="balcony railing"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(m==="balcony railing"&&we(P,a[l].points)){a[l].isDel=!0;break}if(m==="balcony railing"&&Ye(u,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-g)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(m==="window"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(m==="window"&&we(P,a[l].points)){a[l].isDel=!0;break}if(m==="window"&&Ye(u,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-g)>.3)){a[l].isDel=!0;break}}let p=!1,b=[],V=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(p=!0,b=v,V=S):(b=S,V=v),qr(V,b,.03,.5)>.5)if(p)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(Ye(u,P)){const D=Dn(u,P);if(D===1||D===0){if(m==="switch")continue;v.length>S.length?pe(V,u)>=.5&&(w[x].isDel=!0):pe(b,u)>=.5&&(w[x].isDel=!0)}else{if(s==="switch")continue;if(v.length>S.length){if(pe(b,P)>=.5){a[l].isDel=!0;break}}else if(pe(V,P)>=.5){a[l].isDel=!0;break}}}}}}if(a[l].isDel)break}}}for(let r=0;r<t.length;r++){const s=t[r].type,a=t[r].array;for(let l=0;l<a.length;l++){let u=a[l].maxz,h=a[l].minz,g=s==="switch"?.1:.3;const c=a[l].averagePz;if(Math.abs(u-c)<g){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const m=Math.abs(u-c),w=Math.abs(h-c);(s==="tv"&&w<1.6||s!=="window"&&m<1.6)&&(a[l].isDel=!0),s==="window"&&m<1&&(a[l].isDel=!0)}if(s==="chair"){const m=new y.Vector3;a[l].obb.getSize(m),(m.x<.1||m.y<.1||m.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(u-h)<.4&&(a[l].isDel=!0),(h<c&&Math.abs(h-c)>1||h>c&&Math.abs(h-c)>1)&&(a[l].isDel=!0),u<c&&(a[l].isDel=!0)),s==="people"&&(Math.abs(u-h)<1&&(a[l].isDel=!0),h>c&&h-c>.3&&(a[l].isDel=!0),u<c&&(a[l].isDel=!0)),s==="floor"&&a[l].points.length<500&&(a[l].isDel=!0)}}for(let r=0;r<t.length;r++)t[r].array=t[r].array.filter(s=>!s.isDel);const i=[];for(let r=0;r<t.length;r++){const s=t[r].array;for(let a=0;a<s.length;a++)i.push({obbBox:s[a].obb,box:new y.Box3().setFromPoints(s[a].points),category:s[a].type,center:{x:s[a].center.x,y:s[a].center.y,z:(s[a].minz+s[a].maxz)/2},name:s[a].obj_id,obj_id:s[a].obj_id,pcdPoints:s[a].points,positionArr:s[a].positionArr})}return i};function be(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Hr(n){let t=0,e=0,o=0;for(let i=0;i<4;i++){const r=n[i],s=n[(i+1)%4],a=s.x-r.x,l=s.y-r.y,u=Math.sqrt(a*a+l*l);u>t&&(t=u,e=a/u,o=l/u)}return{longSide:t,dirX:e,dirY:o}}function Qe(n,t,e){const i=[];for(const r of n){const s=(r.start.x+r.end.x)/2,a=(r.start.y+r.end.y)/2,l=s-t,u=a-e;l*l+u*u<=3*3&&i.push(r.start.z,r.end.z)}if(i.length===0){const r=[];for(const s of n)r.push(s.start.z,s.end.z);return r.length?(r.sort((s,a)=>s-a),r[Math.floor(r.length/2)]):-1/0}return i.sort((r,s)=>r-s),i[Math.floor(i.length/2)]}function Gn(n,t,e,o,i,r){const s=i-e,a=r-o,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((n-e)**2+(t-o)**2),t:0};const u=n-e,h=t-o,g=(u*s+h*a)/l,c=e+g*s,m=o+g*a;return{dist:Math.sqrt((n-c)**2+(t-m)**2),t:g}}function Yr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((be(n.start,s.start)<=e||be(n.start,s.end)<=e)&&o++,(be(n.end,s.start)<=e||be(n.end,s.end)<=e)&&i++);let r=0;return o>=1&&i>=1?r=5:(o>=1||i>=1)&&(r=2),{left:o,right:i,score:r}}function $r(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Gn(a.x,a.y,o.x,o.y,i.x,i.y);e.push(l)}const r=e.reduce((a,l)=>a+l,0)/e.length,s=e.reduce((a,l)=>a+(l-r)**2,0)/e.length;return s<.01?3:s<.05?2:s<.1?1:0}function Gr(n,t,e=.15){const o=n.end.x-n.start.x,i=n.end.y-n.start.y,r=Math.sqrt(o*o+i*i);if(r<1e-12)return 0;const s=-i/r,a=o/r,l=[[],[]];for(let g=0;g<2;g++){const c=g===0?n.start:n.end;for(const m of t){if(m===n)continue;const w=be(c,m.start),x=be(c,m.end);let P=null;if(w<=e?P=m.end:x<=e&&(P=m.start),!P)continue;const M=m.end.x-m.start.x,d=m.end.y-m.start.y,f=Math.sqrt(M*M+d*d);if(f<1e-12||Math.abs(o*M+i*d)/(r*f)>=.342)continue;const b=(P.x-c.x)*s+(P.y-c.y)*a;l[g].push(b>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const u=[...l[0],...l[1]];return u.every(g=>g===u[0])?2:1}function jr(n,t,e){const o=Yr(n,e),i=$r(n,t),r=Gr(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function Ur(n){const t=n.end.x-n.start.x,e=n.end.y-n.start.y;let o=Math.atan2(e,t)*(180/Math.PI);return o<0&&(o+=180),o}function Zr(n,t){const e=[];for(const o of n){let i=!1;for(const r of e){const s=Math.abs(o.angle-r[0].angle);if(Math.min(s,180-s)<=t){r.push(o),i=!0;break}}i||e.push([o])}return e}function Kr(n,t=.05){const e=[];for(const o of n){let i=!1;for(const r of e)if(Math.abs(o.offset-r[0].offset)<=t){r.push(o),i=!0;break}i||e.push([o])}return e}function Qr(n,t,e,o,i){const r=[];for(const a of n){const l=a.seg,u=(l.start.x-t.start.x)*e+(l.start.y-t.start.y)*o,h=(l.end.x-t.start.x)*e+(l.end.y-t.start.y)*o;r.push({l:Math.min(u,h),r:Math.max(u,h),idx:a.idx})}r.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:u}of r){if(s.length===0){s.push({l:a,r:l,srcIdxs:[u]});continue}const h=s[s.length-1];a<=h.r+i?(h.r=Math.max(h.r,l),h.srcIdxs.includes(u)||h.srcIdxs.push(u)):s.push({l:a,r:l,srcIdxs:[u]})}return s}function Jr(n,t,e,o,i,r,s){const a=e-t,l={...n};return l.start={x:n.start.x+t*o,y:n.start.y+t*i,z:n.start.z},l.end={x:n.start.x+e*o,y:n.start.y+e*i,z:n.start.z},l.length=a,l.direction={x:o,y:i,z:0},l.rooftopPz=r,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function ti(n,t){let e=!0;for(;e;){e=!1;for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o],s=n[i];if(r.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(r.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(r.end.x-s.start.x)<.001&&Math.abs(r.end.y-s.start.y)<.001,l=Math.abs(r.start.x-s.end.x)<.001&&Math.abs(r.start.y-s.end.y)<.001,u=Math.abs(r.end.x-s.end.x)<.001&&Math.abs(r.end.y-s.end.y)<.001,h=Math.abs(r.start.x-s.start.x)<.001&&Math.abs(r.start.y-s.start.y)<.001;if(!(a||l||u||h)||r.direction.x*s.direction.x+r.direction.y*s.direction.y<.98)continue;let c=r.start,m=r.end;a?m=s.end:l?c=s.start:u?m=s.start:h&&(c=s.end);const w=Math.hypot(m.x-c.x,m.y-c.y),x={...r};x.start=c,x.end=m,x.length=w,x.direction={x:(m.x-c.x)/w,y:(m.y-c.y)/w,z:0},x.rooftopPz=r.rooftopPz!==void 0?r.rooftopPz:s.rooftopPz,x.buildRosource=r.buildRosource||s.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),n[o]=x,t[o]=[...new Set([...t[o],...t[i]])],n.splice(i,1),t.splice(i,1),i--,e=!0}}return{segments:n,sourceMap:t}}function Je(n,t=5,e=.05){if(n.length<=1)return{segments:n,sourceMap:n.map((l,u)=>[u])};const o=n.map((l,u)=>({seg:l,angle:Ur(l),idx:u}));o.sort((l,u)=>l.angle-u.angle);const i=Zr(o,t),r=[],s=[],a=[];for(const l of i){let u=l[0].seg;for(const M of l)M.seg.length>u.length&&(u=M.seg);const h=u.end.x-u.start.x,g=u.end.y-u.start.y,c=Math.sqrt(h*h+g*g);if(c<1e-12)continue;const m=-g/c,w=h/c,x=l.map(M=>{const d=M.seg.start.x-u.start.x,f=M.seg.start.y-u.start.y;return{seg:M.seg,offset:Math.abs(d*m+f*w),idx:M.idx}});x.sort((M,d)=>M.offset-d.offset);const P=Kr(x);for(const M of P){let d=M[0].seg;for(const T of M)T.seg.length>d.length&&(d=T.seg);const f=d.end.x-d.start.x,p=d.end.y-d.start.y,b=Math.sqrt(f*f+p*p);if(b<1e-12)continue;const V=f/b,v=p/b,S=M.map(T=>T.seg.rooftopPz??0),z=Math.max(...S),D=[...new Set(S.map(T=>T.toFixed(3)))];if(D.length>1){const T=M.map(E=>({idx:E.idx,start:{x:E.seg.start.x,y:E.seg.start.y,z:E.seg.start.z},end:{x:E.seg.end.x,y:E.seg.end.y,z:E.seg.end.z},length:E.seg.length,rooftopPz:E.seg.rooftopPz??0}));a.push({values:[...D],segments:T})}[...new Set(M.map(T=>String(T.seg.buildRosource)))];const _=Qr(M,d,V,v,e);for(const{l:T,r:E,srcIdxs:A}of _){if(E-T<.01)continue;const F=Jr(d,T,E,V,v,z,d.buildRosource);r.push(F),s.push(A)}}}return{...ti(r,s),debugRPZGroups:a}}function ei(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function ni(n,t,e){return[{x:t,y:e,z:0},{x:n[0].x,y:n[0].y,z:0},{x:n[1].x,y:n[1].y,z:0},{x:n[2].x,y:n[2].y,z:0},{x:n[3].x,y:n[3].y,z:0}]}function oi(n,t,e,o,i,r,s){const a=[{margin:r.projectionMargin,maxDist:r.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const u of a){if(l.length>0)break;for(const h of n){const g=t*r.minLengthRatio;if(h.length<g)continue;const{start:c,end:m}=h;let w=!1,x=1/0;for(const S of i){const{dist:z,t:D}=Gn(S.x,S.y,c.x,c.y,m.x,m.y);D>=-u.margin&&D<=1+u.margin&&z<=u.maxDist&&(w=!0,x=Math.min(x,z))}if(!w){`${u.maxDist}${(-u.margin).toFixed(1)}${(1+u.margin).toFixed(1)}`;continue}const P=Math.sqrt((m.x-c.x)**2+(m.y-c.y)**2);if(P<1e-12)continue;const M=(m.x-c.x)/P,d=(m.y-c.y)/P,f=Math.abs(e*M+o*d),p=Math.abs(-o*M+e*d),b=Math.max(f,p),V=Math.acos(Math.min(b,1))*(180/Math.PI);if(V>r.angleThreshold){`${V.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(P>.01){const S=[];for(let _=1;_<=4;_++){const T=i[_],E=T.x-c.x,A=T.y-c.y,F=(E*M+A*d)/P;S.push(F)}const z=Math.min(...S),D=Math.max(...S);D>z&&(v=Math.max(0,Math.min(1,D)-Math.max(0,z))/(D-z))}l.push({seg:h,minDist:x,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function ri(n,t,e,o){if(n.length<=1)return n.length===1&&(n[0].score=-1),n;for(const i of n){const{score:r,details:s}=jr(i.seg,t,e);i.score=r,i.details=s}return n.sort((i,r)=>r.embedRatio-i.embedRatio||r.score-i.score||i.minDist-r.minDist),n}function ii(n,t,e,o){const i=n.end.x-n.start.x,r=n.end.y-n.start.y,s=Math.sqrt(i*i+r*r),a=i/s,l=r/s,u=t.map(v=>{const S=v.x-n.start.x,z=v.y-n.start.y;return(S*a+z*l)/s}),h=Math.min(...u),g=Math.max(...u),c=(g-h)*s,m=(h+g)/2,w=n.start.x+m*i,x=n.start.y+m*r,P=e.box.min.z,M=e.box.max.z,d=Math.abs(M-P),f=Qe(o,n.start.x,n.start.y),p=Math.max(0,P-f),b=h<=0&&g>=1,V=n.start.z+m*(n.end.z-n.start.z);return{p:{x:w,y:x,z:V},width:c,full:b,height:d,groundClearance:p}}function jn(n,t,e){var h,g,c,m,w;const o=t.map(x=>e[x]),i=[],r=[],s=[],a=[],l=[];let u;for(const x of o){if((h=x.points)!=null&&h.length)for(const P of x.points)i.push(P);if((g=x.originalPoints)!=null&&g.length)for(const P of x.originalPoints)r.push(P);if((c=x.doorAndBeamData)!=null&&c.length)for(const P of x.doorAndBeamData)s.push(P);if((m=x.insetionArr)!=null&&m.length)for(const P of x.insetionArr)a.push(P);if((w=x.drawWindow)!=null&&w.length)for(const P of x.drawWindow)l.push(P);x.boxData&&!u&&(u=x.boxData)}i.length&&(n.points=i),r.length&&(n.originalPoints=r),s.length&&(n.doorAndBeamData=s),a.length&&(n.insetionArr=a),l.length&&(n.drawWindow=l),u&&(n.boxData=u)}function Un(n,t,e,o){var u;const i=ei(e),r=[],{segments:s,sourceMap:a}=o??Je(t),l=s;for(const h of n){const g=(u=h.coordinatesByArea)==null?void 0:u.coordinates;if(!g||g.length<4)continue;const c=g.slice(0,4),m=c.reduce((D,_)=>D+_.x,0)/4,w=c.reduce((D,_)=>D+_.y,0)/4,{longSide:x,dirX:P,dirY:M}=Hr(c);if(x<.01)continue;const d=c.reduce((D,_)=>D+_.z,0)/4,f=Qe(t,m,w);if(d<f-.3)continue;const p=ni(c,m,w);h.name;let b=oi(l,x,P,M,p,i,h.name);b=ri(b,p,t,h.name);let V=null,v=1/0,S=0;if(b.length>0){const D=b[0];V=D.seg,v=D.minDist,S=D.ratio}let z;if(V&&(z=ii(V,c,h,s),!i.printOnly)){const D=V;D.drawWindow||(D.drawWindow=[]),D.drawWindow.push(z)}V&&r.push({windowName:h.name,windowCategory:h.category,windowCenter:h.center,wallSegment:V,distance:v,wallLengthRatio:S,drawWindow:z})}for(const h of r){const g=h.wallSegment,c=s.indexOf(g);if(c===-1)continue;const m=a[c];!m||m.length<=1||jn(g,m,t)}return r}function si(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],{segments:r,sourceMap:s}=Je(n),a=Un(i,n,o,{segments:r,sourceMap:s}),l=new Set;for(const c of a){const m=r.indexOf(c.wallSegment);m>=0&&l.add(m)}const u=[],h=new Set;for(const c of l){const m=s[c];if(m){jn(r[c],m,n);for(const w of m)h.add(w)}u.push(r[c])}for(let c=0;c<n.length;c++)h.has(c)||u.push(n[c]);const g=new Set(a.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(g.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of a)c.drawWindow&&c.wallSegment&&(c.wallSegment.drawWindow||(c.wallSegment.drawWindow=[]),c.wallSegment.drawWindow.push(c.drawWindow));return{segments:u,matches:a}}exports.computeContour=Ge;exports.computeLocalFloorZ=Qe;exports.findWindowWalls=Un;exports.getAllGeometry=mo;exports.getBeamLine=Vo;exports.getColLine=zo;exports.getMergeMeaning=Xr;exports.mergeCollinearSegments=Je;exports.processData=si;exports.updateStEdPoint=go;
1
+ "use strict";var Zn=Object.defineProperty;var Kn=(n,t,e)=>t in n?Zn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Oe=(n,t,e)=>Kn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function Qn(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const x=Qn(lt);function Jn(n,t=!1){const e=n[0].index!==null,o=new Set(Object.keys(n[0].attributes)),i=new Set(Object.keys(n[0].morphAttributes)),r={},s={},a=n[0].morphTargetsRelative,l=new lt.BufferGeometry;let c=0;for(let h=0;h<n.length;++h){const d=n[h];let u=0;if(e!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!o.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;r[f]===void 0&&(r[f]=[]),r[f].push(d.attributes[f]),u++}if(u!==o.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!i.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[f]===void 0&&(s[f]=[]),s[f].push(d.morphAttributes[f])}if(t){let f;if(e)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,f,h),c+=f}}if(e){let h=0;const d=[];for(let u=0;u<n.length;++u){const f=n[u].index;for(let w=0;w<f.count;++w)d.push(f.getX(w)+h);h+=n[u].attributes.position.count}l.setIndex(d)}for(const h in r){const d=tn(r[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in s){const d=s[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let u=0;u<d;++u){const f=[];for(let y=0;y<s[h].length;++y)f.push(s[h][y][u]);const w=tn(f);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(w)}}return l}function tn(n){let t,e,o,i=-1,r=0;for(let c=0;c<n.length;++c){const h=n[c];if(t===void 0&&(t=h.array.constructor),t!==h.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=h.itemSize),e!==h.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(o===void 0&&(o=h.normalized),o!==h.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=h.gpuType),i!==h.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=h.count*e}const s=new t(r),a=new lt.BufferAttribute(s,e,o);let l=0;for(let c=0;c<n.length;++c){const h=n[c];if(h.isInterleavedBufferAttribute){const d=l/e;for(let u=0,f=h.count;u<f;u++)for(let w=0;w<e;w++){const y=h.getComponent(u,w);a.setComponent(u+d,w,y)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const to=(n,t,e)=>{let o=new x.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(n),i.push(t);let r=new x.BufferGeometry;r.setFromPoints(i),r.rotateX(-Math.PI/2),e.add(new x.Line(r,o))},te=(n,t,e,o,i=1e-8)=>{const r=t.x-n.x,s=t.y-n.y,a=o.x-e.x,l=o.y-e.y,c=r*l-s*a;if(Math.abs(c)<i)return null;const h=((e.x-n.x)*l-(e.y-n.y)*a)/c,d=((e.x-n.x)*s-(e.y-n.y)*r)/c;return h<-i||h>1+i||d<-i||d>1+i?null:{point:new x.Vector3(n.x+h*r,n.y+h*s,n.z)}},eo=(n,t,e={})=>{const{fontSize:o=36,fontFamily:i="sans-serif",backgroundColor:r="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=e,h=document.createElement("canvas").getContext("2d");h.font=`bold ${o}px ${i}`;const u=h.measureText(n).width;let f=Math.min(u+a*2,l),w=o+a*2;const y=document.createElement("canvas");y.width=f,y.height=w;const M=y.getContext("2d");M.fillStyle=r,M.fillRect(0,0,f,w),M.fillStyle=s,M.font=`bold ${o}px ${i}`,M.textAlign="center",M.textBaseline="middle",u>l-a*2?no(M,n,f/2,w/2,l,o):M.fillText(n,f/2,w/2);const P=new x.CanvasTexture(y),g=new x.SpriteMaterial({map:P,depthTest:!1,transparent:!0}),m=new x.Sprite(g);m.position.set(t.x,t.y,t.z);const p=.005;return m.scale.set(f*p,w*p,1),m};function no(n,t,e,o,i,r){const s=t.split("");let a="",l=r*1.2,c=o;for(let h=0;h<s.length;h++){const d=a+s[h];n.measureText(d).width>i&&h>0?(n.fillText(a,e,c),a=s[h],c+=l):a=d}n.fillText(a,e,c)}const oe=(n,t,e=.01)=>{const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(o<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const r={x:n.x/o,y:n.y/o,z:n.z/o},s={x:t.x/i,y:t.y/i,z:t.z/i};let a=r.x*s.x+r.y*s.y+r.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),c=l<=e;return{parallel:c,sameDirection:c?a>0:null,angle:l}},oo=(n,t,e,o)=>{const i=n;let r=[];if(o&&o.length&&(r=o.map(z=>z.clone())),!i||i.length<4)return{};const s=new x.Vector3().subVectors(i[1],i[0]).normalize(),a=new x.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let c=1/0,h=-1/0,d=1/0,u=-1/0;for(const z of i){const v=z.dot(s),S=z.dot(a);v<c&&(c=v),v>h&&(h=v),S<d&&(d=S),S>u&&(u=S)}const f=i[0].dot(l),w=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),y=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),M=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(f)),P=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(f));let g=[w,y,M,P],m=oe(new x.Vector3().subVectors(w,y),new x.Vector3(0,0,1));m&&m.parallel&&(g=[w,P,M,y]);let p=0;if(o.length>0){const z=new x.Vector3().subVectors(g[1],g[0]).normalize(),v=z.clone().negate(),S=new x.Vector3().subVectors(g[3],g[0]).normalize(),V=S.clone().negate();let D=g[0].distanceTo(g[1]),_=g[0].distanceTo(g[3]),E=D/t,T=_/e,A=.001;for(let O=0;O<E;O++){let I=g[0],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(z,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new x.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[0]=g[0].addScaledVector(z,t),g[3]=g[3].addScaledVector(z,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<E;O++){let I=g[1],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(v,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new x.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[1]=g[1].addScaledVector(v,t),g[2]=g[2].addScaledVector(v,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<T;O++){let I=g[3],B=0;for(let L=0;L<E;L++){let N=I.clone().addScaledVector(z,t),C=N.clone().addScaledVector(V,e),R=I.clone().addScaledVector(V,e),$=new x.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=N}if(B>=E/2)break;p+=B,g[2]=g[2].addScaledVector(V,e),g[3]=g[3].addScaledVector(V,e)}}const b=g[0].distanceTo(g[1])*g[0].distanceTo(g[3]);return{facePoints:g,boxArea:b,totalInPlaneNum:p}},Jt=(n,t,e,o,i=x.MathUtils.degToRad(8))=>{const r=new x.Vector3,s=new x.Vector3;r.subVectors(new x.Vector3(t.x,t.y,0),new x.Vector3(n.x,n.y,0)).normalize(),s.subVectors(new x.Vector3(o.x,o.y,0),new x.Vector3(e.x,e.y,0)).normalize();const a=r.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),c=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:c,angle:l,angleDeg:x.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},re=(n,t,e,o)=>{const i=new x.Vector3().subVectors(t,n),r=new x.Vector3().subVectors(o,e),s=i.length(),a=r.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),r.normalize();const l=Math.abs(i.dot(r)),c=Math.min(1,Math.max(0,l)),h=Math.acos(c),d=x.MathUtils.radToDeg(h),u=1-c;return{rate:u,percent:`${(u*100).toFixed(2)}%`,angle:d,isPerpendicular:Math.abs(d-90)<.01,isParallel:d<.01}},ee=(n,t,e=!1)=>new x.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),ne=(n,t,e,o,i={})=>{const{parallelAngleMax:r=x.MathUtils.degToRad(10),collinearAngleMax:s=x.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,c=new x.Vector3().subVectors(t,n),h=new x.Vector3().subVectors(o,e),d=c.clone().normalize(),u=h.clone().normalize();let f=x.MathUtils.clamp(d.dot(u),-1,1);const w=Math.acos(Math.abs(f)),y=x.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:y,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};f<0&&u.negate();const M=new x.Vector3().addVectors(d,u).normalize(),P=new x.Vector3().addVectors(n,t).multiplyScalar(.5),g=en(e,P,d),m=en(o,P,d),p=(g+m)/2,b=Math.max(g,m),z=n.dot(M),v=t.dot(M),S=e.dot(M),V=o.dot(M),D=Math.min(z,v),_=Math.max(z,v),E=Math.min(S,V),T=Math.max(S,V),A=_-D,O=T-E,I=Math.min(A,O),B=Math.min(_,T)-Math.max(D,E),L=B<0?-B:0,N=B>0?B:0,C=I>0?N/I:0,R=ro(n,t,e,o),$=w<=s&&p<a;let X;return $?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:y,avgPerpendicularDistance:p,maxPerpendicularDistance:b,gap:L,overlap:N,closestDistance:R}};function en(n,t,e){const o=new x.Vector3().subVectors(n,t),i=o.dot(e),r=e.clone().multiplyScalar(i);return new x.Vector3().subVectors(o,r).length()}function ro(n,t,e,o){const i=new x.Vector3().subVectors(t,n),r=new x.Vector3().subVectors(o,e),s=new x.Vector3().subVectors(e,n),a=i.dot(i),l=i.dot(r),c=r.dot(r),h=i.dot(s),d=r.dot(s),u=a*c-l*l;let f,w;u<1e-10?(f=0,w=c!==0?d/c:0):(f=(l*d-c*h)/u,w=(a*d-l*h)/u),f=x.MathUtils.clamp(f,0,1),w=c!==0?x.MathUtils.clamp((l*f+d)/c,0,1):0,f=a!==0?x.MathUtils.clamp((l*w-h)/a,0,1):0;const y=n.clone().add(i.clone().multiplyScalar(f)),M=e.clone().add(r.clone().multiplyScalar(w));return y.distanceTo(M)}const nn=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),io=n=>{let t=new x.Vector3(n.start.x,n.start.y,n.start.z),e=new x.Vector3(n.end.x,n.end.y,n.end.z),o=t.distanceTo(e),i=n.rooftopPz-n.start.z,r=nn(o,100),s=nn(i,70),a=i/s,l=new Map;for(let y=0;y<s;y++)l.set((y+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let c=new x.Line3(t,e);const h=n.originalPoints,d=new x.Vector3;for(let y=0;y<h.length;y++){const M=h[y];let g=c.closestPointToPoint(M,!0,d).distanceTo(M);const m=Math.floor(g/a);if(m<s){const p=l.get((m+1)*a);p.count++,M.z<p.minZ&&(p.minZ=M.z),M.z>p.maxZ&&(p.maxZ=M.z)}}let u,f,w=r/2;for(const[y,M]of l)if(M.count>=w){u=M.minZ;break}for(const[y,M]of[...l.entries()].reverse())if(M.count>=w){f=M.maxZ;break}return{minZ:u,maxZ:f}},Ve=(n,t,e)=>{let o=new x.Plane;const i=new x.Vector3(n.x,n.y,n.z),r=new x.Vector3(t.x,t.y,t.z),s=new x.Vector3(t.x,t.y,t.z+5);o.setFromCoplanarPoints(i,r,s);const a=[],l=[];e.forEach(M=>{const P=new x.Vector3;o.projectPoint(M,P),l.push(P.clone()),P.z=i.z,a.push(P)});let c=new x.Vector3,h=new x.Vector3;o.projectPoint(i,c),o.projectPoint(r,h);const d=new x.Line3(c,h),u=[],f=[],w=[];let y=new x.Vector3;return a.forEach((M,P)=>{d.closestPointToPoint(M,!0,y).distanceTo(M)<.001?(u.push(e[P]),f.push(l[P])):w.push(M)}),{newOriginalPoints:u,newProjectPoints:w,newOnLinePoints:f}},so=n=>{function t(e,o,i,r,s,a,l,c,h){let d=new x.Line3(e,o),u=new Map,f=new x.Vector3,w=e.clone(),y=o.clone(),M=0;for(;;){let P=new Map,g=0;for(let m=0;m<h.checkResults.length;m++)if(!(h.checkResults[m].allCenterPoints.length/c*100<1))for(let b=0;b<h.checkResults[m].allCenterPoints.length;b++){if(u.has(m)&&u.get(m).removePtsIndex.includes(b))continue;let z=h.checkResults[m].allCenterPoints[b];z=new x.Vector3(z.x,z.y,z.z);let v=d.closestPointToPoint(z,!0,f),S=z.distanceTo(v);Math.abs(S-s)<.01&&(g++,P.has(m)?P.get(m).removePtsIndex.push(b):P.set(m,{index:m,removePtsIndex:[b]}))}if(M==l){e=w,o=y;break}if(g<a/20*18||g==0){P.clear(),l-M<5&&(e=w,o=y,u.clear());break}else{M++;for(const[m,p]of P)u.has(m)?u.get(m).removePtsIndex.push(...p.removePtsIndex):u.set(m,p);P.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),d.set(e,o)}}if(u.size>0&&M!=l)for(const[P,g]of u){let m=[],p=[];for(let b=0;b<h.checkResults[P].allCenterPoints.length;b++)g.removePtsIndex.includes(b)||(m.push(h.checkResults[P].allCenterPoints[b]),p.push(h.checkResults[P].originalVertices[b]));h.checkResults[P].allCenterPoints=m,h.checkResults[P].originalVertices=p}}for(let e=0;e<n.length;e++){const o=n[e];if(o.length<.5)continue;let i=-1,r=-1;if(!o.checkResults||o.checkResults.length<=0)continue;if(o.checkResults[0].originalVertices&&o.checkResults[0].originalVertices.length>0){const S=o.checkResults[0].originalVertices[0];let[V,D,_,E]=S;V=new x.Vector3(V.x,V.y,V.z),D=new x.Vector3(D.x,D.y,D.z),_=new x.Vector3(_.x,_.y,_.z),E=new x.Vector3(E.x,E.y,E.z),i=V.distanceTo(D),r=V.distanceTo(E);let T=new x.Vector3().subVectors(V,D).normalize(),A=oe(T,new x.Vector3(0,0,1));A&&A.parallel&&([r,i]=[i,r])}if(i<0||r<0)continue;let s=new x.Vector3(o.start.x,o.start.y,o.start.z),a=new x.Vector3(o.end.x,o.end.y,o.end.z);const l=s.distanceTo(a),c=o.rooftopPz-o.start.z,h=Math.ceil(l/i),d=Math.ceil(c/r);let u=s.clone(),f=a.clone(),w=f.clone().add(new x.Vector3(0,0,c)),y=u.clone().add(new x.Vector3(0,0,c)),M=new x.Vector3().subVectors(f,u).normalize(),P=M.clone().negate();new x.Vector3().subVectors(w,u).normalize().clone().negate();let m=i/2,p=l*c,b=i*r,z=p/b;t(u,y,M,i,m,d,h,z,o),t(f,w,P,i,m,d,h,z,o),o.start=u,o.end=f;const{newOriginalPoints:v}=Ve(u,f,o.originalPoints);o.originalPoints=v}},Lt=(n,t)=>new x.Vector3(n.x,n.y,0).distanceTo(new x.Vector3(t.x,t.y,0)),ao=(n,t,e=1e-6)=>{const o=new x.Vector3;return n.closestPointToPoint(t,!0,o),o.distanceTo(t)<e},Se=n=>{let t=0,e=[];for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o].distanceTo(n[i]);r>t&&(t=r,e=[n[o],n[i]])}return e},kt=(n,t,e=.03)=>Math.abs(n.x-t.x)<e&&Math.abs(n.y-t.y)<e&&Math.abs(n.z-t.z)<e,lo=()=>{const n=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),t=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),e=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0");return`#${n}${t}${e}`},co=(n,t=.001)=>{const e=new Map,o=[];for(const i of n){const r=Math.round(i.x/t),s=Math.round(i.y/t),a=Math.round(i.z/t),l=`${r},${s},${a}`;e.has(l)||(e.set(l,!0),o.push(i))}return o};class uo{constructor(){Oe(this,"results");Oe(this,"clusterResults");this.results=null}initLimits1(t,e){let o,i;return t<.3?o=5:t<.5?o=8:t<.8?o=10:t<1?o=15:t<2?o=30:t<3?o=35:t<4?o=40:t<5?o=45:t<6?o=50:t<7?o=60:t<8.5?o=70:t<10?o=80:t<15?o=100:t<20?o=120:t<25?o=140:t<30?o=160:t<35?o=180:t<40?o=200:t<45?o=230:t<50?o=250:o=350,e<1?i=30:e<2?i=40:e<2.5?i=45:e<3?i=60:e<3.6?i=70:e<4&&(i=80),{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits2(t,e){const r=Math.round(Math.max(5,Math.min(350,t/.08))),s=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(t,e){const o=Math.round(Math.max(5,Math.min(350,65*Math.sqrt(t))))*1,i=Math.round(Math.max(30,Math.min(80,15*Math.sqrt(e))))*1;return{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits3(t,e){let o;t<2?o=.06:t<10?o=.1:o=.15;const i=Math.round(Math.max(5,Math.min(350,t/o))),r=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:i,verticalSubdivisions:r}}createWallPlaneMeshFromFourPoints(t,e,o,i,r,s,a=16777215){const l=[t,e,o,i];for(let M=0;M<l.length;M++)this.isValidVector3(l[M])||(console.error(`点${M+1}包含无效数据:`,l[M]),l[M]=new x.Vector3(M,0,M));const c=new x.BufferGeometry,h=new Float32Array([l[0].x,l[0].y,l[0].z,l[1].x,l[1].y,l[1].z,l[2].x,l[2].y,l[2].z,l[3].x,l[3].y,l[3].z]),d=[0,1,2,0,2,3],u=new Float32Array([0,0,1,0,1,1,0,1]);c.setAttribute("position",new x.BufferAttribute(h,3)),c.setAttribute("uv",new x.BufferAttribute(u,2)),c.setIndex(d),c.computeVertexNormals();const f=new x.Mesh(c,r),w=new x.EdgesGeometry(c),y=new x.LineSegments(w,new x.LineBasicMaterial({color:a}));return s.add(y),f}createSubdividedWallPlane(t,e,o,i,r){const s=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return s;const a=new x.Vector3(t.start.x,t.start.y,t.start.z),l=new x.Vector3(t.end.x,t.end.y,t.end.z),c=new x.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new x.Vector3(t.start.x,t.start.y,t.rooftopPz),d=[a,l,c,h];for(let g=0;g<d.length;g++)if(!this.isValidVector3(d[g]))return console.error(`墙体基础点${g}无效:`,d[g]),s;const u=a.distanceTo(l),f=Math.abs(t.rooftopPz-t.start.z);if(u===0||f===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",l),console.log(t.length),s;const w=u/o,y=f/e,M=new x.Vector3().subVectors(l,a).normalize(),P=new x.Vector3(0,0,1);for(let g=0;g<e;g++)for(let m=0;m<o;m++)try{const p=new x.Vector3().copy(a).add(M.clone().multiplyScalar(m*w)).add(P.clone().multiplyScalar(g*y)),b=new x.Vector3().copy(a).add(M.clone().multiplyScalar((m+1)*w)).add(P.clone().multiplyScalar(g*y)),z=new x.Vector3().copy(a).add(M.clone().multiplyScalar((m+1)*w)).add(P.clone().multiplyScalar((g+1)*y)),v=new x.Vector3().copy(a).add(M.clone().multiplyScalar(m*w)).add(P.clone().multiplyScalar((g+1)*y)),S={points:[p,b,z,v],userData:{}};S.userData={type:"wallSegment",row:g,col:m,originalMaterial:i,width:w,height:y},s.push(S)}catch(p){console.error(`创建墙体小平面(${g}, ${m})时出错:`,p)}return s}calculateMinRequiredPoints(t){const i=Math.floor(Math.log1p(t)*.5);return Math.max(1,i)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,o,i){if(e===0)return!1;const r=t.area,s=t.minRequiredPoints,a=t.expectedDensity,l=e/Math.max(r,.001),c=e>=s,h=l>=a*.3;let d=!0;return r<.5&&e>0&&(d=this.checkSmallAreaDistribution(t,o,i)),c&&h&&d}checkSmallAreaDistribution(t,e,o){if(e.length<2)return!0;const i=e.map(l=>o[l]);t.bounds;const r=t.center;let s=0;const a=Math.sqrt(t.area)*.3;return i.forEach(l=>{l.distanceTo(r)<=a&&s++}),s/i.length>=.3}getFailureReason(t,e){const o=t.area,i=t.minRequiredPoints,r=t.expectedDensity,s=e/Math.max(o,.001),a=[];return e===0?a.push("无点"):(e<i&&a.push(`点数不足: ${e}/${i}`),s<r*.3&&a.push(`密度不足: ${s.toFixed(2)}/${r.toFixed(2)}`),o<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((i,r)=>i-r),o=Math.floor(e.length/2);return e.length%2!==0?e[o]:(e[o-1]+e[o])/2}isPointInBoundingBox(t,e,o=.1){return t.x>=e.min[0]-o&&t.x<=e.max[0]+o&&t.y>=e.min[1]-o&&t.y<=e.max[1]+o&&t.z>=e.min[2]-o&&t.z<=e.max[2]+o}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const o=e.attributes.position;if(o.count<3)return null;const i=new x.Vector3().fromBufferAttribute(o,0),r=new x.Vector3().fromBufferAttribute(o,1),s=new x.Vector3().fromBufferAttribute(o,2);i.applyMatrix4(t.matrixWorld),r.applyMatrix4(t.matrixWorld),s.applyMatrix4(t.matrixWorld);const a=new x.Plane;return a.setFromCoplanarPoints(i,r,s),a}analyzePointDistribution(t,e,o=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};const i=performance.now(),r=[];t.forEach(s=>{if(s.userData&&s.userData.type==="wallSegment"){const a=this.getWorldVerticesNew(s.points);if(a.length<4)return;const l=new x.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);s.userData.center=l,s.vertices=a,r.push(s)}}),this.results.totalSegments=r.length;for(const s of r){if(s.vertices.length<4)continue;const a=s.userData.center,l=`row${s.userData.row}_col${s.userData.col}`,[c,h,d,u]=s.vertices,f=new x.Vector3().subVectors(h,c).normalize(),w=new x.Vector3().subVectors(u,c).normalize(),y=c.distanceTo(h),M=c.distanceTo(u),P=new x.Plane;P.setFromCoplanarPoints(c,h,u);const g=y/2,m=M/2;for(let p=0;p<e.length;p++)this.isPointInWallSegmentOptimized(e[p],a,P,c,f,w,y,M,g,m,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(p))}return r.forEach(s=>{const a=`row${s.userData.row}_col${s.userData.col}`,l=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;l>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:s.userData.row,col:s.userData.col,width:s.userData.width,height:s.userData.height,segmentKey:a,vertices:s.vertices,center:s.userData.center,mesh:s,pointCount:l,hasPointsButNotEnough:l>0&&l<1}))}),this.results.analysisTime=performance.now()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,o,i,r,s,a,l,c,h,d){if(Math.abs(o.distanceToPoint(t))>d)return!1;const f=new x.Vector3().subVectors(t,e),w=Math.abs(f.dot(r)),y=Math.abs(f.dot(s));if(w>c&&y>h)return!1;const M=new x.Vector3().subVectors(t,i),P=M.dot(r),g=M.dot(s),m=P>=-d&&P<=a+d,p=g>=-d&&g<=l+d;return m&&p}isPointInWallSegment(t,e,o,i=.1){if(!t.geometry)return!1;try{const r=this.getWorldVertices(t);return r.length<4?!1:this.isPointInRotatedWall(r,e,o,i)}catch(r){return console.error("判断点是否在墙体平面内时出错:",r),!1}}isPointInRotatedWall(t,e,o,i=.1){const[r,s,a,l]=t,c=new x.Plane;if(c.setFromCoplanarPoints(r,s,l),Math.abs(c.distanceToPoint(e))>i)return!1;const d=new x.Vector3().subVectors(s,r).normalize(),u=new x.Vector3().subVectors(l,r).normalize();new x.Vector3().crossVectors(d,u).normalize();const f=new x.Vector3().subVectors(e,r),w=f.dot(d),y=f.dot(u),M=r.distanceTo(s),P=r.distanceTo(l),g=w>=-i&&w<=M+i,m=y>=-i&&y<=P+i;return g&&m&&o.distanceTo(e)<M/2&&o.distanceTo(e)<P/2}getWorldVertices(t){if(t._cachedWorldVertices&&t.matrixWorld.equals(t._cachedMatrixWorld))return t._cachedWorldVertices;const e=t.geometry.getAttribute("position"),o=[];for(let i=0;i<Math.min(4,e.count);i++){const r=new x.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.push(r)}return t._cachedWorldVertices=o,t._cachedMatrixWorld=t.matrixWorld.clone(),o}getWorldVerticesNew(t){const e=[];for(let o=0;o<t.length;o++){const i=t[o].clone();e.push(i)}return e}getWallSegmentBounds(t){if(!t.geometry)return null;const e=t.geometry.getAttribute("position"),o=new x.Box3;for(let i=0;i<e.count;i++){const r=new x.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.expandByPoint(r)}return{min:o.min.toArray(),max:o.max.toArray(),center:o.getCenter(new x.Vector3).toArray(),size:o.getSize(new x.Vector3).toArray()}}highlightEmptySegments(t,e,o,i=1){var d;if(!this.results){console.warn("请先运行分析函数");return}const r=new Map,s=new Map;this.results.missingSegments.forEach(u=>{r.set(u.segmentKey,u),s.has(u.row)||s.set(u.row,new Map),s.get(u.row).set(u.col,{segmentKey:u.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(u=>{if(u.userData&&u.userData.type==="wallSegment"){const f=`row${u.userData.row}_col${u.userData.col}`,w=r.has(f);s.has(u.userData.row)||s.set(u.userData.row,new Map),s.get(u.userData.row).has(u.userData.col)||s.get(u.userData.row).set(u.userData.col,{segmentKey:f,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,f]of r){const w=(d=s.get(f.row))==null?void 0:d.get(f.col);if(w&&!w.visited){const y=[],M=[[f.row,f.col]];for(w.visited=!0;M.length>0;){const[P,g]=M.shift(),m=`row${P}_col${g}`;r.has(m)&&y.push(r.get(m));for(const[p,b]of l){const z=P+p,v=g+b;if(s.has(z)&&s.get(z).has(v)){const S=s.get(z).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,M.push([z,v]))}}}y.length>=i&&a.push(y)}}const c=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((u,f)=>f.length-u.length),highlightedMeshes:h,clusterMaterials:c,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,o,i,r){let s=0;const a=e;let l=!0;for(let y=i;y<=r;y++)t.has(a)&&t.get(a).has(y)||(l=!1);l&&s++;const c=o;let h=!0;for(let y=i;y<=r;y++)t.has(c)&&t.get(c).has(y)||(h=!1);h&&s++;const d=i;let u=!0;for(let y=e;y<=o;y++)t.has(y)&&t.get(y).has(d)||(u=!1);u&&s++;const f=r;let w=!0;for(let y=e;y<=o;y++)t.has(y)&&t.get(y).has(f)||(w=!1);return w&&s++,s/4}calculateClusterQualityScore(t){const r=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+r*.2}calculateStrictClusterBounds(t){var d,u;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(f=>{f.vertices&&f.vertices.length>0&&e.push(...f.vertices)}),e.length===0){const f=[...new Set(t.map(y=>y.row))];return{width:[...new Set(t.map(y=>y.col))].length*(((d=t[0].bounds)==null?void 0:d.width)||1),height:f.length*(((u=t[0].bounds)==null?void 0:u.height)||1)}}const o=Math.min(...e.map(f=>f.x)),i=Math.max(...e.map(f=>f.x)),r=Math.min(...e.map(f=>f.y)),s=Math.max(...e.map(f=>f.y)),a=Math.min(...e.map(f=>f.z)),l=Math.max(...e.map(f=>f.z)),c=Math.abs(i-o),h=Math.max(Math.abs(s-r),Math.abs(l-a));return{width:c,height:h}}createClusterMaterials(t){const e=[],o=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let i=0;i<t;i++){const r=o[i%o.length],s=new x.MeshBasicMaterial({color:r,transparent:!0,opacity:.6,side:x.DoubleSide});e.push(s)}return e}clearHighlights(t){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(e=>{t.remove(e),e.material&&e.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,o)=>{e.mesh&&e.mesh.userData.originalMaterial&&(e.mesh.material=e.mesh.userData.originalMaterial)}),this.clusterResults.highlightedMeshes=[])}getClusterInfo(){return this.clusterResults?{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((t,e)=>({clusterIndex:e,size:t.length,segments:t.map(o=>o.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(t=>t.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(t=>t.length))}:null}restoreOriginalMaterials(t){let e=0;t.traverse(o=>{o.userData&&o.userData.originalMaterial&&(o.material=o.userData.originalMaterial,delete o.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new x.Group;return t.traverse(o=>{if(o.userData&&o.userData.type==="wallSegment"){const i=this.getWorldVertices(o);if(i.length<4)return;const r=new x.Vector3().add(i[0]).add(i[1]).add(i[2]).add(i[3]).multiplyScalar(.25),s=new x.Vector3().subVectors(i[1],i[0]).normalize(),a=new x.Vector3().subVectors(i[3],i[0]).normalize(),l=new x.Vector3().crossVectors(s,a).normalize(),c=new x.ArrowHelper(l,r,.3,16711680),h=new x.ArrowHelper(s,r,.2,65280),d=new x.ArrowHelper(a,r,.2,255);e.add(c),e.add(h),e.add(d)}}),e}printAnalysisResults(){if(!this.results){console.warn("没有可用的分析结果");return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(t=>{}),this.results.pointsInSegments.forEach((t,e)=>{})}isValidVector3(t){return t&&!isNaN(t.x)&&!isNaN(t.y)&&!isNaN(t.z)&&isFinite(t.x)&&isFinite(t.y)&&isFinite(t.z)}mergeWallGroupMeshes(t){const e=[];if(t.traverse(o=>{o.isMesh&&o.geometry&&e.push(o)}),e.length===0)return null;try{const o=e.map(a=>a.geometry);o.forEach((a,l)=>{a.applyMatrix4(e[l].matrixWorld)});const i=Jn(o),r=e[0].material.clone(),s=new x.Mesh(i,r);return s.name="mergedWalls",s}catch(o){return console.error("合并网格时出错:",o),null}}}const ho=n=>{let t={};const e=[],o=[],i=[];return n[0].width,n[0].height,n.forEach(r=>{o.push(...r.vertices),i.push(r.center),e.push(r.vertices)}),t.originalVertices=e,t.allCenterPoints=i,t},fo=n=>{const t=new lt.Vector3().copy(n.start).add(n.end).multiplyScalar(.5),e=new lt.Vector3().subVectors(new lt.Vector3(t.x,t.y,t.z+1),t).normalize(),o=new lt.Vector3(n.direction.x,n.direction.y,0);o.applyAxisAngle(e,Math.PI/2);const i=new lt.Vector3().copy(t).add(o.clone().multiplyScalar(n.length)),r=new lt.Vector3().copy(t).sub(o.clone().multiplyScalar(n.length));return t.z=n.start.z,i.z=n.start.z,r.z=n.start.z,{start:i,end:r,center:t,direction:o}},mo=(n,t,e=!0)=>{let o=[];if(!n)return[];for(let i=0;i<n.length;i++){const r=n[i];if(!r)continue;let s=new x.Vector3(r.start.x,r.start.y,r.start.z);s.applyEuler(new x.Euler(-Math.PI/2,0,0));let a=new x.Vector3(r.end.x,r.end.y,r.end.z);if(a.applyEuler(new x.Euler(-Math.PI/2,0,0)),t.add(eo(String(i),new x.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(r.isBayWindow||r.isWindow)&&e)continue;const l=new lt.Plane().setFromCoplanarPoints(new lt.Vector3(r.start.x,r.start.y,r.start.z),new lt.Vector3(r.end.x,r.end.y,r.end.z),new lt.Vector3(r.start.x,r.start.y,r.rooftopPz)),c=[];r.originalPoints.forEach((v,S)=>{const V=new lt.Vector3;l.projectPoint(v,V),c.push(V)});const h=new lt.Vector3(r.start.x,r.start.y,r.start.z).distanceTo(new lt.Vector3(r.end.x,r.end.y,r.end.z)),d=Math.abs(r.rooftopPz-r.start.z),u=new x.MeshBasicMaterial({color:"red",side:x.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),f=new x.Group,w=new uo,{horizontalSubdivisions:y,verticalSubdivisions:M}=w.initLimits4(h,d),P=w.createSubdividedWallPlane(r,M,y,u,f);w.analyzePointDistribution(P,c,.01);const g=new x.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:x.DoubleSide}),m=w.highlightEmptySegments(P,g,f),p=[];for(const v of m.clusters){const S=ho(v);S&&p.push(S)}const z=fo(r).direction;r.checkResults=p,r.verticalDirection=z,r.originaIndex=i,o.push(r)}return o},go=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(m=>{let p=new x.Vector3(m.x,m.y,0),b=!1;for(let z=0;z<i.length;z++)if(kt(p,i[z],.01)){b=!0;break}b||i.push(p)});const r=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),s=1;let a=new x.Vector3(o.start.x,o.start.y,o.start.z),l=new x.Vector3(o.end.x,o.end.y,o.end.z),c=new x.Vector3().subVectors(l,a).normalize(),h=c.clone().cross(new x.Vector3(0,0,1)).normalize(),d=h.clone().negate(),u=[];const f=[];let w=o.length/r;console.log(w);for(let m=0;m<r;m++){const p=[];p.push(a.clone().addScaledVector(h,s)),p.push(p[0].clone().addScaledVector(c,w)),p.push(p[1].clone().addScaledVector(d,s*2)),p.push(a.clone().addScaledVector(d,w));let b=[];for(let z=0;z<i.length;z++)u.includes(z)||yo(i[z],p)&&(u.push(z),b.push(i[z]));b.length>0&&f.push(xo(b)),a=a.addScaledVector(c,w)}const y=new Float32Array(i.length*3);i.forEach((m,p)=>{y[p*3]=m.x,y[p*3+1]=m.y,y[p*3+2]=m.z});const M=new x.BufferGeometry;M.setAttribute("position",new x.BufferAttribute(y,3)),M.rotateX(-Math.PI/2),t.add(new x.Points(M,new x.PointsMaterial({color:lo(),size:.02})));const[P,g]=Mo(f,{plane:"xy",trimRatio:0});to(P,g,t)}};function on(n,t="xy"){if(t==="xy")return{x:n.x,y:n.y};if(t==="xz")return{x:n.x,y:n.z};if(t==="yz")return{x:n.y,y:n.z};throw new Error(`Unsupported plane: ${t}`)}function po(n,t,e){const o=t.x-n.x,i=t.y-n.y,r=e.x-n.x,s=e.y-n.y;return o*s-i*r}function yo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=on(n,e),i=t.map(a=>on(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],c=i[(a+1)%4],h=po(l,c,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function xo(n){if(!n||n.length===0)return null;const t=new x.Vector3(0,0,0);for(const e of n)Array.isArray(e)?(t.x+=e[0],t.y+=e[1],t.z+=e[2]):(t.x+=e.x,t.y+=e.y,t.z+=e.z);return t.divideScalar(n.length),t}function wo(n){return n instanceof x.Vector3?n.clone():Array.isArray(n)?new x.Vector3(n[0],n[1],n[2]):new x.Vector3(n.x,n.y,n.z)}function bo(n,t="xy"){const e=wo(n);if(t==="xy")return{x:e.x,y:e.y,up:e.z};if(t==="xz")return{x:e.x,y:e.z,up:e.y};if(t==="yz")return{x:e.y,y:e.z,up:e.x};throw new Error(`Unsupported plane: ${t}`)}function rn(n,t,e,o="xy"){if(o==="xy")return new x.Vector3(n,t,e);if(o==="xz")return new x.Vector3(n,e,t);if(o==="yz")return new x.Vector3(e,n,t);throw new Error(`Unsupported plane: ${o}`)}function Po(n,t,e){if(Math.abs(t)<1e-12)return n>=e?{x:1,y:0}:{x:0,y:1};const i=n+e,r=n*e-t*t,s=Math.sqrt(Math.max(0,i*i*.25-r)),a=i*.5+s;let l=t,c=a-n;const h=Math.hypot(l,c);return h<1e-12?{x:1,y:0}:{x:l/h,y:c/h}}function Mo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>bo(B,e));let r=0,s=0,a=0;for(const B of i)r+=B.x,s+=B.y,a+=B.up;r/=i.length,s/=i.length,a/=i.length;let l=0,c=0,h=0;for(const B of i){const L=B.x-r,N=B.y-s;l+=L*L,c+=L*N,h+=N*N}l/=i.length,c/=i.length,h/=i.length;const d=Po(l,c,h),u={x:-d.y,y:d.x},f=[];for(const B of i){const L=B.x-r,N=B.y-s,C=L*d.x+N*d.y,R=L*u.x+N*u.y;f.push({s:C,t:R,up:B.up})}f.sort((B,L)=>B.s-L.s);const w=f.length;let y=Math.floor(w*o),M=Math.ceil(w*(1-o))-1;y=Math.max(0,Math.min(w-1,y)),M=Math.max(0,Math.min(w-1,M));const P=f[y],g=f[M],m=(()=>{const B=f.map(N=>N.t).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),p=(()=>{const B=f.map(N=>N.up).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),b=P.s,z=g.s,v=m,S=m,V=p,D=p,_=r+d.x*b+u.x*v,E=s+d.y*b+u.y*v,T=r+d.x*z+u.x*S,A=s+d.y*z+u.y*S,O=rn(_,E,V,e),I=rn(T,A,D,e);return[O,I]}const Vo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let m=0;m<o.length;m++){const p=o[m];p.isLine2=!0,n.push(p)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const m of n){let p=[];if(!(!m.checkResults||m.checkResults.length<=0)){for(let b=0;b<m.checkResults.length;b++){let D=function(A){for(;V[A]!==A;)V[A]=V[V[A]],A=V[A];return A};const z=m.checkResults[b];if(z.isDoor=!1,!z.originalVertices||z.originalVertices.length==0)continue;const v=[];z.originalVertices.forEach(A=>{let O=[];A.forEach(I=>{O.push(new x.Vector3(I.x,I.y,I.z))}),v.push(O)});const S=v.length,V=Array.from({length:S},(A,O)=>O);for(let A=0;A<S;A++)for(let O=A+1;O<S;O++){const I=v[A],B=v[O];if(I.some(N=>B.some(C=>N.equals(C)))){const N=D(A),C=D(O);N!==C&&(V[N]=C)}}const _=new Map;let E=-1,T=-1;for(let A=0;A<S;A++){const O=D(A);_.has(O)||_.set(O,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const I=_.get(O);let[B,L,N,C]=v[A];const R=new x.Vector3().add(B).add(L).add(N).add(C).multiplyScalar(.25);if(I.points.push(...v[A]),I.area+=B.distanceTo(L)*B.distanceTo(C),I.originalVertices.push(v[A]),I.index=b,I.centerPts.push(R),E==-1||T==-1){let $=new x.Vector3().subVectors(B,L).normalize();T=B.distanceTo(C),E=B.distanceTo(L);let X=oe($,new x.Vector3(0,0,1));X&&X.parallel&&([T,E]=[E,T])}I.gridWidth=E,I.gridHeight=T}p.push(..._.values())}m.mergeCheckRegion=p}}let r=new Map;for(const m of n){if(m.length<.3)continue;let p=m.rooftopPz-m.start.z,b=Math.floor(m.rooftopPz-m.start.z);r.has(b)?r.set(b,{num:r.get(b).num+1,totalHeight:r.get(b).totalHeight+p}):r.set(b,{num:1,totalHeight:p})}let s=[...r.entries()].reduce((m,p)=>p[1].num>m[1].num?p:m);s[0],s[1].totalHeight/s[1].num;const a=[];for(let m=0;m<e.length;m++){const p=e[m];if(p.isFindBeam=!1,p.category=="door"){let b=[];p.coordinatesByArea.coordinates.forEach(D=>{b.push(new x.Vector3(D.x,D.y,D.z))}),b[0].equals(b[b.length-1])&&b.pop();let z=b[0].distanceTo(b[1]),v=b[0].distanceTo(b[3]);v>z&&([z,v]=[v,z],b=[b[0],b[3],b[2],b[1]]);let S=ee(b[0],b[3],!0),V=ee(b[1],b[2],!0);a.push({doorStartPt:S,doorEndPt:V,boxPoints:b,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:m,isFind:!1,inWall:!1})}}for(let m=0;m<a.length;m++){const p=a[m];for(let b=0;b<n.length;b++){if(n[b].length<.5)continue;let z=[];const v=ee(n[b].start,n[b].end,!0);z.push(v),z.push(ee(v,n[b].start,!0)),z.push(ee(v,n[b].end,!0));let S=!1;const V=p.boxPoints.length;for(let D=0;D<z.length;D++){const _=z[D].x,E=z[D].y;for(let T=0,A=V-1;T<V;A=T++){const O=p.boxPoints[T].x,I=p.boxPoints[T].y,B=p.boxPoints[A].x,L=p.boxPoints[A].y;I>E!=L>E&&_<(B-O)*(E-I)/(L-I)+O&&(S=!S)}if(S)break}if(S){let D=new x.Vector3(n[b].start.x,n[b].start.y,0),_=new x.Vector3(n[b].end.x,n[b].end.y,0),E=p.doorStartPt.distanceTo(p.doorEndPt),T=D.distanceTo(_),A=Jt(p.doorStartPt,p.doorEndPt,D,_);if(Math.abs(T-E)<.5&&A&&A.angleDeg<15){p.doorStartPt=new x.Vector3(n[b].start.x,n[b].start.y,0),p.doorEndPt=new x.Vector3(n[b].end.x,n[b].end.y,0);break}else if(Math.abs(T-E)>1.3&&A&&A.angleDeg<15){let O=ne(p.doorStartPt,p.doorEndPt,D,_,{parallelAngleMax:x.MathUtils.degToRad(15)}),I=p.doorStartPt.distanceTo(D),B=p.doorStartPt.distanceTo(_),L=p.doorEndPt.distanceTo(D),N=p.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||N<.2;if(O&&O.type=="collinear_overlap"&&O.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let R=new x.Line3(D,_),$=R.closestPointToPoint(p.doorStartPt,!0,new x.Vector3),X=R.closestPointToPoint(p.doorEndPt,!0,new x.Vector3),ot=$.distanceTo(p.doorStartPt),K=X.distanceTo(p.doorEndPt);if(ot<.1||K<.1){p.inWall=!0;break}}}}else continue}}let l=0,c=[],h=[],d=[];const u=[];let f=.15;for(let m=0;m<n.length;m++){const p=n[m];if(p.noDetection||(p.doorAndBeamData=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0))continue;p.completePointAreaPercentage=-1;let b=new x.Box3;b.setFromPoints(p.originalPoints);let z=b.max.z;b.min.z;const v=new x.Vector3(p.start.x,p.start.y,p.start.z),S=new x.Vector3(p.end.x,p.end.y,p.end.z);let V=p.rooftopPz-p.start.z,D=0;for(const E of p.mergeCheckRegion){const{facePoints:T,boxArea:A,totalInPlaneNum:O}=oo(E.points,E.gridWidth,E.gridHeight,E.centerPts);if(!T||T.length<=0)continue;T[0].distanceTo(T[1]);let I=T[0].distanceTo(T[3]);const B=E.gridHeight*(I/E.gridHeight/3*2)+E.gridHeight/2;let L=new x.Vector3(T[0].x,T[0].y,T[0].z+B),N=new x.Vector3(T[1].x,T[1].y,T[1].z+B);const C=new x.Line3(L,N),R=[];let $=new x.Vector3;E.points.forEach(rt=>{C.closestPointToPoint(rt,!0,$).distanceTo(rt)<E.gridHeight+.01&&R.push(rt)});let X=[],ot=[];for(;;){let rt=[];for(let F=0;F<R.length;F++)ot.includes(F)||rt.length==0&&(rt.push(R[F]),ot.push(F));for(let F=0;F<R.length;F++)if(!ot.includes(F)){for(let H=0;H<rt.length;H++)if(R[F].distanceTo(rt[H])<E.gridWidth+.01){rt.push(R[F]),ot.push(F),F=-1;break}}if(rt.length==0)break;X.push(rt)}const K=[];for(let rt=0;rt<X.length;rt++){const F={lineSt:new x.Vector3,lineEd:new x.Vector3,facePoints:[]};let H=Se(X[rt]);Array.isArray(H)&&H.length==2&&(F.lineSt=H[0],F.lineEd=H[1],F.facePoints.push(new x.Vector3(H[0].x,H[0].y,T[0].z)),F.facePoints.push(new x.Vector3(H[1].x,H[1].y,T[0].z)),F.facePoints.push(new x.Vector3(H[1].x,H[1].y,T[2].z)),F.facePoints.push(new x.Vector3(H[0].x,H[0].y,T[2].z)),K.push(F))}D+=E.area;let G=0;if(O!=0&&(G=E.gridHeight*E.gridWidth*O),(E.area-G)/A*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const F=K[rt];let H=F.facePoints[0].distanceTo(F.facePoints[1]),Vt=F.facePoints[0].distanceTo(F.facePoints[3]),Zt=H/p.length*100,qt=p.rooftopPz-F.facePoints[2].z;if(Vt<1.5||z<F.facePoints[2].z||qt>V/3*2)continue;let Rt=!1,_t=!1,Et=!1,Ft=[],tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone(),W=F.facePoints[0].clone(),j=F.facePoints[1].clone(),Nt=!1,Tt=-1;if(Math.abs(F.facePoints[0].z-p.start.z)<.25){if(H>.17&&p.length>.5){let Wt=Lt(v,W),J=Lt(v,j),ut=Lt(S,W),q=Lt(S,j);const Pt=.1,zt=10;if(Wt<Pt||J<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new x.Vector3(p.start.x,p.start.y,0),pt=new x.Vector3(p.end.x,p.end.y,0),Mt=new x.Vector3().subVectors(Q,pt).normalize();let Gt=new x.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)continue;const it=new x.Vector3(n[U].start.x,n[U].start.y,0),mt=new x.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85){let At=Ct.point.distanceTo(Q);if(Ct.point.distanceTo(pt),At<.3){dt=!0,ft=1/0,Z=-1;break}}continue}if(St&&St.angle>85){const Y=new x.Line3(it,mt).closestPointToPoint(Q,!0,Gt);let yt=Jt(Q,pt,Y,Q);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt,zt),st=pt.clone().addScaledVector(Mt.clone().negate(),zt);let wt=new x.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=Q.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new x.Vector3(W.x,W.y,0),Y=new x.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(Q,pt,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new x.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,Wt<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}if(ut<Pt||q<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new x.Vector3(p.start.x,p.start.y,0),pt=new x.Vector3(p.end.x,p.end.y,0),Mt=new x.Vector3().subVectors(pt,Q).normalize();let Gt=new x.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)continue;const it=new x.Vector3(n[U].start.x,n[U].start.y,0),mt=new x.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85&&(Ct.point.distanceTo(Q),Ct.point.distanceTo(pt)<.3)){dt=!0,ft=1/0,Z=-1;break}continue}if(St&&St.angle>85){const Y=new x.Line3(it,mt).closestPointToPoint(pt,!0,Gt);let yt=Jt(pt,Q,Y,pt);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt.clone().negate(),zt),st=pt.clone().addScaledVector(Mt,zt);let wt=new x.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=pt.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new x.Vector3(W.x,W.y,0),Y=new x.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(pt,Q,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new x.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,ut<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}H=ct.distanceTo(tt)}if(Zt<85&&H>.3||H>.7&&Vt>V-V/3){let Wt=!1;for(let J=0;J<t.length;J++){let ut=J+1;if(ut>=t.length)continue;let q=new x.Vector3(t[J].x,t[J].y,t[J].z),Pt=new x.Vector3(t[ut].x,t[ut].y,t[ut].z);if(te(new x.Vector3(q.x,q.y,0),new x.Vector3(Pt.x,Pt.y,0),new x.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),new x.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),.1)!=null){Wt=!0;break}}for(let J=0;J<a.length;J++){let ut=new x.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new x.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new x.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new x.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=F.facePoints[2].z<a[J].maxZ||Math.abs(F.facePoints[2].z-a[J].maxZ)<.3;if(Math.abs(F.facePoints[2].z-a[J].maxZ)>.2,Ut){let at=ne(ut.clone(),q.clone(),Pt.clone(),zt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let Q=ee(ut,q),pt=new x.Line3(new x.Vector3(p.start.x,p.start.y,0),new x.Vector3(p.end.x,p.end.y,0)),Mt=new x.Vector3,Gt=pt.closestPointToPoint(Q,!0,Mt);if(Q.distanceTo(Gt)<.15){let Z=Pt.distanceTo(ut),k=zt.distanceTo(ut);if(Z>.25&&k>.25){let it=Pt.distanceTo(q),mt=zt.distanceTo(q);if(it>.2&&mt>.2)continue}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,Tt=J,e[a[J].index].isFindBeam=!0;let dt=new x.Vector3().subVectors(Pt,zt).normalize(),U=ut.distanceTo(q)-at.overlap;k<Z&&dt.negate(),Z>k?(tt=F.facePoints[2].clone().addScaledVector(dt,U),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(dt,U),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let Q=Pt.distanceTo(zt),pt=q.distanceTo(ut);if(Math.abs(Q-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>Q&&Math.abs(pt-at.overlap)>1){let Mt=Pt.distanceTo(ut),Gt=Pt.distanceTo(q),ft=zt.distanceTo(ut),Z=zt.distanceTo(q),k=Mt<Gt?Mt:Gt,dt=ft<Z?ft:Z,U=new x.Vector3().subVectors(Pt,zt).normalize(),it=pt-at.overlap;k<dt?(U.negate(),tt=F.facePoints[2].clone().addScaledVector(U,it),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(U,it),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,e[a[J].index].isFindBeam=!0,Tt=J}}}}if(!Et&&H<1.5)for(let J=0;J<a.length;J++){if(a[J].inWall)continue;let ut=new x.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new x.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new x.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new x.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=new x.Vector3().subVectors(ut,q).normalize(),at=new x.Vector3().subVectors(Pt,zt).normalize(),Q=.25,pt=ut.clone().addScaledVector(Ut,Q),Mt=q.clone().addScaledVector(Ut.clone().negate(),Q),Gt=Pt.clone().addScaledVector(at,Q),ft=zt.clone().addScaledVector(at.clone().negate(),Q),Z=te(pt,Mt,Gt,ft),k=!0,dt=ut.distanceTo(Pt),U=ut.distanceTo(zt),it=q.distanceTo(Pt),mt=q.distanceTo(zt);(dt<f||U<f||it<f||mt<f||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Tt=J)}(_t||Wt||Math.abs(Vt-V)>.1&&Vt>V/2&&H>.3)&&(Rt=!0)}}if(Rt){let Wt=!1;for(let Z=0;Z<d.length;Z++){let k=ne(d[Z].start,d[Z].end,W,j);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){Wt=!0;break}}if(Wt){Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1);continue}d.push({start:W,end:j});{new x.PointsMaterial({color:65535,size:.01});let Z=new x.Vector3().subVectors(W,j),k=new x.Vector3().subVectors(j,W),dt=1/0,U=1/0,it=W.clone(),mt=j.clone();const Ct=[],St=[];let At=new x.Line3(tt,ct),Y=new x.Vector3,yt=999999;if(p.originalPoints.forEach(et=>{if(et.z-W.z<Vt/2+.1&&et.z-W.z>Vt/2-.1&&Ct.push(et),et.z>tt.z){let st=At.closestPointToPoint(et,!0,Y),wt=new x.Vector3().subVectors(st,tt),vt=new x.Vector3().subVectors(st,ct),Bt=oe(Z,vt),bt=oe(k,wt);Bt&&Bt.parallel&&!Bt.sameDirection&&bt&&bt.parallel&&!bt.sameDirection&&St.push(et)}}),Ct.length>0){const{newProjectPoints:et}=Ve(W,j,Ct);for(const st of et)st.z=W.z;et.forEach(st=>{let wt=new x.Vector3(st.x,st.y,W.z),vt=new x.Vector3().subVectors(wt,j),Bt=new x.Vector3().subVectors(wt,W),bt=oe(Z,Bt),Xt=oe(k,vt);if(bt&&bt.parallel&&bt.sameDirection){let $t=wt.distanceTo(W);$t<dt&&(dt=$t,it=wt)}else if(Xt&&Xt.parallel&&Xt.sameDirection){let $t=wt.distanceTo(j);$t<U&&(U=$t,mt=wt)}})}if(it.equals(W)||(W=it,ct=new x.Vector3(W.x,W.y,ct.z)),mt.equals(j)||(j=mt,tt=new x.Vector3(j.x,j.y,tt.z)),St.length>10){const{newOnLinePoints:et}=Ve(ct,tt,St);for(let st=0;st<et.length;st++){let vt=At.closestPointToPoint(et[st],!0,Y).distanceTo(et[st]);vt>.02&&yt>vt&&(yt=vt)}tt.z+=yt,ct.z+=yt,Vt+=yt}}let J=j.distanceTo(W);if(J<.4&&!_t||J<.3&&_t)continue;h.includes(m)||h.push(m),p.checkResults[E.index].isDoor=!0;let ut="",q={id:l,beamStart:tt,beamEnd:ct,beamHeight:p.rooftopPz-tt.z,doorStart:W,doorEnd:j,doorHeight:Vt,nearId:-1,type:ut,isExtend:Nt,isDoor:_t,isPullOutDoor:Et,pcbDoorIndexs:Ft,beamNearWallVec:new x.Vector3(0,0,0)},Pt=!1,zt=new x.Vector3,Ut=new x.Vector3,at=-1,Q=-1,pt=-1;for(let Z=0;Z<c.length;Z++){const k=n[c[Z].linesIndex].doorAndBeamData[c[Z].doorIndex];if(k.nearId!=-1)continue;let dt=Jt(tt.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let U=tt.distanceTo(ct),it=k.beamStart.distanceTo(k.beamEnd),mt=new x.Line3(tt.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let Ct=ee(k.beamStart,k.beamEnd,!0);it>U&&(mt.start=new x.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new x.Vector3(k.beamEnd.x,k.beamEnd.y,0),Ct=ee(tt,ct,!0));let St=new x.Vector3,At=mt.closestPointToPoint(Ct,!0,St),Y=At.distanceTo(Ct),yt=new x.Vector3().subVectors(Ct,At).normalize(),et=yt.clone().negate(),st=Ct.clone().addScaledVector(et,Y+.1),wt=te(mt.start,mt.end,Ct,st),vt=!_t&&!k.isDoor&&(U>it*2||it>U*2);if(Y<.4&&wt!=null&&!vt){k.nearId=l,q.nearId=k.id;let Bt=.8;(k.isDoor||q.isDoor)&&(k.isDoor=!0,q.isDoor=!0);const bt=Ft.some(Xt=>k.pcbDoorIndexs.includes(Xt));U<it?U>Bt&&!k.isPullOutDoor?(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Et||Et&&k.isPullOutDoor&&bt?(q.beamStart=k.beamStart.clone().addScaledVector(yt,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(yt,Y),q.doorStart=k.doorStart.clone().addScaledVector(yt,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(yt,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):U>it&&(it>Bt&&!Et?(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):!k.isPullOutDoor||Et&&k.isPullOutDoor&&bt?(k.beamStart=tt.clone().addScaledVector(yt,Y),k.beamEnd=ct.clone().addScaledVector(yt,Y),k.doorStart=W.clone().addScaledVector(yt,Y),k.doorEnd=j.clone().addScaledVector(yt,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight)),at=q.nearId,zt=k.beamStart.clone(),Ut=k.beamEnd.clone(),Pt=!0,Q=c[Z].linesIndex,pt=c[Z].doorIndex;break}}}let Mt=!1;if(!Pt){let Z=new x.Line3(W.clone(),j.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==m)continue;let dt=new x.Vector3(n[k].start.x,n[k].start.y,n[k].start.z),U=new x.Vector3(n[k].end.x,n[k].end.y,n[k].end.z),it=ne(dt,U,W,j),mt=Jt(dt,U,W,j);const Ct=io(n[k]);if(it&&it.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let st=new x.Line3(dt,U),wt=new x.Vector3(W.x,W.y,dt.z),vt=st.closestPointToPoint(wt,!0,new x.Vector3),Bt=re(vt,wt,W,j);Bt&&Bt.angle>85&&(q.beamNearWallVec=new x.Vector3().subVectors(vt,wt).normalize())}const St=[];n[k].originalPoints.forEach(st=>{st.z>W.z+.2&&st.z<W.z+Vt/2&&St.push(new x.Vector3(st.x,st.y,W.z))});const At=new x.Vector3;let Y=[],yt=[];for(let st=0;st<St.length;st++){let wt=Z.closestPointToPoint(St[st],!0,At);wt.distanceTo(St[st])<.15&&(Y.push(St[st]),yt.push(wt.clone()))}for(let st=0;st<yt.length;st++)ao(Z,yt[st])&&Y.push(yt[st]);if(Y=yt,Y=co(Y),Y.length<150)continue;let et=Se(Y);if(et.length==2){let st=et[0].distanceTo(et[1]);if(Math.abs(st-Z.distance())<.3){let wt=new x.Line3(dt,U),vt=new x.Vector3(W.x,W.y,dt.z),Bt=wt.closestPointToPoint(vt,!0,new x.Vector3);if(q.beamNearWallVec=new x.Vector3().subVectors(Bt,vt).normalize(),q.beamStart.z>Ct.maxZ-.03&&H>1)Mt=!0;else if(Wt=!0,Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1),Q!=-1&&pt!=-1){const bt=n[Q].doorAndBeamData[pt];bt.nearId=-1}break}}if(Wt)break}else it&&it.type=="collinear_overlap"&&it.maxPerpendicularDistance>.3&&it.maxPerpendicularDistance<.7&&(Mt=!0)}if(Wt){if(H<1.8)continue;Mt=!0}}let Gt=!1;if(at!=-1)for(let Z=0;Z<u.length&&!(u[Z].length==1&&(u[Z][0].id==l?(u[Z].push({id:at,beamStart:zt,beamEnd:Ut}),Gt=!0):u[Z][0].id==at&&(u[Z].push({id:l,beamStart:tt,beamEnd:ct}),Gt=!0),Gt));Z++);Gt||u.push([{id:l,beamStart:tt,beamEnd:ct}]);const ft=q.doorStart.distanceTo(q.doorEnd);if(_t?ut="door":ft>1.8?ut="beam":ut=Mt&&ft>1?"beam":"hole",q.type=ut,q.nearId!=-1&&ut=="hole"){let Z=!1;for(let k=0;k<n.length;k++)if(n[k].doorAndBeamData){for(let dt=0;dt<n[k].doorAndBeamData.length;dt++)if(n[k].doorAndBeamData[dt].nearId==l&&n[k].doorAndBeamData[dt].type=="beam"){n[k].doorAndBeamData[dt].type=ut,Z=!0;break}if(Z)break}}if(p.doorAndBeamData.push(q),c.push({linesIndex:m,doorIndex:p.doorAndBeamData.length-1}),l++,Et&&H<2)break}}}let _=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=D/_*100}if(h.length>1)for(let m=0;m<h.length;m++){let p=[];for(let b=0;b<n[h[m]].doorAndBeamData.length;b++){let z=!1;if(n[h[m]].doorAndBeamData[b].type==="beam"&&n[h[m]].doorAndBeamData[b].beamNearWallVec.x==0&&n[h[m]].doorAndBeamData[b].beamNearWallVec.y==0&&n[h[m]].doorAndBeamData[b].beamNearWallVec.z==0&&n[h[m]].doorAndBeamData[b].nearId==-1&&(z=!0),!z){let v=n[h[m]].doorAndBeamData[b].doorStart.clone(),S=n[h[m]].doorAndBeamData[b].doorEnd.clone();v.z=S.z=0;let V=v.distanceTo(S);for(let D=0;D<h.length;D++)if(m!=D)for(let _=0;_<n[h[D]].doorAndBeamData.length;_++){let E=n[h[D]].doorAndBeamData[_].doorStart.clone(),T=n[h[D]].doorAndBeamData[_].doorEnd.clone();E.z=T.z=0,E.distanceTo(T);let A=ne(v,S,E,T);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let O=new x.Line3(E,T),I=ee(v,S),B=O.closestPointToPoint(I,!0,new x.Vector3),L=I.distanceTo(B);if(Math.abs(V-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[m]].doorAndBeamData[b].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),z=!0;break}}}}z||p.push(n[h[m]].doorAndBeamData[b])}p.length!=n[h[m]].doorAndBeamData.length&&(n[h[m]].doorAndBeamData=p)}let w=.65,y=2,M=[],P=[];for(let m=0;m<a.length;m++){if(a[m].isFind||a[m].inWall)continue;let p=new x.Vector3(a[m].doorStartPt.x,a[m].doorStartPt.y,0),b=new x.Vector3(a[m].doorEndPt.x,a[m].doorEndPt.y,0),z=new x.Vector3().subVectors(p,b).normalize();for(let v=0;v<n.length;v++){if(n[v].length<.7||n[v].completePointAreaPercentage>60)continue;let S=new x.Vector3(n[v].start.x,n[v].start.y,0),V=new x.Vector3(n[v].end.x,n[v].end.y,0),D=new x.Vector3().subVectors(S,V).normalize(),_=.3,E=p.clone().addScaledVector(z,_),T=b.clone().addScaledVector(z.clone().negate(),_),A=S.clone().addScaledVector(D,_),O=V.clone().addScaledVector(D.clone().negate(),_);te(E,T,A,O);let I=Jt(E,T,A,O),B=p.distanceTo(S)>b.distanceTo(S)?b:p,L=B.distanceTo(S),N=B.distanceTo(V);if((L<f||N<f)&&I&&!I.isParallel){let R=p.distanceTo(S),$=p.distanceTo(V),X=R<$?S:V,ot=!1;for(let K=0;K<n.length;K++){if(K==v||M.includes(K)||n[K].length<.7)continue;let G=new x.Vector3(n[K].start.x,n[K].start.y,0),ht=new x.Vector3(n[K].end.x,n[K].end.y,0),rt=new x.Vector3().subVectors(G,ht).normalize(),F=rt.clone().negate(),H=G.clone().addScaledVector(rt,5),Vt=ht.clone().addScaledVector(F,5),Zt=re(S,V,G,ht),qt=ne(S,V,G,ht),Rt=te(S,V,H,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<f||Rt.point.distanceTo(V)<f),(Zt&&Zt.angle>85||qt&&qt.type=="collinear_gap")&&_t){let Et=new x.Line3(S,V),Ft=new x.Vector3,tt=Et.closestPointToPoint(G,!0,Ft),ct=Et.closestPointToPoint(ht,!0,Ft),W=tt.distanceTo(G),j=ct.distanceTo(ht),Nt,Tt;if(W>j&&j>w)Nt=ht,Tt=ct;else if(W<j&&W>w)Nt=G,Tt=tt;else continue;if(W=X.distanceTo(G),j=X.distanceTo(ht),W>y&&j>y)continue;let Wt=Jt(Nt,Tt,G,ht),J=Jt(Nt,Tt,E,T);if(J&&J.isParallel||!Wt||!Wt.isParallel)continue;let ut=ne(p,b,Nt,Tt);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Nt.z=Tt.z=n[K].start.z;let q=!1;for(let at=0;at<P.length;at++){let Q=ne(P[at].start,P[at].end,Nt,Tt);if(Q&&Q.type=="collinear_overlap"&&Q.maxPerpendicularDistance<.2){q=!0;break}}if(q)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let Q=new x.Vector3(n[at].start.x,n[at].start.y,n[at].start.z),pt=new x.Vector3(n[at].end.x,n[at].end.y,n[at].end.z),Mt=ne(Q,pt,Nt,Tt);if(Mt&&Mt.type=="collinear_overlap"&&Mt.maxPerpendicularDistance<.1){q=!0;break}}if(q)continue;P.push({start:Nt,end:Tt}),M.push(K);let Pt=n[K].rooftopPz-n[K].start.z,zt=n[v].rooftopPz-n[v].start.z,Ut=Pt<zt?Pt:zt;n[K].doorAndBeamData||(n[K].doorAndBeamData=[]),n[K].doorAndBeamData.push({id:l,beamStart:Nt,beamEnd:Tt,beamHeight:Ut,doorStart:Nt,doorEnd:Tt,doorHeight:Ut,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new x.Vector3(0,0,0)}),e[a[m].index].isFindBeam=!0,e[a[m].index].isFindOnlyDoor=!0,u.push([{id:l,beamStart:Nt,beamEnd:Tt}]),l++,ot=!0;break}}if(ot)break}}}let g=[];for(let m=0;m<n.length;m++)n[m].isLine2||g.push(n[m]),n[m].isLine2&&n[m].doorAndBeamData.length!=0&&g.push(n[m]);return n.length=0,n.push(...g),{lines:n,beamGroup:u}},zo=(n,t)=>{if(!n||n.length<=0)return;let e={rectangles:[],threeEdgeRect:[]},o=new Set,i=.2,r=1.5,s=.15,a=2;if(!n[0].uuid){let l=1e4;for(let c=0;c<n.length;c++)n[c].uuid=l++}for(let l=0;l<n.length;l++){let c=n[l].length;if(o.has(n[l].uuid)||c<i||c>r)continue;let h=[],d=new x.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new x.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new x.Vector3().subVectors(u,d).normalize().clone().negate(),y=new x.Vector3,M=new x.Vector3,P=new x.Vector3;new x.Vector3;for(let g=0;g<n.length;g++){let m=n[g].length;if(g==l||m<i||m>r)continue;let p=new x.Vector3(n[g].start.x,n[g].start.y,n[g].start.z),b=new x.Vector3(n[g].end.x,n[g].end.y,n[g].end.z),z=re(d,u,p,b);if(!z||z.angle<85)continue;let v=kt(p,d),S=kt(p,u),V=kt(b,d),D=kt(b,u);if(!(!v&&!S&&!V&&!D)){v||S?(y=p.clone(),M=b.clone()):(y=b.clone(),M=p.clone()),P=new x.Vector3().subVectors(M,y).normalize(),P.clone().negate();for(let _=0;_<n.length;_++){let E=n[_].length;if(_==l||_==g||E<i||E>r)continue;let T=new x.Vector3(n[_].start.x,n[_].start.y,n[_].start.z),A=new x.Vector3(n[_].end.x,n[_].end.y,n[_].end.z),O=re(p,b,T,A);if(!O||O.angle<85)continue;let I=kt(T,M),B=kt(A,M);if(!I&&!B)continue;new x.Vector3;let L=new x.Vector3,N=new x.Vector3;I?(N=new x.Vector3().subVectors(A,T).normalize(),T.clone(),L=A.clone()):(N=new x.Vector3().subVectors(T,A).normalize(),A.clone(),L=T.clone());let C=oe(w,N,.1);if(!(!C||!C.parallel||!C.sameDirection)){for(let R=0;R<n.length;R++){let $=n[R].length;if(R==l||R==g||R==_||$<i||$>r)continue;let X=new x.Vector3(n[R].start.x,n[R].start.y,n[R].start.z),ot=new x.Vector3(n[R].end.x,n[R].end.y,n[R].end.z),K=re(X,ot,T,A);if(!K||K.angle<85)continue;let G=kt(X,L),ht=kt(ot,L);if(!G&&!ht)continue;new x.Vector3;let rt=new x.Vector3;G?(X.clone(),rt=ot.clone()):(ot.clone(),rt=X.clone());let F=kt(rt,d),H=kt(rt,u);if(!F&&!H)continue;let Vt=c*m;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[g].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(g=>o.add(g)),e.rectangles.push(h))}for(let l=0;l<n.length;l++){let c=n[l].length;if(o.has(n[l].uuid)||c<i||c>r)continue;let h={indexs:[],missingEdge:{start:new x.Vector3,end:new x.Vector3}},d=new x.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new x.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),f=!0,w=!0;for(let P=0;P<n.length;P++){if(P==l||n[P].length<i)continue;let g=new x.Vector3(n[P].start.x,n[P].start.y,n[P].start.z),m=new x.Vector3(n[P].end.x,n[P].end.y,n[P].end.z),p=kt(g,d),b=kt(m,d),z=kt(g,u),v=kt(m,u);if(p||b?f=!1:(z||v)&&(w=!1),!f&&!w)break}if(!f&&!w)continue;let y=new x.Vector3;f||([d,u]=[u,d]),y=new x.Vector3().subVectors(u,d).normalize();let M=y.clone().negate();for(let P=0;P<n.length;P++){let g=n[P].length;if(P==l||o.has(P)||g<i||g>r)continue;let m=new x.Vector3(n[P].start.x,n[P].start.y,n[P].start.z),p=new x.Vector3(n[P].end.x,n[P].end.y,n[P].end.z),b=re(d,u,m,p);if(!b||b.angle<85)continue;let z=kt(m,u),v=kt(p,u);if(!z&&!v)continue;new x.Vector3;let S=new x.Vector3;z?(m.clone(),S=p.clone()):(p.clone(),S=m.clone());for(let V=0;V<n.length;V++){let D=n[V].length;if(V==l||V==P||o.has(V)||D<i||D>r)continue;let _=new x.Vector3(n[V].start.x,n[V].start.y,n[V].start.z),E=new x.Vector3(n[V].end.x,n[V].end.y,n[V].end.z),T=re(m,p,_,E);if(!T||T.angle<85)continue;let A=kt(_,S),O=kt(E,S);if(!A&&!O)continue;let I=new x.Vector3,B=new x.Vector3;A?(I=_.clone(),B=E.clone()):(I=E.clone(),B=_.clone());let L=new x.Vector3().subVectors(B,I).normalize(),N=oe(M,L,.1);if(!N||!N.parallel||!N.sameDirection)continue;let C=!0,R=!0;for(let X=0;X<n.length;X++){if(X==V||n[X].length<i)continue;let ot=new x.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),K=new x.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),G=kt(ot,_),ht=kt(K,_),rt=kt(ot,E),F=kt(K,E);if(G||ht?C=!1:(rt||F)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let $=c*g;if(!($<s||$>a)){h.indexs=[n[l].uuid,n[P].uuid,n[V].uuid],h.missingEdge.start=B,h.missingEdge.end=d;break}}if(h.indexs.length==3)break}h.indexs.length==3&&(h.indexs.forEach(P=>o.add(P)),e.threeEdgeRect.push(h))}return e},ae=11102230246251565e-32,Yt=134217729,So=(3+8*ae)*ae;function Ne(n,t,e,o,i){let r,s,a,l,c=t[0],h=o[0],d=0,u=0;h>c==h>-c?(r=c,c=t[++d]):(r=h,h=o[++u]);let f=0;if(d<n&&u<e)for(h>c==h>-c?(s=c+r,a=r-(s-c),c=t[++d]):(s=h+r,a=r-(s-h),h=o[++u]),r=s,a!==0&&(i[f++]=a);d<n&&u<e;)h>c==h>-c?(s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++d]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u]),r=s,a!==0&&(i[f++]=a);for(;d<n;)s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++d],r=s,a!==0&&(i[f++]=a);for(;u<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u],r=s,a!==0&&(i[f++]=a);return(r!==0||f===0)&&(i[f++]=r),f}function vo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function ze(n){return new Float64Array(n)}const Do=(3+16*ae)*ae,_o=(2+12*ae)*ae,Eo=(9+64*ae)*ae*ae,me=ze(4),sn=ze(8),an=ze(12),ln=ze(16),jt=ze(4);function To(n,t,e,o,i,r,s){let a,l,c,h,d,u,f,w,y,M,P,g,m,p,b,z,v,S;const V=n-i,D=e-i,_=t-r,E=o-r;p=V*E,u=Yt*V,f=u-(u-V),w=V-f,u=Yt*E,y=u-(u-E),M=E-y,b=w*M-(p-f*y-w*y-f*M),z=_*D,u=Yt*_,f=u-(u-_),w=_-f,u=Yt*D,y=u-(u-D),M=D-y,v=w*M-(z-f*y-w*y-f*M),P=b-v,d=b-P,me[0]=b-(P+d)+(d-v),g=p+P,d=g-p,m=p-(g-d)+(P-d),P=m-z,d=m-P,me[1]=m-(P+d)+(d-z),S=g+P,d=S-g,me[2]=g-(S-d)+(P-d),me[3]=S;let T=vo(4,me),A=_o*s;if(T>=A||-T>=A||(d=n-V,a=n-(V+d)+(d-i),d=e-D,c=e-(D+d)+(d-i),d=t-_,l=t-(_+d)+(d-r),d=o-E,h=o-(E+d)+(d-r),a===0&&l===0&&c===0&&h===0)||(A=Eo*s+So*Math.abs(T),T+=V*h+E*a-(_*c+D*l),T>=A||-T>=A))return T;p=a*E,u=Yt*a,f=u-(u-a),w=a-f,u=Yt*E,y=u-(u-E),M=E-y,b=w*M-(p-f*y-w*y-f*M),z=l*D,u=Yt*l,f=u-(u-l),w=l-f,u=Yt*D,y=u-(u-D),M=D-y,v=w*M-(z-f*y-w*y-f*M),P=b-v,d=b-P,jt[0]=b-(P+d)+(d-v),g=p+P,d=g-p,m=p-(g-d)+(P-d),P=m-z,d=m-P,jt[1]=m-(P+d)+(d-z),S=g+P,d=S-g,jt[2]=g-(S-d)+(P-d),jt[3]=S;const O=Ne(4,me,4,jt,sn);p=V*h,u=Yt*V,f=u-(u-V),w=V-f,u=Yt*h,y=u-(u-h),M=h-y,b=w*M-(p-f*y-w*y-f*M),z=_*c,u=Yt*_,f=u-(u-_),w=_-f,u=Yt*c,y=u-(u-c),M=c-y,v=w*M-(z-f*y-w*y-f*M),P=b-v,d=b-P,jt[0]=b-(P+d)+(d-v),g=p+P,d=g-p,m=p-(g-d)+(P-d),P=m-z,d=m-P,jt[1]=m-(P+d)+(d-z),S=g+P,d=S-g,jt[2]=g-(S-d)+(P-d),jt[3]=S;const I=Ne(O,sn,4,jt,an);p=a*h,u=Yt*a,f=u-(u-a),w=a-f,u=Yt*h,y=u-(u-h),M=h-y,b=w*M-(p-f*y-w*y-f*M),z=l*c,u=Yt*l,f=u-(u-l),w=l-f,u=Yt*c,y=u-(u-c),M=c-y,v=w*M-(z-f*y-w*y-f*M),P=b-v,d=b-P,jt[0]=b-(P+d)+(d-v),g=p+P,d=g-p,m=p-(g-d)+(P-d),P=m-z,d=m-P,jt[1]=m-(P+d)+(d-z),S=g+P,d=S-g,jt[2]=g-(S-d)+(P-d),jt[3]=S;const B=Ne(I,an,4,jt,ln);return ln[B-1]}function ve(n,t,e,o,i,r){const s=(t-r)*(e-i),a=(n-i)*(o-r),l=s-a,c=Math.abs(s+a);return Math.abs(l)>=Do*c?l:-To(n,t,e,o,i,r,c)}const cn=Math.pow(2,-52),De=new Uint32Array(512);class Be{static from(t,e=Co,o=Lo){const i=t.length,r=new Float64Array(i*2);for(let s=0;s<i;s++){const a=t[s];r[2*s]=e(a),r[2*s+1]=o(a)}return new Be(r)}constructor(t){const e=t.length>>1;if(e>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const o=Math.max(2*e-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:o,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let a=1/0,l=1/0,c=-1/0,h=-1/0;for(let V=0;V<s;V++){const D=t[2*V],_=t[2*V+1];D<a&&(a=D),_<l&&(l=_),D>c&&(c=D),_>h&&(h=_),this._ids[V]=V}const d=(a+c)/2,u=(l+h)/2;let f=0,w=0,y=0;for(let V=0,D=1/0;V<s;V++){const _=qe(d,u,t[2*V],t[2*V+1]);_<D&&(f=V,D=_)}const M=t[2*f],P=t[2*f+1];for(let V=0,D=1/0;V<s;V++){if(V===f)continue;const _=qe(M,P,t[2*V],t[2*V+1]);_<D&&_>0&&(w=V,D=_)}let g=t[2*w],m=t[2*w+1],p=1/0;for(let V=0;V<s;V++){if(V===f||V===w)continue;const D=Io(M,P,g,m,t[2*V],t[2*V+1]);D<p&&(y=V,p=D)}let b=t[2*y],z=t[2*y+1];if(p===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ye(this._ids,this._dists,0,s-1);const V=new Uint32Array(s);let D=0;for(let _=0,E=-1/0;_<s;_++){const T=this._ids[_],A=this._dists[T];A>E&&(V[D++]=T,E=A)}this.hull=V.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(M,P,g,m,b,z)<0){const V=w,D=g,_=m;w=y,g=b,m=z,y=V,b=D,z=_}const v=ko(M,P,g,m,b,z);this._cx=v.x,this._cy=v.y;for(let V=0;V<s;V++)this._dists[V]=qe(t[2*V],t[2*V+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=f;let S=3;o[f]=e[y]=w,o[w]=e[f]=y,o[y]=e[w]=f,i[f]=0,i[w]=1,i[y]=2,r.fill(-1),r[this._hashKey(M,P)]=f,r[this._hashKey(g,m)]=w,r[this._hashKey(b,z)]=y,this.trianglesLen=0,this._addTriangle(f,w,y,-1,-1,-1);for(let V=0,D=0,_=0;V<this._ids.length;V++){const E=this._ids[V],T=t[2*E],A=t[2*E+1];if(V>0&&Math.abs(T-D)<=cn&&Math.abs(A-_)<=cn||(D=T,_=A,E===f||E===w||E===y))continue;let O=0;for(let C=0,R=this._hashKey(T,A);C<this._hashSize&&(O=r[(R+C)%this._hashSize],!(O!==-1&&O!==o[O]));C++);O=e[O];let I=O,B;for(;B=o[I],ve(T,A,t[2*I],t[2*I+1],t[2*B],t[2*B+1])>=0;)if(I=B,I===O){I=-1;break}if(I===-1)continue;let L=this._addTriangle(I,E,o[I],-1,-1,i[I]);i[E]=this._legalize(L+2),i[I]=L,S++;let N=o[I];for(;B=o[N],ve(T,A,t[2*N],t[2*N+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(N,E,B,i[E],-1,i[N]),i[E]=this._legalize(L+2),o[N]=N,S--,N=B;if(I===O)for(;B=e[I],ve(T,A,t[2*B],t[2*B+1],t[2*I],t[2*I+1])<0;)L=this._addTriangle(B,E,I,-1,i[I],i[B]),this._legalize(L+2),i[B]=L,o[I]=I,S--,I=B;this._hullStart=e[E]=I,o[I]=e[N]=E,o[E]=N,r[this._hashKey(T,A)]=E,r[this._hashKey(t[2*I],t[2*I+1])]=I}this.hull=new Uint32Array(S);for(let V=0,D=this._hullStart;V<S;V++)this.hull[V]=D,D=o[D];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(Ao(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:o,coords:i}=this;let r=0,s=0;for(;;){const a=o[t],l=t-t%3;if(s=l+(t+2)%3,a===-1){if(r===0)break;t=De[--r];continue}const c=a-a%3,h=l+(t+1)%3,d=c+(a+2)%3,u=e[s],f=e[t],w=e[h],y=e[d];if(Bo(i[2*u],i[2*u+1],i[2*f],i[2*f+1],i[2*w],i[2*w+1],i[2*y],i[2*y+1])){e[t]=y,e[a]=u;const P=o[d];if(P===-1){let m=this._hullStart;do{if(this._hullTri[m]===d){this._hullTri[m]=t;break}m=this._hullPrev[m]}while(m!==this._hullStart)}this._link(t,P),this._link(a,o[s]),this._link(s,d);const g=c+(a+1)%3;r<De.length&&(De[r++]=g)}else{if(r===0)break;t=De[--r]}}return s}_link(t,e){this._halfedges[t]=e,e!==-1&&(this._halfedges[e]=t)}_addTriangle(t,e,o,i,r,s){const a=this.trianglesLen;return this._triangles[a]=t,this._triangles[a+1]=e,this._triangles[a+2]=o,this._link(a,i),this._link(a+1,r),this._link(a+2,s),this.trianglesLen+=3,a}}function Ao(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function qe(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function Bo(n,t,e,o,i,r,s,a){const l=n-s,c=t-a,h=e-s,d=o-a,u=i-s,f=r-a,w=l*l+c*c,y=h*h+d*d,M=u*u+f*f;return l*(d*M-y*f)-c*(h*M-y*u)+w*(h*f-d*u)<0}function Io(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,d=l*l+c*c,u=.5/(s*c-a*l),f=(c*h-a*d)*u,w=(s*d-l*h)*u;return f*f+w*w}function ko(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,d=l*l+c*c,u=.5/(s*c-a*l),f=n+(c*h-a*d)*u,w=t+(s*d-l*h)*u;return{x:f,y:w}}function ye(n,t,e,o){if(o-e<=20)for(let i=e+1;i<=o;i++){const r=n[i],s=t[r];let a=i-1;for(;a>=e&&t[n[a]]>s;)n[a+1]=n[a--];n[a+1]=r}else{const i=e+o>>1;let r=e+1,s=o;Me(n,i,r),t[n[e]]>t[n[o]]&&Me(n,e,o),t[n[r]]>t[n[o]]&&Me(n,r,o),t[n[e]]>t[n[r]]&&Me(n,e,r);const a=n[r],l=t[a];for(;;){do r++;while(t[n[r]]<l);do s--;while(t[n[s]]>l);if(s<r)break;Me(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ye(n,t,r,o),ye(n,t,e,s-1)):(ye(n,t,e,s-1),ye(n,t,r,o))}}function Me(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Co(n){return n[0]}function Lo(n){return n[1]}const un=1e-6;class de{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,o){t=+t,e=+e,o=+o;const i=t+o,r=e;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>un||Math.abs(this._y1-r)>un)&&(this._+="L"+i+","+r),o&&(this._+=`A${o},${o},0,1,1,${t-o},${e}A${o},${o},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,o,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+o}v${+i}h${-o}Z`}value(){return this._||null}}class Ge{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class Ro{constructor(t,[e,o,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e))||!((r=+r)>=(o=+o)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:o},vectors:i}=this;let r,s;const a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let y=0,M=0,P=o.length,g,m;y<P;y+=3,M+=2){const p=o[y]*2,b=o[y+1]*2,z=o[y+2]*2,v=t[p],S=t[p+1],V=t[b],D=t[b+1],_=t[z],E=t[z+1],T=V-v,A=D-S,O=_-v,I=E-S,B=(T*I-A*O)*2;if(Math.abs(B)<1e-9){if(r===void 0){r=s=0;for(const N of e)r+=t[N*2],s+=t[N*2+1];r/=e.length,s/=e.length}const L=1e9*Math.sign((r-v)*I-(s-S)*O);g=(v+_)/2-L*I,m=(S+E)/2+L*O}else{const L=1/B,N=T*T+A*A,C=O*O+I*I;g=v+(I*N-A*C)*L,m=S+(T*C-O*N)*L}a[M]=g,a[M+1]=m}let l=e[e.length-1],c,h=l*4,d,u=t[2*l],f,w=t[2*l+1];i.fill(0);for(let y=0;y<e.length;++y)l=e[y],c=h,d=u,f=w,h=l*4,u=t[2*l],w=t[2*l+1],i[c+2]=i[h]=f-w,i[c+3]=i[h+1]=u-d}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,d=o.length;h<d;++h){const u=o[h];if(u<h)continue;const f=Math.floor(h/3)*2,w=Math.floor(u/3)*2,y=s[f],M=s[f+1],P=s[w],g=s[w+1];this._renderSegment(y,M,P,g,t)}let l,c=r[r.length-1];for(let h=0;h<r.length;++h){l=c,c=r[h];const d=Math.floor(i[c]/3)*2,u=s[d],f=s[d+1],w=l*4,y=this._project(u,f,a[w+2],a[w+3]);y&&this._renderSegment(u,f,y[0],y[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new de:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const o=e==null?e=new de:void 0,i=this._clip(t);if(i===null||!i.length)return;e.moveTo(i[0],i[1]);let r=i.length;for(;i[0]===i[r-2]&&i[1]===i[r-1]&&r>1;)r-=2;for(let s=2;s<r;s+=2)(i[s]!==i[s-2]||i[s+1]!==i[s-1])&&e.lineTo(i[s],i[s+1]);return e.closePath(),o&&o.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,o=t.length/2;e<o;++e){const i=this.cellPolygon(e);i&&(i.index=e,yield i)}}cellPolygon(t){const e=new Ge;return this.renderCell(t,e),e.value()}_renderSegment(t,e,o,i,r){let s;const a=this._regioncode(t,e),l=this._regioncode(o,i);a===0&&l===0?(r.moveTo(t,e),r.lineTo(o,i)):(s=this._clipSegment(t,e,o,i,a,l))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,o){return e=+e,e!==e||(o=+o,o!==o)?!1:this.delaunay._step(t,e,o)===t}*neighbors(t){const e=this._clip(t);if(e)for(const o of this.delaunay.neighbors(t)){const i=this._clip(o);if(i){t:for(let r=0,s=e.length;r<s;r+=2)for(let a=0,l=i.length;a<l;a+=2)if(e[r]===i[a]&&e[r+1]===i[a+1]&&e[(r+2)%s]===i[(a+l-2)%l]&&e[(r+3)%s]===i[(a+l-1)%l]){yield o;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:o,halfedges:i,triangles:r}}=this,s=o[t];if(s===-1)return null;const a=[];let l=s;do{const c=Math.floor(l/3);if(a.push(e[c*2],e[c*2+1]),l=l%3===2?l-2:l+1,r[l]!==t)break;l=i[l]}while(l!==s&&l!==-1);return a}_clip(t){if(t===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(e===null)return null;const{vectors:o}=this,i=t*4;return this._simplify(o[i]||o[i+1]?this._clipInfinite(t,e,o[i],o[i+1],o[i+2],o[i+3]):this._clipFinite(t,e))}_clipFinite(t,e){const o=e.length;let i=null,r,s,a=e[o-2],l=e[o-1],c,h=this._regioncode(a,l),d,u=0;for(let f=0;f<o;f+=2)if(r=a,s=l,a=e[f],l=e[f+1],c=h,h=this._regioncode(a,l),c===0&&h===0)d=u,u=0,i?i.push(a,l):i=[a,l];else{let w,y,M,P,g;if(c===0){if((w=this._clipSegment(r,s,a,l,c,h))===null)continue;[y,M,P,g]=w}else{if((w=this._clipSegment(a,l,r,s,h,c))===null)continue;[P,g,y,M]=w,d=u,u=this._edgecode(y,M),d&&u&&this._edge(t,d,u,i,i.length),i?i.push(y,M):i=[y,M]}d=u,u=this._edgecode(P,g),d&&u&&this._edge(t,d,u,i,i.length),i?i.push(P,g):i=[P,g]}if(i)d=u,u=this._edgecode(i[0],i[1]),d&&u&&this._edge(t,d,u,i,i.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(t,e,o,i,r,s){const a=r<s;for(a&&([t,e,o,i,r,s]=[o,i,t,e,s,r]);;){if(r===0&&s===0)return a?[o,i,t,e]:[t,e,o,i];if(r&s)return null;let l,c,h=r||s;h&8?(l=t+(o-t)*(this.ymax-e)/(i-e),c=this.ymax):h&4?(l=t+(o-t)*(this.ymin-e)/(i-e),c=this.ymin):h&2?(c=e+(i-e)*(this.xmax-t)/(o-t),l=this.xmax):(c=e+(i-e)*(this.xmin-t)/(o-t),l=this.xmin),r?(t=l,e=c,r=this._regioncode(t,e)):(o=l,i=c,s=this._regioncode(o,i))}}_clipInfinite(t,e,o,i,r,s){let a=Array.from(e),l;if((l=this._project(a[0],a[1],o,i))&&a.unshift(l[0],l[1]),(l=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(l[0],l[1]),a=this._clipFinite(t,a))for(let c=0,h=a.length,d,u=this._edgecode(a[h-2],a[h-1]);c<h;c+=2)d=u,u=this._edgecode(a[c],a[c+1]),d&&u&&(c=this._edge(t,d,u,a,c),h=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,o,i,r){for(;e!==o;){let s,a;switch(e){case 5:e=4;continue;case 4:e=6,s=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,s=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,s=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,s=this.xmin,a=this.ymin;break}(i[r]!==s||i[r+1]!==a)&&this.contains(t,s,a)&&(i.splice(r,0,s,a),r+=2)}return r}_project(t,e,o,i){let r=1/0,s,a,l;if(i<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/i)<r&&(l=this.ymin,a=t+(r=s)*o)}else if(i>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/i)<r&&(l=this.ymax,a=t+(r=s)*o)}if(o>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/o)<r&&(a=this.xmax,l=e+(r=s)*i)}else if(o<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/o)<r&&(a=this.xmin,l=e+(r=s)*i)}return[a,l]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let e=0;e<t.length;e+=2){const o=(e+2)%t.length,i=(e+4)%t.length;(t[e]===t[o]&&t[o]===t[i]||t[e+1]===t[o+1]&&t[o+1]===t[i+1])&&(t.splice(o,2),e-=2)}t.length||(t=null)}return t}}const Fo=2*Math.PI,ge=Math.pow;function Oo(n){return n[0]}function No(n){return n[1]}function qo(n){const{triangles:t,coords:e}=n;for(let o=0;o<t.length;o+=3){const i=2*t[o],r=2*t[o+1],s=2*t[o+2];if((e[s]-e[i])*(e[r+1]-e[i+1])-(e[r]-e[i])*(e[s+1]-e[i+1])>1e-10)return!1}return!0}function Wo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class ke{static from(t,e=Oo,o=No,i){return new ke("length"in t?Xo(t,e,o,i):Float64Array.from($o(t,e,o,i)))}constructor(t){this._delaunator=new Be(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&qo(t)){this.collinear=Int32Array.from({length:e.length/2},(u,f)=>f).sort((u,f)=>e[2*u]-e[2*f]||e[2*u+1]-e[2*f+1]);const l=this.collinear[0],c=this.collinear[this.collinear.length-1],h=[e[2*l],e[2*l+1],e[2*c],e[2*c+1]],d=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let u=0,f=e.length/2;u<f;++u){const w=Wo(e[2*u],e[2*u+1],d);e[2*u]=w[0],e[2*u+1]=w[1]}this._delaunator=new Be(e)}else delete this.collinear;const o=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,c=o.length;l<c;++l){const h=r[l%3===2?l-2:l+1];(o[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,c=i.length;l<c;++l)a[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new Ro(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const d=a.indexOf(t);d>0&&(yield a[d-1]),d<a.length-1&&(yield a[d+1]);return}const l=e[t];if(l===-1)return;let c=l,h=-1;do{if(yield h=s[c],c=c%3===2?c-2:c+1,s[c]!==t)return;if(c=r[c],c===-1){const d=o[(i[t]+1)%o.length];d!==h&&(yield d);return}}while(c!==l)}find(t,e,o=0){if(t=+t,t!==t||(e=+e,e!==e))return-1;const i=o;let r;for(;(r=this._step(o,t,e))>=0&&r!==o&&r!==i;)o=r;return r}_step(t,e,o){const{inedges:i,hull:r,_hullIndex:s,halfedges:a,triangles:l,points:c}=this;if(i[t]===-1||!c.length)return(t+1)%(c.length>>1);let h=t,d=ge(e-c[t*2],2)+ge(o-c[t*2+1],2);const u=i[t];let f=u;do{let w=l[f];const y=ge(e-c[w*2],2)+ge(o-c[w*2+1],2);if(y<d&&(d=y,h=w),f=f%3===2?f-2:f+1,l[f]!==t)break;if(f=a[f],f===-1){if(f=r[(s[t]+1)%r.length],f!==w&&ge(e-c[f*2],2)+ge(o-c[f*2+1],2)<d)return f;break}}while(f!==u);return h}render(t){const e=t==null?t=new de:void 0,{points:o,halfedges:i,triangles:r}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const c=r[s]*2,h=r[l]*2;t.moveTo(o[c],o[c+1]),t.lineTo(o[h],o[h+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){e===void 0&&(!t||typeof t.moveTo!="function")&&(e=t,t=null),e=e==null?2:+e;const o=t==null?t=new de:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const a=i[r],l=i[r+1];t.moveTo(a+e,l),t.arc(a,l,e,0,Fo)}return o&&o.value()}renderHull(t){const e=t==null?t=new de:void 0,{hull:o,points:i}=this,r=o[0]*2,s=o.length;t.moveTo(i[r],i[r+1]);for(let a=1;a<s;++a){const l=2*o[a];t.lineTo(i[l],i[l+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new Ge;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new de:void 0,{points:i,triangles:r}=this,s=r[t*=3]*2,a=r[t+1]*2,l=r[t+2]*2;return e.moveTo(i[s],i[s+1]),e.lineTo(i[a],i[a+1]),e.lineTo(i[l],i[l+1]),e.closePath(),o&&o.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,o=t.length/3;e<o;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new Ge;return this.renderTriangle(t,e),e.value()}}function Xo(n,t,e,o){const i=n.length,r=new Float64Array(i*2);for(let s=0;s<i;++s){const a=n[s];r[s*2]=t.call(o,a,s,n),r[s*2+1]=e.call(o,a,s,n)}return r}function*$o(n,t,e,o){let i=0;for(const r of n)yield t.call(o,r,i,n),yield e.call(o,r,i,n),++i}function Ho(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Yo(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),c=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return c===0?1/0:s*a*l/(4*c)}function je(n){if(!n||n.length<3)return[];const t=new Set,e=[];for(const w of n){const y=`${w[0]}_${w[1]}`;t.has(y)||(t.add(y),e.push(w))}if(e.length<3)return[];const o=new ke(Float64Array.from(e.flat())),{triangles:i}=o;if(!i.length)return[];const r=new Map,s=(w,y)=>w<y?`${w}_${y}`:`${y}_${w}`;for(let w=0;w<i.length;w+=3){const y=i[w],M=i[w+1],P=i[w+2],[g,m]=e[y],[p,b]=e[M],[z,v]=e[P],S=Yo(g,m,p,b,z,v),V=Ho(e,y,M,P);if(S<=1/V)for(const[D,_]of[[y,M],[M,P],[P,y]]){const E=s(D,_);r.set(E,(r.get(E)||0)+1)}}const a=[];for(const[w,y]of r)y===1&&a.push(w.split("_").map(Number));if(!a.length)return[];const l=new Map;for(const[w,y]of a)(l.get(w)||l.set(w,[]).get(w)).push(y),(l.get(y)||l.set(y,[]).get(y)).push(w);const c=a[0][0],h=[],d=new Set;let u=c,f=-1;do{h.push(e[u]),d.add(u);const w=l.get(u)||[];let y=w.find(M=>M!==f&&!d.has(M));if(y===void 0&&(y=w.find(M=>M!==f)),y===void 0)break;f=u,u=y}while(u!==c&&h.length<=a.length+1);return h}const gt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},xt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},It=[[],[],[]],nt=[[],[],[]],Dt=[],ce=new lt.Vector3,ue=new lt.Vector3,he=new lt.Vector3,Ot=new lt.Vector3,hn=new lt.Vector3,fn=new lt.Vector3,Qt=new lt.Matrix3,dn=new lt.Box3,_e=new lt.Matrix4,mn=new lt.Matrix4,gn=new lt.Ray;let Tn=class{constructor(t=new lt.Vector3,e=new lt.Vector3,o=new lt.Matrix3){this.center=t,this.halfSize=e,this.rotation=o}set(t,e,o){return this.center=t,this.halfSize=e,this.rotation=o,this}copy(t){return this.center.copy(t.center),this.halfSize.copy(t.halfSize),this.rotation.copy(t.rotation),this}clone(){return new this.constructor().copy(this)}getSize(t){return t.copy(this.halfSize).multiplyScalar(2)}clampPoint(t,e){const o=this.halfSize;Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const i=lt.MathUtils.clamp(Ot.dot(ce),-o.x,o.x);e.add(ce.multiplyScalar(i));const r=lt.MathUtils.clamp(Ot.dot(ue),-o.y,o.y);e.add(ue.multiplyScalar(r));const s=lt.MathUtils.clamp(Ot.dot(he),-o.z,o.z);return e.add(he.multiplyScalar(s)),e}containsPoint(t){return Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),Math.abs(Ot.dot(ce))<=this.halfSize.x&&Math.abs(Ot.dot(ue))<=this.halfSize.y&&Math.abs(Ot.dot(he))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Go.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,fn),fn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){gt.c=this.center,gt.e[0]=this.halfSize.x,gt.e[1]=this.halfSize.y,gt.e[2]=this.halfSize.z,this.rotation.extractBasis(gt.u[0],gt.u[1],gt.u[2]),xt.c=t.center,xt.e[0]=t.halfSize.x,xt.e[1]=t.halfSize.y,xt.e[2]=t.halfSize.z,t.rotation.extractBasis(xt.u[0],xt.u[1],xt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)It[r][s]=gt.u[r].dot(xt.u[s]);Ot.subVectors(xt.c,gt.c),Dt[0]=Ot.dot(gt.u[0]),Dt[1]=Ot.dot(gt.u[1]),Dt[2]=Ot.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)nt[r][s]=Math.abs(It[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*nt[r][0]+xt.e[1]*nt[r][1]+xt.e[2]*nt[r][2],Math.abs(Dt[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*nt[0][r]+gt.e[1]*nt[1][r]+gt.e[2]*nt[2][r],i=xt.e[r],Math.abs(Dt[0]*It[0][r]+Dt[1]*It[1][r]+Dt[2]*It[2][r])>o+i)return!1;return o=gt.e[1]*nt[2][0]+gt.e[2]*nt[1][0],i=xt.e[1]*nt[0][2]+xt.e[2]*nt[0][1],!(Math.abs(Dt[2]*It[1][0]-Dt[1]*It[2][0])>o+i||(o=gt.e[1]*nt[2][1]+gt.e[2]*nt[1][1],i=xt.e[0]*nt[0][2]+xt.e[2]*nt[0][0],Math.abs(Dt[2]*It[1][1]-Dt[1]*It[2][1])>o+i)||(o=gt.e[1]*nt[2][2]+gt.e[2]*nt[1][2],i=xt.e[0]*nt[0][1]+xt.e[1]*nt[0][0],Math.abs(Dt[2]*It[1][2]-Dt[1]*It[2][2])>o+i)||(o=gt.e[0]*nt[2][0]+gt.e[2]*nt[0][0],i=xt.e[1]*nt[1][2]+xt.e[2]*nt[1][1],Math.abs(Dt[0]*It[2][0]-Dt[2]*It[0][0])>o+i)||(o=gt.e[0]*nt[2][1]+gt.e[2]*nt[0][1],i=xt.e[0]*nt[1][2]+xt.e[2]*nt[1][0],Math.abs(Dt[0]*It[2][1]-Dt[2]*It[0][1])>o+i)||(o=gt.e[0]*nt[2][2]+gt.e[2]*nt[0][2],i=xt.e[0]*nt[1][1]+xt.e[1]*nt[1][0],Math.abs(Dt[0]*It[2][2]-Dt[2]*It[0][2])>o+i)||(o=gt.e[0]*nt[1][0]+gt.e[1]*nt[0][0],i=xt.e[1]*nt[2][2]+xt.e[2]*nt[2][1],Math.abs(Dt[1]*It[0][0]-Dt[0]*It[1][0])>o+i)||(o=gt.e[0]*nt[1][1]+gt.e[1]*nt[0][1],i=xt.e[0]*nt[2][2]+xt.e[2]*nt[2][0],Math.abs(Dt[1]*It[0][1]-Dt[0]*It[1][1])>o+i)||(o=gt.e[0]*nt[1][2]+gt.e[1]*nt[0][2],i=xt.e[0]*nt[2][1]+xt.e[1]*nt[2][0],Math.abs(Dt[1]*It[0][2]-Dt[0]*It[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ce,ue,he);const e=this.halfSize.x*Math.abs(t.normal.dot(ce))+this.halfSize.y*Math.abs(t.normal.dot(ue))+this.halfSize.z*Math.abs(t.normal.dot(he)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(hn),dn.setFromCenterAndSize(Ot.set(0,0,0),hn),_e.setFromMatrix3(this.rotation),_e.setPosition(this.center),mn.copy(_e).invert(),gn.copy(t).applyMatrix4(mn),gn.intersectBox(dn,e)?e.applyMatrix4(_e):null}intersectsRay(t){return this.intersectRay(t,Ot)!==null}fromBox3(t){return t.getCenter(this.center),t.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(t){return t.center.equals(this.center)&&t.halfSize.equals(this.halfSize)&&t.rotation.equals(this.rotation)}applyMatrix4(t){const e=t.elements;let o=Ot.set(e[0],e[1],e[2]).length();const i=Ot.set(e[4],e[5],e[6]).length(),r=Ot.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Qt.setFromMatrix4(t);const a=1/o,l=1/i,c=1/r;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[3]*=l,Qt.elements[4]*=l,Qt.elements[5]*=l,Qt.elements[6]*=c,Qt.elements[7]*=c,Qt.elements[8]*=c,this.rotation.multiply(Qt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ot.setFromMatrixPosition(t),this.center.add(Ot),this}};const Go=new Tn;var Ht=63710088e-1,An={centimeters:Ht*100,centimetres:Ht*100,degrees:360/(2*Math.PI),feet:Ht*3.28084,inches:Ht*39.37,kilometers:Ht/1e3,kilometres:Ht/1e3,meters:Ht,metres:Ht,miles:Ht/1609.344,millimeters:Ht*1e3,millimetres:Ht*1e3,nauticalmiles:Ht/1852,radians:1,yards:Ht*1.0936};function Bn(n,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=n,o}function In(n,t,e={}){if(!n)throw new Error("coordinates is required");if(!Array.isArray(n))throw new Error("coordinates must be an Array");if(n.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!pn(n[0])||!pn(n[1]))throw new Error("coordinates must contain numbers");return Bn({type:"Point",coordinates:n},t,e)}function kn(n,t,e={}){for(const i of n){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<i[i.length-1].length;r++)if(i[i.length-1][r]!==i[0][r])throw new Error("First and last Position are not equivalent.")}return Bn({type:"Polygon",coordinates:n},t,e)}function jo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Uo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n/e}function Cn(n){return n%(2*Math.PI)*180/Math.PI}function ie(n){return n%360*Math.PI/180}function Ln(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return jo(Uo(n,t),e)}function pn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function Zo(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function Pe(n,t,e){if(n!==null)for(var o,i,r,s,a,l,c,h=0,d=0,u,f=n.type,w=f==="FeatureCollection",y=f==="Feature",M=w?n.features.length:1,P=0;P<M;P++){c=w?n.features[P].geometry:y?n.geometry:n,u=c?c.type==="GeometryCollection":!1,a=u?c.geometries.length:1;for(var g=0;g<a;g++){var m=0,p=0;if(s=u?c.geometries[g]:c,s!==null){l=s.coordinates;var b=s.type;switch(h=e&&(b==="Polygon"||b==="MultiPolygon")?1:0,b){case null:break;case"Point":if(t(l,d,P,m,p)===!1)return!1;d++,m++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],d,P,m,p)===!1)return!1;d++,b==="MultiPoint"&&m++}b==="LineString"&&m++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-h;i++){if(t(l[o][i],d,P,m,p)===!1)return!1;d++}b==="MultiLineString"&&m++,b==="Polygon"&&p++}b==="Polygon"&&m++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(p=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],d,P,m,p)===!1)return!1;d++}p++}m++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(Pe(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ko(n){var t=[];return Pe(n,function(e){t.push(e)}),t}function Qo(n,t){var e,o,i,r,s,a,l,c,h,d,u=0,f=n.type==="FeatureCollection",w=n.type==="Feature",y=f?n.features.length:1;for(e=0;e<y;e++){for(a=f?n.features[e].geometry:w?n.geometry:n,c=f?n.features[e].properties:w?n.properties:{},h=f?n.features[e].bbox:w?n.bbox:void 0,d=f?n.features[e].id:w?n.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(r=l?a.geometries[i]:a,r===null){if(t(null,u,c,h,d)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,u,c,h,d)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],u,c,h,d)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}u++}}function Jo(n,t,e){var o=e;return Qo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function er(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function o(){return this instanceof o?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(o){var i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:function(){return n[o]}})}),e}var Ze={exports:{}},Fn={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(g,m,p,b,z){(function v(S,V,D,_,E){for(;_>D;){if(_-D>600){var T=_-D+1,A=V-D+1,O=Math.log(T),I=.5*Math.exp(2*O/3),B=.5*Math.sqrt(O*I*(T-I)/T)*(A-T/2<0?-1:1),L=Math.max(D,Math.floor(V-A*I/T+B)),N=Math.min(_,Math.floor(V+(T-A)*I/T+B));v(S,V,L,N,E)}var C=S[V],R=D,$=_;for(o(S,D,V),E(S[_],C)>0&&o(S,D,_);R<$;){for(o(S,R,$),R++,$--;E(S[R],C)<0;)R++;for(;E(S[$],C)>0;)$--}E(S[D],C)===0?o(S,D,$):o(S,++$,_),$<=V&&(D=$+1),V<=$&&(_=$-1)}})(g,m,p||0,b||g.length-1,z||i)}function o(g,m,p){var b=g[m];g[m]=g[p],g[p]=b}function i(g,m){return g<m?-1:g>m?1:0}var r=function(g){g===void 0&&(g=9),this._maxEntries=Math.max(4,g),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(g,m,p){if(!p)return m.indexOf(g);for(var b=0;b<m.length;b++)if(p(g,m[b]))return b;return-1}function a(g,m){l(g,0,g.children.length,m,g)}function l(g,m,p,b,z){z||(z=M(null)),z.minX=1/0,z.minY=1/0,z.maxX=-1/0,z.maxY=-1/0;for(var v=m;v<p;v++){var S=g.children[v];c(z,g.leaf?b(S):S)}return z}function c(g,m){return g.minX=Math.min(g.minX,m.minX),g.minY=Math.min(g.minY,m.minY),g.maxX=Math.max(g.maxX,m.maxX),g.maxY=Math.max(g.maxY,m.maxY),g}function h(g,m){return g.minX-m.minX}function d(g,m){return g.minY-m.minY}function u(g){return(g.maxX-g.minX)*(g.maxY-g.minY)}function f(g){return g.maxX-g.minX+(g.maxY-g.minY)}function w(g,m){return g.minX<=m.minX&&g.minY<=m.minY&&m.maxX<=g.maxX&&m.maxY<=g.maxY}function y(g,m){return m.minX<=g.maxX&&m.minY<=g.maxY&&m.maxX>=g.minX&&m.maxY>=g.minY}function M(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function P(g,m,p,b,z){for(var v=[m,p];v.length;)if(!((p=v.pop())-(m=v.pop())<=b)){var S=m+Math.ceil((p-m)/b/2)*b;e(g,S,m,p,z),v.push(m,S,S,p)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(g){var m=this.data,p=[];if(!y(g,m))return p;for(var b=this.toBBox,z=[];m;){for(var v=0;v<m.children.length;v++){var S=m.children[v],V=m.leaf?b(S):S;y(g,V)&&(m.leaf?p.push(S):w(g,V)?this._all(S,p):z.push(S))}m=z.pop()}return p},r.prototype.collides=function(g){var m=this.data;if(!y(g,m))return!1;for(var p=[];m;){for(var b=0;b<m.children.length;b++){var z=m.children[b],v=m.leaf?this.toBBox(z):z;if(y(g,v)){if(m.leaf||w(g,v))return!0;p.push(z)}}m=p.pop()}return!1},r.prototype.load=function(g){if(!g||!g.length)return this;if(g.length<this._minEntries){for(var m=0;m<g.length;m++)this.insert(g[m]);return this}var p=this._build(g.slice(),0,g.length-1,0);if(this.data.children.length)if(this.data.height===p.height)this._splitRoot(this.data,p);else{if(this.data.height<p.height){var b=this.data;this.data=p,p=b}this._insert(p,this.data.height-p.height-1,!0)}else this.data=p;return this},r.prototype.insert=function(g){return g&&this._insert(g,this.data.height-1),this},r.prototype.clear=function(){return this.data=M([]),this},r.prototype.remove=function(g,m){if(!g)return this;for(var p,b,z,v=this.data,S=this.toBBox(g),V=[],D=[];v||V.length;){if(v||(v=V.pop(),b=V[V.length-1],p=D.pop(),z=!0),v.leaf){var _=s(g,v.children,m);if(_!==-1)return v.children.splice(_,1),V.push(v),this._condense(V),this}z||v.leaf||!w(v,S)?b?(p++,v=b.children[p],z=!1):v=null:(V.push(v),D.push(p),p=0,b=v,v=v.children[0])}return this},r.prototype.toBBox=function(g){return g},r.prototype.compareMinX=function(g,m){return g.minX-m.minX},r.prototype.compareMinY=function(g,m){return g.minY-m.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(g){return this.data=g,this},r.prototype._all=function(g,m){for(var p=[];g;)g.leaf?m.push.apply(m,g.children):p.push.apply(p,g.children),g=p.pop();return m},r.prototype._build=function(g,m,p,b){var z,v=p-m+1,S=this._maxEntries;if(v<=S)return a(z=M(g.slice(m,p+1)),this.toBBox),z;b||(b=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,b-1))),(z=M([])).leaf=!1,z.height=b;var V=Math.ceil(v/S),D=V*Math.ceil(Math.sqrt(S));P(g,m,p,D,this.compareMinX);for(var _=m;_<=p;_+=D){var E=Math.min(_+D-1,p);P(g,_,E,V,this.compareMinY);for(var T=_;T<=E;T+=V){var A=Math.min(T+V-1,E);z.children.push(this._build(g,T,A,b-1))}}return a(z,this.toBBox),z},r.prototype._chooseSubtree=function(g,m,p,b){for(;b.push(m),!m.leaf&&b.length-1!==p;){for(var z=1/0,v=1/0,S=void 0,V=0;V<m.children.length;V++){var D=m.children[V],_=u(D),E=(T=g,A=D,(Math.max(A.maxX,T.maxX)-Math.min(A.minX,T.minX))*(Math.max(A.maxY,T.maxY)-Math.min(A.minY,T.minY))-_);E<v?(v=E,z=_<z?_:z,S=D):E===v&&_<z&&(z=_,S=D)}m=S||m.children[0]}var T,A;return m},r.prototype._insert=function(g,m,p){var b=p?g:this.toBBox(g),z=[],v=this._chooseSubtree(b,this.data,m,z);for(v.children.push(g),c(v,b);m>=0&&z[m].children.length>this._maxEntries;)this._split(z,m),m--;this._adjustParentBBoxes(b,z,m)},r.prototype._split=function(g,m){var p=g[m],b=p.children.length,z=this._minEntries;this._chooseSplitAxis(p,z,b);var v=this._chooseSplitIndex(p,z,b),S=M(p.children.splice(v,p.children.length-v));S.height=p.height,S.leaf=p.leaf,a(p,this.toBBox),a(S,this.toBBox),m?g[m-1].children.push(S):this._splitRoot(p,S)},r.prototype._splitRoot=function(g,m){this.data=M([g,m]),this.data.height=g.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(g,m,p){for(var b,z,v,S,V,D,_,E=1/0,T=1/0,A=m;A<=p-m;A++){var O=l(g,0,A,this.toBBox),I=l(g,A,p,this.toBBox),B=(z=O,v=I,S=void 0,V=void 0,D=void 0,_=void 0,S=Math.max(z.minX,v.minX),V=Math.max(z.minY,v.minY),D=Math.min(z.maxX,v.maxX),_=Math.min(z.maxY,v.maxY),Math.max(0,D-S)*Math.max(0,_-V)),L=u(O)+u(I);B<E?(E=B,b=A,T=L<T?L:T):B===E&&L<T&&(T=L,b=A)}return b||p-m},r.prototype._chooseSplitAxis=function(g,m,p){var b=g.leaf?this.compareMinX:h,z=g.leaf?this.compareMinY:d;this._allDistMargin(g,m,p,b)<this._allDistMargin(g,m,p,z)&&g.children.sort(b)},r.prototype._allDistMargin=function(g,m,p,b){g.children.sort(b);for(var z=this.toBBox,v=l(g,0,m,z),S=l(g,p-m,p,z),V=f(v)+f(S),D=m;D<p-m;D++){var _=g.children[D];c(v,g.leaf?z(_):_),V+=f(v)}for(var E=p-m-1;E>=m;E--){var T=g.children[E];c(S,g.leaf?z(T):T),V+=f(S)}return V},r.prototype._adjustParentBBoxes=function(g,m,p){for(var b=p;b>=0;b--)c(m[b],g)},r.prototype._condense=function(g){for(var m=g.length-1,p=void 0;m>=0;m--)g[m].children.length===0?m>0?(p=g[m-1].children).splice(p.indexOf(g[m]),1):this.clear():a(g[m],this.toBBox)},r})})(Fn);var nr=Fn.exports;class or{constructor(t=[],e=rr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let o=(this.length>>1)-1;o>=0;o--)this._down(o)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:o}=this,i=e[t];for(;t>0;){const r=t-1>>1,s=e[r];if(o(i,s)>=0)break;e[t]=s,t=r}e[t]=i}_down(t){const{data:e,compare:o}=this,i=this.length>>1,r=e[t];for(;t<i;){let s=(t<<1)+1,a=e[s];const l=s+1;if(l<this.length&&o(e[l],a)<0&&(s=l,a=e[l]),o(a,r)>=0)break;e[t]=a,t=s}e[t]=r}}function rr(n,t){return n<t?-1:n>t?1:0}const ir=Object.freeze(Object.defineProperty({__proto__:null,default:or},Symbol.toStringTag,{value:"Module"})),sr=er(ir);var Ce={exports:{}},ar=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=(i-o)/2,c=0,h=l-1;c<l;h=c++){var d=e[o+c*2+0],u=e[o+c*2+1],f=e[o+h*2+0],w=e[o+h*2+1],y=u>s!=w>s&&r<(f-d)*(s-u)/(w-u)+d;y&&(a=!a)}return a},lr=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=i-o,c=0,h=l-1;c<l;h=c++){var d=e[c+o][0],u=e[c+o][1],f=e[h+o][0],w=e[h+o][1],y=u>s!=w>s&&r<(f-d)*(s-u)/(w-u)+d;y&&(a=!a)}return a},On=ar,Nn=lr;Ce.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Nn(t,e,o,i):On(t,e,o,i)};Ce.exports.nested=Nn;Ce.exports.flat=On;var cr=Ce.exports,Ue={exports:{}};(function(n,t){(function(e,o){o(t)})(Rn,function(e){const i=33306690738754706e-32;function r(y,M,P,g,m){let p,b,z,v,S=M[0],V=g[0],D=0,_=0;V>S==V>-S?(p=S,S=M[++D]):(p=V,V=g[++_]);let E=0;if(D<y&&_<P)for(V>S==V>-S?(z=p-((b=S+p)-S),S=M[++D]):(z=p-((b=V+p)-V),V=g[++_]),p=b,z!==0&&(m[E++]=z);D<y&&_<P;)V>S==V>-S?(z=p-((b=p+S)-(v=b-p))+(S-v),S=M[++D]):(z=p-((b=p+V)-(v=b-p))+(V-v),V=g[++_]),p=b,z!==0&&(m[E++]=z);for(;D<y;)z=p-((b=p+S)-(v=b-p))+(S-v),S=M[++D],p=b,z!==0&&(m[E++]=z);for(;_<P;)z=p-((b=p+V)-(v=b-p))+(V-v),V=g[++_],p=b,z!==0&&(m[E++]=z);return p===0&&E!==0||(m[E++]=p),E}function s(y){return new Float64Array(y)}const a=33306690738754716e-32,l=22204460492503146e-32,c=11093356479670487e-47,h=s(4),d=s(8),u=s(12),f=s(16),w=s(4);e.orient2d=function(y,M,P,g,m,p){const b=(M-p)*(P-m),z=(y-m)*(g-p),v=b-z;if(b===0||z===0||b>0!=z>0)return v;const S=Math.abs(b+z);return Math.abs(v)>=a*S?v:-function(V,D,_,E,T,A,O){let I,B,L,N,C,R,$,X,ot,K,G,ht,rt,F,H,Vt,Zt,qt;const Rt=V-T,_t=_-T,Et=D-A,Ft=E-A;C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=Rt*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=Et*_t)-$*ot-X*ot-$*K))),h[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),h[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,h[2]=ht-(qt-C)+(G-C),h[3]=qt;let tt=function(Tt,Wt){let J=Wt[0];for(let ut=1;ut<Tt;ut++)J+=Wt[ut];return J}(4,h),ct=l*O;if(tt>=ct||-tt>=ct||(I=V-(Rt+(C=V-Rt))+(C-T),L=_-(_t+(C=_-_t))+(C-T),B=D-(Et+(C=D-Et))+(C-A),N=E-(Ft+(C=E-Ft))+(C-A),I===0&&B===0&&L===0&&N===0)||(ct=c*O+i*Math.abs(tt),(tt+=Rt*N+Ft*I-(Et*L+_t*B))>=ct||-tt>=ct))return tt;C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=I*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=B*_t)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const W=r(4,h,4,w,d);C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=Rt*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=Et*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const j=r(W,d,4,w,u);C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=I*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=B*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const Nt=r(j,u,4,w,f);return f[Nt-1]}(y,M,P,g,m,p,S)},e.orient2dfast=function(y,M,P,g,m,p){return(M-p)*(P-m)-(y-m)*(g-p)},Object.defineProperty(e,"__esModule",{value:!0})})})(Ue,Ue.exports);var ur=Ue.exports,yn=nr,Ae=sr,hr=cr,fr=ur.orient2d;Ae.default&&(Ae=Ae.default);Ze.exports=qn;Ze.exports.default=qn;function qn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=yr(n),i=new yn(16);i.toBBox=function(g){return{minX:g[0],minY:g[1],maxX:g[0],maxY:g[1]}},i.compareMinX=function(g,m){return g[0]-m[0]},i.compareMinY=function(g,m){return g[1]-m[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=bn(l,a),r.push(a)}var c=new yn(16);for(s=0;s<r.length;s++)c.insert(We(r[s]));for(var h=t*t,d=e*e;r.length;){var u=r.shift(),f=u.p,w=u.next.p,y=Xe(f,w);if(!(y<d)){var M=y/h;l=dr(i,u.prev.p,f,w,u.next.next.p,M,c),l&&Math.min(Xe(l,f),Xe(l,w))<=M&&(r.push(u),r.push(bn(l,u)),i.remove(l),c.remove(u),c.insert(We(u)),c.insert(We(u.next)))}}u=a;var P=[];do P.push(u.p),u=u.next;while(u!==a);return P.push(u.p),P}function dr(n,t,e,o,i,r,s){for(var a=new Ae([],mr),l=n.data;l;){for(var c=0;c<l.children.length;c++){var h=l.children[c],d=l.leaf?$e(h,e,o):gr(e,o,h);d>r||a.push({node:h,dist:d})}for(;a.length&&!a.peek().node.children;){var u=a.pop(),f=u.node,w=$e(f,t,e),y=$e(f,o,i);if(u.dist<w&&u.dist<y&&wn(e,f,s)&&wn(o,f,s))return f}l=a.pop(),l&&(l=l.node)}return null}function mr(n,t){return n.dist-t.dist}function gr(n,t,e){if(xn(n,e)||xn(t,e))return 0;var o=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=Ee(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=Ee(n[0],n[1],t[0],t[1],e.minX,e.maxY,e.maxX,e.maxY);return s===0?0:Math.min(o,i,r,s)}function xn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function wn(n,t,e){for(var o=Math.min(n[0],t[0]),i=Math.min(n[1],t[1]),r=Math.max(n[0],t[0]),s=Math.max(n[1],t[1]),a=e.search({minX:o,minY:i,maxX:r,maxY:s}),l=0;l<a.length;l++)if(pr(a[l].p,a[l].next.p,n,t))return!1;return!0}function xe(n,t,e){return fr(n[0],n[1],t[0],t[1],e[0],e[1])}function pr(n,t,e,o){return n!==o&&t!==e&&xe(n,t,e)>0!=xe(n,t,o)>0&&xe(e,o,n)>0!=xe(e,o,t)>0}function We(n){var t=n.p,e=n.next.p;return n.minX=Math.min(t[0],e[0]),n.minY=Math.min(t[1],e[1]),n.maxX=Math.max(t[0],e[0]),n.maxY=Math.max(t[1],e[1]),n}function yr(n){for(var t=n[0],e=n[0],o=n[0],i=n[0],r=0;r<n.length;r++){var s=n[r];s[0]<t[0]&&(t=s),s[0]>o[0]&&(o=s),s[1]<e[1]&&(e=s),s[1]>i[1]&&(i=s)}var a=[t,e,o,i],l=a.slice();for(r=0;r<n.length;r++)hr(n[r],a)||l.push(n[r]);return wr(l)}function bn(n,t){var e={p:n,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e):(e.prev=e,e.next=e),e}function Xe(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function $e(n,t,e){var o=t[0],i=t[1],r=e[0]-o,s=e[1]-i;if(r!==0||s!==0){var a=((n[0]-o)*r+(n[1]-i)*s)/(r*r+s*s);a>1?(o=e[0],i=e[1]):a>0&&(o+=r*a,i+=s*a)}return r=n[0]-o,s=n[1]-i,r*r+s*s}function Ee(n,t,e,o,i,r,s,a){var l=e-n,c=o-t,h=s-i,d=a-r,u=n-i,f=t-r,w=l*l+c*c,y=l*h+c*d,M=h*h+d*d,P=l*u+c*f,g=h*u+d*f,m=w*M-y*y,p,b,z,v,S=m,V=m;m===0?(b=0,S=1,v=g,V=M):(b=y*g-M*P,v=w*g-y*P,b<0?(b=0,v=g,V=M):b>S&&(b=S,v=g+y,V=M)),v<0?(v=0,-P<0?b=0:-P>w?b=S:(b=-P,S=w)):v>V&&(v=V,-P+y<0?b=0:-P+y>w?b=S:(b=-P+y,S=w)),p=b===0?0:b/S,z=v===0?0:v/V;var D=(1-p)*n+p*e,_=(1-p)*t+p*o,E=(1-z)*i+z*s,T=(1-z)*r+z*a,A=E-D,O=T-_;return A*A+O*O}function xr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function wr(n){n.sort(xr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&xe(t[t.length-2],t[t.length-1],n[e])<=0;)t.pop();t.push(n[e])}for(var o=[],i=n.length-1;i>=0;i--){for(;o.length>=2&&xe(o[o.length-2],o[o.length-1],n[i])<=0;)o.pop();o.push(n[i])}return o.pop(),t.pop(),t.concat(o)}var br=Ze.exports;const Pr=tr(br);function Mr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(Pe(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=Pr(e,t.concavity);return o.length>3?kn([o]):null}function Wn(n,t={}){let e=0,o=0,i=0;return Pe(n,function(r){e+=r[0],o+=r[1],i++},!0),In([e/i,o/i],t.properties)}function se(n){if(!n)throw new Error("coord is required");if(!Array.isArray(n)){if(n.type==="Feature"&&n.geometry!==null&&n.geometry.type==="Point")return[...n.geometry.coordinates];if(n.type==="Point")return[...n.coordinates]}if(Array.isArray(n)&&n.length>=2&&!Array.isArray(n[0])&&!Array.isArray(n[1]))return[...n];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Vr(n){if(Array.isArray(n))return n;if(n.type==="Feature"){if(n.geometry!==null)return n.geometry.coordinates}else if(n.coordinates)return n.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function zr(n,t,e={}){let o;return e.final?o=Pn(se(t),se(n)):o=Pn(se(n),se(t)),o>180?-(360-o):o}function Pn(n,t){const e=ie(n[1]),o=ie(t[1]);let i=ie(t[0]-n[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(i,r);return(Cn(s)+360)%360}function Sr(n,t,e={}){const o=se(n),i=se(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=vr(o,i);return Ln(r,"meters",e.units)}function vr(n,t,e){e=e===void 0?Ht:Number(e);const o=e,i=n[1]*Math.PI/180,r=t[1]*Math.PI/180,s=r-i;let a=Math.abs(t[0]-n[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+c*c*a*a)*o}function Dr(n,t,e,o={}){const i=t<0;let r=Ln(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=se(n),a=_r(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,In(a,o.properties)}function _r(n,t,e,o){o=o===void 0?Ht:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ie(n[1]),a=ie(e),l=i*Math.cos(a);let c=s+l;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);const h=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),d=Math.abs(h)>1e-11?l/h:Math.cos(s),u=i*Math.sin(a)/d;return[((r+u)*180/Math.PI+540)%360-180,c*180/Math.PI]}function Er(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Xn(n);case"FeatureCollection":return Tr(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ke(n);default:throw new Error("unknown GeoJSON type")}}function Xn(n){const t={type:"Feature"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=n[e]}}),t.properties=$n(n.properties),n.geometry==null?t.geometry=null:t.geometry=Ke(n.geometry),t}function $n(n){const t={};return n&&Object.keys(n).forEach(e=>{const o=n[e];typeof o=="object"?o===null?t[e]=null:Array.isArray(o)?t[e]=o.map(i=>i):t[e]=$n(o):t[e]=o}),t}function Tr(n){const t={type:"FeatureCollection"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=n[e]}}),t.features=n.features.map(e=>Xn(e)),t}function Ke(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>Ke(e)),t):(t.coordinates=Hn(n.coordinates),t)}function Hn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Hn(e))}function Mn(n,t,e){if(e=e||{},!Zo(e))throw new Error("options is invalid");const o=e.pivot,i=e.mutate;if(!n)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("angle is required");if(t===0)return n;const r=o??Wn(n);return(i===!1||i===void 0)&&(n=Er(n)),Pe(n,function(s){const l=zr(r,s)+t,c=Sr(r,s),h=Vr(Dr(r,c,l));s[0]=h[0],s[1]=h[1]}),n}function Yn(n,t,e={}){if(e.final===!0)return Ar(n,t);const o=se(n),i=se(t),r=ie(o[0]),s=ie(i[0]),a=ie(o[1]),l=ie(i[1]),c=Math.sin(s-r)*Math.cos(l),h=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-r);return Cn(Math.atan2(c,h))}function Ar(n,t){let e=Yn(t,n);return e=(e+180)%360,e}function Br(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return Pe(n,o=>{e[0]>o[0]&&(e[0]=o[0]),e[1]>o[1]&&(e[1]=o[1]),e[2]<o[0]&&(e[2]=o[0]),e[3]<o[1]&&(e[3]=o[1])}),e}function Ir(n,t={}){const e=Number(n[0]),o=Number(n[1]),i=Number(n[2]),r=Number(n[3]);if(n.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[e,o];return kn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function kr(n){return Ir(Br(n))}function Cr(n){return Jo(n,(t,e)=>t+Lr(e),0)}function Lr(n){let t=0,e;switch(n.type){case"Polygon":return Vn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=Vn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function Vn(n){let t=0;if(n&&n.length>0){t+=Math.abs(zn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(zn(n[e]))}return t}var Rr=Ht*Ht/2,He=Math.PI/180;function zn(n){const t=n.length-1;if(t<=2)return 0;let e=0,o=0;for(;o<t;){const i=n[o],r=n[o+1===t?0:o+1],s=n[o+2>=t?(o+2)%t:o+2],a=i[0]*He,l=r[1]*He,c=s[0]*He;e+=(c-a)*Math.sin(l),o++}return e*Rr}function Fr(n){const t=Mr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=Wn(t),o=Ko(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=Yn(o[s],o[s+1]),l=Mn(t,-1*a,{pivot:e}),c=kr(l),h=Cr(c);h<i&&(i=h,r=Mn(c,a,{pivot:e}))}return r}function Sn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Or(n){let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const[r,s]of n)r<t&&(t=r),r>e&&(e=r),s<o&&(o=s),s>i&&(i=s);return[(e+t)*.5,(i+o)*.5]}class Ie extends Tn{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Te,fe,new x.Vector3);const t=this.halfSize.clone().multiplyScalar(2),e=new x.Mesh(new x.BoxGeometry(t.x,t.y,t.z));return e.position.copy(this.center),e.rotation.setFromQuaternion(fe),e}getBoxEdge(t=16776960){const e=this.getBoxMesh();qr.setFromObject(e);const o=new x.EdgesGeometry(e.geometry.clone().applyMatrix4(e.matrixWorld));return new x.LineSegments(o,new x.LineBasicMaterial({color:t,toneMapped:!1}))}toJson(){return le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Te,fe,new x.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:fe.toArray()}}static from(t,e,o,i=new Ie){if(o instanceof x.Euler)fe.setFromEuler(o);else if(o instanceof x.Quaternion)fe.copy(o);else throw new Error("传入的旋转不是欧拉角或者四元数");return le.compose(e,fe,Nr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(t,e,o,i=new Ie){const r=Fr({type:"Polygon",coordinates:[t.map(f=>[f.x,f.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Sn(s[0],s[1]),l=Sn(s[1],s[2]),c=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Te.set(a,l,o),vn.set(0,0,c);const[h,d]=Or(s);return e.x=h,e.y=d,this.from(Te,e,vn,i)}}const le=new x.Matrix4,fe=new x.Quaternion,vn=new x.Euler,Nr=new x.Vector3(1,1,1),Te=new x.Vector3,qr=new x.Box3;function Wr(n,t,e=.005,o=.2){if(!n.length||!t.length)return 0;const i=Math.max(e,.03),r=e*e,s=new Map,a=(d,u,f)=>`${Math.floor(d/i)},${Math.floor(u/i)},${Math.floor(f/i)}`;for(const d of t){const u=a(d.x,d.y,d.z);s.has(u)||s.set(u,[]),s.get(u).push(d)}let l=0;const c=Math.ceil(e/i)+1,h=[];for(let d=-c;d<=c;d++)for(let u=-c;u<=c;u++)for(let f=-c;f<=c;f++)d*d+u*u+f*f<=c*c&&h.push([d,u,f]);for(const d of n){const u=Math.floor(d.x/i),f=Math.floor(d.y/i),w=Math.floor(d.z/i);let y=!1;for(const[M,P,g]of h){const m=`${u+M},${f+P},${w+g}`;if(s.has(m)){for(const p of s.get(m))if(d.distanceToSquared(p)<r){y=!0;break}if(y)break}}if(y&&(l++,l/n.length>o))return l/n.length}return l/n.length}function pe(n,t,e=.5){let o=0,i=0;for(const r of n)if(t.containsPoint(r)&&(o++,i=o/n.length,i>e))break;return i}function Ye(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=we(n,o),s=we(t,e);if(r||s)return!0}return!1}function Dn(n,t){const e=new x.Vector3,o=new x.Vector3;n.getSize(e),t.getSize(o);const i=e.x*e.y*e.z,r=o.x*o.y*o.z;return i>r?1:i<r?-1:0}function we(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function _n(n){if(n.length===0)return{x:0,y:0,z:0,h:0};let t=0,e=0,o=-1/0,i=1/0;for(const r of n)t+=r.x,e+=r.y,o=Math.max(o,r.z),i=Math.min(i,r.z);return{x:t/n.length,y:e/n.length,z:0,maxz:o,minz:i,h:o-i}}function En(n,t,e,o){const i=[];for(let s=0;s<n.length;s++)i.push(new x.Vector3(n[s][0],n[s][1],0));if(i.length==0)return null;const r=Ie.fromByPath2D(i,t,e);return r.center.z=o,r}const Xr=n=>{if(n.length==0)return[];const t=[],e=new Map;for(let i=0;i<n.length;i++){let r=n[i].points.map(y=>[y.x,y.y]),s=n[i].obj_id;s=s.replace(/calcony railing/g,"balcony railing").replace(/glass balcony railing/g,"balcony railing").replace(/metal balcony railing/g,"balcony railing").replace(/temporary construction guardrail/g,"balcony railing").replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor"),s.split("_").slice(1,3).join("_").split(".")[0].split("_")[0];const a=s.indexOf("_")+1,l=s.lastIndexOf("_"),c=s.substring(a,l);if(c==="wall")continue;let h=[];for(let y=0;y<n[i].points.length;y++)h.push(new x.Vector3(n[i].points[y].x,n[i].points[y].y,n[i].points[y].z));let d=-99999;if(c==="floor"){let y=new Map;for(let P=0;P<n[i].points.length;P++){let g=n[i].points[P].z;if(g=Math.floor(g*10)/10,y.has(g)){const m=y.get(g);m.num+=1,m.points.push(n[i].points[P]),y.set(g,m)}else y.set(g,{num:1,points:[n[i].points[P]]})}let M=[...y.entries()].reduce((P,g)=>g[1].num>P[1].num?g:P);r=[],r=M[1].points.map(P=>[P.x,P.y]),h=[],h=M[1].points.map(P=>new x.Vector3(P.x,P.y,P.z)),d=M[0]}const u=_n(h),f={points:h,path:je(r),h:u.h,minz:u.minz,maxz:u.maxz,center:{x:u.x,y:u.y,z:u.z},obj_id:n[i].obj_id,type:c,averagePz:n[i].averagePz,obb:null,isDel:!1,obj_id:s,positionArr:[n[i].position]};if(f.obb=En(f.path,f.center,f.h,(f.maxz+f.minz)/2),f.obb==null)continue;let w=-1;for(let y=0;y<t.length;y++)if(t[y].type==c){w=y;break}if(w!=-1?t[w].array.push(f):t.push({type:c,array:[f]}),c=="floor"&&d!=-99999)if(e.has(d)){const y=e.get(d);y.num+=f.points.length,y.datas.push(f),e.set(d,y)}else e.set(d,{num:f.points.length,datas:[f]})}let o=-1/0;if(e.size>0){let i=[];for(const[r,s]of e.entries()){const{num:a,datas:l}=s;a>3e3&&(r>o&&(o=r),i.push(...l))}for(let r=0;r<t.length;r++)if(t[r].type=="floor"){t[r].array=i;break}}for(let i=0;i<t.length;i++){const r=t[i].array,s=[],a=[];for(let c=0;c<r.length;c++){if(r[c].obb==null||s.includes(c))continue;const h={...r[c],obb:r[c].obb.clone()};for(let d=c+1;d<r.length;d++){if(r[d].obb==null||s.includes(d))continue;if(h.obb.intersectsOBB(r[d].obb)){s.push(d);for(let y=0;y<r[d].points.length;y++)(r[d].points[y].z>o&&r[d].points[y].z-o>.1||h.type=="floor")&&h.points.push(r[d].points[y]);const f=h.points.map(y=>[y.x,y.y]);h.path=je(f);const w=_n(h.points);h.h=w.h,h.minz=w.minz,h.maxz=w.maxz,h.center={x:w.x,y:w.y,z:w.z},h.obb=En(h.path,h.center,h.h,(h.maxz+h.minz)/2),h.positionArr.push(...r[d].positionArr),d=c}}h.path.length>r[c].path.length&&(s.push(c),a.push(h))}const l=[];for(let c=0;c<r.length;c++)s.includes(c)||l.push(r[c]);l.push(...a),t[i].array=l}for(let i=0;i<t.length;i++){const r=t[i].type;if(r==="people"||r==="floor")continue;const s=t[i].array;for(let a=0;a<s.length;a++){const l=s[a].obb,c=s[a].minz;s[a].maxz;const h=s[a].averagePz;if(r==="window"||r==="door"||r==="tv"||r==="chair"||r==="cabinet"||r==="table"){const d=new x.Vector3;l.getSize(d);const u=[d.x,d.y,d.z];let f=0;for(const w of u)if(w<.2&&(f++,f===2)){s[a].isDel=!0;break}}if(!s[a].isDel)for(let d=i+1;d<t.length;d++){const u=t[d].type;if(u==="people"||u==="floor")continue;const f=t[d].array;for(let w=0;w<f.length;w++){if(f[w].isDel)continue;const y=f[w].obb,M=f[w].minz;if(f[w].maxz,l.intersectsOBB(y)){pe(f[w].points,l);const P=pe(s[a].points,y),g=Dn(l,y);if(P>=.3&&g==-1){s[a].isDel=!0;break}if(r!=="wall"&&r!=="floor"&&r!=="roof"){if(r==="window"){if(u==="balcony railing"&&we(l,f[w].points)){f[w].isDel=!0;continue}if(u==="balcony railing"&&we(y,s[a].points)){s[a].isDel=!0;break}if(u==="balcony railing"&&Ye(l,y,s[a].points,f[w].points)&&(Math.abs(c-M)<.1||Math.abs(M-h)>.3)){f[w].isDel=!0;continue}}else if(r==="balcony railing"){if(u==="window"&&we(l,f[w].points)){f[w].isDel=!0;continue}if(u==="window"&&we(y,s[a].points)){s[a].isDel=!0;break}if(u==="window"&&Ye(l,y,s[a].points,f[w].points)&&(Math.abs(c-M)<.1||Math.abs(c-h)>.3)){s[a].isDel=!0;break}}let m=!1,p=[],b=[];const z=s[a].points,v=f[w].points;if(z.length>v.length?(m=!0,p=z,b=v):(p=v,b=z),Wr(b,p,.03,.5)>.5)if(m)f[w].isDel=!0;else{s[a].isDel=!0;break}else if(Ye(l,y)){const V=Dn(l,y);if(V===1||V===0){if(u==="switch")continue;z.length>v.length?pe(b,l)>=.5&&(f[w].isDel=!0):pe(p,l)>=.5&&(f[w].isDel=!0)}else{if(r==="switch")continue;if(z.length>v.length){if(pe(p,y)>=.5){s[a].isDel=!0;break}}else if(pe(b,y)>=.5){s[a].isDel=!0;break}}}}}}if(s[a].isDel)break}}}for(let i=0;i<t.length;i++){const r=t[i].type,s=t[i].array;for(let a=0;a<s.length;a++){let l=s[a].maxz,c=s[a].minz,h=r==="switch"?.1:.3;const d=s[a].averagePz;if(Math.abs(l-d)<h){s[a].isDel=!0;continue}if(r==="window"||r==="door"||r==="tv"){const u=Math.abs(l-d),f=Math.abs(c-d);(r==="tv"&&f<1.6||r!=="window"&&u<1.6)&&(s[a].isDel=!0),r==="window"&&u<1&&(s[a].isDel=!0)}if(r==="chair"){const u=new x.Vector3;s[a].obb.getSize(u),(u.x<.1||u.y<.1||u.z<.2)&&(s[a].isDel=!0)}r==="balcony railing"&&(Math.abs(l-c)<.4&&(s[a].isDel=!0),(c<d&&Math.abs(c-d)>1||c>d&&Math.abs(c-d)>1)&&(s[a].isDel=!0),l<d&&(s[a].isDel=!0)),r==="people"&&(Math.abs(l-c)<1&&(s[a].isDel=!0),c>d&&c-d>.3&&(s[a].isDel=!0),l<d&&(s[a].isDel=!0)),r==="floor"&&s[a].points.length<500&&(s[a].isDel=!0)}}for(let i=0;i<t.length;i++)t[i].array=t[i].array.filter(r=>!r.isDel);return t};function $r(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Hr(n){if(!n.length)return 0;const t=[...n].sort((o,i)=>o-i),e=Math.floor(t.length/2);return t.length%2?t[e]:(t[e-1]+t[e])/2}function Yr(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),c=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2,h=Math.max(s,a,l);return c===0?{radius:1/0,maxEdge:h}:{radius:s*a*l/(4*c),maxEdge:h}}function Gr(n,t){const e=[],o=new Set,i=(r,s)=>r<s?`${r}_${s}`:`${s}_${r}`;for(let r=0;r<t.length;r+=3){const s=t[r],a=t[r+1],l=t[r+2],c=[[s,a],[a,l],[l,s]];for(const[h,d]of c){const u=i(h,d);if(o.has(u))continue;o.add(u);const[f,w]=n[h],[y,M]=n[d],P=Math.hypot(y-f,M-w);Number.isFinite(P)&&P>0&&e.push(P)}}return Hr(e)}function jr(n){const t=new Set,e=[];for(const o of n){if(!o||o.length<2)continue;const i=o[0],r=o[1];if(!Number.isFinite(i)||!Number.isFinite(r))continue;const s=`${i}_${r}`;t.has(s)||(t.add(s),e.push([i,r]))}return e}function Ur(n){const t=new Map;for(const[e,o]of n)t.has(e)||t.set(e,[]),t.has(o)||t.set(o,[]),t.get(e).push(o),t.get(o).push(e);return t}function Zr(n,t){if(!t.length)return[];const e=Ur(t),o=t[0][0],i=[],r=new Set;let s=o,a=-1;do{i.push(n[s]),r.add(s);const l=e.get(s)||[];let c=l.find(h=>h!==a&&!r.has(h));if(c===void 0&&(c=l.find(h=>h!==a)),c===void 0)break;a=s,s=c}while(s!==o&&i.length<=t.length+1);return i}function Kr(n,t={}){const{edgeFactor:e=20,alphaScale:o=2}=t;if(!n||n.length<3)return[];const i=jr(n);if(i.length<3)return[];const r=new ke(Float64Array.from(i.flat())),{triangles:s}=r;if(!s.length)return[];const a=Gr(i,s);if(!Number.isFinite(a)||a<=0)return[];const l=a*e,c=new Map,h=(f,w)=>f<w?`${f}_${w}`:`${w}_${f}`;for(let f=0;f<s.length;f+=3){const w=s[f],y=s[f+1],M=s[f+2],[P,g]=i[w],[m,p]=i[y],[b,z]=i[M],{radius:v,maxEdge:S}=Yr(P,g,m,p,b,z),V=$r(i,w,y,M)*o;if(v<=1/V&&S<=l){const D=[[w,y],[y,M],[M,w]];for(const[_,E]of D){const T=h(_,E);c.set(T,(c.get(T)||0)+1)}}}const d=[];for(const[f,w]of c)w===1&&d.push(f.split("_").map(Number));return d.length?Zr(i,d):[]}function be(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Qr(n){let t=0,e=0,o=0;for(let i=0;i<4;i++){const r=n[i],s=n[(i+1)%4],a=s.x-r.x,l=s.y-r.y,c=Math.sqrt(a*a+l*l);c>t&&(t=c,e=a/c,o=l/c)}return{longSide:t,dirX:e,dirY:o}}function Qe(n,t,e){const i=[];for(const r of n){const s=(r.start.x+r.end.x)/2,a=(r.start.y+r.end.y)/2,l=s-t,c=a-e;l*l+c*c<=3*3&&i.push(r.start.z,r.end.z)}if(i.length===0){const r=[];for(const s of n)r.push(s.start.z,s.end.z);return r.length?(r.sort((s,a)=>s-a),r[Math.floor(r.length/2)]):-1/0}return i.sort((r,s)=>r-s),i[Math.floor(i.length/2)]}function Gn(n,t,e,o,i,r){const s=i-e,a=r-o,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((n-e)**2+(t-o)**2),t:0};const c=n-e,h=t-o,d=(c*s+h*a)/l,u=e+d*s,f=o+d*a;return{dist:Math.sqrt((n-u)**2+(t-f)**2),t:d}}function Jr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((be(n.start,s.start)<=e||be(n.start,s.end)<=e)&&o++,(be(n.end,s.start)<=e||be(n.end,s.end)<=e)&&i++);let r=0;return o>=1&&i>=1?r=5:(o>=1||i>=1)&&(r=2),{left:o,right:i,score:r}}function ti(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Gn(a.x,a.y,o.x,o.y,i.x,i.y);e.push(l)}const r=e.reduce((a,l)=>a+l,0)/e.length,s=e.reduce((a,l)=>a+(l-r)**2,0)/e.length;return s<.01?3:s<.05?2:s<.1?1:0}function ei(n,t,e=.15){const o=n.end.x-n.start.x,i=n.end.y-n.start.y,r=Math.sqrt(o*o+i*i);if(r<1e-12)return 0;const s=-i/r,a=o/r,l=[[],[]];for(let d=0;d<2;d++){const u=d===0?n.start:n.end;for(const f of t){if(f===n)continue;const w=be(u,f.start),y=be(u,f.end);let M=null;if(w<=e?M=f.end:y<=e&&(M=f.start),!M)continue;const P=f.end.x-f.start.x,g=f.end.y-f.start.y,m=Math.sqrt(P*P+g*g);if(m<1e-12||Math.abs(o*P+i*g)/(r*m)>=.342)continue;const b=(M.x-u.x)*s+(M.y-u.y)*a;l[d].push(b>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const c=[...l[0],...l[1]];return c.every(d=>d===c[0])?2:1}function ni(n,t,e){const o=Jr(n,e),i=ti(n,t),r=ei(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function oi(n){const t=n.end.x-n.start.x,e=n.end.y-n.start.y;let o=Math.atan2(e,t)*(180/Math.PI);return o<0&&(o+=180),o}function ri(n,t){const e=[];for(const o of n){let i=!1;for(const r of e){const s=Math.abs(o.angle-r[0].angle);if(Math.min(s,180-s)<=t){r.push(o),i=!0;break}}i||e.push([o])}return e}function ii(n,t=.05){const e=[];for(const o of n){let i=!1;for(const r of e)if(Math.abs(o.offset-r[0].offset)<=t){r.push(o),i=!0;break}i||e.push([o])}return e}function si(n,t,e,o,i){const r=[];for(const a of n){const l=a.seg,c=(l.start.x-t.start.x)*e+(l.start.y-t.start.y)*o,h=(l.end.x-t.start.x)*e+(l.end.y-t.start.y)*o;r.push({l:Math.min(c,h),r:Math.max(c,h),idx:a.idx})}r.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:c}of r){if(s.length===0){s.push({l:a,r:l,srcIdxs:[c]});continue}const h=s[s.length-1];a<=h.r+i?(h.r=Math.max(h.r,l),h.srcIdxs.includes(c)||h.srcIdxs.push(c)):s.push({l:a,r:l,srcIdxs:[c]})}return s}function ai(n,t,e,o,i,r,s){const a=e-t,l={...n};return l.start={x:n.start.x+t*o,y:n.start.y+t*i,z:n.start.z},l.end={x:n.start.x+e*o,y:n.start.y+e*i,z:n.start.z},l.length=a,l.direction={x:o,y:i,z:0},l.rooftopPz=r,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function li(n,t){let e=!0;for(;e;){e=!1;for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o],s=n[i];if(r.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(r.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(r.end.x-s.start.x)<.001&&Math.abs(r.end.y-s.start.y)<.001,l=Math.abs(r.start.x-s.end.x)<.001&&Math.abs(r.start.y-s.end.y)<.001,c=Math.abs(r.end.x-s.end.x)<.001&&Math.abs(r.end.y-s.end.y)<.001,h=Math.abs(r.start.x-s.start.x)<.001&&Math.abs(r.start.y-s.start.y)<.001;if(!(a||l||c||h)||r.direction.x*s.direction.x+r.direction.y*s.direction.y<.98)continue;let u=r.start,f=r.end;a?f=s.end:l?u=s.start:c?f=s.start:h&&(u=s.end);const w=Math.hypot(f.x-u.x,f.y-u.y),y={...r};y.start=u,y.end=f,y.length=w,y.direction={x:(f.x-u.x)/w,y:(f.y-u.y)/w,z:0},y.rooftopPz=r.rooftopPz!==void 0?r.rooftopPz:s.rooftopPz,y.buildRosource=r.buildRosource||s.buildRosource,y.isRebuild=!1,y.doorAndBeamData||(y.doorAndBeamData=[]),y.insetionArr||(y.insetionArr=[]),n[o]=y,t[o]=[...new Set([...t[o],...t[i]])],n.splice(i,1),t.splice(i,1),i--,e=!0}}return{segments:n,sourceMap:t}}function Je(n,t=5,e=.05){if(n.length<=1)return{segments:n,sourceMap:n.map((l,c)=>[c])};const o=n.map((l,c)=>({seg:l,angle:oi(l),idx:c}));o.sort((l,c)=>l.angle-c.angle);const i=ri(o,t),r=[],s=[],a=[];for(const l of i){let c=l[0].seg;for(const P of l)P.seg.length>c.length&&(c=P.seg);const h=c.end.x-c.start.x,d=c.end.y-c.start.y,u=Math.sqrt(h*h+d*d);if(u<1e-12)continue;const f=-d/u,w=h/u,y=l.map(P=>{const g=P.seg.start.x-c.start.x,m=P.seg.start.y-c.start.y;return{seg:P.seg,offset:Math.abs(g*f+m*w),idx:P.idx}});y.sort((P,g)=>P.offset-g.offset);const M=ii(y);for(const P of M){let g=P[0].seg;for(const E of P)E.seg.length>g.length&&(g=E.seg);const m=g.end.x-g.start.x,p=g.end.y-g.start.y,b=Math.sqrt(m*m+p*p);if(b<1e-12)continue;const z=m/b,v=p/b,S=P.map(E=>E.seg.rooftopPz??0),V=Math.max(...S),D=[...new Set(S.map(E=>E.toFixed(3)))];if(D.length>1){const E=P.map(T=>({idx:T.idx,start:{x:T.seg.start.x,y:T.seg.start.y,z:T.seg.start.z},end:{x:T.seg.end.x,y:T.seg.end.y,z:T.seg.end.z},length:T.seg.length,rooftopPz:T.seg.rooftopPz??0}));a.push({values:[...D],segments:E})}[...new Set(P.map(E=>String(E.seg.buildRosource)))];const _=si(P,g,z,v,e);for(const{l:E,r:T,srcIdxs:A}of _){if(T-E<.01)continue;const O=ai(g,E,T,z,v,V,g.buildRosource);r.push(O),s.push(A)}}}return{...li(r,s),debugRPZGroups:a}}function ci(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function ui(n,t,e){return[{x:t,y:e,z:0},{x:n[0].x,y:n[0].y,z:0},{x:n[1].x,y:n[1].y,z:0},{x:n[2].x,y:n[2].y,z:0},{x:n[3].x,y:n[3].y,z:0}]}function hi(n,t,e,o,i,r,s){const a=[{margin:r.projectionMargin,maxDist:r.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const c of a){if(l.length>0)break;for(const h of n){const d=t*r.minLengthRatio;if(h.length<d)continue;const{start:u,end:f}=h;let w=!1,y=1/0;for(const S of i){const{dist:V,t:D}=Gn(S.x,S.y,u.x,u.y,f.x,f.y);D>=-c.margin&&D<=1+c.margin&&V<=c.maxDist&&(w=!0,y=Math.min(y,V))}if(!w){`${c.maxDist}${(-c.margin).toFixed(1)}${(1+c.margin).toFixed(1)}`;continue}const M=Math.sqrt((f.x-u.x)**2+(f.y-u.y)**2);if(M<1e-12)continue;const P=(f.x-u.x)/M,g=(f.y-u.y)/M,m=Math.abs(e*P+o*g),p=Math.abs(-o*P+e*g),b=Math.max(m,p),z=Math.acos(Math.min(b,1))*(180/Math.PI);if(z>r.angleThreshold){`${z.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(M>.01){const S=[];for(let _=1;_<=4;_++){const E=i[_],T=E.x-u.x,A=E.y-u.y,O=(T*P+A*g)/M;S.push(O)}const V=Math.min(...S),D=Math.max(...S);D>V&&(v=Math.max(0,Math.min(1,D)-Math.max(0,V))/(D-V))}l.push({seg:h,minDist:y,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function fi(n,t,e,o){if(n.length<=1)return n.length===1&&(n[0].score=-1),n;for(const i of n){const{score:r,details:s}=ni(i.seg,t,e);i.score=r,i.details=s}return n.sort((i,r)=>r.embedRatio-i.embedRatio||r.score-i.score||i.minDist-r.minDist),n}function di(n,t,e,o){const i=n.end.x-n.start.x,r=n.end.y-n.start.y,s=Math.sqrt(i*i+r*r),a=i/s,l=r/s,c=t.map(v=>{const S=v.x-n.start.x,V=v.y-n.start.y;return(S*a+V*l)/s}),h=Math.min(...c),d=Math.max(...c),u=(d-h)*s,f=(h+d)/2,w=n.start.x+f*i,y=n.start.y+f*r,M=e.box.min.z,P=e.box.max.z,g=Math.abs(P-M),m=Qe(o,n.start.x,n.start.y),p=Math.max(0,M-m),b=h<=0&&d>=1,z=n.start.z+f*(n.end.z-n.start.z);return{p:{x:w,y,z},width:u,full:b,height:g,groundClearance:p}}function jn(n,t,e){var h,d,u,f,w;const o=t.map(y=>e[y]),i=[],r=[],s=[],a=[],l=[];let c;for(const y of o){if((h=y.points)!=null&&h.length)for(const M of y.points)i.push(M);if((d=y.originalPoints)!=null&&d.length)for(const M of y.originalPoints)r.push(M);if((u=y.doorAndBeamData)!=null&&u.length)for(const M of y.doorAndBeamData)s.push(M);if((f=y.insetionArr)!=null&&f.length)for(const M of y.insetionArr)a.push(M);if((w=y.drawWindow)!=null&&w.length)for(const M of y.drawWindow)l.push(M);y.boxData&&!c&&(c=y.boxData)}i.length&&(n.points=i),r.length&&(n.originalPoints=r),s.length&&(n.doorAndBeamData=s),a.length&&(n.insetionArr=a),l.length&&(n.drawWindow=l),c&&(n.boxData=c)}function Un(n,t,e,o){var c;const i=ci(e),r=[],{segments:s,sourceMap:a}=o??Je(t),l=s;for(const h of n){const d=(c=h.coordinatesByArea)==null?void 0:c.coordinates;if(!d||d.length<4)continue;const u=d.slice(0,4),f=u.reduce((D,_)=>D+_.x,0)/4,w=u.reduce((D,_)=>D+_.y,0)/4,{longSide:y,dirX:M,dirY:P}=Qr(u);if(y<.01)continue;const g=u.reduce((D,_)=>D+_.z,0)/4,m=Qe(t,f,w);if(g<m-.3)continue;const p=ui(u,f,w);h.name;let b=hi(l,y,M,P,p,i,h.name);b=fi(b,p,t,h.name);let z=null,v=1/0,S=0;if(b.length>0){const D=b[0];z=D.seg,v=D.minDist,S=D.ratio}let V;if(z&&(V=di(z,u,h,s),!i.printOnly)){const D=z;D.drawWindow||(D.drawWindow=[]),D.drawWindow.push(V)}z&&r.push({windowName:h.name,windowCategory:h.category,windowCenter:h.center,wallSegment:z,distance:v,wallLengthRatio:S,drawWindow:V})}for(const h of r){const d=h.wallSegment,u=s.indexOf(d);if(u===-1)continue;const f=a[u];!f||f.length<=1||jn(d,f,t)}return r}function mi(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(u=>u&&u.category==="window"&&!u.isBayWindowObj):[],{segments:r,sourceMap:s}=Je(n),a=Un(i,n,o,{segments:r,sourceMap:s}),l=new Set;for(const u of a){const f=r.indexOf(u.wallSegment);f>=0&&l.add(f)}const c=[],h=new Set;for(const u of l){const f=s[u];if(f){jn(r[u],f,n);for(const w of f)h.add(w)}c.push(r[u])}for(let u=0;u<n.length;u++)h.has(u)||c.push(n[u]);const d=new Set(a.map(u=>u.windowName));for(const u of t)u&&u.category==="window"&&!u.isBayWindowObj&&(d.has(u.name)?delete u.AbnormalWindow:u.AbnormalWindow=!0);for(const u of a)u.drawWindow&&u.wallSegment&&(u.wallSegment.drawWindow||(u.wallSegment.drawWindow=[]),u.wallSegment.drawWindow.push(u.drawWindow));return{segments:c,matches:a}}exports.computeContour=je;exports.computeContourNew=Kr;exports.computeLocalFloorZ=Qe;exports.findWindowWalls=Un;exports.getAllGeometry=mo;exports.getBeamLine=Vo;exports.getColLine=zo;exports.getMergeMeaning=Xr;exports.mergeCollinearSegments=Je;exports.processData=mi;exports.updateStEdPoint=go;