rm-graphical-computing 1.0.69 → 1.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var Zn=Object.defineProperty;var Kn=(n,t,e)=>t in n?Zn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Oe=(n,t,e)=>Kn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function Qn(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const y=Qn(lt);function Jn(n,t=!1){const e=n[0].index!==null,o=new Set(Object.keys(n[0].attributes)),i=new Set(Object.keys(n[0].morphAttributes)),r={},s={},a=n[0].morphTargetsRelative,l=new lt.BufferGeometry;let u=0;for(let h=0;h<n.length;++h){const d=n[h];let c=0;if(e!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!o.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;r[f]===void 0&&(r[f]=[]),r[f].push(d.attributes[f]),c++}if(c!==o.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!i.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[f]===void 0&&(s[f]=[]),s[f].push(d.morphAttributes[f])}if(t){let f;if(e)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(u,f,h),u+=f}}if(e){let h=0;const d=[];for(let c=0;c<n.length;++c){const f=n[c].index;for(let w=0;w<f.count;++w)d.push(f.getX(w)+h);h+=n[c].attributes.position.count}l.setIndex(d)}for(const h in r){const d=tn(r[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in s){const d=s[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let c=0;c<d;++c){const f=[];for(let x=0;x<s[h].length;++x)f.push(s[h][x][c]);const w=tn(f);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(w)}}return l}function tn(n){let t,e,o,i=-1,r=0;for(let u=0;u<n.length;++u){const h=n[u];if(t===void 0&&(t=h.array.constructor),t!==h.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=h.itemSize),e!==h.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(o===void 0&&(o=h.normalized),o!==h.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=h.gpuType),i!==h.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=h.count*e}const s=new t(r),a=new lt.BufferAttribute(s,e,o);let l=0;for(let u=0;u<n.length;++u){const h=n[u];if(h.isInterleavedBufferAttribute){const d=l/e;for(let c=0,f=h.count;c<f;c++)for(let w=0;w<e;w++){const x=h.getComponent(c,w);a.setComponent(c+d,w,x)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const to=(n,t,e)=>{let o=new y.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(n),i.push(t);let r=new y.BufferGeometry;r.setFromPoints(i),r.rotateX(-Math.PI/2),e.add(new y.Line(r,o))},te=(n,t,e,o,i=1e-8)=>{const r=t.x-n.x,s=t.y-n.y,a=o.x-e.x,l=o.y-e.y,u=r*l-s*a;if(Math.abs(u)<i)return null;const h=((e.x-n.x)*l-(e.y-n.y)*a)/u,d=((e.x-n.x)*s-(e.y-n.y)*r)/u;return h<-i||h>1+i||d<-i||d>1+i?null:{point:new y.Vector3(n.x+h*r,n.y+h*s,n.z)}},eo=(n,t,e={})=>{const{fontSize:o=36,fontFamily:i="sans-serif",backgroundColor:r="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=e,h=document.createElement("canvas").getContext("2d");h.font=`bold ${o}px ${i}`;const c=h.measureText(n).width;let f=Math.min(c+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=f,x.height=w;const b=x.getContext("2d");b.fillStyle=r,b.fillRect(0,0,f,w),b.fillStyle=s,b.font=`bold ${o}px ${i}`,b.textAlign="center",b.textBaseline="middle",c>l-a*2?no(b,n,f/2,w/2,l,o):b.fillText(n,f/2,w/2);const M=new y.CanvasTexture(x),g=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),m=new y.Sprite(g);m.position.set(t.x,t.y,t.z);const p=.005;return m.scale.set(f*p,w*p,1),m};function no(n,t,e,o,i,r){const s=t.split("");let a="",l=r*1.2,u=o;for(let h=0;h<s.length;h++){const d=a+s[h];n.measureText(d).width>i&&h>0?(n.fillText(a,e,u),a=s[h],u+=l):a=d}n.fillText(a,e,u)}const oe=(n,t,e=.01)=>{const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(o<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const r={x:n.x/o,y:n.y/o,z:n.z/o},s={x:t.x/i,y:t.y/i,z:t.z/i};let a=r.x*s.x+r.y*s.y+r.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),u=l<=e;return{parallel:u,sameDirection:u?a>0:null,angle:l}},oo=(n,t,e,o)=>{const i=n;let r=[];if(o&&o.length&&(r=o.map(V=>V.clone())),!i||i.length<4)return{};const s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let u=1/0,h=-1/0,d=1/0,c=-1/0;for(const V of i){const v=V.dot(s),S=V.dot(a);v<u&&(u=v),v>h&&(h=v),S<d&&(d=S),S>c&&(c=S)}const f=i[0].dot(l),w=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),b=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(f)),M=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(f));let g=[w,x,b,M],m=oe(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));m&&m.parallel&&(g=[w,M,b,x]);let p=0;if(o.length>0){const V=new y.Vector3().subVectors(g[1],g[0]).normalize(),v=V.clone().negate(),S=new y.Vector3().subVectors(g[3],g[0]).normalize(),z=S.clone().negate();let D=g[0].distanceTo(g[1]),_=g[0].distanceTo(g[3]),E=D/t,T=_/e,A=.001;for(let O=0;O<E;O++){let I=g[0],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(V,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[0]=g[0].addScaledVector(V,t),g[3]=g[3].addScaledVector(V,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<E;O++){let I=g[1],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(v,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[1]=g[1].addScaledVector(v,t),g[2]=g[2].addScaledVector(v,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<T;O++){let I=g[3],B=0;for(let L=0;L<E;L++){let N=I.clone().addScaledVector(V,t),C=N.clone().addScaledVector(z,e),R=I.clone().addScaledVector(z,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=N}if(B>=E/2)break;p+=B,g[2]=g[2].addScaledVector(z,e),g[3]=g[3].addScaledVector(z,e)}}const P=g[0].distanceTo(g[1])*g[0].distanceTo(g[3]);return{facePoints:g,boxArea:P,totalInPlaneNum:p}},Jt=(n,t,e,o,i=y.MathUtils.degToRad(8))=>{const r=new y.Vector3,s=new y.Vector3;r.subVectors(new y.Vector3(t.x,t.y,0),new y.Vector3(n.x,n.y,0)).normalize(),s.subVectors(new y.Vector3(o.x,o.y,0),new y.Vector3(e.x,e.y,0)).normalize();const a=r.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),u=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:u,angle:l,angleDeg:y.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},re=(n,t,e,o)=>{const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=i.length(),a=r.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),r.normalize();const l=Math.abs(i.dot(r)),u=Math.min(1,Math.max(0,l)),h=Math.acos(u),d=y.MathUtils.radToDeg(h),c=1-u;return{rate:c,percent:`${(c*100).toFixed(2)}%`,angle:d,isPerpendicular:Math.abs(d-90)<.01,isParallel:d<.01}},ee=(n,t,e=!1)=>new y.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),ne=(n,t,e,o,i={})=>{const{parallelAngleMax:r=y.MathUtils.degToRad(10),collinearAngleMax:s=y.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,u=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),d=u.clone().normalize(),c=h.clone().normalize();let f=y.MathUtils.clamp(d.dot(c),-1,1);const w=Math.acos(Math.abs(f)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};f<0&&c.negate();const b=new y.Vector3().addVectors(d,c).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),g=en(e,M,d),m=en(o,M,d),p=(g+m)/2,P=Math.max(g,m),V=n.dot(b),v=t.dot(b),S=e.dot(b),z=o.dot(b),D=Math.min(V,v),_=Math.max(V,v),E=Math.min(S,z),T=Math.max(S,z),A=_-D,O=T-E,I=Math.min(A,O),B=Math.min(_,T)-Math.max(D,E),L=B<0?-B:0,N=B>0?B:0,C=I>0?N/I:0,R=ro(n,t,e,o),$=w<=s&&p<a;let X;return $?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:x,avgPerpendicularDistance:p,maxPerpendicularDistance:P,gap:L,overlap:N,closestDistance:R}};function en(n,t,e){const o=new y.Vector3().subVectors(n,t),i=o.dot(e),r=e.clone().multiplyScalar(i);return new y.Vector3().subVectors(o,r).length()}function ro(n,t,e,o){const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=new y.Vector3().subVectors(e,n),a=i.dot(i),l=i.dot(r),u=r.dot(r),h=i.dot(s),d=r.dot(s),c=a*u-l*l;let f,w;c<1e-10?(f=0,w=u!==0?d/u:0):(f=(l*d-u*h)/c,w=(a*d-l*h)/c),f=y.MathUtils.clamp(f,0,1),w=u!==0?y.MathUtils.clamp((l*f+d)/u,0,1):0,f=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(f)),b=e.clone().add(r.clone().multiplyScalar(w));return x.distanceTo(b)}const nn=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),io=n=>{let t=new y.Vector3(n.start.x,n.start.y,n.start.z),e=new y.Vector3(n.end.x,n.end.y,n.end.z),o=t.distanceTo(e),i=n.rooftopPz-n.start.z,r=nn(o,100),s=nn(i,70),a=i/s,l=new Map;for(let x=0;x<s;x++)l.set((x+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let u=new y.Line3(t,e);const h=n.originalPoints,d=new y.Vector3;for(let x=0;x<h.length;x++){const b=h[x];let g=u.closestPointToPoint(b,!0,d).distanceTo(b);const m=Math.floor(g/a);if(m<s){const p=l.get((m+1)*a);p.count++,b.z<p.minZ&&(p.minZ=b.z),b.z>p.maxZ&&(p.maxZ=b.z)}}let c,f,w=r/2;for(const[x,b]of l)if(b.count>=w){c=b.minZ;break}for(const[x,b]of[...l.entries()].reverse())if(b.count>=w){f=b.maxZ;break}return{minZ:c,maxZ:f}},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(b=>{const M=new y.Vector3;o.projectPoint(b,M),l.push(M.clone()),M.z=i.z,a.push(M)});let u=new y.Vector3,h=new y.Vector3;o.projectPoint(i,u),o.projectPoint(r,h);const d=new y.Line3(u,h),c=[],f=[],w=[];let x=new y.Vector3;return a.forEach((b,M)=>{d.closestPointToPoint(b,!0,x).distanceTo(b)<.001?(c.push(e[M]),f.push(l[M])):w.push(b)}),{newOriginalPoints:c,newProjectPoints:w,newOnLinePoints:f}},so=n=>{function t(e,o,i,r,s,a,l,u,h){let d=new y.Line3(e,o),c=new Map,f=new y.Vector3,w=e.clone(),x=o.clone(),b=0;for(;;){let M=new Map,g=0;for(let m=0;m<h.checkResults.length;m++)if(!(h.checkResults[m].allCenterPoints.length/u*100<1))for(let P=0;P<h.checkResults[m].allCenterPoints.length;P++){if(c.has(m)&&c.get(m).removePtsIndex.includes(P))continue;let V=h.checkResults[m].allCenterPoints[P];V=new y.Vector3(V.x,V.y,V.z);let v=d.closestPointToPoint(V,!0,f),S=V.distanceTo(v);Math.abs(S-s)<.01&&(g++,M.has(m)?M.get(m).removePtsIndex.push(P):M.set(m,{index:m,removePtsIndex:[P]}))}if(b==l){e=w,o=x;break}if(g<a/20*18||g==0){M.clear(),l-b<5&&(e=w,o=x,c.clear());break}else{b++;for(const[m,p]of M)c.has(m)?c.get(m).removePtsIndex.push(...p.removePtsIndex):c.set(m,p);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),d.set(e,o)}}if(c.size>0&&b!=l)for(const[M,g]of c){let m=[],p=[];for(let P=0;P<h.checkResults[M].allCenterPoints.length;P++)g.removePtsIndex.includes(P)||(m.push(h.checkResults[M].allCenterPoints[P]),p.push(h.checkResults[M].originalVertices[P]));h.checkResults[M].allCenterPoints=m,h.checkResults[M].originalVertices=p}}for(let e=0;e<n.length;e++){const o=n[e];if(o.length<.5)continue;let i=-1,r=-1;if(!o.checkResults||o.checkResults.length<=0)continue;if(o.checkResults[0].originalVertices&&o.checkResults[0].originalVertices.length>0){const S=o.checkResults[0].originalVertices[0];let[z,D,_,E]=S;z=new y.Vector3(z.x,z.y,z.z),D=new y.Vector3(D.x,D.y,D.z),_=new y.Vector3(_.x,_.y,_.z),E=new y.Vector3(E.x,E.y,E.z),i=z.distanceTo(D),r=z.distanceTo(E);let T=new y.Vector3().subVectors(z,D).normalize(),A=oe(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),u=o.rooftopPz-o.start.z,h=Math.ceil(l/i),d=Math.ceil(u/r);let c=s.clone(),f=a.clone(),w=f.clone().add(new y.Vector3(0,0,u)),x=c.clone().add(new y.Vector3(0,0,u)),b=new y.Vector3().subVectors(f,c).normalize(),M=b.clone().negate();new y.Vector3().subVectors(w,c).normalize().clone().negate();let m=i/2,p=l*u,P=i*r,V=p/P;t(c,x,b,i,m,d,h,V,o),t(f,w,M,i,m,d,h,V,o),o.start=c,o.end=f;const{newOriginalPoints:v}=Ve(c,f,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 b=0;b<l.length;b++)this.isValidVector3(l[b])||(console.error(`点${b+1}包含无效数据:`,l[b]),l[b]=new y.Vector3(b,0,b));const u=new y.BufferGeometry,h=new Float32Array([l[0].x,l[0].y,l[0].z,l[1].x,l[1].y,l[1].z,l[2].x,l[2].y,l[2].z,l[3].x,l[3].y,l[3].z]),d=[0,1,2,0,2,3],c=new Float32Array([0,0,1,0,1,1,0,1]);u.setAttribute("position",new y.BufferAttribute(h,3)),u.setAttribute("uv",new y.BufferAttribute(c,2)),u.setIndex(d),u.computeVertexNormals();const f=new y.Mesh(u,r),w=new y.EdgesGeometry(u),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),f}createSubdividedWallPlane(t,e,o,i,r){const s=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return s;const a=new y.Vector3(t.start.x,t.start.y,t.start.z),l=new y.Vector3(t.end.x,t.end.y,t.end.z),u=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),d=[a,l,u,h];for(let g=0;g<d.length;g++)if(!this.isValidVector3(d[g]))return console.error(`墙体基础点${g}无效:`,d[g]),s;const c=a.distanceTo(l),f=Math.abs(t.rooftopPz-t.start.z);if(c===0||f===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",l),console.log(t.length),s;const w=c/o,x=f/e,b=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let g=0;g<e;g++)for(let m=0;m<o;m++)try{const p=new y.Vector3().copy(a).add(b.clone().multiplyScalar(m*w)).add(M.clone().multiplyScalar(g*x)),P=new y.Vector3().copy(a).add(b.clone().multiplyScalar((m+1)*w)).add(M.clone().multiplyScalar(g*x)),V=new y.Vector3().copy(a).add(b.clone().multiplyScalar((m+1)*w)).add(M.clone().multiplyScalar((g+1)*x)),v=new y.Vector3().copy(a).add(b.clone().multiplyScalar(m*w)).add(M.clone().multiplyScalar((g+1)*x)),S={points:[p,P,V,v],userData:{}};S.userData={type:"wallSegment",row:g,col:m,originalMaterial:i,width:w,height:x},s.push(S)}catch(p){console.error(`创建墙体小平面(${g}, ${m})时出错:`,p)}return s}calculateMinRequiredPoints(t){const i=Math.floor(Math.log1p(t)*.5);return Math.max(1,i)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,o,i){if(e===0)return!1;const r=t.area,s=t.minRequiredPoints,a=t.expectedDensity,l=e/Math.max(r,.001),u=e>=s,h=l>=a*.3;let d=!0;return r<.5&&e>0&&(d=this.checkSmallAreaDistribution(t,o,i)),u&&h&&d}checkSmallAreaDistribution(t,e,o){if(e.length<2)return!0;const i=e.map(l=>o[l]);t.bounds;const r=t.center;let s=0;const a=Math.sqrt(t.area)*.3;return i.forEach(l=>{l.distanceTo(r)<=a&&s++}),s/i.length>=.3}getFailureReason(t,e){const o=t.area,i=t.minRequiredPoints,r=t.expectedDensity,s=e/Math.max(o,.001),a=[];return e===0?a.push("无点"):(e<i&&a.push(`点数不足: ${e}/${i}`),s<r*.3&&a.push(`密度不足: ${s.toFixed(2)}/${r.toFixed(2)}`),o<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((i,r)=>i-r),o=Math.floor(e.length/2);return e.length%2!==0?e[o]:(e[o-1]+e[o])/2}isPointInBoundingBox(t,e,o=.1){return t.x>=e.min[0]-o&&t.x<=e.max[0]+o&&t.y>=e.min[1]-o&&t.y<=e.max[1]+o&&t.z>=e.min[2]-o&&t.z<=e.max[2]+o}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const o=e.attributes.position;if(o.count<3)return null;const i=new y.Vector3().fromBufferAttribute(o,0),r=new y.Vector3().fromBufferAttribute(o,1),s=new y.Vector3().fromBufferAttribute(o,2);i.applyMatrix4(t.matrixWorld),r.applyMatrix4(t.matrixWorld),s.applyMatrix4(t.matrixWorld);const a=new y.Plane;return a.setFromCoplanarPoints(i,r,s),a}analyzePointDistribution(t,e,o=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};const i=performance.now(),r=[];t.forEach(s=>{if(s.userData&&s.userData.type==="wallSegment"){const a=this.getWorldVerticesNew(s.points);if(a.length<4)return;const l=new y.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);s.userData.center=l,s.vertices=a,r.push(s)}}),this.results.totalSegments=r.length;for(const s of r){if(s.vertices.length<4)continue;const a=s.userData.center,l=`row${s.userData.row}_col${s.userData.col}`,[u,h,d,c]=s.vertices,f=new y.Vector3().subVectors(h,u).normalize(),w=new y.Vector3().subVectors(c,u).normalize(),x=u.distanceTo(h),b=u.distanceTo(c),M=new y.Plane;M.setFromCoplanarPoints(u,h,c);const g=x/2,m=b/2;for(let p=0;p<e.length;p++)this.isPointInWallSegmentOptimized(e[p],a,M,u,f,w,x,b,g,m,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(p))}return r.forEach(s=>{const a=`row${s.userData.row}_col${s.userData.col}`,l=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;l>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:s.userData.row,col:s.userData.col,width:s.userData.width,height:s.userData.height,segmentKey:a,vertices:s.vertices,center:s.userData.center,mesh:s,pointCount:l,hasPointsButNotEnough:l>0&&l<1}))}),this.results.analysisTime=performance.now()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,o,i,r,s,a,l,u,h,d){if(Math.abs(o.distanceToPoint(t))>d)return!1;const f=new y.Vector3().subVectors(t,e),w=Math.abs(f.dot(r)),x=Math.abs(f.dot(s));if(w>u&&x>h)return!1;const b=new y.Vector3().subVectors(t,i),M=b.dot(r),g=b.dot(s),m=M>=-d&&M<=a+d,p=g>=-d&&g<=l+d;return m&&p}isPointInWallSegment(t,e,o,i=.1){if(!t.geometry)return!1;try{const r=this.getWorldVertices(t);return r.length<4?!1:this.isPointInRotatedWall(r,e,o,i)}catch(r){return console.error("判断点是否在墙体平面内时出错:",r),!1}}isPointInRotatedWall(t,e,o,i=.1){const[r,s,a,l]=t,u=new y.Plane;if(u.setFromCoplanarPoints(r,s,l),Math.abs(u.distanceToPoint(e))>i)return!1;const d=new y.Vector3().subVectors(s,r).normalize(),c=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(d,c).normalize();const f=new y.Vector3().subVectors(e,r),w=f.dot(d),x=f.dot(c),b=r.distanceTo(s),M=r.distanceTo(l),g=w>=-i&&w<=b+i,m=x>=-i&&x<=M+i;return g&&m&&o.distanceTo(e)<b/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 d;if(!this.results){console.warn("请先运行分析函数");return}const r=new Map,s=new Map;this.results.missingSegments.forEach(c=>{r.set(c.segmentKey,c),s.has(c.row)||s.set(c.row,new Map),s.get(c.row).set(c.col,{segmentKey:c.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(c=>{if(c.userData&&c.userData.type==="wallSegment"){const f=`row${c.userData.row}_col${c.userData.col}`,w=r.has(f);s.has(c.userData.row)||s.set(c.userData.row,new Map),s.get(c.userData.row).has(c.userData.col)||s.get(c.userData.row).set(c.userData.col,{segmentKey:f,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[c,f]of r){const w=(d=s.get(f.row))==null?void 0:d.get(f.col);if(w&&!w.visited){const x=[],b=[[f.row,f.col]];for(w.visited=!0;b.length>0;){const[M,g]=b.shift(),m=`row${M}_col${g}`;r.has(m)&&x.push(r.get(m));for(const[p,P]of l){const V=M+p,v=g+P;if(s.has(V)&&s.get(V).has(v)){const S=s.get(V).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,b.push([V,v]))}}}x.length>=i&&a.push(x)}}const u=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((c,f)=>f.length-c.length),highlightedMeshes:h,clusterMaterials:u,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,o,i,r){let s=0;const a=e;let l=!0;for(let x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const u=o;let h=!0;for(let x=i;x<=r;x++)t.has(u)&&t.get(u).has(x)||(h=!1);h&&s++;const d=i;let c=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(d)||(c=!1);c&&s++;const f=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(f)||(w=!1);return w&&s++,s/4}calculateClusterQualityScore(t){const r=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+r*.2}calculateStrictClusterBounds(t){var d,c;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(f=>{f.vertices&&f.vertices.length>0&&e.push(...f.vertices)}),e.length===0){const f=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((d=t[0].bounds)==null?void 0:d.width)||1),height:f.length*(((c=t[0].bounds)==null?void 0:c.height)||1)}}const o=Math.min(...e.map(f=>f.x)),i=Math.max(...e.map(f=>f.x)),r=Math.min(...e.map(f=>f.y)),s=Math.max(...e.map(f=>f.y)),a=Math.min(...e.map(f=>f.z)),l=Math.max(...e.map(f=>f.z)),u=Math.abs(i-o),h=Math.max(Math.abs(s-r),Math.abs(l-a));return{width:u,height:h}}createClusterMaterials(t){const e=[],o=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let i=0;i<t;i++){const r=o[i%o.length],s=new y.MeshBasicMaterial({color:r,transparent:!0,opacity:.6,side:y.DoubleSide});e.push(s)}return e}clearHighlights(t){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(e=>{t.remove(e),e.material&&e.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,o)=>{e.mesh&&e.mesh.userData.originalMaterial&&(e.mesh.material=e.mesh.userData.originalMaterial)}),this.clusterResults.highlightedMeshes=[])}getClusterInfo(){return this.clusterResults?{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((t,e)=>({clusterIndex:e,size:t.length,segments:t.map(o=>o.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(t=>t.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(t=>t.length))}:null}restoreOriginalMaterials(t){let e=0;t.traverse(o=>{o.userData&&o.userData.originalMaterial&&(o.material=o.userData.originalMaterial,delete o.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new y.Group;return t.traverse(o=>{if(o.userData&&o.userData.type==="wallSegment"){const i=this.getWorldVertices(o);if(i.length<4)return;const r=new y.Vector3().add(i[0]).add(i[1]).add(i[2]).add(i[3]).multiplyScalar(.25),s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=new y.Vector3().crossVectors(s,a).normalize(),u=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),d=new y.ArrowHelper(a,r,.2,255);e.add(u),e.add(h),e.add(d)}}),e}printAnalysisResults(){if(!this.results){console.warn("没有可用的分析结果");return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(t=>{}),this.results.pointsInSegments.forEach((t,e)=>{})}isValidVector3(t){return t&&!isNaN(t.x)&&!isNaN(t.y)&&!isNaN(t.z)&&isFinite(t.x)&&isFinite(t.y)&&isFinite(t.z)}mergeWallGroupMeshes(t){const e=[];if(t.traverse(o=>{o.isMesh&&o.geometry&&e.push(o)}),e.length===0)return null;try{const o=e.map(a=>a.geometry);o.forEach((a,l)=>{a.applyMatrix4(e[l].matrixWorld)});const i=Jn(o),r=e[0].material.clone(),s=new y.Mesh(i,r);return s.name="mergedWalls",s}catch(o){return console.error("合并网格时出错:",o),null}}}const ho=n=>{let t={};const e=[],o=[],i=[];return n[0].width,n[0].height,n.forEach(r=>{o.push(...r.vertices),i.push(r.center),e.push(r.vertices)}),t.originalVertices=e,t.allCenterPoints=i,t},fo=n=>{const t=new lt.Vector3().copy(n.start).add(n.end).multiplyScalar(.5),e=new lt.Vector3().subVectors(new lt.Vector3(t.x,t.y,t.z+1),t).normalize(),o=new lt.Vector3(n.direction.x,n.direction.y,0);o.applyAxisAngle(e,Math.PI/2);const i=new lt.Vector3().copy(t).add(o.clone().multiplyScalar(n.length)),r=new lt.Vector3().copy(t).sub(o.clone().multiplyScalar(n.length));return t.z=n.start.z,i.z=n.start.z,r.z=n.start.z,{start:i,end:r,center:t,direction:o}},mo=(n,t,e=!0)=>{let o=[];if(!n)return[];for(let i=0;i<n.length;i++){const r=n[i];if(!r)continue;let s=new y.Vector3(r.start.x,r.start.y,r.start.z);s.applyEuler(new y.Euler(-Math.PI/2,0,0));let a=new y.Vector3(r.end.x,r.end.y,r.end.z);if(a.applyEuler(new y.Euler(-Math.PI/2,0,0)),t.add(eo(String(i),new y.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(r.isBayWindow||r.isWindow)&&e)continue;const l=new lt.Plane().setFromCoplanarPoints(new lt.Vector3(r.start.x,r.start.y,r.start.z),new lt.Vector3(r.end.x,r.end.y,r.end.z),new lt.Vector3(r.start.x,r.start.y,r.rooftopPz)),u=[];r.originalPoints.forEach((v,S)=>{const z=new lt.Vector3;l.projectPoint(v,z),u.push(z)});const h=new lt.Vector3(r.start.x,r.start.y,r.start.z).distanceTo(new lt.Vector3(r.end.x,r.end.y,r.end.z)),d=Math.abs(r.rooftopPz-r.start.z),c=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),f=new y.Group,w=new uo,{horizontalSubdivisions:x,verticalSubdivisions:b}=w.initLimits4(h,d),M=w.createSubdividedWallPlane(r,b,x,c,f);w.analyzePointDistribution(M,u,.01);const g=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),m=w.highlightEmptySegments(M,g,f),p=[];for(const v of m.clusters){const S=ho(v);S&&p.push(S)}const V=fo(r).direction;r.checkResults=p,r.verticalDirection=V,r.originaIndex=i,o.push(r)}return o},go=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(m=>{let p=new y.Vector3(m.x,m.y,0),P=!1;for(let V=0;V<i.length;V++)if(kt(p,i[V],.01)){P=!0;break}P||i.push(p)});const r=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),s=1;let a=new y.Vector3(o.start.x,o.start.y,o.start.z),l=new y.Vector3(o.end.x,o.end.y,o.end.z),u=new y.Vector3().subVectors(l,a).normalize(),h=u.clone().cross(new y.Vector3(0,0,1)).normalize(),d=h.clone().negate(),c=[];const f=[];let w=o.length/r;console.log(w);for(let m=0;m<r;m++){const p=[];p.push(a.clone().addScaledVector(h,s)),p.push(p[0].clone().addScaledVector(u,w)),p.push(p[1].clone().addScaledVector(d,s*2)),p.push(a.clone().addScaledVector(d,w));let P=[];for(let V=0;V<i.length;V++)c.includes(V)||yo(i[V],p)&&(c.push(V),P.push(i[V]));P.length>0&&f.push(xo(P)),a=a.addScaledVector(u,w)}const x=new Float32Array(i.length*3);i.forEach((m,p)=>{x[p*3]=m.x,x[p*3+1]=m.y,x[p*3+2]=m.z});const b=new y.BufferGeometry;b.setAttribute("position",new y.BufferAttribute(x,3)),b.rotateX(-Math.PI/2),t.add(new y.Points(b,new y.PointsMaterial({color:lo(),size:.02})));const[M,g]=Mo(f,{plane:"xy",trimRatio:0});to(M,g,t)}};function on(n,t="xy"){if(t==="xy")return{x:n.x,y:n.y};if(t==="xz")return{x:n.x,y:n.z};if(t==="yz")return{x:n.y,y:n.z};throw new Error(`Unsupported plane: ${t}`)}function po(n,t,e){const o=t.x-n.x,i=t.y-n.y,r=e.x-n.x,s=e.y-n.y;return o*s-i*r}function yo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=on(n,e),i=t.map(a=>on(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],u=i[(a+1)%4],h=po(l,u,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function xo(n){if(!n||n.length===0)return null;const t=new y.Vector3(0,0,0);for(const e of n)Array.isArray(e)?(t.x+=e[0],t.y+=e[1],t.z+=e[2]):(t.x+=e.x,t.y+=e.y,t.z+=e.z);return t.divideScalar(n.length),t}function wo(n){return n instanceof y.Vector3?n.clone():Array.isArray(n)?new y.Vector3(n[0],n[1],n[2]):new y.Vector3(n.x,n.y,n.z)}function bo(n,t="xy"){const e=wo(n);if(t==="xy")return{x:e.x,y:e.y,up:e.z};if(t==="xz")return{x:e.x,y:e.z,up:e.y};if(t==="yz")return{x:e.y,y:e.z,up:e.x};throw new Error(`Unsupported plane: ${t}`)}function rn(n,t,e,o="xy"){if(o==="xy")return new y.Vector3(n,t,e);if(o==="xz")return new y.Vector3(n,e,t);if(o==="yz")return new y.Vector3(e,n,t);throw new Error(`Unsupported plane: ${o}`)}function Po(n,t,e){if(Math.abs(t)<1e-12)return n>=e?{x:1,y:0}:{x:0,y:1};const i=n+e,r=n*e-t*t,s=Math.sqrt(Math.max(0,i*i*.25-r)),a=i*.5+s;let l=t,u=a-n;const h=Math.hypot(l,u);return h<1e-12?{x:1,y:0}:{x:l/h,y:u/h}}function Mo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>bo(B,e));let r=0,s=0,a=0;for(const B of i)r+=B.x,s+=B.y,a+=B.up;r/=i.length,s/=i.length,a/=i.length;let l=0,u=0,h=0;for(const B of i){const L=B.x-r,N=B.y-s;l+=L*L,u+=L*N,h+=N*N}l/=i.length,u/=i.length,h/=i.length;const d=Po(l,u,h),c={x:-d.y,y:d.x},f=[];for(const B of i){const L=B.x-r,N=B.y-s,C=L*d.x+N*d.y,R=L*c.x+N*c.y;f.push({s:C,t:R,up:B.up})}f.sort((B,L)=>B.s-L.s);const w=f.length;let x=Math.floor(w*o),b=Math.ceil(w*(1-o))-1;x=Math.max(0,Math.min(w-1,x)),b=Math.max(0,Math.min(w-1,b));const M=f[x],g=f[b],m=(()=>{const B=f.map(N=>N.t).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),p=(()=>{const B=f.map(N=>N.up).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),P=M.s,V=g.s,v=m,S=m,z=p,D=p,_=r+d.x*P+c.x*v,E=s+d.y*P+c.y*v,T=r+d.x*V+c.x*S,A=s+d.y*V+c.y*S,O=rn(_,E,z,e),I=rn(T,A,D,e);return[O,I]}const Vo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let m=0;m<o.length;m++){const p=o[m];p.isLine2=!0,n.push(p)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const m of n){let p=[];if(!(!m.checkResults||m.checkResults.length<=0)){for(let P=0;P<m.checkResults.length;P++){let D=function(A){for(;z[A]!==A;)z[A]=z[z[A]],A=z[A];return A};const V=m.checkResults[P];if(V.isDoor=!1,!V.originalVertices||V.originalVertices.length==0)continue;const v=[];V.originalVertices.forEach(A=>{let O=[];A.forEach(I=>{O.push(new y.Vector3(I.x,I.y,I.z))}),v.push(O)});const S=v.length,z=Array.from({length:S},(A,O)=>O);for(let A=0;A<S;A++)for(let O=A+1;O<S;O++){const I=v[A],B=v[O];if(I.some(N=>B.some(C=>N.equals(C)))){const N=D(A),C=D(O);N!==C&&(z[N]=C)}}const _=new Map;let E=-1,T=-1;for(let A=0;A<S;A++){const O=D(A);_.has(O)||_.set(O,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const I=_.get(O);let[B,L,N,C]=v[A];const R=new y.Vector3().add(B).add(L).add(N).add(C).multiplyScalar(.25);if(I.points.push(...v[A]),I.area+=B.distanceTo(L)*B.distanceTo(C),I.originalVertices.push(v[A]),I.index=P,I.centerPts.push(R),E==-1||T==-1){let $=new y.Vector3().subVectors(B,L).normalize();T=B.distanceTo(C),E=B.distanceTo(L);let X=oe($,new y.Vector3(0,0,1));X&&X.parallel&&([T,E]=[E,T])}I.gridWidth=E,I.gridHeight=T}p.push(..._.values())}m.mergeCheckRegion=p}}let r=new Map;for(const m of n){if(m.length<.3)continue;let p=m.rooftopPz-m.start.z,P=Math.floor(m.rooftopPz-m.start.z);r.has(P)?r.set(P,{num:r.get(P).num+1,totalHeight:r.get(P).totalHeight+p}):r.set(P,{num:1,totalHeight:p})}let s=[...r.entries()].reduce((m,p)=>p[1].num>m[1].num?p:m);s[0],s[1].totalHeight/s[1].num;const a=[];for(let m=0;m<e.length;m++){const p=e[m];if(p.isFindBeam=!1,p.category=="door"){let P=[];p.coordinatesByArea.coordinates.forEach(D=>{P.push(new y.Vector3(D.x,D.y,D.z))}),P[0].equals(P[P.length-1])&&P.pop();let V=P[0].distanceTo(P[1]),v=P[0].distanceTo(P[3]);v>V&&([V,v]=[v,V],P=[P[0],P[3],P[2],P[1]]);let S=ee(P[0],P[3],!0),z=ee(P[1],P[2],!0);a.push({doorStartPt:S,doorEndPt:z,boxPoints:P,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:m,isFind:!1,inWall:!1})}}for(let m=0;m<a.length;m++){const p=a[m];for(let P=0;P<n.length;P++){if(n[P].length<.5)continue;let V=[];const v=ee(n[P].start,n[P].end,!0);V.push(v),V.push(ee(v,n[P].start,!0)),V.push(ee(v,n[P].end,!0));let S=!1;const z=p.boxPoints.length;for(let D=0;D<V.length;D++){const _=V[D].x,E=V[D].y;for(let T=0,A=z-1;T<z;A=T++){const O=p.boxPoints[T].x,I=p.boxPoints[T].y,B=p.boxPoints[A].x,L=p.boxPoints[A].y;I>E!=L>E&&_<(B-O)*(E-I)/(L-I)+O&&(S=!S)}if(S)break}if(S){let D=new y.Vector3(n[P].start.x,n[P].start.y,0),_=new y.Vector3(n[P].end.x,n[P].end.y,0),E=p.doorStartPt.distanceTo(p.doorEndPt),T=D.distanceTo(_),A=Jt(p.doorStartPt,p.doorEndPt,D,_);if(Math.abs(T-E)<.5&&A&&A.angleDeg<15){p.doorStartPt=new y.Vector3(n[P].start.x,n[P].start.y,0),p.doorEndPt=new y.Vector3(n[P].end.x,n[P].end.y,0);break}else if(Math.abs(T-E)>1.3&&A&&A.angleDeg<15){let O=ne(p.doorStartPt,p.doorEndPt,D,_,{parallelAngleMax:y.MathUtils.degToRad(15)}),I=p.doorStartPt.distanceTo(D),B=p.doorStartPt.distanceTo(_),L=p.doorEndPt.distanceTo(D),N=p.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||N<.2;if(O&&O.type=="collinear_overlap"&&O.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let R=new y.Line3(D,_),$=R.closestPointToPoint(p.doorStartPt,!0,new y.Vector3),X=R.closestPointToPoint(p.doorEndPt,!0,new y.Vector3),ot=$.distanceTo(p.doorStartPt),K=X.distanceTo(p.doorEndPt);if(ot<.1||K<.1){p.inWall=!0;break}}}}else continue}}let l=0,u=[],h=[],d=[];const c=[];let f=.15;for(let m=0;m<n.length;m++){const p=n[m];if(p.noDetection||(p.doorAndBeamData=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0))continue;p.completePointAreaPercentage=-1;let P=new y.Box3;P.setFromPoints(p.originalPoints);let V=P.max.z;P.min.z;const v=new y.Vector3(p.start.x,p.start.y,p.start.z),S=new y.Vector3(p.end.x,p.end.y,p.end.z);let z=p.rooftopPz-p.start.z,D=0;for(const E of p.mergeCheckRegion){const{facePoints:T,boxArea:A,totalInPlaneNum:O}=oo(E.points,E.gridWidth,E.gridHeight,E.centerPts);if(!T||T.length<=0)continue;T[0].distanceTo(T[1]);let I=T[0].distanceTo(T[3]);const B=E.gridHeight*(I/E.gridHeight/3*2)+E.gridHeight/2;let L=new y.Vector3(T[0].x,T[0].y,T[0].z+B),N=new y.Vector3(T[1].x,T[1].y,T[1].z+B);const C=new y.Line3(L,N),R=[];let $=new y.Vector3;E.points.forEach(rt=>{C.closestPointToPoint(rt,!0,$).distanceTo(rt)<E.gridHeight+.01&&R.push(rt)});let X=[],ot=[];for(;;){let rt=[];for(let F=0;F<R.length;F++)ot.includes(F)||rt.length==0&&(rt.push(R[F]),ot.push(F));for(let F=0;F<R.length;F++)if(!ot.includes(F)){for(let H=0;H<rt.length;H++)if(R[F].distanceTo(rt[H])<E.gridWidth+.01){rt.push(R[F]),ot.push(F),F=-1;break}}if(rt.length==0)break;X.push(rt)}const K=[];for(let rt=0;rt<X.length;rt++){const F={lineSt:new y.Vector3,lineEd:new y.Vector3,facePoints:[]};let H=Se(X[rt]);Array.isArray(H)&&H.length==2&&(F.lineSt=H[0],F.lineEd=H[1],F.facePoints.push(new y.Vector3(H[0].x,H[0].y,T[0].z)),F.facePoints.push(new y.Vector3(H[1].x,H[1].y,T[0].z)),F.facePoints.push(new y.Vector3(H[1].x,H[1].y,T[2].z)),F.facePoints.push(new y.Vector3(H[0].x,H[0].y,T[2].z)),K.push(F))}D+=E.area;let G=0;if(O!=0&&(G=E.gridHeight*E.gridWidth*O),(E.area-G)/A*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const F=K[rt];let H=F.facePoints[0].distanceTo(F.facePoints[1]),Vt=F.facePoints[0].distanceTo(F.facePoints[3]),Zt=H/p.length*100,qt=p.rooftopPz-F.facePoints[2].z;if(Vt<1.5||V<F.facePoints[2].z||qt>z/3*2)continue;let Rt=!1,_t=!1,Et=!1,Ft=[],tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone(),W=F.facePoints[0].clone(),j=F.facePoints[1].clone(),Nt=!1,Tt=-1;if(Math.abs(F.facePoints[0].z-p.start.z)<.25){if(H>.17&&p.length>.5){let Wt=Lt(v,W),J=Lt(v,j),ut=Lt(S,W),q=Lt(S,j);const Pt=.1,zt=10;if(Wt<Pt||J<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(Q,pt).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)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 Y=new y.Line3(it,mt).closestPointToPoint(Q,!0,Gt);let yt=Jt(Q,pt,Y,Q);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt,zt),st=pt.clone().addScaledVector(Mt.clone().negate(),zt);let wt=new 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(W.x,W.y,0),Y=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(Q,pt,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,Wt<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}if(ut<Pt||q<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(pt,Q).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)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 Y=new y.Line3(it,mt).closestPointToPoint(pt,!0,Gt);let yt=Jt(pt,Q,Y,pt);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt.clone().negate(),zt),st=pt.clone().addScaledVector(Mt,zt);let wt=new 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(W.x,W.y,0),Y=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(pt,Q,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,ut<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}H=ct.distanceTo(tt)}if(Zt<85&&H>.3||H>.7&&Vt>z-z/3){let Wt=!1;for(let J=0;J<t.length;J++){let ut=J+1;if(ut>=t.length)continue;let q=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(q.x,q.y,0),new y.Vector3(Pt.x,Pt.y,0),new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),.1)!=null){Wt=!0;break}}for(let J=0;J<a.length;J++){let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=F.facePoints[2].z<a[J].maxZ||Math.abs(F.facePoints[2].z-a[J].maxZ)<.3;if(Math.abs(F.facePoints[2].z-a[J].maxZ)>.2,Ut){let at=ne(ut.clone(),q.clone(),Pt.clone(),zt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let Q=ee(ut,q),pt=new y.Line3(new y.Vector3(p.start.x,p.start.y,0),new y.Vector3(p.end.x,p.end.y,0)),Mt=new y.Vector3,Gt=pt.closestPointToPoint(Q,!0,Mt);if(Q.distanceTo(Gt)<.15){let Z=Pt.distanceTo(ut),k=zt.distanceTo(ut);if(Z>.25&&k>.25){let it=Pt.distanceTo(q),mt=zt.distanceTo(q);if(it>.2&&mt>.2)continue}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,Tt=J,e[a[J].index].isFindBeam=!0;let dt=new y.Vector3().subVectors(Pt,zt).normalize(),U=ut.distanceTo(q)-at.overlap;k<Z&&dt.negate(),Z>k?(tt=F.facePoints[2].clone().addScaledVector(dt,U),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(dt,U),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let Q=Pt.distanceTo(zt),pt=q.distanceTo(ut);if(Math.abs(Q-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>Q&&Math.abs(pt-at.overlap)>1){let Mt=Pt.distanceTo(ut),Gt=Pt.distanceTo(q),ft=zt.distanceTo(ut),Z=zt.distanceTo(q),k=Mt<Gt?Mt:Gt,dt=ft<Z?ft:Z,U=new y.Vector3().subVectors(Pt,zt).normalize(),it=pt-at.overlap;k<dt?(U.negate(),tt=F.facePoints[2].clone().addScaledVector(U,it),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(U,it),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,e[a[J].index].isFindBeam=!0,Tt=J}}}}if(!Et&&H<1.5)for(let J=0;J<a.length;J++){if(a[J].inWall)continue;let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=new y.Vector3().subVectors(ut,q).normalize(),at=new y.Vector3().subVectors(Pt,zt).normalize(),Q=.25,pt=ut.clone().addScaledVector(Ut,Q),Mt=q.clone().addScaledVector(Ut.clone().negate(),Q),Gt=Pt.clone().addScaledVector(at,Q),ft=zt.clone().addScaledVector(at.clone().negate(),Q),Z=te(pt,Mt,Gt,ft),k=!0,dt=ut.distanceTo(Pt),U=ut.distanceTo(zt),it=q.distanceTo(Pt),mt=q.distanceTo(zt);(dt<f||U<f||it<f||mt<f||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Tt=J)}(_t||Wt||Math.abs(Vt-z)>.1&&Vt>z/2&&H>.3)&&(Rt=!0)}}if(Rt){let Wt=!1;for(let Z=0;Z<d.length;Z++){let k=ne(d[Z].start,d[Z].end,W,j);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){Wt=!0;break}}if(Wt){Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1);continue}d.push({start:W,end:j});{new y.PointsMaterial({color:65535,size:.01});let Z=new y.Vector3().subVectors(W,j),k=new y.Vector3().subVectors(j,W),dt=1/0,U=1/0,it=W.clone(),mt=j.clone();const Ct=[],St=[];let At=new y.Line3(tt,ct),Y=new y.Vector3,yt=999999;if(p.originalPoints.forEach(et=>{if(et.z-W.z<Vt/2+.1&&et.z-W.z>Vt/2-.1&&Ct.push(et),et.z>tt.z){let st=At.closestPointToPoint(et,!0,Y),wt=new 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(W,j,Ct);for(const st of et)st.z=W.z;et.forEach(st=>{let wt=new y.Vector3(st.x,st.y,W.z),vt=new y.Vector3().subVectors(wt,j),Bt=new y.Vector3().subVectors(wt,W),bt=oe(Z,Bt),Xt=oe(k,vt);if(bt&&bt.parallel&&bt.sameDirection){let $t=wt.distanceTo(W);$t<dt&&(dt=$t,it=wt)}else if(Xt&&Xt.parallel&&Xt.sameDirection){let $t=wt.distanceTo(j);$t<U&&(U=$t,mt=wt)}})}if(it.equals(W)||(W=it,ct=new y.Vector3(W.x,W.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,Y).distanceTo(et[st]);vt>.02&&yt>vt&&(yt=vt)}tt.z+=yt,ct.z+=yt,Vt+=yt}}let J=j.distanceTo(W);if(J<.4&&!_t||J<.3&&_t)continue;h.includes(m)||h.push(m),p.checkResults[E.index].isDoor=!0;let ut="",q={id:l,beamStart:tt,beamEnd:ct,beamHeight:p.rooftopPz-tt.z,doorStart:W,doorEnd:j,doorHeight:Vt,nearId:-1,type:ut,isExtend:Nt,isDoor:_t,isPullOutDoor:Et,pcbDoorIndexs:Ft,beamNearWallVec:new y.Vector3(0,0,0)},Pt=!1,zt=new y.Vector3,Ut=new y.Vector3,at=-1,Q=-1,pt=-1;for(let Z=0;Z<u.length;Z++){const k=n[u[Z].linesIndex].doorAndBeamData[u[Z].doorIndex];if(k.nearId!=-1)continue;let dt=Jt(tt.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let U=tt.distanceTo(ct),it=k.beamStart.distanceTo(k.beamEnd),mt=new y.Line3(tt.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let Ct=ee(k.beamStart,k.beamEnd,!0);it>U&&(mt.start=new y.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new y.Vector3(k.beamEnd.x,k.beamEnd.y,0),Ct=ee(tt,ct,!0));let St=new y.Vector3,At=mt.closestPointToPoint(Ct,!0,St),Y=At.distanceTo(Ct),yt=new y.Vector3().subVectors(Ct,At).normalize(),et=yt.clone().negate(),st=Ct.clone().addScaledVector(et,Y+.1),wt=te(mt.start,mt.end,Ct,st),vt=!_t&&!k.isDoor&&(U>it*2||it>U*2);if(Y<.4&&wt!=null&&!vt){k.nearId=l,q.nearId=k.id;let Bt=.8;(k.isDoor||q.isDoor)&&(k.isDoor=!0,q.isDoor=!0);const bt=Ft.some(Xt=>k.pcbDoorIndexs.includes(Xt));U<it?U>Bt&&!k.isPullOutDoor?(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Et||Et&&k.isPullOutDoor&&bt?(q.beamStart=k.beamStart.clone().addScaledVector(yt,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(yt,Y),q.doorStart=k.doorStart.clone().addScaledVector(yt,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(yt,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):U>it&&(it>Bt&&!Et?(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):!k.isPullOutDoor||Et&&k.isPullOutDoor&&bt?(k.beamStart=tt.clone().addScaledVector(yt,Y),k.beamEnd=ct.clone().addScaledVector(yt,Y),k.doorStart=W.clone().addScaledVector(yt,Y),k.doorEnd=j.clone().addScaledVector(yt,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight)),at=q.nearId,zt=k.beamStart.clone(),Ut=k.beamEnd.clone(),Pt=!0,Q=u[Z].linesIndex,pt=u[Z].doorIndex;break}}}let Mt=!1;if(!Pt){let Z=new y.Line3(W.clone(),j.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==m)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,W,j),mt=Jt(dt,U,W,j);const Ct=io(n[k]);if(it&&it.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let st=new y.Line3(dt,U),wt=new y.Vector3(W.x,W.y,dt.z),vt=st.closestPointToPoint(wt,!0,new y.Vector3),Bt=re(vt,wt,W,j);Bt&&Bt.angle>85&&(q.beamNearWallVec=new y.Vector3().subVectors(vt,wt).normalize())}const St=[];n[k].originalPoints.forEach(st=>{st.z>W.z+.2&&st.z<W.z+Vt/2&&St.push(new y.Vector3(st.x,st.y,W.z))});const At=new y.Vector3;let Y=[],yt=[];for(let st=0;st<St.length;st++){let wt=Z.closestPointToPoint(St[st],!0,At);wt.distanceTo(St[st])<.15&&(Y.push(St[st]),yt.push(wt.clone()))}for(let st=0;st<yt.length;st++)ao(Z,yt[st])&&Y.push(yt[st]);if(Y=yt,Y=co(Y),Y.length<150)continue;let et=Se(Y);if(et.length==2){let st=et[0].distanceTo(et[1]);if(Math.abs(st-Z.distance())<.3){let wt=new y.Line3(dt,U),vt=new y.Vector3(W.x,W.y,dt.z),Bt=wt.closestPointToPoint(vt,!0,new y.Vector3);if(q.beamNearWallVec=new y.Vector3().subVectors(Bt,vt).normalize(),q.beamStart.z>Ct.maxZ-.03&&H>1)Mt=!0;else if(Wt=!0,Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1),Q!=-1&&pt!=-1){const bt=n[Q].doorAndBeamData[pt];bt.nearId=-1}break}}if(Wt)break}else it&&it.type=="collinear_overlap"&&it.maxPerpendicularDistance>.3&&it.maxPerpendicularDistance<.7&&(Mt=!0)}if(Wt){if(H<1.8)continue;Mt=!0}}let Gt=!1;if(at!=-1)for(let Z=0;Z<c.length&&!(c[Z].length==1&&(c[Z][0].id==l?(c[Z].push({id:at,beamStart:zt,beamEnd:Ut}),Gt=!0):c[Z][0].id==at&&(c[Z].push({id:l,beamStart:tt,beamEnd:ct}),Gt=!0),Gt));Z++);Gt||c.push([{id:l,beamStart:tt,beamEnd:ct}]);const ft=q.doorStart.distanceTo(q.doorEnd);if(_t?ut="door":ft>1.8?ut="beam":ut=Mt&&ft>1?"beam":"hole",q.type=ut,q.nearId!=-1&&ut=="hole"){let Z=!1;for(let k=0;k<n.length;k++)if(n[k].doorAndBeamData){for(let dt=0;dt<n[k].doorAndBeamData.length;dt++)if(n[k].doorAndBeamData[dt].nearId==l&&n[k].doorAndBeamData[dt].type=="beam"){n[k].doorAndBeamData[dt].type=ut,Z=!0;break}if(Z)break}}if(p.doorAndBeamData.push(q),u.push({linesIndex:m,doorIndex:p.doorAndBeamData.length-1}),l++,Et&&H<2)break}}}let _=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=D/_*100}if(h.length>1)for(let m=0;m<h.length;m++){let p=[];for(let P=0;P<n[h[m]].doorAndBeamData.length;P++){let V=!1;if(n[h[m]].doorAndBeamData[P].type==="beam"&&n[h[m]].doorAndBeamData[P].beamNearWallVec.x==0&&n[h[m]].doorAndBeamData[P].beamNearWallVec.y==0&&n[h[m]].doorAndBeamData[P].beamNearWallVec.z==0&&n[h[m]].doorAndBeamData[P].nearId==-1&&(V=!0),!V){let v=n[h[m]].doorAndBeamData[P].doorStart.clone(),S=n[h[m]].doorAndBeamData[P].doorEnd.clone();v.z=S.z=0;let z=v.distanceTo(S);for(let D=0;D<h.length;D++)if(m!=D)for(let _=0;_<n[h[D]].doorAndBeamData.length;_++){let E=n[h[D]].doorAndBeamData[_].doorStart.clone(),T=n[h[D]].doorAndBeamData[_].doorEnd.clone();E.z=T.z=0,E.distanceTo(T);let A=ne(v,S,E,T);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let O=new y.Line3(E,T),I=ee(v,S),B=O.closestPointToPoint(I,!0,new y.Vector3),L=I.distanceTo(B);if(Math.abs(z-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[m]].doorAndBeamData[P].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),V=!0;break}}}}V||p.push(n[h[m]].doorAndBeamData[P])}p.length!=n[h[m]].doorAndBeamData.length&&(n[h[m]].doorAndBeamData=p)}let w=.65,x=2,b=[],M=[];for(let m=0;m<a.length;m++){if(a[m].isFind||a[m].inWall)continue;let p=new y.Vector3(a[m].doorStartPt.x,a[m].doorStartPt.y,0),P=new y.Vector3(a[m].doorEndPt.x,a[m].doorEndPt.y,0),V=new y.Vector3().subVectors(p,P).normalize();for(let v=0;v<n.length;v++){if(n[v].length<.7||n[v].completePointAreaPercentage>60)continue;let S=new y.Vector3(n[v].start.x,n[v].start.y,0),z=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,z).normalize(),_=.3,E=p.clone().addScaledVector(V,_),T=P.clone().addScaledVector(V.clone().negate(),_),A=S.clone().addScaledVector(D,_),O=z.clone().addScaledVector(D.clone().negate(),_);te(E,T,A,O);let I=Jt(E,T,A,O),B=p.distanceTo(S)>P.distanceTo(S)?P:p,L=B.distanceTo(S),N=B.distanceTo(z);if((L<f||N<f)&&I&&!I.isParallel){let R=p.distanceTo(S),$=p.distanceTo(z),X=R<$?S:z,ot=!1;for(let K=0;K<n.length;K++){if(K==v||b.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(),F=rt.clone().negate(),H=G.clone().addScaledVector(rt,5),Vt=ht.clone().addScaledVector(F,5),Zt=re(S,z,G,ht),qt=ne(S,z,G,ht),Rt=te(S,z,H,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<f||Rt.point.distanceTo(z)<f),(Zt&&Zt.angle>85||qt&&qt.type=="collinear_gap")&&_t){let Et=new y.Line3(S,z),Ft=new y.Vector3,tt=Et.closestPointToPoint(G,!0,Ft),ct=Et.closestPointToPoint(ht,!0,Ft),W=tt.distanceTo(G),j=ct.distanceTo(ht),Nt,Tt;if(W>j&&j>w)Nt=ht,Tt=ct;else if(W<j&&W>w)Nt=G,Tt=tt;else continue;if(W=X.distanceTo(G),j=X.distanceTo(ht),W>x&&j>x)continue;let Wt=Jt(Nt,Tt,G,ht),J=Jt(Nt,Tt,E,T);if(J&&J.isParallel||!Wt||!Wt.isParallel)continue;let ut=ne(p,P,Nt,Tt);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Nt.z=Tt.z=n[K].start.z;let q=!1;for(let at=0;at<M.length;at++){let Q=ne(M[at].start,M[at].end,Nt,Tt);if(Q&&Q.type=="collinear_overlap"&&Q.maxPerpendicularDistance<.2){q=!0;break}}if(q)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let Q=new 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,Nt,Tt);if(Mt&&Mt.type=="collinear_overlap"&&Mt.maxPerpendicularDistance<.1){q=!0;break}}if(q)continue;M.push({start:Nt,end:Tt}),b.push(K);let Pt=n[K].rooftopPz-n[K].start.z,zt=n[v].rooftopPz-n[v].start.z,Ut=Pt<zt?Pt:zt;n[K].doorAndBeamData||(n[K].doorAndBeamData=[]),n[K].doorAndBeamData.push({id:l,beamStart:Nt,beamEnd:Tt,beamHeight:Ut,doorStart:Nt,doorEnd:Tt,doorHeight:Ut,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new y.Vector3(0,0,0)}),e[a[m].index].isFindBeam=!0,e[a[m].index].isFindOnlyDoor=!0,c.push([{id:l,beamStart:Nt,beamEnd:Tt}]),l++,ot=!0;break}}if(ot)break}}}let g=[];for(let m=0;m<n.length;m++)n[m].isLine2||g.push(n[m]),n[m].isLine2&&n[m].doorAndBeamData.length!=0&&g.push(n[m]);return n.length=0,n.push(...g),{lines:n,beamGroup:c}},zo=(n,t)=>{if(!n||n.length<=0)return;let e={rectangles:[],threeEdgeRect:[]},o=new Set,i=.2,r=1.5,s=.15,a=2;if(!n[0].uuid){let l=1e4;for(let u=0;u<n.length;u++)n[u].uuid=l++}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h=[],d=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(c,d).normalize().clone().negate(),x=new y.Vector3,b=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let g=0;g<n.length;g++){let m=n[g].length;if(g==l||m<i||m>r)continue;let p=new y.Vector3(n[g].start.x,n[g].start.y,n[g].start.z),P=new y.Vector3(n[g].end.x,n[g].end.y,n[g].end.z),V=re(d,c,p,P);if(!V||V.angle<85)continue;let v=kt(p,d),S=kt(p,c),z=kt(P,d),D=kt(P,c);if(!(!v&&!S&&!z&&!D)){v||S?(x=p.clone(),b=P.clone()):(x=P.clone(),b=p.clone()),M=new y.Vector3().subVectors(b,x).normalize(),M.clone().negate();for(let _=0;_<n.length;_++){let E=n[_].length;if(_==l||_==g||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),O=re(p,P,T,A);if(!O||O.angle<85)continue;let I=kt(T,b),B=kt(A,b);if(!I&&!B)continue;new y.Vector3;let L=new y.Vector3,N=new y.Vector3;I?(N=new y.Vector3().subVectors(A,T).normalize(),T.clone(),L=A.clone()):(N=new y.Vector3().subVectors(T,A).normalize(),A.clone(),L=T.clone());let C=oe(w,N,.1);if(!(!C||!C.parallel||!C.sameDirection)){for(let R=0;R<n.length;R++){let $=n[R].length;if(R==l||R==g||R==_||$<i||$>r)continue;let X=new 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,T,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 F=kt(rt,d),H=kt(rt,c);if(!F&&!H)continue;let Vt=u*m;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[g].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(g=>o.add(g)),e.rectangles.push(h))}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h={uuids:[],missingEdge:{start:new y.Vector3,end:new y.Vector3}},d=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),f=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let g=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),m=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),p=kt(g,d),P=kt(m,d),V=kt(g,c),v=kt(m,c);if(p||P?f=!1:(V||v)&&(w=!1),!f&&!w)break}if(!f&&!w)continue;let x=new y.Vector3;f||([d,c]=[c,d]),x=new y.Vector3().subVectors(c,d).normalize();let b=x.clone().negate();for(let M=0;M<n.length;M++){let g=n[M].length;if(M==l||o.has(M)||g<i||g>r)continue;let m=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),P=re(d,c,m,p);if(!P||P.angle<85)continue;let V=kt(m,c),v=kt(p,c);if(!V&&!v)continue;new y.Vector3;let S=new y.Vector3;V?(m.clone(),S=p.clone()):(p.clone(),S=m.clone());for(let z=0;z<n.length;z++){let D=n[z].length;if(z==l||z==M||o.has(z)||D<i||D>r)continue;let _=new y.Vector3(n[z].start.x,n[z].start.y,n[z].start.z),E=new y.Vector3(n[z].end.x,n[z].end.y,n[z].end.z),T=re(m,p,_,E);if(!T||T.angle<85)continue;let A=kt(_,S),O=kt(E,S);if(!A&&!O)continue;let I=new 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(),N=oe(b,L,.1);if(!N||!N.parallel||!N.sameDirection)continue;let C=!0,R=!0;for(let X=0;X<n.length;X++){if(X==z||n[X].length<i)continue;let ot=new y.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),K=new y.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),G=kt(ot,_),ht=kt(K,_),rt=kt(ot,E),F=kt(K,E);if(G||ht?C=!1:(rt||F)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let $=u*g;if(!($<s||$>a)){h.uuids=[n[l].uuid,n[M].uuid,n[z].uuid],h.missingEdge.start=B,h.missingEdge.end=d;break}}if(h.uuids.length==3)break}h.uuids.length==3&&(h.uuids.forEach(M=>o.add(M)),e.threeEdgeRect.push(h))}return e},ae=11102230246251565e-32,Yt=134217729,So=(3+8*ae)*ae;function Ne(n,t,e,o,i){let r,s,a,l,u=t[0],h=o[0],d=0,c=0;h>u==h>-u?(r=u,u=t[++d]):(r=h,h=o[++c]);let f=0;if(d<n&&c<e)for(h>u==h>-u?(s=u+r,a=r-(s-u),u=t[++d]):(s=h+r,a=r-(s-h),h=o[++c]),r=s,a!==0&&(i[f++]=a);d<n&&c<e;)h>u==h>-u?(s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++d]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c]),r=s,a!==0&&(i[f++]=a);for(;d<n;)s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++d],r=s,a!==0&&(i[f++]=a);for(;c<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c],r=s,a!==0&&(i[f++]=a);return(r!==0||f===0)&&(i[f++]=r),f}function vo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function ze(n){return new Float64Array(n)}const Do=(3+16*ae)*ae,_o=(2+12*ae)*ae,Eo=(9+64*ae)*ae*ae,me=ze(4),sn=ze(8),an=ze(12),ln=ze(16),jt=ze(4);function To(n,t,e,o,i,r,s){let a,l,u,h,d,c,f,w,x,b,M,g,m,p,P,V,v,S;const z=n-i,D=e-i,_=t-r,E=o-r;p=z*E,c=Yt*z,f=c-(c-z),w=z-f,c=Yt*E,x=c-(c-E),b=E-x,P=w*b-(p-f*x-w*x-f*b),V=_*D,c=Yt*_,f=c-(c-_),w=_-f,c=Yt*D,x=c-(c-D),b=D-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,me[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,me[1]=m-(M+d)+(d-V),S=g+M,d=S-g,me[2]=g-(S-d)+(M-d),me[3]=S;let T=vo(4,me),A=_o*s;if(T>=A||-T>=A||(d=n-z,a=n-(z+d)+(d-i),d=e-D,u=e-(D+d)+(d-i),d=t-_,l=t-(_+d)+(d-r),d=o-E,h=o-(E+d)+(d-r),a===0&&l===0&&u===0&&h===0)||(A=Eo*s+So*Math.abs(T),T+=z*h+E*a-(_*u+D*l),T>=A||-T>=A))return T;p=a*E,c=Yt*a,f=c-(c-a),w=a-f,c=Yt*E,x=c-(c-E),b=E-x,P=w*b-(p-f*x-w*x-f*b),V=l*D,c=Yt*l,f=c-(c-l),w=l-f,c=Yt*D,x=c-(c-D),b=D-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const O=Ne(4,me,4,jt,sn);p=z*h,c=Yt*z,f=c-(c-z),w=z-f,c=Yt*h,x=c-(c-h),b=h-x,P=w*b-(p-f*x-w*x-f*b),V=_*u,c=Yt*_,f=c-(c-_),w=_-f,c=Yt*u,x=c-(c-u),b=u-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const I=Ne(O,sn,4,jt,an);p=a*h,c=Yt*a,f=c-(c-a),w=a-f,c=Yt*h,x=c-(c-h),b=h-x,P=w*b-(p-f*x-w*x-f*b),V=l*u,c=Yt*l,f=c-(c-l),w=l-f,c=Yt*u,x=c-(c-u),b=u-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const B=Ne(I,an,4,jt,ln);return ln[B-1]}function ve(n,t,e,o,i,r){const s=(t-r)*(e-i),a=(n-i)*(o-r),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=Do*u?l:-To(n,t,e,o,i,r,u)}const cn=Math.pow(2,-52),De=new Uint32Array(512);class Be{static from(t,e=Co,o=Lo){const i=t.length,r=new Float64Array(i*2);for(let s=0;s<i;s++){const a=t[s];r[2*s]=e(a),r[2*s+1]=o(a)}return new Be(r)}constructor(t){const e=t.length>>1;if(e>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const o=Math.max(2*e-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:o,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let a=1/0,l=1/0,u=-1/0,h=-1/0;for(let z=0;z<s;z++){const D=t[2*z],_=t[2*z+1];D<a&&(a=D),_<l&&(l=_),D>u&&(u=D),_>h&&(h=_),this._ids[z]=z}const d=(a+u)/2,c=(l+h)/2;let f=0,w=0,x=0;for(let z=0,D=1/0;z<s;z++){const _=qe(d,c,t[2*z],t[2*z+1]);_<D&&(f=z,D=_)}const b=t[2*f],M=t[2*f+1];for(let z=0,D=1/0;z<s;z++){if(z===f)continue;const _=qe(b,M,t[2*z],t[2*z+1]);_<D&&_>0&&(w=z,D=_)}let g=t[2*w],m=t[2*w+1],p=1/0;for(let z=0;z<s;z++){if(z===f||z===w)continue;const D=Io(b,M,g,m,t[2*z],t[2*z+1]);D<p&&(x=z,p=D)}let P=t[2*x],V=t[2*x+1];if(p===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ye(this._ids,this._dists,0,s-1);const z=new Uint32Array(s);let D=0;for(let _=0,E=-1/0;_<s;_++){const T=this._ids[_],A=this._dists[T];A>E&&(z[D++]=T,E=A)}this.hull=z.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(b,M,g,m,P,V)<0){const z=w,D=g,_=m;w=x,g=P,m=V,x=z,P=D,V=_}const v=ko(b,M,g,m,P,V);this._cx=v.x,this._cy=v.y;for(let z=0;z<s;z++)this._dists[z]=qe(t[2*z],t[2*z+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=f;let S=3;o[f]=e[x]=w,o[w]=e[f]=x,o[x]=e[w]=f,i[f]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(b,M)]=f,r[this._hashKey(g,m)]=w,r[this._hashKey(P,V)]=x,this.trianglesLen=0,this._addTriangle(f,w,x,-1,-1,-1);for(let z=0,D=0,_=0;z<this._ids.length;z++){const E=this._ids[z],T=t[2*E],A=t[2*E+1];if(z>0&&Math.abs(T-D)<=cn&&Math.abs(A-_)<=cn||(D=T,_=A,E===f||E===w||E===x))continue;let O=0;for(let C=0,R=this._hashKey(T,A);C<this._hashSize&&(O=r[(R+C)%this._hashSize],!(O!==-1&&O!==o[O]));C++);O=e[O];let I=O,B;for(;B=o[I],ve(T,A,t[2*I],t[2*I+1],t[2*B],t[2*B+1])>=0;)if(I=B,I===O){I=-1;break}if(I===-1)continue;let L=this._addTriangle(I,E,o[I],-1,-1,i[I]);i[E]=this._legalize(L+2),i[I]=L,S++;let N=o[I];for(;B=o[N],ve(T,A,t[2*N],t[2*N+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(N,E,B,i[E],-1,i[N]),i[E]=this._legalize(L+2),o[N]=N,S--,N=B;if(I===O)for(;B=e[I],ve(T,A,t[2*B],t[2*B+1],t[2*I],t[2*I+1])<0;)L=this._addTriangle(B,E,I,-1,i[I],i[B]),this._legalize(L+2),i[B]=L,o[I]=I,S--,I=B;this._hullStart=e[E]=I,o[I]=e[N]=E,o[E]=N,r[this._hashKey(T,A)]=E,r[this._hashKey(t[2*I],t[2*I+1])]=I}this.hull=new Uint32Array(S);for(let z=0,D=this._hullStart;z<S;z++)this.hull[z]=D,D=o[D];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(Ao(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:o,coords:i}=this;let r=0,s=0;for(;;){const a=o[t],l=t-t%3;if(s=l+(t+2)%3,a===-1){if(r===0)break;t=De[--r];continue}const u=a-a%3,h=l+(t+1)%3,d=u+(a+2)%3,c=e[s],f=e[t],w=e[h],x=e[d];if(Bo(i[2*c],i[2*c+1],i[2*f],i[2*f+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=c;const M=o[d];if(M===-1){let m=this._hullStart;do{if(this._hullTri[m]===d){this._hullTri[m]=t;break}m=this._hullPrev[m]}while(m!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,d);const g=u+(a+1)%3;r<De.length&&(De[r++]=g)}else{if(r===0)break;t=De[--r]}}return s}_link(t,e){this._halfedges[t]=e,e!==-1&&(this._halfedges[e]=t)}_addTriangle(t,e,o,i,r,s){const a=this.trianglesLen;return this._triangles[a]=t,this._triangles[a+1]=e,this._triangles[a+2]=o,this._link(a,i),this._link(a+1,r),this._link(a+2,s),this.trianglesLen+=3,a}}function Ao(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function qe(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function Bo(n,t,e,o,i,r,s,a){const l=n-s,u=t-a,h=e-s,d=o-a,c=i-s,f=r-a,w=l*l+u*u,x=h*h+d*d,b=c*c+f*f;return l*(d*b-x*f)-u*(h*b-x*c)+w*(h*f-d*c)<0}function Io(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,d=l*l+u*u,c=.5/(s*u-a*l),f=(u*h-a*d)*c,w=(s*d-l*h)*c;return f*f+w*w}function ko(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,d=l*l+u*u,c=.5/(s*u-a*l),f=n+(u*h-a*d)*c,w=t+(s*d-l*h)*c;return{x:f,y:w}}function ye(n,t,e,o){if(o-e<=20)for(let i=e+1;i<=o;i++){const r=n[i],s=t[r];let a=i-1;for(;a>=e&&t[n[a]]>s;)n[a+1]=n[a--];n[a+1]=r}else{const i=e+o>>1;let r=e+1,s=o;Me(n,i,r),t[n[e]]>t[n[o]]&&Me(n,e,o),t[n[r]]>t[n[o]]&&Me(n,r,o),t[n[e]]>t[n[r]]&&Me(n,e,r);const a=n[r],l=t[a];for(;;){do r++;while(t[n[r]]<l);do s--;while(t[n[s]]>l);if(s<r)break;Me(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ye(n,t,r,o),ye(n,t,e,s-1)):(ye(n,t,e,s-1),ye(n,t,r,o))}}function Me(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Co(n){return n[0]}function Lo(n){return n[1]}const un=1e-6;class de{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,o){t=+t,e=+e,o=+o;const i=t+o,r=e;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>un||Math.abs(this._y1-r)>un)&&(this._+="L"+i+","+r),o&&(this._+=`A${o},${o},0,1,1,${t-o},${e}A${o},${o},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,o,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+o}v${+i}h${-o}Z`}value(){return this._||null}}class Ge{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class Ro{constructor(t,[e,o,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e))||!((r=+r)>=(o=+o)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:o},vectors:i}=this;let r,s;const a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let x=0,b=0,M=o.length,g,m;x<M;x+=3,b+=2){const p=o[x]*2,P=o[x+1]*2,V=o[x+2]*2,v=t[p],S=t[p+1],z=t[P],D=t[P+1],_=t[V],E=t[V+1],T=z-v,A=D-S,O=_-v,I=E-S,B=(T*I-A*O)*2;if(Math.abs(B)<1e-9){if(r===void 0){r=s=0;for(const N of e)r+=t[N*2],s+=t[N*2+1];r/=e.length,s/=e.length}const L=1e9*Math.sign((r-v)*I-(s-S)*O);g=(v+_)/2-L*I,m=(S+E)/2+L*O}else{const L=1/B,N=T*T+A*A,C=O*O+I*I;g=v+(I*N-A*C)*L,m=S+(T*C-O*N)*L}a[b]=g,a[b+1]=m}let l=e[e.length-1],u,h=l*4,d,c=t[2*l],f,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],u=h,d=c,f=w,h=l*4,c=t[2*l],w=t[2*l+1],i[u+2]=i[h]=f-w,i[u+3]=i[h+1]=c-d}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,d=o.length;h<d;++h){const c=o[h];if(c<h)continue;const f=Math.floor(h/3)*2,w=Math.floor(c/3)*2,x=s[f],b=s[f+1],M=s[w],g=s[w+1];this._renderSegment(x,b,M,g,t)}let l,u=r[r.length-1];for(let h=0;h<r.length;++h){l=u,u=r[h];const d=Math.floor(i[u]/3)*2,c=s[d],f=s[d+1],w=l*4,x=this._project(c,f,a[w+2],a[w+3]);x&&this._renderSegment(c,f,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 Ge;return this.renderCell(t,e),e.value()}_renderSegment(t,e,o,i,r){let s;const a=this._regioncode(t,e),l=this._regioncode(o,i);a===0&&l===0?(r.moveTo(t,e),r.lineTo(o,i)):(s=this._clipSegment(t,e,o,i,a,l))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,o){return e=+e,e!==e||(o=+o,o!==o)?!1:this.delaunay._step(t,e,o)===t}*neighbors(t){const e=this._clip(t);if(e)for(const o of this.delaunay.neighbors(t)){const i=this._clip(o);if(i){t:for(let r=0,s=e.length;r<s;r+=2)for(let a=0,l=i.length;a<l;a+=2)if(e[r]===i[a]&&e[r+1]===i[a+1]&&e[(r+2)%s]===i[(a+l-2)%l]&&e[(r+3)%s]===i[(a+l-1)%l]){yield o;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:o,halfedges:i,triangles:r}}=this,s=o[t];if(s===-1)return null;const a=[];let l=s;do{const u=Math.floor(l/3);if(a.push(e[u*2],e[u*2+1]),l=l%3===2?l-2:l+1,r[l]!==t)break;l=i[l]}while(l!==s&&l!==-1);return a}_clip(t){if(t===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(e===null)return null;const{vectors:o}=this,i=t*4;return this._simplify(o[i]||o[i+1]?this._clipInfinite(t,e,o[i],o[i+1],o[i+2],o[i+3]):this._clipFinite(t,e))}_clipFinite(t,e){const o=e.length;let i=null,r,s,a=e[o-2],l=e[o-1],u,h=this._regioncode(a,l),d,c=0;for(let f=0;f<o;f+=2)if(r=a,s=l,a=e[f],l=e[f+1],u=h,h=this._regioncode(a,l),u===0&&h===0)d=c,c=0,i?i.push(a,l):i=[a,l];else{let w,x,b,M,g;if(u===0){if((w=this._clipSegment(r,s,a,l,u,h))===null)continue;[x,b,M,g]=w}else{if((w=this._clipSegment(a,l,r,s,h,u))===null)continue;[M,g,x,b]=w,d=c,c=this._edgecode(x,b),d&&c&&this._edge(t,d,c,i,i.length),i?i.push(x,b):i=[x,b]}d=c,c=this._edgecode(M,g),d&&c&&this._edge(t,d,c,i,i.length),i?i.push(M,g):i=[M,g]}if(i)d=c,c=this._edgecode(i[0],i[1]),d&&c&&this._edge(t,d,c,i,i.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(t,e,o,i,r,s){const a=r<s;for(a&&([t,e,o,i,r,s]=[o,i,t,e,s,r]);;){if(r===0&&s===0)return a?[o,i,t,e]:[t,e,o,i];if(r&s)return null;let l,u,h=r||s;h&8?(l=t+(o-t)*(this.ymax-e)/(i-e),u=this.ymax):h&4?(l=t+(o-t)*(this.ymin-e)/(i-e),u=this.ymin):h&2?(u=e+(i-e)*(this.xmax-t)/(o-t),l=this.xmax):(u=e+(i-e)*(this.xmin-t)/(o-t),l=this.xmin),r?(t=l,e=u,r=this._regioncode(t,e)):(o=l,i=u,s=this._regioncode(o,i))}}_clipInfinite(t,e,o,i,r,s){let a=Array.from(e),l;if((l=this._project(a[0],a[1],o,i))&&a.unshift(l[0],l[1]),(l=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(l[0],l[1]),a=this._clipFinite(t,a))for(let u=0,h=a.length,d,c=this._edgecode(a[h-2],a[h-1]);u<h;u+=2)d=c,c=this._edgecode(a[u],a[u+1]),d&&c&&(u=this._edge(t,d,c,a,u),h=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,o,i,r){for(;e!==o;){let s,a;switch(e){case 5:e=4;continue;case 4:e=6,s=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,s=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,s=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,s=this.xmin,a=this.ymin;break}(i[r]!==s||i[r+1]!==a)&&this.contains(t,s,a)&&(i.splice(r,0,s,a),r+=2)}return r}_project(t,e,o,i){let r=1/0,s,a,l;if(i<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/i)<r&&(l=this.ymin,a=t+(r=s)*o)}else if(i>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/i)<r&&(l=this.ymax,a=t+(r=s)*o)}if(o>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/o)<r&&(a=this.xmax,l=e+(r=s)*i)}else if(o<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/o)<r&&(a=this.xmin,l=e+(r=s)*i)}return[a,l]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let e=0;e<t.length;e+=2){const o=(e+2)%t.length,i=(e+4)%t.length;(t[e]===t[o]&&t[o]===t[i]||t[e+1]===t[o+1]&&t[o+1]===t[i+1])&&(t.splice(o,2),e-=2)}t.length||(t=null)}return t}}const Fo=2*Math.PI,ge=Math.pow;function Oo(n){return n[0]}function No(n){return n[1]}function qo(n){const{triangles:t,coords:e}=n;for(let o=0;o<t.length;o+=3){const i=2*t[o],r=2*t[o+1],s=2*t[o+2];if((e[s]-e[i])*(e[r+1]-e[i+1])-(e[r]-e[i])*(e[s+1]-e[i+1])>1e-10)return!1}return!0}function Wo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class ke{static from(t,e=Oo,o=No,i){return new ke("length"in t?Xo(t,e,o,i):Float64Array.from($o(t,e,o,i)))}constructor(t){this._delaunator=new Be(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&qo(t)){this.collinear=Int32Array.from({length:e.length/2},(c,f)=>f).sort((c,f)=>e[2*c]-e[2*f]||e[2*c+1]-e[2*f+1]);const l=this.collinear[0],u=this.collinear[this.collinear.length-1],h=[e[2*l],e[2*l+1],e[2*u],e[2*u+1]],d=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let c=0,f=e.length/2;c<f;++c){const w=Wo(e[2*c],e[2*c+1],d);e[2*c]=w[0],e[2*c+1]=w[1]}this._delaunator=new Be(e)}else delete this.collinear;const o=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,u=o.length;l<u;++l){const h=r[l%3===2?l-2:l+1];(o[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,u=i.length;l<u;++l)a[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new Ro(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const d=a.indexOf(t);d>0&&(yield a[d-1]),d<a.length-1&&(yield a[d+1]);return}const l=e[t];if(l===-1)return;let u=l,h=-1;do{if(yield h=s[u],u=u%3===2?u-2:u+1,s[u]!==t)return;if(u=r[u],u===-1){const d=o[(i[t]+1)%o.length];d!==h&&(yield d);return}}while(u!==l)}find(t,e,o=0){if(t=+t,t!==t||(e=+e,e!==e))return-1;const i=o;let r;for(;(r=this._step(o,t,e))>=0&&r!==o&&r!==i;)o=r;return r}_step(t,e,o){const{inedges:i,hull:r,_hullIndex:s,halfedges:a,triangles:l,points:u}=this;if(i[t]===-1||!u.length)return(t+1)%(u.length>>1);let h=t,d=ge(e-u[t*2],2)+ge(o-u[t*2+1],2);const c=i[t];let f=c;do{let w=l[f];const x=ge(e-u[w*2],2)+ge(o-u[w*2+1],2);if(x<d&&(d=x,h=w),f=f%3===2?f-2:f+1,l[f]!==t)break;if(f=a[f],f===-1){if(f=r[(s[t]+1)%r.length],f!==w&&ge(e-u[f*2],2)+ge(o-u[f*2+1],2)<d)return f;break}}while(f!==c);return h}render(t){const e=t==null?t=new de:void 0,{points:o,halfedges:i,triangles:r}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const u=r[s]*2,h=r[l]*2;t.moveTo(o[u],o[u+1]),t.lineTo(o[h],o[h+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){e===void 0&&(!t||typeof t.moveTo!="function")&&(e=t,t=null),e=e==null?2:+e;const o=t==null?t=new de:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const a=i[r],l=i[r+1];t.moveTo(a+e,l),t.arc(a,l,e,0,Fo)}return o&&o.value()}renderHull(t){const e=t==null?t=new de:void 0,{hull:o,points:i}=this,r=o[0]*2,s=o.length;t.moveTo(i[r],i[r+1]);for(let a=1;a<s;++a){const l=2*o[a];t.lineTo(i[l],i[l+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new Ge;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new de:void 0,{points:i,triangles:r}=this,s=r[t*=3]*2,a=r[t+1]*2,l=r[t+2]*2;return e.moveTo(i[s],i[s+1]),e.lineTo(i[a],i[a+1]),e.lineTo(i[l],i[l+1]),e.closePath(),o&&o.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,o=t.length/3;e<o;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new Ge;return this.renderTriangle(t,e),e.value()}}function Xo(n,t,e,o){const i=n.length,r=new Float64Array(i*2);for(let s=0;s<i;++s){const a=n[s];r[s*2]=t.call(o,a,s,n),r[s*2+1]=e.call(o,a,s,n)}return r}function*$o(n,t,e,o){let i=0;for(const r of n)yield t.call(o,r,i,n),yield e.call(o,r,i,n),++i}function Ho(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Yo(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),u=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return u===0?1/0:s*a*l/(4*u)}function je(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 ke(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],b=i[w+1],M=i[w+2],[g,m]=e[x],[p,P]=e[b],[V,v]=e[M],S=Yo(g,m,p,P,V,v),z=Ho(e,x,b,M);if(S<=1/z)for(const[D,_]of[[x,b],[b,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 u=a[0][0],h=[],d=new Set;let c=u,f=-1;do{h.push(e[c]),d.add(c);const w=l.get(c)||[];let x=w.find(b=>b!==f&&!d.has(b));if(x===void 0&&(x=w.find(b=>b!==f)),x===void 0)break;f=c,c=x}while(c!==u&&h.length<=a.length+1);return h}const gt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},xt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},It=[[],[],[]],nt=[[],[],[]],Dt=[],ce=new lt.Vector3,ue=new lt.Vector3,he=new lt.Vector3,Ot=new lt.Vector3,hn=new lt.Vector3,fn=new lt.Vector3,Qt=new lt.Matrix3,dn=new lt.Box3,_e=new lt.Matrix4,mn=new lt.Matrix4,gn=new lt.Ray;let Tn=class{constructor(t=new lt.Vector3,e=new lt.Vector3,o=new lt.Matrix3){this.center=t,this.halfSize=e,this.rotation=o}set(t,e,o){return this.center=t,this.halfSize=e,this.rotation=o,this}copy(t){return this.center.copy(t.center),this.halfSize.copy(t.halfSize),this.rotation.copy(t.rotation),this}clone(){return new this.constructor().copy(this)}getSize(t){return t.copy(this.halfSize).multiplyScalar(2)}clampPoint(t,e){const o=this.halfSize;Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const i=lt.MathUtils.clamp(Ot.dot(ce),-o.x,o.x);e.add(ce.multiplyScalar(i));const r=lt.MathUtils.clamp(Ot.dot(ue),-o.y,o.y);e.add(ue.multiplyScalar(r));const s=lt.MathUtils.clamp(Ot.dot(he),-o.z,o.z);return e.add(he.multiplyScalar(s)),e}containsPoint(t){return Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),Math.abs(Ot.dot(ce))<=this.halfSize.x&&Math.abs(Ot.dot(ue))<=this.halfSize.y&&Math.abs(Ot.dot(he))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Go.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,fn),fn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){gt.c=this.center,gt.e[0]=this.halfSize.x,gt.e[1]=this.halfSize.y,gt.e[2]=this.halfSize.z,this.rotation.extractBasis(gt.u[0],gt.u[1],gt.u[2]),xt.c=t.center,xt.e[0]=t.halfSize.x,xt.e[1]=t.halfSize.y,xt.e[2]=t.halfSize.z,t.rotation.extractBasis(xt.u[0],xt.u[1],xt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)It[r][s]=gt.u[r].dot(xt.u[s]);Ot.subVectors(xt.c,gt.c),Dt[0]=Ot.dot(gt.u[0]),Dt[1]=Ot.dot(gt.u[1]),Dt[2]=Ot.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)nt[r][s]=Math.abs(It[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*nt[r][0]+xt.e[1]*nt[r][1]+xt.e[2]*nt[r][2],Math.abs(Dt[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*nt[0][r]+gt.e[1]*nt[1][r]+gt.e[2]*nt[2][r],i=xt.e[r],Math.abs(Dt[0]*It[0][r]+Dt[1]*It[1][r]+Dt[2]*It[2][r])>o+i)return!1;return o=gt.e[1]*nt[2][0]+gt.e[2]*nt[1][0],i=xt.e[1]*nt[0][2]+xt.e[2]*nt[0][1],!(Math.abs(Dt[2]*It[1][0]-Dt[1]*It[2][0])>o+i||(o=gt.e[1]*nt[2][1]+gt.e[2]*nt[1][1],i=xt.e[0]*nt[0][2]+xt.e[2]*nt[0][0],Math.abs(Dt[2]*It[1][1]-Dt[1]*It[2][1])>o+i)||(o=gt.e[1]*nt[2][2]+gt.e[2]*nt[1][2],i=xt.e[0]*nt[0][1]+xt.e[1]*nt[0][0],Math.abs(Dt[2]*It[1][2]-Dt[1]*It[2][2])>o+i)||(o=gt.e[0]*nt[2][0]+gt.e[2]*nt[0][0],i=xt.e[1]*nt[1][2]+xt.e[2]*nt[1][1],Math.abs(Dt[0]*It[2][0]-Dt[2]*It[0][0])>o+i)||(o=gt.e[0]*nt[2][1]+gt.e[2]*nt[0][1],i=xt.e[0]*nt[1][2]+xt.e[2]*nt[1][0],Math.abs(Dt[0]*It[2][1]-Dt[2]*It[0][1])>o+i)||(o=gt.e[0]*nt[2][2]+gt.e[2]*nt[0][2],i=xt.e[0]*nt[1][1]+xt.e[1]*nt[1][0],Math.abs(Dt[0]*It[2][2]-Dt[2]*It[0][2])>o+i)||(o=gt.e[0]*nt[1][0]+gt.e[1]*nt[0][0],i=xt.e[1]*nt[2][2]+xt.e[2]*nt[2][1],Math.abs(Dt[1]*It[0][0]-Dt[0]*It[1][0])>o+i)||(o=gt.e[0]*nt[1][1]+gt.e[1]*nt[0][1],i=xt.e[0]*nt[2][2]+xt.e[2]*nt[2][0],Math.abs(Dt[1]*It[0][1]-Dt[0]*It[1][1])>o+i)||(o=gt.e[0]*nt[1][2]+gt.e[1]*nt[0][2],i=xt.e[0]*nt[2][1]+xt.e[1]*nt[2][0],Math.abs(Dt[1]*It[0][2]-Dt[0]*It[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ce,ue,he);const e=this.halfSize.x*Math.abs(t.normal.dot(ce))+this.halfSize.y*Math.abs(t.normal.dot(ue))+this.halfSize.z*Math.abs(t.normal.dot(he)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(hn),dn.setFromCenterAndSize(Ot.set(0,0,0),hn),_e.setFromMatrix3(this.rotation),_e.setPosition(this.center),mn.copy(_e).invert(),gn.copy(t).applyMatrix4(mn),gn.intersectBox(dn,e)?e.applyMatrix4(_e):null}intersectsRay(t){return this.intersectRay(t,Ot)!==null}fromBox3(t){return t.getCenter(this.center),t.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(t){return t.center.equals(this.center)&&t.halfSize.equals(this.halfSize)&&t.rotation.equals(this.rotation)}applyMatrix4(t){const e=t.elements;let o=Ot.set(e[0],e[1],e[2]).length();const i=Ot.set(e[4],e[5],e[6]).length(),r=Ot.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Qt.setFromMatrix4(t);const a=1/o,l=1/i,u=1/r;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[3]*=l,Qt.elements[4]*=l,Qt.elements[5]*=l,Qt.elements[6]*=u,Qt.elements[7]*=u,Qt.elements[8]*=u,this.rotation.multiply(Qt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ot.setFromMatrixPosition(t),this.center.add(Ot),this}};const Go=new Tn;var Ht=63710088e-1,An={centimeters:Ht*100,centimetres:Ht*100,degrees:360/(2*Math.PI),feet:Ht*3.28084,inches:Ht*39.37,kilometers:Ht/1e3,kilometres:Ht/1e3,meters:Ht,metres:Ht,miles:Ht/1609.344,millimeters:Ht*1e3,millimetres:Ht*1e3,nauticalmiles:Ht/1852,radians:1,yards:Ht*1.0936};function Bn(n,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=n,o}function In(n,t,e={}){if(!n)throw new Error("coordinates is required");if(!Array.isArray(n))throw new Error("coordinates must be an Array");if(n.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!pn(n[0])||!pn(n[1]))throw new Error("coordinates must contain numbers");return Bn({type:"Point",coordinates:n},t,e)}function kn(n,t,e={}){for(const i of n){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<i[i.length-1].length;r++)if(i[i.length-1][r]!==i[0][r])throw new Error("First and last Position are not equivalent.")}return Bn({type:"Polygon",coordinates:n},t,e)}function jo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Uo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n/e}function Cn(n){return n%(2*Math.PI)*180/Math.PI}function ie(n){return n%360*Math.PI/180}function Ln(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return jo(Uo(n,t),e)}function pn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function Zo(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function Pe(n,t,e){if(n!==null)for(var o,i,r,s,a,l,u,h=0,d=0,c,f=n.type,w=f==="FeatureCollection",x=f==="Feature",b=w?n.features.length:1,M=0;M<b;M++){u=w?n.features[M].geometry:x?n.geometry:n,c=u?u.type==="GeometryCollection":!1,a=c?u.geometries.length:1;for(var g=0;g<a;g++){var m=0,p=0;if(s=c?u.geometries[g]:u,s!==null){l=s.coordinates;var P=s.type;switch(h=e&&(P==="Polygon"||P==="MultiPolygon")?1:0,P){case null:break;case"Point":if(t(l,d,M,m,p)===!1)return!1;d++,m++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],d,M,m,p)===!1)return!1;d++,P==="MultiPoint"&&m++}P==="LineString"&&m++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-h;i++){if(t(l[o][i],d,M,m,p)===!1)return!1;d++}P==="MultiLineString"&&m++,P==="Polygon"&&p++}P==="Polygon"&&m++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(p=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],d,M,m,p)===!1)return!1;d++}p++}m++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(Pe(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ko(n){var t=[];return Pe(n,function(e){t.push(e)}),t}function Qo(n,t){var e,o,i,r,s,a,l,u,h,d,c=0,f=n.type==="FeatureCollection",w=n.type==="Feature",x=f?n.features.length:1;for(e=0;e<x;e++){for(a=f?n.features[e].geometry:w?n.geometry:n,u=f?n.features[e].properties:w?n.properties:{},h=f?n.features[e].bbox:w?n.bbox:void 0,d=f?n.features[e].id:w?n.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(r=l?a.geometries[i]:a,r===null){if(t(null,c,u,h,d)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,c,u,h,d)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],c,u,h,d)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}c++}}function Jo(n,t,e){var o=e;return Qo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function er(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function o(){return this instanceof o?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(o){var i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:function(){return n[o]}})}),e}var Ze={exports:{}},Fn={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(g,m,p,P,V){(function v(S,z,D,_,E){for(;_>D;){if(_-D>600){var T=_-D+1,A=z-D+1,O=Math.log(T),I=.5*Math.exp(2*O/3),B=.5*Math.sqrt(O*I*(T-I)/T)*(A-T/2<0?-1:1),L=Math.max(D,Math.floor(z-A*I/T+B)),N=Math.min(_,Math.floor(z+(T-A)*I/T+B));v(S,z,L,N,E)}var C=S[z],R=D,$=_;for(o(S,D,z),E(S[_],C)>0&&o(S,D,_);R<$;){for(o(S,R,$),R++,$--;E(S[R],C)<0;)R++;for(;E(S[$],C)>0;)$--}E(S[D],C)===0?o(S,D,$):o(S,++$,_),$<=z&&(D=$+1),z<=$&&(_=$-1)}})(g,m,p||0,P||g.length-1,V||i)}function o(g,m,p){var P=g[m];g[m]=g[p],g[p]=P}function i(g,m){return g<m?-1:g>m?1:0}var r=function(g){g===void 0&&(g=9),this._maxEntries=Math.max(4,g),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(g,m,p){if(!p)return m.indexOf(g);for(var P=0;P<m.length;P++)if(p(g,m[P]))return P;return-1}function a(g,m){l(g,0,g.children.length,m,g)}function l(g,m,p,P,V){V||(V=b(null)),V.minX=1/0,V.minY=1/0,V.maxX=-1/0,V.maxY=-1/0;for(var v=m;v<p;v++){var S=g.children[v];u(V,g.leaf?P(S):S)}return V}function u(g,m){return g.minX=Math.min(g.minX,m.minX),g.minY=Math.min(g.minY,m.minY),g.maxX=Math.max(g.maxX,m.maxX),g.maxY=Math.max(g.maxY,m.maxY),g}function h(g,m){return g.minX-m.minX}function d(g,m){return g.minY-m.minY}function c(g){return(g.maxX-g.minX)*(g.maxY-g.minY)}function f(g){return g.maxX-g.minX+(g.maxY-g.minY)}function w(g,m){return g.minX<=m.minX&&g.minY<=m.minY&&m.maxX<=g.maxX&&m.maxY<=g.maxY}function x(g,m){return m.minX<=g.maxX&&m.minY<=g.maxY&&m.maxX>=g.minX&&m.maxY>=g.minY}function b(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(g,m,p,P,V){for(var v=[m,p];v.length;)if(!((p=v.pop())-(m=v.pop())<=P)){var S=m+Math.ceil((p-m)/P/2)*P;e(g,S,m,p,V),v.push(m,S,S,p)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(g){var m=this.data,p=[];if(!x(g,m))return p;for(var P=this.toBBox,V=[];m;){for(var v=0;v<m.children.length;v++){var S=m.children[v],z=m.leaf?P(S):S;x(g,z)&&(m.leaf?p.push(S):w(g,z)?this._all(S,p):V.push(S))}m=V.pop()}return p},r.prototype.collides=function(g){var m=this.data;if(!x(g,m))return!1;for(var p=[];m;){for(var P=0;P<m.children.length;P++){var V=m.children[P],v=m.leaf?this.toBBox(V):V;if(x(g,v)){if(m.leaf||w(g,v))return!0;p.push(V)}}m=p.pop()}return!1},r.prototype.load=function(g){if(!g||!g.length)return this;if(g.length<this._minEntries){for(var m=0;m<g.length;m++)this.insert(g[m]);return this}var p=this._build(g.slice(),0,g.length-1,0);if(this.data.children.length)if(this.data.height===p.height)this._splitRoot(this.data,p);else{if(this.data.height<p.height){var P=this.data;this.data=p,p=P}this._insert(p,this.data.height-p.height-1,!0)}else this.data=p;return this},r.prototype.insert=function(g){return g&&this._insert(g,this.data.height-1),this},r.prototype.clear=function(){return this.data=b([]),this},r.prototype.remove=function(g,m){if(!g)return this;for(var p,P,V,v=this.data,S=this.toBBox(g),z=[],D=[];v||z.length;){if(v||(v=z.pop(),P=z[z.length-1],p=D.pop(),V=!0),v.leaf){var _=s(g,v.children,m);if(_!==-1)return v.children.splice(_,1),z.push(v),this._condense(z),this}V||v.leaf||!w(v,S)?P?(p++,v=P.children[p],V=!1):v=null:(z.push(v),D.push(p),p=0,P=v,v=v.children[0])}return this},r.prototype.toBBox=function(g){return g},r.prototype.compareMinX=function(g,m){return g.minX-m.minX},r.prototype.compareMinY=function(g,m){return g.minY-m.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(g){return this.data=g,this},r.prototype._all=function(g,m){for(var p=[];g;)g.leaf?m.push.apply(m,g.children):p.push.apply(p,g.children),g=p.pop();return m},r.prototype._build=function(g,m,p,P){var V,v=p-m+1,S=this._maxEntries;if(v<=S)return a(V=b(g.slice(m,p+1)),this.toBBox),V;P||(P=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,P-1))),(V=b([])).leaf=!1,V.height=P;var z=Math.ceil(v/S),D=z*Math.ceil(Math.sqrt(S));M(g,m,p,D,this.compareMinX);for(var _=m;_<=p;_+=D){var E=Math.min(_+D-1,p);M(g,_,E,z,this.compareMinY);for(var T=_;T<=E;T+=z){var A=Math.min(T+z-1,E);V.children.push(this._build(g,T,A,P-1))}}return a(V,this.toBBox),V},r.prototype._chooseSubtree=function(g,m,p,P){for(;P.push(m),!m.leaf&&P.length-1!==p;){for(var V=1/0,v=1/0,S=void 0,z=0;z<m.children.length;z++){var D=m.children[z],_=c(D),E=(T=g,A=D,(Math.max(A.maxX,T.maxX)-Math.min(A.minX,T.minX))*(Math.max(A.maxY,T.maxY)-Math.min(A.minY,T.minY))-_);E<v?(v=E,V=_<V?_:V,S=D):E===v&&_<V&&(V=_,S=D)}m=S||m.children[0]}var T,A;return m},r.prototype._insert=function(g,m,p){var P=p?g:this.toBBox(g),V=[],v=this._chooseSubtree(P,this.data,m,V);for(v.children.push(g),u(v,P);m>=0&&V[m].children.length>this._maxEntries;)this._split(V,m),m--;this._adjustParentBBoxes(P,V,m)},r.prototype._split=function(g,m){var p=g[m],P=p.children.length,V=this._minEntries;this._chooseSplitAxis(p,V,P);var v=this._chooseSplitIndex(p,V,P),S=b(p.children.splice(v,p.children.length-v));S.height=p.height,S.leaf=p.leaf,a(p,this.toBBox),a(S,this.toBBox),m?g[m-1].children.push(S):this._splitRoot(p,S)},r.prototype._splitRoot=function(g,m){this.data=b([g,m]),this.data.height=g.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(g,m,p){for(var P,V,v,S,z,D,_,E=1/0,T=1/0,A=m;A<=p-m;A++){var O=l(g,0,A,this.toBBox),I=l(g,A,p,this.toBBox),B=(V=O,v=I,S=void 0,z=void 0,D=void 0,_=void 0,S=Math.max(V.minX,v.minX),z=Math.max(V.minY,v.minY),D=Math.min(V.maxX,v.maxX),_=Math.min(V.maxY,v.maxY),Math.max(0,D-S)*Math.max(0,_-z)),L=c(O)+c(I);B<E?(E=B,P=A,T=L<T?L:T):B===E&&L<T&&(T=L,P=A)}return P||p-m},r.prototype._chooseSplitAxis=function(g,m,p){var P=g.leaf?this.compareMinX:h,V=g.leaf?this.compareMinY:d;this._allDistMargin(g,m,p,P)<this._allDistMargin(g,m,p,V)&&g.children.sort(P)},r.prototype._allDistMargin=function(g,m,p,P){g.children.sort(P);for(var V=this.toBBox,v=l(g,0,m,V),S=l(g,p-m,p,V),z=f(v)+f(S),D=m;D<p-m;D++){var _=g.children[D];u(v,g.leaf?V(_):_),z+=f(v)}for(var E=p-m-1;E>=m;E--){var T=g.children[E];u(S,g.leaf?V(T):T),z+=f(S)}return z},r.prototype._adjustParentBBoxes=function(g,m,p){for(var P=p;P>=0;P--)u(m[P],g)},r.prototype._condense=function(g){for(var m=g.length-1,p=void 0;m>=0;m--)g[m].children.length===0?m>0?(p=g[m-1].children).splice(p.indexOf(g[m]),1):this.clear():a(g[m],this.toBBox)},r})})(Fn);var nr=Fn.exports;class or{constructor(t=[],e=rr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let o=(this.length>>1)-1;o>=0;o--)this._down(o)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:o}=this,i=e[t];for(;t>0;){const r=t-1>>1,s=e[r];if(o(i,s)>=0)break;e[t]=s,t=r}e[t]=i}_down(t){const{data:e,compare:o}=this,i=this.length>>1,r=e[t];for(;t<i;){let s=(t<<1)+1,a=e[s];const l=s+1;if(l<this.length&&o(e[l],a)<0&&(s=l,a=e[l]),o(a,r)>=0)break;e[t]=a,t=s}e[t]=r}}function rr(n,t){return n<t?-1:n>t?1:0}const ir=Object.freeze(Object.defineProperty({__proto__:null,default:or},Symbol.toStringTag,{value:"Module"})),sr=er(ir);var Ce={exports:{}},ar=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=(i-o)/2,u=0,h=l-1;u<l;h=u++){var d=e[o+u*2+0],c=e[o+u*2+1],f=e[o+h*2+0],w=e[o+h*2+1],x=c>s!=w>s&&r<(f-d)*(s-c)/(w-c)+d;x&&(a=!a)}return a},lr=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=i-o,u=0,h=l-1;u<l;h=u++){var d=e[u+o][0],c=e[u+o][1],f=e[h+o][0],w=e[h+o][1],x=c>s!=w>s&&r<(f-d)*(s-c)/(w-c)+d;x&&(a=!a)}return a},On=ar,Nn=lr;Ce.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Nn(t,e,o,i):On(t,e,o,i)};Ce.exports.nested=Nn;Ce.exports.flat=On;var cr=Ce.exports,Ue={exports:{}};(function(n,t){(function(e,o){o(t)})(Rn,function(e){const i=33306690738754706e-32;function r(x,b,M,g,m){let p,P,V,v,S=b[0],z=g[0],D=0,_=0;z>S==z>-S?(p=S,S=b[++D]):(p=z,z=g[++_]);let E=0;if(D<x&&_<M)for(z>S==z>-S?(V=p-((P=S+p)-S),S=b[++D]):(V=p-((P=z+p)-z),z=g[++_]),p=P,V!==0&&(m[E++]=V);D<x&&_<M;)z>S==z>-S?(V=p-((P=p+S)-(v=P-p))+(S-v),S=b[++D]):(V=p-((P=p+z)-(v=P-p))+(z-v),z=g[++_]),p=P,V!==0&&(m[E++]=V);for(;D<x;)V=p-((P=p+S)-(v=P-p))+(S-v),S=b[++D],p=P,V!==0&&(m[E++]=V);for(;_<M;)V=p-((P=p+z)-(v=P-p))+(z-v),z=g[++_],p=P,V!==0&&(m[E++]=V);return p===0&&E!==0||(m[E++]=p),E}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,u=11093356479670487e-47,h=s(4),d=s(8),c=s(12),f=s(16),w=s(4);e.orient2d=function(x,b,M,g,m,p){const P=(b-p)*(M-m),V=(x-m)*(g-p),v=P-V;if(P===0||V===0||P>0!=V>0)return v;const S=Math.abs(P+V);return Math.abs(v)>=a*S?v:-function(z,D,_,E,T,A,O){let I,B,L,N,C,R,$,X,ot,K,G,ht,rt,F,H,Vt,Zt,qt;const Rt=z-T,_t=_-T,Et=D-A,Ft=E-A;C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=Rt*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=Et*_t)-$*ot-X*ot-$*K))),h[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),h[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,h[2]=ht-(qt-C)+(G-C),h[3]=qt;let tt=function(Tt,Wt){let J=Wt[0];for(let ut=1;ut<Tt;ut++)J+=Wt[ut];return J}(4,h),ct=l*O;if(tt>=ct||-tt>=ct||(I=z-(Rt+(C=z-Rt))+(C-T),L=_-(_t+(C=_-_t))+(C-T),B=D-(Et+(C=D-Et))+(C-A),N=E-(Ft+(C=E-Ft))+(C-A),I===0&&B===0&&L===0&&N===0)||(ct=u*O+i*Math.abs(tt),(tt+=Rt*N+Ft*I-(Et*L+_t*B))>=ct||-tt>=ct))return tt;C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=I*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=B*_t)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const W=r(4,h,4,w,d);C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=Rt*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=Et*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const j=r(W,d,4,w,c);C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=I*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=B*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const Nt=r(j,c,4,w,f);return f[Nt-1]}(x,b,M,g,m,p,S)},e.orient2dfast=function(x,b,M,g,m,p){return(b-p)*(M-m)-(x-m)*(g-p)},Object.defineProperty(e,"__esModule",{value:!0})})})(Ue,Ue.exports);var ur=Ue.exports,yn=nr,Ae=sr,hr=cr,fr=ur.orient2d;Ae.default&&(Ae=Ae.default);Ze.exports=qn;Ze.exports.default=qn;function qn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=yr(n),i=new yn(16);i.toBBox=function(g){return{minX:g[0],minY:g[1],maxX:g[0],maxY:g[1]}},i.compareMinX=function(g,m){return g[0]-m[0]},i.compareMinY=function(g,m){return g[1]-m[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=bn(l,a),r.push(a)}var u=new yn(16);for(s=0;s<r.length;s++)u.insert(We(r[s]));for(var h=t*t,d=e*e;r.length;){var c=r.shift(),f=c.p,w=c.next.p,x=Xe(f,w);if(!(x<d)){var b=x/h;l=dr(i,c.prev.p,f,w,c.next.next.p,b,u),l&&Math.min(Xe(l,f),Xe(l,w))<=b&&(r.push(c),r.push(bn(l,c)),i.remove(l),u.remove(c),u.insert(We(c)),u.insert(We(c.next)))}}c=a;var M=[];do M.push(c.p),c=c.next;while(c!==a);return M.push(c.p),M}function dr(n,t,e,o,i,r,s){for(var a=new Ae([],mr),l=n.data;l;){for(var u=0;u<l.children.length;u++){var h=l.children[u],d=l.leaf?$e(h,e,o):gr(e,o,h);d>r||a.push({node:h,dist:d})}for(;a.length&&!a.peek().node.children;){var c=a.pop(),f=c.node,w=$e(f,t,e),x=$e(f,o,i);if(c.dist<w&&c.dist<x&&wn(e,f,s)&&wn(o,f,s))return f}l=a.pop(),l&&(l=l.node)}return null}function mr(n,t){return n.dist-t.dist}function gr(n,t,e){if(xn(n,e)||xn(t,e))return 0;var o=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=Ee(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=Ee(n[0],n[1],t[0],t[1],e.minX,e.maxY,e.maxX,e.maxY);return s===0?0:Math.min(o,i,r,s)}function xn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function wn(n,t,e){for(var o=Math.min(n[0],t[0]),i=Math.min(n[1],t[1]),r=Math.max(n[0],t[0]),s=Math.max(n[1],t[1]),a=e.search({minX:o,minY:i,maxX:r,maxY:s}),l=0;l<a.length;l++)if(pr(a[l].p,a[l].next.p,n,t))return!1;return!0}function xe(n,t,e){return fr(n[0],n[1],t[0],t[1],e[0],e[1])}function pr(n,t,e,o){return n!==o&&t!==e&&xe(n,t,e)>0!=xe(n,t,o)>0&&xe(e,o,n)>0!=xe(e,o,t)>0}function We(n){var t=n.p,e=n.next.p;return n.minX=Math.min(t[0],e[0]),n.minY=Math.min(t[1],e[1]),n.maxX=Math.max(t[0],e[0]),n.maxY=Math.max(t[1],e[1]),n}function yr(n){for(var t=n[0],e=n[0],o=n[0],i=n[0],r=0;r<n.length;r++){var s=n[r];s[0]<t[0]&&(t=s),s[0]>o[0]&&(o=s),s[1]<e[1]&&(e=s),s[1]>i[1]&&(i=s)}var a=[t,e,o,i],l=a.slice();for(r=0;r<n.length;r++)hr(n[r],a)||l.push(n[r]);return wr(l)}function bn(n,t){var e={p:n,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e):(e.prev=e,e.next=e),e}function Xe(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function $e(n,t,e){var o=t[0],i=t[1],r=e[0]-o,s=e[1]-i;if(r!==0||s!==0){var a=((n[0]-o)*r+(n[1]-i)*s)/(r*r+s*s);a>1?(o=e[0],i=e[1]):a>0&&(o+=r*a,i+=s*a)}return r=n[0]-o,s=n[1]-i,r*r+s*s}function Ee(n,t,e,o,i,r,s,a){var l=e-n,u=o-t,h=s-i,d=a-r,c=n-i,f=t-r,w=l*l+u*u,x=l*h+u*d,b=h*h+d*d,M=l*c+u*f,g=h*c+d*f,m=w*b-x*x,p,P,V,v,S=m,z=m;m===0?(P=0,S=1,v=g,z=b):(P=x*g-b*M,v=w*g-x*M,P<0?(P=0,v=g,z=b):P>S&&(P=S,v=g+x,z=b)),v<0?(v=0,-M<0?P=0:-M>w?P=S:(P=-M,S=w)):v>z&&(v=z,-M+x<0?P=0:-M+x>w?P=S:(P=-M+x,S=w)),p=P===0?0:P/S,V=v===0?0:v/z;var D=(1-p)*n+p*e,_=(1-p)*t+p*o,E=(1-V)*i+V*s,T=(1-V)*r+V*a,A=E-D,O=T-_;return A*A+O*O}function xr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function wr(n){n.sort(xr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&xe(t[t.length-2],t[t.length-1],n[e])<=0;)t.pop();t.push(n[e])}for(var o=[],i=n.length-1;i>=0;i--){for(;o.length>=2&&xe(o[o.length-2],o[o.length-1],n[i])<=0;)o.pop();o.push(n[i])}return o.pop(),t.pop(),t.concat(o)}var br=Ze.exports;const Pr=tr(br);function Mr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(Pe(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=Pr(e,t.concavity);return o.length>3?kn([o]):null}function Wn(n,t={}){let e=0,o=0,i=0;return Pe(n,function(r){e+=r[0],o+=r[1],i++},!0),In([e/i,o/i],t.properties)}function se(n){if(!n)throw new Error("coord is required");if(!Array.isArray(n)){if(n.type==="Feature"&&n.geometry!==null&&n.geometry.type==="Point")return[...n.geometry.coordinates];if(n.type==="Point")return[...n.coordinates]}if(Array.isArray(n)&&n.length>=2&&!Array.isArray(n[0])&&!Array.isArray(n[1]))return[...n];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Vr(n){if(Array.isArray(n))return n;if(n.type==="Feature"){if(n.geometry!==null)return n.geometry.coordinates}else if(n.coordinates)return n.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function zr(n,t,e={}){let o;return e.final?o=Pn(se(t),se(n)):o=Pn(se(n),se(t)),o>180?-(360-o):o}function Pn(n,t){const e=ie(n[1]),o=ie(t[1]);let i=ie(t[0]-n[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(i,r);return(Cn(s)+360)%360}function Sr(n,t,e={}){const o=se(n),i=se(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=vr(o,i);return Ln(r,"meters",e.units)}function vr(n,t,e){e=e===void 0?Ht:Number(e);const o=e,i=n[1]*Math.PI/180,r=t[1]*Math.PI/180,s=r-i;let a=Math.abs(t[0]-n[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),u=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+u*u*a*a)*o}function Dr(n,t,e,o={}){const i=t<0;let r=Ln(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=se(n),a=_r(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,In(a,o.properties)}function _r(n,t,e,o){o=o===void 0?Ht:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ie(n[1]),a=ie(e),l=i*Math.cos(a);let u=s+l;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);const h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),d=Math.abs(h)>1e-11?l/h:Math.cos(s),c=i*Math.sin(a)/d;return[((r+c)*180/Math.PI+540)%360-180,u*180/Math.PI]}function Er(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Xn(n);case"FeatureCollection":return Tr(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ke(n);default:throw new Error("unknown GeoJSON type")}}function Xn(n){const t={type:"Feature"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=n[e]}}),t.properties=$n(n.properties),n.geometry==null?t.geometry=null:t.geometry=Ke(n.geometry),t}function $n(n){const t={};return n&&Object.keys(n).forEach(e=>{const o=n[e];typeof o=="object"?o===null?t[e]=null:Array.isArray(o)?t[e]=o.map(i=>i):t[e]=$n(o):t[e]=o}),t}function Tr(n){const t={type:"FeatureCollection"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=n[e]}}),t.features=n.features.map(e=>Xn(e)),t}function Ke(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>Ke(e)),t):(t.coordinates=Hn(n.coordinates),t)}function Hn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Hn(e))}function Mn(n,t,e){if(e=e||{},!Zo(e))throw new Error("options is invalid");const o=e.pivot,i=e.mutate;if(!n)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("angle is required");if(t===0)return n;const r=o??Wn(n);return(i===!1||i===void 0)&&(n=Er(n)),Pe(n,function(s){const l=zr(r,s)+t,u=Sr(r,s),h=Vr(Dr(r,u,l));s[0]=h[0],s[1]=h[1]}),n}function Yn(n,t,e={}){if(e.final===!0)return Ar(n,t);const o=se(n),i=se(t),r=ie(o[0]),s=ie(i[0]),a=ie(o[1]),l=ie(i[1]),u=Math.sin(s-r)*Math.cos(l),h=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-r);return Cn(Math.atan2(u,h))}function Ar(n,t){let e=Yn(t,n);return e=(e+180)%360,e}function Br(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return Pe(n,o=>{e[0]>o[0]&&(e[0]=o[0]),e[1]>o[1]&&(e[1]=o[1]),e[2]<o[0]&&(e[2]=o[0]),e[3]<o[1]&&(e[3]=o[1])}),e}function Ir(n,t={}){const e=Number(n[0]),o=Number(n[1]),i=Number(n[2]),r=Number(n[3]);if(n.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[e,o];return kn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function kr(n){return Ir(Br(n))}function Cr(n){return Jo(n,(t,e)=>t+Lr(e),0)}function Lr(n){let t=0,e;switch(n.type){case"Polygon":return Vn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=Vn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function Vn(n){let t=0;if(n&&n.length>0){t+=Math.abs(zn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(zn(n[e]))}return t}var Rr=Ht*Ht/2,He=Math.PI/180;function zn(n){const t=n.length-1;if(t<=2)return 0;let e=0,o=0;for(;o<t;){const i=n[o],r=n[o+1===t?0:o+1],s=n[o+2>=t?(o+2)%t:o+2],a=i[0]*He,l=r[1]*He,u=s[0]*He;e+=(u-a)*Math.sin(l),o++}return e*Rr}function Fr(n){const t=Mr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=Wn(t),o=Ko(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=Yn(o[s],o[s+1]),l=Mn(t,-1*a,{pivot:e}),u=kr(l),h=Cr(u);h<i&&(i=h,r=Mn(u,a,{pivot:e}))}return r}function Sn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Or(n){let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const[r,s]of n)r<t&&(t=r),r>e&&(e=r),s<o&&(o=s),s>i&&(i=s);return[(e+t)*.5,(i+o)*.5]}class Ie extends Tn{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Te,fe,new 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();qr.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(Te,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,Nr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(t,e,o,i=new Ie){const r=Fr({type:"Polygon",coordinates:[t.map(f=>[f.x,f.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Sn(s[0],s[1]),l=Sn(s[1],s[2]),u=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Te.set(a,l,o),vn.set(0,0,u);const[h,d]=Or(s);return e.x=h,e.y=d,this.from(Te,e,vn,i)}}const le=new y.Matrix4,fe=new y.Quaternion,vn=new y.Euler,Nr=new y.Vector3(1,1,1),Te=new y.Vector3,qr=new y.Box3;function Wr(n,t,e=.005,o=.2){if(!n.length||!t.length)return 0;const i=Math.max(e,.03),r=e*e,s=new Map,a=(d,c,f)=>`${Math.floor(d/i)},${Math.floor(c/i)},${Math.floor(f/i)}`;for(const d of t){const c=a(d.x,d.y,d.z);s.has(c)||s.set(c,[]),s.get(c).push(d)}let l=0;const u=Math.ceil(e/i)+1,h=[];for(let d=-u;d<=u;d++)for(let c=-u;c<=u;c++)for(let f=-u;f<=u;f++)d*d+c*c+f*f<=u*u&&h.push([d,c,f]);for(const d of n){const c=Math.floor(d.x/i),f=Math.floor(d.y/i),w=Math.floor(d.z/i);let x=!1;for(const[b,M,g]of h){const m=`${c+b},${f+M},${w+g}`;if(s.has(m)){for(const p of s.get(m))if(d.distanceToSquared(p)<r){x=!0;break}if(x)break}}if(x&&(l++,l/n.length>o))return l/n.length}return l/n.length}function pe(n,t,e=.5){let o=0,i=0;for(const r of n)if(t.containsPoint(r)&&(o++,i=o/n.length,i>e))break;return i}function Ye(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=we(n,o),s=we(t,e);if(r||s)return!0}return!1}function Dn(n,t){const e=new y.Vector3,o=new y.Vector3;n.getSize(e),t.getSize(o);const i=e.x*e.y*e.z,r=o.x*o.y*o.z;return i>r?1:i<r?-1:0}function we(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function _n(n){if(n.length===0)return{x:0,y:0,z:0,h:0};let t=0,e=0,o=-1/0,i=1/0;for(const r of n)t+=r.x,e+=r.y,o=Math.max(o,r.z),i=Math.min(i,r.z);return{x:t/n.length,y:e/n.length,z:0,maxz:o,minz:i,h:o-i}}function En(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(b=>[b.x,b.y]),a=n[r].obj_id;a=a.replace(/calcony railing/g,"balcony railing").replace(/glass balcony railing/g,"balcony railing").replace(/metal balcony railing/g,"balcony railing").replace(/temporary construction guardrail/g,"balcony railing").replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor"),a.split("_").slice(1,3).join("_").split(".")[0].split("_")[0];const l=a.indexOf("_")+1,u=a.lastIndexOf("_"),h=a.substring(l,u);if(h==="wall")continue;let d=[];for(let b=0;b<n[r].points.length;b++)d.push(new y.Vector3(n[r].points[b].x,n[r].points[b].y,n[r].points[b].z));let c=-99999;if(h==="floor"){let b=new Map;for(let g=0;g<n[r].points.length;g++){let m=n[r].points[g].z;if(m=Math.floor(m*10)/10,b.has(m)){const p=b.get(m);p.num+=1,p.points.push(n[r].points[g]),b.set(m,p)}else b.set(m,{num:1,points:[n[r].points[g]]})}let M=[...b.entries()].reduce((g,m)=>m[1].num>g[1].num?m:g);s=[],s=M[1].points.map(g=>[g.x,g.y]),d=[],d=M[1].points.map(g=>new y.Vector3(g.x,g.y,g.z)),c=M[0]}const f=_n(d),w={points:d,path:je(s),h:f.h,minz:f.minz,maxz:f.maxz,center:{x:f.x,y:f.y,z:f.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=En(w.path,w.center,w.h,(w.maxz+w.minz)/2),w.obb==null)continue;let x=-1;for(let b=0;b<t.length;b++)if(t[b].type==h){x=b;break}if(x!=-1?t[x].array.push(w):t.push({type:h,array:[w]}),h=="floor"&&c!=-99999)if(e.has(c)){const b=e.get(c);b.num+=w.points.length,b.datas.push(w),e.set(c,b)}else e.set(c,{num:w.points.length,datas:[w]})}let o=-1/0;if(e.size>0){let r=[];for(const[s,a]of e.entries()){const{num:l,datas:u}=a;l>3e3&&(s>o&&(o=s),r.push(...u))}for(let s=0;s<t.length;s++)if(t[s].type=="floor"){t[s].array=r;break}}for(let r=0;r<t.length;r++){const s=t[r].array,a=[],l=[];for(let h=0;h<s.length;h++){if(s[h].obb==null||a.includes(h))continue;const d={...s[h],obb:s[h].obb.clone()};for(let c=h+1;c<s.length;c++){if(s[c].obb==null||a.includes(c))continue;if(d.obb.intersectsOBB(s[c].obb)){a.push(c);for(let b=0;b<s[c].points.length;b++)(s[c].points[b].z>o&&s[c].points[b].z-o>.1||d.type=="floor")&&d.points.push(s[c].points[b]);const w=d.points.map(b=>[b.x,b.y]);d.path=je(w);const x=_n(d.points);d.h=x.h,d.minz=x.minz,d.maxz=x.maxz,d.center={x:x.x,y:x.y,z:x.z},d.obb=En(d.path,d.center,d.h,(d.maxz+d.minz)/2),d.positionArr.push(...s[c].positionArr),c=h}}d.path.length>s[h].path.length&&(a.push(h),l.push(d))}const u=[];for(let h=0;h<s.length;h++)a.includes(h)||u.push(s[h]);u.push(...l),t[r].array=u}for(let r=0;r<t.length;r++){const s=t[r].type;if(s==="people"||s==="floor")continue;const a=t[r].array;for(let l=0;l<a.length;l++){const u=a[l].obb,h=a[l].minz;a[l].maxz;const d=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const c=new y.Vector3;u.getSize(c);const f=[c.x,c.y,c.z];let w=0;for(const x of f)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let c=r+1;c<t.length;c++){const f=t[c].type;if(f==="people"||f==="floor")continue;const w=t[c].array;for(let x=0;x<w.length;x++){if(w[x].isDel)continue;const b=w[x].obb,M=w[x].minz;if(w[x].maxz,u.intersectsOBB(b)){pe(w[x].points,u);const g=pe(a[l].points,b),m=Dn(u,b);if(g>=.3&&m==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(f==="balcony railing"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(f==="balcony railing"&&we(b,a[l].points)){a[l].isDel=!0;break}if(f==="balcony railing"&&Ye(u,b,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-d)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(f==="window"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(f==="window"&&we(b,a[l].points)){a[l].isDel=!0;break}if(f==="window"&&Ye(u,b,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-d)>.3)){a[l].isDel=!0;break}}let p=!1,P=[],V=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(p=!0,P=v,V=S):(P=S,V=v),Wr(V,P,.03,.5)>.5)if(p)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(Ye(u,b)){const D=Dn(u,b);if(D===1||D===0){if(f==="switch")continue;v.length>S.length?pe(V,u)>=.5&&(w[x].isDel=!0):pe(P,u)>=.5&&(w[x].isDel=!0)}else{if(s==="switch")continue;if(v.length>S.length){if(pe(P,b)>=.5){a[l].isDel=!0;break}}else if(pe(V,b)>=.5){a[l].isDel=!0;break}}}}}}if(a[l].isDel)break}}}for(let r=0;r<t.length;r++){const s=t[r].type,a=t[r].array;for(let l=0;l<a.length;l++){let u=a[l].maxz,h=a[l].minz,d=s==="switch"?.1:.3;const c=a[l].averagePz;if(Math.abs(u-c)<d){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const f=Math.abs(u-c),w=Math.abs(h-c);(s==="tv"&&w<1.6||s!=="window"&&f<1.6)&&(a[l].isDel=!0),s==="window"&&f<1&&(a[l].isDel=!0)}if(s==="chair"){const f=new y.Vector3;a[l].obb.getSize(f),(f.x<.1||f.y<.1||f.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(u-h)<.4&&(a[l].isDel=!0),(h<c&&Math.abs(h-c)>1||h>c&&Math.abs(h-c)>1)&&(a[l].isDel=!0),u<c&&(a[l].isDel=!0)),s==="people"&&(Math.abs(u-h)<1&&(a[l].isDel=!0),h>c&&h-c>.3&&(a[l].isDel=!0),u<c&&(a[l].isDel=!0)),s==="floor"&&a[l].points.length<500&&(a[l].isDel=!0)}}for(let r=0;r<t.length;r++)t[r].array=t[r].array.filter(s=>!s.isDel);const i=[];for(let r=0;r<t.length;r++){const s=t[r].array;for(let a=0;a<s.length;a++)i.push({obbBox:s[a].obb,box:new y.Box3().setFromPoints(s[a].points),category:s[a].type,center:{x:s[a].center.x,y:s[a].center.y,z:(s[a].minz+s[a].maxz)/2},name:s[a].obj_id,obj_id:s[a].obj_id,pcdPoints:s[a].points,positionArr:s[a].positionArr})}return i};function $r(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Hr(n){if(!n.length)return 0;const t=[...n].sort((o,i)=>o-i),e=Math.floor(t.length/2);return t.length%2?t[e]:(t[e-1]+t[e])/2}function Yr(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),u=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2,h=Math.max(s,a,l);return u===0?{radius:1/0,maxEdge:h}:{radius:s*a*l/(4*u),maxEdge:h}}function Gr(n,t){const e=[],o=new Set,i=(r,s)=>r<s?`${r}_${s}`:`${s}_${r}`;for(let r=0;r<t.length;r+=3){const s=t[r],a=t[r+1],l=t[r+2],u=[[s,a],[a,l],[l,s]];for(const[h,d]of u){const c=i(h,d);if(o.has(c))continue;o.add(c);const[f,w]=n[h],[x,b]=n[d],M=Math.hypot(x-f,b-w);Number.isFinite(M)&&M>0&&e.push(M)}}return Hr(e)}function jr(n){const t=new Set,e=[];for(const o of n){if(!o||o.length<2)continue;const i=o[0],r=o[1];if(!Number.isFinite(i)||!Number.isFinite(r))continue;const s=`${i}_${r}`;t.has(s)||(t.add(s),e.push([i,r]))}return e}function Ur(n){const t=new Map;for(const[e,o]of n)t.has(e)||t.set(e,[]),t.has(o)||t.set(o,[]),t.get(e).push(o),t.get(o).push(e);return t}function Zr(n,t){if(!t.length)return[];const e=Ur(t),o=t[0][0],i=[],r=new Set;let s=o,a=-1;do{i.push(n[s]),r.add(s);const l=e.get(s)||[];let u=l.find(h=>h!==a&&!r.has(h));if(u===void 0&&(u=l.find(h=>h!==a)),u===void 0)break;a=s,s=u}while(s!==o&&i.length<=t.length+1);return i}function Kr(n,t={}){const{edgeFactor:e=20,alphaScale:o=2}=t;if(!n||n.length<3)return[];const i=jr(n);if(i.length<3)return[];const r=new ke(Float64Array.from(i.flat())),{triangles:s}=r;if(!s.length)return[];const a=Gr(i,s);if(!Number.isFinite(a)||a<=0)return[];const l=a*e,u=new Map,h=(f,w)=>f<w?`${f}_${w}`:`${w}_${f}`;for(let f=0;f<s.length;f+=3){const w=s[f],x=s[f+1],b=s[f+2],[M,g]=i[w],[m,p]=i[x],[P,V]=i[b],{radius:v,maxEdge:S}=Yr(M,g,m,p,P,V),z=$r(i,w,x,b)*o;if(v<=1/z&&S<=l){const D=[[w,x],[x,b],[b,w]];for(const[_,E]of D){const T=h(_,E);u.set(T,(u.get(T)||0)+1)}}}const d=[];for(const[f,w]of u)w===1&&d.push(f.split("_").map(Number));return d.length?Zr(i,d):[]}function be(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Qr(n){let t=0,e=0,o=0;for(let i=0;i<4;i++){const r=n[i],s=n[(i+1)%4],a=s.x-r.x,l=s.y-r.y,u=Math.sqrt(a*a+l*l);u>t&&(t=u,e=a/u,o=l/u)}return{longSide:t,dirX:e,dirY:o}}function Qe(n,t,e){const i=[];for(const r of n){const s=(r.start.x+r.end.x)/2,a=(r.start.y+r.end.y)/2,l=s-t,u=a-e;l*l+u*u<=3*3&&i.push(r.start.z,r.end.z)}if(i.length===0){const r=[];for(const s of n)r.push(s.start.z,s.end.z);return r.length?(r.sort((s,a)=>s-a),r[Math.floor(r.length/2)]):-1/0}return i.sort((r,s)=>r-s),i[Math.floor(i.length/2)]}function Gn(n,t,e,o,i,r){const s=i-e,a=r-o,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((n-e)**2+(t-o)**2),t:0};const u=n-e,h=t-o,d=(u*s+h*a)/l,c=e+d*s,f=o+d*a;return{dist:Math.sqrt((n-c)**2+(t-f)**2),t:d}}function Jr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((be(n.start,s.start)<=e||be(n.start,s.end)<=e)&&o++,(be(n.end,s.start)<=e||be(n.end,s.end)<=e)&&i++);let r=0;return o>=1&&i>=1?r=5:(o>=1||i>=1)&&(r=2),{left:o,right:i,score:r}}function ti(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Gn(a.x,a.y,o.x,o.y,i.x,i.y);e.push(l)}const r=e.reduce((a,l)=>a+l,0)/e.length,s=e.reduce((a,l)=>a+(l-r)**2,0)/e.length;return s<.01?3:s<.05?2:s<.1?1:0}function ei(n,t,e=.15){const o=n.end.x-n.start.x,i=n.end.y-n.start.y,r=Math.sqrt(o*o+i*i);if(r<1e-12)return 0;const s=-i/r,a=o/r,l=[[],[]];for(let d=0;d<2;d++){const c=d===0?n.start:n.end;for(const f of t){if(f===n)continue;const w=be(c,f.start),x=be(c,f.end);let b=null;if(w<=e?b=f.end:x<=e&&(b=f.start),!b)continue;const M=f.end.x-f.start.x,g=f.end.y-f.start.y,m=Math.sqrt(M*M+g*g);if(m<1e-12||Math.abs(o*M+i*g)/(r*m)>=.342)continue;const P=(b.x-c.x)*s+(b.y-c.y)*a;l[d].push(P>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const u=[...l[0],...l[1]];return u.every(d=>d===u[0])?2:1}function ni(n,t,e){const o=Jr(n,e),i=ti(n,t),r=ei(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function oi(n){const t=n.end.x-n.start.x,e=n.end.y-n.start.y;let o=Math.atan2(e,t)*(180/Math.PI);return o<0&&(o+=180),o}function ri(n,t){const e=[];for(const o of n){let i=!1;for(const r of e){const s=Math.abs(o.angle-r[0].angle);if(Math.min(s,180-s)<=t){r.push(o),i=!0;break}}i||e.push([o])}return e}function ii(n,t=.05){const e=[];for(const o of n){let i=!1;for(const r of e)if(Math.abs(o.offset-r[0].offset)<=t){r.push(o),i=!0;break}i||e.push([o])}return e}function si(n,t,e,o,i){const r=[];for(const a of n){const l=a.seg,u=(l.start.x-t.start.x)*e+(l.start.y-t.start.y)*o,h=(l.end.x-t.start.x)*e+(l.end.y-t.start.y)*o;r.push({l:Math.min(u,h),r:Math.max(u,h),idx:a.idx})}r.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:u}of r){if(s.length===0){s.push({l:a,r:l,srcIdxs:[u]});continue}const h=s[s.length-1];a<=h.r+i?(h.r=Math.max(h.r,l),h.srcIdxs.includes(u)||h.srcIdxs.push(u)):s.push({l:a,r:l,srcIdxs:[u]})}return s}function ai(n,t,e,o,i,r,s){const a=e-t,l={...n};return l.start={x:n.start.x+t*o,y:n.start.y+t*i,z:n.start.z},l.end={x:n.start.x+e*o,y:n.start.y+e*i,z:n.start.z},l.length=a,l.direction={x:o,y:i,z:0},l.rooftopPz=r,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function li(n,t){let e=!0;for(;e;){e=!1;for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o],s=n[i];if(r.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(r.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(r.end.x-s.start.x)<.001&&Math.abs(r.end.y-s.start.y)<.001,l=Math.abs(r.start.x-s.end.x)<.001&&Math.abs(r.start.y-s.end.y)<.001,u=Math.abs(r.end.x-s.end.x)<.001&&Math.abs(r.end.y-s.end.y)<.001,h=Math.abs(r.start.x-s.start.x)<.001&&Math.abs(r.start.y-s.start.y)<.001;if(!(a||l||u||h)||r.direction.x*s.direction.x+r.direction.y*s.direction.y<.98)continue;let c=r.start,f=r.end;a?f=s.end:l?c=s.start:u?f=s.start:h&&(c=s.end);const w=Math.hypot(f.x-c.x,f.y-c.y),x={...r};x.start=c,x.end=f,x.length=w,x.direction={x:(f.x-c.x)/w,y:(f.y-c.y)/w,z:0},r.rooftopPz!==void 0&&s.rooftopPz!==void 0?x.rooftopPz=Math.max(r.rooftopPz,s.rooftopPz):x.rooftopPz=r.rooftopPz!==void 0?r.rooftopPz:s.rooftopPz,x.buildRosource=r.buildRosource||s.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),n[o]=x,t[o]=[...new Set([...t[o],...t[i]])],n.splice(i,1),t.splice(i,1),i--,e=!0}}return{segments:n,sourceMap:t}}function Je(n,t=5,e=.05){if(n.length<=1)return{segments:n,sourceMap:n.map((l,u)=>[u])};const o=n.map((l,u)=>({seg:l,angle:oi(l),idx:u}));o.sort((l,u)=>l.angle-u.angle);const i=ri(o,t),r=[],s=[],a=[];for(const l of i){let u=l[0].seg;for(const M of l)M.seg.length>u.length&&(u=M.seg);const h=u.end.x-u.start.x,d=u.end.y-u.start.y,c=Math.sqrt(h*h+d*d);if(c<1e-12)continue;const f=-d/c,w=h/c,x=l.map(M=>{const g=M.seg.start.x-u.start.x,m=M.seg.start.y-u.start.y;return{seg:M.seg,offset:Math.abs(g*f+m*w),idx:M.idx}});x.sort((M,g)=>M.offset-g.offset);const b=ii(x);for(const M of b){let g=M[0].seg;for(const E of M)E.seg.length>g.length&&(g=E.seg);const m=g.end.x-g.start.x,p=g.end.y-g.start.y,P=Math.sqrt(m*m+p*p);if(P<1e-12)continue;const V=m/P,v=p/P,S=M.map(E=>E.seg.rooftopPz??0),z=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 _=si(M,g,V,v,e);for(const{l:E,r:T,srcIdxs:A}of _){if(T-E<.01)continue;const O=ai(g,E,T,V,v,z,g.buildRosource);r.push(O),s.push(A)}}}return{...li(r,s),debugRPZGroups:a}}function ci(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function ui(n,t,e){return[{x:t,y:e,z:0},{x:n[0].x,y:n[0].y,z:0},{x:n[1].x,y:n[1].y,z:0},{x:n[2].x,y:n[2].y,z:0},{x:n[3].x,y:n[3].y,z:0}]}function hi(n,t,e,o,i,r,s){const a=[{margin:r.projectionMargin,maxDist:r.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const u of a){if(l.length>0)break;for(const h of n){const d=t*r.minLengthRatio;if(h.length<d)continue;const{start:c,end:f}=h;let w=!1,x=1/0;for(const S of i){const{dist:z,t:D}=Gn(S.x,S.y,c.x,c.y,f.x,f.y);D>=-u.margin&&D<=1+u.margin&&z<=u.maxDist&&(w=!0,x=Math.min(x,z))}if(!w){`${u.maxDist}${(-u.margin).toFixed(1)}${(1+u.margin).toFixed(1)}`;continue}const b=Math.sqrt((f.x-c.x)**2+(f.y-c.y)**2);if(b<1e-12)continue;const M=(f.x-c.x)/b,g=(f.y-c.y)/b,m=Math.abs(e*M+o*g),p=Math.abs(-o*M+e*g),P=Math.max(m,p),V=Math.acos(Math.min(P,1))*(180/Math.PI);if(V>r.angleThreshold){`${V.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(b>.01){const S=[];for(let _=1;_<=4;_++){const E=i[_],T=E.x-c.x,A=E.y-c.y,O=(T*M+A*g)/b;S.push(O)}const z=Math.min(...S),D=Math.max(...S);D>z&&(v=Math.max(0,Math.min(1,D)-Math.max(0,z))/(D-z))}l.push({seg:h,minDist:x,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function fi(n,t,e,o){if(n.length<=1)return n.length===1&&(n[0].score=-1),n;for(const i of n){const{score:r,details:s}=ni(i.seg,t,e);i.score=r,i.details=s}return n.sort((i,r)=>r.embedRatio-i.embedRatio||r.score-i.score||i.minDist-r.minDist),n}function di(n,t,e,o){const i=n.end.x-n.start.x,r=n.end.y-n.start.y,s=Math.sqrt(i*i+r*r),a=i/s,l=r/s,u=t.map(v=>{const S=v.x-n.start.x,z=v.y-n.start.y;return(S*a+z*l)/s}),h=Math.min(...u),d=Math.max(...u),c=(d-h)*s,f=(h+d)/2,w=n.start.x+f*i,x=n.start.y+f*r,b=e.box.min.z,M=e.box.max.z,g=Math.abs(M-b),m=Qe(o,n.start.x,n.start.y),p=Math.max(0,b-m),P=h<=0&&d>=1,V=n.start.z+f*(n.end.z-n.start.z);return{p:{x:w,y:x,z:V},width:c,full:P,height:g,groundClearance:p}}function jn(n,t,e){var d,c,f,w,x;const o=t.map(b=>e[b]),i=[],r=[],s=[],a=[],l=[];let u,h;for(const b of o){if((d=b.points)!=null&&d.length)for(const M of b.points)i.push(M);if((c=b.originalPoints)!=null&&c.length)for(const M of b.originalPoints)r.push(M);if((f=b.doorAndBeamData)!=null&&f.length)for(const M of b.doorAndBeamData)s.push(M);if((w=b.insetionArr)!=null&&w.length)for(const M of b.insetionArr)a.push(M);if((x=b.drawWindow)!=null&&x.length)for(const M of b.drawWindow)l.push(M);b.boxData&&!u&&(u=b.boxData),b.rooftopPz!==void 0&&(h===void 0||b.rooftopPz>h)&&(h=b.rooftopPz)}i.length&&(n.points=i),r.length&&(n.originalPoints=r),s.length&&(n.doorAndBeamData=s),a.length&&(n.insetionArr=a),l.length&&(n.drawWindow=l),u&&(n.boxData=u),h!==void 0&&(n.rooftopPz=h)}function Un(n,t,e,o){var u;const i=ci(e),r=[],{segments:s,sourceMap:a}=o??Je(t),l=s;for(const h of n){const d=(u=h.coordinatesByArea)==null?void 0:u.coordinates;if(!d||d.length<4)continue;const c=d.slice(0,4),f=c.reduce((D,_)=>D+_.x,0)/4,w=c.reduce((D,_)=>D+_.y,0)/4,{longSide:x,dirX:b,dirY:M}=Qr(c);if(x<.01)continue;const g=c.reduce((D,_)=>D+_.z,0)/4,m=Qe(t,f,w);if(g<m-.3)continue;const p=ui(c,f,w);h.name;let P=hi(l,x,b,M,p,i,h.name);P=fi(P,p,t,h.name);let V=null,v=1/0,S=0;if(P.length>0){const D=P[0];V=D.seg,v=D.minDist,S=D.ratio}let z;if(V&&(z=di(V,c,h,s),!i.printOnly)){const D=V;D.drawWindow||(D.drawWindow=[]),D.drawWindow.push(z)}V&&r.push({windowName:h.name,windowCategory:h.category,windowCenter:h.center,wallSegment:V,distance:v,wallLengthRatio:S,drawWindow:z})}for(const h of r){const d=h.wallSegment,c=s.indexOf(d);if(c===-1)continue;const f=a[c];!f||f.length<=1||jn(d,f,t)}return r}function mi(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],{segments:r,sourceMap:s}=Je(n),a=Un(i,n,o,{segments:r,sourceMap:s}),l=new Set;for(const c of a){const f=r.indexOf(c.wallSegment);f>=0&&l.add(f)}const u=[],h=new Set;for(const c of l){const f=s[c];if(f){jn(r[c],f,n);for(const w of f)h.add(w)}u.push(r[c])}for(let c=0;c<n.length;c++)h.has(c)||u.push(n[c]);const d=new Set(a.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(d.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of a)c.drawWindow&&c.wallSegment&&(c.wallSegment.drawWindow||(c.wallSegment.drawWindow=[]),c.wallSegment.drawWindow.push(c.drawWindow));return{segments:u,matches:a}}exports.computeContour=je;exports.computeContourNew=Kr;exports.computeLocalFloorZ=Qe;exports.findWindowWalls=Un;exports.getAllGeometry=mo;exports.getBeamLine=Vo;exports.getColLine=zo;exports.getMergeMeaning=Xr;exports.mergeCollinearSegments=Je;exports.processData=mi;exports.updateStEdPoint=go;
1
+ "use strict";var Zn=Object.defineProperty;var Kn=(n,t,e)=>t in n?Zn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Oe=(n,t,e)=>Kn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function Qn(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const y=Qn(lt);function Jn(n,t=!1){const e=n[0].index!==null,o=new Set(Object.keys(n[0].attributes)),i=new Set(Object.keys(n[0].morphAttributes)),r={},s={},a=n[0].morphTargetsRelative,l=new lt.BufferGeometry;let u=0;for(let h=0;h<n.length;++h){const d=n[h];let c=0;if(e!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!o.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;r[f]===void 0&&(r[f]=[]),r[f].push(d.attributes[f]),c++}if(c!==o.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!i.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[f]===void 0&&(s[f]=[]),s[f].push(d.morphAttributes[f])}if(t){let f;if(e)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(u,f,h),u+=f}}if(e){let h=0;const d=[];for(let c=0;c<n.length;++c){const f=n[c].index;for(let w=0;w<f.count;++w)d.push(f.getX(w)+h);h+=n[c].attributes.position.count}l.setIndex(d)}for(const h in r){const d=tn(r[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in s){const d=s[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let c=0;c<d;++c){const f=[];for(let x=0;x<s[h].length;++x)f.push(s[h][x][c]);const w=tn(f);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(w)}}return l}function tn(n){let t,e,o,i=-1,r=0;for(let u=0;u<n.length;++u){const h=n[u];if(t===void 0&&(t=h.array.constructor),t!==h.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=h.itemSize),e!==h.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(o===void 0&&(o=h.normalized),o!==h.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=h.gpuType),i!==h.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=h.count*e}const s=new t(r),a=new lt.BufferAttribute(s,e,o);let l=0;for(let u=0;u<n.length;++u){const h=n[u];if(h.isInterleavedBufferAttribute){const d=l/e;for(let c=0,f=h.count;c<f;c++)for(let w=0;w<e;w++){const x=h.getComponent(c,w);a.setComponent(c+d,w,x)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const to=(n,t,e)=>{let o=new y.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(n),i.push(t);let r=new y.BufferGeometry;r.setFromPoints(i),r.rotateX(-Math.PI/2),e.add(new y.Line(r,o))},te=(n,t,e,o,i=1e-8)=>{const r=t.x-n.x,s=t.y-n.y,a=o.x-e.x,l=o.y-e.y,u=r*l-s*a;if(Math.abs(u)<i)return null;const h=((e.x-n.x)*l-(e.y-n.y)*a)/u,d=((e.x-n.x)*s-(e.y-n.y)*r)/u;return h<-i||h>1+i||d<-i||d>1+i?null:{point:new y.Vector3(n.x+h*r,n.y+h*s,n.z)}},eo=(n,t,e={})=>{const{fontSize:o=36,fontFamily:i="sans-serif",backgroundColor:r="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=e,h=document.createElement("canvas").getContext("2d");h.font=`bold ${o}px ${i}`;const c=h.measureText(n).width;let f=Math.min(c+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=f,x.height=w;const b=x.getContext("2d");b.fillStyle=r,b.fillRect(0,0,f,w),b.fillStyle=s,b.font=`bold ${o}px ${i}`,b.textAlign="center",b.textBaseline="middle",c>l-a*2?no(b,n,f/2,w/2,l,o):b.fillText(n,f/2,w/2);const M=new y.CanvasTexture(x),g=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),m=new y.Sprite(g);m.position.set(t.x,t.y,t.z);const p=.005;return m.scale.set(f*p,w*p,1),m};function no(n,t,e,o,i,r){const s=t.split("");let a="",l=r*1.2,u=o;for(let h=0;h<s.length;h++){const d=a+s[h];n.measureText(d).width>i&&h>0?(n.fillText(a,e,u),a=s[h],u+=l):a=d}n.fillText(a,e,u)}const oe=(n,t,e=.01)=>{const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(o<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const r={x:n.x/o,y:n.y/o,z:n.z/o},s={x:t.x/i,y:t.y/i,z:t.z/i};let a=r.x*s.x+r.y*s.y+r.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),u=l<=e;return{parallel:u,sameDirection:u?a>0:null,angle:l}},oo=(n,t,e,o)=>{const i=n;let r=[];if(o&&o.length&&(r=o.map(V=>V.clone())),!i||i.length<4)return{};const s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let u=1/0,h=-1/0,d=1/0,c=-1/0;for(const V of i){const v=V.dot(s),S=V.dot(a);v<u&&(u=v),v>h&&(h=v),S<d&&(d=S),S>c&&(c=S)}const f=i[0].dot(l),w=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(f)),b=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(f)),M=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(f));let g=[w,x,b,M],m=oe(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));m&&m.parallel&&(g=[w,M,b,x]);let p=0;if(o.length>0){const V=new y.Vector3().subVectors(g[1],g[0]).normalize(),v=V.clone().negate(),S=new y.Vector3().subVectors(g[3],g[0]).normalize(),z=S.clone().negate();let D=g[0].distanceTo(g[1]),_=g[0].distanceTo(g[3]),E=D/t,T=_/e,A=.001;for(let O=0;O<E;O++){let I=g[0],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(V,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[0]=g[0].addScaledVector(V,t),g[3]=g[3].addScaledVector(V,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<E;O++){let I=g[1],B=0;for(let L=0;L<T;L++){let N=I.clone().addScaledVector(v,t),C=N.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=R}if(B>=T/2)break;p+=B,g[1]=g[1].addScaledVector(v,t),g[2]=g[2].addScaledVector(v,t)}D=g[0].distanceTo(g[1]),E=D/t;for(let O=0;O<T;O++){let I=g[3],B=0;for(let L=0;L<E;L++){let N=I.clone().addScaledVector(V,t),C=N.clone().addScaledVector(z,e),R=I.clone().addScaledVector(z,e),$=new y.Vector3().add(I).add(N).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo($)<A){B++;break}I=N}if(B>=E/2)break;p+=B,g[2]=g[2].addScaledVector(z,e),g[3]=g[3].addScaledVector(z,e)}}const P=g[0].distanceTo(g[1])*g[0].distanceTo(g[3]);return{facePoints:g,boxArea:P,totalInPlaneNum:p}},Jt=(n,t,e,o,i=y.MathUtils.degToRad(8))=>{const r=new y.Vector3,s=new y.Vector3;r.subVectors(new y.Vector3(t.x,t.y,0),new y.Vector3(n.x,n.y,0)).normalize(),s.subVectors(new y.Vector3(o.x,o.y,0),new y.Vector3(e.x,e.y,0)).normalize();const a=r.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),u=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:u,angle:l,angleDeg:y.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},re=(n,t,e,o)=>{const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=i.length(),a=r.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),r.normalize();const l=Math.abs(i.dot(r)),u=Math.min(1,Math.max(0,l)),h=Math.acos(u),d=y.MathUtils.radToDeg(h),c=1-u;return{rate:c,percent:`${(c*100).toFixed(2)}%`,angle:d,isPerpendicular:Math.abs(d-90)<.01,isParallel:d<.01}},ee=(n,t,e=!1)=>new y.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),ne=(n,t,e,o,i={})=>{const{parallelAngleMax:r=y.MathUtils.degToRad(10),collinearAngleMax:s=y.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,u=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),d=u.clone().normalize(),c=h.clone().normalize();let f=y.MathUtils.clamp(d.dot(c),-1,1);const w=Math.acos(Math.abs(f)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};f<0&&c.negate();const b=new y.Vector3().addVectors(d,c).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),g=en(e,M,d),m=en(o,M,d),p=(g+m)/2,P=Math.max(g,m),V=n.dot(b),v=t.dot(b),S=e.dot(b),z=o.dot(b),D=Math.min(V,v),_=Math.max(V,v),E=Math.min(S,z),T=Math.max(S,z),A=_-D,O=T-E,I=Math.min(A,O),B=Math.min(_,T)-Math.max(D,E),L=B<0?-B:0,N=B>0?B:0,C=I>0?N/I:0,R=ro(n,t,e,o),$=w<=s&&p<a;let X;return $?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:x,avgPerpendicularDistance:p,maxPerpendicularDistance:P,gap:L,overlap:N,closestDistance:R}};function en(n,t,e){const o=new y.Vector3().subVectors(n,t),i=o.dot(e),r=e.clone().multiplyScalar(i);return new y.Vector3().subVectors(o,r).length()}function ro(n,t,e,o){const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=new y.Vector3().subVectors(e,n),a=i.dot(i),l=i.dot(r),u=r.dot(r),h=i.dot(s),d=r.dot(s),c=a*u-l*l;let f,w;c<1e-10?(f=0,w=u!==0?d/u:0):(f=(l*d-u*h)/c,w=(a*d-l*h)/c),f=y.MathUtils.clamp(f,0,1),w=u!==0?y.MathUtils.clamp((l*f+d)/u,0,1):0,f=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(f)),b=e.clone().add(r.clone().multiplyScalar(w));return x.distanceTo(b)}const nn=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),io=n=>{let t=new y.Vector3(n.start.x,n.start.y,n.start.z),e=new y.Vector3(n.end.x,n.end.y,n.end.z),o=t.distanceTo(e),i=n.rooftopPz-n.start.z,r=nn(o,100),s=nn(i,70),a=i/s,l=new Map;for(let x=0;x<s;x++)l.set((x+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let u=new y.Line3(t,e);const h=n.originalPoints,d=new y.Vector3;for(let x=0;x<h.length;x++){const b=h[x];let g=u.closestPointToPoint(b,!0,d).distanceTo(b);const m=Math.floor(g/a);if(m<s){const p=l.get((m+1)*a);p.count++,b.z<p.minZ&&(p.minZ=b.z),b.z>p.maxZ&&(p.maxZ=b.z)}}let c,f,w=r/2;for(const[x,b]of l)if(b.count>=w){c=b.minZ;break}for(const[x,b]of[...l.entries()].reverse())if(b.count>=w){f=b.maxZ;break}return{minZ:c,maxZ:f}},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(b=>{const M=new y.Vector3;o.projectPoint(b,M),l.push(M.clone()),M.z=i.z,a.push(M)});let u=new y.Vector3,h=new y.Vector3;o.projectPoint(i,u),o.projectPoint(r,h);const d=new y.Line3(u,h),c=[],f=[],w=[];let x=new y.Vector3;return a.forEach((b,M)=>{d.closestPointToPoint(b,!0,x).distanceTo(b)<.001?(c.push(e[M]),f.push(l[M])):w.push(b)}),{newOriginalPoints:c,newProjectPoints:w,newOnLinePoints:f}},so=n=>{function t(e,o,i,r,s,a,l,u,h){let d=new y.Line3(e,o),c=new Map,f=new y.Vector3,w=e.clone(),x=o.clone(),b=0;for(;;){let M=new Map,g=0;for(let m=0;m<h.checkResults.length;m++)if(!(h.checkResults[m].allCenterPoints.length/u*100<1))for(let P=0;P<h.checkResults[m].allCenterPoints.length;P++){if(c.has(m)&&c.get(m).removePtsIndex.includes(P))continue;let V=h.checkResults[m].allCenterPoints[P];V=new y.Vector3(V.x,V.y,V.z);let v=d.closestPointToPoint(V,!0,f),S=V.distanceTo(v);Math.abs(S-s)<.01&&(g++,M.has(m)?M.get(m).removePtsIndex.push(P):M.set(m,{index:m,removePtsIndex:[P]}))}if(b==l){e=w,o=x;break}if(g<a/20*18||g==0){M.clear(),l-b<5&&(e=w,o=x,c.clear());break}else{b++;for(const[m,p]of M)c.has(m)?c.get(m).removePtsIndex.push(...p.removePtsIndex):c.set(m,p);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),d.set(e,o)}}if(c.size>0&&b!=l)for(const[M,g]of c){let m=[],p=[];for(let P=0;P<h.checkResults[M].allCenterPoints.length;P++)g.removePtsIndex.includes(P)||(m.push(h.checkResults[M].allCenterPoints[P]),p.push(h.checkResults[M].originalVertices[P]));h.checkResults[M].allCenterPoints=m,h.checkResults[M].originalVertices=p}}for(let e=0;e<n.length;e++){const o=n[e];if(o.length<.5)continue;let i=-1,r=-1;if(!o.checkResults||o.checkResults.length<=0)continue;if(o.checkResults[0].originalVertices&&o.checkResults[0].originalVertices.length>0){const S=o.checkResults[0].originalVertices[0];let[z,D,_,E]=S;z=new y.Vector3(z.x,z.y,z.z),D=new y.Vector3(D.x,D.y,D.z),_=new y.Vector3(_.x,_.y,_.z),E=new y.Vector3(E.x,E.y,E.z),i=z.distanceTo(D),r=z.distanceTo(E);let T=new y.Vector3().subVectors(z,D).normalize(),A=oe(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),u=o.rooftopPz-o.start.z,h=Math.ceil(l/i),d=Math.ceil(u/r);let c=s.clone(),f=a.clone(),w=f.clone().add(new y.Vector3(0,0,u)),x=c.clone().add(new y.Vector3(0,0,u)),b=new y.Vector3().subVectors(f,c).normalize(),M=b.clone().negate();new y.Vector3().subVectors(w,c).normalize().clone().negate();let m=i/2,p=l*u,P=i*r,V=p/P;t(c,x,b,i,m,d,h,V,o),t(f,w,M,i,m,d,h,V,o),o.start=c,o.end=f;const{newOriginalPoints:v}=Ve(c,f,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 b=0;b<l.length;b++)this.isValidVector3(l[b])||(console.error(`点${b+1}包含无效数据:`,l[b]),l[b]=new y.Vector3(b,0,b));const u=new y.BufferGeometry,h=new Float32Array([l[0].x,l[0].y,l[0].z,l[1].x,l[1].y,l[1].z,l[2].x,l[2].y,l[2].z,l[3].x,l[3].y,l[3].z]),d=[0,1,2,0,2,3],c=new Float32Array([0,0,1,0,1,1,0,1]);u.setAttribute("position",new y.BufferAttribute(h,3)),u.setAttribute("uv",new y.BufferAttribute(c,2)),u.setIndex(d),u.computeVertexNormals();const f=new y.Mesh(u,r),w=new y.EdgesGeometry(u),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),f}createSubdividedWallPlane(t,e,o,i,r){const s=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return s;const a=new y.Vector3(t.start.x,t.start.y,t.start.z),l=new y.Vector3(t.end.x,t.end.y,t.end.z),u=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),d=[a,l,u,h];for(let g=0;g<d.length;g++)if(!this.isValidVector3(d[g]))return console.error(`墙体基础点${g}无效:`,d[g]),s;const c=a.distanceTo(l),f=Math.abs(t.rooftopPz-t.start.z);if(c===0||f===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",l),console.log(t.length),s;const w=c/o,x=f/e,b=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let g=0;g<e;g++)for(let m=0;m<o;m++)try{const p=new y.Vector3().copy(a).add(b.clone().multiplyScalar(m*w)).add(M.clone().multiplyScalar(g*x)),P=new y.Vector3().copy(a).add(b.clone().multiplyScalar((m+1)*w)).add(M.clone().multiplyScalar(g*x)),V=new y.Vector3().copy(a).add(b.clone().multiplyScalar((m+1)*w)).add(M.clone().multiplyScalar((g+1)*x)),v=new y.Vector3().copy(a).add(b.clone().multiplyScalar(m*w)).add(M.clone().multiplyScalar((g+1)*x)),S={points:[p,P,V,v],userData:{}};S.userData={type:"wallSegment",row:g,col:m,originalMaterial:i,width:w,height:x},s.push(S)}catch(p){console.error(`创建墙体小平面(${g}, ${m})时出错:`,p)}return s}calculateMinRequiredPoints(t){const i=Math.floor(Math.log1p(t)*.5);return Math.max(1,i)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,o,i){if(e===0)return!1;const r=t.area,s=t.minRequiredPoints,a=t.expectedDensity,l=e/Math.max(r,.001),u=e>=s,h=l>=a*.3;let d=!0;return r<.5&&e>0&&(d=this.checkSmallAreaDistribution(t,o,i)),u&&h&&d}checkSmallAreaDistribution(t,e,o){if(e.length<2)return!0;const i=e.map(l=>o[l]);t.bounds;const r=t.center;let s=0;const a=Math.sqrt(t.area)*.3;return i.forEach(l=>{l.distanceTo(r)<=a&&s++}),s/i.length>=.3}getFailureReason(t,e){const o=t.area,i=t.minRequiredPoints,r=t.expectedDensity,s=e/Math.max(o,.001),a=[];return e===0?a.push("无点"):(e<i&&a.push(`点数不足: ${e}/${i}`),s<r*.3&&a.push(`密度不足: ${s.toFixed(2)}/${r.toFixed(2)}`),o<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((i,r)=>i-r),o=Math.floor(e.length/2);return e.length%2!==0?e[o]:(e[o-1]+e[o])/2}isPointInBoundingBox(t,e,o=.1){return t.x>=e.min[0]-o&&t.x<=e.max[0]+o&&t.y>=e.min[1]-o&&t.y<=e.max[1]+o&&t.z>=e.min[2]-o&&t.z<=e.max[2]+o}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const o=e.attributes.position;if(o.count<3)return null;const i=new y.Vector3().fromBufferAttribute(o,0),r=new y.Vector3().fromBufferAttribute(o,1),s=new y.Vector3().fromBufferAttribute(o,2);i.applyMatrix4(t.matrixWorld),r.applyMatrix4(t.matrixWorld),s.applyMatrix4(t.matrixWorld);const a=new y.Plane;return a.setFromCoplanarPoints(i,r,s),a}analyzePointDistribution(t,e,o=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};const i=performance.now(),r=[];t.forEach(s=>{if(s.userData&&s.userData.type==="wallSegment"){const a=this.getWorldVerticesNew(s.points);if(a.length<4)return;const l=new y.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);s.userData.center=l,s.vertices=a,r.push(s)}}),this.results.totalSegments=r.length;for(const s of r){if(s.vertices.length<4)continue;const a=s.userData.center,l=`row${s.userData.row}_col${s.userData.col}`,[u,h,d,c]=s.vertices,f=new y.Vector3().subVectors(h,u).normalize(),w=new y.Vector3().subVectors(c,u).normalize(),x=u.distanceTo(h),b=u.distanceTo(c),M=new y.Plane;M.setFromCoplanarPoints(u,h,c);const g=x/2,m=b/2;for(let p=0;p<e.length;p++)this.isPointInWallSegmentOptimized(e[p],a,M,u,f,w,x,b,g,m,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(p))}return r.forEach(s=>{const a=`row${s.userData.row}_col${s.userData.col}`,l=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;l>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:s.userData.row,col:s.userData.col,width:s.userData.width,height:s.userData.height,segmentKey:a,vertices:s.vertices,center:s.userData.center,mesh:s,pointCount:l,hasPointsButNotEnough:l>0&&l<1}))}),this.results.analysisTime=performance.now()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,o,i,r,s,a,l,u,h,d){if(Math.abs(o.distanceToPoint(t))>d)return!1;const f=new y.Vector3().subVectors(t,e),w=Math.abs(f.dot(r)),x=Math.abs(f.dot(s));if(w>u&&x>h)return!1;const b=new y.Vector3().subVectors(t,i),M=b.dot(r),g=b.dot(s),m=M>=-d&&M<=a+d,p=g>=-d&&g<=l+d;return m&&p}isPointInWallSegment(t,e,o,i=.1){if(!t.geometry)return!1;try{const r=this.getWorldVertices(t);return r.length<4?!1:this.isPointInRotatedWall(r,e,o,i)}catch(r){return console.error("判断点是否在墙体平面内时出错:",r),!1}}isPointInRotatedWall(t,e,o,i=.1){const[r,s,a,l]=t,u=new y.Plane;if(u.setFromCoplanarPoints(r,s,l),Math.abs(u.distanceToPoint(e))>i)return!1;const d=new y.Vector3().subVectors(s,r).normalize(),c=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(d,c).normalize();const f=new y.Vector3().subVectors(e,r),w=f.dot(d),x=f.dot(c),b=r.distanceTo(s),M=r.distanceTo(l),g=w>=-i&&w<=b+i,m=x>=-i&&x<=M+i;return g&&m&&o.distanceTo(e)<b/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 d;if(!this.results){console.warn("请先运行分析函数");return}const r=new Map,s=new Map;this.results.missingSegments.forEach(c=>{r.set(c.segmentKey,c),s.has(c.row)||s.set(c.row,new Map),s.get(c.row).set(c.col,{segmentKey:c.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(c=>{if(c.userData&&c.userData.type==="wallSegment"){const f=`row${c.userData.row}_col${c.userData.col}`,w=r.has(f);s.has(c.userData.row)||s.set(c.userData.row,new Map),s.get(c.userData.row).has(c.userData.col)||s.get(c.userData.row).set(c.userData.col,{segmentKey:f,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[c,f]of r){const w=(d=s.get(f.row))==null?void 0:d.get(f.col);if(w&&!w.visited){const x=[],b=[[f.row,f.col]];for(w.visited=!0;b.length>0;){const[M,g]=b.shift(),m=`row${M}_col${g}`;r.has(m)&&x.push(r.get(m));for(const[p,P]of l){const V=M+p,v=g+P;if(s.has(V)&&s.get(V).has(v)){const S=s.get(V).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,b.push([V,v]))}}}x.length>=i&&a.push(x)}}const u=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((c,f)=>f.length-c.length),highlightedMeshes:h,clusterMaterials:u,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,o,i,r){let s=0;const a=e;let l=!0;for(let x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const u=o;let h=!0;for(let x=i;x<=r;x++)t.has(u)&&t.get(u).has(x)||(h=!1);h&&s++;const d=i;let c=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(d)||(c=!1);c&&s++;const f=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(f)||(w=!1);return w&&s++,s/4}calculateClusterQualityScore(t){const r=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+r*.2}calculateStrictClusterBounds(t){var d,c;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(f=>{f.vertices&&f.vertices.length>0&&e.push(...f.vertices)}),e.length===0){const f=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((d=t[0].bounds)==null?void 0:d.width)||1),height:f.length*(((c=t[0].bounds)==null?void 0:c.height)||1)}}const o=Math.min(...e.map(f=>f.x)),i=Math.max(...e.map(f=>f.x)),r=Math.min(...e.map(f=>f.y)),s=Math.max(...e.map(f=>f.y)),a=Math.min(...e.map(f=>f.z)),l=Math.max(...e.map(f=>f.z)),u=Math.abs(i-o),h=Math.max(Math.abs(s-r),Math.abs(l-a));return{width:u,height:h}}createClusterMaterials(t){const e=[],o=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let i=0;i<t;i++){const r=o[i%o.length],s=new y.MeshBasicMaterial({color:r,transparent:!0,opacity:.6,side:y.DoubleSide});e.push(s)}return e}clearHighlights(t){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(e=>{t.remove(e),e.material&&e.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,o)=>{e.mesh&&e.mesh.userData.originalMaterial&&(e.mesh.material=e.mesh.userData.originalMaterial)}),this.clusterResults.highlightedMeshes=[])}getClusterInfo(){return this.clusterResults?{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((t,e)=>({clusterIndex:e,size:t.length,segments:t.map(o=>o.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(t=>t.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(t=>t.length))}:null}restoreOriginalMaterials(t){let e=0;t.traverse(o=>{o.userData&&o.userData.originalMaterial&&(o.material=o.userData.originalMaterial,delete o.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new y.Group;return t.traverse(o=>{if(o.userData&&o.userData.type==="wallSegment"){const i=this.getWorldVertices(o);if(i.length<4)return;const r=new y.Vector3().add(i[0]).add(i[1]).add(i[2]).add(i[3]).multiplyScalar(.25),s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=new y.Vector3().crossVectors(s,a).normalize(),u=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),d=new y.ArrowHelper(a,r,.2,255);e.add(u),e.add(h),e.add(d)}}),e}printAnalysisResults(){if(!this.results){console.warn("没有可用的分析结果");return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(t=>{}),this.results.pointsInSegments.forEach((t,e)=>{})}isValidVector3(t){return t&&!isNaN(t.x)&&!isNaN(t.y)&&!isNaN(t.z)&&isFinite(t.x)&&isFinite(t.y)&&isFinite(t.z)}mergeWallGroupMeshes(t){const e=[];if(t.traverse(o=>{o.isMesh&&o.geometry&&e.push(o)}),e.length===0)return null;try{const o=e.map(a=>a.geometry);o.forEach((a,l)=>{a.applyMatrix4(e[l].matrixWorld)});const i=Jn(o),r=e[0].material.clone(),s=new y.Mesh(i,r);return s.name="mergedWalls",s}catch(o){return console.error("合并网格时出错:",o),null}}}const ho=n=>{let t={};const e=[],o=[],i=[];return n[0].width,n[0].height,n.forEach(r=>{o.push(...r.vertices),i.push(r.center),e.push(r.vertices)}),t.originalVertices=e,t.allCenterPoints=i,t},fo=n=>{const t=new lt.Vector3().copy(n.start).add(n.end).multiplyScalar(.5),e=new lt.Vector3().subVectors(new lt.Vector3(t.x,t.y,t.z+1),t).normalize(),o=new lt.Vector3(n.direction.x,n.direction.y,0);o.applyAxisAngle(e,Math.PI/2);const i=new lt.Vector3().copy(t).add(o.clone().multiplyScalar(n.length)),r=new lt.Vector3().copy(t).sub(o.clone().multiplyScalar(n.length));return t.z=n.start.z,i.z=n.start.z,r.z=n.start.z,{start:i,end:r,center:t,direction:o}},mo=(n,t,e=!0)=>{let o=[];if(!n)return[];for(let i=0;i<n.length;i++){const r=n[i];if(!r)continue;let s=new y.Vector3(r.start.x,r.start.y,r.start.z);s.applyEuler(new y.Euler(-Math.PI/2,0,0));let a=new y.Vector3(r.end.x,r.end.y,r.end.z);if(a.applyEuler(new y.Euler(-Math.PI/2,0,0)),t.add(eo(String(i),new y.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(r.isBayWindow||r.isWindow)&&e)continue;const l=new lt.Plane().setFromCoplanarPoints(new lt.Vector3(r.start.x,r.start.y,r.start.z),new lt.Vector3(r.end.x,r.end.y,r.end.z),new lt.Vector3(r.start.x,r.start.y,r.rooftopPz)),u=[];r.originalPoints.forEach((v,S)=>{const z=new lt.Vector3;l.projectPoint(v,z),u.push(z)});const h=new lt.Vector3(r.start.x,r.start.y,r.start.z).distanceTo(new lt.Vector3(r.end.x,r.end.y,r.end.z)),d=Math.abs(r.rooftopPz-r.start.z),c=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),f=new y.Group,w=new uo,{horizontalSubdivisions:x,verticalSubdivisions:b}=w.initLimits4(h,d),M=w.createSubdividedWallPlane(r,b,x,c,f);w.analyzePointDistribution(M,u,.01);const g=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),m=w.highlightEmptySegments(M,g,f),p=[];for(const v of m.clusters){const S=ho(v);S&&p.push(S)}const V=fo(r).direction;r.checkResults=p,r.verticalDirection=V,r.originaIndex=i,o.push(r)}return o},go=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(m=>{let p=new y.Vector3(m.x,m.y,0),P=!1;for(let V=0;V<i.length;V++)if(kt(p,i[V],.01)){P=!0;break}P||i.push(p)});const r=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),s=1;let a=new y.Vector3(o.start.x,o.start.y,o.start.z),l=new y.Vector3(o.end.x,o.end.y,o.end.z),u=new y.Vector3().subVectors(l,a).normalize(),h=u.clone().cross(new y.Vector3(0,0,1)).normalize(),d=h.clone().negate(),c=[];const f=[];let w=o.length/r;console.log(w);for(let m=0;m<r;m++){const p=[];p.push(a.clone().addScaledVector(h,s)),p.push(p[0].clone().addScaledVector(u,w)),p.push(p[1].clone().addScaledVector(d,s*2)),p.push(a.clone().addScaledVector(d,w));let P=[];for(let V=0;V<i.length;V++)c.includes(V)||yo(i[V],p)&&(c.push(V),P.push(i[V]));P.length>0&&f.push(xo(P)),a=a.addScaledVector(u,w)}const x=new Float32Array(i.length*3);i.forEach((m,p)=>{x[p*3]=m.x,x[p*3+1]=m.y,x[p*3+2]=m.z});const b=new y.BufferGeometry;b.setAttribute("position",new y.BufferAttribute(x,3)),b.rotateX(-Math.PI/2),t.add(new y.Points(b,new y.PointsMaterial({color:lo(),size:.02})));const[M,g]=Mo(f,{plane:"xy",trimRatio:0});to(M,g,t)}};function on(n,t="xy"){if(t==="xy")return{x:n.x,y:n.y};if(t==="xz")return{x:n.x,y:n.z};if(t==="yz")return{x:n.y,y:n.z};throw new Error(`Unsupported plane: ${t}`)}function po(n,t,e){const o=t.x-n.x,i=t.y-n.y,r=e.x-n.x,s=e.y-n.y;return o*s-i*r}function yo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=on(n,e),i=t.map(a=>on(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],u=i[(a+1)%4],h=po(l,u,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function xo(n){if(!n||n.length===0)return null;const t=new y.Vector3(0,0,0);for(const e of n)Array.isArray(e)?(t.x+=e[0],t.y+=e[1],t.z+=e[2]):(t.x+=e.x,t.y+=e.y,t.z+=e.z);return t.divideScalar(n.length),t}function wo(n){return n instanceof y.Vector3?n.clone():Array.isArray(n)?new y.Vector3(n[0],n[1],n[2]):new y.Vector3(n.x,n.y,n.z)}function bo(n,t="xy"){const e=wo(n);if(t==="xy")return{x:e.x,y:e.y,up:e.z};if(t==="xz")return{x:e.x,y:e.z,up:e.y};if(t==="yz")return{x:e.y,y:e.z,up:e.x};throw new Error(`Unsupported plane: ${t}`)}function rn(n,t,e,o="xy"){if(o==="xy")return new y.Vector3(n,t,e);if(o==="xz")return new y.Vector3(n,e,t);if(o==="yz")return new y.Vector3(e,n,t);throw new Error(`Unsupported plane: ${o}`)}function Po(n,t,e){if(Math.abs(t)<1e-12)return n>=e?{x:1,y:0}:{x:0,y:1};const i=n+e,r=n*e-t*t,s=Math.sqrt(Math.max(0,i*i*.25-r)),a=i*.5+s;let l=t,u=a-n;const h=Math.hypot(l,u);return h<1e-12?{x:1,y:0}:{x:l/h,y:u/h}}function Mo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>bo(B,e));let r=0,s=0,a=0;for(const B of i)r+=B.x,s+=B.y,a+=B.up;r/=i.length,s/=i.length,a/=i.length;let l=0,u=0,h=0;for(const B of i){const L=B.x-r,N=B.y-s;l+=L*L,u+=L*N,h+=N*N}l/=i.length,u/=i.length,h/=i.length;const d=Po(l,u,h),c={x:-d.y,y:d.x},f=[];for(const B of i){const L=B.x-r,N=B.y-s,C=L*d.x+N*d.y,R=L*c.x+N*c.y;f.push({s:C,t:R,up:B.up})}f.sort((B,L)=>B.s-L.s);const w=f.length;let x=Math.floor(w*o),b=Math.ceil(w*(1-o))-1;x=Math.max(0,Math.min(w-1,x)),b=Math.max(0,Math.min(w-1,b));const M=f[x],g=f[b],m=(()=>{const B=f.map(N=>N.t).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),p=(()=>{const B=f.map(N=>N.up).sort((N,C)=>N-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),P=M.s,V=g.s,v=m,S=m,z=p,D=p,_=r+d.x*P+c.x*v,E=s+d.y*P+c.y*v,T=r+d.x*V+c.x*S,A=s+d.y*V+c.y*S,O=rn(_,E,z,e),I=rn(T,A,D,e);return[O,I]}const Vo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let m=0;m<o.length;m++){const p=o[m];p.isLine2=!0,n.push(p)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const m of n){let p=[];if(!(!m.checkResults||m.checkResults.length<=0)){for(let P=0;P<m.checkResults.length;P++){let D=function(A){for(;z[A]!==A;)z[A]=z[z[A]],A=z[A];return A};const V=m.checkResults[P];if(V.isDoor=!1,!V.originalVertices||V.originalVertices.length==0)continue;const v=[];V.originalVertices.forEach(A=>{let O=[];A.forEach(I=>{O.push(new y.Vector3(I.x,I.y,I.z))}),v.push(O)});const S=v.length,z=Array.from({length:S},(A,O)=>O);for(let A=0;A<S;A++)for(let O=A+1;O<S;O++){const I=v[A],B=v[O];if(I.some(N=>B.some(C=>N.equals(C)))){const N=D(A),C=D(O);N!==C&&(z[N]=C)}}const _=new Map;let E=-1,T=-1;for(let A=0;A<S;A++){const O=D(A);_.has(O)||_.set(O,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const I=_.get(O);let[B,L,N,C]=v[A];const R=new y.Vector3().add(B).add(L).add(N).add(C).multiplyScalar(.25);if(I.points.push(...v[A]),I.area+=B.distanceTo(L)*B.distanceTo(C),I.originalVertices.push(v[A]),I.index=P,I.centerPts.push(R),E==-1||T==-1){let $=new y.Vector3().subVectors(B,L).normalize();T=B.distanceTo(C),E=B.distanceTo(L);let X=oe($,new y.Vector3(0,0,1));X&&X.parallel&&([T,E]=[E,T])}I.gridWidth=E,I.gridHeight=T}p.push(..._.values())}m.mergeCheckRegion=p}}let r=new Map;for(const m of n){if(m.length<.3)continue;let p=m.rooftopPz-m.start.z,P=Math.floor(m.rooftopPz-m.start.z);r.has(P)?r.set(P,{num:r.get(P).num+1,totalHeight:r.get(P).totalHeight+p}):r.set(P,{num:1,totalHeight:p})}let s=[...r.entries()].reduce((m,p)=>p[1].num>m[1].num?p:m);s[0],s[1].totalHeight/s[1].num;const a=[];for(let m=0;m<e.length;m++){const p=e[m];if(p.isFindBeam=!1,p.category=="door"){let P=[];p.coordinatesByArea.coordinates.forEach(D=>{P.push(new y.Vector3(D.x,D.y,D.z))}),P[0].equals(P[P.length-1])&&P.pop();let V=P[0].distanceTo(P[1]),v=P[0].distanceTo(P[3]);v>V&&([V,v]=[v,V],P=[P[0],P[3],P[2],P[1]]);let S=ee(P[0],P[3],!0),z=ee(P[1],P[2],!0);a.push({doorStartPt:S,doorEndPt:z,boxPoints:P,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:m,isFind:!1,inWall:!1})}}for(let m=0;m<a.length;m++){const p=a[m];for(let P=0;P<n.length;P++){if(n[P].length<.5)continue;let V=[];const v=ee(n[P].start,n[P].end,!0);V.push(v),V.push(ee(v,n[P].start,!0)),V.push(ee(v,n[P].end,!0));let S=!1;const z=p.boxPoints.length;for(let D=0;D<V.length;D++){const _=V[D].x,E=V[D].y;for(let T=0,A=z-1;T<z;A=T++){const O=p.boxPoints[T].x,I=p.boxPoints[T].y,B=p.boxPoints[A].x,L=p.boxPoints[A].y;I>E!=L>E&&_<(B-O)*(E-I)/(L-I)+O&&(S=!S)}if(S)break}if(S){let D=new y.Vector3(n[P].start.x,n[P].start.y,0),_=new y.Vector3(n[P].end.x,n[P].end.y,0),E=p.doorStartPt.distanceTo(p.doorEndPt),T=D.distanceTo(_),A=Jt(p.doorStartPt,p.doorEndPt,D,_);if(Math.abs(T-E)<.5&&A&&A.angleDeg<15){p.doorStartPt=new y.Vector3(n[P].start.x,n[P].start.y,0),p.doorEndPt=new y.Vector3(n[P].end.x,n[P].end.y,0);break}else if(Math.abs(T-E)>1.3&&A&&A.angleDeg<15){let O=ne(p.doorStartPt,p.doorEndPt,D,_,{parallelAngleMax:y.MathUtils.degToRad(15)}),I=p.doorStartPt.distanceTo(D),B=p.doorStartPt.distanceTo(_),L=p.doorEndPt.distanceTo(D),N=p.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||N<.2;if(O&&O.type=="collinear_overlap"&&O.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let R=new y.Line3(D,_),$=R.closestPointToPoint(p.doorStartPt,!0,new y.Vector3),X=R.closestPointToPoint(p.doorEndPt,!0,new y.Vector3),ot=$.distanceTo(p.doorStartPt),K=X.distanceTo(p.doorEndPt);if(ot<.1||K<.1){p.inWall=!0;break}}}}else continue}}let l=0,u=[],h=[],d=[];const c=[];let f=.15;for(let m=0;m<n.length;m++){const p=n[m];if(p.noDetection||(p.doorAndBeamData=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0))continue;p.completePointAreaPercentage=-1;let P=new y.Box3;P.setFromPoints(p.originalPoints);let V=P.max.z;P.min.z;const v=new y.Vector3(p.start.x,p.start.y,p.start.z),S=new y.Vector3(p.end.x,p.end.y,p.end.z);let z=p.rooftopPz-p.start.z,D=0;for(const E of p.mergeCheckRegion){const{facePoints:T,boxArea:A,totalInPlaneNum:O}=oo(E.points,E.gridWidth,E.gridHeight,E.centerPts);if(!T||T.length<=0)continue;T[0].distanceTo(T[1]);let I=T[0].distanceTo(T[3]);const B=E.gridHeight*(I/E.gridHeight/3*2)+E.gridHeight/2;let L=new y.Vector3(T[0].x,T[0].y,T[0].z+B),N=new y.Vector3(T[1].x,T[1].y,T[1].z+B);const C=new y.Line3(L,N),R=[];let $=new y.Vector3;E.points.forEach(rt=>{C.closestPointToPoint(rt,!0,$).distanceTo(rt)<E.gridHeight+.01&&R.push(rt)});let X=[],ot=[];for(;;){let rt=[];for(let F=0;F<R.length;F++)ot.includes(F)||rt.length==0&&(rt.push(R[F]),ot.push(F));for(let F=0;F<R.length;F++)if(!ot.includes(F)){for(let H=0;H<rt.length;H++)if(R[F].distanceTo(rt[H])<E.gridWidth+.01){rt.push(R[F]),ot.push(F),F=-1;break}}if(rt.length==0)break;X.push(rt)}const K=[];for(let rt=0;rt<X.length;rt++){const F={lineSt:new y.Vector3,lineEd:new y.Vector3,facePoints:[]};let H=Se(X[rt]);Array.isArray(H)&&H.length==2&&(F.lineSt=H[0],F.lineEd=H[1],F.facePoints.push(new y.Vector3(H[0].x,H[0].y,T[0].z)),F.facePoints.push(new y.Vector3(H[1].x,H[1].y,T[0].z)),F.facePoints.push(new y.Vector3(H[1].x,H[1].y,T[2].z)),F.facePoints.push(new y.Vector3(H[0].x,H[0].y,T[2].z)),K.push(F))}D+=E.area;let G=0;if(O!=0&&(G=E.gridHeight*E.gridWidth*O),(E.area-G)/A*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const F=K[rt];let H=F.facePoints[0].distanceTo(F.facePoints[1]),Vt=F.facePoints[0].distanceTo(F.facePoints[3]),Zt=H/p.length*100,qt=p.rooftopPz-F.facePoints[2].z;if(Vt<1.5||V<F.facePoints[2].z||qt>z/3*2)continue;let Rt=!1,_t=!1,Et=!1,Ft=[],tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone(),W=F.facePoints[0].clone(),j=F.facePoints[1].clone(),Nt=!1,Tt=-1;if(Math.abs(F.facePoints[0].z-p.start.z)<.25){if(H>.17&&p.length>.5){let Wt=Lt(v,W),J=Lt(v,j),ut=Lt(S,W),q=Lt(S,j);const Pt=.1,zt=10;if(Wt<Pt||J<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(Q,pt).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)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 Y=new y.Line3(it,mt).closestPointToPoint(Q,!0,Gt);let yt=Jt(Q,pt,Y,Q);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt,zt),st=pt.clone().addScaledVector(Mt.clone().negate(),zt);let wt=new 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(W.x,W.y,0),Y=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(Q,pt,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,Wt<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}if(ut<Pt||q<Pt){const{newOriginalPoints:Ut}=Ve(W,j,p.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=W.z}),at.length>10){const Q=new y.Vector3(p.start.x,p.start.y,0),pt=new y.Vector3(p.end.x,p.end.y,0),Mt=new y.Vector3().subVectors(pt,Q).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==m)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 Y=new y.Line3(it,mt).closestPointToPoint(pt,!0,Gt);let yt=Jt(pt,Q,Y,pt);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt.clone().negate(),zt),st=pt.clone().addScaledVector(Mt,zt);let wt=new 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(W.x,W.y,0),Y=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt(Y,it),wt=Lt(Y,mt),vt=Jt(pt,Q,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let $t=Se(Xt);if($t.length==2){let Kt=Lt(At,$t[0]),Le=Lt(At,$t[1]),Re=Lt(Y,$t[0]),Fe=Lt(Y,$t[1]);if(Kt<.2||Le<.2||Re<.2||Fe<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(p.length-H>.2||p.length-H<.02)&&ft<H*3)n[Z].length>.25&&H+ft>.5&&(Nt=!0,ut<Pt?(ct=ct.addScaledVector(Mt,ft),W=W.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&p.length-H>.1)continue;if(!k&&!dt&&p.length-H<.1&&p.length<1.8)continue}}else continue}H=ct.distanceTo(tt)}if(Zt<85&&H>.3||H>.7&&Vt>z-z/3){let Wt=!1;for(let J=0;J<t.length;J++){let ut=J+1;if(ut>=t.length)continue;let q=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(q.x,q.y,0),new y.Vector3(Pt.x,Pt.y,0),new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),.1)!=null){Wt=!0;break}}for(let J=0;J<a.length;J++){let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=F.facePoints[2].z<a[J].maxZ||Math.abs(F.facePoints[2].z-a[J].maxZ)<.3;if(Math.abs(F.facePoints[2].z-a[J].maxZ)>.2,Ut){let at=ne(ut.clone(),q.clone(),Pt.clone(),zt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let Q=ee(ut,q),pt=new y.Line3(new y.Vector3(p.start.x,p.start.y,0),new y.Vector3(p.end.x,p.end.y,0)),Mt=new y.Vector3,Gt=pt.closestPointToPoint(Q,!0,Mt);if(Q.distanceTo(Gt)<.15){let Z=Pt.distanceTo(ut),k=zt.distanceTo(ut);if(Z>.25&&k>.25){let it=Pt.distanceTo(q),mt=zt.distanceTo(q);if(it>.2&&mt>.2)continue}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,Tt=J,e[a[J].index].isFindBeam=!0;let dt=new y.Vector3().subVectors(Pt,zt).normalize(),U=ut.distanceTo(q)-at.overlap;k<Z&&dt.negate(),Z>k?(tt=F.facePoints[2].clone().addScaledVector(dt,U),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(dt,U),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let Q=Pt.distanceTo(zt),pt=q.distanceTo(ut);if(Math.abs(Q-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>Q&&Math.abs(pt-at.overlap)>1){let Mt=Pt.distanceTo(ut),Gt=Pt.distanceTo(q),ft=zt.distanceTo(ut),Z=zt.distanceTo(q),k=Mt<Gt?Mt:Gt,dt=ft<Z?ft:Z,U=new y.Vector3().subVectors(Pt,zt).normalize(),it=pt-at.overlap;k<dt?(U.negate(),tt=F.facePoints[2].clone().addScaledVector(U,it),ct=F.facePoints[3].clone(),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z):(tt=F.facePoints[2].clone(),ct=F.facePoints[3].clone().addScaledVector(U,it),W=ct.clone(),j=tt.clone(),W.z=j.z=F.facePoints[0].z)}_t=!0,Et=!0,Ft.push(a[J].index),a[J].isFind=!0,e[a[J].index].isFindBeam=!0,Tt=J}}}}if(!Et&&H<1.5)for(let J=0;J<a.length;J++){if(a[J].inWall)continue;let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),q=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(F.facePoints[0].x,F.facePoints[0].y,0),zt=new y.Vector3(F.facePoints[1].x,F.facePoints[1].y,0),Ut=new y.Vector3().subVectors(ut,q).normalize(),at=new y.Vector3().subVectors(Pt,zt).normalize(),Q=.25,pt=ut.clone().addScaledVector(Ut,Q),Mt=q.clone().addScaledVector(Ut.clone().negate(),Q),Gt=Pt.clone().addScaledVector(at,Q),ft=zt.clone().addScaledVector(at.clone().negate(),Q),Z=te(pt,Mt,Gt,ft),k=!0,dt=ut.distanceTo(Pt),U=ut.distanceTo(zt),it=q.distanceTo(Pt),mt=q.distanceTo(zt);(dt<f||U<f||it<f||mt<f||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Tt=J)}(_t||Wt||Math.abs(Vt-z)>.1&&Vt>z/2&&H>.3)&&(Rt=!0)}}if(Rt){let Wt=!1;for(let Z=0;Z<d.length;Z++){let k=ne(d[Z].start,d[Z].end,W,j);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){Wt=!0;break}}if(Wt){Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1);continue}d.push({start:W,end:j});{new y.PointsMaterial({color:65535,size:.01});let Z=new y.Vector3().subVectors(W,j),k=new y.Vector3().subVectors(j,W),dt=1/0,U=1/0,it=W.clone(),mt=j.clone();const Ct=[],St=[];let At=new y.Line3(tt,ct),Y=new y.Vector3,yt=999999;if(p.originalPoints.forEach(et=>{if(et.z-W.z<Vt/2+.1&&et.z-W.z>Vt/2-.1&&Ct.push(et),et.z>tt.z){let st=At.closestPointToPoint(et,!0,Y),wt=new 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(W,j,Ct);for(const st of et)st.z=W.z;et.forEach(st=>{let wt=new y.Vector3(st.x,st.y,W.z),vt=new y.Vector3().subVectors(wt,j),Bt=new y.Vector3().subVectors(wt,W),bt=oe(Z,Bt),Xt=oe(k,vt);if(bt&&bt.parallel&&bt.sameDirection){let $t=wt.distanceTo(W);$t<dt&&(dt=$t,it=wt)}else if(Xt&&Xt.parallel&&Xt.sameDirection){let $t=wt.distanceTo(j);$t<U&&(U=$t,mt=wt)}})}if(it.equals(W)||(W=it,ct=new y.Vector3(W.x,W.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,Y).distanceTo(et[st]);vt>.02&&yt>vt&&(yt=vt)}tt.z+=yt,ct.z+=yt,Vt+=yt}}let J=j.distanceTo(W);if(J<.4&&!_t||J<.3&&_t)continue;h.includes(m)||h.push(m),p.checkResults[E.index].isDoor=!0;let ut="",q={id:l,beamStart:tt,beamEnd:ct,beamHeight:p.rooftopPz-tt.z,doorStart:W,doorEnd:j,doorHeight:Vt,nearId:-1,type:ut,isExtend:Nt,isDoor:_t,isPullOutDoor:Et,pcbDoorIndexs:Ft,beamNearWallVec:new y.Vector3(0,0,0)},Pt=!1,zt=new y.Vector3,Ut=new y.Vector3,at=-1,Q=-1,pt=-1;for(let Z=0;Z<u.length;Z++){const k=n[u[Z].linesIndex].doorAndBeamData[u[Z].doorIndex];if(k.nearId!=-1)continue;let dt=Jt(tt.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let U=tt.distanceTo(ct),it=k.beamStart.distanceTo(k.beamEnd),mt=new y.Line3(tt.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let Ct=ee(k.beamStart,k.beamEnd,!0);it>U&&(mt.start=new y.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new y.Vector3(k.beamEnd.x,k.beamEnd.y,0),Ct=ee(tt,ct,!0));let St=new y.Vector3,At=mt.closestPointToPoint(Ct,!0,St),Y=At.distanceTo(Ct),yt=new y.Vector3().subVectors(Ct,At).normalize(),et=yt.clone().negate(),st=Ct.clone().addScaledVector(et,Y+.1),wt=te(mt.start,mt.end,Ct,st),vt=!_t&&!k.isDoor&&(U>it*2||it>U*2);if(Y<.4&&wt!=null&&!vt){k.nearId=l,q.nearId=k.id;let Bt=.8;(k.isDoor||q.isDoor)&&(k.isDoor=!0,q.isDoor=!0);const bt=Ft.some(Xt=>k.pcbDoorIndexs.includes(Xt));U<it?U>Bt&&!k.isPullOutDoor?(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Et||Et&&k.isPullOutDoor&&bt?(q.beamStart=k.beamStart.clone().addScaledVector(yt,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(yt,Y),q.doorStart=k.doorStart.clone().addScaledVector(yt,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(yt,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):(k.beamStart=tt.clone().addScaledVector(et,Y),k.beamEnd=ct.clone().addScaledVector(et,Y),k.doorStart=W.clone().addScaledVector(et,Y),k.doorEnd=j.clone().addScaledVector(et,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):U>it&&(it>Bt&&!Et?(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight):!k.isPullOutDoor||Et&&k.isPullOutDoor&&bt?(k.beamStart=tt.clone().addScaledVector(yt,Y),k.beamEnd=ct.clone().addScaledVector(yt,Y),k.doorStart=W.clone().addScaledVector(yt,Y),k.doorEnd=j.clone().addScaledVector(yt,Y),k.doorHeight=q.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(q.beamStart=k.beamStart.clone().addScaledVector(et,Y),q.beamEnd=k.beamEnd.clone().addScaledVector(et,Y),q.doorStart=k.doorStart.clone().addScaledVector(et,Y),q.doorEnd=k.doorEnd.clone().addScaledVector(et,Y),q.doorHeight=k.doorHeight,q.beamStart.z=q.beamEnd.z=q.doorStart.z+q.doorHeight)),at=q.nearId,zt=k.beamStart.clone(),Ut=k.beamEnd.clone(),Pt=!0,Q=u[Z].linesIndex,pt=u[Z].doorIndex;break}}}let Mt=!1;if(!Pt){let Z=new y.Line3(W.clone(),j.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==m)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,W,j),mt=Jt(dt,U,W,j);const Ct=io(n[k]);if(it&&it.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let st=new y.Line3(dt,U),wt=new y.Vector3(W.x,W.y,dt.z),vt=st.closestPointToPoint(wt,!0,new y.Vector3),Bt=re(vt,wt,W,j);Bt&&Bt.angle>85&&(q.beamNearWallVec=new y.Vector3().subVectors(vt,wt).normalize())}const St=[];n[k].originalPoints.forEach(st=>{st.z>W.z+.2&&st.z<W.z+Vt/2&&St.push(new y.Vector3(st.x,st.y,W.z))});const At=new y.Vector3;let Y=[],yt=[];for(let st=0;st<St.length;st++){let wt=Z.closestPointToPoint(St[st],!0,At);wt.distanceTo(St[st])<.15&&(Y.push(St[st]),yt.push(wt.clone()))}for(let st=0;st<yt.length;st++)ao(Z,yt[st])&&Y.push(yt[st]);if(Y=yt,Y=co(Y),Y.length<150)continue;let et=Se(Y);if(et.length==2){let st=et[0].distanceTo(et[1]);if(Math.abs(st-Z.distance())<.3){let wt=new y.Line3(dt,U),vt=new y.Vector3(W.x,W.y,dt.z),Bt=wt.closestPointToPoint(vt,!0,new y.Vector3);if(q.beamNearWallVec=new y.Vector3().subVectors(Bt,vt).normalize(),q.beamStart.z>Ct.maxZ-.03&&H>1)Mt=!0;else if(Wt=!0,Tt!=-1&&(e[a[Tt].index].isFindBeam=!1,a[Tt].isFind=!1),Q!=-1&&pt!=-1){const bt=n[Q].doorAndBeamData[pt];bt.nearId=-1}break}}if(Wt)break}else it&&it.type=="collinear_overlap"&&it.maxPerpendicularDistance>.3&&it.maxPerpendicularDistance<.7&&(Mt=!0)}if(Wt){if(H<1.8)continue;Mt=!0}}let Gt=!1;if(at!=-1)for(let Z=0;Z<c.length&&!(c[Z].length==1&&(c[Z][0].id==l?(c[Z].push({id:at,beamStart:zt,beamEnd:Ut}),Gt=!0):c[Z][0].id==at&&(c[Z].push({id:l,beamStart:tt,beamEnd:ct}),Gt=!0),Gt));Z++);Gt||c.push([{id:l,beamStart:tt,beamEnd:ct}]);const ft=q.doorStart.distanceTo(q.doorEnd);if(_t?ut="door":ft>1.8?ut="beam":ut=Mt&&ft>1?"beam":"hole",q.type=ut,q.nearId!=-1&&ut=="hole"){let Z=!1;for(let k=0;k<n.length;k++)if(n[k].doorAndBeamData){for(let dt=0;dt<n[k].doorAndBeamData.length;dt++)if(n[k].doorAndBeamData[dt].nearId==l&&n[k].doorAndBeamData[dt].type=="beam"){n[k].doorAndBeamData[dt].type=ut,Z=!0;break}if(Z)break}}if(p.doorAndBeamData.push(q),u.push({linesIndex:m,doorIndex:p.doorAndBeamData.length-1}),l++,Et&&H<2)break}}}let _=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=D/_*100}if(h.length>1)for(let m=0;m<h.length;m++){let p=[];for(let P=0;P<n[h[m]].doorAndBeamData.length;P++){let V=!1;if(n[h[m]].doorAndBeamData[P].type==="beam"&&n[h[m]].doorAndBeamData[P].beamNearWallVec.x==0&&n[h[m]].doorAndBeamData[P].beamNearWallVec.y==0&&n[h[m]].doorAndBeamData[P].beamNearWallVec.z==0&&n[h[m]].doorAndBeamData[P].nearId==-1&&(V=!0),!V){let v=n[h[m]].doorAndBeamData[P].doorStart.clone(),S=n[h[m]].doorAndBeamData[P].doorEnd.clone();v.z=S.z=0;let z=v.distanceTo(S);for(let D=0;D<h.length;D++)if(m!=D)for(let _=0;_<n[h[D]].doorAndBeamData.length;_++){let E=n[h[D]].doorAndBeamData[_].doorStart.clone(),T=n[h[D]].doorAndBeamData[_].doorEnd.clone();E.z=T.z=0,E.distanceTo(T);let A=ne(v,S,E,T);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let O=new y.Line3(E,T),I=ee(v,S),B=O.closestPointToPoint(I,!0,new y.Vector3),L=I.distanceTo(B);if(Math.abs(z-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[m]].doorAndBeamData[P].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),V=!0;break}}}}V||p.push(n[h[m]].doorAndBeamData[P])}p.length!=n[h[m]].doorAndBeamData.length&&(n[h[m]].doorAndBeamData=p)}let w=.65,x=2,b=[],M=[];for(let m=0;m<a.length;m++){if(a[m].isFind||a[m].inWall)continue;let p=new y.Vector3(a[m].doorStartPt.x,a[m].doorStartPt.y,0),P=new y.Vector3(a[m].doorEndPt.x,a[m].doorEndPt.y,0),V=new y.Vector3().subVectors(p,P).normalize();for(let v=0;v<n.length;v++){if(n[v].length<.7||n[v].completePointAreaPercentage>60)continue;let S=new y.Vector3(n[v].start.x,n[v].start.y,0),z=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,z).normalize(),_=.3,E=p.clone().addScaledVector(V,_),T=P.clone().addScaledVector(V.clone().negate(),_),A=S.clone().addScaledVector(D,_),O=z.clone().addScaledVector(D.clone().negate(),_);te(E,T,A,O);let I=Jt(E,T,A,O),B=p.distanceTo(S)>P.distanceTo(S)?P:p,L=B.distanceTo(S),N=B.distanceTo(z);if((L<f||N<f)&&I&&!I.isParallel){let R=p.distanceTo(S),$=p.distanceTo(z),X=R<$?S:z,ot=!1;for(let K=0;K<n.length;K++){if(K==v||b.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(),F=rt.clone().negate(),H=G.clone().addScaledVector(rt,5),Vt=ht.clone().addScaledVector(F,5),Zt=re(S,z,G,ht),qt=ne(S,z,G,ht),Rt=te(S,z,H,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<f||Rt.point.distanceTo(z)<f),(Zt&&Zt.angle>85||qt&&qt.type=="collinear_gap")&&_t){let Et=new y.Line3(S,z),Ft=new y.Vector3,tt=Et.closestPointToPoint(G,!0,Ft),ct=Et.closestPointToPoint(ht,!0,Ft),W=tt.distanceTo(G),j=ct.distanceTo(ht),Nt,Tt;if(W>j&&j>w)Nt=ht,Tt=ct;else if(W<j&&W>w)Nt=G,Tt=tt;else continue;if(W=X.distanceTo(G),j=X.distanceTo(ht),W>x&&j>x)continue;let Wt=Jt(Nt,Tt,G,ht),J=Jt(Nt,Tt,E,T);if(J&&J.isParallel||!Wt||!Wt.isParallel)continue;let ut=ne(p,P,Nt,Tt);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Nt.z=Tt.z=n[K].start.z;let q=!1;for(let at=0;at<M.length;at++){let Q=ne(M[at].start,M[at].end,Nt,Tt);if(Q&&Q.type=="collinear_overlap"&&Q.maxPerpendicularDistance<.2){q=!0;break}}if(q)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let Q=new 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,Nt,Tt);if(Mt&&Mt.type=="collinear_overlap"&&Mt.maxPerpendicularDistance<.1){q=!0;break}}if(q)continue;M.push({start:Nt,end:Tt}),b.push(K);let Pt=n[K].rooftopPz-n[K].start.z,zt=n[v].rooftopPz-n[v].start.z,Ut=Pt<zt?Pt:zt;n[K].doorAndBeamData||(n[K].doorAndBeamData=[]),n[K].doorAndBeamData.push({id:l,beamStart:Nt,beamEnd:Tt,beamHeight:Ut,doorStart:Nt,doorEnd:Tt,doorHeight:Ut,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new y.Vector3(0,0,0)}),e[a[m].index].isFindBeam=!0,e[a[m].index].isFindOnlyDoor=!0,c.push([{id:l,beamStart:Nt,beamEnd:Tt}]),l++,ot=!0;break}}if(ot)break}}}let g=[];for(let m=0;m<n.length;m++)n[m].isLine2||g.push(n[m]),n[m].isLine2&&n[m].doorAndBeamData.length!=0&&g.push(n[m]);return n.length=0,n.push(...g),{lines:n,beamGroup:c}},zo=(n,t)=>{if(!n||n.length<=0)return;let e={rectangles:[],threeEdgeRect:[]},o=new Set,i=.2,r=1.5,s=.15,a=2;if(!n[0].uuid){let l=1e4;for(let u=0;u<n.length;u++)n[u].uuid=l++}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h=[],d=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(c,d).normalize().clone().negate(),x=new y.Vector3,b=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let g=0;g<n.length;g++){let m=n[g].length;if(g==l||m<i||m>r)continue;let p=new y.Vector3(n[g].start.x,n[g].start.y,n[g].start.z),P=new y.Vector3(n[g].end.x,n[g].end.y,n[g].end.z),V=re(d,c,p,P);if(!V||V.angle<85)continue;let v=kt(p,d),S=kt(p,c),z=kt(P,d),D=kt(P,c);if(!(!v&&!S&&!z&&!D)){v||S?(x=p.clone(),b=P.clone()):(x=P.clone(),b=p.clone()),M=new y.Vector3().subVectors(b,x).normalize(),M.clone().negate();for(let _=0;_<n.length;_++){let E=n[_].length;if(_==l||_==g||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),O=re(p,P,T,A);if(!O||O.angle<85)continue;let I=kt(T,b),B=kt(A,b);if(!I&&!B)continue;new y.Vector3;let L=new y.Vector3,N=new y.Vector3;I?(N=new y.Vector3().subVectors(A,T).normalize(),T.clone(),L=A.clone()):(N=new y.Vector3().subVectors(T,A).normalize(),A.clone(),L=T.clone());let C=oe(w,N,.1);if(!(!C||!C.parallel||!C.sameDirection)){for(let R=0;R<n.length;R++){let $=n[R].length;if(R==l||R==g||R==_||$<i||$>r)continue;let X=new 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,T,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 F=kt(rt,d),H=kt(rt,c);if(!F&&!H)continue;let Vt=u*m;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[g].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(g=>o.add(g)),e.rectangles.push(h))}for(let l=0;l<n.length;l++){let u=n[l].length;if(o.has(n[l].uuid)||u<i||u>r)continue;let h={uuids:[],missingEdge:{start:new y.Vector3,end:new y.Vector3}},d=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),c=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),f=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let g=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),m=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),p=kt(g,d),P=kt(m,d),V=kt(g,c),v=kt(m,c);if(p||P?f=!1:(V||v)&&(w=!1),!f&&!w)break}if(!f&&!w)continue;let x=new y.Vector3;f||([d,c]=[c,d]),x=new y.Vector3().subVectors(c,d).normalize();let b=x.clone().negate();for(let M=0;M<n.length;M++){let g=n[M].length;if(M==l||o.has(M)||g<i||g>r)continue;let m=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),P=re(d,c,m,p);if(!P||P.angle<85)continue;let V=kt(m,c),v=kt(p,c);if(!V&&!v)continue;new y.Vector3;let S=new y.Vector3;V?(m.clone(),S=p.clone()):(p.clone(),S=m.clone());for(let z=0;z<n.length;z++){let D=n[z].length;if(z==l||z==M||o.has(z)||D<i||D>r)continue;let _=new y.Vector3(n[z].start.x,n[z].start.y,n[z].start.z),E=new y.Vector3(n[z].end.x,n[z].end.y,n[z].end.z),T=re(m,p,_,E);if(!T||T.angle<85)continue;let A=kt(_,S),O=kt(E,S);if(!A&&!O)continue;let I=new 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(),N=oe(b,L,.1);if(!N||!N.parallel||!N.sameDirection)continue;let C=!0,R=!0;for(let X=0;X<n.length;X++){if(X==z||n[X].length<i)continue;let ot=new y.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),K=new y.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),G=kt(ot,_),ht=kt(K,_),rt=kt(ot,E),F=kt(K,E);if(G||ht?C=!1:(rt||F)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let $=u*g;if(!($<s||$>a)){h.uuids=[n[l].uuid,n[M].uuid,n[z].uuid],h.missingEdge.start=B,h.missingEdge.end=d;break}}if(h.uuids.length==3)break}h.uuids.length==3&&(h.uuids.forEach(M=>o.add(M)),e.threeEdgeRect.push(h))}return e},ae=11102230246251565e-32,Yt=134217729,So=(3+8*ae)*ae;function Ne(n,t,e,o,i){let r,s,a,l,u=t[0],h=o[0],d=0,c=0;h>u==h>-u?(r=u,u=t[++d]):(r=h,h=o[++c]);let f=0;if(d<n&&c<e)for(h>u==h>-u?(s=u+r,a=r-(s-u),u=t[++d]):(s=h+r,a=r-(s-h),h=o[++c]),r=s,a!==0&&(i[f++]=a);d<n&&c<e;)h>u==h>-u?(s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++d]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c]),r=s,a!==0&&(i[f++]=a);for(;d<n;)s=r+u,l=s-r,a=r-(s-l)+(u-l),u=t[++d],r=s,a!==0&&(i[f++]=a);for(;c<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++c],r=s,a!==0&&(i[f++]=a);return(r!==0||f===0)&&(i[f++]=r),f}function vo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function ze(n){return new Float64Array(n)}const Do=(3+16*ae)*ae,_o=(2+12*ae)*ae,Eo=(9+64*ae)*ae*ae,me=ze(4),sn=ze(8),an=ze(12),ln=ze(16),jt=ze(4);function To(n,t,e,o,i,r,s){let a,l,u,h,d,c,f,w,x,b,M,g,m,p,P,V,v,S;const z=n-i,D=e-i,_=t-r,E=o-r;p=z*E,c=Yt*z,f=c-(c-z),w=z-f,c=Yt*E,x=c-(c-E),b=E-x,P=w*b-(p-f*x-w*x-f*b),V=_*D,c=Yt*_,f=c-(c-_),w=_-f,c=Yt*D,x=c-(c-D),b=D-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,me[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,me[1]=m-(M+d)+(d-V),S=g+M,d=S-g,me[2]=g-(S-d)+(M-d),me[3]=S;let T=vo(4,me),A=_o*s;if(T>=A||-T>=A||(d=n-z,a=n-(z+d)+(d-i),d=e-D,u=e-(D+d)+(d-i),d=t-_,l=t-(_+d)+(d-r),d=o-E,h=o-(E+d)+(d-r),a===0&&l===0&&u===0&&h===0)||(A=Eo*s+So*Math.abs(T),T+=z*h+E*a-(_*u+D*l),T>=A||-T>=A))return T;p=a*E,c=Yt*a,f=c-(c-a),w=a-f,c=Yt*E,x=c-(c-E),b=E-x,P=w*b-(p-f*x-w*x-f*b),V=l*D,c=Yt*l,f=c-(c-l),w=l-f,c=Yt*D,x=c-(c-D),b=D-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const O=Ne(4,me,4,jt,sn);p=z*h,c=Yt*z,f=c-(c-z),w=z-f,c=Yt*h,x=c-(c-h),b=h-x,P=w*b-(p-f*x-w*x-f*b),V=_*u,c=Yt*_,f=c-(c-_),w=_-f,c=Yt*u,x=c-(c-u),b=u-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const I=Ne(O,sn,4,jt,an);p=a*h,c=Yt*a,f=c-(c-a),w=a-f,c=Yt*h,x=c-(c-h),b=h-x,P=w*b-(p-f*x-w*x-f*b),V=l*u,c=Yt*l,f=c-(c-l),w=l-f,c=Yt*u,x=c-(c-u),b=u-x,v=w*b-(V-f*x-w*x-f*b),M=P-v,d=P-M,jt[0]=P-(M+d)+(d-v),g=p+M,d=g-p,m=p-(g-d)+(M-d),M=m-V,d=m-M,jt[1]=m-(M+d)+(d-V),S=g+M,d=S-g,jt[2]=g-(S-d)+(M-d),jt[3]=S;const B=Ne(I,an,4,jt,ln);return ln[B-1]}function ve(n,t,e,o,i,r){const s=(t-r)*(e-i),a=(n-i)*(o-r),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=Do*u?l:-To(n,t,e,o,i,r,u)}const cn=Math.pow(2,-52),De=new Uint32Array(512);class Be{static from(t,e=Co,o=Lo){const i=t.length,r=new Float64Array(i*2);for(let s=0;s<i;s++){const a=t[s];r[2*s]=e(a),r[2*s+1]=o(a)}return new Be(r)}constructor(t){const e=t.length>>1;if(e>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const o=Math.max(2*e-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:o,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let a=1/0,l=1/0,u=-1/0,h=-1/0;for(let z=0;z<s;z++){const D=t[2*z],_=t[2*z+1];D<a&&(a=D),_<l&&(l=_),D>u&&(u=D),_>h&&(h=_),this._ids[z]=z}const d=(a+u)/2,c=(l+h)/2;let f=0,w=0,x=0;for(let z=0,D=1/0;z<s;z++){const _=qe(d,c,t[2*z],t[2*z+1]);_<D&&(f=z,D=_)}const b=t[2*f],M=t[2*f+1];for(let z=0,D=1/0;z<s;z++){if(z===f)continue;const _=qe(b,M,t[2*z],t[2*z+1]);_<D&&_>0&&(w=z,D=_)}let g=t[2*w],m=t[2*w+1],p=1/0;for(let z=0;z<s;z++){if(z===f||z===w)continue;const D=Io(b,M,g,m,t[2*z],t[2*z+1]);D<p&&(x=z,p=D)}let P=t[2*x],V=t[2*x+1];if(p===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ye(this._ids,this._dists,0,s-1);const z=new Uint32Array(s);let D=0;for(let _=0,E=-1/0;_<s;_++){const T=this._ids[_],A=this._dists[T];A>E&&(z[D++]=T,E=A)}this.hull=z.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(b,M,g,m,P,V)<0){const z=w,D=g,_=m;w=x,g=P,m=V,x=z,P=D,V=_}const v=ko(b,M,g,m,P,V);this._cx=v.x,this._cy=v.y;for(let z=0;z<s;z++)this._dists[z]=qe(t[2*z],t[2*z+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=f;let S=3;o[f]=e[x]=w,o[w]=e[f]=x,o[x]=e[w]=f,i[f]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(b,M)]=f,r[this._hashKey(g,m)]=w,r[this._hashKey(P,V)]=x,this.trianglesLen=0,this._addTriangle(f,w,x,-1,-1,-1);for(let z=0,D=0,_=0;z<this._ids.length;z++){const E=this._ids[z],T=t[2*E],A=t[2*E+1];if(z>0&&Math.abs(T-D)<=cn&&Math.abs(A-_)<=cn||(D=T,_=A,E===f||E===w||E===x))continue;let O=0;for(let C=0,R=this._hashKey(T,A);C<this._hashSize&&(O=r[(R+C)%this._hashSize],!(O!==-1&&O!==o[O]));C++);O=e[O];let I=O,B;for(;B=o[I],ve(T,A,t[2*I],t[2*I+1],t[2*B],t[2*B+1])>=0;)if(I=B,I===O){I=-1;break}if(I===-1)continue;let L=this._addTriangle(I,E,o[I],-1,-1,i[I]);i[E]=this._legalize(L+2),i[I]=L,S++;let N=o[I];for(;B=o[N],ve(T,A,t[2*N],t[2*N+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(N,E,B,i[E],-1,i[N]),i[E]=this._legalize(L+2),o[N]=N,S--,N=B;if(I===O)for(;B=e[I],ve(T,A,t[2*B],t[2*B+1],t[2*I],t[2*I+1])<0;)L=this._addTriangle(B,E,I,-1,i[I],i[B]),this._legalize(L+2),i[B]=L,o[I]=I,S--,I=B;this._hullStart=e[E]=I,o[I]=e[N]=E,o[E]=N,r[this._hashKey(T,A)]=E,r[this._hashKey(t[2*I],t[2*I+1])]=I}this.hull=new Uint32Array(S);for(let z=0,D=this._hullStart;z<S;z++)this.hull[z]=D,D=o[D];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(Ao(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:o,coords:i}=this;let r=0,s=0;for(;;){const a=o[t],l=t-t%3;if(s=l+(t+2)%3,a===-1){if(r===0)break;t=De[--r];continue}const u=a-a%3,h=l+(t+1)%3,d=u+(a+2)%3,c=e[s],f=e[t],w=e[h],x=e[d];if(Bo(i[2*c],i[2*c+1],i[2*f],i[2*f+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=c;const M=o[d];if(M===-1){let m=this._hullStart;do{if(this._hullTri[m]===d){this._hullTri[m]=t;break}m=this._hullPrev[m]}while(m!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,d);const g=u+(a+1)%3;r<De.length&&(De[r++]=g)}else{if(r===0)break;t=De[--r]}}return s}_link(t,e){this._halfedges[t]=e,e!==-1&&(this._halfedges[e]=t)}_addTriangle(t,e,o,i,r,s){const a=this.trianglesLen;return this._triangles[a]=t,this._triangles[a+1]=e,this._triangles[a+2]=o,this._link(a,i),this._link(a+1,r),this._link(a+2,s),this.trianglesLen+=3,a}}function Ao(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function qe(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function Bo(n,t,e,o,i,r,s,a){const l=n-s,u=t-a,h=e-s,d=o-a,c=i-s,f=r-a,w=l*l+u*u,x=h*h+d*d,b=c*c+f*f;return l*(d*b-x*f)-u*(h*b-x*c)+w*(h*f-d*c)<0}function Io(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,d=l*l+u*u,c=.5/(s*u-a*l),f=(u*h-a*d)*c,w=(s*d-l*h)*c;return f*f+w*w}function ko(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,u=r-t,h=s*s+a*a,d=l*l+u*u,c=.5/(s*u-a*l),f=n+(u*h-a*d)*c,w=t+(s*d-l*h)*c;return{x:f,y:w}}function ye(n,t,e,o){if(o-e<=20)for(let i=e+1;i<=o;i++){const r=n[i],s=t[r];let a=i-1;for(;a>=e&&t[n[a]]>s;)n[a+1]=n[a--];n[a+1]=r}else{const i=e+o>>1;let r=e+1,s=o;Me(n,i,r),t[n[e]]>t[n[o]]&&Me(n,e,o),t[n[r]]>t[n[o]]&&Me(n,r,o),t[n[e]]>t[n[r]]&&Me(n,e,r);const a=n[r],l=t[a];for(;;){do r++;while(t[n[r]]<l);do s--;while(t[n[s]]>l);if(s<r)break;Me(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ye(n,t,r,o),ye(n,t,e,s-1)):(ye(n,t,e,s-1),ye(n,t,r,o))}}function Me(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Co(n){return n[0]}function Lo(n){return n[1]}const un=1e-6;class de{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,o){t=+t,e=+e,o=+o;const i=t+o,r=e;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>un||Math.abs(this._y1-r)>un)&&(this._+="L"+i+","+r),o&&(this._+=`A${o},${o},0,1,1,${t-o},${e}A${o},${o},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,o,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+o}v${+i}h${-o}Z`}value(){return this._||null}}class Ge{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class Ro{constructor(t,[e,o,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e))||!((r=+r)>=(o=+o)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:o},vectors:i}=this;let r,s;const a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let x=0,b=0,M=o.length,g,m;x<M;x+=3,b+=2){const p=o[x]*2,P=o[x+1]*2,V=o[x+2]*2,v=t[p],S=t[p+1],z=t[P],D=t[P+1],_=t[V],E=t[V+1],T=z-v,A=D-S,O=_-v,I=E-S,B=(T*I-A*O)*2;if(Math.abs(B)<1e-9){if(r===void 0){r=s=0;for(const N of e)r+=t[N*2],s+=t[N*2+1];r/=e.length,s/=e.length}const L=1e9*Math.sign((r-v)*I-(s-S)*O);g=(v+_)/2-L*I,m=(S+E)/2+L*O}else{const L=1/B,N=T*T+A*A,C=O*O+I*I;g=v+(I*N-A*C)*L,m=S+(T*C-O*N)*L}a[b]=g,a[b+1]=m}let l=e[e.length-1],u,h=l*4,d,c=t[2*l],f,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],u=h,d=c,f=w,h=l*4,c=t[2*l],w=t[2*l+1],i[u+2]=i[h]=f-w,i[u+3]=i[h+1]=c-d}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,d=o.length;h<d;++h){const c=o[h];if(c<h)continue;const f=Math.floor(h/3)*2,w=Math.floor(c/3)*2,x=s[f],b=s[f+1],M=s[w],g=s[w+1];this._renderSegment(x,b,M,g,t)}let l,u=r[r.length-1];for(let h=0;h<r.length;++h){l=u,u=r[h];const d=Math.floor(i[u]/3)*2,c=s[d],f=s[d+1],w=l*4,x=this._project(c,f,a[w+2],a[w+3]);x&&this._renderSegment(c,f,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 Ge;return this.renderCell(t,e),e.value()}_renderSegment(t,e,o,i,r){let s;const a=this._regioncode(t,e),l=this._regioncode(o,i);a===0&&l===0?(r.moveTo(t,e),r.lineTo(o,i)):(s=this._clipSegment(t,e,o,i,a,l))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,o){return e=+e,e!==e||(o=+o,o!==o)?!1:this.delaunay._step(t,e,o)===t}*neighbors(t){const e=this._clip(t);if(e)for(const o of this.delaunay.neighbors(t)){const i=this._clip(o);if(i){t:for(let r=0,s=e.length;r<s;r+=2)for(let a=0,l=i.length;a<l;a+=2)if(e[r]===i[a]&&e[r+1]===i[a+1]&&e[(r+2)%s]===i[(a+l-2)%l]&&e[(r+3)%s]===i[(a+l-1)%l]){yield o;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:o,halfedges:i,triangles:r}}=this,s=o[t];if(s===-1)return null;const a=[];let l=s;do{const u=Math.floor(l/3);if(a.push(e[u*2],e[u*2+1]),l=l%3===2?l-2:l+1,r[l]!==t)break;l=i[l]}while(l!==s&&l!==-1);return a}_clip(t){if(t===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(e===null)return null;const{vectors:o}=this,i=t*4;return this._simplify(o[i]||o[i+1]?this._clipInfinite(t,e,o[i],o[i+1],o[i+2],o[i+3]):this._clipFinite(t,e))}_clipFinite(t,e){const o=e.length;let i=null,r,s,a=e[o-2],l=e[o-1],u,h=this._regioncode(a,l),d,c=0;for(let f=0;f<o;f+=2)if(r=a,s=l,a=e[f],l=e[f+1],u=h,h=this._regioncode(a,l),u===0&&h===0)d=c,c=0,i?i.push(a,l):i=[a,l];else{let w,x,b,M,g;if(u===0){if((w=this._clipSegment(r,s,a,l,u,h))===null)continue;[x,b,M,g]=w}else{if((w=this._clipSegment(a,l,r,s,h,u))===null)continue;[M,g,x,b]=w,d=c,c=this._edgecode(x,b),d&&c&&this._edge(t,d,c,i,i.length),i?i.push(x,b):i=[x,b]}d=c,c=this._edgecode(M,g),d&&c&&this._edge(t,d,c,i,i.length),i?i.push(M,g):i=[M,g]}if(i)d=c,c=this._edgecode(i[0],i[1]),d&&c&&this._edge(t,d,c,i,i.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(t,e,o,i,r,s){const a=r<s;for(a&&([t,e,o,i,r,s]=[o,i,t,e,s,r]);;){if(r===0&&s===0)return a?[o,i,t,e]:[t,e,o,i];if(r&s)return null;let l,u,h=r||s;h&8?(l=t+(o-t)*(this.ymax-e)/(i-e),u=this.ymax):h&4?(l=t+(o-t)*(this.ymin-e)/(i-e),u=this.ymin):h&2?(u=e+(i-e)*(this.xmax-t)/(o-t),l=this.xmax):(u=e+(i-e)*(this.xmin-t)/(o-t),l=this.xmin),r?(t=l,e=u,r=this._regioncode(t,e)):(o=l,i=u,s=this._regioncode(o,i))}}_clipInfinite(t,e,o,i,r,s){let a=Array.from(e),l;if((l=this._project(a[0],a[1],o,i))&&a.unshift(l[0],l[1]),(l=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(l[0],l[1]),a=this._clipFinite(t,a))for(let u=0,h=a.length,d,c=this._edgecode(a[h-2],a[h-1]);u<h;u+=2)d=c,c=this._edgecode(a[u],a[u+1]),d&&c&&(u=this._edge(t,d,c,a,u),h=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,o,i,r){for(;e!==o;){let s,a;switch(e){case 5:e=4;continue;case 4:e=6,s=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,s=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,s=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,s=this.xmin,a=this.ymin;break}(i[r]!==s||i[r+1]!==a)&&this.contains(t,s,a)&&(i.splice(r,0,s,a),r+=2)}return r}_project(t,e,o,i){let r=1/0,s,a,l;if(i<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/i)<r&&(l=this.ymin,a=t+(r=s)*o)}else if(i>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/i)<r&&(l=this.ymax,a=t+(r=s)*o)}if(o>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/o)<r&&(a=this.xmax,l=e+(r=s)*i)}else if(o<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/o)<r&&(a=this.xmin,l=e+(r=s)*i)}return[a,l]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let e=0;e<t.length;e+=2){const o=(e+2)%t.length,i=(e+4)%t.length;(t[e]===t[o]&&t[o]===t[i]||t[e+1]===t[o+1]&&t[o+1]===t[i+1])&&(t.splice(o,2),e-=2)}t.length||(t=null)}return t}}const Fo=2*Math.PI,ge=Math.pow;function Oo(n){return n[0]}function No(n){return n[1]}function qo(n){const{triangles:t,coords:e}=n;for(let o=0;o<t.length;o+=3){const i=2*t[o],r=2*t[o+1],s=2*t[o+2];if((e[s]-e[i])*(e[r+1]-e[i+1])-(e[r]-e[i])*(e[s+1]-e[i+1])>1e-10)return!1}return!0}function Wo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class ke{static from(t,e=Oo,o=No,i){return new ke("length"in t?Xo(t,e,o,i):Float64Array.from($o(t,e,o,i)))}constructor(t){this._delaunator=new Be(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&qo(t)){this.collinear=Int32Array.from({length:e.length/2},(c,f)=>f).sort((c,f)=>e[2*c]-e[2*f]||e[2*c+1]-e[2*f+1]);const l=this.collinear[0],u=this.collinear[this.collinear.length-1],h=[e[2*l],e[2*l+1],e[2*u],e[2*u+1]],d=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let c=0,f=e.length/2;c<f;++c){const w=Wo(e[2*c],e[2*c+1],d);e[2*c]=w[0],e[2*c+1]=w[1]}this._delaunator=new Be(e)}else delete this.collinear;const o=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,u=o.length;l<u;++l){const h=r[l%3===2?l-2:l+1];(o[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,u=i.length;l<u;++l)a[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new Ro(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const d=a.indexOf(t);d>0&&(yield a[d-1]),d<a.length-1&&(yield a[d+1]);return}const l=e[t];if(l===-1)return;let u=l,h=-1;do{if(yield h=s[u],u=u%3===2?u-2:u+1,s[u]!==t)return;if(u=r[u],u===-1){const d=o[(i[t]+1)%o.length];d!==h&&(yield d);return}}while(u!==l)}find(t,e,o=0){if(t=+t,t!==t||(e=+e,e!==e))return-1;const i=o;let r;for(;(r=this._step(o,t,e))>=0&&r!==o&&r!==i;)o=r;return r}_step(t,e,o){const{inedges:i,hull:r,_hullIndex:s,halfedges:a,triangles:l,points:u}=this;if(i[t]===-1||!u.length)return(t+1)%(u.length>>1);let h=t,d=ge(e-u[t*2],2)+ge(o-u[t*2+1],2);const c=i[t];let f=c;do{let w=l[f];const x=ge(e-u[w*2],2)+ge(o-u[w*2+1],2);if(x<d&&(d=x,h=w),f=f%3===2?f-2:f+1,l[f]!==t)break;if(f=a[f],f===-1){if(f=r[(s[t]+1)%r.length],f!==w&&ge(e-u[f*2],2)+ge(o-u[f*2+1],2)<d)return f;break}}while(f!==c);return h}render(t){const e=t==null?t=new de:void 0,{points:o,halfedges:i,triangles:r}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const u=r[s]*2,h=r[l]*2;t.moveTo(o[u],o[u+1]),t.lineTo(o[h],o[h+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){e===void 0&&(!t||typeof t.moveTo!="function")&&(e=t,t=null),e=e==null?2:+e;const o=t==null?t=new de:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const a=i[r],l=i[r+1];t.moveTo(a+e,l),t.arc(a,l,e,0,Fo)}return o&&o.value()}renderHull(t){const e=t==null?t=new de:void 0,{hull:o,points:i}=this,r=o[0]*2,s=o.length;t.moveTo(i[r],i[r+1]);for(let a=1;a<s;++a){const l=2*o[a];t.lineTo(i[l],i[l+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new Ge;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new de:void 0,{points:i,triangles:r}=this,s=r[t*=3]*2,a=r[t+1]*2,l=r[t+2]*2;return e.moveTo(i[s],i[s+1]),e.lineTo(i[a],i[a+1]),e.lineTo(i[l],i[l+1]),e.closePath(),o&&o.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,o=t.length/3;e<o;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new Ge;return this.renderTriangle(t,e),e.value()}}function Xo(n,t,e,o){const i=n.length,r=new Float64Array(i*2);for(let s=0;s<i;++s){const a=n[s];r[s*2]=t.call(o,a,s,n),r[s*2+1]=e.call(o,a,s,n)}return r}function*$o(n,t,e,o){let i=0;for(const r of n)yield t.call(o,r,i,n),yield e.call(o,r,i,n),++i}function Ho(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Yo(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),u=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return u===0?1/0:s*a*l/(4*u)}function je(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 ke(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],b=i[w+1],M=i[w+2],[g,m]=e[x],[p,P]=e[b],[V,v]=e[M],S=Yo(g,m,p,P,V,v),z=Ho(e,x,b,M);if(S<=1/z)for(const[D,_]of[[x,b],[b,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 u=a[0][0],h=[],d=new Set;let c=u,f=-1;do{h.push(e[c]),d.add(c);const w=l.get(c)||[];let x=w.find(b=>b!==f&&!d.has(b));if(x===void 0&&(x=w.find(b=>b!==f)),x===void 0)break;f=c,c=x}while(c!==u&&h.length<=a.length+1);return h}const gt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},xt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},It=[[],[],[]],nt=[[],[],[]],Dt=[],ce=new lt.Vector3,ue=new lt.Vector3,he=new lt.Vector3,Ot=new lt.Vector3,hn=new lt.Vector3,fn=new lt.Vector3,Qt=new lt.Matrix3,dn=new lt.Box3,_e=new lt.Matrix4,mn=new lt.Matrix4,gn=new lt.Ray;let Tn=class{constructor(t=new lt.Vector3,e=new lt.Vector3,o=new lt.Matrix3){this.center=t,this.halfSize=e,this.rotation=o}set(t,e,o){return this.center=t,this.halfSize=e,this.rotation=o,this}copy(t){return this.center.copy(t.center),this.halfSize.copy(t.halfSize),this.rotation.copy(t.rotation),this}clone(){return new this.constructor().copy(this)}getSize(t){return t.copy(this.halfSize).multiplyScalar(2)}clampPoint(t,e){const o=this.halfSize;Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const i=lt.MathUtils.clamp(Ot.dot(ce),-o.x,o.x);e.add(ce.multiplyScalar(i));const r=lt.MathUtils.clamp(Ot.dot(ue),-o.y,o.y);e.add(ue.multiplyScalar(r));const s=lt.MathUtils.clamp(Ot.dot(he),-o.z,o.z);return e.add(he.multiplyScalar(s)),e}containsPoint(t){return Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),Math.abs(Ot.dot(ce))<=this.halfSize.x&&Math.abs(Ot.dot(ue))<=this.halfSize.y&&Math.abs(Ot.dot(he))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Go.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,fn),fn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){gt.c=this.center,gt.e[0]=this.halfSize.x,gt.e[1]=this.halfSize.y,gt.e[2]=this.halfSize.z,this.rotation.extractBasis(gt.u[0],gt.u[1],gt.u[2]),xt.c=t.center,xt.e[0]=t.halfSize.x,xt.e[1]=t.halfSize.y,xt.e[2]=t.halfSize.z,t.rotation.extractBasis(xt.u[0],xt.u[1],xt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)It[r][s]=gt.u[r].dot(xt.u[s]);Ot.subVectors(xt.c,gt.c),Dt[0]=Ot.dot(gt.u[0]),Dt[1]=Ot.dot(gt.u[1]),Dt[2]=Ot.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)nt[r][s]=Math.abs(It[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*nt[r][0]+xt.e[1]*nt[r][1]+xt.e[2]*nt[r][2],Math.abs(Dt[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*nt[0][r]+gt.e[1]*nt[1][r]+gt.e[2]*nt[2][r],i=xt.e[r],Math.abs(Dt[0]*It[0][r]+Dt[1]*It[1][r]+Dt[2]*It[2][r])>o+i)return!1;return o=gt.e[1]*nt[2][0]+gt.e[2]*nt[1][0],i=xt.e[1]*nt[0][2]+xt.e[2]*nt[0][1],!(Math.abs(Dt[2]*It[1][0]-Dt[1]*It[2][0])>o+i||(o=gt.e[1]*nt[2][1]+gt.e[2]*nt[1][1],i=xt.e[0]*nt[0][2]+xt.e[2]*nt[0][0],Math.abs(Dt[2]*It[1][1]-Dt[1]*It[2][1])>o+i)||(o=gt.e[1]*nt[2][2]+gt.e[2]*nt[1][2],i=xt.e[0]*nt[0][1]+xt.e[1]*nt[0][0],Math.abs(Dt[2]*It[1][2]-Dt[1]*It[2][2])>o+i)||(o=gt.e[0]*nt[2][0]+gt.e[2]*nt[0][0],i=xt.e[1]*nt[1][2]+xt.e[2]*nt[1][1],Math.abs(Dt[0]*It[2][0]-Dt[2]*It[0][0])>o+i)||(o=gt.e[0]*nt[2][1]+gt.e[2]*nt[0][1],i=xt.e[0]*nt[1][2]+xt.e[2]*nt[1][0],Math.abs(Dt[0]*It[2][1]-Dt[2]*It[0][1])>o+i)||(o=gt.e[0]*nt[2][2]+gt.e[2]*nt[0][2],i=xt.e[0]*nt[1][1]+xt.e[1]*nt[1][0],Math.abs(Dt[0]*It[2][2]-Dt[2]*It[0][2])>o+i)||(o=gt.e[0]*nt[1][0]+gt.e[1]*nt[0][0],i=xt.e[1]*nt[2][2]+xt.e[2]*nt[2][1],Math.abs(Dt[1]*It[0][0]-Dt[0]*It[1][0])>o+i)||(o=gt.e[0]*nt[1][1]+gt.e[1]*nt[0][1],i=xt.e[0]*nt[2][2]+xt.e[2]*nt[2][0],Math.abs(Dt[1]*It[0][1]-Dt[0]*It[1][1])>o+i)||(o=gt.e[0]*nt[1][2]+gt.e[1]*nt[0][2],i=xt.e[0]*nt[2][1]+xt.e[1]*nt[2][0],Math.abs(Dt[1]*It[0][2]-Dt[0]*It[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ce,ue,he);const e=this.halfSize.x*Math.abs(t.normal.dot(ce))+this.halfSize.y*Math.abs(t.normal.dot(ue))+this.halfSize.z*Math.abs(t.normal.dot(he)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(hn),dn.setFromCenterAndSize(Ot.set(0,0,0),hn),_e.setFromMatrix3(this.rotation),_e.setPosition(this.center),mn.copy(_e).invert(),gn.copy(t).applyMatrix4(mn),gn.intersectBox(dn,e)?e.applyMatrix4(_e):null}intersectsRay(t){return this.intersectRay(t,Ot)!==null}fromBox3(t){return t.getCenter(this.center),t.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(t){return t.center.equals(this.center)&&t.halfSize.equals(this.halfSize)&&t.rotation.equals(this.rotation)}applyMatrix4(t){const e=t.elements;let o=Ot.set(e[0],e[1],e[2]).length();const i=Ot.set(e[4],e[5],e[6]).length(),r=Ot.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Qt.setFromMatrix4(t);const a=1/o,l=1/i,u=1/r;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[3]*=l,Qt.elements[4]*=l,Qt.elements[5]*=l,Qt.elements[6]*=u,Qt.elements[7]*=u,Qt.elements[8]*=u,this.rotation.multiply(Qt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ot.setFromMatrixPosition(t),this.center.add(Ot),this}};const Go=new Tn;var Ht=63710088e-1,An={centimeters:Ht*100,centimetres:Ht*100,degrees:360/(2*Math.PI),feet:Ht*3.28084,inches:Ht*39.37,kilometers:Ht/1e3,kilometres:Ht/1e3,meters:Ht,metres:Ht,miles:Ht/1609.344,millimeters:Ht*1e3,millimetres:Ht*1e3,nauticalmiles:Ht/1852,radians:1,yards:Ht*1.0936};function Bn(n,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=n,o}function In(n,t,e={}){if(!n)throw new Error("coordinates is required");if(!Array.isArray(n))throw new Error("coordinates must be an Array");if(n.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!pn(n[0])||!pn(n[1]))throw new Error("coordinates must contain numbers");return Bn({type:"Point",coordinates:n},t,e)}function kn(n,t,e={}){for(const i of n){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<i[i.length-1].length;r++)if(i[i.length-1][r]!==i[0][r])throw new Error("First and last Position are not equivalent.")}return Bn({type:"Polygon",coordinates:n},t,e)}function jo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Uo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n/e}function Cn(n){return n%(2*Math.PI)*180/Math.PI}function ie(n){return n%360*Math.PI/180}function Ln(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return jo(Uo(n,t),e)}function pn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function Zo(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function Pe(n,t,e){if(n!==null)for(var o,i,r,s,a,l,u,h=0,d=0,c,f=n.type,w=f==="FeatureCollection",x=f==="Feature",b=w?n.features.length:1,M=0;M<b;M++){u=w?n.features[M].geometry:x?n.geometry:n,c=u?u.type==="GeometryCollection":!1,a=c?u.geometries.length:1;for(var g=0;g<a;g++){var m=0,p=0;if(s=c?u.geometries[g]:u,s!==null){l=s.coordinates;var P=s.type;switch(h=e&&(P==="Polygon"||P==="MultiPolygon")?1:0,P){case null:break;case"Point":if(t(l,d,M,m,p)===!1)return!1;d++,m++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],d,M,m,p)===!1)return!1;d++,P==="MultiPoint"&&m++}P==="LineString"&&m++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-h;i++){if(t(l[o][i],d,M,m,p)===!1)return!1;d++}P==="MultiLineString"&&m++,P==="Polygon"&&p++}P==="Polygon"&&m++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(p=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],d,M,m,p)===!1)return!1;d++}p++}m++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(Pe(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ko(n){var t=[];return Pe(n,function(e){t.push(e)}),t}function Qo(n,t){var e,o,i,r,s,a,l,u,h,d,c=0,f=n.type==="FeatureCollection",w=n.type==="Feature",x=f?n.features.length:1;for(e=0;e<x;e++){for(a=f?n.features[e].geometry:w?n.geometry:n,u=f?n.features[e].properties:w?n.properties:{},h=f?n.features[e].bbox:w?n.bbox:void 0,d=f?n.features[e].id:w?n.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(r=l?a.geometries[i]:a,r===null){if(t(null,c,u,h,d)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,c,u,h,d)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],c,u,h,d)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}c++}}function Jo(n,t,e){var o=e;return Qo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function er(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function o(){return this instanceof o?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(o){var i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:function(){return n[o]}})}),e}var Ze={exports:{}},Fn={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(g,m,p,P,V){(function v(S,z,D,_,E){for(;_>D;){if(_-D>600){var T=_-D+1,A=z-D+1,O=Math.log(T),I=.5*Math.exp(2*O/3),B=.5*Math.sqrt(O*I*(T-I)/T)*(A-T/2<0?-1:1),L=Math.max(D,Math.floor(z-A*I/T+B)),N=Math.min(_,Math.floor(z+(T-A)*I/T+B));v(S,z,L,N,E)}var C=S[z],R=D,$=_;for(o(S,D,z),E(S[_],C)>0&&o(S,D,_);R<$;){for(o(S,R,$),R++,$--;E(S[R],C)<0;)R++;for(;E(S[$],C)>0;)$--}E(S[D],C)===0?o(S,D,$):o(S,++$,_),$<=z&&(D=$+1),z<=$&&(_=$-1)}})(g,m,p||0,P||g.length-1,V||i)}function o(g,m,p){var P=g[m];g[m]=g[p],g[p]=P}function i(g,m){return g<m?-1:g>m?1:0}var r=function(g){g===void 0&&(g=9),this._maxEntries=Math.max(4,g),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(g,m,p){if(!p)return m.indexOf(g);for(var P=0;P<m.length;P++)if(p(g,m[P]))return P;return-1}function a(g,m){l(g,0,g.children.length,m,g)}function l(g,m,p,P,V){V||(V=b(null)),V.minX=1/0,V.minY=1/0,V.maxX=-1/0,V.maxY=-1/0;for(var v=m;v<p;v++){var S=g.children[v];u(V,g.leaf?P(S):S)}return V}function u(g,m){return g.minX=Math.min(g.minX,m.minX),g.minY=Math.min(g.minY,m.minY),g.maxX=Math.max(g.maxX,m.maxX),g.maxY=Math.max(g.maxY,m.maxY),g}function h(g,m){return g.minX-m.minX}function d(g,m){return g.minY-m.minY}function c(g){return(g.maxX-g.minX)*(g.maxY-g.minY)}function f(g){return g.maxX-g.minX+(g.maxY-g.minY)}function w(g,m){return g.minX<=m.minX&&g.minY<=m.minY&&m.maxX<=g.maxX&&m.maxY<=g.maxY}function x(g,m){return m.minX<=g.maxX&&m.minY<=g.maxY&&m.maxX>=g.minX&&m.maxY>=g.minY}function b(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(g,m,p,P,V){for(var v=[m,p];v.length;)if(!((p=v.pop())-(m=v.pop())<=P)){var S=m+Math.ceil((p-m)/P/2)*P;e(g,S,m,p,V),v.push(m,S,S,p)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(g){var m=this.data,p=[];if(!x(g,m))return p;for(var P=this.toBBox,V=[];m;){for(var v=0;v<m.children.length;v++){var S=m.children[v],z=m.leaf?P(S):S;x(g,z)&&(m.leaf?p.push(S):w(g,z)?this._all(S,p):V.push(S))}m=V.pop()}return p},r.prototype.collides=function(g){var m=this.data;if(!x(g,m))return!1;for(var p=[];m;){for(var P=0;P<m.children.length;P++){var V=m.children[P],v=m.leaf?this.toBBox(V):V;if(x(g,v)){if(m.leaf||w(g,v))return!0;p.push(V)}}m=p.pop()}return!1},r.prototype.load=function(g){if(!g||!g.length)return this;if(g.length<this._minEntries){for(var m=0;m<g.length;m++)this.insert(g[m]);return this}var p=this._build(g.slice(),0,g.length-1,0);if(this.data.children.length)if(this.data.height===p.height)this._splitRoot(this.data,p);else{if(this.data.height<p.height){var P=this.data;this.data=p,p=P}this._insert(p,this.data.height-p.height-1,!0)}else this.data=p;return this},r.prototype.insert=function(g){return g&&this._insert(g,this.data.height-1),this},r.prototype.clear=function(){return this.data=b([]),this},r.prototype.remove=function(g,m){if(!g)return this;for(var p,P,V,v=this.data,S=this.toBBox(g),z=[],D=[];v||z.length;){if(v||(v=z.pop(),P=z[z.length-1],p=D.pop(),V=!0),v.leaf){var _=s(g,v.children,m);if(_!==-1)return v.children.splice(_,1),z.push(v),this._condense(z),this}V||v.leaf||!w(v,S)?P?(p++,v=P.children[p],V=!1):v=null:(z.push(v),D.push(p),p=0,P=v,v=v.children[0])}return this},r.prototype.toBBox=function(g){return g},r.prototype.compareMinX=function(g,m){return g.minX-m.minX},r.prototype.compareMinY=function(g,m){return g.minY-m.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(g){return this.data=g,this},r.prototype._all=function(g,m){for(var p=[];g;)g.leaf?m.push.apply(m,g.children):p.push.apply(p,g.children),g=p.pop();return m},r.prototype._build=function(g,m,p,P){var V,v=p-m+1,S=this._maxEntries;if(v<=S)return a(V=b(g.slice(m,p+1)),this.toBBox),V;P||(P=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,P-1))),(V=b([])).leaf=!1,V.height=P;var z=Math.ceil(v/S),D=z*Math.ceil(Math.sqrt(S));M(g,m,p,D,this.compareMinX);for(var _=m;_<=p;_+=D){var E=Math.min(_+D-1,p);M(g,_,E,z,this.compareMinY);for(var T=_;T<=E;T+=z){var A=Math.min(T+z-1,E);V.children.push(this._build(g,T,A,P-1))}}return a(V,this.toBBox),V},r.prototype._chooseSubtree=function(g,m,p,P){for(;P.push(m),!m.leaf&&P.length-1!==p;){for(var V=1/0,v=1/0,S=void 0,z=0;z<m.children.length;z++){var D=m.children[z],_=c(D),E=(T=g,A=D,(Math.max(A.maxX,T.maxX)-Math.min(A.minX,T.minX))*(Math.max(A.maxY,T.maxY)-Math.min(A.minY,T.minY))-_);E<v?(v=E,V=_<V?_:V,S=D):E===v&&_<V&&(V=_,S=D)}m=S||m.children[0]}var T,A;return m},r.prototype._insert=function(g,m,p){var P=p?g:this.toBBox(g),V=[],v=this._chooseSubtree(P,this.data,m,V);for(v.children.push(g),u(v,P);m>=0&&V[m].children.length>this._maxEntries;)this._split(V,m),m--;this._adjustParentBBoxes(P,V,m)},r.prototype._split=function(g,m){var p=g[m],P=p.children.length,V=this._minEntries;this._chooseSplitAxis(p,V,P);var v=this._chooseSplitIndex(p,V,P),S=b(p.children.splice(v,p.children.length-v));S.height=p.height,S.leaf=p.leaf,a(p,this.toBBox),a(S,this.toBBox),m?g[m-1].children.push(S):this._splitRoot(p,S)},r.prototype._splitRoot=function(g,m){this.data=b([g,m]),this.data.height=g.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(g,m,p){for(var P,V,v,S,z,D,_,E=1/0,T=1/0,A=m;A<=p-m;A++){var O=l(g,0,A,this.toBBox),I=l(g,A,p,this.toBBox),B=(V=O,v=I,S=void 0,z=void 0,D=void 0,_=void 0,S=Math.max(V.minX,v.minX),z=Math.max(V.minY,v.minY),D=Math.min(V.maxX,v.maxX),_=Math.min(V.maxY,v.maxY),Math.max(0,D-S)*Math.max(0,_-z)),L=c(O)+c(I);B<E?(E=B,P=A,T=L<T?L:T):B===E&&L<T&&(T=L,P=A)}return P||p-m},r.prototype._chooseSplitAxis=function(g,m,p){var P=g.leaf?this.compareMinX:h,V=g.leaf?this.compareMinY:d;this._allDistMargin(g,m,p,P)<this._allDistMargin(g,m,p,V)&&g.children.sort(P)},r.prototype._allDistMargin=function(g,m,p,P){g.children.sort(P);for(var V=this.toBBox,v=l(g,0,m,V),S=l(g,p-m,p,V),z=f(v)+f(S),D=m;D<p-m;D++){var _=g.children[D];u(v,g.leaf?V(_):_),z+=f(v)}for(var E=p-m-1;E>=m;E--){var T=g.children[E];u(S,g.leaf?V(T):T),z+=f(S)}return z},r.prototype._adjustParentBBoxes=function(g,m,p){for(var P=p;P>=0;P--)u(m[P],g)},r.prototype._condense=function(g){for(var m=g.length-1,p=void 0;m>=0;m--)g[m].children.length===0?m>0?(p=g[m-1].children).splice(p.indexOf(g[m]),1):this.clear():a(g[m],this.toBBox)},r})})(Fn);var nr=Fn.exports;class or{constructor(t=[],e=rr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let o=(this.length>>1)-1;o>=0;o--)this._down(o)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:o}=this,i=e[t];for(;t>0;){const r=t-1>>1,s=e[r];if(o(i,s)>=0)break;e[t]=s,t=r}e[t]=i}_down(t){const{data:e,compare:o}=this,i=this.length>>1,r=e[t];for(;t<i;){let s=(t<<1)+1,a=e[s];const l=s+1;if(l<this.length&&o(e[l],a)<0&&(s=l,a=e[l]),o(a,r)>=0)break;e[t]=a,t=s}e[t]=r}}function rr(n,t){return n<t?-1:n>t?1:0}const ir=Object.freeze(Object.defineProperty({__proto__:null,default:or},Symbol.toStringTag,{value:"Module"})),sr=er(ir);var Ce={exports:{}},ar=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=(i-o)/2,u=0,h=l-1;u<l;h=u++){var d=e[o+u*2+0],c=e[o+u*2+1],f=e[o+h*2+0],w=e[o+h*2+1],x=c>s!=w>s&&r<(f-d)*(s-c)/(w-c)+d;x&&(a=!a)}return a},lr=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=i-o,u=0,h=l-1;u<l;h=u++){var d=e[u+o][0],c=e[u+o][1],f=e[h+o][0],w=e[h+o][1],x=c>s!=w>s&&r<(f-d)*(s-c)/(w-c)+d;x&&(a=!a)}return a},On=ar,Nn=lr;Ce.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Nn(t,e,o,i):On(t,e,o,i)};Ce.exports.nested=Nn;Ce.exports.flat=On;var cr=Ce.exports,Ue={exports:{}};(function(n,t){(function(e,o){o(t)})(Rn,function(e){const i=33306690738754706e-32;function r(x,b,M,g,m){let p,P,V,v,S=b[0],z=g[0],D=0,_=0;z>S==z>-S?(p=S,S=b[++D]):(p=z,z=g[++_]);let E=0;if(D<x&&_<M)for(z>S==z>-S?(V=p-((P=S+p)-S),S=b[++D]):(V=p-((P=z+p)-z),z=g[++_]),p=P,V!==0&&(m[E++]=V);D<x&&_<M;)z>S==z>-S?(V=p-((P=p+S)-(v=P-p))+(S-v),S=b[++D]):(V=p-((P=p+z)-(v=P-p))+(z-v),z=g[++_]),p=P,V!==0&&(m[E++]=V);for(;D<x;)V=p-((P=p+S)-(v=P-p))+(S-v),S=b[++D],p=P,V!==0&&(m[E++]=V);for(;_<M;)V=p-((P=p+z)-(v=P-p))+(z-v),z=g[++_],p=P,V!==0&&(m[E++]=V);return p===0&&E!==0||(m[E++]=p),E}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,u=11093356479670487e-47,h=s(4),d=s(8),c=s(12),f=s(16),w=s(4);e.orient2d=function(x,b,M,g,m,p){const P=(b-p)*(M-m),V=(x-m)*(g-p),v=P-V;if(P===0||V===0||P>0!=V>0)return v;const S=Math.abs(P+V);return Math.abs(v)>=a*S?v:-function(z,D,_,E,T,A,O){let I,B,L,N,C,R,$,X,ot,K,G,ht,rt,F,H,Vt,Zt,qt;const Rt=z-T,_t=_-T,Et=D-A,Ft=E-A;C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=Rt*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=Et*_t)-$*ot-X*ot-$*K))),h[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),h[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,h[2]=ht-(qt-C)+(G-C),h[3]=qt;let tt=function(Tt,Wt){let J=Wt[0];for(let ut=1;ut<Tt;ut++)J+=Wt[ut];return J}(4,h),ct=l*O;if(tt>=ct||-tt>=ct||(I=z-(Rt+(C=z-Rt))+(C-T),L=_-(_t+(C=_-_t))+(C-T),B=D-(Et+(C=D-Et))+(C-A),N=E-(Ft+(C=E-Ft))+(C-A),I===0&&B===0&&L===0&&N===0)||(ct=u*O+i*Math.abs(tt),(tt+=Rt*N+Ft*I-(Et*L+_t*B))>=ct||-tt>=ct))return tt;C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=Ft-(ot=(R=134217729*Ft)-(R-Ft)))-((F=I*Ft)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=B*_t)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const W=r(4,h,4,w,d);C=(H=(X=Rt-($=(R=134217729*Rt)-(R-Rt)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=Rt*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=Et-($=(R=134217729*Et)-(R-Et)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=Et*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const j=r(W,d,4,w,c);C=(H=(X=I-($=(R=134217729*I)-(R-I)))*(K=N-(ot=(R=134217729*N)-(R-N)))-((F=I*N)-$*ot-X*ot-$*K))-(G=H-(Zt=(X=B-($=(R=134217729*B)-(R-B)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=B*L)-$*ot-X*ot-$*K))),w[0]=H-(G+C)+(C-Zt),C=(rt=F-((ht=F+G)-(C=ht-F))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(qt=ht+G)-ht,w[2]=ht-(qt-C)+(G-C),w[3]=qt;const Nt=r(j,c,4,w,f);return f[Nt-1]}(x,b,M,g,m,p,S)},e.orient2dfast=function(x,b,M,g,m,p){return(b-p)*(M-m)-(x-m)*(g-p)},Object.defineProperty(e,"__esModule",{value:!0})})})(Ue,Ue.exports);var ur=Ue.exports,yn=nr,Ae=sr,hr=cr,fr=ur.orient2d;Ae.default&&(Ae=Ae.default);Ze.exports=qn;Ze.exports.default=qn;function qn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=yr(n),i=new yn(16);i.toBBox=function(g){return{minX:g[0],minY:g[1],maxX:g[0],maxY:g[1]}},i.compareMinX=function(g,m){return g[0]-m[0]},i.compareMinY=function(g,m){return g[1]-m[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=bn(l,a),r.push(a)}var u=new yn(16);for(s=0;s<r.length;s++)u.insert(We(r[s]));for(var h=t*t,d=e*e;r.length;){var c=r.shift(),f=c.p,w=c.next.p,x=Xe(f,w);if(!(x<d)){var b=x/h;l=dr(i,c.prev.p,f,w,c.next.next.p,b,u),l&&Math.min(Xe(l,f),Xe(l,w))<=b&&(r.push(c),r.push(bn(l,c)),i.remove(l),u.remove(c),u.insert(We(c)),u.insert(We(c.next)))}}c=a;var M=[];do M.push(c.p),c=c.next;while(c!==a);return M.push(c.p),M}function dr(n,t,e,o,i,r,s){for(var a=new Ae([],mr),l=n.data;l;){for(var u=0;u<l.children.length;u++){var h=l.children[u],d=l.leaf?$e(h,e,o):gr(e,o,h);d>r||a.push({node:h,dist:d})}for(;a.length&&!a.peek().node.children;){var c=a.pop(),f=c.node,w=$e(f,t,e),x=$e(f,o,i);if(c.dist<w&&c.dist<x&&wn(e,f,s)&&wn(o,f,s))return f}l=a.pop(),l&&(l=l.node)}return null}function mr(n,t){return n.dist-t.dist}function gr(n,t,e){if(xn(n,e)||xn(t,e))return 0;var o=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=Ee(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=Ee(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=Ee(n[0],n[1],t[0],t[1],e.minX,e.maxY,e.maxX,e.maxY);return s===0?0:Math.min(o,i,r,s)}function xn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function wn(n,t,e){for(var o=Math.min(n[0],t[0]),i=Math.min(n[1],t[1]),r=Math.max(n[0],t[0]),s=Math.max(n[1],t[1]),a=e.search({minX:o,minY:i,maxX:r,maxY:s}),l=0;l<a.length;l++)if(pr(a[l].p,a[l].next.p,n,t))return!1;return!0}function xe(n,t,e){return fr(n[0],n[1],t[0],t[1],e[0],e[1])}function pr(n,t,e,o){return n!==o&&t!==e&&xe(n,t,e)>0!=xe(n,t,o)>0&&xe(e,o,n)>0!=xe(e,o,t)>0}function We(n){var t=n.p,e=n.next.p;return n.minX=Math.min(t[0],e[0]),n.minY=Math.min(t[1],e[1]),n.maxX=Math.max(t[0],e[0]),n.maxY=Math.max(t[1],e[1]),n}function yr(n){for(var t=n[0],e=n[0],o=n[0],i=n[0],r=0;r<n.length;r++){var s=n[r];s[0]<t[0]&&(t=s),s[0]>o[0]&&(o=s),s[1]<e[1]&&(e=s),s[1]>i[1]&&(i=s)}var a=[t,e,o,i],l=a.slice();for(r=0;r<n.length;r++)hr(n[r],a)||l.push(n[r]);return wr(l)}function bn(n,t){var e={p:n,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e):(e.prev=e,e.next=e),e}function Xe(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function $e(n,t,e){var o=t[0],i=t[1],r=e[0]-o,s=e[1]-i;if(r!==0||s!==0){var a=((n[0]-o)*r+(n[1]-i)*s)/(r*r+s*s);a>1?(o=e[0],i=e[1]):a>0&&(o+=r*a,i+=s*a)}return r=n[0]-o,s=n[1]-i,r*r+s*s}function Ee(n,t,e,o,i,r,s,a){var l=e-n,u=o-t,h=s-i,d=a-r,c=n-i,f=t-r,w=l*l+u*u,x=l*h+u*d,b=h*h+d*d,M=l*c+u*f,g=h*c+d*f,m=w*b-x*x,p,P,V,v,S=m,z=m;m===0?(P=0,S=1,v=g,z=b):(P=x*g-b*M,v=w*g-x*M,P<0?(P=0,v=g,z=b):P>S&&(P=S,v=g+x,z=b)),v<0?(v=0,-M<0?P=0:-M>w?P=S:(P=-M,S=w)):v>z&&(v=z,-M+x<0?P=0:-M+x>w?P=S:(P=-M+x,S=w)),p=P===0?0:P/S,V=v===0?0:v/z;var D=(1-p)*n+p*e,_=(1-p)*t+p*o,E=(1-V)*i+V*s,T=(1-V)*r+V*a,A=E-D,O=T-_;return A*A+O*O}function xr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function wr(n){n.sort(xr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&xe(t[t.length-2],t[t.length-1],n[e])<=0;)t.pop();t.push(n[e])}for(var o=[],i=n.length-1;i>=0;i--){for(;o.length>=2&&xe(o[o.length-2],o[o.length-1],n[i])<=0;)o.pop();o.push(n[i])}return o.pop(),t.pop(),t.concat(o)}var br=Ze.exports;const Pr=tr(br);function Mr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(Pe(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=Pr(e,t.concavity);return o.length>3?kn([o]):null}function Wn(n,t={}){let e=0,o=0,i=0;return Pe(n,function(r){e+=r[0],o+=r[1],i++},!0),In([e/i,o/i],t.properties)}function se(n){if(!n)throw new Error("coord is required");if(!Array.isArray(n)){if(n.type==="Feature"&&n.geometry!==null&&n.geometry.type==="Point")return[...n.geometry.coordinates];if(n.type==="Point")return[...n.coordinates]}if(Array.isArray(n)&&n.length>=2&&!Array.isArray(n[0])&&!Array.isArray(n[1]))return[...n];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Vr(n){if(Array.isArray(n))return n;if(n.type==="Feature"){if(n.geometry!==null)return n.geometry.coordinates}else if(n.coordinates)return n.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function zr(n,t,e={}){let o;return e.final?o=Pn(se(t),se(n)):o=Pn(se(n),se(t)),o>180?-(360-o):o}function Pn(n,t){const e=ie(n[1]),o=ie(t[1]);let i=ie(t[0]-n[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(i,r);return(Cn(s)+360)%360}function Sr(n,t,e={}){const o=se(n),i=se(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=vr(o,i);return Ln(r,"meters",e.units)}function vr(n,t,e){e=e===void 0?Ht:Number(e);const o=e,i=n[1]*Math.PI/180,r=t[1]*Math.PI/180,s=r-i;let a=Math.abs(t[0]-n[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),u=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+u*u*a*a)*o}function Dr(n,t,e,o={}){const i=t<0;let r=Ln(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=se(n),a=_r(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,In(a,o.properties)}function _r(n,t,e,o){o=o===void 0?Ht:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ie(n[1]),a=ie(e),l=i*Math.cos(a);let u=s+l;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);const h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),d=Math.abs(h)>1e-11?l/h:Math.cos(s),c=i*Math.sin(a)/d;return[((r+c)*180/Math.PI+540)%360-180,u*180/Math.PI]}function Er(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Xn(n);case"FeatureCollection":return Tr(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ke(n);default:throw new Error("unknown GeoJSON type")}}function Xn(n){const t={type:"Feature"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=n[e]}}),t.properties=$n(n.properties),n.geometry==null?t.geometry=null:t.geometry=Ke(n.geometry),t}function $n(n){const t={};return n&&Object.keys(n).forEach(e=>{const o=n[e];typeof o=="object"?o===null?t[e]=null:Array.isArray(o)?t[e]=o.map(i=>i):t[e]=$n(o):t[e]=o}),t}function Tr(n){const t={type:"FeatureCollection"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=n[e]}}),t.features=n.features.map(e=>Xn(e)),t}function Ke(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>Ke(e)),t):(t.coordinates=Hn(n.coordinates),t)}function Hn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Hn(e))}function Mn(n,t,e){if(e=e||{},!Zo(e))throw new Error("options is invalid");const o=e.pivot,i=e.mutate;if(!n)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("angle is required");if(t===0)return n;const r=o??Wn(n);return(i===!1||i===void 0)&&(n=Er(n)),Pe(n,function(s){const l=zr(r,s)+t,u=Sr(r,s),h=Vr(Dr(r,u,l));s[0]=h[0],s[1]=h[1]}),n}function Yn(n,t,e={}){if(e.final===!0)return Ar(n,t);const o=se(n),i=se(t),r=ie(o[0]),s=ie(i[0]),a=ie(o[1]),l=ie(i[1]),u=Math.sin(s-r)*Math.cos(l),h=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-r);return Cn(Math.atan2(u,h))}function Ar(n,t){let e=Yn(t,n);return e=(e+180)%360,e}function Br(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return Pe(n,o=>{e[0]>o[0]&&(e[0]=o[0]),e[1]>o[1]&&(e[1]=o[1]),e[2]<o[0]&&(e[2]=o[0]),e[3]<o[1]&&(e[3]=o[1])}),e}function Ir(n,t={}){const e=Number(n[0]),o=Number(n[1]),i=Number(n[2]),r=Number(n[3]);if(n.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[e,o];return kn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function kr(n){return Ir(Br(n))}function Cr(n){return Jo(n,(t,e)=>t+Lr(e),0)}function Lr(n){let t=0,e;switch(n.type){case"Polygon":return Vn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=Vn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function Vn(n){let t=0;if(n&&n.length>0){t+=Math.abs(zn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(zn(n[e]))}return t}var Rr=Ht*Ht/2,He=Math.PI/180;function zn(n){const t=n.length-1;if(t<=2)return 0;let e=0,o=0;for(;o<t;){const i=n[o],r=n[o+1===t?0:o+1],s=n[o+2>=t?(o+2)%t:o+2],a=i[0]*He,l=r[1]*He,u=s[0]*He;e+=(u-a)*Math.sin(l),o++}return e*Rr}function Fr(n){const t=Mr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=Wn(t),o=Ko(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=Yn(o[s],o[s+1]),l=Mn(t,-1*a,{pivot:e}),u=kr(l),h=Cr(u);h<i&&(i=h,r=Mn(u,a,{pivot:e}))}return r}function Sn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Or(n){let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const[r,s]of n)r<t&&(t=r),r>e&&(e=r),s<o&&(o=s),s>i&&(i=s);return[(e+t)*.5,(i+o)*.5]}class Ie extends Tn{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Te,fe,new 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();qr.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(Te,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,Nr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(t,e,o,i=new Ie){const r=Fr({type:"Polygon",coordinates:[t.map(f=>[f.x,f.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Sn(s[0],s[1]),l=Sn(s[1],s[2]),u=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Te.set(a,l,o),vn.set(0,0,u);const[h,d]=Or(s);return e.x=h,e.y=d,this.from(Te,e,vn,i)}}const le=new y.Matrix4,fe=new y.Quaternion,vn=new y.Euler,Nr=new y.Vector3(1,1,1),Te=new y.Vector3,qr=new y.Box3;function Wr(n,t,e=.005,o=.2){if(!n.length||!t.length)return 0;const i=Math.max(e,.03),r=e*e,s=new Map,a=(d,c,f)=>`${Math.floor(d/i)},${Math.floor(c/i)},${Math.floor(f/i)}`;for(const d of t){const c=a(d.x,d.y,d.z);s.has(c)||s.set(c,[]),s.get(c).push(d)}let l=0;const u=Math.ceil(e/i)+1,h=[];for(let d=-u;d<=u;d++)for(let c=-u;c<=u;c++)for(let f=-u;f<=u;f++)d*d+c*c+f*f<=u*u&&h.push([d,c,f]);for(const d of n){const c=Math.floor(d.x/i),f=Math.floor(d.y/i),w=Math.floor(d.z/i);let x=!1;for(const[b,M,g]of h){const m=`${c+b},${f+M},${w+g}`;if(s.has(m)){for(const p of s.get(m))if(d.distanceToSquared(p)<r){x=!0;break}if(x)break}}if(x&&(l++,l/n.length>o))return l/n.length}return l/n.length}function pe(n,t,e=.5){let o=0,i=0;for(const r of n)if(t.containsPoint(r)&&(o++,i=o/n.length,i>e))break;return i}function Ye(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=we(n,o),s=we(t,e);if(r||s)return!0}return!1}function Dn(n,t){const e=new y.Vector3,o=new y.Vector3;n.getSize(e),t.getSize(o);const i=e.x*e.y*e.z,r=o.x*o.y*o.z;return i>r?1:i<r?-1:0}function we(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function _n(n){if(n.length===0)return{x:0,y:0,z:0,h:0};let t=0,e=0,o=-1/0,i=1/0;for(const r of n)t+=r.x,e+=r.y,o=Math.max(o,r.z),i=Math.min(i,r.z);return{x:t/n.length,y:e/n.length,z:0,maxz:o,minz:i,h:o-i}}function En(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,t)=>{if(n.length==0)return[];t||(t=n[0].averagePz);const e=[],o=new Map;for(let r=0;r<n.length;r++){let s=n[r].points.map(b=>[b.x,b.y]),a=n[r].obj_id;a=a.replace(/calcony railing/g,"balcony railing").replace(/glass balcony railing/g,"balcony railing").replace(/metal balcony railing/g,"balcony railing").replace(/temporary construction guardrail/g,"balcony railing").replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor"),a.split("_").slice(1,3).join("_").split(".")[0].split("_")[0];const l=a.indexOf("_")+1,u=a.lastIndexOf("_"),h=a.substring(l,u);if(h==="wall")continue;let d=[];for(let b=0;b<n[r].points.length;b++)d.push(new y.Vector3(n[r].points[b].x,n[r].points[b].y,n[r].points[b].z));let c=-99999;if(h==="floor"){let b=new Map;for(let g=0;g<n[r].points.length;g++){let m=n[r].points[g].z;if(m=Math.floor(m*10)/10,b.has(m)){const p=b.get(m);p.num+=1,p.points.push(n[r].points[g]),b.set(m,p)}else b.set(m,{num:1,points:[n[r].points[g]]})}let M=[...b.entries()].reduce((g,m)=>m[1].num>g[1].num?m:g);s=[],s=M[1].points.map(g=>[g.x,g.y]),d=[],d=M[1].points.map(g=>new y.Vector3(g.x,g.y,g.z)),c=M[0]}const f=_n(d),w={points:d,path:je(s),h:f.h,minz:f.minz,maxz:f.maxz,center:{x:f.x,y:f.y,z:f.z},obj_id:n[r].obj_id,type:h,averagePz:t,obb:null,isDel:!1,obj_id:a,positionArr:[n[r].position]};if(w.obb=En(w.path,w.center,w.h,(w.maxz+w.minz)/2),w.obb==null)continue;let x=-1;for(let b=0;b<e.length;b++)if(e[b].type==h){x=b;break}if(x!=-1?e[x].array.push(w):e.push({type:h,array:[w]}),h=="floor"&&c!=-99999)if(o.has(c)){const b=o.get(c);b.num+=w.points.length,b.datas.push(w),o.set(c,b)}else o.set(c,{num:w.points.length,datas:[w]})}if(o.size>0){let r=[];for(const[s,a]of o.entries()){const{num:l,datas:u}=a;l>3e3&&r.push(...u)}for(let s=0;s<e.length;s++)if(e[s].type=="floor"){e[s].array=r;break}}for(let r=0;r<e.length;r++){const s=e[r].array,a=[],l=[];for(let h=0;h<s.length;h++){if(s[h].obb==null||a.includes(h))continue;const d={...s[h],obb:s[h].obb.clone()};for(let c=h+1;c<s.length;c++){if(s[c].obb==null||a.includes(c))continue;if(d.obb.intersectsOBB(s[c].obb)){a.push(c);for(let b=0;b<s[c].points.length;b++)(s[c].points[b].z>t&&s[c].points[b].z-t>.1||d.type=="floor")&&d.points.push(s[c].points[b]);const w=d.points.map(b=>[b.x,b.y]);d.path=je(w);const x=_n(d.points);d.h=x.h,d.minz=x.minz,d.maxz=x.maxz,d.center={x:x.x,y:x.y,z:x.z},d.obb=En(d.path,d.center,d.h,(d.maxz+d.minz)/2),d.positionArr.push(...s[c].positionArr),c=h}}d.path.length>s[h].path.length&&(a.push(h),l.push(d))}const u=[];for(let h=0;h<s.length;h++)a.includes(h)||u.push(s[h]);u.push(...l),e[r].array=u}for(let r=0;r<e.length;r++){const s=e[r].type;if(s==="people"||s==="floor")continue;const a=e[r].array;for(let l=0;l<a.length;l++){const u=a[l].obb,h=a[l].minz;a[l].maxz;const d=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const c=new y.Vector3;u.getSize(c);const f=[c.x,c.y,c.z];let w=0;for(const x of f)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let c=r+1;c<e.length;c++){const f=e[c].type;if(f==="people"||f==="floor")continue;const w=e[c].array;for(let x=0;x<w.length;x++){if(w[x].isDel)continue;const b=w[x].obb,M=w[x].minz;if(w[x].maxz,u.intersectsOBB(b)){pe(w[x].points,u);const g=pe(a[l].points,b),m=Dn(u,b);if(g>=.3&&m==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(f==="balcony railing"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(f==="balcony railing"&&we(b,a[l].points)){a[l].isDel=!0;break}if(f==="balcony railing"&&Ye(u,b,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-d)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(f==="window"&&we(u,w[x].points)){w[x].isDel=!0;continue}if(f==="window"&&we(b,a[l].points)){a[l].isDel=!0;break}if(f==="window"&&Ye(u,b,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-d)>.3)){a[l].isDel=!0;break}}let p=!1,P=[],V=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(p=!0,P=v,V=S):(P=S,V=v),Wr(V,P,.03,.5)>.5)if(p)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(Ye(u,b)){const D=Dn(u,b);if(D===1||D===0){if(f==="switch")continue;v.length>S.length?pe(V,u)>=.5&&(w[x].isDel=!0):pe(P,u)>=.5&&(w[x].isDel=!0)}else{if(s==="switch")continue;if(v.length>S.length){if(pe(P,b)>=.5){a[l].isDel=!0;break}}else if(pe(V,b)>=.5){a[l].isDel=!0;break}}}}}}if(a[l].isDel)break}}}for(let r=0;r<e.length;r++){const s=e[r].type,a=e[r].array;for(let l=0;l<a.length;l++){let u=a[l].maxz,h=a[l].minz,d=s==="switch"?.1:.3;if(Math.abs(u-t)<d){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const c=Math.abs(u-t),f=Math.abs(h-t);(s==="tv"&&f<1.6||s!=="window"&&c<1.6)&&(a[l].isDel=!0),s==="window"&&c<1&&(a[l].isDel=!0)}if(s==="chair"){const c=new y.Vector3;a[l].obb.getSize(c),(c.x<.1||c.y<.1||c.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(u-h)<.4&&(a[l].isDel=!0),(h<t&&Math.abs(h-t)>1||h>t&&Math.abs(h-t)>1)&&(a[l].isDel=!0),u<t&&(a[l].isDel=!0)),s==="people"&&(Math.abs(u-h)<1&&(a[l].isDel=!0),h>t&&h-t>.3&&(a[l].isDel=!0),u<t&&(a[l].isDel=!0)),s==="floor"&&a[l].points.length<500&&(a[l].isDel=!0)}}for(let r=0;r<e.length;r++)e[r].array=e[r].array.filter(s=>!s.isDel);const i=[];for(let r=0;r<e.length;r++){const s=e[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 $r(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function Hr(n){if(!n.length)return 0;const t=[...n].sort((o,i)=>o-i),e=Math.floor(t.length/2);return t.length%2?t[e]:(t[e-1]+t[e])/2}function Yr(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),u=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2,h=Math.max(s,a,l);return u===0?{radius:1/0,maxEdge:h}:{radius:s*a*l/(4*u),maxEdge:h}}function Gr(n,t){const e=[],o=new Set,i=(r,s)=>r<s?`${r}_${s}`:`${s}_${r}`;for(let r=0;r<t.length;r+=3){const s=t[r],a=t[r+1],l=t[r+2],u=[[s,a],[a,l],[l,s]];for(const[h,d]of u){const c=i(h,d);if(o.has(c))continue;o.add(c);const[f,w]=n[h],[x,b]=n[d],M=Math.hypot(x-f,b-w);Number.isFinite(M)&&M>0&&e.push(M)}}return Hr(e)}function jr(n){const t=new Set,e=[];for(const o of n){if(!o||o.length<2)continue;const i=o[0],r=o[1];if(!Number.isFinite(i)||!Number.isFinite(r))continue;const s=`${i}_${r}`;t.has(s)||(t.add(s),e.push([i,r]))}return e}function Ur(n){const t=new Map;for(const[e,o]of n)t.has(e)||t.set(e,[]),t.has(o)||t.set(o,[]),t.get(e).push(o),t.get(o).push(e);return t}function Zr(n,t){if(!t.length)return[];const e=Ur(t),o=t[0][0],i=[],r=new Set;let s=o,a=-1;do{i.push(n[s]),r.add(s);const l=e.get(s)||[];let u=l.find(h=>h!==a&&!r.has(h));if(u===void 0&&(u=l.find(h=>h!==a)),u===void 0)break;a=s,s=u}while(s!==o&&i.length<=t.length+1);return i}function Kr(n,t={}){const{edgeFactor:e=20,alphaScale:o=2}=t;if(!n||n.length<3)return[];const i=jr(n);if(i.length<3)return[];const r=new ke(Float64Array.from(i.flat())),{triangles:s}=r;if(!s.length)return[];const a=Gr(i,s);if(!Number.isFinite(a)||a<=0)return[];const l=a*e,u=new Map,h=(f,w)=>f<w?`${f}_${w}`:`${w}_${f}`;for(let f=0;f<s.length;f+=3){const w=s[f],x=s[f+1],b=s[f+2],[M,g]=i[w],[m,p]=i[x],[P,V]=i[b],{radius:v,maxEdge:S}=Yr(M,g,m,p,P,V),z=$r(i,w,x,b)*o;if(v<=1/z&&S<=l){const D=[[w,x],[x,b],[b,w]];for(const[_,E]of D){const T=h(_,E);u.set(T,(u.get(T)||0)+1)}}}const d=[];for(const[f,w]of u)w===1&&d.push(f.split("_").map(Number));return d.length?Zr(i,d):[]}function be(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Qr(n){let t=0,e=0,o=0;for(let i=0;i<4;i++){const r=n[i],s=n[(i+1)%4],a=s.x-r.x,l=s.y-r.y,u=Math.sqrt(a*a+l*l);u>t&&(t=u,e=a/u,o=l/u)}return{longSide:t,dirX:e,dirY:o}}function Qe(n,t,e){const i=[];for(const r of n){const s=(r.start.x+r.end.x)/2,a=(r.start.y+r.end.y)/2,l=s-t,u=a-e;l*l+u*u<=3*3&&i.push(r.start.z,r.end.z)}if(i.length===0){const r=[];for(const s of n)r.push(s.start.z,s.end.z);return r.length?(r.sort((s,a)=>s-a),r[Math.floor(r.length/2)]):-1/0}return i.sort((r,s)=>r-s),i[Math.floor(i.length/2)]}function Gn(n,t,e,o,i,r){const s=i-e,a=r-o,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((n-e)**2+(t-o)**2),t:0};const u=n-e,h=t-o,d=(u*s+h*a)/l,c=e+d*s,f=o+d*a;return{dist:Math.sqrt((n-c)**2+(t-f)**2),t:d}}function Jr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((be(n.start,s.start)<=e||be(n.start,s.end)<=e)&&o++,(be(n.end,s.start)<=e||be(n.end,s.end)<=e)&&i++);let r=0;return o>=1&&i>=1?r=5:(o>=1||i>=1)&&(r=2),{left:o,right:i,score:r}}function ti(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Gn(a.x,a.y,o.x,o.y,i.x,i.y);e.push(l)}const r=e.reduce((a,l)=>a+l,0)/e.length,s=e.reduce((a,l)=>a+(l-r)**2,0)/e.length;return s<.01?3:s<.05?2:s<.1?1:0}function ei(n,t,e=.15){const o=n.end.x-n.start.x,i=n.end.y-n.start.y,r=Math.sqrt(o*o+i*i);if(r<1e-12)return 0;const s=-i/r,a=o/r,l=[[],[]];for(let d=0;d<2;d++){const c=d===0?n.start:n.end;for(const f of t){if(f===n)continue;const w=be(c,f.start),x=be(c,f.end);let b=null;if(w<=e?b=f.end:x<=e&&(b=f.start),!b)continue;const M=f.end.x-f.start.x,g=f.end.y-f.start.y,m=Math.sqrt(M*M+g*g);if(m<1e-12||Math.abs(o*M+i*g)/(r*m)>=.342)continue;const P=(b.x-c.x)*s+(b.y-c.y)*a;l[d].push(P>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const u=[...l[0],...l[1]];return u.every(d=>d===u[0])?2:1}function ni(n,t,e){const o=Jr(n,e),i=ti(n,t),r=ei(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function oi(n){const t=n.end.x-n.start.x,e=n.end.y-n.start.y;let o=Math.atan2(e,t)*(180/Math.PI);return o<0&&(o+=180),o}function ri(n,t){const e=[];for(const o of n){let i=!1;for(const r of e){const s=Math.abs(o.angle-r[0].angle);if(Math.min(s,180-s)<=t){r.push(o),i=!0;break}}i||e.push([o])}return e}function ii(n,t=.05){const e=[];for(const o of n){let i=!1;for(const r of e)if(Math.abs(o.offset-r[0].offset)<=t){r.push(o),i=!0;break}i||e.push([o])}return e}function si(n,t,e,o,i){const r=[];for(const a of n){const l=a.seg,u=(l.start.x-t.start.x)*e+(l.start.y-t.start.y)*o,h=(l.end.x-t.start.x)*e+(l.end.y-t.start.y)*o;r.push({l:Math.min(u,h),r:Math.max(u,h),idx:a.idx})}r.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:u}of r){if(s.length===0){s.push({l:a,r:l,srcIdxs:[u]});continue}const h=s[s.length-1];a<=h.r+i?(h.r=Math.max(h.r,l),h.srcIdxs.includes(u)||h.srcIdxs.push(u)):s.push({l:a,r:l,srcIdxs:[u]})}return s}function ai(n,t,e,o,i,r,s){const a=e-t,l={...n};return l.start={x:n.start.x+t*o,y:n.start.y+t*i,z:n.start.z},l.end={x:n.start.x+e*o,y:n.start.y+e*i,z:n.start.z},l.length=a,l.direction={x:o,y:i,z:0},l.rooftopPz=r,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function li(n,t){let e=!0;for(;e;){e=!1;for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o],s=n[i];if(r.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(r.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(r.end.x-s.start.x)<.001&&Math.abs(r.end.y-s.start.y)<.001,l=Math.abs(r.start.x-s.end.x)<.001&&Math.abs(r.start.y-s.end.y)<.001,u=Math.abs(r.end.x-s.end.x)<.001&&Math.abs(r.end.y-s.end.y)<.001,h=Math.abs(r.start.x-s.start.x)<.001&&Math.abs(r.start.y-s.start.y)<.001;if(!(a||l||u||h)||r.direction.x*s.direction.x+r.direction.y*s.direction.y<.98)continue;let c=r.start,f=r.end;a?f=s.end:l?c=s.start:u?f=s.start:h&&(c=s.end);const w=Math.hypot(f.x-c.x,f.y-c.y),x={...r};x.start=c,x.end=f,x.length=w,x.direction={x:(f.x-c.x)/w,y:(f.y-c.y)/w,z:0},r.rooftopPz!==void 0&&s.rooftopPz!==void 0?x.rooftopPz=Math.max(r.rooftopPz,s.rooftopPz):x.rooftopPz=r.rooftopPz!==void 0?r.rooftopPz:s.rooftopPz,x.buildRosource=r.buildRosource||s.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),n[o]=x,t[o]=[...new Set([...t[o],...t[i]])],n.splice(i,1),t.splice(i,1),i--,e=!0}}return{segments:n,sourceMap:t}}function Je(n,t=5,e=.05){if(n.length<=1)return{segments:n,sourceMap:n.map((l,u)=>[u])};const o=n.map((l,u)=>({seg:l,angle:oi(l),idx:u}));o.sort((l,u)=>l.angle-u.angle);const i=ri(o,t),r=[],s=[],a=[];for(const l of i){let u=l[0].seg;for(const M of l)M.seg.length>u.length&&(u=M.seg);const h=u.end.x-u.start.x,d=u.end.y-u.start.y,c=Math.sqrt(h*h+d*d);if(c<1e-12)continue;const f=-d/c,w=h/c,x=l.map(M=>{const g=M.seg.start.x-u.start.x,m=M.seg.start.y-u.start.y;return{seg:M.seg,offset:Math.abs(g*f+m*w),idx:M.idx}});x.sort((M,g)=>M.offset-g.offset);const b=ii(x);for(const M of b){let g=M[0].seg;for(const E of M)E.seg.length>g.length&&(g=E.seg);const m=g.end.x-g.start.x,p=g.end.y-g.start.y,P=Math.sqrt(m*m+p*p);if(P<1e-12)continue;const V=m/P,v=p/P,S=M.map(E=>E.seg.rooftopPz??0),z=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 _=si(M,g,V,v,e);for(const{l:E,r:T,srcIdxs:A}of _){if(T-E<.01)continue;const O=ai(g,E,T,V,v,z,g.buildRosource);r.push(O),s.push(A)}}}return{...li(r,s),debugRPZGroups:a}}function ci(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function ui(n,t,e){return[{x:t,y:e,z:0},{x:n[0].x,y:n[0].y,z:0},{x:n[1].x,y:n[1].y,z:0},{x:n[2].x,y:n[2].y,z:0},{x:n[3].x,y:n[3].y,z:0}]}function hi(n,t,e,o,i,r,s){const a=[{margin:r.projectionMargin,maxDist:r.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const u of a){if(l.length>0)break;for(const h of n){const d=t*r.minLengthRatio;if(h.length<d)continue;const{start:c,end:f}=h;let w=!1,x=1/0;for(const S of i){const{dist:z,t:D}=Gn(S.x,S.y,c.x,c.y,f.x,f.y);D>=-u.margin&&D<=1+u.margin&&z<=u.maxDist&&(w=!0,x=Math.min(x,z))}if(!w){`${u.maxDist}${(-u.margin).toFixed(1)}${(1+u.margin).toFixed(1)}`;continue}const b=Math.sqrt((f.x-c.x)**2+(f.y-c.y)**2);if(b<1e-12)continue;const M=(f.x-c.x)/b,g=(f.y-c.y)/b,m=Math.abs(e*M+o*g),p=Math.abs(-o*M+e*g),P=Math.max(m,p),V=Math.acos(Math.min(P,1))*(180/Math.PI);if(V>r.angleThreshold){`${V.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(b>.01){const S=[];for(let _=1;_<=4;_++){const E=i[_],T=E.x-c.x,A=E.y-c.y,O=(T*M+A*g)/b;S.push(O)}const z=Math.min(...S),D=Math.max(...S);D>z&&(v=Math.max(0,Math.min(1,D)-Math.max(0,z))/(D-z))}l.push({seg:h,minDist:x,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function fi(n,t,e,o){if(n.length<=1)return n.length===1&&(n[0].score=-1),n;for(const i of n){const{score:r,details:s}=ni(i.seg,t,e);i.score=r,i.details=s}return n.sort((i,r)=>r.embedRatio-i.embedRatio||r.score-i.score||i.minDist-r.minDist),n}function di(n,t,e,o){const i=n.end.x-n.start.x,r=n.end.y-n.start.y,s=Math.sqrt(i*i+r*r),a=i/s,l=r/s,u=t.map(v=>{const S=v.x-n.start.x,z=v.y-n.start.y;return(S*a+z*l)/s}),h=Math.min(...u),d=Math.max(...u),c=(d-h)*s,f=(h+d)/2,w=n.start.x+f*i,x=n.start.y+f*r,b=e.box.min.z,M=e.box.max.z,g=Math.abs(M-b),m=Qe(o,n.start.x,n.start.y),p=Math.max(0,b-m),P=h<=0&&d>=1,V=n.start.z+f*(n.end.z-n.start.z);return{p:{x:w,y:x,z:V},width:c,full:P,height:g,groundClearance:p}}function jn(n,t,e){var d,c,f,w,x;const o=t.map(b=>e[b]),i=[],r=[],s=[],a=[],l=[];let u,h;for(const b of o){if((d=b.points)!=null&&d.length)for(const M of b.points)i.push(M);if((c=b.originalPoints)!=null&&c.length)for(const M of b.originalPoints)r.push(M);if((f=b.doorAndBeamData)!=null&&f.length)for(const M of b.doorAndBeamData)s.push(M);if((w=b.insetionArr)!=null&&w.length)for(const M of b.insetionArr)a.push(M);if((x=b.drawWindow)!=null&&x.length)for(const M of b.drawWindow)l.push(M);b.boxData&&!u&&(u=b.boxData),b.rooftopPz!==void 0&&(h===void 0||b.rooftopPz>h)&&(h=b.rooftopPz)}i.length&&(n.points=i),r.length&&(n.originalPoints=r),s.length&&(n.doorAndBeamData=s),a.length&&(n.insetionArr=a),l.length&&(n.drawWindow=l),u&&(n.boxData=u),h!==void 0&&(n.rooftopPz=h)}function Un(n,t,e,o){var u;const i=ci(e),r=[],{segments:s,sourceMap:a}=o??Je(t),l=s;for(const h of n){const d=(u=h.coordinatesByArea)==null?void 0:u.coordinates;if(!d||d.length<4)continue;const c=d.slice(0,4),f=c.reduce((D,_)=>D+_.x,0)/4,w=c.reduce((D,_)=>D+_.y,0)/4,{longSide:x,dirX:b,dirY:M}=Qr(c);if(x<.01)continue;const g=c.reduce((D,_)=>D+_.z,0)/4,m=Qe(t,f,w);if(g<m-.3)continue;const p=ui(c,f,w);h.name;let P=hi(l,x,b,M,p,i,h.name);P=fi(P,p,t,h.name);let V=null,v=1/0,S=0;if(P.length>0){const D=P[0];V=D.seg,v=D.minDist,S=D.ratio}let z;if(V&&(z=di(V,c,h,s),!i.printOnly)){const D=V;D.drawWindow||(D.drawWindow=[]),D.drawWindow.push(z)}V&&r.push({windowName:h.name,windowCategory:h.category,windowCenter:h.center,wallSegment:V,distance:v,wallLengthRatio:S,drawWindow:z})}for(const h of r){const d=h.wallSegment,c=s.indexOf(d);if(c===-1)continue;const f=a[c];!f||f.length<=1||jn(d,f,t)}return r}function mi(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],{segments:r,sourceMap:s}=Je(n),a=Un(i,n,o,{segments:r,sourceMap:s}),l=new Set;for(const c of a){const f=r.indexOf(c.wallSegment);f>=0&&l.add(f)}const u=[],h=new Set;for(const c of l){const f=s[c];if(f){jn(r[c],f,n);for(const w of f)h.add(w)}u.push(r[c])}for(let c=0;c<n.length;c++)h.has(c)||u.push(n[c]);const d=new Set(a.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(d.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of a)c.drawWindow&&c.wallSegment&&(c.wallSegment.drawWindow||(c.wallSegment.drawWindow=[]),c.wallSegment.drawWindow.push(c.drawWindow));return{segments:u,matches:a}}exports.computeContour=je;exports.computeContourNew=Kr;exports.computeLocalFloorZ=Qe;exports.findWindowWalls=Un;exports.getAllGeometry=mo;exports.getBeamLine=Vo;exports.getColLine=zo;exports.getMergeMeaning=Xr;exports.mergeCollinearSegments=Je;exports.processData=mi;exports.updateStEdPoint=go;