rm-graphical-computing 1.0.62 → 1.0.63

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 +1273 -1239
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var $n=Object.defineProperty;var Gn=(n,t,e)=>t in n?$n(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Ie=(n,t,e)=>Gn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function jn(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=jn(lt);function Un(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 f=n[h];let u=0;if(e!==(f.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 g in f.attributes){if(!o.has(g))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+g+'" attribute exists among all geometries, or in none of them.'),null;r[g]===void 0&&(r[g]=[]),r[g].push(f.attributes[g]),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!==f.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const g in f.morphAttributes){if(!i.has(g))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[g]===void 0&&(s[g]=[]),s[g].push(f.morphAttributes[g])}if(t){let g;if(e)g=f.index.count;else if(f.attributes.position!==void 0)g=f.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,g,h),c+=g}}if(e){let h=0;const f=[];for(let u=0;u<n.length;++u){const g=n[u].index;for(let w=0;w<g.count;++w)f.push(g.getX(w)+h);h+=n[u].attributes.position.count}l.setIndex(f)}for(const h in r){const f=Ue(r[h]);if(!f)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,f)}for(const h in s){const f=s[h][0].length;if(f===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let u=0;u<f;++u){const g=[];for(let x=0;x<s[h].length;++x)g.push(s[h][x][u]);const w=Ue(g);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 Ue(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 f=l/e;for(let u=0,g=h.count;u<g;u++)for(let w=0;w<e;w++){const x=h.getComponent(u,w);a.setComponent(u+f,w,x)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const Zn=(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))},Kt=(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,f=((e.x-n.x)*s-(e.y-n.y)*r)/c;return h<-i||h>1+i||f<-i||f>1+i?null:{point:new y.Vector3(n.x+h*r,n.y+h*s,n.z)}},Kn=(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 g=Math.min(u+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=g,x.height=w;const P=x.getContext("2d");P.fillStyle=r,P.fillRect(0,0,g,w),P.fillStyle=s,P.font=`bold ${o}px ${i}`,P.textAlign="center",P.textBaseline="middle",u>l-a*2?Qn(P,n,g/2,w/2,l,o):P.fillText(n,g/2,w/2);const M=new y.CanvasTexture(x),m=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),d=new y.Sprite(m);d.position.set(t.x,t.y,t.z);const p=.005;return d.scale.set(g*p,w*p,1),d};function Qn(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 f=a+s[h];n.measureText(f).width>i&&h>0?(n.fillText(a,e,c),a=s[h],c+=l):a=f}n.fillText(a,e,c)}const te=(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}},Jn=(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 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 c=1/0,h=-1/0,f=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<f&&(f=S),S>u&&(u=S)}const g=i[0].dot(l),w=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(g)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(g)),P=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(g)),M=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(g));let m=[w,x,P,M],d=te(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));d&&d.parallel&&(m=[w,M,P,x]);let p=0;if(o.length>0){const z=new y.Vector3().subVectors(m[1],m[0]).normalize(),v=z.clone().negate(),S=new y.Vector3().subVectors(m[3],m[0]).normalize(),V=S.clone().negate();let D=m[0].distanceTo(m[1]),_=m[0].distanceTo(m[3]),E=D/t,T=_/e,A=.001;for(let F=0;F<E;F++){let I=m[0],B=0;for(let L=0;L<T;L++){let W=I.clone().addScaledVector(z,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>=T/2)break;p+=B,m[0]=m[0].addScaledVector(z,t),m[3]=m[3].addScaledVector(z,t)}D=m[0].distanceTo(m[1]),E=D/t;for(let F=0;F<E;F++){let I=m[1],B=0;for(let L=0;L<T;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>=T/2)break;p+=B,m[1]=m[1].addScaledVector(v,t),m[2]=m[2].addScaledVector(v,t)}D=m[0].distanceTo(m[1]),E=D/t;for(let F=0;F<T;F++){let I=m[3],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(z,t),C=W.clone().addScaledVector(V,e),R=I.clone().addScaledVector(V,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>=E/2)break;p+=B,m[2]=m[2].addScaledVector(V,e),m[3]=m[3].addScaledVector(V,e)}}const b=m[0].distanceTo(m[1])*m[0].distanceTo(m[3]);return{facePoints:m,boxArea:b,totalInPlaneNum:p}},ie=(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)),c=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:c,angle:l,angleDeg:y.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},ee=(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)),c=Math.min(1,Math.max(0,l)),h=Math.acos(c),f=y.MathUtils.radToDeg(h),u=1-c;return{rate:u,percent:`${(u*100).toFixed(2)}%`,angle:f,isPerpendicular:Math.abs(f-90)<.01,isParallel:f<.01}},Qt=(n,t,e=!1)=>new y.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),Jt=(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,c=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),f=c.clone().normalize(),u=h.clone().normalize();let g=y.MathUtils.clamp(f.dot(u),-1,1);const w=Math.acos(Math.abs(g)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};g<0&&u.negate();const P=new y.Vector3().addVectors(f,u).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),m=Ze(e,M,f),d=Ze(o,M,f),p=(m+d)/2,b=Math.max(m,d),z=n.dot(P),v=t.dot(P),S=e.dot(P),V=o.dot(P),D=Math.min(z,v),_=Math.max(z,v),E=Math.min(S,V),T=Math.max(S,V),A=_-D,F=T-E,I=Math.min(A,F),B=Math.min(_,T)-Math.max(D,E),L=B<0?-B:0,W=B>0?B:0,C=I>0?W/I:0,R=to(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 Ze(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 to(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),c=r.dot(r),h=i.dot(s),f=r.dot(s),u=a*c-l*l;let g,w;u<1e-10?(g=0,w=c!==0?f/c:0):(g=(l*f-c*h)/u,w=(a*f-l*h)/u),g=y.MathUtils.clamp(g,0,1),w=c!==0?y.MathUtils.clamp((l*g+f)/c,0,1):0,g=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(g)),P=e.clone().add(r.clone().multiplyScalar(w));return x.distanceTo(P)}const Ke=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),eo=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=Ke(o,100),s=Ke(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 c=new y.Line3(t,e);const h=n.originalPoints,f=new y.Vector3;for(let x=0;x<h.length;x++){const P=h[x];let m=c.closestPointToPoint(P,!0,f).distanceTo(P);const d=Math.floor(m/a);if(d<s){const p=l.get((d+1)*a);p.count++,P.z<p.minZ&&(p.minZ=P.z),P.z>p.maxZ&&(p.maxZ=P.z)}}let u,g,w=r/2;for(const[x,P]of l)if(P.count>=w){u=P.minZ;break}for(const[x,P]of[...l.entries()].reverse())if(P.count>=w){g=P.maxZ;break}return{minZ:u,maxZ:g}},Me=(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 c=new y.Vector3,h=new y.Vector3;o.projectPoint(i,c),o.projectPoint(r,h);const f=new y.Line3(c,h),u=[],g=[],w=[];let x=new y.Vector3;return a.forEach((P,M)=>{f.closestPointToPoint(P,!0,x).distanceTo(P)<.001?(u.push(e[M]),g.push(l[M])):w.push(P)}),{newOriginalPoints:u,newProjectPoints:w,newOnLinePoints:g}},no=n=>{function t(e,o,i,r,s,a,l,c,h){let f=new y.Line3(e,o),u=new Map,g=new y.Vector3,w=e.clone(),x=o.clone(),P=0;for(;;){let M=new Map,m=0;for(let d=0;d<h.checkResults.length;d++)if(!(h.checkResults[d].allCenterPoints.length/c*100<1))for(let b=0;b<h.checkResults[d].allCenterPoints.length;b++){if(u.has(d)&&u.get(d).removePtsIndex.includes(b))continue;let z=h.checkResults[d].allCenterPoints[b];z=new y.Vector3(z.x,z.y,z.z);let v=f.closestPointToPoint(z,!0,g),S=z.distanceTo(v);Math.abs(S-s)<.01&&(m++,M.has(d)?M.get(d).removePtsIndex.push(b):M.set(d,{index:d,removePtsIndex:[b]}))}if(P==l){e=w,o=x;break}if(m<a/20*18||m==0){M.clear(),l-P<5&&(e=w,o=x,u.clear());break}else{P++;for(const[d,p]of M)u.has(d)?u.get(d).removePtsIndex.push(...p.removePtsIndex):u.set(d,p);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),f.set(e,o)}}if(u.size>0&&P!=l)for(const[M,m]of u){let d=[],p=[];for(let b=0;b<h.checkResults[M].allCenterPoints.length;b++)m.removePtsIndex.includes(b)||(d.push(h.checkResults[M].allCenterPoints[b]),p.push(h.checkResults[M].originalVertices[b]));h.checkResults[M].allCenterPoints=d,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[V,D,_,E]=S;V=new y.Vector3(V.x,V.y,V.z),D=new y.Vector3(D.x,D.y,D.z),_=new y.Vector3(_.x,_.y,_.z),E=new y.Vector3(E.x,E.y,E.z),i=V.distanceTo(D),r=V.distanceTo(E);let T=new y.Vector3().subVectors(V,D).normalize(),A=te(T,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),c=o.rooftopPz-o.start.z,h=Math.ceil(l/i),f=Math.ceil(c/r);let u=s.clone(),g=a.clone(),w=g.clone().add(new y.Vector3(0,0,c)),x=u.clone().add(new y.Vector3(0,0,c)),P=new y.Vector3().subVectors(g,u).normalize(),M=P.clone().negate();new y.Vector3().subVectors(w,u).normalize().clone().negate();let d=i/2,p=l*c,b=i*r,z=p/b;t(u,x,P,i,d,f,h,z,o),t(g,w,M,i,d,f,h,z,o),o.start=u,o.end=g;const{newOriginalPoints:v}=Me(u,g,o.originalPoints);o.originalPoints=v}},jt=(n,t)=>new y.Vector3(n.x,n.y,0).distanceTo(new y.Vector3(t.x,t.y,0)),oo=(n,t,e=1e-6)=>{const o=new y.Vector3;return n.closestPointToPoint(t,!0,o),o.distanceTo(t)<e},Qe=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},Tt=(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,ro=()=>{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}`},io=(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 so{constructor(){Ie(this,"results");Ie(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 c=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]),f=[0,1,2,0,2,3],u=new Float32Array([0,0,1,0,1,1,0,1]);c.setAttribute("position",new y.BufferAttribute(h,3)),c.setAttribute("uv",new y.BufferAttribute(u,2)),c.setIndex(f),c.computeVertexNormals();const g=new y.Mesh(c,r),w=new y.EdgesGeometry(c),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),g}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),c=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),f=[a,l,c,h];for(let m=0;m<f.length;m++)if(!this.isValidVector3(f[m]))return console.error(`墙体基础点${m}无效:`,f[m]),s;const u=a.distanceTo(l),g=Math.abs(t.rooftopPz-t.start.z);if(u===0||g===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,x=g/e,P=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let m=0;m<e;m++)for(let d=0;d<o;d++)try{const p=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar(m*x)),b=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar(m*x)),z=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar((m+1)*x)),v=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar((m+1)*x)),S={points:[p,b,z,v],userData:{}};S.userData={type:"wallSegment",row:m,col:d,originalMaterial:i,width:w,height:x},s.push(S)}catch(p){console.error(`创建墙体小平面(${m}, ${d})时出错:`,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 f=!0;return r<.5&&e>0&&(f=this.checkSmallAreaDistribution(t,o,i)),c&&h&&f}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}`,[c,h,f,u]=s.vertices,g=new y.Vector3().subVectors(h,c).normalize(),w=new y.Vector3().subVectors(u,c).normalize(),x=c.distanceTo(h),P=c.distanceTo(u),M=new y.Plane;M.setFromCoplanarPoints(c,h,u);const m=x/2,d=P/2;for(let p=0;p<e.length;p++)this.isPointInWallSegmentOptimized(e[p],a,M,c,g,w,x,P,m,d,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,f){if(Math.abs(o.distanceToPoint(t))>f)return!1;const g=new y.Vector3().subVectors(t,e),w=Math.abs(g.dot(r)),x=Math.abs(g.dot(s));if(w>c&&x>h)return!1;const P=new y.Vector3().subVectors(t,i),M=P.dot(r),m=P.dot(s),d=M>=-f&&M<=a+f,p=m>=-f&&m<=l+f;return d&&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 y.Plane;if(c.setFromCoplanarPoints(r,s,l),Math.abs(c.distanceToPoint(e))>i)return!1;const f=new y.Vector3().subVectors(s,r).normalize(),u=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(f,u).normalize();const g=new y.Vector3().subVectors(e,r),w=g.dot(f),x=g.dot(u),P=r.distanceTo(s),M=r.distanceTo(l),m=w>=-i&&w<=P+i,d=x>=-i&&x<=M+i;return m&&d&&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 f;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 g=`row${u.userData.row}_col${u.userData.col}`,w=r.has(g);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:g,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,g]of r){const w=(f=s.get(g.row))==null?void 0:f.get(g.col);if(w&&!w.visited){const x=[],P=[[g.row,g.col]];for(w.visited=!0;P.length>0;){const[M,m]=P.shift(),d=`row${M}_col${m}`;r.has(d)&&x.push(r.get(d));for(const[p,b]of l){const z=M+p,v=m+b;if(s.has(z)&&s.get(z).has(v)){const S=s.get(z).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,P.push([z,v]))}}}x.length>=i&&a.push(x)}}const c=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((u,g)=>g.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 x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const c=o;let h=!0;for(let x=i;x<=r;x++)t.has(c)&&t.get(c).has(x)||(h=!1);h&&s++;const f=i;let u=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(f)||(u=!1);u&&s++;const g=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(g)||(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 f,u;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(g=>{g.vertices&&g.vertices.length>0&&e.push(...g.vertices)}),e.length===0){const g=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((f=t[0].bounds)==null?void 0:f.width)||1),height:g.length*(((u=t[0].bounds)==null?void 0:u.height)||1)}}const o=Math.min(...e.map(g=>g.x)),i=Math.max(...e.map(g=>g.x)),r=Math.min(...e.map(g=>g.y)),s=Math.max(...e.map(g=>g.y)),a=Math.min(...e.map(g=>g.z)),l=Math.max(...e.map(g=>g.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 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(),c=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),f=new y.ArrowHelper(a,r,.2,255);e.add(c),e.add(h),e.add(f)}}),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=Un(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 ao=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},lo=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}},co=(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(Kn(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)),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)),f=Math.abs(r.rooftopPz-r.start.z),u=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),g=new y.Group,w=new so,{horizontalSubdivisions:x,verticalSubdivisions:P}=w.initLimits4(h,f),M=w.createSubdividedWallPlane(r,P,x,u,g);w.analyzePointDistribution(M,c,.01);const m=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),d=w.highlightEmptySegments(M,m,g),p=[];for(const v of d.clusters){const S=ao(v);S&&p.push(S)}const z=lo(r).direction;r.checkResults=p,r.verticalDirection=z,r.originaIndex=i,o.push(r)}return o},uo=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(d=>{let p=new y.Vector3(d.x,d.y,0),b=!1;for(let z=0;z<i.length;z++)if(Tt(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 y.Vector3(o.start.x,o.start.y,o.start.z),l=new y.Vector3(o.end.x,o.end.y,o.end.z),c=new y.Vector3().subVectors(l,a).normalize(),h=c.clone().cross(new y.Vector3(0,0,1)).normalize(),f=h.clone().negate(),u=[];const g=[];let w=o.length/r;console.log(w);for(let d=0;d<r;d++){const p=[];p.push(a.clone().addScaledVector(h,s)),p.push(p[0].clone().addScaledVector(c,w)),p.push(p[1].clone().addScaledVector(f,s*2)),p.push(a.clone().addScaledVector(f,w));let b=[];for(let z=0;z<i.length;z++)u.includes(z)||fo(i[z],p)&&(u.push(z),b.push(i[z]));b.length>0&&g.push(mo(b)),a=a.addScaledVector(c,w)}const x=new Float32Array(i.length*3);i.forEach((d,p)=>{x[p*3]=d.x,x[p*3+1]=d.y,x[p*3+2]=d.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:ro(),size:.02})));const[M,m]=xo(g,{plane:"xy",trimRatio:0});Zn(M,m,t)}};function Je(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 ho(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 fo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=Je(n,e),i=t.map(a=>Je(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],c=i[(a+1)%4],h=ho(l,c,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function mo(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 go(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 po(n,t="xy"){const e=go(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 tn(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 yo(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 xo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>po(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,W=B.y-s;l+=L*L,c+=L*W,h+=W*W}l/=i.length,c/=i.length,h/=i.length;const f=yo(l,c,h),u={x:-f.y,y:f.x},g=[];for(const B of i){const L=B.x-r,W=B.y-s,C=L*f.x+W*f.y,R=L*u.x+W*u.y;g.push({s:C,t:R,up:B.up})}g.sort((B,L)=>B.s-L.s);const w=g.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=g[x],m=g[P],d=(()=>{const B=g.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=g.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,z=m.s,v=d,S=d,V=p,D=p,_=r+f.x*b+u.x*v,E=s+f.y*b+u.y*v,T=r+f.x*z+u.x*S,A=s+f.y*z+u.y*S,F=tn(_,E,V,e),I=tn(T,A,D,e);return[F,I]}const wo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let d=0;d<o.length;d++){const p=o[d];p.isLine2=!0,n.push(p)}if(no(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const d of n){let p=[];if(!(!d.checkResults||d.checkResults.length<=0)){for(let b=0;b<d.checkResults.length;b++){let D=function(A){for(;V[A]!==A;)V[A]=V[V[A]],A=V[A];return A};const z=d.checkResults[b];if(z.isDoor=!1,!z.originalVertices||z.originalVertices.length==0)continue;const v=[];z.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,V=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&&(V[W]=C)}}const _=new Map;let E=-1,T=-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),E==-1||T==-1){let H=new y.Vector3().subVectors(B,L).normalize();T=B.distanceTo(C),E=B.distanceTo(L);let X=te(H,new y.Vector3(0,0,1));X&&X.parallel&&([T,E]=[E,T])}I.gridWidth=E,I.gridHeight=T}p.push(..._.values())}d.mergeCheckRegion=p}}let r=new Map;for(const d of n){if(d.length<.3)continue;let p=d.rooftopPz-d.start.z,b=Math.floor(d.rooftopPz-d.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((d,p)=>p[1].num>d[1].num?p:d);s[0],s[1].totalHeight/s[1].num;const a=[];for(let d=0;d<e.length;d++){const p=e[d];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 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=Qt(b[0],b[3],!0),V=Qt(b[1],b[2],!0);a.push({doorStartPt:S,doorEndPt:V,boxPoints:b,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:d,isFind:!1,inWall:!1})}}for(let d=0;d<a.length;d++){const p=a[d];for(let b=0;b<n.length;b++){if(n[b].length<.5)continue;let z=[];const v=Qt(n[b].start,n[b].end,!0);z.push(v),z.push(Qt(v,n[b].start,!0)),z.push(Qt(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 F=p.boxPoints[T].x,I=p.boxPoints[T].y,B=p.boxPoints[A].x,L=p.boxPoints[A].y;I>E!=L>E&&_<(B-F)*(E-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),E=p.doorStartPt.distanceTo(p.doorEndPt),T=D.distanceTo(_),A=ie(p.doorStartPt,p.doorEndPt,D,_);if(Math.abs(T-E)<.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(T-E)>1.3&&A&&A.angleDeg<15){let F=Jt(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),nt=H.distanceTo(p.doorStartPt),U=X.distanceTo(p.doorEndPt);if(nt<.1||U<.1){p.inWall=!0;break}}}}else continue}}let l=0,c=[],h=[],f=[];const u=[];let g=.15;for(let d=0;d<n.length;d++){const p=n[d];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 z=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 V=p.rooftopPz-p.start.z,D=0;for(const E of p.mergeCheckRegion){const{facePoints:T,boxArea:A,totalInPlaneNum:F}=Jn(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 y.Vector3(T[0].x,T[0].y,T[0].z+B),W=new y.Vector3(T[1].x,T[1].y,T[1].z+B);const C=new y.Line3(L,W),R=[];let H=new y.Vector3;E.points.forEach(ot=>{C.closestPointToPoint(ot,!0,H).distanceTo(ot)<E.gridHeight+.01&&R.push(ot)});let X=[],nt=[];for(;;){let ot=[];for(let O=0;O<R.length;O++)nt.includes(O)||ot.length==0&&(ot.push(R[O]),nt.push(O));for(let O=0;O<R.length;O++)if(!nt.includes(O)){for(let Y=0;Y<ot.length;Y++)if(R[O].distanceTo(ot[Y])<E.gridWidth+.01){ot.push(R[O]),nt.push(O),O=-1;break}}if(ot.length==0)break;X.push(ot)}const U=[];for(let ot=0;ot<X.length;ot++){const O={lineSt:new y.Vector3,lineEd:new y.Vector3,facePoints:[]};let Y=Qe(X[ot]);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,T[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,T[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,T[2].z)),O.facePoints.push(new y.Vector3(Y[0].x,Y[0].y,T[2].z)),U.push(O))}D+=E.area;let $=0;if(F!=0&&($=E.gridHeight*E.gridWidth*F),(E.area-$)/A*100>70&&U.length==1||U.length>1)for(let ot=0;ot<U.length;ot++){const O=U[ot];let Y=O.facePoints[0].distanceTo(O.facePoints[1]),Mt=O.facePoints[0].distanceTo(O.facePoints[3]),Gt=Y/p.length*100,Ft=p.rooftopPz-O.facePoints[2].z;if(Mt<1.5||z<O.facePoints[2].z||Ft>V/3*2)continue;let Bt=!1,vt=!1,Dt=!1,It=[],Q=O.facePoints[2].clone(),ct=O.facePoints[3].clone(),q=O.facePoints[0].clone(),G=O.facePoints[1].clone(),Lt=!1,_t=-1;if(Math.abs(O.facePoints[0].z-p.start.z)<.25){if(Y>.17&&p.length>.5){let Wt=jt(v,q),K=jt(v,G),ut=jt(S,q),N=jt(S,G);const bt=.1,Vt=10;if(Wt<bt||K<bt){const{newOriginalPoints:$t}=Me(q,G,p.originalPoints),at=[];if($t.forEach(J=>{J.z>=Q.z?at.push(J):J.z<=q.z}),at.length>10){const J=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Pt=new y.Vector3().subVectors(J,pt).normalize();let Ht=new y.Vector3,ft=1/0,j=-1,k=!1,dt=!1;for(let it=0;it<n.length;it++){if(it==d)continue;const st=new y.Vector3(n[it].start.x,n[it].start.y,0),mt=new y.Vector3(n[it].end.x,n[it].end.y,0),At=Kt(J,pt,st,mt);let zt=ee(J,pt,st,mt);if(At!=null){if(zt&&zt.angle>85){let Rt=At.point.distanceTo(J);if(At.point.distanceTo(pt),Rt<.3){dt=!0,ft=1/0,j=-1;break}}continue}if(zt&&zt.angle>85){const Z=new y.Line3(st,mt).closestPointToPoint(J,!0,Ht);let yt=ie(J,pt,Z,J);if(!yt||yt.direction!="same")continue;const tt=J.clone().addScaledVector(Pt,Vt),rt=pt.clone().addScaledVector(Pt.clone().negate(),Vt);let wt=new y.Vector3().subVectors(mt,st).normalize(),kt=st.clone().addScaledVector(wt.clone().negate(),.03),Nt=mt.clone().addScaledVector(wt,.03);const Ot=Kt(tt,rt,kt,Nt);if(Ot==null)continue;let Ut=J.distanceTo(Ot.point);Ut<ft&&(ft=Ut,j=it)}else if(zt&&zt.angle<5){const Rt=new y.Vector3(q.x,q.y,0),Z=new y.Vector3(G.x,G.y,0);let yt=jt(Rt,st),tt=jt(Rt,mt),rt=jt(Z,st),wt=jt(Z,mt);if(yt<.08||tt<.08||rt<.08||wt<.08){k=!0,ft=1/0,j=-1;break}}}if(ft!=1/0&&ft<2&&p.length-Y>.2&&ft<Y*3)n[j].length>.25&&Y+ft>.5&&(Lt=!0,Wt<bt?(ct=ct.addScaledVector(Pt,ft),q=q.addScaledVector(Pt,ft)):(Q=Q.addScaledVector(Pt,ft),G=G.addScaledVector(Pt,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<bt||N<bt){const{newOriginalPoints:$t}=Me(q,G,p.originalPoints),at=[];if($t.forEach(J=>{J.z>=Q.z?at.push(J):J.z<=q.z}),at.length>10){const J=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Pt=new y.Vector3().subVectors(pt,J).normalize();let Ht=new y.Vector3,ft=1/0,j=-1,k=!1,dt=!1;for(let it=0;it<n.length;it++){if(it==d)continue;const st=new y.Vector3(n[it].start.x,n[it].start.y,0),mt=new y.Vector3(n[it].end.x,n[it].end.y,0),At=Kt(J,pt,st,mt);let zt=ee(J,pt,st,mt);if(At!=null){if(zt&&zt.angle>85&&(At.point.distanceTo(J),At.point.distanceTo(pt)<.3)){dt=!0,ft=1/0,j=-1;break}continue}if(zt&&zt.angle>85){const Z=new y.Line3(st,mt).closestPointToPoint(pt,!0,Ht);let yt=ie(pt,J,Z,pt);if(!yt||yt.direction!="same")continue;const tt=J.clone().addScaledVector(Pt.clone().negate(),Vt),rt=pt.clone().addScaledVector(Pt,Vt);let wt=new y.Vector3().subVectors(mt,st).normalize(),kt=st.clone().addScaledVector(wt.clone().negate(),.03),Nt=mt.clone().addScaledVector(wt,.03);const Ot=Kt(tt,rt,kt,Nt);if(Ot==null)continue;let Ut=pt.distanceTo(Ot.point);Ut<ft&&(ft=Ut,j=it)}else if(zt&&zt.angle<5){const Rt=new y.Vector3(q.x,q.y,0),Z=new y.Vector3(G.x,G.y,0);let yt=jt(Rt,st),tt=jt(Rt,mt),rt=jt(Z,st),wt=jt(Z,mt);if(yt<.08||tt<.08||rt<.08||wt<.08){k=!0,ft=1/0,j=-1;break}}}if(ft!=1/0&&ft<2&&p.length-Y>.2&&ft<Y*3)n[j].length>.25&&Y+ft>.5&&(Lt=!0,ut<bt?(ct=ct.addScaledVector(Pt,ft),q=q.addScaledVector(Pt,ft)):(Q=Q.addScaledVector(Pt,ft),G=G.addScaledVector(Pt,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(Q)}if(Gt<85&&Y>.3||Y>.7&&Mt>V-V/3){let Wt=!1;for(let K=0;K<t.length;K++){let ut=K+1;if(ut>=t.length)continue;let N=new y.Vector3(t[K].x,t[K].y,t[K].z),bt=new y.Vector3(t[ut].x,t[ut].y,t[ut].z);if(Kt(new y.Vector3(N.x,N.y,0),new y.Vector3(bt.x,bt.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){Wt=!0;break}}for(let K=0;K<a.length;K++){let ut=new y.Vector3(a[K].doorStartPt.x,a[K].doorStartPt.y,0),N=new y.Vector3(a[K].doorEndPt.x,a[K].doorEndPt.y,0),bt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),Vt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),$t=O.facePoints[2].z<a[K].maxZ||Math.abs(O.facePoints[2].z-a[K].maxZ)<.3;if(Math.abs(O.facePoints[2].z-a[K].maxZ)>.2,$t){let at=Jt(ut.clone(),N.clone(),bt.clone(),Vt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let J=Qt(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)),Pt=new y.Vector3,Ht=pt.closestPointToPoint(J,!0,Pt);if(J.distanceTo(Ht)<.15){let j=bt.distanceTo(ut),k=Vt.distanceTo(ut);if(j>.25&&k>.25){let st=bt.distanceTo(N),mt=Vt.distanceTo(N);if(st>.2&&mt>.2)continue}vt=!0,Dt=!0,It.push(a[K].index),a[K].isFind=!0,_t=K,e[a[K].index].isFindBeam=!0;let dt=new y.Vector3().subVectors(bt,Vt).normalize(),it=ut.distanceTo(N)-at.overlap;k<j&&dt.negate(),j>k?(Q=O.facePoints[2].clone().addScaledVector(dt,it),ct=O.facePoints[3].clone(),q=ct.clone(),G=Q.clone(),q.z=G.z=O.facePoints[0].z):(Q=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(dt,it),q=ct.clone(),G=Q.clone(),q.z=G.z=O.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let J=bt.distanceTo(Vt),pt=N.distanceTo(ut);if(Math.abs(J-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>J&&Math.abs(pt-at.overlap)>1){let Pt=bt.distanceTo(ut),Ht=bt.distanceTo(N),ft=Vt.distanceTo(ut),j=Vt.distanceTo(N),k=Pt<Ht?Pt:Ht,dt=ft<j?ft:j,it=new y.Vector3().subVectors(bt,Vt).normalize(),st=pt-at.overlap;k<dt?(it.negate(),Q=O.facePoints[2].clone().addScaledVector(it,st),ct=O.facePoints[3].clone(),q=ct.clone(),G=Q.clone(),q.z=G.z=O.facePoints[0].z):(Q=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(it,st),q=ct.clone(),G=Q.clone(),q.z=G.z=O.facePoints[0].z)}vt=!0,Dt=!0,It.push(a[K].index),a[K].isFind=!0,e[a[K].index].isFindBeam=!0,_t=K}}}}if(!Dt&&Y<1.5)for(let K=0;K<a.length;K++){if(a[K].inWall)continue;let ut=new y.Vector3(a[K].doorStartPt.x,a[K].doorStartPt.y,0),N=new y.Vector3(a[K].doorEndPt.x,a[K].doorEndPt.y,0),bt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),Vt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),$t=new y.Vector3().subVectors(ut,N).normalize(),at=new y.Vector3().subVectors(bt,Vt).normalize(),J=.25,pt=ut.clone().addScaledVector($t,J),Pt=N.clone().addScaledVector($t.clone().negate(),J),Ht=bt.clone().addScaledVector(at,J),ft=Vt.clone().addScaledVector(at.clone().negate(),J),j=Kt(pt,Pt,Ht,ft),k=!0,dt=ut.distanceTo(bt),it=ut.distanceTo(Vt),st=N.distanceTo(bt),mt=N.distanceTo(Vt);(dt<g||it<g||st<g||mt<g||j)&&k&&(e[a[K].index].isFindBeam=!0,vt=!0,a[K].isFind=!0,_t=K)}(vt||Wt||Math.abs(Mt-V)>.1&&Mt>V/2&&Y>.3)&&(Bt=!0)}}if(Bt){let Wt=!1;for(let j=0;j<f.length;j++){let k=Jt(f[j].start,f[j].end,q,G);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){Wt=!0;break}}if(Wt){_t!=-1&&(e[a[_t].index].isFindBeam=!1,a[_t].isFind=!1);continue}f.push({start:q,end:G});{new y.PointsMaterial({color:65535,size:.01});let j=new y.Vector3().subVectors(q,G),k=new y.Vector3().subVectors(G,q),dt=1/0,it=1/0,st=q.clone(),mt=G.clone();const At=[],zt=[];let Rt=new y.Line3(Q,ct),Z=new y.Vector3,yt=999999;if(p.originalPoints.forEach(tt=>{if(tt.z-q.z<Mt/2+.1&&tt.z-q.z>Mt/2-.1&&At.push(tt),tt.z>Q.z){let rt=Rt.closestPointToPoint(tt,!0,Z),wt=new y.Vector3().subVectors(rt,Q),kt=new y.Vector3().subVectors(rt,ct),Nt=te(j,kt),Ot=te(k,wt);Nt&&Nt.parallel&&!Nt.sameDirection&&Ot&&Ot.parallel&&!Ot.sameDirection&&zt.push(tt)}}),At.length>0){const{newProjectPoints:tt}=Me(q,G,At);for(const rt of tt)rt.z=q.z;tt.forEach(rt=>{let wt=new y.Vector3(rt.x,rt.y,q.z),kt=new y.Vector3().subVectors(wt,G),Nt=new y.Vector3().subVectors(wt,q),Ot=te(j,Nt),Ut=te(k,kt);if(Ot&&Ot.parallel&&Ot.sameDirection){let be=wt.distanceTo(q);be<dt&&(dt=be,st=wt)}else if(Ut&&Ut.parallel&&Ut.sameDirection){let be=wt.distanceTo(G);be<it&&(it=be,mt=wt)}})}if(st.equals(q)||(q=st,ct=new y.Vector3(q.x,q.y,ct.z)),mt.equals(G)||(G=mt,Q=new y.Vector3(G.x,G.y,Q.z)),zt.length>10){const{newOnLinePoints:tt}=Me(ct,Q,zt);for(let rt=0;rt<tt.length;rt++){let kt=Rt.closestPointToPoint(tt[rt],!0,Z).distanceTo(tt[rt]);kt>.02&&yt>kt&&(yt=kt)}Q.z+=yt,ct.z+=yt,Mt+=yt}}let K=G.distanceTo(q);if(K<.4&&!vt||K<.3&&vt)continue;h.includes(d)||h.push(d),p.checkResults[E.index].isDoor=!0;let ut="",N={id:l,beamStart:Q,beamEnd:ct,beamHeight:p.rooftopPz-Q.z,doorStart:q,doorEnd:G,doorHeight:Mt,nearId:-1,type:ut,isExtend:Lt,isDoor:vt,isPullOutDoor:Dt,pcbDoorIndexs:It,beamNearWallVec:new y.Vector3(0,0,0)},bt=!1,Vt=new y.Vector3,$t=new y.Vector3,at=-1,J=-1,pt=-1;for(let j=0;j<c.length;j++){const k=n[c[j].linesIndex].doorAndBeamData[c[j].doorIndex];if(k.nearId!=-1)continue;let dt=ie(Q.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let it=Q.distanceTo(ct),st=k.beamStart.distanceTo(k.beamEnd),mt=new y.Line3(Q.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let At=Qt(k.beamStart,k.beamEnd,!0);st>it&&(mt.start=new y.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new y.Vector3(k.beamEnd.x,k.beamEnd.y,0),At=Qt(Q,ct,!0));let zt=new y.Vector3,Rt=mt.closestPointToPoint(At,!0,zt),Z=Rt.distanceTo(At),yt=new y.Vector3().subVectors(At,Rt).normalize(),tt=yt.clone().negate(),rt=At.clone().addScaledVector(tt,Z+.1),wt=Kt(mt.start,mt.end,At,rt),kt=!vt&&!k.isDoor&&(it>st*2||st>it*2);if(Z<.4&&wt!=null&&!kt){k.nearId=l,N.nearId=k.id;let Nt=.8;(k.isDoor||N.isDoor)&&(k.isDoor=!0,N.isDoor=!0);const Ot=It.some(Ut=>k.pcbDoorIndexs.includes(Ut));it<st?it>Nt&&!k.isPullOutDoor?(k.beamStart=Q.clone().addScaledVector(tt,Z),k.beamEnd=ct.clone().addScaledVector(tt,Z),k.doorStart=q.clone().addScaledVector(tt,Z),k.doorEnd=G.clone().addScaledVector(tt,Z),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Dt||Dt&&k.isPullOutDoor&&Ot?(N.beamStart=k.beamStart.clone().addScaledVector(yt,Z),N.beamEnd=k.beamEnd.clone().addScaledVector(yt,Z),N.doorStart=k.doorStart.clone().addScaledVector(yt,Z),N.doorEnd=k.doorEnd.clone().addScaledVector(yt,Z),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):(k.beamStart=Q.clone().addScaledVector(tt,Z),k.beamEnd=ct.clone().addScaledVector(tt,Z),k.doorStart=q.clone().addScaledVector(tt,Z),k.doorEnd=G.clone().addScaledVector(tt,Z),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):it>st&&(st>Nt&&!Dt?(N.beamStart=k.beamStart.clone().addScaledVector(tt,Z),N.beamEnd=k.beamEnd.clone().addScaledVector(tt,Z),N.doorStart=k.doorStart.clone().addScaledVector(tt,Z),N.doorEnd=k.doorEnd.clone().addScaledVector(tt,Z),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):!k.isPullOutDoor||Dt&&k.isPullOutDoor&&Ot?(k.beamStart=Q.clone().addScaledVector(yt,Z),k.beamEnd=ct.clone().addScaledVector(yt,Z),k.doorStart=q.clone().addScaledVector(yt,Z),k.doorEnd=G.clone().addScaledVector(yt,Z),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(N.beamStart=k.beamStart.clone().addScaledVector(tt,Z),N.beamEnd=k.beamEnd.clone().addScaledVector(tt,Z),N.doorStart=k.doorStart.clone().addScaledVector(tt,Z),N.doorEnd=k.doorEnd.clone().addScaledVector(tt,Z),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight)),at=N.nearId,Vt=k.beamStart.clone(),$t=k.beamEnd.clone(),bt=!0,J=c[j].linesIndex,pt=c[j].doorIndex;break}}}let Pt=!1;if(!bt){let j=new y.Line3(q.clone(),G.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==d)continue;let dt=new y.Vector3(n[k].start.x,n[k].start.y,n[k].start.z),it=new y.Vector3(n[k].end.x,n[k].end.y,n[k].end.z),st=Jt(dt,it,q,G),mt=ie(dt,it,q,G);const At=eo(n[k]);if(st&&st.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let rt=new y.Line3(dt,it),wt=new y.Vector3(q.x,q.y,dt.z),kt=rt.closestPointToPoint(wt,!0,new y.Vector3),Nt=ee(kt,wt,q,G);Nt&&Nt.angle>85&&(N.beamNearWallVec=new y.Vector3().subVectors(kt,wt).normalize())}const zt=[];n[k].originalPoints.forEach(rt=>{rt.z>q.z+.2&&rt.z<q.z+Mt/2&&zt.push(new y.Vector3(rt.x,rt.y,q.z))});const Rt=new y.Vector3;let Z=[],yt=[];for(let rt=0;rt<zt.length;rt++){let wt=j.closestPointToPoint(zt[rt],!0,Rt);wt.distanceTo(zt[rt])<.15&&(Z.push(zt[rt]),yt.push(wt.clone()))}for(let rt=0;rt<yt.length;rt++)oo(j,yt[rt])&&Z.push(yt[rt]);if(Z=yt,Z=io(Z),Z.length<150)continue;let tt=Qe(Z);if(tt.length==2){let rt=tt[0].distanceTo(tt[1]);if(Math.abs(rt-j.distance())<.3){let wt=new y.Line3(dt,it),kt=new y.Vector3(q.x,q.y,dt.z),Nt=wt.closestPointToPoint(kt,!0,new y.Vector3);if(N.beamNearWallVec=new y.Vector3().subVectors(Nt,kt).normalize(),N.beamStart.z>At.maxZ-.03&&Y>1)Pt=!0;else if(Wt=!0,_t!=-1&&(e[a[_t].index].isFindBeam=!1,a[_t].isFind=!1),J!=-1&&pt!=-1){const Ot=n[J].doorAndBeamData[pt];Ot.nearId=-1}break}}if(Wt)break}else st&&st.type=="collinear_overlap"&&st.maxPerpendicularDistance>.3&&st.maxPerpendicularDistance<.7&&(Pt=!0)}if(Wt){if(Y<1.8)continue;Pt=!0}}let Ht=!1;if(at!=-1)for(let j=0;j<u.length&&!(u[j].length==1&&(u[j][0].id==l?(u[j].push({id:at,beamStart:Vt,beamEnd:$t}),Ht=!0):u[j][0].id==at&&(u[j].push({id:l,beamStart:Q,beamEnd:ct}),Ht=!0),Ht));j++);Ht||u.push([{id:l,beamStart:Q,beamEnd:ct}]);const ft=N.doorStart.distanceTo(N.doorEnd);if(vt?ut="door":ft>1.8?ut="beam":ut=Pt&&ft>1?"beam":"hole",N.type=ut,N.nearId!=-1&&ut=="hole"){let j=!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,j=!0;break}if(j)break}}if(p.doorAndBeamData.push(N),c.push({linesIndex:d,doorIndex:p.doorAndBeamData.length-1}),l++,Dt&&Y<2)break}}}let _=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=D/_*100}if(h.length>1)for(let d=0;d<h.length;d++){let p=[];for(let b=0;b<n[h[d]].doorAndBeamData.length;b++){let z=!1;if(n[h[d]].doorAndBeamData[b].type==="beam"&&n[h[d]].doorAndBeamData[b].beamNearWallVec.x==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.y==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.z==0&&n[h[d]].doorAndBeamData[b].nearId==-1&&(z=!0),!z){let v=n[h[d]].doorAndBeamData[b].doorStart.clone(),S=n[h[d]].doorAndBeamData[b].doorEnd.clone();v.z=S.z=0;let V=v.distanceTo(S);for(let D=0;D<h.length;D++)if(d!=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=Jt(v,S,E,T);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let F=new y.Line3(E,T),I=Qt(v,S),B=F.closestPointToPoint(I,!0,new y.Vector3),L=I.distanceTo(B);if(Math.abs(V-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[d]].doorAndBeamData[b].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),z=!0;break}}}}z||p.push(n[h[d]].doorAndBeamData[b])}p.length!=n[h[d]].doorAndBeamData.length&&(n[h[d]].doorAndBeamData=p)}let w=.65,x=2,P=[],M=[];for(let d=0;d<a.length;d++){if(a[d].isFind||a[d].inWall)continue;let p=new y.Vector3(a[d].doorStartPt.x,a[d].doorStartPt.y,0),b=new y.Vector3(a[d].doorEndPt.x,a[d].doorEndPt.y,0),z=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),V=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,V).normalize(),_=.3,E=p.clone().addScaledVector(z,_),T=b.clone().addScaledVector(z.clone().negate(),_),A=S.clone().addScaledVector(D,_),F=V.clone().addScaledVector(D.clone().negate(),_);Kt(E,T,A,F);let I=ie(E,T,A,F),B=p.distanceTo(S)>b.distanceTo(S)?b:p,L=B.distanceTo(S),W=B.distanceTo(V);if((L<g||W<g)&&I&&!I.isParallel){let R=p.distanceTo(S),H=p.distanceTo(V),X=R<H?S:V,nt=!1;for(let U=0;U<n.length;U++){if(U==v||P.includes(U)||n[U].length<.7)continue;let $=new y.Vector3(n[U].start.x,n[U].start.y,0),ht=new y.Vector3(n[U].end.x,n[U].end.y,0),ot=new y.Vector3().subVectors($,ht).normalize(),O=ot.clone().negate(),Y=$.clone().addScaledVector(ot,5),Mt=ht.clone().addScaledVector(O,5),Gt=ee(S,V,$,ht),Ft=Jt(S,V,$,ht),Bt=Kt(S,V,Y,Mt),vt=!0;if(Bt!=null&&(vt=Bt.point.distanceTo(S)<g||Bt.point.distanceTo(V)<g),(Gt&&Gt.angle>85||Ft&&Ft.type=="collinear_gap")&&vt){let Dt=new y.Line3(S,V),It=new y.Vector3,Q=Dt.closestPointToPoint($,!0,It),ct=Dt.closestPointToPoint(ht,!0,It),q=Q.distanceTo($),G=ct.distanceTo(ht),Lt,_t;if(q>G&&G>w)Lt=ht,_t=ct;else if(q<G&&q>w)Lt=$,_t=Q;else continue;if(q=X.distanceTo($),G=X.distanceTo(ht),q>x&&G>x)continue;let Wt=ie(Lt,_t,$,ht),K=ie(Lt,_t,E,T);if(K&&K.isParallel||!Wt||!Wt.isParallel)continue;let ut=Jt(p,b,Lt,_t);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Lt.z=_t.z=n[U].start.z;let N=!1;for(let at=0;at<M.length;at++){let J=Jt(M[at].start,M[at].end,Lt,_t);if(J&&J.type=="collinear_overlap"&&J.maxPerpendicularDistance<.2){N=!0;break}}if(N)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let J=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),Pt=Jt(J,pt,Lt,_t);if(Pt&&Pt.type=="collinear_overlap"&&Pt.maxPerpendicularDistance<.1){N=!0;break}}if(N)continue;M.push({start:Lt,end:_t}),P.push(U);let bt=n[U].rooftopPz-n[U].start.z,Vt=n[v].rooftopPz-n[v].start.z,$t=bt<Vt?bt:Vt;n[U].doorAndBeamData||(n[U].doorAndBeamData=[]),n[U].doorAndBeamData.push({id:l,beamStart:Lt,beamEnd:_t,beamHeight:$t,doorStart:Lt,doorEnd:_t,doorHeight:$t,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new y.Vector3(0,0,0)}),e[a[d].index].isFindBeam=!0,e[a[d].index].isFindOnlyDoor=!0,u.push([{id:l,beamStart:Lt,beamEnd:_t}]),l++,nt=!0;break}}if(nt)break}}}let m=[];for(let d=0;d<n.length;d++)n[d].isLine2||m.push(n[d]),n[d].isLine2&&n[d].doorAndBeamData.length!=0&&m.push(n[d]);return n.length=0,n.push(...m),{lines:n,beamGroup:u}},bo=(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=[],f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(u,f).normalize().clone().negate(),x=new y.Vector3,P=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let m=0;m<n.length;m++){let d=n[m].length;if(m==l||d<i||d>r)continue;let p=new y.Vector3(n[m].start.x,n[m].start.y,n[m].start.z),b=new y.Vector3(n[m].end.x,n[m].end.y,n[m].end.z),z=ee(f,u,p,b);if(!z||z.angle<85)continue;let v=Tt(p,f),S=Tt(p,u),V=Tt(b,f),D=Tt(b,u);if(!(!v&&!S&&!V&&!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 E=n[_].length;if(_==l||_==m||E<i||E>r)continue;let T=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=ee(p,b,T,A);if(!F||F.angle<85)continue;let I=Tt(T,P),B=Tt(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,T).normalize(),T.clone(),L=A.clone()):(W=new y.Vector3().subVectors(T,A).normalize(),A.clone(),L=T.clone());let C=te(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==m||R==_||H<i||H>r)continue;let X=new y.Vector3(n[R].start.x,n[R].start.y,n[R].start.z),nt=new y.Vector3(n[R].end.x,n[R].end.y,n[R].end.z),U=ee(X,nt,T,A);if(!U||U.angle<85)continue;let $=Tt(X,L),ht=Tt(nt,L);if(!$&&!ht)continue;new y.Vector3;let ot=new y.Vector3;$?(X.clone(),ot=nt.clone()):(nt.clone(),ot=X.clone());let O=Tt(ot,f),Y=Tt(ot,u);if(!O&&!Y)continue;let Mt=c*d;if(!(Mt<s||Mt>a)){h=[n[l].uuid,n[m].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(m=>o.add(m)),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 y.Vector3,end:new y.Vector3}},f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),g=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let m=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),d=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),p=Tt(m,f),b=Tt(d,f),z=Tt(m,u),v=Tt(d,u);if(p||b?g=!1:(z||v)&&(w=!1),!g&&!w)break}if(!g&&!w)continue;let x=new y.Vector3;g||([f,u]=[u,f]),x=new y.Vector3().subVectors(u,f).normalize();let P=x.clone().negate();for(let M=0;M<n.length;M++){let m=n[M].length;if(M==l||o.has(M)||m<i||m>r)continue;let d=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=ee(f,u,d,p);if(!b||b.angle<85)continue;let z=Tt(d,u),v=Tt(p,u);if(!z&&!v)continue;new y.Vector3;let S=new y.Vector3;z?(d.clone(),S=p.clone()):(p.clone(),S=d.clone());for(let V=0;V<n.length;V++){let D=n[V].length;if(V==l||V==M||o.has(V)||D<i||D>r)continue;let _=new y.Vector3(n[V].start.x,n[V].start.y,n[V].start.z),E=new y.Vector3(n[V].end.x,n[V].end.y,n[V].end.z),T=ee(d,p,_,E);if(!T||T.angle<85)continue;let A=Tt(_,S),F=Tt(E,S);if(!A&&!F)continue;let I=new y.Vector3,B=new y.Vector3;A?(I=_.clone(),B=E.clone()):(I=E.clone(),B=_.clone());let L=new y.Vector3().subVectors(B,I).normalize(),W=te(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==V||n[X].length<i)continue;let nt=new y.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),U=new y.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),$=Tt(nt,_),ht=Tt(U,_),ot=Tt(nt,E),O=Tt(U,E);if($||ht?C=!1:(ot||O)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let H=c*m;if(!(H<s||H>a)){h.indexs=[n[l].uuid,n[M].uuid,n[V].uuid],h.missingEdge.start=B,h.missingEdge.end=f;break}}if(h.indexs.length==3)break}h.indexs.length==3&&(h.indexs.forEach(M=>o.add(M)),e.threeEdgeRect.push(h))}return e},re=11102230246251565e-32,Xt=134217729,Po=(3+8*re)*re;function ke(n,t,e,o,i){let r,s,a,l,c=t[0],h=o[0],f=0,u=0;h>c==h>-c?(r=c,c=t[++f]):(r=h,h=o[++u]);let g=0;if(f<n&&u<e)for(h>c==h>-c?(s=c+r,a=r-(s-c),c=t[++f]):(s=h+r,a=r-(s-h),h=o[++u]),r=s,a!==0&&(i[g++]=a);f<n&&u<e;)h>c==h>-c?(s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u]),r=s,a!==0&&(i[g++]=a);for(;f<n;)s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f],r=s,a!==0&&(i[g++]=a);for(;u<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u],r=s,a!==0&&(i[g++]=a);return(r!==0||g===0)&&(i[g++]=r),g}function Mo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function Ve(n){return new Float64Array(n)}const Vo=(3+16*re)*re,zo=(2+12*re)*re,So=(9+64*re)*re*re,fe=Ve(4),en=Ve(8),nn=Ve(12),on=Ve(16),Yt=Ve(4);function vo(n,t,e,o,i,r,s){let a,l,c,h,f,u,g,w,x,P,M,m,d,p,b,z,v,S;const V=n-i,D=e-i,_=t-r,E=o-r;p=V*E,u=Xt*V,g=u-(u-V),w=V-g,u=Xt*E,x=u-(u-E),P=E-x,b=w*P-(p-g*x-w*x-g*P),z=_*D,u=Xt*_,g=u-(u-_),w=_-g,u=Xt*D,x=u-(u-D),P=D-x,v=w*P-(z-g*x-w*x-g*P),M=b-v,f=b-M,fe[0]=b-(M+f)+(f-v),m=p+M,f=m-p,d=p-(m-f)+(M-f),M=d-z,f=d-M,fe[1]=d-(M+f)+(f-z),S=m+M,f=S-m,fe[2]=m-(S-f)+(M-f),fe[3]=S;let T=Mo(4,fe),A=zo*s;if(T>=A||-T>=A||(f=n-V,a=n-(V+f)+(f-i),f=e-D,c=e-(D+f)+(f-i),f=t-_,l=t-(_+f)+(f-r),f=o-E,h=o-(E+f)+(f-r),a===0&&l===0&&c===0&&h===0)||(A=So*s+Po*Math.abs(T),T+=V*h+E*a-(_*c+D*l),T>=A||-T>=A))return T;p=a*E,u=Xt*a,g=u-(u-a),w=a-g,u=Xt*E,x=u-(u-E),P=E-x,b=w*P-(p-g*x-w*x-g*P),z=l*D,u=Xt*l,g=u-(u-l),w=l-g,u=Xt*D,x=u-(u-D),P=D-x,v=w*P-(z-g*x-w*x-g*P),M=b-v,f=b-M,Yt[0]=b-(M+f)+(f-v),m=p+M,f=m-p,d=p-(m-f)+(M-f),M=d-z,f=d-M,Yt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,Yt[2]=m-(S-f)+(M-f),Yt[3]=S;const F=ke(4,fe,4,Yt,en);p=V*h,u=Xt*V,g=u-(u-V),w=V-g,u=Xt*h,x=u-(u-h),P=h-x,b=w*P-(p-g*x-w*x-g*P),z=_*c,u=Xt*_,g=u-(u-_),w=_-g,u=Xt*c,x=u-(u-c),P=c-x,v=w*P-(z-g*x-w*x-g*P),M=b-v,f=b-M,Yt[0]=b-(M+f)+(f-v),m=p+M,f=m-p,d=p-(m-f)+(M-f),M=d-z,f=d-M,Yt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,Yt[2]=m-(S-f)+(M-f),Yt[3]=S;const I=ke(F,en,4,Yt,nn);p=a*h,u=Xt*a,g=u-(u-a),w=a-g,u=Xt*h,x=u-(u-h),P=h-x,b=w*P-(p-g*x-w*x-g*P),z=l*c,u=Xt*l,g=u-(u-l),w=l-g,u=Xt*c,x=u-(u-c),P=c-x,v=w*P-(z-g*x-w*x-g*P),M=b-v,f=b-M,Yt[0]=b-(M+f)+(f-v),m=p+M,f=m-p,d=p-(m-f)+(M-f),M=d-z,f=d-M,Yt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,Yt[2]=m-(S-f)+(M-f),Yt[3]=S;const B=ke(I,nn,4,Yt,on);return on[B-1]}function ze(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)>=Vo*c?l:-vo(n,t,e,o,i,r,c)}const rn=Math.pow(2,-52),Se=new Uint32Array(512);class Te{static from(t,e=Ao,o=Bo){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 Te(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 f=(a+c)/2,u=(l+h)/2;let g=0,w=0,x=0;for(let V=0,D=1/0;V<s;V++){const _=Ce(f,u,t[2*V],t[2*V+1]);_<D&&(g=V,D=_)}const P=t[2*g],M=t[2*g+1];for(let V=0,D=1/0;V<s;V++){if(V===g)continue;const _=Ce(P,M,t[2*V],t[2*V+1]);_<D&&_>0&&(w=V,D=_)}let m=t[2*w],d=t[2*w+1],p=1/0;for(let V=0;V<s;V++){if(V===g||V===w)continue;const D=Eo(P,M,m,d,t[2*V],t[2*V+1]);D<p&&(x=V,p=D)}let b=t[2*x],z=t[2*x+1];if(p===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ge(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(ze(P,M,m,d,b,z)<0){const V=w,D=m,_=d;w=x,m=b,d=z,x=V,b=D,z=_}const v=To(P,M,m,d,b,z);this._cx=v.x,this._cy=v.y;for(let V=0;V<s;V++)this._dists[V]=Ce(t[2*V],t[2*V+1],v.x,v.y);ge(this._ids,this._dists,0,s-1),this._hullStart=g;let S=3;o[g]=e[x]=w,o[w]=e[g]=x,o[x]=e[w]=g,i[g]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(P,M)]=g,r[this._hashKey(m,d)]=w,r[this._hashKey(b,z)]=x,this.trianglesLen=0,this._addTriangle(g,w,x,-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)<=rn&&Math.abs(A-_)<=rn||(D=T,_=A,E===g||E===w||E===x))continue;let F=0;for(let C=0,R=this._hashKey(T,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],ze(T,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,E,o[I],-1,-1,i[I]);i[E]=this._legalize(L+2),i[I]=L,S++;let W=o[I];for(;B=o[W],ze(T,A,t[2*W],t[2*W+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(W,E,B,i[E],-1,i[W]),i[E]=this._legalize(L+2),o[W]=W,S--,W=B;if(I===F)for(;B=e[I],ze(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[W]=E,o[E]=W,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(Do(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=Se[--r];continue}const c=a-a%3,h=l+(t+1)%3,f=c+(a+2)%3,u=e[s],g=e[t],w=e[h],x=e[f];if(_o(i[2*u],i[2*u+1],i[2*g],i[2*g+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=u;const M=o[f];if(M===-1){let d=this._hullStart;do{if(this._hullTri[d]===f){this._hullTri[d]=t;break}d=this._hullPrev[d]}while(d!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,f);const m=c+(a+1)%3;r<Se.length&&(Se[r++]=m)}else{if(r===0)break;t=Se[--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 Do(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function Ce(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function _o(n,t,e,o,i,r,s,a){const l=n-s,c=t-a,h=e-s,f=o-a,u=i-s,g=r-a,w=l*l+c*c,x=h*h+f*f,P=u*u+g*g;return l*(f*P-x*g)-c*(h*P-x*u)+w*(h*g-f*u)<0}function Eo(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,f=l*l+c*c,u=.5/(s*c-a*l),g=(c*h-a*f)*u,w=(s*f-l*h)*u;return g*g+w*w}function To(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,f=l*l+c*c,u=.5/(s*c-a*l),g=n+(c*h-a*f)*u,w=t+(s*f-l*h)*u;return{x:g,y:w}}function ge(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;Pe(n,i,r),t[n[e]]>t[n[o]]&&Pe(n,e,o),t[n[r]]>t[n[o]]&&Pe(n,r,o),t[n[e]]>t[n[r]]&&Pe(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;Pe(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ge(n,t,r,o),ge(n,t,e,s-1)):(ge(n,t,e,s-1),ge(n,t,r,o))}}function Pe(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Ao(n){return n[0]}function Bo(n){return n[1]}const sn=1e-6;class he{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)>sn||Math.abs(this._y1-r)>sn)&&(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 Ne{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 Io{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,m,d;x<M;x+=3,P+=2){const p=o[x]*2,b=o[x+1]*2,z=o[x+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,F=_-v,I=E-S,B=(T*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);m=(v+_)/2-L*I,d=(S+E)/2+L*F}else{const L=1/B,W=T*T+A*A,C=F*F+I*I;m=v+(I*W-A*C)*L,d=S+(T*C-F*W)*L}a[P]=m,a[P+1]=d}let l=e[e.length-1],c,h=l*4,f,u=t[2*l],g,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],c=h,f=u,g=w,h=l*4,u=t[2*l],w=t[2*l+1],i[c+2]=i[h]=g-w,i[c+3]=i[h+1]=u-f}render(t){const e=t==null?t=new he:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,f=o.length;h<f;++h){const u=o[h];if(u<h)continue;const g=Math.floor(h/3)*2,w=Math.floor(u/3)*2,x=s[g],P=s[g+1],M=s[w],m=s[w+1];this._renderSegment(x,P,M,m,t)}let l,c=r[r.length-1];for(let h=0;h<r.length;++h){l=c,c=r[h];const f=Math.floor(i[c]/3)*2,u=s[f],g=s[f+1],w=l*4,x=this._project(u,g,a[w+2],a[w+3]);x&&this._renderSegment(u,g,x[0],x[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new he: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 he: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 Ne;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),f,u=0;for(let g=0;g<o;g+=2)if(r=a,s=l,a=e[g],l=e[g+1],c=h,h=this._regioncode(a,l),c===0&&h===0)f=u,u=0,i?i.push(a,l):i=[a,l];else{let w,x,P,M,m;if(c===0){if((w=this._clipSegment(r,s,a,l,c,h))===null)continue;[x,P,M,m]=w}else{if((w=this._clipSegment(a,l,r,s,h,c))===null)continue;[M,m,x,P]=w,f=u,u=this._edgecode(x,P),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(x,P):i=[x,P]}f=u,u=this._edgecode(M,m),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(M,m):i=[M,m]}if(i)f=u,u=this._edgecode(i[0],i[1]),f&&u&&this._edge(t,f,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,f,u=this._edgecode(a[h-2],a[h-1]);c<h;c+=2)f=u,u=this._edgecode(a[c],a[c+1]),f&&u&&(c=this._edge(t,f,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 ko=2*Math.PI,de=Math.pow;function Co(n){return n[0]}function Lo(n){return n[1]}function Ro(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 Oo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class He{static from(t,e=Co,o=Lo,i){return new He("length"in t?Fo(t,e,o,i):Float64Array.from(Wo(t,e,o,i)))}constructor(t){this._delaunator=new Te(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&&Ro(t)){this.collinear=Int32Array.from({length:e.length/2},(u,g)=>g).sort((u,g)=>e[2*u]-e[2*g]||e[2*u+1]-e[2*g+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]],f=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let u=0,g=e.length/2;u<g;++u){const w=Oo(e[2*u],e[2*u+1],f);e[2*u]=w[0],e[2*u+1]=w[1]}this._delaunator=new Te(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 Io(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const f=a.indexOf(t);f>0&&(yield a[f-1]),f<a.length-1&&(yield a[f+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 f=o[(i[t]+1)%o.length];f!==h&&(yield f);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,f=de(e-c[t*2],2)+de(o-c[t*2+1],2);const u=i[t];let g=u;do{let w=l[g];const x=de(e-c[w*2],2)+de(o-c[w*2+1],2);if(x<f&&(f=x,h=w),g=g%3===2?g-2:g+1,l[g]!==t)break;if(g=a[g],g===-1){if(g=r[(s[t]+1)%r.length],g!==w&&de(e-c[g*2],2)+de(o-c[g*2+1],2)<f)return g;break}}while(g!==u);return h}render(t){const e=t==null?t=new he: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 he: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,ko)}return o&&o.value()}renderHull(t){const e=t==null?t=new he: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 Ne;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new he: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 Ne;return this.renderTriangle(t,e),e.value()}}function Fo(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*Wo(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 No(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function qo(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 qe(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 He(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],[m,d]=e[x],[p,b]=e[P],[z,v]=e[M],S=qo(m,d,p,b,z,v),V=No(e,x,P,M);if(S<=1/V)for(const[D,_]of[[x,P],[P,M],[M,x]]){const E=s(D,_);r.set(E,(r.get(E)||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 c=a[0][0],h=[],f=new Set;let u=c,g=-1;do{h.push(e[u]),f.add(u);const w=l.get(u)||[];let x=w.find(P=>P!==g&&!f.has(P));if(x===void 0&&(x=w.find(P=>P!==g)),x===void 0)break;g=u,u=x}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:[]},Et=[[],[],[]],et=[[],[],[]],St=[],ae=new lt.Vector3,le=new lt.Vector3,ce=new lt.Vector3,Ct=new lt.Vector3,an=new lt.Vector3,ln=new lt.Vector3,Zt=new lt.Matrix3,cn=new lt.Box3,ve=new lt.Matrix4,un=new lt.Matrix4,hn=new lt.Ray;let vn=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;Ct.subVectors(t,this.center),this.rotation.extractBasis(ae,le,ce),e.copy(this.center);const i=lt.MathUtils.clamp(Ct.dot(ae),-o.x,o.x);e.add(ae.multiplyScalar(i));const r=lt.MathUtils.clamp(Ct.dot(le),-o.y,o.y);e.add(le.multiplyScalar(r));const s=lt.MathUtils.clamp(Ct.dot(ce),-o.z,o.z);return e.add(ce.multiplyScalar(s)),e}containsPoint(t){return Ct.subVectors(t,this.center),this.rotation.extractBasis(ae,le,ce),Math.abs(Ct.dot(ae))<=this.halfSize.x&&Math.abs(Ct.dot(le))<=this.halfSize.y&&Math.abs(Ct.dot(ce))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Xo.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,ln),ln.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++)Et[r][s]=gt.u[r].dot(xt.u[s]);Ct.subVectors(xt.c,gt.c),St[0]=Ct.dot(gt.u[0]),St[1]=Ct.dot(gt.u[1]),St[2]=Ct.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)et[r][s]=Math.abs(Et[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*et[r][0]+xt.e[1]*et[r][1]+xt.e[2]*et[r][2],Math.abs(St[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*et[0][r]+gt.e[1]*et[1][r]+gt.e[2]*et[2][r],i=xt.e[r],Math.abs(St[0]*Et[0][r]+St[1]*Et[1][r]+St[2]*Et[2][r])>o+i)return!1;return o=gt.e[1]*et[2][0]+gt.e[2]*et[1][0],i=xt.e[1]*et[0][2]+xt.e[2]*et[0][1],!(Math.abs(St[2]*Et[1][0]-St[1]*Et[2][0])>o+i||(o=gt.e[1]*et[2][1]+gt.e[2]*et[1][1],i=xt.e[0]*et[0][2]+xt.e[2]*et[0][0],Math.abs(St[2]*Et[1][1]-St[1]*Et[2][1])>o+i)||(o=gt.e[1]*et[2][2]+gt.e[2]*et[1][2],i=xt.e[0]*et[0][1]+xt.e[1]*et[0][0],Math.abs(St[2]*Et[1][2]-St[1]*Et[2][2])>o+i)||(o=gt.e[0]*et[2][0]+gt.e[2]*et[0][0],i=xt.e[1]*et[1][2]+xt.e[2]*et[1][1],Math.abs(St[0]*Et[2][0]-St[2]*Et[0][0])>o+i)||(o=gt.e[0]*et[2][1]+gt.e[2]*et[0][1],i=xt.e[0]*et[1][2]+xt.e[2]*et[1][0],Math.abs(St[0]*Et[2][1]-St[2]*Et[0][1])>o+i)||(o=gt.e[0]*et[2][2]+gt.e[2]*et[0][2],i=xt.e[0]*et[1][1]+xt.e[1]*et[1][0],Math.abs(St[0]*Et[2][2]-St[2]*Et[0][2])>o+i)||(o=gt.e[0]*et[1][0]+gt.e[1]*et[0][0],i=xt.e[1]*et[2][2]+xt.e[2]*et[2][1],Math.abs(St[1]*Et[0][0]-St[0]*Et[1][0])>o+i)||(o=gt.e[0]*et[1][1]+gt.e[1]*et[0][1],i=xt.e[0]*et[2][2]+xt.e[2]*et[2][0],Math.abs(St[1]*Et[0][1]-St[0]*Et[1][1])>o+i)||(o=gt.e[0]*et[1][2]+gt.e[1]*et[0][2],i=xt.e[0]*et[2][1]+xt.e[1]*et[2][0],Math.abs(St[1]*Et[0][2]-St[0]*Et[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ae,le,ce);const e=this.halfSize.x*Math.abs(t.normal.dot(ae))+this.halfSize.y*Math.abs(t.normal.dot(le))+this.halfSize.z*Math.abs(t.normal.dot(ce)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(an),cn.setFromCenterAndSize(Ct.set(0,0,0),an),ve.setFromMatrix3(this.rotation),ve.setPosition(this.center),un.copy(ve).invert(),hn.copy(t).applyMatrix4(un),hn.intersectBox(cn,e)?e.applyMatrix4(ve):null}intersectsRay(t){return this.intersectRay(t,Ct)!==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=Ct.set(e[0],e[1],e[2]).length();const i=Ct.set(e[4],e[5],e[6]).length(),r=Ct.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Zt.setFromMatrix4(t);const a=1/o,l=1/i,c=1/r;return Zt.elements[0]*=a,Zt.elements[1]*=a,Zt.elements[2]*=a,Zt.elements[3]*=l,Zt.elements[4]*=l,Zt.elements[5]*=l,Zt.elements[6]*=c,Zt.elements[7]*=c,Zt.elements[8]*=c,this.rotation.multiply(Zt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ct.setFromMatrixPosition(t),this.center.add(Ct),this}};const Xo=new vn;var qt=63710088e-1,Dn={centimeters:qt*100,centimetres:qt*100,degrees:360/(2*Math.PI),feet:qt*3.28084,inches:qt*39.37,kilometers:qt/1e3,kilometres:qt/1e3,meters:qt,metres:qt,miles:qt/1609.344,millimeters:qt*1e3,millimetres:qt*1e3,nauticalmiles:qt/1852,radians:1,yards:qt*1.0936};function _n(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 En(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(!fn(n[0])||!fn(n[1]))throw new Error("coordinates must contain numbers");return _n({type:"Point",coordinates:n},t,e)}function Tn(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 _n({type:"Polygon",coordinates:n},t,e)}function Ho(n,t="kilometers"){const e=Dn[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Yo(n,t="kilometers"){const e=Dn[t];if(!e)throw new Error(t+" units is invalid");return n/e}function An(n){return n%(2*Math.PI)*180/Math.PI}function ne(n){return n%360*Math.PI/180}function Bn(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return Ho(Yo(n,t),e)}function fn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function $o(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function we(n,t,e){if(n!==null)for(var o,i,r,s,a,l,c,h=0,f=0,u,g=n.type,w=g==="FeatureCollection",x=g==="Feature",P=w?n.features.length:1,M=0;M<P;M++){c=w?n.features[M].geometry:x?n.geometry:n,u=c?c.type==="GeometryCollection":!1,a=u?c.geometries.length:1;for(var m=0;m<a;m++){var d=0,p=0;if(s=u?c.geometries[m]: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,f,M,d,p)===!1)return!1;f++,d++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],f,M,d,p)===!1)return!1;f++,b==="MultiPoint"&&d++}b==="LineString"&&d++;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],f,M,d,p)===!1)return!1;f++}b==="MultiLineString"&&d++,b==="Polygon"&&p++}b==="Polygon"&&d++;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],f,M,d,p)===!1)return!1;f++}p++}d++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(we(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Go(n){var t=[];return we(n,function(e){t.push(e)}),t}function jo(n,t){var e,o,i,r,s,a,l,c,h,f,u=0,g=n.type==="FeatureCollection",w=n.type==="Feature",x=g?n.features.length:1;for(e=0;e<x;e++){for(a=g?n.features[e].geometry:w?n.geometry:n,c=g?n.features[e].properties:w?n.properties:{},h=g?n.features[e].bbox:w?n.bbox:void 0,f=g?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,f)===!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,f)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],u,c,h,f)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}u++}}function Uo(n,t,e){var o=e;return jo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var In=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Zo(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function Ko(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 Ye={exports:{}},kn={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(In,function(){function e(m,d,p,b,z){(function v(S,V,D,_,E){for(;_>D;){if(_-D>600){var T=_-D+1,A=V-D+1,F=Math.log(T),I=.5*Math.exp(2*F/3),B=.5*Math.sqrt(F*I*(T-I)/T)*(A-T/2<0?-1:1),L=Math.max(D,Math.floor(V-A*I/T+B)),W=Math.min(_,Math.floor(V+(T-A)*I/T+B));v(S,V,L,W,E)}var C=S[V],R=D,H=_;for(o(S,D,V),E(S[_],C)>0&&o(S,D,_);R<H;){for(o(S,R,H),R++,H--;E(S[R],C)<0;)R++;for(;E(S[H],C)>0;)H--}E(S[D],C)===0?o(S,D,H):o(S,++H,_),H<=V&&(D=H+1),V<=H&&(_=H-1)}})(m,d,p||0,b||m.length-1,z||i)}function o(m,d,p){var b=m[d];m[d]=m[p],m[p]=b}function i(m,d){return m<d?-1:m>d?1:0}var r=function(m){m===void 0&&(m=9),this._maxEntries=Math.max(4,m),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(m,d,p){if(!p)return d.indexOf(m);for(var b=0;b<d.length;b++)if(p(m,d[b]))return b;return-1}function a(m,d){l(m,0,m.children.length,d,m)}function l(m,d,p,b,z){z||(z=P(null)),z.minX=1/0,z.minY=1/0,z.maxX=-1/0,z.maxY=-1/0;for(var v=d;v<p;v++){var S=m.children[v];c(z,m.leaf?b(S):S)}return z}function c(m,d){return m.minX=Math.min(m.minX,d.minX),m.minY=Math.min(m.minY,d.minY),m.maxX=Math.max(m.maxX,d.maxX),m.maxY=Math.max(m.maxY,d.maxY),m}function h(m,d){return m.minX-d.minX}function f(m,d){return m.minY-d.minY}function u(m){return(m.maxX-m.minX)*(m.maxY-m.minY)}function g(m){return m.maxX-m.minX+(m.maxY-m.minY)}function w(m,d){return m.minX<=d.minX&&m.minY<=d.minY&&d.maxX<=m.maxX&&d.maxY<=m.maxY}function x(m,d){return d.minX<=m.maxX&&d.minY<=m.maxY&&d.maxX>=m.minX&&d.maxY>=m.minY}function P(m){return{children:m,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(m,d,p,b,z){for(var v=[d,p];v.length;)if(!((p=v.pop())-(d=v.pop())<=b)){var S=d+Math.ceil((p-d)/b/2)*b;e(m,S,d,p,z),v.push(d,S,S,p)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(m){var d=this.data,p=[];if(!x(m,d))return p;for(var b=this.toBBox,z=[];d;){for(var v=0;v<d.children.length;v++){var S=d.children[v],V=d.leaf?b(S):S;x(m,V)&&(d.leaf?p.push(S):w(m,V)?this._all(S,p):z.push(S))}d=z.pop()}return p},r.prototype.collides=function(m){var d=this.data;if(!x(m,d))return!1;for(var p=[];d;){for(var b=0;b<d.children.length;b++){var z=d.children[b],v=d.leaf?this.toBBox(z):z;if(x(m,v)){if(d.leaf||w(m,v))return!0;p.push(z)}}d=p.pop()}return!1},r.prototype.load=function(m){if(!m||!m.length)return this;if(m.length<this._minEntries){for(var d=0;d<m.length;d++)this.insert(m[d]);return this}var p=this._build(m.slice(),0,m.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(m){return m&&this._insert(m,this.data.height-1),this},r.prototype.clear=function(){return this.data=P([]),this},r.prototype.remove=function(m,d){if(!m)return this;for(var p,b,z,v=this.data,S=this.toBBox(m),V=[],D=[];v||V.length;){if(v||(v=V.pop(),b=V[V.length-1],p=D.pop(),z=!0),v.leaf){var _=s(m,v.children,d);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(m){return m},r.prototype.compareMinX=function(m,d){return m.minX-d.minX},r.prototype.compareMinY=function(m,d){return m.minY-d.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(m){return this.data=m,this},r.prototype._all=function(m,d){for(var p=[];m;)m.leaf?d.push.apply(d,m.children):p.push.apply(p,m.children),m=p.pop();return d},r.prototype._build=function(m,d,p,b){var z,v=p-d+1,S=this._maxEntries;if(v<=S)return a(z=P(m.slice(d,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=P([])).leaf=!1,z.height=b;var V=Math.ceil(v/S),D=V*Math.ceil(Math.sqrt(S));M(m,d,p,D,this.compareMinX);for(var _=d;_<=p;_+=D){var E=Math.min(_+D-1,p);M(m,_,E,V,this.compareMinY);for(var T=_;T<=E;T+=V){var A=Math.min(T+V-1,E);z.children.push(this._build(m,T,A,b-1))}}return a(z,this.toBBox),z},r.prototype._chooseSubtree=function(m,d,p,b){for(;b.push(d),!d.leaf&&b.length-1!==p;){for(var z=1/0,v=1/0,S=void 0,V=0;V<d.children.length;V++){var D=d.children[V],_=u(D),E=(T=m,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)}d=S||d.children[0]}var T,A;return d},r.prototype._insert=function(m,d,p){var b=p?m:this.toBBox(m),z=[],v=this._chooseSubtree(b,this.data,d,z);for(v.children.push(m),c(v,b);d>=0&&z[d].children.length>this._maxEntries;)this._split(z,d),d--;this._adjustParentBBoxes(b,z,d)},r.prototype._split=function(m,d){var p=m[d],b=p.children.length,z=this._minEntries;this._chooseSplitAxis(p,z,b);var v=this._chooseSplitIndex(p,z,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),d?m[d-1].children.push(S):this._splitRoot(p,S)},r.prototype._splitRoot=function(m,d){this.data=P([m,d]),this.data.height=m.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(m,d,p){for(var b,z,v,S,V,D,_,E=1/0,T=1/0,A=d;A<=p-d;A++){var F=l(m,0,A,this.toBBox),I=l(m,A,p,this.toBBox),B=(z=F,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(F)+u(I);B<E?(E=B,b=A,T=L<T?L:T):B===E&&L<T&&(T=L,b=A)}return b||p-d},r.prototype._chooseSplitAxis=function(m,d,p){var b=m.leaf?this.compareMinX:h,z=m.leaf?this.compareMinY:f;this._allDistMargin(m,d,p,b)<this._allDistMargin(m,d,p,z)&&m.children.sort(b)},r.prototype._allDistMargin=function(m,d,p,b){m.children.sort(b);for(var z=this.toBBox,v=l(m,0,d,z),S=l(m,p-d,p,z),V=g(v)+g(S),D=d;D<p-d;D++){var _=m.children[D];c(v,m.leaf?z(_):_),V+=g(v)}for(var E=p-d-1;E>=d;E--){var T=m.children[E];c(S,m.leaf?z(T):T),V+=g(S)}return V},r.prototype._adjustParentBBoxes=function(m,d,p){for(var b=p;b>=0;b--)c(d[b],m)},r.prototype._condense=function(m){for(var d=m.length-1,p=void 0;d>=0;d--)m[d].children.length===0?d>0?(p=m[d-1].children).splice(p.indexOf(m[d]),1):this.clear():a(m[d],this.toBBox)},r})})(kn);var Qo=kn.exports;class Jo{constructor(t=[],e=tr){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 tr(n,t){return n<t?-1:n>t?1:0}const er=Object.freeze(Object.defineProperty({__proto__:null,default:Jo},Symbol.toStringTag,{value:"Module"})),nr=Ko(er);var Be={exports:{}},or=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 f=e[o+c*2+0],u=e[o+c*2+1],g=e[o+h*2+0],w=e[o+h*2+1],x=u>s!=w>s&&r<(g-f)*(s-u)/(w-u)+f;x&&(a=!a)}return a},rr=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 f=e[c+o][0],u=e[c+o][1],g=e[h+o][0],w=e[h+o][1],x=u>s!=w>s&&r<(g-f)*(s-u)/(w-u)+f;x&&(a=!a)}return a},Cn=or,Ln=rr;Be.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Ln(t,e,o,i):Cn(t,e,o,i)};Be.exports.nested=Ln;Be.exports.flat=Cn;var ir=Be.exports,Xe={exports:{}};(function(n,t){(function(e,o){o(t)})(In,function(e){const i=33306690738754706e-32;function r(x,P,M,m,d){let p,b,z,v,S=P[0],V=m[0],D=0,_=0;V>S==V>-S?(p=S,S=P[++D]):(p=V,V=m[++_]);let E=0;if(D<x&&_<M)for(V>S==V>-S?(z=p-((b=S+p)-S),S=P[++D]):(z=p-((b=V+p)-V),V=m[++_]),p=b,z!==0&&(d[E++]=z);D<x&&_<M;)V>S==V>-S?(z=p-((b=p+S)-(v=b-p))+(S-v),S=P[++D]):(z=p-((b=p+V)-(v=b-p))+(V-v),V=m[++_]),p=b,z!==0&&(d[E++]=z);for(;D<x;)z=p-((b=p+S)-(v=b-p))+(S-v),S=P[++D],p=b,z!==0&&(d[E++]=z);for(;_<M;)z=p-((b=p+V)-(v=b-p))+(V-v),V=m[++_],p=b,z!==0&&(d[E++]=z);return p===0&&E!==0||(d[E++]=p),E}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,c=11093356479670487e-47,h=s(4),f=s(8),u=s(12),g=s(16),w=s(4);e.orient2d=function(x,P,M,m,d,p){const b=(P-p)*(M-d),z=(x-d)*(m-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,F){let I,B,L,W,C,R,H,X,nt,U,$,ht,ot,O,Y,Mt,Gt,Ft;const Bt=V-T,vt=_-T,Dt=D-A,It=E-A;C=(Y=(X=Bt-(H=(R=134217729*Bt)-(R-Bt)))*(U=It-(nt=(R=134217729*It)-(R-It)))-((O=Bt*It)-H*nt-X*nt-H*U))-($=Y-(Gt=(X=Dt-(H=(R=134217729*Dt)-(R-Dt)))*(U=vt-(nt=(R=134217729*vt)-(R-vt)))-((Mt=Dt*vt)-H*nt-X*nt-H*U))),h[0]=Y-($+C)+(C-Gt),C=(ot=O-((ht=O+$)-(C=ht-O))+($-C))-($=ot-Mt),h[1]=ot-($+C)+(C-Mt),C=(Ft=ht+$)-ht,h[2]=ht-(Ft-C)+($-C),h[3]=Ft;let Q=function(_t,Wt){let K=Wt[0];for(let ut=1;ut<_t;ut++)K+=Wt[ut];return K}(4,h),ct=l*F;if(Q>=ct||-Q>=ct||(I=V-(Bt+(C=V-Bt))+(C-T),L=_-(vt+(C=_-vt))+(C-T),B=D-(Dt+(C=D-Dt))+(C-A),W=E-(It+(C=E-It))+(C-A),I===0&&B===0&&L===0&&W===0)||(ct=c*F+i*Math.abs(Q),(Q+=Bt*W+It*I-(Dt*L+vt*B))>=ct||-Q>=ct))return Q;C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(U=It-(nt=(R=134217729*It)-(R-It)))-((O=I*It)-H*nt-X*nt-H*U))-($=Y-(Gt=(X=B-(H=(R=134217729*B)-(R-B)))*(U=vt-(nt=(R=134217729*vt)-(R-vt)))-((Mt=B*vt)-H*nt-X*nt-H*U))),w[0]=Y-($+C)+(C-Gt),C=(ot=O-((ht=O+$)-(C=ht-O))+($-C))-($=ot-Mt),w[1]=ot-($+C)+(C-Mt),C=(Ft=ht+$)-ht,w[2]=ht-(Ft-C)+($-C),w[3]=Ft;const q=r(4,h,4,w,f);C=(Y=(X=Bt-(H=(R=134217729*Bt)-(R-Bt)))*(U=W-(nt=(R=134217729*W)-(R-W)))-((O=Bt*W)-H*nt-X*nt-H*U))-($=Y-(Gt=(X=Dt-(H=(R=134217729*Dt)-(R-Dt)))*(U=L-(nt=(R=134217729*L)-(R-L)))-((Mt=Dt*L)-H*nt-X*nt-H*U))),w[0]=Y-($+C)+(C-Gt),C=(ot=O-((ht=O+$)-(C=ht-O))+($-C))-($=ot-Mt),w[1]=ot-($+C)+(C-Mt),C=(Ft=ht+$)-ht,w[2]=ht-(Ft-C)+($-C),w[3]=Ft;const G=r(q,f,4,w,u);C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(U=W-(nt=(R=134217729*W)-(R-W)))-((O=I*W)-H*nt-X*nt-H*U))-($=Y-(Gt=(X=B-(H=(R=134217729*B)-(R-B)))*(U=L-(nt=(R=134217729*L)-(R-L)))-((Mt=B*L)-H*nt-X*nt-H*U))),w[0]=Y-($+C)+(C-Gt),C=(ot=O-((ht=O+$)-(C=ht-O))+($-C))-($=ot-Mt),w[1]=ot-($+C)+(C-Mt),C=(Ft=ht+$)-ht,w[2]=ht-(Ft-C)+($-C),w[3]=Ft;const Lt=r(G,u,4,w,g);return g[Lt-1]}(x,P,M,m,d,p,S)},e.orient2dfast=function(x,P,M,m,d,p){return(P-p)*(M-d)-(x-d)*(m-p)},Object.defineProperty(e,"__esModule",{value:!0})})})(Xe,Xe.exports);var sr=Xe.exports,dn=Qo,Ee=nr,ar=ir,lr=sr.orient2d;Ee.default&&(Ee=Ee.default);Ye.exports=Rn;Ye.exports.default=Rn;function Rn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=dr(n),i=new dn(16);i.toBBox=function(m){return{minX:m[0],minY:m[1],maxX:m[0],maxY:m[1]}},i.compareMinX=function(m,d){return m[0]-d[0]},i.compareMinY=function(m,d){return m[1]-d[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=pn(l,a),r.push(a)}var c=new dn(16);for(s=0;s<r.length;s++)c.insert(Le(r[s]));for(var h=t*t,f=e*e;r.length;){var u=r.shift(),g=u.p,w=u.next.p,x=Re(g,w);if(!(x<f)){var P=x/h;l=cr(i,u.prev.p,g,w,u.next.next.p,P,c),l&&Math.min(Re(l,g),Re(l,w))<=P&&(r.push(u),r.push(pn(l,u)),i.remove(l),c.remove(u),c.insert(Le(u)),c.insert(Le(u.next)))}}u=a;var M=[];do M.push(u.p),u=u.next;while(u!==a);return M.push(u.p),M}function cr(n,t,e,o,i,r,s){for(var a=new Ee([],ur),l=n.data;l;){for(var c=0;c<l.children.length;c++){var h=l.children[c],f=l.leaf?Oe(h,e,o):hr(e,o,h);f>r||a.push({node:h,dist:f})}for(;a.length&&!a.peek().node.children;){var u=a.pop(),g=u.node,w=Oe(g,t,e),x=Oe(g,o,i);if(u.dist<w&&u.dist<x&&gn(e,g,s)&&gn(o,g,s))return g}l=a.pop(),l&&(l=l.node)}return null}function ur(n,t){return n.dist-t.dist}function hr(n,t,e){if(mn(n,e)||mn(t,e))return 0;var o=De(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=De(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=De(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=De(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 mn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function gn(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(fr(a[l].p,a[l].next.p,n,t))return!1;return!0}function pe(n,t,e){return lr(n[0],n[1],t[0],t[1],e[0],e[1])}function fr(n,t,e,o){return n!==o&&t!==e&&pe(n,t,e)>0!=pe(n,t,o)>0&&pe(e,o,n)>0!=pe(e,o,t)>0}function Le(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 dr(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++)ar(n[r],a)||l.push(n[r]);return gr(l)}function pn(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 Re(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function Oe(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 De(n,t,e,o,i,r,s,a){var l=e-n,c=o-t,h=s-i,f=a-r,u=n-i,g=t-r,w=l*l+c*c,x=l*h+c*f,P=h*h+f*f,M=l*u+c*g,m=h*u+f*g,d=w*P-x*x,p,b,z,v,S=d,V=d;d===0?(b=0,S=1,v=m,V=P):(b=x*m-P*M,v=w*m-x*M,b<0?(b=0,v=m,V=P):b>S&&(b=S,v=m+x,V=P)),v<0?(v=0,-M<0?b=0:-M>w?b=S:(b=-M,S=w)):v>V&&(v=V,-M+x<0?b=0:-M+x>w?b=S:(b=-M+x,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,F=T-_;return A*A+F*F}function mr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function gr(n){n.sort(mr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&pe(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&&pe(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 pr=Ye.exports;const yr=Zo(pr);function xr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(we(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=yr(e,t.concavity);return o.length>3?Tn([o]):null}function On(n,t={}){let e=0,o=0,i=0;return we(n,function(r){e+=r[0],o+=r[1],i++},!0),En([e/i,o/i],t.properties)}function oe(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 wr(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 br(n,t,e={}){let o;return e.final?o=yn(oe(t),oe(n)):o=yn(oe(n),oe(t)),o>180?-(360-o):o}function yn(n,t){const e=ne(n[1]),o=ne(t[1]);let i=ne(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(An(s)+360)%360}function Pr(n,t,e={}){const o=oe(n),i=oe(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=Mr(o,i);return Bn(r,"meters",e.units)}function Mr(n,t,e){e=e===void 0?qt: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 Vr(n,t,e,o={}){const i=t<0;let r=Bn(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=oe(n),a=zr(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,En(a,o.properties)}function zr(n,t,e,o){o=o===void 0?qt:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ne(n[1]),a=ne(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)),f=Math.abs(h)>1e-11?l/h:Math.cos(s),u=i*Math.sin(a)/f;return[((r+u)*180/Math.PI+540)%360-180,c*180/Math.PI]}function Sr(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Fn(n);case"FeatureCollection":return vr(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return $e(n);default:throw new Error("unknown GeoJSON type")}}function Fn(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=Wn(n.properties),n.geometry==null?t.geometry=null:t.geometry=$e(n.geometry),t}function Wn(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]=Wn(o):t[e]=o}),t}function vr(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=>Fn(e)),t}function $e(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>$e(e)),t):(t.coordinates=Nn(n.coordinates),t)}function Nn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Nn(e))}function xn(n,t,e){if(e=e||{},!$o(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??On(n);return(i===!1||i===void 0)&&(n=Sr(n)),we(n,function(s){const l=br(r,s)+t,c=Pr(r,s),h=wr(Vr(r,c,l));s[0]=h[0],s[1]=h[1]}),n}function qn(n,t,e={}){if(e.final===!0)return Dr(n,t);const o=oe(n),i=oe(t),r=ne(o[0]),s=ne(i[0]),a=ne(o[1]),l=ne(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 An(Math.atan2(c,h))}function Dr(n,t){let e=qn(t,n);return e=(e+180)%360,e}function _r(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return we(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 Er(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 Tn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function Tr(n){return Er(_r(n))}function Ar(n){return Uo(n,(t,e)=>t+Br(e),0)}function Br(n){let t=0,e;switch(n.type){case"Polygon":return wn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=wn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function wn(n){let t=0;if(n&&n.length>0){t+=Math.abs(bn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(bn(n[e]))}return t}var Ir=qt*qt/2,Fe=Math.PI/180;function bn(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]*Fe,l=r[1]*Fe,c=s[0]*Fe;e+=(c-a)*Math.sin(l),o++}return e*Ir}function kr(n){const t=xr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=On(t),o=Go(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=qn(o[s],o[s+1]),l=xn(t,-1*a,{pivot:e}),c=Tr(l),h=Ar(c);h<i&&(i=h,r=xn(c,a,{pivot:e}))}return r}function Pn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Cr(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 Ae extends vn{getBoxMesh(){se.identity(),se.setFromMatrix3(this.rotation),se.decompose(_e,ue,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(ue),e}getBoxEdge(t=16776960){const e=this.getBoxMesh();Rr.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 se.identity(),se.setFromMatrix3(this.rotation),se.decompose(_e,ue,new y.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:ue.toArray()}}static from(t,e,o,i=new Ae){if(o instanceof y.Euler)ue.setFromEuler(o);else if(o instanceof y.Quaternion)ue.copy(o);else throw new Error("传入的旋转不是欧拉角或者四元数");return se.compose(e,ue,Lr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(se),i}static fromByPath2D(t,e,o,i=new Ae){const r=kr({type:"Polygon",coordinates:[t.map(g=>[g.x,g.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Pn(s[0],s[1]),l=Pn(s[1],s[2]),c=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);_e.set(a,l,o),Mn.set(0,0,c);const[h,f]=Cr(s);return e.x=h,e.y=f,this.from(_e,e,Mn,i)}}const se=new y.Matrix4,ue=new y.Quaternion,Mn=new y.Euler,Lr=new y.Vector3(1,1,1),_e=new y.Vector3,Rr=new y.Box3;function Or(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=(f,u,g)=>`${Math.floor(f/i)},${Math.floor(u/i)},${Math.floor(g/i)}`;for(const f of t){const u=a(f.x,f.y,f.z);s.has(u)||s.set(u,[]),s.get(u).push(f)}let l=0;const c=Math.ceil(e/i)+1,h=[];for(let f=-c;f<=c;f++)for(let u=-c;u<=c;u++)for(let g=-c;g<=c;g++)f*f+u*u+g*g<=c*c&&h.push([f,u,g]);for(const f of n){const u=Math.floor(f.x/i),g=Math.floor(f.y/i),w=Math.floor(f.z/i);let x=!1;for(const[P,M,m]of h){const d=`${u+P},${g+M},${w+m}`;if(s.has(d)){for(const p of s.get(d))if(f.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 me(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 We(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=ye(n,o),s=ye(t,e);if(r||s)return!0}return!1}function Vn(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 ye(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function zn(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 Sn(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=Ae.fromByPath2D(i,t,e);return r.center.z=o,r}const Fr=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,c=a.lastIndexOf("_"),h=a.substring(l,c);if(h==="wall")continue;let f=[];for(let P=0;P<n[r].points.length;P++)f.push(new y.Vector3(n[r].points[P].x,n[r].points[P].y,n[r].points[P].z));let u=-99999;if(h==="floor"){let P=new Map;for(let m=0;m<n[r].points.length;m++){let d=n[r].points[m].z;if(d=Math.floor(d*10)/10,P.has(d)){const p=P.get(d);p.num+=1,p.points.push(n[r].points[m]),P.set(d,p)}else P.set(d,{num:1,points:[n[r].points[m]]})}let M=[...P.entries()].reduce((m,d)=>d[1].num>m[1].num?d:m);s=[],s=M[1].points.map(m=>[m.x,m.y]),f=[],f=M[1].points.map(m=>new y.Vector3(m.x,m.y,m.z)),u=M[0]}const g=zn(f),w={points:f,path:qe(s),h:g.h,minz:g.minz,maxz:g.maxz,center:{x:g.x,y:g.y,z:g.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=Sn(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"&&u!=-99999)if(e.has(u)){const P=e.get(u);P.num+=w.points.length,P.datas.push(w),e.set(u,P)}else e.set(u,{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:c}=a;l>3e3&&(s>o&&(o=s),r.push(...c))}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 f={...s[h],obb:s[h].obb.clone()};for(let u=h+1;u<s.length;u++){if(s[u].obb==null||a.includes(u))continue;if(f.obb.intersectsOBB(s[u].obb)){a.push(u);for(let P=0;P<s[u].points.length;P++)(s[u].points[P].z>o&&s[u].points[P].z-o>.1||f.type=="floor")&&f.points.push(s[u].points[P]);const w=f.points.map(P=>[P.x,P.y]);f.path=qe(w);const x=zn(f.points);f.h=x.h,f.minz=x.minz,f.maxz=x.maxz,f.center={x:x.x,y:x.y,z:x.z},f.obb=Sn(f.path,f.center,f.h,(f.maxz+f.minz)/2),f.positionArr.push(...s[u].positionArr),u=h}}f.path.length>s[h].path.length&&(a.push(h),l.push(f))}const c=[];for(let h=0;h<s.length;h++)a.includes(h)||c.push(s[h]);c.push(...l),t[r].array=c}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 c=a[l].obb,h=a[l].minz;a[l].maxz;const f=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const u=new y.Vector3;c.getSize(u);const g=[u.x,u.y,u.z];let w=0;for(const x of g)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let u=r+1;u<t.length;u++){const g=t[u].type;if(g==="people"||g==="floor")continue;const w=t[u].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,c.intersectsOBB(P)){me(w[x].points,c);const m=me(a[l].points,P),d=Vn(c,P);if(m>=.3&&d==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(g==="balcony railing"&&ye(c,w[x].points)){w[x].isDel=!0;continue}if(g==="balcony railing"&&ye(P,a[l].points)){a[l].isDel=!0;break}if(g==="balcony railing"&&We(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-f)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(g==="window"&&ye(c,w[x].points)){w[x].isDel=!0;continue}if(g==="window"&&ye(P,a[l].points)){a[l].isDel=!0;break}if(g==="window"&&We(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-f)>.3)){a[l].isDel=!0;break}}let p=!1,b=[],z=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(p=!0,b=v,z=S):(b=S,z=v),Or(z,b,.03,.5)>.5)if(p)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(We(c,P)){const D=Vn(c,P);if(D===1||D===0){if(g==="switch")continue;v.length>S.length?me(z,c)>=.5&&(w[x].isDel=!0):me(b,c)>=.5&&(w[x].isDel=!0)}else{if(s==="switch")continue;if(v.length>S.length){if(me(b,P)>=.5){a[l].isDel=!0;break}}else if(me(z,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 c=a[l].maxz,h=a[l].minz,f=s==="switch"?.1:.3;const u=a[l].averagePz;if(Math.abs(c-u)<f){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const g=Math.abs(c-u),w=Math.abs(h-u);(s==="tv"&&w<1.6||s!=="window"&&g<1.6)&&(a[l].isDel=!0),s==="window"&&g<1&&(a[l].isDel=!0)}if(s==="chair"){const g=new y.Vector3;a[l].obb.getSize(g),(g.x<.1||g.y<.1||g.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(c-h)<.4&&(a[l].isDel=!0),(h<u&&Math.abs(h-u)>1||h>u&&Math.abs(h-u)>1)&&(a[l].isDel=!0),c<u&&(a[l].isDel=!0)),s==="people"&&(Math.abs(c-h)<1&&(a[l].isDel=!0),h>u&&h-u>.3&&(a[l].isDel=!0),c<u&&(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 xe(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Wr(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 Ge(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 Xn(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,f=(c*s+h*a)/l,u=e+f*s,g=o+f*a;return{dist:Math.sqrt((n-u)**2+(t-g)**2),t:f}}function Nr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((xe(n.start,s.start)<=e||xe(n.start,s.end)<=e)&&o++,(xe(n.end,s.start)<=e||xe(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 qr(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Xn(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 Xr(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 f=0;f<2;f++){const u=f===0?n.start:n.end;for(const g of t){if(g===n)continue;const w=xe(u,g.start),x=xe(u,g.end);let P=null;if(w<=e?P=g.end:x<=e&&(P=g.start),!P)continue;const M=g.end.x-g.start.x,m=g.end.y-g.start.y,d=Math.sqrt(M*M+m*m);if(d<1e-12||Math.abs(o*M+i*m)/(r*d)>=.342)continue;const b=(P.x-u.x)*s+(P.y-u.y)*a;l[f].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(f=>f===c[0])?2:1}function Hr(n,t,e){const o=Nr(n,e),i=qr(n,t),r=Xr(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function Yr(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 $r(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 Gr(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 jr(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 Ur(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 Zr(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,g=r.end;a?g=s.end:l?u=s.start:c?g=s.start:h&&(u=s.end);const w=Math.hypot(g.x-u.x,g.y-u.y),x={...r};x.start=u,x.end=g,x.length=w,x.direction={x:(g.x-u.x)/w,y:(g.y-u.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,c)=>[c])};const o=n.map((l,c)=>({seg:l,angle:Yr(l),idx:c}));o.sort((l,c)=>l.angle-c.angle);const i=$r(o,t),r=[],s=[],a=[];for(const l of i){let c=l[0].seg;for(const M of l)M.seg.length>c.length&&(c=M.seg);const h=c.end.x-c.start.x,f=c.end.y-c.start.y,u=Math.sqrt(h*h+f*f);if(u<1e-12)continue;const g=-f/u,w=h/u,x=l.map(M=>{const m=M.seg.start.x-c.start.x,d=M.seg.start.y-c.start.y;return{seg:M.seg,offset:Math.abs(m*g+d*w),idx:M.idx}});x.sort((M,m)=>M.offset-m.offset);const P=Gr(x);for(const M of P){let m=M[0].seg;for(const E of M)E.seg.length>m.length&&(m=E.seg);const d=m.end.x-m.start.x,p=m.end.y-m.start.y,b=Math.sqrt(d*d+p*p);if(b<1e-12)continue;const z=d/b,v=p/b,S=M.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=M.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(M.map(E=>String(E.seg.buildRosource)))];const _=jr(M,m,z,v,e);for(const{l:E,r:T,srcIdxs:A}of _){if(T-E<.01)continue;const F=Ur(m,E,T,z,v,V,m.buildRosource);r.push(F),s.push(A)}}}return{...Zr(r,s),debugRPZGroups:a}}function Kr(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function Qr(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 Jr(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 f=t*r.minLengthRatio;if(h.length<f)continue;const{start:u,end:g}=h;let w=!1,x=1/0;for(const S of i){const{dist:V,t:D}=Xn(S.x,S.y,u.x,u.y,g.x,g.y);D>=-c.margin&&D<=1+c.margin&&V<=c.maxDist&&(w=!0,x=Math.min(x,V))}if(!w){`${c.maxDist}${(-c.margin).toFixed(1)}${(1+c.margin).toFixed(1)}`;continue}const P=Math.sqrt((g.x-u.x)**2+(g.y-u.y)**2);if(P<1e-12)continue;const M=(g.x-u.x)/P,m=(g.y-u.y)/P,d=Math.abs(e*M+o*m),p=Math.abs(-o*M+e*m),b=Math.max(d,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(P>.01){const S=[];for(let _=1;_<=4;_++){const E=i[_],T=E.x-u.x,A=E.y-u.y,F=(T*M+A*m)/P;S.push(F)}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:x,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function ti(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}=Hr(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 ei(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),f=Math.max(...c),u=(f-h)*s,g=(h+f)/2,w=n.start.x+g*i,x=n.start.y+g*r,P=e.box.min.z,M=e.box.max.z,m=Math.abs(M-P),d=Ge(o,n.start.x,n.start.y),p=Math.max(0,P-d),b=h<=0&&f>=1,z=n.start.z+g*(n.end.z-n.start.z);return{p:{x:w,y:x,z},width:u,full:b,height:m,groundClearance:p}}function Hn(n,t,e){var h,f,u,g,w;const o=t.map(x=>e[x]),i=[],r=[],s=[],a=[],l=[];let c;for(const x of o){if((h=x.points)!=null&&h.length)for(const P of x.points)i.push(P);if((f=x.originalPoints)!=null&&f.length)for(const P of x.originalPoints)r.push(P);if((u=x.doorAndBeamData)!=null&&u.length)for(const P of x.doorAndBeamData)s.push(P);if((g=x.insetionArr)!=null&&g.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&&!c&&(c=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),c&&(n.boxData=c)}function Yn(n,t,e){var l;const o=Kr(e),i=[],{segments:r,sourceMap:s}=je(t),a=r;for(const c of n){const h=(l=c.coordinatesByArea)==null?void 0:l.coordinates;if(!h||h.length<4)continue;const f=h.slice(0,4),u=f.reduce((V,D)=>V+D.x,0)/4,g=f.reduce((V,D)=>V+D.y,0)/4,{longSide:w,dirX:x,dirY:P}=Wr(f);if(w<.01)continue;const M=f.reduce((V,D)=>V+D.z,0)/4,m=Ge(t,u,g);if(M<m-.3)continue;const d=Qr(f,u,g);c.name;let p=Jr(a,w,x,P,d,o,c.name);p=ti(p,d,t,c.name);let b=null,z=1/0,v=0;if(p.length>0){const V=p[0];b=V.seg,z=V.minDist,v=V.ratio}let S;if(b&&(S=ei(b,f,c,r),!o.printOnly)){const V=b;V.drawWindow||(V.drawWindow=[]),V.drawWindow.push(S)}b&&i.push({windowName:c.name,windowCategory:c.category,windowCenter:c.center,wallSegment:b,distance:z,wallLengthRatio:v,drawWindow:S})}for(const c of i){const h=c.wallSegment,f=r.indexOf(h);if(f===-1)continue;const u=s[f];!u||u.length<=1||Hn(h,u,t)}return i}function ni(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],r=Yn(i,n,o),{segments:s,sourceMap:a}=je(n);for(let c=0;c<s.length;c++){const h=a[c];h&&Hn(s[c],h,n)}const l=new Set(r.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(l.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of r)if(c.drawWindow){const h=s.find(f=>Math.abs(f.start.x-c.wallSegment.start.x)<.01&&Math.abs(f.start.y-c.wallSegment.start.y)<.01&&Math.abs(f.end.x-c.wallSegment.end.x)<.01&&Math.abs(f.end.y-c.wallSegment.end.y)<.01);h&&(h.drawWindow||(h.drawWindow=[]),h.drawWindow.push(c.drawWindow))}return{segments:s,matches:r,sourceMap:a}}exports.computeContour=qe;exports.computeLocalFloorZ=Ge;exports.findWindowWalls=Yn;exports.getAllGeometry=co;exports.getBeamLine=wo;exports.getColLine=bo;exports.getMergeMeaning=Fr;exports.mergeCollinearSegments=je;exports.processData=ni;exports.updateStEdPoint=uo;
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 c=0;for(let h=0;h<n.length;++h){const f=n[h];let u=0;if(e!==(f.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 p in f.attributes){if(!o.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(f.attributes[p]),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!==f.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in f.morphAttributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[p]===void 0&&(s[p]=[]),s[p].push(f.morphAttributes[p])}if(t){let p;if(e)p=f.index.count;else if(f.attributes.position!==void 0)p=f.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,p,h),c+=p}}if(e){let h=0;const f=[];for(let u=0;u<n.length;++u){const p=n[u].index;for(let w=0;w<p.count;++w)f.push(p.getX(w)+h);h+=n[u].attributes.position.count}l.setIndex(f)}for(const h in r){const f=tn(r[h]);if(!f)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,f)}for(const h in s){const f=s[h][0].length;if(f===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let u=0;u<f;++u){const p=[];for(let x=0;x<s[h].length;++x)p.push(s[h][x][u]);const w=tn(p);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 f=l/e;for(let u=0,p=h.count;u<p;u++)for(let w=0;w<e;w++){const x=h.getComponent(u,w);a.setComponent(u+f,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,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,f=((e.x-n.x)*s-(e.y-n.y)*r)/c;return h<-i||h>1+i||f<-i||f>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 u=h.measureText(n).width;let p=Math.min(u+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=p,x.height=w;const P=x.getContext("2d");P.fillStyle=r,P.fillRect(0,0,p,w),P.fillStyle=s,P.font=`bold ${o}px ${i}`,P.textAlign="center",P.textBaseline="middle",u>l-a*2?no(P,n,p/2,w/2,l,o):P.fillText(n,p/2,w/2);const M=new y.CanvasTexture(x),m=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),d=new y.Sprite(m);d.position.set(t.x,t.y,t.z);const g=.005;return d.scale.set(p*g,w*g,1),d};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 f=a+s[h];n.measureText(f).width>i&&h>0?(n.fillText(a,e,c),a=s[h],c+=l):a=f}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 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 c=1/0,h=-1/0,f=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<f&&(f=S),S>u&&(u=S)}const p=i[0].dot(l),w=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(p)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(p)),P=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(p)),M=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(p));let m=[w,x,P,M],d=oe(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));d&&d.parallel&&(m=[w,M,P,x]);let g=0;if(o.length>0){const z=new y.Vector3().subVectors(m[1],m[0]).normalize(),v=z.clone().negate(),S=new y.Vector3().subVectors(m[3],m[0]).normalize(),V=S.clone().negate();let D=m[0].distanceTo(m[1]),_=m[0].distanceTo(m[3]),T=D/t,E=_/e,A=.001;for(let F=0;F<T;F++){let I=m[0],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(z,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;g+=B,m[0]=m[0].addScaledVector(z,t),m[3]=m[3].addScaledVector(z,t)}D=m[0].distanceTo(m[1]),T=D/t;for(let F=0;F<T;F++){let I=m[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;g+=B,m[1]=m[1].addScaledVector(v,t),m[2]=m[2].addScaledVector(v,t)}D=m[0].distanceTo(m[1]),T=D/t;for(let F=0;F<E;F++){let I=m[3],B=0;for(let L=0;L<T;L++){let W=I.clone().addScaledVector(z,t),C=W.clone().addScaledVector(V,e),R=I.clone().addScaledVector(V,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;g+=B,m[2]=m[2].addScaledVector(V,e),m[3]=m[3].addScaledVector(V,e)}}const b=m[0].distanceTo(m[1])*m[0].distanceTo(m[3]);return{facePoints:m,boxArea:b,totalInPlaneNum:g}},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)),c=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:c,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)),c=Math.min(1,Math.max(0,l)),h=Math.acos(c),f=y.MathUtils.radToDeg(h),u=1-c;return{rate:u,percent:`${(u*100).toFixed(2)}%`,angle:f,isPerpendicular:Math.abs(f-90)<.01,isParallel:f<.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,c=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),f=c.clone().normalize(),u=h.clone().normalize();let p=y.MathUtils.clamp(f.dot(u),-1,1);const w=Math.acos(Math.abs(p)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};p<0&&u.negate();const P=new y.Vector3().addVectors(f,u).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),m=en(e,M,f),d=en(o,M,f),g=(m+d)/2,b=Math.max(m,d),z=n.dot(P),v=t.dot(P),S=e.dot(P),V=o.dot(P),D=Math.min(z,v),_=Math.max(z,v),T=Math.min(S,V),E=Math.max(S,V),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&&g<a;let X;return H?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:x,avgPerpendicularDistance:g,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),c=r.dot(r),h=i.dot(s),f=r.dot(s),u=a*c-l*l;let p,w;u<1e-10?(p=0,w=c!==0?f/c:0):(p=(l*f-c*h)/u,w=(a*f-l*h)/u),p=y.MathUtils.clamp(p,0,1),w=c!==0?y.MathUtils.clamp((l*p+f)/c,0,1):0,p=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(p)),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 c=new y.Line3(t,e);const h=n.originalPoints,f=new y.Vector3;for(let x=0;x<h.length;x++){const P=h[x];let m=c.closestPointToPoint(P,!0,f).distanceTo(P);const d=Math.floor(m/a);if(d<s){const g=l.get((d+1)*a);g.count++,P.z<g.minZ&&(g.minZ=P.z),P.z>g.maxZ&&(g.maxZ=P.z)}}let u,p,w=r/2;for(const[x,P]of l)if(P.count>=w){u=P.minZ;break}for(const[x,P]of[...l.entries()].reverse())if(P.count>=w){p=P.maxZ;break}return{minZ:u,maxZ:p}},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 c=new y.Vector3,h=new y.Vector3;o.projectPoint(i,c),o.projectPoint(r,h);const f=new y.Line3(c,h),u=[],p=[],w=[];let x=new y.Vector3;return a.forEach((P,M)=>{f.closestPointToPoint(P,!0,x).distanceTo(P)<.001?(u.push(e[M]),p.push(l[M])):w.push(P)}),{newOriginalPoints:u,newProjectPoints:w,newOnLinePoints:p}},so=n=>{function t(e,o,i,r,s,a,l,c,h){let f=new y.Line3(e,o),u=new Map,p=new y.Vector3,w=e.clone(),x=o.clone(),P=0;for(;;){let M=new Map,m=0;for(let d=0;d<h.checkResults.length;d++)if(!(h.checkResults[d].allCenterPoints.length/c*100<1))for(let b=0;b<h.checkResults[d].allCenterPoints.length;b++){if(u.has(d)&&u.get(d).removePtsIndex.includes(b))continue;let z=h.checkResults[d].allCenterPoints[b];z=new y.Vector3(z.x,z.y,z.z);let v=f.closestPointToPoint(z,!0,p),S=z.distanceTo(v);Math.abs(S-s)<.01&&(m++,M.has(d)?M.get(d).removePtsIndex.push(b):M.set(d,{index:d,removePtsIndex:[b]}))}if(P==l){e=w,o=x;break}if(m<a/20*18||m==0){M.clear(),l-P<5&&(e=w,o=x,u.clear());break}else{P++;for(const[d,g]of M)u.has(d)?u.get(d).removePtsIndex.push(...g.removePtsIndex):u.set(d,g);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),f.set(e,o)}}if(u.size>0&&P!=l)for(const[M,m]of u){let d=[],g=[];for(let b=0;b<h.checkResults[M].allCenterPoints.length;b++)m.removePtsIndex.includes(b)||(d.push(h.checkResults[M].allCenterPoints[b]),g.push(h.checkResults[M].originalVertices[b]));h.checkResults[M].allCenterPoints=d,h.checkResults[M].originalVertices=g}}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,_,T]=S;V=new y.Vector3(V.x,V.y,V.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=V.distanceTo(D),r=V.distanceTo(T);let E=new y.Vector3().subVectors(V,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),c=o.rooftopPz-o.start.z,h=Math.ceil(l/i),f=Math.ceil(c/r);let u=s.clone(),p=a.clone(),w=p.clone().add(new y.Vector3(0,0,c)),x=u.clone().add(new y.Vector3(0,0,c)),P=new y.Vector3().subVectors(p,u).normalize(),M=P.clone().negate();new y.Vector3().subVectors(w,u).normalize().clone().negate();let d=i/2,g=l*c,b=i*r,z=g/b;t(u,x,P,i,d,f,h,z,o),t(p,w,M,i,d,f,h,z,o),o.start=u,o.end=p;const{newOriginalPoints:v}=Ve(u,p,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 c=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]),f=[0,1,2,0,2,3],u=new Float32Array([0,0,1,0,1,1,0,1]);c.setAttribute("position",new y.BufferAttribute(h,3)),c.setAttribute("uv",new y.BufferAttribute(u,2)),c.setIndex(f),c.computeVertexNormals();const p=new y.Mesh(c,r),w=new y.EdgesGeometry(c),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),p}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),c=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),f=[a,l,c,h];for(let m=0;m<f.length;m++)if(!this.isValidVector3(f[m]))return console.error(`墙体基础点${m}无效:`,f[m]),s;const u=a.distanceTo(l),p=Math.abs(t.rooftopPz-t.start.z);if(u===0||p===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,x=p/e,P=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let m=0;m<e;m++)for(let d=0;d<o;d++)try{const g=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar(m*x)),b=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar(m*x)),z=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar((m+1)*x)),v=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar((m+1)*x)),S={points:[g,b,z,v],userData:{}};S.userData={type:"wallSegment",row:m,col:d,originalMaterial:i,width:w,height:x},s.push(S)}catch(g){console.error(`创建墙体小平面(${m}, ${d})时出错:`,g)}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 f=!0;return r<.5&&e>0&&(f=this.checkSmallAreaDistribution(t,o,i)),c&&h&&f}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}`,[c,h,f,u]=s.vertices,p=new y.Vector3().subVectors(h,c).normalize(),w=new y.Vector3().subVectors(u,c).normalize(),x=c.distanceTo(h),P=c.distanceTo(u),M=new y.Plane;M.setFromCoplanarPoints(c,h,u);const m=x/2,d=P/2;for(let g=0;g<e.length;g++)this.isPointInWallSegmentOptimized(e[g],a,M,c,p,w,x,P,m,d,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(g))}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,f){if(Math.abs(o.distanceToPoint(t))>f)return!1;const p=new y.Vector3().subVectors(t,e),w=Math.abs(p.dot(r)),x=Math.abs(p.dot(s));if(w>c&&x>h)return!1;const P=new y.Vector3().subVectors(t,i),M=P.dot(r),m=P.dot(s),d=M>=-f&&M<=a+f,g=m>=-f&&m<=l+f;return d&&g}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 y.Plane;if(c.setFromCoplanarPoints(r,s,l),Math.abs(c.distanceToPoint(e))>i)return!1;const f=new y.Vector3().subVectors(s,r).normalize(),u=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(f,u).normalize();const p=new y.Vector3().subVectors(e,r),w=p.dot(f),x=p.dot(u),P=r.distanceTo(s),M=r.distanceTo(l),m=w>=-i&&w<=P+i,d=x>=-i&&x<=M+i;return m&&d&&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 f;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 p=`row${u.userData.row}_col${u.userData.col}`,w=r.has(p);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:p,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,p]of r){const w=(f=s.get(p.row))==null?void 0:f.get(p.col);if(w&&!w.visited){const x=[],P=[[p.row,p.col]];for(w.visited=!0;P.length>0;){const[M,m]=P.shift(),d=`row${M}_col${m}`;r.has(d)&&x.push(r.get(d));for(const[g,b]of l){const z=M+g,v=m+b;if(s.has(z)&&s.get(z).has(v)){const S=s.get(z).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,P.push([z,v]))}}}x.length>=i&&a.push(x)}}const c=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((u,p)=>p.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 x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const c=o;let h=!0;for(let x=i;x<=r;x++)t.has(c)&&t.get(c).has(x)||(h=!1);h&&s++;const f=i;let u=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(f)||(u=!1);u&&s++;const p=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(p)||(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 f,u;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(p=>{p.vertices&&p.vertices.length>0&&e.push(...p.vertices)}),e.length===0){const p=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((f=t[0].bounds)==null?void 0:f.width)||1),height:p.length*(((u=t[0].bounds)==null?void 0:u.height)||1)}}const o=Math.min(...e.map(p=>p.x)),i=Math.max(...e.map(p=>p.x)),r=Math.min(...e.map(p=>p.y)),s=Math.max(...e.map(p=>p.y)),a=Math.min(...e.map(p=>p.z)),l=Math.max(...e.map(p=>p.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 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(),c=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),f=new y.ArrowHelper(a,r,.2,255);e.add(c),e.add(h),e.add(f)}}),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)),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)),f=Math.abs(r.rooftopPz-r.start.z),u=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),p=new y.Group,w=new uo,{horizontalSubdivisions:x,verticalSubdivisions:P}=w.initLimits4(h,f),M=w.createSubdividedWallPlane(r,P,x,u,p);w.analyzePointDistribution(M,c,.01);const m=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),d=w.highlightEmptySegments(M,m,p),g=[];for(const v of d.clusters){const S=ho(v);S&&g.push(S)}const z=fo(r).direction;r.checkResults=g,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(d=>{let g=new y.Vector3(d.x,d.y,0),b=!1;for(let z=0;z<i.length;z++)if(kt(g,i[z],.01)){b=!0;break}b||i.push(g)});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),c=new y.Vector3().subVectors(l,a).normalize(),h=c.clone().cross(new y.Vector3(0,0,1)).normalize(),f=h.clone().negate(),u=[];const p=[];let w=o.length/r;console.log(w);for(let d=0;d<r;d++){const g=[];g.push(a.clone().addScaledVector(h,s)),g.push(g[0].clone().addScaledVector(c,w)),g.push(g[1].clone().addScaledVector(f,s*2)),g.push(a.clone().addScaledVector(f,w));let b=[];for(let z=0;z<i.length;z++)u.includes(z)||yo(i[z],g)&&(u.push(z),b.push(i[z]));b.length>0&&p.push(xo(b)),a=a.addScaledVector(c,w)}const x=new Float32Array(i.length*3);i.forEach((d,g)=>{x[g*3]=d.x,x[g*3+1]=d.y,x[g*3+2]=d.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,m]=Mo(p,{plane:"xy",trimRatio:0});to(M,m,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 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,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,W=B.y-s;l+=L*L,c+=L*W,h+=W*W}l/=i.length,c/=i.length,h/=i.length;const f=Po(l,c,h),u={x:-f.y,y:f.x},p=[];for(const B of i){const L=B.x-r,W=B.y-s,C=L*f.x+W*f.y,R=L*u.x+W*u.y;p.push({s:C,t:R,up:B.up})}p.sort((B,L)=>B.s-L.s);const w=p.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=p[x],m=p[P],d=(()=>{const B=p.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]})(),g=(()=>{const B=p.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,z=m.s,v=d,S=d,V=g,D=g,_=r+f.x*b+u.x*v,T=s+f.y*b+u.y*v,E=r+f.x*z+u.x*S,A=s+f.y*z+u.y*S,F=rn(_,T,V,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 d=0;d<o.length;d++){const g=o[d];g.isLine2=!0,n.push(g)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const d of n){let g=[];if(!(!d.checkResults||d.checkResults.length<=0)){for(let b=0;b<d.checkResults.length;b++){let D=function(A){for(;V[A]!==A;)V[A]=V[V[A]],A=V[A];return A};const z=d.checkResults[b];if(z.isDoor=!1,!z.originalVertices||z.originalVertices.length==0)continue;const v=[];z.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,V=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&&(V[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}g.push(..._.values())}d.mergeCheckRegion=g}}let r=new Map;for(const d of n){if(d.length<.3)continue;let g=d.rooftopPz-d.start.z,b=Math.floor(d.rooftopPz-d.start.z);r.has(b)?r.set(b,{num:r.get(b).num+1,totalHeight:r.get(b).totalHeight+g}):r.set(b,{num:1,totalHeight:g})}let s=[...r.entries()].reduce((d,g)=>g[1].num>d[1].num?g:d);s[0],s[1].totalHeight/s[1].num;const a=[];for(let d=0;d<e.length;d++){const g=e[d];if(g.isFindBeam=!1,g.category=="door"){let b=[];g.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 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:g.coordinatesByArea.heightData.minZ,maxZ:g.coordinatesByArea.heightData.maxZ,index:d,isFind:!1,inWall:!1})}}for(let d=0;d<a.length;d++){const g=a[d];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=g.boxPoints.length;for(let D=0;D<z.length;D++){const _=z[D].x,T=z[D].y;for(let E=0,A=V-1;E<V;A=E++){const F=g.boxPoints[E].x,I=g.boxPoints[E].y,B=g.boxPoints[A].x,L=g.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=g.doorStartPt.distanceTo(g.doorEndPt),E=D.distanceTo(_),A=Jt(g.doorStartPt,g.doorEndPt,D,_);if(Math.abs(E-T)<.5&&A&&A.angleDeg<15){g.doorStartPt=new y.Vector3(n[b].start.x,n[b].start.y,0),g.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(g.doorStartPt,g.doorEndPt,D,_,{parallelAngleMax:y.MathUtils.degToRad(15)}),I=g.doorStartPt.distanceTo(D),B=g.doorStartPt.distanceTo(_),L=g.doorEndPt.distanceTo(D),W=g.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||W<.2;if(F&&F.type=="collinear_overlap"&&F.maxPerpendicularDistance<.1&&!C){g.inWall=!0;break}else{let R=new y.Line3(D,_),H=R.closestPointToPoint(g.doorStartPt,!0,new y.Vector3),X=R.closestPointToPoint(g.doorEndPt,!0,new y.Vector3),ot=H.distanceTo(g.doorStartPt),K=X.distanceTo(g.doorEndPt);if(ot<.1||K<.1){g.inWall=!0;break}}}}else continue}}let l=0,c=[],h=[],f=[];const u=[];let p=.15;for(let d=0;d<n.length;d++){const g=n[d];if(g.noDetection||(g.doorAndBeamData=[],!g.mergeCheckRegion||g.mergeCheckRegion.length==0))continue;g.completePointAreaPercentage=-1;let b=new y.Box3;b.setFromPoints(g.originalPoints);let z=b.max.z;b.min.z;const v=new y.Vector3(g.start.x,g.start.y,g.start.z),S=new y.Vector3(g.end.x,g.end.y,g.end.z);let V=g.rooftopPz-g.start.z,D=0;for(const T of g.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/g.length*100,Nt=g.rooftopPz-O.facePoints[2].z;if(Vt<1.5||z<O.facePoints[2].z||Nt>V/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-g.start.z)<.25){if(Y>.17&&g.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,g.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(g.start.x,g.start.y,0),pt=new y.Vector3(g.end.x,g.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==d)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&&(g.length-Y>.2||g.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&&g.length-Y>.1)continue;if(!k&&!dt&&g.length-Y<.1&&g.length<1.8)continue}}else continue}if(ut<Pt||N<Pt){const{newOriginalPoints:Ut}=Ve(q,j,g.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(g.start.x,g.start.y,0),pt=new y.Vector3(g.end.x,g.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==d)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&&(g.length-Y>.2||g.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&&g.length-Y>.1)continue;if(!k&&!dt&&g.length-Y<.1&&g.length<1.8)continue}}else continue}Y=ct.distanceTo(tt)}if(Zt<85&&Y>.3||Y>.7&&Vt>V-V/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(g.start.x,g.start.y,0),new y.Vector3(g.end.x,g.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<p||U<p||it<p||mt<p||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Et=J)}(_t||qt||Math.abs(Vt-V)>.1&&Vt>V/2&&Y>.3)&&(Rt=!0)}}if(Rt){let qt=!1;for(let Z=0;Z<f.length;Z++){let k=ne(f[Z].start,f[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}f.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(g.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(d)||h.push(d),g.checkResults[T.index].isDoor=!0;let ut="",N={id:l,beamStart:tt,beamEnd:ct,beamHeight:g.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<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 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=c[Z].linesIndex,pt=c[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==d)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<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=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(g.doorAndBeamData.push(N),c.push({linesIndex:d,doorIndex:g.doorAndBeamData.length-1}),l++,Tt&&Y<2)break}}}let _=g.length*(g.rooftopPz-g.start.z);g.completePointAreaPercentage=D/_*100}if(h.length>1)for(let d=0;d<h.length;d++){let g=[];for(let b=0;b<n[h[d]].doorAndBeamData.length;b++){let z=!1;if(n[h[d]].doorAndBeamData[b].type==="beam"&&n[h[d]].doorAndBeamData[b].beamNearWallVec.x==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.y==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.z==0&&n[h[d]].doorAndBeamData[b].nearId==-1&&(z=!0),!z){let v=n[h[d]].doorAndBeamData[b].doorStart.clone(),S=n[h[d]].doorAndBeamData[b].doorEnd.clone();v.z=S.z=0;let V=v.distanceTo(S);for(let D=0;D<h.length;D++)if(d!=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(V-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[d]].doorAndBeamData[b].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),z=!0;break}}}}z||g.push(n[h[d]].doorAndBeamData[b])}g.length!=n[h[d]].doorAndBeamData.length&&(n[h[d]].doorAndBeamData=g)}let w=.65,x=2,P=[],M=[];for(let d=0;d<a.length;d++){if(a[d].isFind||a[d].inWall)continue;let g=new y.Vector3(a[d].doorStartPt.x,a[d].doorStartPt.y,0),b=new y.Vector3(a[d].doorEndPt.x,a[d].doorEndPt.y,0),z=new y.Vector3().subVectors(g,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),V=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,V).normalize(),_=.3,T=g.clone().addScaledVector(z,_),E=b.clone().addScaledVector(z.clone().negate(),_),A=S.clone().addScaledVector(D,_),F=V.clone().addScaledVector(D.clone().negate(),_);te(T,E,A,F);let I=Jt(T,E,A,F),B=g.distanceTo(S)>b.distanceTo(S)?b:g,L=B.distanceTo(S),W=B.distanceTo(V);if((L<p||W<p)&&I&&!I.isParallel){let R=g.distanceTo(S),H=g.distanceTo(V),X=R<H?S:V,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,V,G,ht),Nt=ne(S,V,G,ht),Rt=te(S,V,Y,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<p||Rt.point.distanceTo(V)<p),(Zt&&Zt.angle>85||Nt&&Nt.type=="collinear_gap")&&_t){let Tt=new y.Line3(S,V),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(g,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[d].index].isFindBeam=!0,e[a[d].index].isFindOnlyDoor=!0,u.push([{id:l,beamStart:Wt,beamEnd:Et}]),l++,ot=!0;break}}if(ot)break}}}let m=[];for(let d=0;d<n.length;d++)n[d].isLine2||m.push(n[d]),n[d].isLine2&&n[d].doorAndBeamData.length!=0&&m.push(n[d]);return n.length=0,n.push(...m),{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=[],f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(u,f).normalize().clone().negate(),x=new y.Vector3,P=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let m=0;m<n.length;m++){let d=n[m].length;if(m==l||d<i||d>r)continue;let g=new y.Vector3(n[m].start.x,n[m].start.y,n[m].start.z),b=new y.Vector3(n[m].end.x,n[m].end.y,n[m].end.z),z=re(f,u,g,b);if(!z||z.angle<85)continue;let v=kt(g,f),S=kt(g,u),V=kt(b,f),D=kt(b,u);if(!(!v&&!S&&!V&&!D)){v||S?(x=g.clone(),P=b.clone()):(x=b.clone(),P=g.clone()),M=new y.Vector3().subVectors(P,x).normalize(),M.clone().negate();for(let _=0;_<n.length;_++){let T=n[_].length;if(_==l||_==m||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(g,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==m||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,f),Y=kt(rt,u);if(!O&&!Y)continue;let Vt=c*d;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[m].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(m=>o.add(m)),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 y.Vector3,end:new y.Vector3}},f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),p=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let m=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),d=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),g=kt(m,f),b=kt(d,f),z=kt(m,u),v=kt(d,u);if(g||b?p=!1:(z||v)&&(w=!1),!p&&!w)break}if(!p&&!w)continue;let x=new y.Vector3;p||([f,u]=[u,f]),x=new y.Vector3().subVectors(u,f).normalize();let P=x.clone().negate();for(let M=0;M<n.length;M++){let m=n[M].length;if(M==l||o.has(M)||m<i||m>r)continue;let d=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),g=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),b=re(f,u,d,g);if(!b||b.angle<85)continue;let z=kt(d,u),v=kt(g,u);if(!z&&!v)continue;new y.Vector3;let S=new y.Vector3;z?(d.clone(),S=g.clone()):(g.clone(),S=d.clone());for(let V=0;V<n.length;V++){let D=n[V].length;if(V==l||V==M||o.has(V)||D<i||D>r)continue;let _=new y.Vector3(n[V].start.x,n[V].start.y,n[V].start.z),T=new y.Vector3(n[V].end.x,n[V].end.y,n[V].end.z),E=re(d,g,_,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==V||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=c*m;if(!(H<s||H>a)){h.indexs=[n[l].uuid,n[M].uuid,n[V].uuid],h.missingEdge.start=B,h.missingEdge.end=f;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,c=t[0],h=o[0],f=0,u=0;h>c==h>-c?(r=c,c=t[++f]):(r=h,h=o[++u]);let p=0;if(f<n&&u<e)for(h>c==h>-c?(s=c+r,a=r-(s-c),c=t[++f]):(s=h+r,a=r-(s-h),h=o[++u]),r=s,a!==0&&(i[p++]=a);f<n&&u<e;)h>c==h>-c?(s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u]),r=s,a!==0&&(i[p++]=a);for(;f<n;)s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f],r=s,a!==0&&(i[p++]=a);for(;u<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u],r=s,a!==0&&(i[p++]=a);return(r!==0||p===0)&&(i[p++]=r),p}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,c,h,f,u,p,w,x,P,M,m,d,g,b,z,v,S;const V=n-i,D=e-i,_=t-r,T=o-r;g=V*T,u=$t*V,p=u-(u-V),w=V-p,u=$t*T,x=u-(u-T),P=T-x,b=w*P-(g-p*x-w*x-p*P),z=_*D,u=$t*_,p=u-(u-_),w=_-p,u=$t*D,x=u-(u-D),P=D-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,me[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,me[1]=d-(M+f)+(f-z),S=m+M,f=S-m,me[2]=m-(S-f)+(M-f),me[3]=S;let E=vo(4,me),A=_o*s;if(E>=A||-E>=A||(f=n-V,a=n-(V+f)+(f-i),f=e-D,c=e-(D+f)+(f-i),f=t-_,l=t-(_+f)+(f-r),f=o-T,h=o-(T+f)+(f-r),a===0&&l===0&&c===0&&h===0)||(A=To*s+So*Math.abs(E),E+=V*h+T*a-(_*c+D*l),E>=A||-E>=A))return E;g=a*T,u=$t*a,p=u-(u-a),w=a-p,u=$t*T,x=u-(u-T),P=T-x,b=w*P-(g-p*x-w*x-p*P),z=l*D,u=$t*l,p=u-(u-l),w=l-p,u=$t*D,x=u-(u-D),P=D-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),jt[3]=S;const F=Fe(4,me,4,jt,sn);g=V*h,u=$t*V,p=u-(u-V),w=V-p,u=$t*h,x=u-(u-h),P=h-x,b=w*P-(g-p*x-w*x-p*P),z=_*c,u=$t*_,p=u-(u-_),w=_-p,u=$t*c,x=u-(u-c),P=c-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),jt[3]=S;const I=Fe(F,sn,4,jt,an);g=a*h,u=$t*a,p=u-(u-a),w=a-p,u=$t*h,x=u-(u-h),P=h-x,b=w*P-(g-p*x-w*x-p*P),z=l*c,u=$t*l,p=u-(u-l),w=l-p,u=$t*c,x=u-(u-c),P=c-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),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,c=Math.abs(s+a);return Math.abs(l)>=Do*c?l:-Eo(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 f=(a+c)/2,u=(l+h)/2;let p=0,w=0,x=0;for(let V=0,D=1/0;V<s;V++){const _=We(f,u,t[2*V],t[2*V+1]);_<D&&(p=V,D=_)}const P=t[2*p],M=t[2*p+1];for(let V=0,D=1/0;V<s;V++){if(V===p)continue;const _=We(P,M,t[2*V],t[2*V+1]);_<D&&_>0&&(w=V,D=_)}let m=t[2*w],d=t[2*w+1],g=1/0;for(let V=0;V<s;V++){if(V===p||V===w)continue;const D=Io(P,M,m,d,t[2*V],t[2*V+1]);D<g&&(x=V,g=D)}let b=t[2*x],z=t[2*x+1];if(g===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,T=-1/0;_<s;_++){const E=this._ids[_],A=this._dists[E];A>T&&(V[D++]=E,T=A)}this.hull=V.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(P,M,m,d,b,z)<0){const V=w,D=m,_=d;w=x,m=b,d=z,x=V,b=D,z=_}const v=ko(P,M,m,d,b,z);this._cx=v.x,this._cy=v.y;for(let V=0;V<s;V++)this._dists[V]=We(t[2*V],t[2*V+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=p;let S=3;o[p]=e[x]=w,o[w]=e[p]=x,o[x]=e[w]=p,i[p]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(P,M)]=p,r[this._hashKey(m,d)]=w,r[this._hashKey(b,z)]=x,this.trianglesLen=0,this._addTriangle(p,w,x,-1,-1,-1);for(let V=0,D=0,_=0;V<this._ids.length;V++){const T=this._ids[V],E=t[2*T],A=t[2*T+1];if(V>0&&Math.abs(E-D)<=cn&&Math.abs(A-_)<=cn||(D=E,_=A,T===p||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 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,f=c+(a+2)%3,u=e[s],p=e[t],w=e[h],x=e[f];if(Bo(i[2*u],i[2*u+1],i[2*p],i[2*p+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=u;const M=o[f];if(M===-1){let d=this._hullStart;do{if(this._hullTri[d]===f){this._hullTri[d]=t;break}d=this._hullPrev[d]}while(d!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,f);const m=c+(a+1)%3;r<De.length&&(De[r++]=m)}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,c=t-a,h=e-s,f=o-a,u=i-s,p=r-a,w=l*l+c*c,x=h*h+f*f,P=u*u+p*p;return l*(f*P-x*p)-c*(h*P-x*u)+w*(h*p-f*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,f=l*l+c*c,u=.5/(s*c-a*l),p=(c*h-a*f)*u,w=(s*f-l*h)*u;return p*p+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,f=l*l+c*c,u=.5/(s*c-a*l),p=n+(c*h-a*f)*u,w=t+(s*f-l*h)*u;return{x:p,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,m,d;x<M;x+=3,P+=2){const g=o[x]*2,b=o[x+1]*2,z=o[x+2]*2,v=t[g],S=t[g+1],V=t[b],D=t[b+1],_=t[z],T=t[z+1],E=V-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);m=(v+_)/2-L*I,d=(S+T)/2+L*F}else{const L=1/B,W=E*E+A*A,C=F*F+I*I;m=v+(I*W-A*C)*L,d=S+(E*C-F*W)*L}a[P]=m,a[P+1]=d}let l=e[e.length-1],c,h=l*4,f,u=t[2*l],p,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],c=h,f=u,p=w,h=l*4,u=t[2*l],w=t[2*l+1],i[c+2]=i[h]=p-w,i[c+3]=i[h+1]=u-f}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,f=o.length;h<f;++h){const u=o[h];if(u<h)continue;const p=Math.floor(h/3)*2,w=Math.floor(u/3)*2,x=s[p],P=s[p+1],M=s[w],m=s[w+1];this._renderSegment(x,P,M,m,t)}let l,c=r[r.length-1];for(let h=0;h<r.length;++h){l=c,c=r[h];const f=Math.floor(i[c]/3)*2,u=s[f],p=s[f+1],w=l*4,x=this._project(u,p,a[w+2],a[w+3]);x&&this._renderSegment(u,p,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 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),f,u=0;for(let p=0;p<o;p+=2)if(r=a,s=l,a=e[p],l=e[p+1],c=h,h=this._regioncode(a,l),c===0&&h===0)f=u,u=0,i?i.push(a,l):i=[a,l];else{let w,x,P,M,m;if(c===0){if((w=this._clipSegment(r,s,a,l,c,h))===null)continue;[x,P,M,m]=w}else{if((w=this._clipSegment(a,l,r,s,h,c))===null)continue;[M,m,x,P]=w,f=u,u=this._edgecode(x,P),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(x,P):i=[x,P]}f=u,u=this._edgecode(M,m),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(M,m):i=[M,m]}if(i)f=u,u=this._edgecode(i[0],i[1]),f&&u&&this._edge(t,f,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,f,u=this._edgecode(a[h-2],a[h-1]);c<h;c+=2)f=u,u=this._edgecode(a[c],a[c+1]),f&&u&&(c=this._edge(t,f,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 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},(u,p)=>p).sort((u,p)=>e[2*u]-e[2*p]||e[2*u+1]-e[2*p+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]],f=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let u=0,p=e.length/2;u<p;++u){const w=qo(e[2*u],e[2*u+1],f);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 f=a.indexOf(t);f>0&&(yield a[f-1]),f<a.length-1&&(yield a[f+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 f=o[(i[t]+1)%o.length];f!==h&&(yield f);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,f=ge(e-c[t*2],2)+ge(o-c[t*2+1],2);const u=i[t];let p=u;do{let w=l[p];const x=ge(e-c[w*2],2)+ge(o-c[w*2+1],2);if(x<f&&(f=x,h=w),p=p%3===2?p-2:p+1,l[p]!==t)break;if(p=a[p],p===-1){if(p=r[(s[t]+1)%r.length],p!==w&&ge(e-c[p*2],2)+ge(o-c[p*2+1],2)<f)return p;break}}while(p!==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,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),c=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return c===0?1/0:s*a*l/(4*c)}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],[m,d]=e[x],[g,b]=e[P],[z,v]=e[M],S=$o(m,d,g,b,z,v),V=Yo(e,x,P,M);if(S<=1/V)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 c=a[0][0],h=[],f=new Set;let u=c,p=-1;do{h.push(e[u]),f.add(u);const w=l.get(u)||[];let x=w.find(P=>P!==p&&!f.has(P));if(x===void 0&&(x=w.find(P=>P!==p)),x===void 0)break;p=u,u=x}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,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,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,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,c,h=0,f=0,u,p=n.type,w=p==="FeatureCollection",x=p==="Feature",P=w?n.features.length:1,M=0;M<P;M++){c=w?n.features[M].geometry:x?n.geometry:n,u=c?c.type==="GeometryCollection":!1,a=u?c.geometries.length:1;for(var m=0;m<a;m++){var d=0,g=0;if(s=u?c.geometries[m]: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,f,M,d,g)===!1)return!1;f++,d++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],f,M,d,g)===!1)return!1;f++,b==="MultiPoint"&&d++}b==="LineString"&&d++;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],f,M,d,g)===!1)return!1;f++}b==="MultiLineString"&&d++,b==="Polygon"&&g++}b==="Polygon"&&d++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(g=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],f,M,d,g)===!1)return!1;f++}g++}d++}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,f,u=0,p=n.type==="FeatureCollection",w=n.type==="Feature",x=p?n.features.length:1;for(e=0;e<x;e++){for(a=p?n.features[e].geometry:w?n.geometry:n,c=p?n.features[e].properties:w?n.properties:{},h=p?n.features[e].bbox:w?n.bbox:void 0,f=p?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,f)===!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,f)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],u,c,h,f)===!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:{}},On={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(m,d,g,b,z){(function v(S,V,D,_,T){for(;_>D;){if(_-D>600){var E=_-D+1,A=V-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(V-A*I/E+B)),W=Math.min(_,Math.floor(V+(E-A)*I/E+B));v(S,V,L,W,T)}var C=S[V],R=D,H=_;for(o(S,D,V),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<=V&&(D=H+1),V<=H&&(_=H-1)}})(m,d,g||0,b||m.length-1,z||i)}function o(m,d,g){var b=m[d];m[d]=m[g],m[g]=b}function i(m,d){return m<d?-1:m>d?1:0}var r=function(m){m===void 0&&(m=9),this._maxEntries=Math.max(4,m),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(m,d,g){if(!g)return d.indexOf(m);for(var b=0;b<d.length;b++)if(g(m,d[b]))return b;return-1}function a(m,d){l(m,0,m.children.length,d,m)}function l(m,d,g,b,z){z||(z=P(null)),z.minX=1/0,z.minY=1/0,z.maxX=-1/0,z.maxY=-1/0;for(var v=d;v<g;v++){var S=m.children[v];c(z,m.leaf?b(S):S)}return z}function c(m,d){return m.minX=Math.min(m.minX,d.minX),m.minY=Math.min(m.minY,d.minY),m.maxX=Math.max(m.maxX,d.maxX),m.maxY=Math.max(m.maxY,d.maxY),m}function h(m,d){return m.minX-d.minX}function f(m,d){return m.minY-d.minY}function u(m){return(m.maxX-m.minX)*(m.maxY-m.minY)}function p(m){return m.maxX-m.minX+(m.maxY-m.minY)}function w(m,d){return m.minX<=d.minX&&m.minY<=d.minY&&d.maxX<=m.maxX&&d.maxY<=m.maxY}function x(m,d){return d.minX<=m.maxX&&d.minY<=m.maxY&&d.maxX>=m.minX&&d.maxY>=m.minY}function P(m){return{children:m,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(m,d,g,b,z){for(var v=[d,g];v.length;)if(!((g=v.pop())-(d=v.pop())<=b)){var S=d+Math.ceil((g-d)/b/2)*b;e(m,S,d,g,z),v.push(d,S,S,g)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(m){var d=this.data,g=[];if(!x(m,d))return g;for(var b=this.toBBox,z=[];d;){for(var v=0;v<d.children.length;v++){var S=d.children[v],V=d.leaf?b(S):S;x(m,V)&&(d.leaf?g.push(S):w(m,V)?this._all(S,g):z.push(S))}d=z.pop()}return g},r.prototype.collides=function(m){var d=this.data;if(!x(m,d))return!1;for(var g=[];d;){for(var b=0;b<d.children.length;b++){var z=d.children[b],v=d.leaf?this.toBBox(z):z;if(x(m,v)){if(d.leaf||w(m,v))return!0;g.push(z)}}d=g.pop()}return!1},r.prototype.load=function(m){if(!m||!m.length)return this;if(m.length<this._minEntries){for(var d=0;d<m.length;d++)this.insert(m[d]);return this}var g=this._build(m.slice(),0,m.length-1,0);if(this.data.children.length)if(this.data.height===g.height)this._splitRoot(this.data,g);else{if(this.data.height<g.height){var b=this.data;this.data=g,g=b}this._insert(g,this.data.height-g.height-1,!0)}else this.data=g;return this},r.prototype.insert=function(m){return m&&this._insert(m,this.data.height-1),this},r.prototype.clear=function(){return this.data=P([]),this},r.prototype.remove=function(m,d){if(!m)return this;for(var g,b,z,v=this.data,S=this.toBBox(m),V=[],D=[];v||V.length;){if(v||(v=V.pop(),b=V[V.length-1],g=D.pop(),z=!0),v.leaf){var _=s(m,v.children,d);if(_!==-1)return v.children.splice(_,1),V.push(v),this._condense(V),this}z||v.leaf||!w(v,S)?b?(g++,v=b.children[g],z=!1):v=null:(V.push(v),D.push(g),g=0,b=v,v=v.children[0])}return this},r.prototype.toBBox=function(m){return m},r.prototype.compareMinX=function(m,d){return m.minX-d.minX},r.prototype.compareMinY=function(m,d){return m.minY-d.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(m){return this.data=m,this},r.prototype._all=function(m,d){for(var g=[];m;)m.leaf?d.push.apply(d,m.children):g.push.apply(g,m.children),m=g.pop();return d},r.prototype._build=function(m,d,g,b){var z,v=g-d+1,S=this._maxEntries;if(v<=S)return a(z=P(m.slice(d,g+1)),this.toBBox),z;b||(b=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,b-1))),(z=P([])).leaf=!1,z.height=b;var V=Math.ceil(v/S),D=V*Math.ceil(Math.sqrt(S));M(m,d,g,D,this.compareMinX);for(var _=d;_<=g;_+=D){var T=Math.min(_+D-1,g);M(m,_,T,V,this.compareMinY);for(var E=_;E<=T;E+=V){var A=Math.min(E+V-1,T);z.children.push(this._build(m,E,A,b-1))}}return a(z,this.toBBox),z},r.prototype._chooseSubtree=function(m,d,g,b){for(;b.push(d),!d.leaf&&b.length-1!==g;){for(var z=1/0,v=1/0,S=void 0,V=0;V<d.children.length;V++){var D=d.children[V],_=u(D),T=(E=m,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,z=_<z?_:z,S=D):T===v&&_<z&&(z=_,S=D)}d=S||d.children[0]}var E,A;return d},r.prototype._insert=function(m,d,g){var b=g?m:this.toBBox(m),z=[],v=this._chooseSubtree(b,this.data,d,z);for(v.children.push(m),c(v,b);d>=0&&z[d].children.length>this._maxEntries;)this._split(z,d),d--;this._adjustParentBBoxes(b,z,d)},r.prototype._split=function(m,d){var g=m[d],b=g.children.length,z=this._minEntries;this._chooseSplitAxis(g,z,b);var v=this._chooseSplitIndex(g,z,b),S=P(g.children.splice(v,g.children.length-v));S.height=g.height,S.leaf=g.leaf,a(g,this.toBBox),a(S,this.toBBox),d?m[d-1].children.push(S):this._splitRoot(g,S)},r.prototype._splitRoot=function(m,d){this.data=P([m,d]),this.data.height=m.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(m,d,g){for(var b,z,v,S,V,D,_,T=1/0,E=1/0,A=d;A<=g-d;A++){var F=l(m,0,A,this.toBBox),I=l(m,A,g,this.toBBox),B=(z=F,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(F)+u(I);B<T?(T=B,b=A,E=L<E?L:E):B===T&&L<E&&(E=L,b=A)}return b||g-d},r.prototype._chooseSplitAxis=function(m,d,g){var b=m.leaf?this.compareMinX:h,z=m.leaf?this.compareMinY:f;this._allDistMargin(m,d,g,b)<this._allDistMargin(m,d,g,z)&&m.children.sort(b)},r.prototype._allDistMargin=function(m,d,g,b){m.children.sort(b);for(var z=this.toBBox,v=l(m,0,d,z),S=l(m,g-d,g,z),V=p(v)+p(S),D=d;D<g-d;D++){var _=m.children[D];c(v,m.leaf?z(_):_),V+=p(v)}for(var T=g-d-1;T>=d;T--){var E=m.children[T];c(S,m.leaf?z(E):E),V+=p(S)}return V},r.prototype._adjustParentBBoxes=function(m,d,g){for(var b=g;b>=0;b--)c(d[b],m)},r.prototype._condense=function(m){for(var d=m.length-1,g=void 0;d>=0;d--)m[d].children.length===0?d>0?(g=m[d-1].children).splice(g.indexOf(m[d]),1):this.clear():a(m[d],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,c=0,h=l-1;c<l;h=c++){var f=e[o+c*2+0],u=e[o+c*2+1],p=e[o+h*2+0],w=e[o+h*2+1],x=u>s!=w>s&&r<(p-f)*(s-u)/(w-u)+f;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,c=0,h=l-1;c<l;h=c++){var f=e[c+o][0],u=e[c+o][1],p=e[h+o][0],w=e[h+o][1],x=u>s!=w>s&&r<(p-f)*(s-u)/(w-u)+f;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,m,d){let g,b,z,v,S=P[0],V=m[0],D=0,_=0;V>S==V>-S?(g=S,S=P[++D]):(g=V,V=m[++_]);let T=0;if(D<x&&_<M)for(V>S==V>-S?(z=g-((b=S+g)-S),S=P[++D]):(z=g-((b=V+g)-V),V=m[++_]),g=b,z!==0&&(d[T++]=z);D<x&&_<M;)V>S==V>-S?(z=g-((b=g+S)-(v=b-g))+(S-v),S=P[++D]):(z=g-((b=g+V)-(v=b-g))+(V-v),V=m[++_]),g=b,z!==0&&(d[T++]=z);for(;D<x;)z=g-((b=g+S)-(v=b-g))+(S-v),S=P[++D],g=b,z!==0&&(d[T++]=z);for(;_<M;)z=g-((b=g+V)-(v=b-g))+(V-v),V=m[++_],g=b,z!==0&&(d[T++]=z);return g===0&&T!==0||(d[T++]=g),T}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,c=11093356479670487e-47,h=s(4),f=s(8),u=s(12),p=s(16),w=s(4);e.orient2d=function(x,P,M,m,d,g){const b=(P-g)*(M-d),z=(x-d)*(m-g),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,_,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=V-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=V-(Rt+(C=V-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=c*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,f);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,f,4,w,u);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,u,4,w,p);return p[Wt-1]}(x,P,M,m,d,g,S)},e.orient2dfast=function(x,P,M,m,d,g){return(P-g)*(M-d)-(x-d)*(m-g)},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(m){return{minX:m[0],minY:m[1],maxX:m[0],maxY:m[1]}},i.compareMinX=function(m,d){return m[0]-d[0]},i.compareMinY=function(m,d){return m[1]-d[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(Ne(r[s]));for(var h=t*t,f=e*e;r.length;){var u=r.shift(),p=u.p,w=u.next.p,x=qe(p,w);if(!(x<f)){var P=x/h;l=dr(i,u.prev.p,p,w,u.next.next.p,P,c),l&&Math.min(qe(l,p),qe(l,w))<=P&&(r.push(u),r.push(bn(l,u)),i.remove(l),c.remove(u),c.insert(Ne(u)),c.insert(Ne(u.next)))}}u=a;var M=[];do M.push(u.p),u=u.next;while(u!==a);return M.push(u.p),M}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],f=l.leaf?Xe(h,e,o):gr(e,o,h);f>r||a.push({node:h,dist:f})}for(;a.length&&!a.peek().node.children;){var u=a.pop(),p=u.node,w=Xe(p,t,e),x=Xe(p,o,i);if(u.dist<w&&u.dist<x&&wn(e,p,s)&&wn(o,p,s))return p}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,c=o-t,h=s-i,f=a-r,u=n-i,p=t-r,w=l*l+c*c,x=l*h+c*f,P=h*h+f*f,M=l*u+c*p,m=h*u+f*p,d=w*P-x*x,g,b,z,v,S=d,V=d;d===0?(b=0,S=1,v=m,V=P):(b=x*m-P*M,v=w*m-x*M,b<0?(b=0,v=m,V=P):b>S&&(b=S,v=m+x,V=P)),v<0?(v=0,-M<0?b=0:-M>w?b=S:(b=-M,S=w)):v>V&&(v=V,-M+x<0?b=0:-M+x>w?b=S:(b=-M+x,S=w)),g=b===0?0:b/S,z=v===0?0:v/V;var D=(1-g)*n+g*e,_=(1-g)*t+g*o,T=(1-z)*i+z*s,E=(1-z)*r+z*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)),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?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 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)),f=Math.abs(h)>1e-11?l/h:Math.cos(s),u=i*Math.sin(a)/f;return[((r+u)*180/Math.PI+540)%360-180,c*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,c=Sr(r,s),h=Vr(Dr(r,c,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]),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=$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,c=s[0]*He;e+=(c-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}),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 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(p=>[p.x,p.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]);Ee.set(a,l,o),vn.set(0,0,c);const[h,f]=Fr(s);return e.x=h,e.y=f,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=(f,u,p)=>`${Math.floor(f/i)},${Math.floor(u/i)},${Math.floor(p/i)}`;for(const f of t){const u=a(f.x,f.y,f.z);s.has(u)||s.set(u,[]),s.get(u).push(f)}let l=0;const c=Math.ceil(e/i)+1,h=[];for(let f=-c;f<=c;f++)for(let u=-c;u<=c;u++)for(let p=-c;p<=c;p++)f*f+u*u+p*p<=c*c&&h.push([f,u,p]);for(const f of n){const u=Math.floor(f.x/i),p=Math.floor(f.y/i),w=Math.floor(f.z/i);let x=!1;for(const[P,M,m]of h){const d=`${u+P},${p+M},${w+m}`;if(s.has(d)){for(const g of s.get(d))if(f.distanceToSquared(g)<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,c=a.lastIndexOf("_"),h=a.substring(l,c);if(h==="wall")continue;let f=[];for(let P=0;P<n[r].points.length;P++)f.push(new y.Vector3(n[r].points[P].x,n[r].points[P].y,n[r].points[P].z));let u=-99999;if(h==="floor"){let P=new Map;for(let m=0;m<n[r].points.length;m++){let d=n[r].points[m].z;if(d=Math.floor(d*10)/10,P.has(d)){const g=P.get(d);g.num+=1,g.points.push(n[r].points[m]),P.set(d,g)}else P.set(d,{num:1,points:[n[r].points[m]]})}let M=[...P.entries()].reduce((m,d)=>d[1].num>m[1].num?d:m);s=[],s=M[1].points.map(m=>[m.x,m.y]),f=[],f=M[1].points.map(m=>new y.Vector3(m.x,m.y,m.z)),u=M[0]}const p=_n(f),w={points:f,path:Ge(s),h:p.h,minz:p.minz,maxz:p.maxz,center:{x:p.x,y:p.y,z:p.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"&&u!=-99999)if(e.has(u)){const P=e.get(u);P.num+=w.points.length,P.datas.push(w),e.set(u,P)}else e.set(u,{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:c}=a;l>3e3&&(s>o&&(o=s),r.push(...c))}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 f={...s[h],obb:s[h].obb.clone()};for(let u=h+1;u<s.length;u++){if(s[u].obb==null||a.includes(u))continue;if(f.obb.intersectsOBB(s[u].obb)){a.push(u);for(let P=0;P<s[u].points.length;P++)(s[u].points[P].z>o&&s[u].points[P].z-o>.1||f.type=="floor")&&f.points.push(s[u].points[P]);const w=f.points.map(P=>[P.x,P.y]);f.path=Ge(w);const x=_n(f.points);f.h=x.h,f.minz=x.minz,f.maxz=x.maxz,f.center={x:x.x,y:x.y,z:x.z},f.obb=Tn(f.path,f.center,f.h,(f.maxz+f.minz)/2),f.positionArr.push(...s[u].positionArr),u=h}}f.path.length>s[h].path.length&&(a.push(h),l.push(f))}const c=[];for(let h=0;h<s.length;h++)a.includes(h)||c.push(s[h]);c.push(...l),t[r].array=c}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 c=a[l].obb,h=a[l].minz;a[l].maxz;const f=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const u=new y.Vector3;c.getSize(u);const p=[u.x,u.y,u.z];let w=0;for(const x of p)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let u=r+1;u<t.length;u++){const p=t[u].type;if(p==="people"||p==="floor")continue;const w=t[u].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,c.intersectsOBB(P)){pe(w[x].points,c);const m=pe(a[l].points,P),d=Dn(c,P);if(m>=.3&&d==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(p==="balcony railing"&&we(c,w[x].points)){w[x].isDel=!0;continue}if(p==="balcony railing"&&we(P,a[l].points)){a[l].isDel=!0;break}if(p==="balcony railing"&&Ye(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-f)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(p==="window"&&we(c,w[x].points)){w[x].isDel=!0;continue}if(p==="window"&&we(P,a[l].points)){a[l].isDel=!0;break}if(p==="window"&&Ye(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-f)>.3)){a[l].isDel=!0;break}}let g=!1,b=[],z=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(g=!0,b=v,z=S):(b=S,z=v),qr(z,b,.03,.5)>.5)if(g)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(Ye(c,P)){const D=Dn(c,P);if(D===1||D===0){if(p==="switch")continue;v.length>S.length?pe(z,c)>=.5&&(w[x].isDel=!0):pe(b,c)>=.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(z,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 c=a[l].maxz,h=a[l].minz,f=s==="switch"?.1:.3;const u=a[l].averagePz;if(Math.abs(c-u)<f){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const p=Math.abs(c-u),w=Math.abs(h-u);(s==="tv"&&w<1.6||s!=="window"&&p<1.6)&&(a[l].isDel=!0),s==="window"&&p<1&&(a[l].isDel=!0)}if(s==="chair"){const p=new y.Vector3;a[l].obb.getSize(p),(p.x<.1||p.y<.1||p.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(c-h)<.4&&(a[l].isDel=!0),(h<u&&Math.abs(h-u)>1||h>u&&Math.abs(h-u)>1)&&(a[l].isDel=!0),c<u&&(a[l].isDel=!0)),s==="people"&&(Math.abs(c-h)<1&&(a[l].isDel=!0),h>u&&h-u>.3&&(a[l].isDel=!0),c<u&&(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,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,f=(c*s+h*a)/l,u=e+f*s,p=o+f*a;return{dist:Math.sqrt((n-u)**2+(t-p)**2),t:f}}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 f=0;f<2;f++){const u=f===0?n.start:n.end;for(const p of t){if(p===n)continue;const w=be(u,p.start),x=be(u,p.end);let P=null;if(w<=e?P=p.end:x<=e&&(P=p.start),!P)continue;const M=p.end.x-p.start.x,m=p.end.y-p.start.y,d=Math.sqrt(M*M+m*m);if(d<1e-12||Math.abs(o*M+i*m)/(r*d)>=.342)continue;const b=(P.x-u.x)*s+(P.y-u.y)*a;l[f].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(f=>f===c[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,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 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,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,p=r.end;a?p=s.end:l?u=s.start:c?p=s.start:h&&(u=s.end);const w=Math.hypot(p.x-u.x,p.y-u.y),x={...r};x.start=u,x.end=p,x.length=w,x.direction={x:(p.x-u.x)/w,y:(p.y-u.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,c)=>[c])};const o=n.map((l,c)=>({seg:l,angle:Ur(l),idx:c}));o.sort((l,c)=>l.angle-c.angle);const i=Zr(o,t),r=[],s=[],a=[];for(const l of i){let c=l[0].seg;for(const M of l)M.seg.length>c.length&&(c=M.seg);const h=c.end.x-c.start.x,f=c.end.y-c.start.y,u=Math.sqrt(h*h+f*f);if(u<1e-12)continue;const p=-f/u,w=h/u,x=l.map(M=>{const m=M.seg.start.x-c.start.x,d=M.seg.start.y-c.start.y;return{seg:M.seg,offset:Math.abs(m*p+d*w),idx:M.idx}});x.sort((M,m)=>M.offset-m.offset);const P=Kr(x);for(const M of P){let m=M[0].seg;for(const T of M)T.seg.length>m.length&&(m=T.seg);const d=m.end.x-m.start.x,g=m.end.y-m.start.y,b=Math.sqrt(d*d+g*g);if(b<1e-12)continue;const z=d/b,v=g/b,S=M.map(T=>T.seg.rooftopPz??0),V=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,m,z,v,e);for(const{l:T,r:E,srcIdxs:A}of _){if(E-T<.01)continue;const F=Jr(m,T,E,z,v,V,m.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 c of a){if(l.length>0)break;for(const h of n){const f=t*r.minLengthRatio;if(h.length<f)continue;const{start:u,end:p}=h;let w=!1,x=1/0;for(const S of i){const{dist:V,t:D}=Gn(S.x,S.y,u.x,u.y,p.x,p.y);D>=-c.margin&&D<=1+c.margin&&V<=c.maxDist&&(w=!0,x=Math.min(x,V))}if(!w){`${c.maxDist}${(-c.margin).toFixed(1)}${(1+c.margin).toFixed(1)}`;continue}const P=Math.sqrt((p.x-u.x)**2+(p.y-u.y)**2);if(P<1e-12)continue;const M=(p.x-u.x)/P,m=(p.y-u.y)/P,d=Math.abs(e*M+o*m),g=Math.abs(-o*M+e*m),b=Math.max(d,g),z=Math.acos(Math.min(b,1))*(180/Math.PI);if(z>r.angleThreshold){`${z.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(P>.01){const S=[];for(let _=1;_<=4;_++){const T=i[_],E=T.x-u.x,A=T.y-u.y,F=(E*M+A*m)/P;S.push(F)}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: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,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),f=Math.max(...c),u=(f-h)*s,p=(h+f)/2,w=n.start.x+p*i,x=n.start.y+p*r,P=e.box.min.z,M=e.box.max.z,m=Math.abs(M-P),d=Qe(o,n.start.x,n.start.y),g=Math.max(0,P-d),b=h<=0&&f>=1,z=n.start.z+p*(n.end.z-n.start.z);return{p:{x:w,y:x,z},width:u,full:b,height:m,groundClearance:g}}function jn(n,t,e){var h,f,u,p,w;const o=t.map(x=>e[x]),i=[],r=[],s=[],a=[],l=[];let c;for(const x of o){if((h=x.points)!=null&&h.length)for(const P of x.points)i.push(P);if((f=x.originalPoints)!=null&&f.length)for(const P of x.originalPoints)r.push(P);if((u=x.doorAndBeamData)!=null&&u.length)for(const P of x.doorAndBeamData)s.push(P);if((p=x.insetionArr)!=null&&p.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&&!c&&(c=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),c&&(n.boxData=c)}function Un(n,t,e){var l;const o=ei(e),i=[],{segments:r,sourceMap:s}=Je(t),a=r;for(const c of n){const h=(l=c.coordinatesByArea)==null?void 0:l.coordinates;if(!h||h.length<4)continue;const f=h.slice(0,4),u=f.reduce((V,D)=>V+D.x,0)/4,p=f.reduce((V,D)=>V+D.y,0)/4,{longSide:w,dirX:x,dirY:P}=Hr(f);if(w<.01)continue;const M=f.reduce((V,D)=>V+D.z,0)/4,m=Qe(t,u,p);if(M<m-.3)continue;const d=ni(f,u,p);c.name;let g=oi(a,w,x,P,d,o,c.name);g=ri(g,d,t,c.name);let b=null,z=1/0,v=0;if(g.length>0){const V=g[0];b=V.seg,z=V.minDist,v=V.ratio}let S;if(b&&(S=ii(b,f,c,r),!o.printOnly)){const V=b;V.drawWindow||(V.drawWindow=[]),V.drawWindow.push(S)}b&&i.push({windowName:c.name,windowCategory:c.category,windowCenter:c.center,wallSegment:b,distance:z,wallLengthRatio:v,drawWindow:S})}for(const c of i){const h=c.wallSegment,f=r.indexOf(h);if(f===-1)continue;const u=s[f];!u||u.length<=1||jn(h,u,t)}return i}function si(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],r=Un(i,n,o),{segments:s,sourceMap:a}=Je(n);for(let c=0;c<s.length;c++){const h=a[c];h&&jn(s[c],h,n)}const l=new Set(r.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(l.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of r)if(c.drawWindow){const h=s.find(f=>Math.abs(f.start.x-c.wallSegment.start.x)<.01&&Math.abs(f.start.y-c.wallSegment.start.y)<.01&&Math.abs(f.end.x-c.wallSegment.end.x)<.01&&Math.abs(f.end.y-c.wallSegment.end.y)<.01);h&&(h.drawWindow||(h.drawWindow=[]),h.drawWindow.push(c.drawWindow))}return{segments:s,matches:r,sourceMap: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;