rm-graphical-computing 1.0.67 → 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 +1 -1
- package/dist/index.js +4137 -3502
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $n=Object.create,ze=Object.defineProperty,On=Object.getOwnPropertyDescriptor,qn=Object.getOwnPropertyNames,Nn=Object.getPrototypeOf,yn=Object.prototype.hasOwnProperty,Wn=(t,e,n)=>()=>{if(n)throw n[0];try{return t&&(e=t(t=0)),e}catch(r){throw n=[r],r}},be=(t,e)=>()=>(e||(t((e={exports:{}}).exports,e),t=null),e.exports),Xn=(t,e)=>{let n={};for(var r in t)ze(n,r,{get:t[r],enumerable:!0});return e||ze(n,Symbol.toStringTag,{value:"Module"}),n},xn=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(var i=qn(e),o=0,s=i.length,a;o<s;o++)a=i[o],!yn.call(t,a)&&a!==n&&ze(t,a,{get:(l=>e[l]).bind(null,a),enumerable:!(r=On(e,a))||r.enumerable});return t},wn=(t,e,n)=>(n=t!=null?$n(Nn(t)):{},xn(e||!t||!t.__esModule?ze(n,"default",{value:t,enumerable:!0}):n,t)),Yn=t=>yn.call(t,"module.exports")?t["module.exports"]:xn(ze({},"__esModule",{value:!0}),t);let d=require("three");d=wn(d,1);function Hn(t,e=!1){const n=t[0].index!==null,r=new Set(Object.keys(t[0].attributes)),i=new Set(Object.keys(t[0].morphAttributes)),o={},s={},a=t[0].morphTargetsRelative,l=new d.BufferGeometry;let f=0;for(let u=0;u<t.length;++u){const c=t[u];let h=0;if(n!==(c.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const m in c.attributes){if(!r.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+'. All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.'),null;o[m]===void 0&&(o[m]=[]),o[m].push(c.attributes[m]),h++}if(h!==r.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". Make sure all geometries have the same number of attributes."),null;if(a!==c.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const m in c.morphAttributes){if(!i.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;s[m]===void 0&&(s[m]=[]),s[m].push(c.morphAttributes[m])}if(e){let m;if(n)m=c.index.count;else if(c.attributes.position!==void 0)m=c.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;l.addGroup(f,m,u),f+=m}}if(n){let u=0;const c=[];for(let h=0;h<t.length;++h){const m=t[h].index;for(let y=0;y<m.count;++y)c.push(m.getX(y)+u);u+=t[h].attributes.position.count}l.setIndex(c)}for(const u in o){const c=Xe(o[u]);if(!c)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" attribute."),null;l.setAttribute(u,c)}for(const u in s){const c=s[u][0].length;if(c!==0){l.morphAttributes=l.morphAttributes||{},l.morphAttributes[u]=[];for(let h=0;h<c;++h){const m=[];for(let M=0;M<s[u].length;++M)m.push(s[u][M][h]);const y=Xe(m);if(!y)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;l.morphAttributes[u].push(y)}}}return l}function Xe(t){let e,n,r,i=-1,o=0;for(let f=0;f<t.length;++f){const u=t[f];if(e===void 0&&(e=u.array.constructor),e!==u.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(n===void 0&&(n=u.itemSize),n!==u.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(r===void 0&&(r=u.normalized),r!==u.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=u.gpuType),i!==u.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;o+=u.count*n}const s=new e(o),a=new d.BufferAttribute(s,n,r);let l=0;for(let f=0;f<t.length;++f){const u=t[f];if(u.isInterleavedBufferAttribute){const c=l/n;for(let h=0,m=u.count;h<m;h++)for(let y=0;y<n;y++){const M=u.getComponent(h,y);a.setComponent(h+c,y,M)}}else s.set(u.array,l);l+=u.count*n}return i!==void 0&&(a.gpuType=i),a}var Gn=(t,e,n)=>{let r=new d.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(t),i.push(e);let o=new d.BufferGeometry;o.setFromPoints(i),o.rotateX(-Math.PI/2),n.add(new d.Line(o,r))},te=(t,e,n,r,i=1e-8)=>{const o=e.x-t.x,s=e.y-t.y,a=r.x-n.x,l=r.y-n.y,f=o*l-s*a;if(Math.abs(f)<i)return null;const u=((n.x-t.x)*l-(n.y-t.y)*a)/f,c=((n.x-t.x)*s-(n.y-t.y)*o)/f;return u<-i||u>1+i||c<-i||c>1+i?null:{point:new d.Vector3(t.x+u*o,t.y+u*s,t.z)}},jn=(t,e,n={})=>{const{fontSize:r=36,fontFamily:i="sans-serif",backgroundColor:o="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=n,f=document.createElement("canvas").getContext("2d");f.font=`bold ${r}px ${i}`;const u=f.measureText(t).width;let c=Math.min(u+a*2,l),h=r+a*2;const m=document.createElement("canvas");m.width=c,m.height=h;const y=m.getContext("2d");y.fillStyle=o,y.fillRect(0,0,c,h),y.fillStyle=s,y.font=`bold ${r}px ${i}`,y.textAlign="center",y.textBaseline="middle",u>l-a*2?Un(y,t,c/2,h/2,l,r):y.fillText(t,c/2,h/2);const M=new d.CanvasTexture(m),S=new d.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),z=new d.Sprite(S);z.position.set(e.x,e.y,e.z);const g=.005;return z.scale.set(c*g,h*g,1),z};function Un(t,e,n,r,i,o){const s=e.split("");let a="",l=o*1.2,f=r;for(let u=0;u<s.length;u++){const c=a+s[u];t.measureText(c).width>i&&u>0?(t.fillText(a,n,f),a=s[u],f+=l):a=c}t.fillText(a,n,f)}var re=(t,e,n=.01)=>{const r=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),i=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(r<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const o={x:t.x/r,y:t.y/r,z:t.z/r},s={x:e.x/i,y:e.y/i,z:e.z/i};let a=o.x*s.x+o.y*s.y+o.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),f=l<=n;return{parallel:f,sameDirection:f?a>0:null,angle:l}},Zn=(t,e,n,r)=>{const i=t;let o=[];if(r&&r.length&&(o=r.map(p=>p.clone())),!i||i.length<4)return{};const s=new d.Vector3().subVectors(i[1],i[0]).normalize(),a=new d.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let f=1/0,u=-1/0,c=1/0,h=-1/0;for(const p of i){const v=p.dot(s),P=p.dot(a);v<f&&(f=v),v>u&&(u=v),P<c&&(c=P),P>h&&(h=P)}const m=i[0].dot(l),y=s.clone().multiplyScalar(f).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(m)),M=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(c)).add(l.clone().multiplyScalar(m)),S=s.clone().multiplyScalar(u).add(a.clone().multiplyScalar(h)).add(l.clone().multiplyScalar(m)),z=s.clone().multiplyScalar(f).add(a.clone().multiplyScalar(h)).add(l.clone().multiplyScalar(m));let g=[y,M,S,z],b=re(new d.Vector3().subVectors(y,M),new d.Vector3(0,0,1));b&&b.parallel&&(g=[y,z,S,M]);let x=0;if(r.length>0){const p=new d.Vector3().subVectors(g[1],g[0]).normalize(),v=p.clone().negate(),P=new d.Vector3().subVectors(g[3],g[0]).normalize(),V=P.clone().negate();let _=g[0].distanceTo(g[1]),D=g[0].distanceTo(g[3]),T=_/e,E=D/n,A=.001;for(let I=0;I<T;I++){let B=g[0],k=0;for(let L=0;L<E;L++){let O=B.clone().addScaledVector(p,e),C=O.clone().addScaledVector(P,n),N=B.clone().addScaledVector(P,n),W=new d.Vector3().add(B).add(O).add(C).add(N).multiplyScalar(.25);for(let q=0;q<o.length;q++)if(o[q].distanceTo(W)<A){k++;break}B=N}if(k>=E/2)break;x+=k,g[0]=g[0].addScaledVector(p,e),g[3]=g[3].addScaledVector(p,e)}_=g[0].distanceTo(g[1]),T=_/e;for(let I=0;I<T;I++){let B=g[1],k=0;for(let L=0;L<E;L++){let O=B.clone().addScaledVector(v,e),C=O.clone().addScaledVector(P,n),N=B.clone().addScaledVector(P,n),W=new d.Vector3().add(B).add(O).add(C).add(N).multiplyScalar(.25);for(let q=0;q<o.length;q++)if(o[q].distanceTo(W)<A){k++;break}B=N}if(k>=E/2)break;x+=k,g[1]=g[1].addScaledVector(v,e),g[2]=g[2].addScaledVector(v,e)}_=g[0].distanceTo(g[1]),T=_/e;for(let I=0;I<E;I++){let B=g[3],k=0;for(let L=0;L<T;L++){let O=B.clone().addScaledVector(p,e),C=O.clone().addScaledVector(V,n),N=B.clone().addScaledVector(V,n),W=new d.Vector3().add(B).add(O).add(C).add(N).multiplyScalar(.25);for(let q=0;q<o.length;q++)if(o[q].distanceTo(W)<A){k++;break}B=O}if(k>=T/2)break;x+=k,g[2]=g[2].addScaledVector(V,n),g[3]=g[3].addScaledVector(V,n)}}const w=g[0].distanceTo(g[1])*g[0].distanceTo(g[3]);return{facePoints:g,boxArea:w,totalInPlaneNum:x}},Jt=(t,e,n,r,i=d.MathUtils.degToRad(8))=>{const o=new d.Vector3,s=new d.Vector3;o.subVectors(new d.Vector3(e.x,e.y,0),new d.Vector3(t.x,t.y,0)).normalize(),s.subVectors(new d.Vector3(r.x,r.y,0),new d.Vector3(n.x,n.y,0)).normalize();const a=o.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),f=1-Math.min(l/i,1),u=a>0?"same":"opposite";return{parallelism:f,angle:l,angleDeg:d.MathUtils.radToDeg(l),isParallel:l<i,direction:u,vectors:{v1:o,v2:s}}},oe=(t,e,n,r)=>{const i=new d.Vector3().subVectors(e,t),o=new d.Vector3().subVectors(r,n),s=i.length(),a=o.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),o.normalize();const l=Math.abs(i.dot(o)),f=Math.min(1,Math.max(0,l)),u=Math.acos(f),c=d.MathUtils.radToDeg(u),h=1-f;return{rate:h,percent:`${(h*100).toFixed(2)}%`,angle:c,isPerpendicular:Math.abs(c-90)<.01,isParallel:c<.01}},ee=(t,e,n=!1)=>new d.Vector3((t.x+e.x)/2,(t.y+e.y)/2,n?0:(t.z+e.z)/2),ne=(t,e,n,r,i={})=>{const{parallelAngleMax:o=d.MathUtils.degToRad(10),collinearAngleMax:s=d.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,f=new d.Vector3().subVectors(e,t),u=new d.Vector3().subVectors(r,n),c=f.clone().normalize(),h=u.clone().normalize();let m=d.MathUtils.clamp(c.dot(h),-1,1);const y=Math.acos(Math.abs(m)),M=d.MathUtils.radToDeg(y);if(y>o)return{type:"not_parallel",angleDeg:M,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};m<0&&h.negate();const S=new d.Vector3().addVectors(c,h).normalize(),z=new d.Vector3().addVectors(t,e).multiplyScalar(.5),g=Ye(n,z,c),b=Ye(r,z,c),x=(g+b)/2,w=Math.max(g,b),p=t.dot(S),v=e.dot(S),P=n.dot(S),V=r.dot(S),_=Math.min(p,v),D=Math.max(p,v),T=Math.min(P,V),E=Math.max(P,V),A=D-_,I=E-T,B=Math.min(A,I),k=Math.min(D,E)-Math.max(_,T),L=k<0?-k:0,O=k>0?k:0,C=B>0?O/B:0,N=Kn(t,e,n,r),W=y<=s&&x<a;let q;return W?q=C>.5?"collinear_overlap":"collinear_gap":y<=o&&(q="parallel_offset"),{type:q,angleDeg:M,avgPerpendicularDistance:x,maxPerpendicularDistance:w,gap:L,overlap:O,closestDistance:N}};function Ye(t,e,n){const r=new d.Vector3().subVectors(t,e),i=r.dot(n),o=n.clone().multiplyScalar(i);return new d.Vector3().subVectors(r,o).length()}function Kn(t,e,n,r){const i=new d.Vector3().subVectors(e,t),o=new d.Vector3().subVectors(r,n),s=new d.Vector3().subVectors(n,t),a=i.dot(i),l=i.dot(o),f=o.dot(o),u=i.dot(s),c=o.dot(s),h=a*f-l*l;let m,y;h<1e-10?(m=0,y=f!==0?c/f:0):(m=(l*c-f*u)/h,y=(a*c-l*u)/h),m=d.MathUtils.clamp(m,0,1),y=f!==0?d.MathUtils.clamp((l*m+c)/f,0,1):0,m=a!==0?d.MathUtils.clamp((l*y-u)/a,0,1):0;const M=t.clone().add(i.clone().multiplyScalar(m)),S=n.clone().add(o.clone().multiplyScalar(y));return M.distanceTo(S)}var He=(t,e)=>Math.round(Math.max(5,Math.min(350,e*Math.sqrt(t)))),Qn=t=>{let e=new d.Vector3(t.start.x,t.start.y,t.start.z),n=new d.Vector3(t.end.x,t.end.y,t.end.z),r=e.distanceTo(n),i=t.rooftopPz-t.start.z,o=He(r,100),s=He(i,70),a=i/s,l=new Map;for(let M=0;M<s;M++)l.set((M+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let f=new d.Line3(e,n);const u=t.originalPoints,c=new d.Vector3;for(let M=0;M<u.length;M++){const S=u[M];let z=f.closestPointToPoint(S,!0,c).distanceTo(S);const g=Math.floor(z/a);if(g<s){const b=l.get((g+1)*a);b.count++,S.z<b.minZ&&(b.minZ=S.z),S.z>b.maxZ&&(b.maxZ=S.z)}}let h,m,y=o/2;for(const[M,S]of l)if(S.count>=y){h=S.minZ;break}for(const[M,S]of[...l.entries()].reverse())if(S.count>=y){m=S.maxZ;break}return{minZ:h,maxZ:m}},Ve=(t,e,n)=>{let r=new d.Plane;const i=new d.Vector3(t.x,t.y,t.z),o=new d.Vector3(e.x,e.y,e.z),s=new d.Vector3(e.x,e.y,e.z+5);r.setFromCoplanarPoints(i,o,s);const a=[],l=[];n.forEach(S=>{const z=new d.Vector3;r.projectPoint(S,z),l.push(z.clone()),z.z=i.z,a.push(z)});let f=new d.Vector3,u=new d.Vector3;r.projectPoint(i,f),r.projectPoint(o,u);const c=new d.Line3(f,u),h=[],m=[],y=[];let M=new d.Vector3;return a.forEach((S,z)=>{c.closestPointToPoint(S,!0,M).distanceTo(S)<.001?(h.push(n[z]),m.push(l[z])):y.push(S)}),{newOriginalPoints:h,newProjectPoints:y,newOnLinePoints:m}},Jn=t=>{function e(n,r,i,o,s,a,l,f,u){let c=new d.Line3(n,r),h=new Map,m=new d.Vector3,y=n.clone(),M=r.clone(),S=0;for(;;){let z=new Map,g=0;for(let b=0;b<u.checkResults.length;b++)if(!(u.checkResults[b].allCenterPoints.length/f*100<1))for(let x=0;x<u.checkResults[b].allCenterPoints.length;x++){if(h.has(b)&&h.get(b).removePtsIndex.includes(x))continue;let w=u.checkResults[b].allCenterPoints[x];w=new d.Vector3(w.x,w.y,w.z);let p=c.closestPointToPoint(w,!0,m),v=w.distanceTo(p);Math.abs(v-s)<.01&&(g++,z.has(b)?z.get(b).removePtsIndex.push(x):z.set(b,{index:b,removePtsIndex:[x]}))}if(S==l){n=y,r=M;break}if(g<a/20*18||g==0){z.clear(),l-S<5&&(n=y,r=M,h.clear());break}else{S++;for(const[b,x]of z)h.has(b)?h.get(b).removePtsIndex.push(...x.removePtsIndex):h.set(b,x);z.clear(),n=n.addScaledVector(i,o),r=r.addScaledVector(i,o),c.set(n,r)}}if(h.size>0&&S!=l)for(const[z,g]of h){let b=[],x=[];for(let w=0;w<u.checkResults[z].allCenterPoints.length;w++)g.removePtsIndex.includes(w)||(b.push(u.checkResults[z].allCenterPoints[w]),x.push(u.checkResults[z].originalVertices[w]));u.checkResults[z].allCenterPoints=b,u.checkResults[z].originalVertices=x}}for(let n=0;n<t.length;n++){const r=t[n];if(r.length<.5)continue;let i=-1,o=-1;if(!r.checkResults||r.checkResults.length<=0)continue;if(r.checkResults[0].originalVertices&&r.checkResults[0].originalVertices.length>0){let[w,p,v,P]=r.checkResults[0].originalVertices[0];w=new d.Vector3(w.x,w.y,w.z),p=new d.Vector3(p.x,p.y,p.z),v=new d.Vector3(v.x,v.y,v.z),P=new d.Vector3(P.x,P.y,P.z),i=w.distanceTo(p),o=w.distanceTo(P);let V=re(new d.Vector3().subVectors(w,p).normalize(),new d.Vector3(0,0,1));V&&V.parallel&&([o,i]=[i,o])}if(i<0||o<0)continue;let s=new d.Vector3(r.start.x,r.start.y,r.start.z),a=new d.Vector3(r.end.x,r.end.y,r.end.z);const l=s.distanceTo(a),f=r.rooftopPz-r.start.z,u=Math.ceil(l/i),c=Math.ceil(f/o);let h=s.clone(),m=a.clone(),y=m.clone().add(new d.Vector3(0,0,f)),M=h.clone().add(new d.Vector3(0,0,f)),S=new d.Vector3().subVectors(m,h).normalize(),z=S.clone().negate();new d.Vector3().subVectors(y,h).normalize().clone().negate();let g=i/2;o/2;let b=l*f/(i*o);e(h,M,S,i,g,c,u,b,r),e(m,y,z,i,g,c,u,b,r),r.start=h,r.end=m;const{newOriginalPoints:x}=Ve(h,m,r.originalPoints);r.originalPoints=x}},Ct=(t,e)=>new d.Vector3(t.x,t.y,0).distanceTo(new d.Vector3(e.x,e.y,0)),tr=(t,e,n=1e-6)=>{const r=new d.Vector3;return t.closestPointToPoint(e,!0,r),r.distanceTo(e)<n},Se=t=>{let e=0,n=[];for(let r=0;r<t.length;r++)for(let i=r+1;i<t.length;i++){const o=t[r].distanceTo(t[i]);o>e&&(e=o,n=[t[r],t[i]])}return n},Et=(t,e,n=.03)=>Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n&&Math.abs(t.z-e.z)<n,er=()=>`#${Math.floor(Math.random()*75+180).toString(16).padStart(2,"0")}${Math.floor(Math.random()*75+180).toString(16).padStart(2,"0")}${Math.floor(Math.random()*75+180).toString(16).padStart(2,"0")}`,nr=(t,e=.001)=>{const n=new Map,r=[];for(const i of t){const o=`${Math.round(i.x/e)},${Math.round(i.y/e)},${Math.round(i.z/e)}`;n.has(o)||(n.set(o,!0),r.push(i))}return r},rr=class{results;clusterResults;constructor(){this.results=null}initLimits1(t,e){let n,r;return t<.3?n=5:t<.5?n=8:t<.8?n=10:t<1?n=15:t<2?n=30:t<3?n=35:t<4?n=40:t<5?n=45:t<6?n=50:t<7?n=60:t<8.5?n=70:t<10?n=80:t<15?n=100:t<20?n=120:t<25?n=140:t<30?n=160:t<35?n=180:t<40?n=200:t<45?n=230:t<50?n=250:n=350,e<1?r=30:e<2?r=40:e<2.5?r=45:e<3?r=60:e<3.6?r=70:e<4&&(r=80),{horizontalSubdivisions:n,verticalSubdivisions:r}}initLimits2(t,e){return{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,t/.08))),verticalSubdivisions:Math.round(Math.max(30,Math.min(80,e/.06)))}}initLimits4(t,e){return{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,65*Math.sqrt(t))))*1,verticalSubdivisions:Math.round(Math.max(30,Math.min(80,15*Math.sqrt(e))))*1}}initLimits3(t,e){let n;return t<2?n=.06:t<10?n=.1:n=.15,{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,t/n))),verticalSubdivisions:Math.round(Math.max(30,Math.min(80,e/.06)))}}createWallPlaneMeshFromFourPoints(t,e,n,r,i,o,s=16777215){const a=[t,e,n,r];for(let M=0;M<a.length;M++)this.isValidVector3(a[M])||(console.error(`点${M+1}包含无效数据:`,a[M]),a[M]=new d.Vector3(M,0,M));const l=new d.BufferGeometry,f=new Float32Array([a[0].x,a[0].y,a[0].z,a[1].x,a[1].y,a[1].z,a[2].x,a[2].y,a[2].z,a[3].x,a[3].y,a[3].z]),u=[0,1,2,0,2,3],c=new Float32Array([0,0,1,0,1,1,0,1]);l.setAttribute("position",new d.BufferAttribute(f,3)),l.setAttribute("uv",new d.BufferAttribute(c,2)),l.setIndex(u),l.computeVertexNormals();const h=new d.Mesh(l,i),m=new d.EdgesGeometry(l),y=new d.LineSegments(m,new d.LineBasicMaterial({color:s}));return o.add(y),h}createSubdividedWallPlane(t,e,n,r,i){const o=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return o;const s=new d.Vector3(t.start.x,t.start.y,t.start.z),a=new d.Vector3(t.end.x,t.end.y,t.end.z),l=[s,a,new d.Vector3(t.end.x,t.end.y,t.rooftopPz),new d.Vector3(t.start.x,t.start.y,t.rooftopPz)];for(let M=0;M<l.length;M++)if(!this.isValidVector3(l[M]))return console.error(`墙体基础点${M}无效:`,l[M]),o;const f=s.distanceTo(a),u=Math.abs(t.rooftopPz-t.start.z);if(f===0||u===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",s),console.log("bottomRight",a),console.log(t.length),o;const c=f/n,h=u/e,m=new d.Vector3().subVectors(a,s).normalize(),y=new d.Vector3(0,0,1);for(let M=0;M<e;M++)for(let S=0;S<n;S++)try{const z={points:[new d.Vector3().copy(s).add(m.clone().multiplyScalar(S*c)).add(y.clone().multiplyScalar(M*h)),new d.Vector3().copy(s).add(m.clone().multiplyScalar((S+1)*c)).add(y.clone().multiplyScalar(M*h)),new d.Vector3().copy(s).add(m.clone().multiplyScalar((S+1)*c)).add(y.clone().multiplyScalar((M+1)*h)),new d.Vector3().copy(s).add(m.clone().multiplyScalar(S*c)).add(y.clone().multiplyScalar((M+1)*h))],userData:{}};z.userData={type:"wallSegment",row:M,col:S,originalMaterial:r,width:c,height:h},o.push(z)}catch(z){console.error(`创建墙体小平面(${M}, ${S})时出错:`,z)}return o}calculateMinRequiredPoints(t){const n=Math.floor(Math.log1p(t)*.5);return Math.max(1,n)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,n,r){if(e===0)return!1;const i=t.area,o=t.minRequiredPoints,s=t.expectedDensity,a=e/Math.max(i,.001),l=e>=o,f=a>=s*.3;let u=!0;return i<.5&&e>0&&(u=this.checkSmallAreaDistribution(t,n,r)),l&&f&&u}checkSmallAreaDistribution(t,e,n){if(e.length<2)return!0;const r=e.map(a=>n[a]);t.bounds;const i=t.center;let o=0;const s=Math.sqrt(t.area)*.3;return r.forEach(a=>{a.distanceTo(i)<=s&&o++}),o/r.length>=.3}getFailureReason(t,e){const n=t.area,r=t.minRequiredPoints,i=t.expectedDensity,o=e/Math.max(n,.001),s=[];return e===0?s.push("无点"):(e<r&&s.push(`点数不足: ${e}/${r}`),o<i*.3&&s.push(`密度不足: ${o.toFixed(2)}/${i.toFixed(2)}`),n<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||s.push("小平面分布不均"))),s.length>0?s.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((r,i)=>r-i),n=Math.floor(e.length/2);return e.length%2!==0?e[n]:(e[n-1]+e[n])/2}isPointInBoundingBox(t,e,n=.1){return t.x>=e.min[0]-n&&t.x<=e.max[0]+n&&t.y>=e.min[1]-n&&t.y<=e.max[1]+n&&t.z>=e.min[2]-n&&t.z<=e.max[2]+n}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const n=e.attributes.position;if(n.count<3)return null;const r=new d.Vector3().fromBufferAttribute(n,0),i=new d.Vector3().fromBufferAttribute(n,1),o=new d.Vector3().fromBufferAttribute(n,2);r.applyMatrix4(t.matrixWorld),i.applyMatrix4(t.matrixWorld),o.applyMatrix4(t.matrixWorld);const s=new d.Plane;return s.setFromCoplanarPoints(r,i,o),s}analyzePointDistribution(t,e,n=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:n,analysisTime:null};const r=performance.now(),i=[];t.forEach(o=>{if(o.userData&&o.userData.type==="wallSegment"){const s=this.getWorldVerticesNew(o.points);if(s.length<4)return;const a=new d.Vector3().add(s[0]).add(s[1]).add(s[2]).add(s[3]).multiplyScalar(.25);o.userData.center=a,o.vertices=s,i.push(o)}}),this.results.totalSegments=i.length;for(const o of i){if(o.vertices.length<4)continue;const s=o.userData.center,a=`row${o.userData.row}_col${o.userData.col}`,[l,f,u,c]=o.vertices,h=new d.Vector3().subVectors(f,l).normalize(),m=new d.Vector3().subVectors(c,l).normalize(),y=l.distanceTo(f),M=l.distanceTo(c),S=new d.Plane;S.setFromCoplanarPoints(l,f,c);const z=y/2,g=M/2;for(let b=0;b<e.length;b++)this.isPointInWallSegmentOptimized(e[b],s,S,l,h,m,y,M,z,g,n)&&(this.results.pointsInSegments.has(a)||this.results.pointsInSegments.set(a,[]),this.results.pointsInSegments.get(a).push(b))}return i.forEach(o=>{const s=`row${o.userData.row}_col${o.userData.col}`,a=this.results.pointsInSegments.has(s)?this.results.pointsInSegments.get(s).length:0;a>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:o.userData.row,col:o.userData.col,width:o.userData.width,height:o.userData.height,segmentKey:s,vertices:o.vertices,center:o.userData.center,mesh:o,pointCount:a,hasPointsButNotEnough:a>0&&a<1}))}),this.results.analysisTime=performance.now()-r,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,n,r,i,o,s,a,l,f,u){if(Math.abs(n.distanceToPoint(t))>u)return!1;const c=new d.Vector3().subVectors(t,e),h=Math.abs(c.dot(i)),m=Math.abs(c.dot(o));if(h>l&&m>f)return!1;const y=new d.Vector3().subVectors(t,r),M=y.dot(i),S=y.dot(o),z=M>=-u&&M<=s+u,g=S>=-u&&S<=a+u;return z&&g}isPointInWallSegment(t,e,n,r=.1){if(!t.geometry)return!1;try{const i=this.getWorldVertices(t);return i.length<4?!1:this.isPointInRotatedWall(i,e,n,r)}catch(i){return console.error("判断点是否在墙体平面内时出错:",i),!1}}isPointInRotatedWall(t,e,n,r=.1){const[i,o,s,a]=t,l=new d.Plane;if(l.setFromCoplanarPoints(i,o,a),Math.abs(l.distanceToPoint(e))>r)return!1;const f=new d.Vector3().subVectors(o,i).normalize(),u=new d.Vector3().subVectors(a,i).normalize();new d.Vector3().crossVectors(f,u).normalize();const c=new d.Vector3().subVectors(e,i),h=c.dot(f),m=c.dot(u),y=i.distanceTo(o),M=i.distanceTo(a),S=h>=-r&&h<=y+r,z=m>=-r&&m<=M+r;return S&&z&&n.distanceTo(e)<y/2&&n.distanceTo(e)<M/2}getWorldVertices(t){if(t._cachedWorldVertices&&t.matrixWorld.equals(t._cachedMatrixWorld))return t._cachedWorldVertices;const e=t.geometry.getAttribute("position"),n=[];for(let r=0;r<Math.min(4,e.count);r++){const i=new d.Vector3;i.fromBufferAttribute(e,r),i.applyMatrix4(t.matrixWorld),n.push(i)}return t._cachedWorldVertices=n,t._cachedMatrixWorld=t.matrixWorld.clone(),n}getWorldVerticesNew(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n].clone();e.push(r)}return e}getWallSegmentBounds(t){if(!t.geometry)return null;const e=t.geometry.getAttribute("position"),n=new d.Box3;for(let r=0;r<e.count;r++){const i=new d.Vector3;i.fromBufferAttribute(e,r),i.applyMatrix4(t.matrixWorld),n.expandByPoint(i)}return{min:n.min.toArray(),max:n.max.toArray(),center:n.getCenter(new d.Vector3).toArray(),size:n.getSize(new d.Vector3).toArray()}}highlightEmptySegments(t,e,n,r=1){if(!this.results){console.warn("请先运行分析函数");return}const i=new Map,o=new Map;this.results.missingSegments.forEach(u=>{i.set(u.segmentKey,u),o.has(u.row)||o.set(u.row,new Map),o.get(u.row).set(u.col,{segmentKey:u.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(u=>{if(u.userData&&u.userData.type==="wallSegment"){const c=`row${u.userData.row}_col${u.userData.col}`,h=i.has(c);o.has(u.userData.row)||o.set(u.userData.row,new Map),o.get(u.userData.row).has(u.userData.col)||o.get(u.userData.row).set(u.userData.col,{segmentKey:c,isEmpty:h,visited:!1})}});const s=[],a=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,c]of i){const h=o.get(c.row)?.get(c.col);if(h&&!h.visited){const m=[],y=[[c.row,c.col]];for(h.visited=!0;y.length>0;){const[M,S]=y.shift(),z=`row${M}_col${S}`;i.has(z)&&m.push(i.get(z));for(const[g,b]of a){const x=M+g,w=S+b;if(o.has(x)&&o.get(x).has(w)){const p=o.get(x).get(w);!p.visited&&p.isEmpty&&(p.visited=!0,y.push([x,w]))}}}m.length>=r&&s.push(m)}}const l=this.createClusterMaterials(s.length),f=[];return this.clusterResults={clusters:s.sort((u,c)=>c.length-u.length),highlightedMeshes:f,clusterMaterials:l,totalClusters:s.length,totalHighlighted:f.length},this.clusterResults}calculateBoundaryRegularity(t,e,n,r,i){let o=0,s=0;const a=e;let l=!0;for(let M=r;M<=i;M++)t.has(a)&&t.get(a).has(M)?s++:l=!1;l&&o++;const f=n;let u=!0;for(let M=r;M<=i;M++)t.has(f)&&t.get(f).has(M)?s++:u=!1;u&&o++;const c=r;let h=!0;for(let M=e;M<=n;M++)t.has(M)&&t.get(M).has(c)?s++:h=!1;h&&o++;const m=i;let y=!0;for(let M=e;M<=n;M++)t.has(M)&&t.get(M).has(m)?s++:y=!1;return y&&o++,o/4}calculateClusterQualityScore(t){const i=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+i*.2}calculateStrictClusterBounds(t){if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(l=>{l.vertices&&l.vertices.length>0&&e.push(...l.vertices)}),e.length===0){const l=[...new Set(t.map(f=>f.row))];return{width:[...new Set(t.map(f=>f.col))].length*(t[0].bounds?.width||1),height:l.length*(t[0].bounds?.height||1)}}const n=Math.min(...e.map(l=>l.x)),r=Math.max(...e.map(l=>l.x)),i=Math.min(...e.map(l=>l.y)),o=Math.max(...e.map(l=>l.y)),s=Math.min(...e.map(l=>l.z)),a=Math.max(...e.map(l=>l.z));return{width:Math.abs(r-n),height:Math.max(Math.abs(o-i),Math.abs(a-s))}}createClusterMaterials(t){const e=[],n=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let r=0;r<t;r++){const i=n[r%n.length],o=new d.MeshBasicMaterial({color:i,transparent:!0,opacity:.6,side:d.DoubleSide});e.push(o)}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,n)=>{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(n=>n.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(n=>{n.userData&&n.userData.originalMaterial&&(n.material=n.userData.originalMaterial,delete n.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new d.Group;return t.traverse(n=>{if(n.userData&&n.userData.type==="wallSegment"){const r=this.getWorldVertices(n);if(r.length<4)return;const i=new d.Vector3().add(r[0]).add(r[1]).add(r[2]).add(r[3]).multiplyScalar(.25),o=new d.Vector3().subVectors(r[1],r[0]).normalize(),s=new d.Vector3().subVectors(r[3],r[0]).normalize(),a=new d.Vector3().crossVectors(o,s).normalize(),l=new d.ArrowHelper(a,i,.3,16711680),f=new d.ArrowHelper(o,i,.2,65280),u=new d.ArrowHelper(s,i,.2,255);e.add(l),e.add(f),e.add(u)}}),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(n=>{n.isMesh&&n.geometry&&e.push(n)}),e.length===0)return null;try{const n=e.map(s=>s.geometry);n.forEach((s,a)=>{s.applyMatrix4(e[a].matrixWorld)});const r=Hn(n),i=e[0].material.clone(),o=new d.Mesh(r,i);return o.name="mergedWalls",o}catch(n){return console.error("合并网格时出错:",n),null}}},or=t=>{let e={};const n=[],r=[],i=[];return t[0].width,t[0].height,t.forEach(o=>{r.push(...o.vertices),i.push(o.center),n.push(o.vertices)}),e.originalVertices=n,e.allCenterPoints=i,e},ir=t=>{const e=new d.Vector3().copy(t.start).add(t.end).multiplyScalar(.5),n=new d.Vector3().subVectors(new d.Vector3(e.x,e.y,e.z+1),e).normalize(),r=new d.Vector3(t.direction.x,t.direction.y,0);r.applyAxisAngle(n,Math.PI/2);const i=new d.Vector3().copy(e).add(r.clone().multiplyScalar(t.length)),o=new d.Vector3().copy(e).sub(r.clone().multiplyScalar(t.length));return e.z=t.start.z,i.z=t.start.z,o.z=t.start.z,{start:i,end:o,center:e,direction:r}},sr=(t,e,n=!0)=>{let r=[];if(!t)return[];for(let i=0;i<t.length;i++){const o=t[i];if(!o)continue;let s=new d.Vector3(o.start.x,o.start.y,o.start.z);s.applyEuler(new d.Euler(-Math.PI/2,0,0));let a=new d.Vector3(o.end.x,o.end.y,o.end.z);if(a.applyEuler(new d.Euler(-Math.PI/2,0,0)),e.add(jn(String(i),new d.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(o.isBayWindow||o.isWindow)&&n)continue;const l=new d.Plane().setFromCoplanarPoints(new d.Vector3(o.start.x,o.start.y,o.start.z),new d.Vector3(o.end.x,o.end.y,o.end.z),new d.Vector3(o.start.x,o.start.y,o.rooftopPz)),f=[];o.originalPoints.forEach((p,v)=>{const P=new d.Vector3;l.projectPoint(p,P),f.push(P)});const u=new d.Vector3(o.start.x,o.start.y,o.start.z).distanceTo(new d.Vector3(o.end.x,o.end.y,o.end.z)),c=Math.abs(o.rooftopPz-o.start.z),h=new d.MeshBasicMaterial({color:"red",side:d.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),m=new d.Group,y=new rr,{horizontalSubdivisions:M,verticalSubdivisions:S}=y.initLimits4(u,c),z=y.createSubdividedWallPlane(o,S,M,h,m);y.analyzePointDistribution(z,f,.01);const g=new d.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:d.DoubleSide}),b=y.highlightEmptySegments(z,g,m),x=[];for(const p of b.clusters){const v=or(p);v&&x.push(v)}const w=ir(o).direction;o.checkResults=x,o.verticalDirection=w,o.originaIndex=i,r.push(o)}return r},ar=(t,e)=>{console.log("lines",t);for(let n=0;n<t.length;n++){const r=t[n],i=[];r.originalPoints.forEach(b=>{let x=new d.Vector3(b.x,b.y,0),w=!1;for(let p=0;p<i.length;p++)if(Et(x,i[p],.01)){w=!0;break}w||i.push(x)});const o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(r.length)))),s=1;let a=new d.Vector3(r.start.x,r.start.y,r.start.z),l=new d.Vector3(r.end.x,r.end.y,r.end.z),f=new d.Vector3().subVectors(l,a).normalize(),u=f.clone().cross(new d.Vector3(0,0,1)).normalize(),c=u.clone().negate(),h=[];const m=[];let y=r.length/o;console.log(y);for(let b=0;b<o;b++){const x=[];x.push(a.clone().addScaledVector(u,s)),x.push(x[0].clone().addScaledVector(f,y)),x.push(x[1].clone().addScaledVector(c,s*2)),x.push(a.clone().addScaledVector(c,y));let w=[];for(let p=0;p<i.length;p++)h.includes(p)||cr(i[p],x)&&(h.push(p),w.push(i[p]));w.length>0&&m.push(ur(w)),a=a.addScaledVector(f,y)}const M=new Float32Array(i.length*3);i.forEach((b,x)=>{M[x*3]=b.x,M[x*3+1]=b.y,M[x*3+2]=b.z});const S=new d.BufferGeometry;S.setAttribute("position",new d.BufferAttribute(M,3)),S.rotateX(-Math.PI/2),e.add(new d.Points(S,new d.PointsMaterial({color:er(),size:.02})));const[z,g]=mr(m,{plane:"xy",trimRatio:0});Gn(z,g,e)}};function Ge(t,e="xy"){if(e==="xy")return{x:t.x,y:t.y};if(e==="xz")return{x:t.x,y:t.z};if(e==="yz")return{x:t.y,y:t.z};throw new Error(`Unsupported plane: ${e}`)}function lr(t,e,n){const r=e.x-t.x,i=e.y-t.y,o=n.x-t.x;return r*(n.y-t.y)-i*o}function cr(t,e,n="xy"){if(!e||e.length!==4)throw new Error("rectPoints must contain 4 points");const r=Ge(t,n),i=e.map(a=>Ge(a,n));let o=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],f=i[(a+1)%4],u=lr(l,f,r);if(u>1e-9&&(o=!0),u<-1e-9&&(s=!0),o&&s)return!1}return!0}function ur(t){if(!t||t.length===0)return null;const e=new d.Vector3(0,0,0);for(const n of t)Array.isArray(n)?(e.x+=n[0],e.y+=n[1],e.z+=n[2]):(e.x+=n.x,e.y+=n.y,e.z+=n.z);return e.divideScalar(t.length),e}function hr(t){return t instanceof d.Vector3?t.clone():Array.isArray(t)?new d.Vector3(t[0],t[1],t[2]):new d.Vector3(t.x,t.y,t.z)}function fr(t,e="xy"){const n=hr(t);if(e==="xy")return{x:n.x,y:n.y,up:n.z};if(e==="xz")return{x:n.x,y:n.z,up:n.y};if(e==="yz")return{x:n.y,y:n.z,up:n.x};throw new Error(`Unsupported plane: ${e}`)}function je(t,e,n,r="xy"){if(r==="xy")return new d.Vector3(t,e,n);if(r==="xz")return new d.Vector3(t,n,e);if(r==="yz")return new d.Vector3(n,t,e);throw new Error(`Unsupported plane: ${r}`)}function dr(t,e,n){if(Math.abs(e)<1e-12)return t>=n?{x:1,y:0}:{x:0,y:1};const i=t+n,o=t*n-e*e,s=Math.sqrt(Math.max(0,i*i*.25-o)),a=i*.5+s;let l=e,f=a-t;const u=Math.hypot(l,f);return u<1e-12?{x:1,y:0}:{x:l/u,y:f/u}}function mr(t,e={}){const{plane:n="xy",trimRatio:r=0}=e;if(!t||t.length<2)return null;const i=t.map(I=>fr(I,n));let o=0,s=0,a=0;for(const I of i)o+=I.x,s+=I.y,a+=I.up;o/=i.length,s/=i.length,a/=i.length;let l=0,f=0,u=0;for(const I of i){const B=I.x-o,k=I.y-s;l+=B*B,f+=B*k,u+=k*k}l/=i.length,f/=i.length,u/=i.length;const c=dr(l,f,u),h={x:-c.y,y:c.x},m=[];for(const I of i){const B=I.x-o,k=I.y-s,L=B*c.x+k*c.y,O=B*h.x+k*h.y;m.push({s:L,t:O,up:I.up})}m.sort((I,B)=>I.s-B.s);const y=m.length;let M=Math.floor(y*r),S=Math.ceil(y*(1-r))-1;M=Math.max(0,Math.min(y-1,M)),S=Math.max(0,Math.min(y-1,S));const z=m[M],g=m[S],b=(()=>{const I=m.map(k=>k.t).sort((k,L)=>k-L),B=Math.floor(I.length/2);return I.length%2===0?(I[B-1]+I[B])*.5:I[B]})(),x=(()=>{const I=m.map(k=>k.up).sort((k,L)=>k-L),B=Math.floor(I.length/2);return I.length%2===0?(I[B-1]+I[B])*.5:I[B]})(),w=z.s,p=g.s,v=b,P=b,V=x,_=x,D=o+c.x*w+h.x*v,T=s+c.y*w+h.y*v,E=o+c.x*p+h.x*P,A=s+c.y*p+h.y*P;return[je(D,T,V,n),je(E,A,_,n)]}var gr=async(t,e,n,r,i)=>{if(r&&r.length>0)for(let x=0;x<r.length;x++){const w=r[x];w.isLine2=!0,t.push(w)}if(Jn(t,i),t.length<=0||e.length<=0)return t;n||(n=[]);for(const x of t){let w=[];if(!(!x.checkResults||x.checkResults.length<=0)){for(let p=0;p<x.checkResults.length;p++){let D=function(I){for(;_[I]!==I;)_[I]=_[_[I]],I=_[I];return I};var b=D;const v=x.checkResults[p];if(v.isDoor=!1,!v.originalVertices||v.originalVertices.length==0)continue;const P=[];v.originalVertices.forEach(I=>{let B=[];I.forEach(k=>{B.push(new d.Vector3(k.x,k.y,k.z))}),P.push(B)});const V=P.length,_=Array.from({length:V},(I,B)=>B);for(let I=0;I<V;I++)for(let B=I+1;B<V;B++){const k=P[I],L=P[B];if(k.some(O=>L.some(C=>O.equals(C)))){const O=D(I),C=D(B);O!==C&&(_[O]=C)}}const T=new Map;let E=-1,A=-1;for(let I=0;I<V;I++){const B=D(I);T.has(B)||T.set(B,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const k=T.get(B);let[L,O,C,N]=P[I];const W=new d.Vector3().add(L).add(O).add(C).add(N).multiplyScalar(.25);if(k.points.push(...P[I]),k.area+=L.distanceTo(O)*L.distanceTo(N),k.originalVertices.push(P[I]),k.index=p,k.centerPts.push(W),E==-1||A==-1){let q=new d.Vector3().subVectors(L,O).normalize();A=L.distanceTo(N),E=L.distanceTo(O);let H=re(q,new d.Vector3(0,0,1));H&&H.parallel&&([A,E]=[E,A])}k.gridWidth=E,k.gridHeight=A}w.push(...T.values())}x.mergeCheckRegion=w}}let o=new Map;for(const x of t){if(x.length<.3)continue;let w=x.rooftopPz-x.start.z,p=Math.floor(x.rooftopPz-x.start.z);o.has(p)?o.set(p,{num:o.get(p).num+1,totalHeight:o.get(p).totalHeight+w}):o.set(p,{num:1,totalHeight:w})}let s=[...o.entries()].reduce((x,w)=>w[1].num>x[1].num?w:x);s[0],s[1].totalHeight/s[1].num;const a=[];for(let x=0;x<n.length;x++){const w=n[x];if(w.isFindBeam=!1,w.category=="door"){let p=[];w.coordinatesByArea.coordinates.forEach(D=>{p.push(new d.Vector3(D.x,D.y,D.z))}),p[0].equals(p[p.length-1])&&p.pop();let v=p[0].distanceTo(p[1]),P=p[0].distanceTo(p[3]);P>v&&([v,P]=[P,v],p=[p[0],p[3],p[2],p[1]]);let V=ee(p[0],p[3],!0),_=ee(p[1],p[2],!0);a.push({doorStartPt:V,doorEndPt:_,boxPoints:p,minZ:w.coordinatesByArea.heightData.minZ,maxZ:w.coordinatesByArea.heightData.maxZ,index:x,isFind:!1,inWall:!1})}}for(let x=0;x<a.length;x++){const w=a[x];for(let p=0;p<t.length;p++){if(t[p].length<.5)continue;let v=[];const P=ee(t[p].start,t[p].end,!0);v.push(P),v.push(ee(P,t[p].start,!0)),v.push(ee(P,t[p].end,!0));let V=!1;const _=w.boxPoints.length;for(let D=0;D<v.length;D++){const T=v[D].x,E=v[D].y;for(let A=0,I=_-1;A<_;I=A++){const B=w.boxPoints[A].x,k=w.boxPoints[A].y,L=w.boxPoints[I].x,O=w.boxPoints[I].y;k>E!=O>E&&T<(L-B)*(E-k)/(O-k)+B&&(V=!V)}if(V)break}if(V){let D=new d.Vector3(t[p].start.x,t[p].start.y,0),T=new d.Vector3(t[p].end.x,t[p].end.y,0),E=w.doorStartPt.distanceTo(w.doorEndPt),A=D.distanceTo(T),I=Jt(w.doorStartPt,w.doorEndPt,D,T);if(Math.abs(A-E)<.5&&I&&I.angleDeg<15){w.doorStartPt=new d.Vector3(t[p].start.x,t[p].start.y,0),w.doorEndPt=new d.Vector3(t[p].end.x,t[p].end.y,0);break}else if(Math.abs(A-E)>1.3&&I&&I.angleDeg<15){let B=ne(w.doorStartPt,w.doorEndPt,D,T,{parallelAngleMax:d.MathUtils.degToRad(15)}),k=w.doorStartPt.distanceTo(D),L=w.doorStartPt.distanceTo(T),O=w.doorEndPt.distanceTo(D),C=w.doorEndPt.distanceTo(T),N=k<.2||L<.2||O<.2||C<.2;if(B&&B.type=="collinear_overlap"&&B.maxPerpendicularDistance<.1&&!N){w.inWall=!0;break}else{let W=new d.Line3(D,T),q=W.closestPointToPoint(w.doorStartPt,!0,new d.Vector3),H=W.closestPointToPoint(w.doorEndPt,!0,new d.Vector3),nt=q.distanceTo(w.doorStartPt),K=H.distanceTo(w.doorEndPt);if(nt<.1||K<.1){w.inWall=!0;break}}}}else continue}}let l=0,f=[],u=[],c=[];const h=[];let m=.15;for(let x=0;x<t.length;x++){const w=t[x];if(w.noDetection||(w.doorAndBeamData=[],!w.mergeCheckRegion||w.mergeCheckRegion.length==0))continue;w.completePointAreaPercentage=-1;let p=new d.Box3;p.setFromPoints(w.originalPoints);let v=p.max.z;p.min.z;const P=new d.Vector3(w.start.x,w.start.y,w.start.z),V=new d.Vector3(w.end.x,w.end.y,w.end.z);let _=w.rooftopPz-w.start.z,D=0;for(const E of w.mergeCheckRegion){const{facePoints:A,boxArea:I,totalInPlaneNum:B}=Zn(E.points,E.gridWidth,E.gridHeight,E.centerPts);if(!A||A.length<=0)continue;A[0].distanceTo(A[1]);let k=A[0].distanceTo(A[3]);const L=E.gridHeight*(k/E.gridHeight/3*2)+E.gridHeight/2;let O=new d.Vector3(A[0].x,A[0].y,A[0].z+L),C=new d.Vector3(A[1].x,A[1].y,A[1].z+L);const N=new d.Line3(O,C),W=[];let q=new d.Vector3;E.points.forEach(rt=>{N.closestPointToPoint(rt,!0,q).distanceTo(rt)<E.gridHeight+.01&&W.push(rt)});let H=[],nt=[];for(;;){let rt=[];for(let $=0;$<W.length;$++)nt.includes($)||rt.length==0&&(rt.push(W[$]),nt.push($));for(let $=0;$<W.length;$++)if(!nt.includes($)){for(let Y=0;Y<rt.length;Y++)if(W[$].distanceTo(rt[Y])<E.gridWidth+.01){rt.push(W[$]),nt.push($),$=-1;break}}if(rt.length==0)break;H.push(rt)}const K=[];for(let rt=0;rt<H.length;rt++){const $={lineSt:new d.Vector3,lineEd:new d.Vector3,facePoints:[]};let Y=Se(H[rt]);Array.isArray(Y)&&Y.length==2&&($.lineSt=Y[0],$.lineEd=Y[1],$.facePoints.push(new d.Vector3(Y[0].x,Y[0].y,A[0].z)),$.facePoints.push(new d.Vector3(Y[1].x,Y[1].y,A[0].z)),$.facePoints.push(new d.Vector3(Y[1].x,Y[1].y,A[2].z)),$.facePoints.push(new d.Vector3(Y[0].x,Y[0].y,A[2].z)),K.push($))}D+=E.area;let et=0;if(B!=0&&(et=E.gridHeight*E.gridWidth*B),(E.area-et)/I*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const $=K[rt];let Y=$.facePoints[0].distanceTo($.facePoints[1]),dt=$.facePoints[0].distanceTo($.facePoints[3]),Xt=Y/w.length*100,Rt=w.rooftopPz-$.facePoints[2].z;if(dt<1.5||v<$.facePoints[2].z||Rt>_/3*2)continue;let kt=!1,Vt=!1,Mt=!1,At=[],J=$.facePoints[2].clone(),at=$.facePoints[3].clone(),X=$.facePoints[0].clone(),Z=$.facePoints[1].clone(),ae=!1,Ht=-1;if(Math.abs($.facePoints[0].z-w.start.z)<.25){if(Y>.17&&w.length>.5){let qt=Ct(P,X),Q=Ct(P,Z),mt=Ct(V,X),G=Ct(V,Z);const wt=.1,ct=10;if(qt<wt||Q<wt){const{newOriginalPoints:Lt}=Ve(X,Z,w.originalPoints),_t=[],Nt=[];if(Lt.forEach(lt=>{lt.z>=J.z?_t.push(lt):lt.z<=X.z&&Nt.push(lt)}),_t.length>10){const lt=new d.Vector3(w.start.x,w.start.y,0),xt=new d.Vector3(w.end.x,w.end.y,0),zt=new d.Vector3().subVectors(lt,xt).normalize();let Gt=new d.Vector3,j=1/0,R=-1,pt=!1,vt=!1;for(let tt=0;tt<t.length;tt++){if(tt==x)continue;const gt=new d.Vector3(t[tt].start.x,t[tt].start.y,0),Pt=new d.Vector3(t[tt].end.x,t[tt].end.y,0),Ft=te(lt,xt,gt,Pt);let Bt=oe(lt,xt,gt,Pt);if(Ft!=null){if(Bt&&Bt.angle>85){let U=Ft.point.distanceTo(lt);if(Ft.point.distanceTo(xt),U<.3){vt=!0,j=1/0,R=-1;break}}continue}if(Bt&&Bt.angle>85){let U=Jt(lt,xt,new d.Line3(gt,Pt).closestPointToPoint(lt,!0,Gt),lt);if(!U||U.direction!="same")continue;const ut=lt.clone().addScaledVector(zt,ct),it=xt.clone().addScaledVector(zt.clone().negate(),ct);let ot=new d.Vector3().subVectors(Pt,gt).normalize();const ft=te(ut,it,gt.clone().addScaledVector(ot.clone().negate(),.03),Pt.clone().addScaledVector(ot,.03));if(ft==null)continue;let Dt=lt.distanceTo(ft.point);Dt<j&&(j=Dt,R=tt)}else if(Bt&&Bt.angle<5){const U=new d.Vector3(X.x,X.y,0),ut=new d.Vector3(Z.x,Z.y,0);let it=Ct(U,gt),ot=Ct(U,Pt),ft=Ct(ut,gt),Dt=Ct(ut,Pt),It=Jt(lt,xt,gt,U),Ut=!1;for(let $t=0;$t<t[tt].checkResults.length;$t++){let Pe=[];for(let Zt=0;Zt<t[tt].checkResults[$t].allCenterPoints.length;Zt++)Pe.push(new d.Vector3(t[tt].checkResults[$t].allCenterPoints[Zt].x,t[tt].checkResults[$t].allCenterPoints[Zt].y,0));let Kt=Se(Pe);if(Kt.length==2){let Zt=Ct(U,Kt[0]),Ae=Ct(U,Kt[1]),Be=Ct(ut,Kt[0]),Ie=Ct(ut,Kt[1]);if(Zt<.2||Ae<.2||Be<.2||Ie<.2){Ut=!0;break}}}if(It&&It.direction=="same"&&!Ut&&(it<.1||ot<.1||ft<.1||Dt<.1)){pt=!0,j=1/0,R=-1;break}}}if(j!=1/0&&j<2&&(w.length-Y>.2||w.length-Y<.02)&&j<Y*3)t[R].length>.25&&Y+j>.5&&(ae=!0,qt<wt?(at=at.addScaledVector(zt,j),X=X.addScaledVector(zt,j)):(J=J.addScaledVector(zt,j),Z=Z.addScaledVector(zt,j)));else{if(!pt&&!vt&&w.length-Y>.1)continue;if(!pt&&!vt&&w.length-Y<.1&&w.length<1.8)continue}}else continue}if(mt<wt||G<wt){const{newOriginalPoints:Lt}=Ve(X,Z,w.originalPoints),_t=[],Nt=[];if(Lt.forEach(lt=>{lt.z>=J.z?_t.push(lt):lt.z<=X.z&&Nt.push(lt)}),_t.length>10){const lt=new d.Vector3(w.start.x,w.start.y,0),xt=new d.Vector3(w.end.x,w.end.y,0),zt=new d.Vector3().subVectors(xt,lt).normalize();let Gt=new d.Vector3,j=1/0,R=-1,pt=!1,vt=!1;for(let tt=0;tt<t.length;tt++){if(tt==x)continue;const gt=new d.Vector3(t[tt].start.x,t[tt].start.y,0),Pt=new d.Vector3(t[tt].end.x,t[tt].end.y,0),Ft=te(lt,xt,gt,Pt);let Bt=oe(lt,xt,gt,Pt);if(Ft!=null){if(Bt&&Bt.angle>85&&(Ft.point.distanceTo(lt),Ft.point.distanceTo(xt)<.3)){vt=!0,j=1/0,R=-1;break}continue}if(Bt&&Bt.angle>85){let U=Jt(xt,lt,new d.Line3(gt,Pt).closestPointToPoint(xt,!0,Gt),xt);if(!U||U.direction!="same")continue;const ut=lt.clone().addScaledVector(zt.clone().negate(),ct),it=xt.clone().addScaledVector(zt,ct);let ot=new d.Vector3().subVectors(Pt,gt).normalize();const ft=te(ut,it,gt.clone().addScaledVector(ot.clone().negate(),.03),Pt.clone().addScaledVector(ot,.03));if(ft==null)continue;let Dt=xt.distanceTo(ft.point);Dt<j&&(j=Dt,R=tt)}else if(Bt&&Bt.angle<5){const U=new d.Vector3(X.x,X.y,0),ut=new d.Vector3(Z.x,Z.y,0);let it=Ct(U,gt),ot=Ct(U,Pt),ft=Ct(ut,gt),Dt=Ct(ut,Pt),It=Jt(xt,lt,gt,U),Ut=!1;for(let $t=0;$t<t[tt].checkResults.length;$t++){let Pe=[];for(let Zt=0;Zt<t[tt].checkResults[$t].allCenterPoints.length;Zt++)Pe.push(new d.Vector3(t[tt].checkResults[$t].allCenterPoints[Zt].x,t[tt].checkResults[$t].allCenterPoints[Zt].y,0));let Kt=Se(Pe);if(Kt.length==2){let Zt=Ct(U,Kt[0]),Ae=Ct(U,Kt[1]),Be=Ct(ut,Kt[0]),Ie=Ct(ut,Kt[1]);if(Zt<.2||Ae<.2||Be<.2||Ie<.2){Ut=!0;break}}}if(It&&It.direction=="same"&&!Ut&&(it<.1||ot<.1||ft<.1||Dt<.1)){pt=!0,j=1/0,R=-1;break}}}if(j!=1/0&&j<2&&(w.length-Y>.2||w.length-Y<.02)&&j<Y*3)t[R].length>.25&&Y+j>.5&&(ae=!0,mt<wt?(at=at.addScaledVector(zt,j),X=X.addScaledVector(zt,j)):(J=J.addScaledVector(zt,j),Z=Z.addScaledVector(zt,j)));else{if(!pt&&!vt&&w.length-Y>.1)continue;if(!pt&&!vt&&w.length-Y<.1&&w.length<1.8)continue}}else continue}Y=at.distanceTo(J)}if(Xt<85&&Y>.3||Y>.7&&dt>_-_/3){let qt=!1;for(let Q=0;Q<e.length;Q++){let mt=Q+1;if(mt>=e.length)continue;let G=new d.Vector3(e[Q].x,e[Q].y,e[Q].z),wt=new d.Vector3(e[mt].x,e[mt].y,e[mt].z);if(te(new d.Vector3(G.x,G.y,0),new d.Vector3(wt.x,wt.y,0),new d.Vector3($.facePoints[0].x,$.facePoints[0].y,0),new d.Vector3($.facePoints[1].x,$.facePoints[1].y,0),.1)!=null){qt=!0;break}}for(let Q=0;Q<a.length;Q++){let mt=new d.Vector3(a[Q].doorStartPt.x,a[Q].doorStartPt.y,0),G=new d.Vector3(a[Q].doorEndPt.x,a[Q].doorEndPt.y,0),wt=new d.Vector3($.facePoints[0].x,$.facePoints[0].y,0),ct=new d.Vector3($.facePoints[1].x,$.facePoints[1].y,0),Lt=$.facePoints[2].z<a[Q].maxZ||Math.abs($.facePoints[2].z-a[Q].maxZ)<.3;if(Math.abs($.facePoints[2].z-a[Q].maxZ),Lt){let _t=ne(mt.clone(),G.clone(),wt.clone(),ct.clone(),{distanceThreshold:2});if(_t&&_t.type=="collinear_gap"){let Nt=ee(mt,G),lt=new d.Line3(new d.Vector3(w.start.x,w.start.y,0),new d.Vector3(w.end.x,w.end.y,0)),xt=new d.Vector3,zt=lt.closestPointToPoint(Nt,!0,xt);if(Nt.distanceTo(zt)<.15){let Gt=wt.distanceTo(mt),j=ct.distanceTo(mt);if(Gt>.25&&j>.25){let vt=wt.distanceTo(G),tt=ct.distanceTo(G);if(vt>.2&&tt>.2)continue}Vt=!0,Mt=!0,At.push(a[Q].index),a[Q].isFind=!0,Ht=Q,n[a[Q].index].isFindBeam=!0;let R=new d.Vector3().subVectors(wt,ct).normalize(),pt=mt.distanceTo(G)-_t.overlap;j<Gt&&R.negate(),Gt>j?(J=$.facePoints[2].clone().addScaledVector(R,pt),at=$.facePoints[3].clone(),X=at.clone(),Z=J.clone(),X.z=Z.z=$.facePoints[0].z):(J=$.facePoints[2].clone(),at=$.facePoints[3].clone().addScaledVector(R,pt),X=at.clone(),Z=J.clone(),X.z=Z.z=$.facePoints[0].z)}}else if(_t&&_t.type=="collinear_overlap"&&_t.maxPerpendicularDistance<.35){let Nt=wt.distanceTo(ct),lt=G.distanceTo(mt);if(Math.abs(Nt-_t.overlap)<.25||Math.abs(lt-_t.overlap)<.25){if(lt>Nt&&Math.abs(lt-_t.overlap)>1){let xt=wt.distanceTo(mt),zt=wt.distanceTo(G),Gt=ct.distanceTo(mt),j=ct.distanceTo(G),R=xt<zt?xt:zt,pt=Gt<j?Gt:j,vt=new d.Vector3().subVectors(wt,ct).normalize(),tt=lt-_t.overlap;R<pt?(vt.negate(),J=$.facePoints[2].clone().addScaledVector(vt,tt),at=$.facePoints[3].clone(),X=at.clone(),Z=J.clone(),X.z=Z.z=$.facePoints[0].z):(J=$.facePoints[2].clone(),at=$.facePoints[3].clone().addScaledVector(vt,tt),X=at.clone(),Z=J.clone(),X.z=Z.z=$.facePoints[0].z)}Vt=!0,Mt=!0,At.push(a[Q].index),a[Q].isFind=!0,n[a[Q].index].isFindBeam=!0,Ht=Q}}}}if(!Mt&&Y<1.5)for(let Q=0;Q<a.length;Q++){if(a[Q].inWall)continue;let mt=new d.Vector3(a[Q].doorStartPt.x,a[Q].doorStartPt.y,0),G=new d.Vector3(a[Q].doorEndPt.x,a[Q].doorEndPt.y,0),wt=new d.Vector3($.facePoints[0].x,$.facePoints[0].y,0),ct=new d.Vector3($.facePoints[1].x,$.facePoints[1].y,0),Lt=new d.Vector3().subVectors(mt,G).normalize(),_t=new d.Vector3().subVectors(wt,ct).normalize(),Nt=.25,lt=te(mt.clone().addScaledVector(Lt,Nt),G.clone().addScaledVector(Lt.clone().negate(),Nt),wt.clone().addScaledVector(_t,Nt),ct.clone().addScaledVector(_t.clone().negate(),Nt)),xt=!0,zt=mt.distanceTo(wt),Gt=mt.distanceTo(ct),j=G.distanceTo(wt),R=G.distanceTo(ct);(zt<m||Gt<m||j<m||R<m||lt)&&xt&&(n[a[Q].index].isFindBeam=!0,Vt=!0,a[Q].isFind=!0,Ht=Q)}(Vt||qt||Math.abs(dt-_)>.1&&dt>_/2&&Y>.3)&&(kt=!0)}}if(kt){let qt=!1;for(let j=0;j<c.length;j++){let R=ne(c[j].start,c[j].end,X,Z);if(R&&R.type=="collinear_overlap"&&R.maxPerpendicularDistance<.01){qt=!0;break}}if(qt){Ht!=-1&&(n[a[Ht].index].isFindBeam=!1,a[Ht].isFind=!1);continue}c.push({start:X,end:Z});{new d.PointsMaterial({color:65535,size:.01});let j=new d.Vector3().subVectors(X,Z),R=new d.Vector3().subVectors(Z,X),pt=1/0,vt=1/0,tt=X.clone(),gt=Z.clone();const Pt=[],Ft=[];let Bt=new d.Line3(J,at),U=new d.Vector3,ut=999999;if(w.originalPoints.forEach(it=>{if(it.z-X.z<dt/2+.1&&it.z-X.z>dt/2-.1&&Pt.push(it),it.z>J.z){let ot=Bt.closestPointToPoint(it,!0,U),ft=new d.Vector3().subVectors(ot,J),Dt=re(j,new d.Vector3().subVectors(ot,at)),It=re(R,ft);Dt&&Dt.parallel&&!Dt.sameDirection&&It&&It.parallel&&!It.sameDirection&&Ft.push(it)}}),Pt.length>0){const{newProjectPoints:it}=Ve(X,Z,Pt);for(const ot of it)ot.z=X.z;it.forEach(ot=>{let ft=new d.Vector3(ot.x,ot.y,X.z),Dt=new d.Vector3().subVectors(ft,Z),It=re(j,new d.Vector3().subVectors(ft,X)),Ut=re(R,Dt);if(It&&It.parallel&&It.sameDirection){let $t=ft.distanceTo(X);$t<pt&&(pt=$t,tt=ft)}else if(Ut&&Ut.parallel&&Ut.sameDirection){let $t=ft.distanceTo(Z);$t<vt&&(vt=$t,gt=ft)}})}if(tt.equals(X)||(X=tt,at=new d.Vector3(X.x,X.y,at.z)),gt.equals(Z)||(Z=gt,J=new d.Vector3(Z.x,Z.y,J.z)),Ft.length>10){const{newOnLinePoints:it}=Ve(at,J,Ft);for(let ot=0;ot<it.length;ot++){let ft=Bt.closestPointToPoint(it[ot],!0,U).distanceTo(it[ot]);ft>.02&&ut>ft&&(ut=ft)}J.z+=ut,at.z+=ut,dt+=ut}}let Q=Z.distanceTo(X);if(Q<.4&&!Vt||Q<.3&&Vt)continue;u.includes(x)||u.push(x),w.checkResults[E.index].isDoor=!0;let mt="",G={id:l,beamStart:J,beamEnd:at,beamHeight:w.rooftopPz-J.z,doorStart:X,doorEnd:Z,doorHeight:dt,nearId:-1,type:mt,isExtend:ae,isDoor:Vt,isPullOutDoor:Mt,pcbDoorIndexs:At,beamNearWallVec:new d.Vector3(0,0,0)},wt=!1,ct=new d.Vector3,Lt=new d.Vector3,_t=-1,Nt=-1,lt=-1;for(let j=0;j<f.length;j++){const R=t[f[j].linesIndex].doorAndBeamData[f[j].doorIndex];if(R.nearId!=-1)continue;let pt=Jt(J.clone(),at.clone(),R.beamStart.clone(),R.beamEnd.clone());if(pt&&pt.isParallel){let vt=J.distanceTo(at),tt=R.beamStart.distanceTo(R.beamEnd),gt=new d.Line3(J.clone(),at.clone());gt.start.z=0,gt.end.z=0;let Pt=ee(R.beamStart,R.beamEnd,!0);tt>vt&&(gt.start=new d.Vector3(R.beamStart.x,R.beamStart.y,0),gt.end=new d.Vector3(R.beamEnd.x,R.beamEnd.y,0),Pt=ee(J,at,!0));let Ft=new d.Vector3,Bt=gt.closestPointToPoint(Pt,!0,Ft),U=Bt.distanceTo(Pt),ut=new d.Vector3().subVectors(Pt,Bt).normalize(),it=ut.clone().negate(),ot=Pt.clone().addScaledVector(it,U+.1),ft=te(gt.start,gt.end,Pt,ot),Dt=!Vt&&!R.isDoor&&(vt>tt*2||tt>vt*2);if(U<.4&&ft!=null&&!Dt){R.nearId=l,G.nearId=R.id;let It=.8;(R.isDoor||G.isDoor)&&(R.isDoor=!0,G.isDoor=!0);const Ut=At.some($t=>R.pcbDoorIndexs.includes($t));vt<tt?vt>It&&!R.isPullOutDoor?(R.beamStart=J.clone().addScaledVector(it,U),R.beamEnd=at.clone().addScaledVector(it,U),R.doorStart=X.clone().addScaledVector(it,U),R.doorEnd=Z.clone().addScaledVector(it,U),R.doorHeight=G.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):!Mt||Mt&&R.isPullOutDoor&&Ut?(G.beamStart=R.beamStart.clone().addScaledVector(ut,U),G.beamEnd=R.beamEnd.clone().addScaledVector(ut,U),G.doorStart=R.doorStart.clone().addScaledVector(ut,U),G.doorEnd=R.doorEnd.clone().addScaledVector(ut,U),G.doorHeight=R.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight):(R.beamStart=J.clone().addScaledVector(it,U),R.beamEnd=at.clone().addScaledVector(it,U),R.doorStart=X.clone().addScaledVector(it,U),R.doorEnd=Z.clone().addScaledVector(it,U),R.doorHeight=G.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):vt>tt&&(tt>It&&!Mt?(G.beamStart=R.beamStart.clone().addScaledVector(it,U),G.beamEnd=R.beamEnd.clone().addScaledVector(it,U),G.doorStart=R.doorStart.clone().addScaledVector(it,U),G.doorEnd=R.doorEnd.clone().addScaledVector(it,U),G.doorHeight=R.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight):!R.isPullOutDoor||Mt&&R.isPullOutDoor&&Ut?(R.beamStart=J.clone().addScaledVector(ut,U),R.beamEnd=at.clone().addScaledVector(ut,U),R.doorStart=X.clone().addScaledVector(ut,U),R.doorEnd=Z.clone().addScaledVector(ut,U),R.doorHeight=G.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):(G.beamStart=R.beamStart.clone().addScaledVector(it,U),G.beamEnd=R.beamEnd.clone().addScaledVector(it,U),G.doorStart=R.doorStart.clone().addScaledVector(it,U),G.doorEnd=R.doorEnd.clone().addScaledVector(it,U),G.doorHeight=R.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight)),_t=G.nearId,ct=R.beamStart.clone(),Lt=R.beamEnd.clone(),wt=!0,Nt=f[j].linesIndex,lt=f[j].doorIndex;break}}}let xt=!1;if(!wt){let j=new d.Line3(X.clone(),Z.clone());for(let R=0;R<t.length;R++){if(t[R].length<.5||R==x)continue;let pt=new d.Vector3(t[R].start.x,t[R].start.y,t[R].start.z),vt=new d.Vector3(t[R].end.x,t[R].end.y,t[R].end.z),tt=ne(pt,vt,X,Z),gt=Jt(pt,vt,X,Z);const Pt=Qn(t[R]);if(tt&&tt.maxPerpendicularDistance<.5){if(gt&>.isParallel){let ot=new d.Line3(pt,vt),ft=new d.Vector3(X.x,X.y,pt.z),Dt=ot.closestPointToPoint(ft,!0,new d.Vector3),It=oe(Dt,ft,X,Z);It&&It.angle>85&&(G.beamNearWallVec=new d.Vector3().subVectors(Dt,ft).normalize())}const Ft=[];t[R].originalPoints.forEach(ot=>{ot.z>X.z+.2&&ot.z<X.z+dt/2&&Ft.push(new d.Vector3(ot.x,ot.y,X.z))});const Bt=new d.Vector3;let U=[],ut=[];for(let ot=0;ot<Ft.length;ot++){let ft=j.closestPointToPoint(Ft[ot],!0,Bt);ft.distanceTo(Ft[ot])<.15&&(U.push(Ft[ot]),ut.push(ft.clone()))}for(let ot=0;ot<ut.length;ot++)tr(j,ut[ot])&&U.push(ut[ot]);if(U=ut,U=nr(U),U.length<150)continue;let it=Se(U);if(it.length==2){let ot=it[0].distanceTo(it[1]);if(Math.abs(ot-j.distance())<.3){let ft=new d.Line3(pt,vt),Dt=new d.Vector3(X.x,X.y,pt.z),It=ft.closestPointToPoint(Dt,!0,new d.Vector3);if(G.beamNearWallVec=new d.Vector3().subVectors(It,Dt).normalize(),G.beamStart.z>Pt.maxZ-.03&&Y>1)xt=!0;else if(qt=!0,Ht!=-1&&(n[a[Ht].index].isFindBeam=!1,a[Ht].isFind=!1),Nt!=-1&<!=-1){const Ut=t[Nt].doorAndBeamData[lt];Ut.nearId=-1}break}}if(qt)break}else tt&&tt.type=="collinear_overlap"&&tt.maxPerpendicularDistance>.3&&tt.maxPerpendicularDistance<.7&&(xt=!0)}if(qt){if(Y<1.8)continue;xt=!0}}let zt=!1;if(_t!=-1)for(let j=0;j<h.length&&!(h[j].length==1&&(h[j][0].id==l?(h[j].push({id:_t,beamStart:ct,beamEnd:Lt}),zt=!0):h[j][0].id==_t&&(h[j].push({id:l,beamStart:J,beamEnd:at}),zt=!0),zt));j++);zt||h.push([{id:l,beamStart:J,beamEnd:at}]);const Gt=G.doorStart.distanceTo(G.doorEnd);if(Vt?mt="door":Gt>1.8?mt="beam":mt=xt&&Gt>1?"beam":"hole",G.type=mt,G.nearId!=-1&&mt=="hole"){let j=!1;for(let R=0;R<t.length;R++)if(t[R].doorAndBeamData){for(let pt=0;pt<t[R].doorAndBeamData.length;pt++)if(t[R].doorAndBeamData[pt].nearId==l&&t[R].doorAndBeamData[pt].type=="beam"){t[R].doorAndBeamData[pt].type=mt,j=!0;break}if(j)break}}if(w.doorAndBeamData.push(G),f.push({linesIndex:x,doorIndex:w.doorAndBeamData.length-1}),l++,Mt&&Y<2)break}}}let T=w.length*(w.rooftopPz-w.start.z);w.completePointAreaPercentage=D/T*100}if(u.length>1)for(let x=0;x<u.length;x++){let w=[];for(let p=0;p<t[u[x]].doorAndBeamData.length;p++){let v=!1;if(t[u[x]].doorAndBeamData[p].type==="beam"&&t[u[x]].doorAndBeamData[p].beamNearWallVec.x==0&&t[u[x]].doorAndBeamData[p].beamNearWallVec.y==0&&t[u[x]].doorAndBeamData[p].beamNearWallVec.z==0&&t[u[x]].doorAndBeamData[p].nearId==-1&&(v=!0),!v){let P=t[u[x]].doorAndBeamData[p].doorStart.clone(),V=t[u[x]].doorAndBeamData[p].doorEnd.clone();P.z=V.z=0;let _=P.distanceTo(V);for(let D=0;D<u.length;D++)if(x!=D)for(let T=0;T<t[u[D]].doorAndBeamData.length;T++){let E=t[u[D]].doorAndBeamData[T].doorStart.clone(),A=t[u[D]].doorAndBeamData[T].doorEnd.clone();E.z=A.z=0,E.distanceTo(A);let I=ne(P,V,E,A);if(I.type=="collinear_overlap"&&I.maxPerpendicularDistance<.2){let B=new d.Line3(E,A),k=ee(P,V),L=B.closestPointToPoint(k,!0,new d.Vector3),O=k.distanceTo(L);if(Math.abs(_-I.overlap)<.1&&O<.04){t[u[D]].doorAndBeamData[T].nearId==t[u[x]].doorAndBeamData[p].id&&(t[u[D]].doorAndBeamData[T].nearId=-1),v=!0;break}}}}v||w.push(t[u[x]].doorAndBeamData[p])}w.length!=t[u[x]].doorAndBeamData.length&&(t[u[x]].doorAndBeamData=w)}let y=.65,M=2,S=[],z=[];for(let x=0;x<a.length;x++){if(a[x].isFind||a[x].inWall)continue;let w=new d.Vector3(a[x].doorStartPt.x,a[x].doorStartPt.y,0),p=new d.Vector3(a[x].doorEndPt.x,a[x].doorEndPt.y,0),v=new d.Vector3().subVectors(w,p).normalize();for(let P=0;P<t.length;P++){if(t[P].length<.7||t[P].completePointAreaPercentage>60)continue;let V=new d.Vector3(t[P].start.x,t[P].start.y,0),_=new d.Vector3(t[P].end.x,t[P].end.y,0),D=new d.Vector3().subVectors(V,_).normalize(),T=.3,E=w.clone().addScaledVector(v,T),A=p.clone().addScaledVector(v.clone().negate(),T),I=V.clone().addScaledVector(D,T),B=_.clone().addScaledVector(D.clone().negate(),T);te(E,A,I,B);let k=Jt(E,A,I,B),L=w.distanceTo(V)>p.distanceTo(V)?p:w,O=L.distanceTo(V),C=L.distanceTo(_);if((O<m||C<m)&&k&&!k.isParallel){let N=w.distanceTo(V)<w.distanceTo(_)?V:_,W=!1;for(let q=0;q<t.length;q++){if(q==P||S.includes(q)||t[q].length<.7)continue;let H=new d.Vector3(t[q].start.x,t[q].start.y,0),nt=new d.Vector3(t[q].end.x,t[q].end.y,0),K=new d.Vector3().subVectors(H,nt).normalize(),et=K.clone().negate(),rt=H.clone().addScaledVector(K,5),$=nt.clone().addScaledVector(et,5),Y=oe(V,_,H,nt),dt=ne(V,_,H,nt),Xt=te(V,_,rt,$),Rt=!0;if(Xt!=null&&(Rt=Xt.point.distanceTo(V)<m||Xt.point.distanceTo(_)<m),(Y&&Y.angle>85||dt&&dt.type=="collinear_gap")&&Rt){let kt=new d.Line3(V,_),Vt=new d.Vector3,Mt=kt.closestPointToPoint(H,!0,Vt),At=kt.closestPointToPoint(nt,!0,Vt),J=Mt.distanceTo(H),at=At.distanceTo(nt),X,Z;if(J>at&&at>y)X=nt,Z=At;else if(J<at&&J>y)X=H,Z=Mt;else continue;if(J=N.distanceTo(H),at=N.distanceTo(nt),J>M&&at>M)continue;let ae=Jt(X,Z,H,nt),Ht=Jt(X,Z,E,A);if(Ht&&Ht.isParallel||!ae||!ae.isParallel)continue;let qt=ne(w,p,X,Z);if(qt&&qt.type=="collinear_overlap"&&qt.maxPerpendicularDistance<.2)continue;X.z=Z.z=t[q].start.z;let Q=!1;for(let ct=0;ct<z.length;ct++){let Lt=ne(z[ct].start,z[ct].end,X,Z);if(Lt&&Lt.type=="collinear_overlap"&&Lt.maxPerpendicularDistance<.2){Q=!0;break}}if(Q)continue;for(let ct=0;ct<t.length;ct++){if(t[ct].length<.5)continue;let Lt=ne(new d.Vector3(t[ct].start.x,t[ct].start.y,t[ct].start.z),new d.Vector3(t[ct].end.x,t[ct].end.y,t[ct].end.z),X,Z);if(Lt&&Lt.type=="collinear_overlap"&&Lt.maxPerpendicularDistance<.1){Q=!0;break}}if(Q)continue;z.push({start:X,end:Z}),S.push(q);let mt=t[q].rooftopPz-t[q].start.z,G=t[P].rooftopPz-t[P].start.z,wt=mt<G?mt:G;t[q].doorAndBeamData||(t[q].doorAndBeamData=[]),t[q].doorAndBeamData.push({id:l,beamStart:X,beamEnd:Z,beamHeight:wt,doorStart:X,doorEnd:Z,doorHeight:wt,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new d.Vector3(0,0,0)}),n[a[x].index].isFindBeam=!0,n[a[x].index].isFindOnlyDoor=!0,h.push([{id:l,beamStart:X,beamEnd:Z}]),l++,W=!0;break}}if(W)break}}}let g=[];for(let x=0;x<t.length;x++)t[x].isLine2||g.push(t[x]),t[x].isLine2&&t[x].doorAndBeamData.length!=0&&g.push(t[x]);return t.length=0,t.push(...g),{lines:t,beamGroup:h}},pr=(t,e)=>{if(!t||t.length<=0)return;let n={rectangles:[],threeEdgeRect:[]},r=new Set,i=.2,o=1.5,s=.15,a=2;if(!t[0].uuid){let l=1e4;for(let f=0;f<t.length;f++)t[f].uuid=l++}for(let l=0;l<t.length;l++){let f=t[l].length;if(r.has(t[l].uuid)||f<i||f>o)continue;let u=[],c=new d.Vector3(t[l].start.x,t[l].start.y,t[l].start.z),h=new d.Vector3(t[l].end.x,t[l].end.y,t[l].end.z),m=new d.Vector3().subVectors(h,c).normalize().clone().negate(),y=new d.Vector3,M=new d.Vector3,S=new d.Vector3;new d.Vector3;for(let z=0;z<t.length;z++){let g=t[z].length;if(z==l||g<i||g>o)continue;let b=new d.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),x=new d.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),w=oe(c,h,b,x);if(!w||w.angle<85)continue;let p=Et(b,c),v=Et(b,h),P=Et(x,c),V=Et(x,h);if(!(!p&&!v&&!P&&!V)){p||v?(y=b.clone(),M=x.clone()):(y=x.clone(),M=b.clone()),S=new d.Vector3().subVectors(M,y).normalize(),S.clone().negate();for(let _=0;_<t.length;_++){let D=t[_].length;if(_==l||_==z||D<i||D>o)continue;let T=new d.Vector3(t[_].start.x,t[_].start.y,t[_].start.z),E=new d.Vector3(t[_].end.x,t[_].end.y,t[_].end.z),A=oe(b,x,T,E);if(!A||A.angle<85)continue;let I=Et(T,M),B=Et(E,M);if(!I&&!B)continue;new d.Vector3;let k=new d.Vector3,L=new d.Vector3;I?(L=new d.Vector3().subVectors(E,T).normalize(),T.clone(),k=E.clone()):(L=new d.Vector3().subVectors(T,E).normalize(),E.clone(),k=T.clone());let O=re(m,L,.1);if(!(!O||!O.parallel||!O.sameDirection)){for(let C=0;C<t.length;C++){let N=t[C].length;if(C==l||C==z||C==_||N<i||N>o)continue;let W=new d.Vector3(t[C].start.x,t[C].start.y,t[C].start.z),q=new d.Vector3(t[C].end.x,t[C].end.y,t[C].end.z),H=oe(W,q,T,E);if(!H||H.angle<85)continue;let nt=Et(W,k),K=Et(q,k);if(!nt&&!K)continue;new d.Vector3;let et=new d.Vector3;nt?(W.clone(),et=q.clone()):(q.clone(),et=W.clone());let rt=Et(et,c),$=Et(et,h);if(!rt&&!$)continue;let Y=f*g;if(!(Y<s||Y>a)){u=[t[l].uuid,t[z].uuid,t[_].uuid,t[C].uuid];break}}if(u.length==4)break}}if(u.length==4)break}}u.length==4&&(u.forEach(z=>r.add(z)),n.rectangles.push(u))}for(let l=0;l<t.length;l++){let f=t[l].length;if(r.has(t[l].uuid)||f<i||f>o)continue;let u={indexs:[],missingEdge:{start:new d.Vector3,end:new d.Vector3}},c=new d.Vector3(t[l].start.x,t[l].start.y,t[l].start.z),h=new d.Vector3(t[l].end.x,t[l].end.y,t[l].end.z),m=!0,y=!0;for(let z=0;z<t.length;z++){if(z==l||t[z].length<i)continue;let g=new d.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),b=new d.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),x=Et(g,c),w=Et(b,c),p=Et(g,h),v=Et(b,h);if(x||w?m=!1:(p||v)&&(y=!1),!m&&!y)break}if(!m&&!y)continue;let M=new d.Vector3;m||([c,h]=[h,c]),M=new d.Vector3().subVectors(h,c).normalize();let S=M.clone().negate();for(let z=0;z<t.length;z++){let g=t[z].length;if(z==l||r.has(z)||g<i||g>o)continue;let b=new d.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),x=new d.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),w=oe(c,h,b,x);if(!w||w.angle<85)continue;let p=Et(b,h),v=Et(x,h);if(!p&&!v)continue;new d.Vector3;let P=new d.Vector3;p?(b.clone(),P=x.clone()):(x.clone(),P=b.clone());for(let V=0;V<t.length;V++){let _=t[V].length;if(V==l||V==z||r.has(V)||_<i||_>o)continue;let D=new d.Vector3(t[V].start.x,t[V].start.y,t[V].start.z),T=new d.Vector3(t[V].end.x,t[V].end.y,t[V].end.z),E=oe(b,x,D,T);if(!E||E.angle<85)continue;let A=Et(D,P),I=Et(T,P);if(!A&&!I)continue;let B=new d.Vector3,k=new d.Vector3;A?(B=D.clone(),k=T.clone()):(B=T.clone(),k=D.clone());let L=re(S,new d.Vector3().subVectors(k,B).normalize(),.1);if(!L||!L.parallel||!L.sameDirection)continue;let O=!0,C=!0;for(let W=0;W<t.length;W++){if(W==V||t[W].length<i)continue;let q=new d.Vector3(t[W].start.x,t[W].start.y,t[W].start.z),H=new d.Vector3(t[W].end.x,t[W].end.y,t[W].end.z),nt=Et(q,D),K=Et(H,D),et=Et(q,T),rt=Et(H,T);if(nt||K?O=!1:(et||rt)&&(C=!1),!O&&!C)break}if(!O&&!C)continue;let N=f*g;if(!(N<s||N>a)){u.indexs=[t[l].uuid,t[z].uuid,t[V].uuid],u.missingEdge.start=k,u.missingEdge.end=c;break}}if(u.indexs.length==3)break}u.indexs.length==3&&(u.indexs.forEach(z=>r.add(z)),n.threeEdgeRect.push(u))}return n},bt=11102230246251565e-32,Yt=134217729,yr=3.000000000000001*bt;function ke(t,e,n,r,i){let o,s,a,l,f=e[0],u=r[0],c=0,h=0;u>f==u>-f?(o=f,f=e[++c]):(o=u,u=r[++h]);let m=0;if(c<t&&h<n)for(u>f==u>-f?(s=f+o,a=o-(s-f),f=e[++c]):(s=u+o,a=o-(s-u),u=r[++h]),o=s,a!==0&&(i[m++]=a);c<t&&h<n;)u>f==u>-f?(s=o+f,l=s-o,a=o-(s-l)+(f-l),f=e[++c]):(s=o+u,l=s-o,a=o-(s-l)+(u-l),u=r[++h]),o=s,a!==0&&(i[m++]=a);for(;c<t;)s=o+f,l=s-o,a=o-(s-l)+(f-l),f=e[++c],o=s,a!==0&&(i[m++]=a);for(;h<n;)s=o+u,l=s-o,a=o-(s-l)+(u-l),u=r[++h],o=s,a!==0&&(i[m++]=a);return(o!==0||m===0)&&(i[m++]=o),m}function xr(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}function F(t){return new Float64Array(t)}var wr=(3+16*bt)*bt,br=(2+12*bt)*bt,vr=(9+64*bt)*bt*bt,me=F(4),Ue=F(8),Ze=F(12),Ke=F(16),jt=F(4);function Pr(t,e,n,r,i,o,s){let a,l,f,u,c,h,m,y,M,S,z,g,b,x,w,p,v,P;const V=t-i,_=n-i,D=e-o,T=r-o;x=V*T,h=Yt*V,m=h-(h-V),y=V-m,h=Yt*T,M=h-(h-T),S=T-M,w=y*S-(x-m*M-y*M-m*S),p=D*_,h=Yt*D,m=h-(h-D),y=D-m,h=Yt*_,M=h-(h-_),S=_-M,v=y*S-(p-m*M-y*M-m*S),z=w-v,c=w-z,me[0]=w-(z+c)+(c-v),g=x+z,c=g-x,b=x-(g-c)+(z-c),z=b-p,c=b-z,me[1]=b-(z+c)+(c-p),P=g+z,c=P-g,me[2]=g-(P-c)+(z-c),me[3]=P;let E=xr(4,me),A=br*s;if(E>=A||-E>=A||(c=t-V,a=t-(V+c)+(c-i),c=n-_,f=n-(_+c)+(c-i),c=e-D,l=e-(D+c)+(c-o),c=r-T,u=r-(T+c)+(c-o),a===0&&l===0&&f===0&&u===0)||(A=vr*s+yr*Math.abs(E),E+=V*u+T*a-(D*f+_*l),E>=A||-E>=A))return E;x=a*T,h=Yt*a,m=h-(h-a),y=a-m,h=Yt*T,M=h-(h-T),S=T-M,w=y*S-(x-m*M-y*M-m*S),p=l*_,h=Yt*l,m=h-(h-l),y=l-m,h=Yt*_,M=h-(h-_),S=_-M,v=y*S-(p-m*M-y*M-m*S),z=w-v,c=w-z,jt[0]=w-(z+c)+(c-v),g=x+z,c=g-x,b=x-(g-c)+(z-c),z=b-p,c=b-z,jt[1]=b-(z+c)+(c-p),P=g+z,c=P-g,jt[2]=g-(P-c)+(z-c),jt[3]=P;const I=ke(4,me,4,jt,Ue);x=V*u,h=Yt*V,m=h-(h-V),y=V-m,h=Yt*u,M=h-(h-u),S=u-M,w=y*S-(x-m*M-y*M-m*S),p=D*f,h=Yt*D,m=h-(h-D),y=D-m,h=Yt*f,M=h-(h-f),S=f-M,v=y*S-(p-m*M-y*M-m*S),z=w-v,c=w-z,jt[0]=w-(z+c)+(c-v),g=x+z,c=g-x,b=x-(g-c)+(z-c),z=b-p,c=b-z,jt[1]=b-(z+c)+(c-p),P=g+z,c=P-g,jt[2]=g-(P-c)+(z-c),jt[3]=P;const B=ke(I,Ue,4,jt,Ze);return x=a*u,h=Yt*a,m=h-(h-a),y=a-m,h=Yt*u,M=h-(h-u),S=u-M,w=y*S-(x-m*M-y*M-m*S),p=l*f,h=Yt*l,m=h-(h-l),y=l-m,h=Yt*f,M=h-(h-f),S=f-M,v=y*S-(p-m*M-y*M-m*S),z=w-v,c=w-z,jt[0]=w-(z+c)+(c-v),g=x+z,c=g-x,b=x-(g-c)+(z-c),z=b-p,c=b-z,jt[1]=b-(z+c)+(c-p),P=g+z,c=P-g,jt[2]=g-(P-c)+(z-c),jt[3]=P,Ke[ke(B,Ze,4,jt,Ke)-1]}function _e(t,e,n,r,i,o){const s=(e-o)*(n-i),a=(t-i)*(r-o),l=s-a,f=Math.abs(s+a);return Math.abs(l)>=wr*f?l:-Pr(t,e,n,r,i,o,f)}var Ko=(7+56*bt)*bt,Qo=(3+28*bt)*bt,Jo=(26+288*bt)*bt*bt,ti=F(4),ei=F(4),ni=F(4),ri=F(4),oi=F(4),ii=F(4),si=F(4),ai=F(4),li=F(4),ci=F(8),ui=F(8),hi=F(8),fi=F(4),di=F(8),mi=F(8),gi=F(16),pi=F(12),yi=F(192),xi=F(192),wi=(10+96*bt)*bt,bi=(4+48*bt)*bt,vi=(44+576*bt)*bt*bt,Pi=F(4),Mi=F(4),Vi=F(4),zi=F(4),Si=F(4),_i=F(4),Di=F(4),Ti=F(4),Ei=F(8),Ai=F(8),Bi=F(8),Ii=F(8),ki=F(8),Ci=F(8),Ri=F(8),Li=F(8),Fi=F(8),$i=F(4),Oi=F(4),qi=F(4),Ni=F(8),Wi=F(16),Xi=F(16),Yi=F(16),Hi=F(32),Gi=F(32),ji=F(48),Ui=F(64),Zi=F(1152),Ki=F(1152),Qi=(16+224*bt)*bt,Ji=(5+72*bt)*bt,ts=(71+1408*bt)*bt*bt,es=F(4),ns=F(4),rs=F(4),os=F(4),is=F(4),ss=F(4),as=F(4),ls=F(4),cs=F(4),us=F(4),hs=F(24),fs=F(24),ds=F(24),ms=F(24),gs=F(24),ps=F(24),ys=F(24),xs=F(24),ws=F(24),bs=F(24),vs=F(1152),Ps=F(1152),Ms=F(1152),Vs=F(1152),zs=F(1152),Ss=F(2304),_s=F(2304),Ds=F(3456),Ts=F(5760),Es=F(8),As=F(8),Bs=F(8),Is=F(16),ks=F(24),Cs=F(48),Rs=F(48),Ls=F(96),Fs=F(192),$s=F(384),Os=F(384),qs=F(384),Ns=F(768),Ws=F(96),Xs=F(96),Ys=F(96),Hs=F(1152),Qe=Math.pow(2,-52),De=new Uint32Array(512),Je=class bn{static from(e,n=_r,r=Dr){const i=e.length,o=new Float64Array(i*2);for(let s=0;s<i;s++){const a=e[s];o[2*s]=n(a),o[2*s+1]=r(a)}return new bn(o)}constructor(e){const n=e.length>>1;if(n>0&&typeof e[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=e;const r=Math.max(2*n-5,0);this._triangles=new Uint32Array(r*3),this._halfedges=new Int32Array(r*3),this._hashSize=Math.ceil(Math.sqrt(n)),this._hullPrev=new Uint32Array(n),this._hullNext=new Uint32Array(n),this._hullTri=new Uint32Array(n),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(n),this._dists=new Float64Array(n),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:e,_hullPrev:n,_hullNext:r,_hullTri:i,_hullHash:o}=this,s=e.length>>1;let a=1/0,l=1/0,f=-1/0,u=-1/0;for(let V=0;V<s;V++){const _=e[2*V],D=e[2*V+1];_<a&&(a=_),D<l&&(l=D),_>f&&(f=_),D>u&&(u=D),this._ids[V]=V}const c=(a+f)/2,h=(l+u)/2;let m=0,y=0,M=0;for(let V=0,_=1/0;V<s;V++){const D=Ce(c,h,e[2*V],e[2*V+1]);D<_&&(m=V,_=D)}const S=e[2*m],z=e[2*m+1];for(let V=0,_=1/0;V<s;V++){if(V===m)continue;const D=Ce(S,z,e[2*V],e[2*V+1]);D<_&&D>0&&(y=V,_=D)}let g=e[2*y],b=e[2*y+1],x=1/0;for(let V=0;V<s;V++){if(V===m||V===y)continue;const _=zr(S,z,g,b,e[2*V],e[2*V+1]);_<x&&(M=V,x=_)}let w=e[2*M],p=e[2*M+1];if(x===1/0){for(let D=0;D<s;D++)this._dists[D]=e[2*D]-e[0]||e[2*D+1]-e[1];ye(this._ids,this._dists,0,s-1);const V=new Uint32Array(s);let _=0;for(let D=0,T=-1/0;D<s;D++){const E=this._ids[D],A=this._dists[E];A>T&&(V[_++]=E,T=A)}this.hull=V.subarray(0,_),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(_e(S,z,g,b,w,p)<0){const V=y,_=g,D=b;y=M,g=w,b=p,M=V,w=_,p=D}const v=Sr(S,z,g,b,w,p);this._cx=v.x,this._cy=v.y;for(let V=0;V<s;V++)this._dists[V]=Ce(e[2*V],e[2*V+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=m;let P=3;r[m]=n[M]=y,r[y]=n[m]=M,r[M]=n[y]=m,i[m]=0,i[y]=1,i[M]=2,o.fill(-1),o[this._hashKey(S,z)]=m,o[this._hashKey(g,b)]=y,o[this._hashKey(w,p)]=M,this.trianglesLen=0,this._addTriangle(m,y,M,-1,-1,-1);for(let V=0,_=0,D=0;V<this._ids.length;V++){const T=this._ids[V],E=e[2*T],A=e[2*T+1];if(V>0&&Math.abs(E-_)<=Qe&&Math.abs(A-D)<=Qe||(_=E,D=A,T===m||T===y||T===M))continue;let I=0;for(let C=0,N=this._hashKey(E,A);C<this._hashSize&&(I=o[(N+C)%this._hashSize],!(I!==-1&&I!==r[I]));C++);I=n[I];let B=I,k;for(;k=r[B],_e(E,A,e[2*B],e[2*B+1],e[2*k],e[2*k+1])>=0;)if(B=k,B===I){B=-1;break}if(B===-1)continue;let L=this._addTriangle(B,T,r[B],-1,-1,i[B]);i[T]=this._legalize(L+2),i[B]=L,P++;let O=r[B];for(;k=r[O],_e(E,A,e[2*O],e[2*O+1],e[2*k],e[2*k+1])<0;)L=this._addTriangle(O,T,k,i[T],-1,i[O]),i[T]=this._legalize(L+2),r[O]=O,P--,O=k;if(B===I)for(;k=n[B],_e(E,A,e[2*k],e[2*k+1],e[2*B],e[2*B+1])<0;)L=this._addTriangle(k,T,B,-1,i[B],i[k]),this._legalize(L+2),i[k]=L,r[B]=B,P--,B=k;this._hullStart=n[T]=B,r[B]=n[O]=T,r[T]=O,o[this._hashKey(E,A)]=T,o[this._hashKey(e[2*B],e[2*B+1])]=B}this.hull=new Uint32Array(P);for(let V=0,_=this._hullStart;V<P;V++)this.hull[V]=_,_=r[_];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,n){return Math.floor(Mr(e-this._cx,n-this._cy)*this._hashSize)%this._hashSize}_legalize(e){const{_triangles:n,_halfedges:r,coords:i}=this;let o=0,s=0;for(;;){const a=r[e],l=e-e%3;if(s=l+(e+2)%3,a===-1){if(o===0)break;e=De[--o];continue}const f=a-a%3,u=l+(e+1)%3,c=f+(a+2)%3,h=n[s],m=n[e],y=n[u],M=n[c];if(Vr(i[2*h],i[2*h+1],i[2*m],i[2*m+1],i[2*y],i[2*y+1],i[2*M],i[2*M+1])){n[e]=M,n[a]=h;const S=r[c];if(S===-1){let g=this._hullStart;do{if(this._hullTri[g]===c){this._hullTri[g]=e;break}g=this._hullPrev[g]}while(g!==this._hullStart)}this._link(e,S),this._link(a,r[s]),this._link(s,c);const z=f+(a+1)%3;o<De.length&&(De[o++]=z)}else{if(o===0)break;e=De[--o]}}return s}_link(e,n){this._halfedges[e]=n,n!==-1&&(this._halfedges[n]=e)}_addTriangle(e,n,r,i,o,s){const a=this.trianglesLen;return this._triangles[a]=e,this._triangles[a+1]=n,this._triangles[a+2]=r,this._link(a,i),this._link(a+1,o),this._link(a+2,s),this.trianglesLen+=3,a}};function Mr(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}function Ce(t,e,n,r){const i=t-n,o=e-r;return i*i+o*o}function Vr(t,e,n,r,i,o,s,a){const l=t-s,f=e-a,u=n-s,c=r-a,h=i-s,m=o-a,y=l*l+f*f,M=u*u+c*c,S=h*h+m*m;return l*(c*S-M*m)-f*(u*S-M*h)+y*(u*m-c*h)<0}function zr(t,e,n,r,i,o){const s=n-t,a=r-e,l=i-t,f=o-e,u=s*s+a*a,c=l*l+f*f,h=.5/(s*f-a*l),m=(f*u-a*c)*h,y=(s*c-l*u)*h;return m*m+y*y}function Sr(t,e,n,r,i,o){const s=n-t,a=r-e,l=i-t,f=o-e,u=s*s+a*a,c=l*l+f*f,h=.5/(s*f-a*l);return{x:t+(f*u-a*c)*h,y:e+(s*c-l*u)*h}}function ye(t,e,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){const o=t[i],s=e[o];let a=i-1;for(;a>=n&&e[t[a]]>s;)t[a+1]=t[a--];t[a+1]=o}else{const i=n+r>>1;let o=n+1,s=r;Me(t,i,o),e[t[n]]>e[t[r]]&&Me(t,n,r),e[t[o]]>e[t[r]]&&Me(t,o,r),e[t[n]]>e[t[o]]&&Me(t,n,o);const a=t[o],l=e[a];for(;;){do o++;while(e[t[o]]<l);do s--;while(e[t[s]]>l);if(s<o)break;Me(t,o,s)}t[n+1]=t[s],t[s]=a,r-o+1>=s-n?(ye(t,e,o,r),ye(t,e,n,s-1)):(ye(t,e,n,s-1),ye(t,e,o,r))}}function Me(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function _r(t){return t[0]}function Dr(t){return t[1]}var tn=1e-6,de=class{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,n){t=+t,e=+e,n=+n;const r=t+n,i=e;if(n<0)throw new Error("negative radius");this._x1===null?this._+=`M${r},${i}`:(Math.abs(this._x1-r)>tn||Math.abs(this._y1-i)>tn)&&(this._+="L"+r+","+i),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=r},${this._y1=i}`)}rect(t,e,n,r){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+r}h${-n}Z`}value(){return this._||null}},Fe=class{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}},Tr=class{constructor(t,[e,n,r,i]=[0,0,960,500]){if(!((r=+r)>=(e=+e))||!((i=+i)>=(n=+n)))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=r,this.xmin=e,this.ymax=i,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:r}=this;let i,o;const s=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let y=0,M=0,S=n.length,z,g;y<S;y+=3,M+=2){const b=n[y]*2,x=n[y+1]*2,w=n[y+2]*2,p=t[b],v=t[b+1],P=t[x],V=t[x+1],_=t[w],D=t[w+1],T=P-p,E=V-v,A=_-p,I=D-v,B=(T*I-E*A)*2;if(Math.abs(B)<1e-9){if(i===void 0){i=o=0;for(const L of e)i+=t[L*2],o+=t[L*2+1];i/=e.length,o/=e.length}const k=1e9*Math.sign((i-p)*I-(o-v)*A);z=(p+_)/2-k*I,g=(v+D)/2+k*A}else{const k=1/B,L=T*T+E*E,O=A*A+I*I;z=p+(I*L-E*O)*k,g=v+(T*O-A*L)*k}s[M]=z,s[M+1]=g}let a=e[e.length-1],l,f=a*4,u,c=t[2*a],h,m=t[2*a+1];r.fill(0);for(let y=0;y<e.length;++y)a=e[y],l=f,u=c,h=m,f=a*4,c=t[2*a],m=t[2*a+1],r[l+2]=r[f]=h-m,r[l+3]=r[f+1]=c-u}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:n,inedges:r,hull:i},circumcenters:o,vectors:s}=this;if(i.length<=1)return null;for(let f=0,u=n.length;f<u;++f){const c=n[f];if(c<f)continue;const h=Math.floor(f/3)*2,m=Math.floor(c/3)*2,y=o[h],M=o[h+1],S=o[m],z=o[m+1];this._renderSegment(y,M,S,z,t)}let a,l=i[i.length-1];for(let f=0;f<i.length;++f){a=l,l=i[f];const u=Math.floor(r[l]/3)*2,c=o[u],h=o[u+1],m=a*4,y=this._project(c,h,s[m+2],s[m+3]);y&&this._renderSegment(c,h,y[0],y[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new de:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=e==null?e=new de:void 0,r=this._clip(t);if(r===null||!r.length)return;e.moveTo(r[0],r[1]);let i=r.length;for(;r[0]===r[i-2]&&r[1]===r[i-1]&&i>1;)i-=2;for(let o=2;o<i;o+=2)(r[o]!==r[o-2]||r[o+1]!==r[o-1])&&e.lineTo(r[o],r[o+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const r=this.cellPolygon(e);r&&(r.index=e,yield r)}}cellPolygon(t){const e=new Fe;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,r,i){let o;const s=this._regioncode(t,e),a=this._regioncode(n,r);s===0&&a===0?(i.moveTo(t,e),i.lineTo(n,r)):(o=this._clipSegment(t,e,n,r,s,a))&&(i.moveTo(o[0],o[1]),i.lineTo(o[2],o[3]))}contains(t,e,n){return e=+e,e!==e||(n=+n,n!==n)?!1:this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const r=this._clip(n);if(r){t:for(let i=0,o=e.length;i<o;i+=2)for(let s=0,a=r.length;s<a;s+=2)if(e[i]===r[s]&&e[i+1]===r[s+1]&&e[(i+2)%o]===r[(s+a-2)%a]&&e[(i+3)%o]===r[(s+a-1)%a]){yield n;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:r,triangles:i}}=this,o=n[t];if(o===-1)return null;const s=[];let a=o;do{const l=Math.floor(a/3);if(s.push(e[l*2],e[l*2+1]),a=a%3===2?a-2:a+1,i[a]!==t)break;a=r[a]}while(a!==o&&a!==-1);return s}_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:n}=this,r=t*4;return this._simplify(n[r]||n[r+1]?this._clipInfinite(t,e,n[r],n[r+1],n[r+2],n[r+3]):this._clipFinite(t,e))}_clipFinite(t,e){const n=e.length;let r=null,i,o,s=e[n-2],a=e[n-1],l,f=this._regioncode(s,a),u,c=0;for(let h=0;h<n;h+=2)if(i=s,o=a,s=e[h],a=e[h+1],l=f,f=this._regioncode(s,a),l===0&&f===0)u=c,c=0,r?r.push(s,a):r=[s,a];else{let m,y,M,S,z;if(l===0){if((m=this._clipSegment(i,o,s,a,l,f))===null)continue;[y,M,S,z]=m}else{if((m=this._clipSegment(s,a,i,o,f,l))===null)continue;[S,z,y,M]=m,u=c,c=this._edgecode(y,M),u&&c&&this._edge(t,u,c,r,r.length),r?r.push(y,M):r=[y,M]}u=c,c=this._edgecode(S,z),u&&c&&this._edge(t,u,c,r,r.length),r?r.push(S,z):r=[S,z]}if(r)u=c,c=this._edgecode(r[0],r[1]),u&&c&&this._edge(t,u,c,r,r.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 r}_clipSegment(t,e,n,r,i,o){const s=i<o;for(s&&([t,e,n,r,i,o]=[n,r,t,e,o,i]);;){if(i===0&&o===0)return s?[n,r,t,e]:[t,e,n,r];if(i&o)return null;let a,l,f=i||o;f&8?(a=t+(n-t)*(this.ymax-e)/(r-e),l=this.ymax):f&4?(a=t+(n-t)*(this.ymin-e)/(r-e),l=this.ymin):f&2?(l=e+(r-e)*(this.xmax-t)/(n-t),a=this.xmax):(l=e+(r-e)*(this.xmin-t)/(n-t),a=this.xmin),i?(t=a,e=l,i=this._regioncode(t,e)):(n=a,r=l,o=this._regioncode(n,r))}}_clipInfinite(t,e,n,r,i,o){let s=Array.from(e),a;if((a=this._project(s[0],s[1],n,r))&&s.unshift(a[0],a[1]),(a=this._project(s[s.length-2],s[s.length-1],i,o))&&s.push(a[0],a[1]),s=this._clipFinite(t,s))for(let l=0,f=s.length,u,c=this._edgecode(s[f-2],s[f-1]);l<f;l+=2)u=c,c=this._edgecode(s[l],s[l+1]),u&&c&&(l=this._edge(t,u,c,s,l),f=s.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(s=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return s}_edge(t,e,n,r,i){for(;e!==n;){let o,s;switch(e){case 5:e=4;continue;case 4:e=6,o=this.xmax,s=this.ymin;break;case 6:e=2;continue;case 2:e=10,o=this.xmax,s=this.ymax;break;case 10:e=8;continue;case 8:e=9,o=this.xmin,s=this.ymax;break;case 9:e=1;continue;case 1:e=5,o=this.xmin,s=this.ymin;break}(r[i]!==o||r[i+1]!==s)&&this.contains(t,o,s)&&(r.splice(i,0,o,s),i+=2)}return i}_project(t,e,n,r){let i=1/0,o,s,a;if(r<0){if(e<=this.ymin)return null;(o=(this.ymin-e)/r)<i&&(a=this.ymin,s=t+(i=o)*n)}else if(r>0){if(e>=this.ymax)return null;(o=(this.ymax-e)/r)<i&&(a=this.ymax,s=t+(i=o)*n)}if(n>0){if(t>=this.xmax)return null;(o=(this.xmax-t)/n)<i&&(s=this.xmax,a=e+(i=o)*r)}else if(n<0){if(t<=this.xmin)return null;(o=(this.xmin-t)/n)<i&&(s=this.xmin,a=e+(i=o)*r)}return[s,a]}_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 n=(e+2)%t.length,r=(e+4)%t.length;(t[e]===t[n]&&t[n]===t[r]||t[e+1]===t[n+1]&&t[n+1]===t[r+1])&&(t.splice(n,2),e-=2)}t.length||(t=null)}return t}},Er=2*Math.PI,ge=Math.pow;function Ar(t){return t[0]}function Br(t){return t[1]}function Ir(t){const{triangles:e,coords:n}=t;for(let r=0;r<e.length;r+=3){const i=2*e[r],o=2*e[r+1],s=2*e[r+2];if((n[s]-n[i])*(n[o+1]-n[i+1])-(n[o]-n[i])*(n[s+1]-n[i+1])>1e-10)return!1}return!0}function kr(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}var vn=class Pn{static from(e,n=Ar,r=Br,i){return new Pn("length"in e?Cr(e,n,r,i):Float64Array.from(Rr(e,n,r,i)))}constructor(e){this._delaunator=new Je(e),this.inedges=new Int32Array(e.length/2),this._hullIndex=new Int32Array(e.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const e=this._delaunator,n=this.points;if(e.hull&&e.hull.length>2&&Ir(e)){this.collinear=Int32Array.from({length:n.length/2},(h,m)=>m).sort((h,m)=>n[2*h]-n[2*m]||n[2*h+1]-n[2*m+1]);const l=this.collinear[0],f=this.collinear[this.collinear.length-1],u=[n[2*l],n[2*l+1],n[2*f],n[2*f+1]],c=1e-8*Math.hypot(u[3]-u[1],u[2]-u[0]);for(let h=0,m=n.length/2;h<m;++h){const y=kr(n[2*h],n[2*h+1],c);n[2*h]=y[0],n[2*h+1]=y[1]}this._delaunator=new Je(n)}else delete this.collinear;const r=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,o=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,f=r.length;l<f;++l){const u=o[l%3===2?l-2:l+1];(r[l]===-1||s[u]===-1)&&(s[u]=l)}for(let l=0,f=i.length;l<f;++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(e){return new Tr(this,e)}*neighbors(e){const{inedges:n,hull:r,_hullIndex:i,halfedges:o,triangles:s,collinear:a}=this;if(a){const c=a.indexOf(e);c>0&&(yield a[c-1]),c<a.length-1&&(yield a[c+1]);return}const l=n[e];if(l===-1)return;let f=l,u=-1;do{if(yield u=s[f],f=f%3===2?f-2:f+1,s[f]!==e)return;if(f=o[f],f===-1){const c=r[(i[e]+1)%r.length];c!==u&&(yield c);return}}while(f!==l)}find(e,n,r=0){if(e=+e,e!==e||(n=+n,n!==n))return-1;const i=r;let o;for(;(o=this._step(r,e,n))>=0&&o!==r&&o!==i;)r=o;return o}_step(e,n,r){const{inedges:i,hull:o,_hullIndex:s,halfedges:a,triangles:l,points:f}=this;if(i[e]===-1||!f.length)return(e+1)%(f.length>>1);let u=e,c=ge(n-f[e*2],2)+ge(r-f[e*2+1],2);const h=i[e];let m=h;do{let y=l[m];const M=ge(n-f[y*2],2)+ge(r-f[y*2+1],2);if(M<c&&(c=M,u=y),m=m%3===2?m-2:m+1,l[m]!==e)break;if(m=a[m],m===-1){if(m=o[(s[e]+1)%o.length],m!==y&&ge(n-f[m*2],2)+ge(r-f[m*2+1],2)<c)return m;break}}while(m!==h);return u}render(e){const n=e==null?e=new de:void 0,{points:r,halfedges:i,triangles:o}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const f=o[s]*2,u=o[l]*2;e.moveTo(r[f],r[f+1]),e.lineTo(r[u],r[u+1])}return this.renderHull(e),n&&n.value()}renderPoints(e,n){n===void 0&&(!e||typeof e.moveTo!="function")&&(n=e,e=null),n=n==null?2:+n;const r=e==null?e=new de:void 0,{points:i}=this;for(let o=0,s=i.length;o<s;o+=2){const a=i[o],l=i[o+1];e.moveTo(a+n,l),e.arc(a,l,n,0,Er)}return r&&r.value()}renderHull(e){const n=e==null?e=new de:void 0,{hull:r,points:i}=this,o=r[0]*2,s=r.length;e.moveTo(i[o],i[o+1]);for(let a=1;a<s;++a){const l=2*r[a];e.lineTo(i[l],i[l+1])}return e.closePath(),n&&n.value()}hullPolygon(){const e=new Fe;return this.renderHull(e),e.value()}renderTriangle(e,n){const r=n==null?n=new de:void 0,{points:i,triangles:o}=this,s=o[e*=3]*2,a=o[e+1]*2,l=o[e+2]*2;return n.moveTo(i[s],i[s+1]),n.lineTo(i[a],i[a+1]),n.lineTo(i[l],i[l+1]),n.closePath(),r&&r.value()}*trianglePolygons(){const{triangles:e}=this;for(let n=0,r=e.length/3;n<r;++n)yield this.trianglePolygon(n)}trianglePolygon(e){const n=new Fe;return this.renderTriangle(e,n),n.value()}};function Cr(t,e,n,r){const i=t.length,o=new Float64Array(i*2);for(let s=0;s<i;++s){const a=t[s];o[s*2]=e.call(r,a,s,t),o[s*2+1]=n.call(r,a,s,t)}return o}function*Rr(t,e,n,r){let i=0;for(const o of t)yield e.call(r,o,i,t),yield n.call(r,o,i,t),++i}function Lr(t,e,n,r){return 1+(t[e][0]===0||t[n][0]===0||t[r][0]===0?1:0)}function Fr(t,e,n,r,i,o){const s=Math.hypot(n-i,r-o),a=Math.hypot(t-i,e-o),l=Math.hypot(t-n,e-r),f=Math.abs((n-t)*(o-e)-(i-t)*(r-e))/2;return f===0?1/0:s*a*l/(4*f)}function $e(t){if(!t||t.length<3)return[];const e=new Set,n=[];for(const m of t){const y=`${m[0]}_${m[1]}`;e.has(y)||(e.add(y),n.push(m))}if(n.length<3)return[];const{triangles:r}=new vn(Float64Array.from(n.flat()));if(!r.length)return[];const i=new Map,o=(m,y)=>m<y?`${m}_${y}`:`${y}_${m}`;for(let m=0;m<r.length;m+=3){const y=r[m],M=r[m+1],S=r[m+2],[z,g]=n[y],[b,x]=n[M],[w,p]=n[S];if(Fr(z,g,b,x,w,p)<=1/Lr(n,y,M,S))for(const[v,P]of[[y,M],[M,S],[S,y]]){const V=o(v,P);i.set(V,(i.get(V)||0)+1)}}const s=[];for(const[m,y]of i)y===1&&s.push(m.split("_").map(Number));if(!s.length)return[];const a=new Map;for(const[m,y]of s)(a.get(m)||a.set(m,[]).get(m)).push(y),(a.get(y)||a.set(y,[]).get(y)).push(m);const l=s[0][0],f=[],u=new Set;let c=l,h=-1;do{f.push(n[c]),u.add(c);const m=a.get(c)||[];let y=m.find(M=>M!==h&&!u.has(M));if(y===void 0&&(y=m.find(M=>M!==h)),y===void 0)break;h=c,c=y}while(c!==l&&f.length<=s.length+1);return f}var ht={c:null,u:[new d.Vector3,new d.Vector3,new d.Vector3],e:[]},yt={c:null,u:[new d.Vector3,new d.Vector3,new d.Vector3],e:[]},Tt=[[],[],[]],st=[[],[],[]],St=[],ce=new d.Vector3,ue=new d.Vector3,he=new d.Vector3,Ot=new d.Vector3,en=new d.Vector3,nn=new d.Vector3,Qt=new d.Matrix3,rn=new d.Box3,Te=new d.Matrix4,on=new d.Matrix4,sn=new d.Ray,Mn=class{constructor(t=new d.Vector3,e=new d.Vector3,n=new d.Matrix3){this.center=t,this.halfSize=e,this.rotation=n}set(t,e,n){return this.center=t,this.halfSize=e,this.rotation=n,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 n=this.halfSize;Ot.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const r=d.MathUtils.clamp(Ot.dot(ce),-n.x,n.x);e.add(ce.multiplyScalar(r));const i=d.MathUtils.clamp(Ot.dot(ue),-n.y,n.y);e.add(ue.multiplyScalar(i));const o=d.MathUtils.clamp(Ot.dot(he),-n.z,n.z);return e.add(he.multiplyScalar(o)),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($r.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,nn),nn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){ht.c=this.center,ht.e[0]=this.halfSize.x,ht.e[1]=this.halfSize.y,ht.e[2]=this.halfSize.z,this.rotation.extractBasis(ht.u[0],ht.u[1],ht.u[2]),yt.c=t.center,yt.e[0]=t.halfSize.x,yt.e[1]=t.halfSize.y,yt.e[2]=t.halfSize.z,t.rotation.extractBasis(yt.u[0],yt.u[1],yt.u[2]);for(let i=0;i<3;i++)for(let o=0;o<3;o++)Tt[i][o]=ht.u[i].dot(yt.u[o]);Ot.subVectors(yt.c,ht.c),St[0]=Ot.dot(ht.u[0]),St[1]=Ot.dot(ht.u[1]),St[2]=Ot.dot(ht.u[2]);for(let i=0;i<3;i++)for(let o=0;o<3;o++)st[i][o]=Math.abs(Tt[i][o])+e;let n,r;for(let i=0;i<3;i++)if(n=ht.e[i],r=yt.e[0]*st[i][0]+yt.e[1]*st[i][1]+yt.e[2]*st[i][2],Math.abs(St[i])>n+r)return!1;for(let i=0;i<3;i++)if(n=ht.e[0]*st[0][i]+ht.e[1]*st[1][i]+ht.e[2]*st[2][i],r=yt.e[i],Math.abs(St[0]*Tt[0][i]+St[1]*Tt[1][i]+St[2]*Tt[2][i])>n+r)return!1;return n=ht.e[1]*st[2][0]+ht.e[2]*st[1][0],r=yt.e[1]*st[0][2]+yt.e[2]*st[0][1],!(Math.abs(St[2]*Tt[1][0]-St[1]*Tt[2][0])>n+r||(n=ht.e[1]*st[2][1]+ht.e[2]*st[1][1],r=yt.e[0]*st[0][2]+yt.e[2]*st[0][0],Math.abs(St[2]*Tt[1][1]-St[1]*Tt[2][1])>n+r)||(n=ht.e[1]*st[2][2]+ht.e[2]*st[1][2],r=yt.e[0]*st[0][1]+yt.e[1]*st[0][0],Math.abs(St[2]*Tt[1][2]-St[1]*Tt[2][2])>n+r)||(n=ht.e[0]*st[2][0]+ht.e[2]*st[0][0],r=yt.e[1]*st[1][2]+yt.e[2]*st[1][1],Math.abs(St[0]*Tt[2][0]-St[2]*Tt[0][0])>n+r)||(n=ht.e[0]*st[2][1]+ht.e[2]*st[0][1],r=yt.e[0]*st[1][2]+yt.e[2]*st[1][0],Math.abs(St[0]*Tt[2][1]-St[2]*Tt[0][1])>n+r)||(n=ht.e[0]*st[2][2]+ht.e[2]*st[0][2],r=yt.e[0]*st[1][1]+yt.e[1]*st[1][0],Math.abs(St[0]*Tt[2][2]-St[2]*Tt[0][2])>n+r)||(n=ht.e[0]*st[1][0]+ht.e[1]*st[0][0],r=yt.e[1]*st[2][2]+yt.e[2]*st[2][1],Math.abs(St[1]*Tt[0][0]-St[0]*Tt[1][0])>n+r)||(n=ht.e[0]*st[1][1]+ht.e[1]*st[0][1],r=yt.e[0]*st[2][2]+yt.e[2]*st[2][0],Math.abs(St[1]*Tt[0][1]-St[0]*Tt[1][1])>n+r)||(n=ht.e[0]*st[1][2]+ht.e[1]*st[0][2],r=yt.e[0]*st[2][1]+yt.e[1]*st[2][0],Math.abs(St[1]*Tt[0][2]-St[0]*Tt[1][2])>n+r))}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)),n=t.normal.dot(this.center)-t.constant;return Math.abs(n)<=e}intersectRay(t,e){return this.getSize(en),rn.setFromCenterAndSize(Ot.set(0,0,0),en),Te.setFromMatrix3(this.rotation),Te.setPosition(this.center),on.copy(Te).invert(),sn.copy(t).applyMatrix4(on),sn.intersectBox(rn,e)?e.applyMatrix4(Te):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 n=Ot.set(e[0],e[1],e[2]).length();const r=Ot.set(e[4],e[5],e[6]).length(),i=Ot.set(e[8],e[9],e[10]).length();t.determinant()<0&&(n=-n),Qt.setFromMatrix4(t);const o=1/n,s=1/r,a=1/i;return Qt.elements[0]*=o,Qt.elements[1]*=o,Qt.elements[2]*=o,Qt.elements[3]*=s,Qt.elements[4]*=s,Qt.elements[5]*=s,Qt.elements[6]*=a,Qt.elements[7]*=a,Qt.elements[8]*=a,this.rotation.multiply(Qt),this.halfSize.x*=n,this.halfSize.y*=r,this.halfSize.z*=i,Ot.setFromMatrixPosition(t),this.center.add(Ot),this}},$r=new Mn,Wt=63710088e-1,Vn={centimeters:Wt*100,centimetres:Wt*100,degrees:360/(2*Math.PI),feet:Wt*3.28084,inches:Wt*39.37,kilometers:Wt/1e3,kilometres:Wt/1e3,meters:Wt,metres:Wt,miles:Wt/1609.344,millimeters:Wt*1e3,millimetres:Wt*1e3,nauticalmiles:Wt/1852,radians:1,yards:Wt*1.0936};function zn(t,e,n={}){const r={type:"Feature"};return(n.id===0||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=e||{},r.geometry=t,r}function Sn(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!an(t[0])||!an(t[1]))throw new Error("coordinates must contain numbers");return zn({type:"Point",coordinates:t},e,n)}function _n(t,e,n={}){for(const r of t){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<r[r.length-1].length;i++)if(r[r.length-1][i]!==r[0][i])throw new Error("First and last Position are not equivalent.")}return zn({type:"Polygon",coordinates:t},e,n)}function Or(t,e="kilometers"){const n=Vn[e];if(!n)throw new Error(e+" units is invalid");return t*n}function qr(t,e="kilometers"){const n=Vn[e];if(!n)throw new Error(e+" units is invalid");return t/n}function Dn(t){return t%(2*Math.PI)*180/Math.PI}function ie(t){return t%360*Math.PI/180}function Tn(t,e="kilometers",n="kilometers"){if(!(t>=0))throw new Error("length must be a positive number");return Or(qr(t,e),n)}function an(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function Nr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ve(t,e,n){if(t!==null)for(var r,i,o,s,a,l,f,u=0,c=0,h,m=t.type,y=m==="FeatureCollection",M=m==="Feature",S=y?t.features.length:1,z=0;z<S;z++){f=y?t.features[z].geometry:M?t.geometry:t,h=f?f.type==="GeometryCollection":!1,a=h?f.geometries.length:1;for(var g=0;g<a;g++){var b=0,x=0;if(s=h?f.geometries[g]:f,s!==null){l=s.coordinates;var w=s.type;switch(u=n&&(w==="Polygon"||w==="MultiPolygon")?1:0,w){case null:break;case"Point":if(e(l,c,z,b,x)===!1)return!1;c++,b++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(e(l[r],c,z,b,x)===!1)return!1;c++,w==="MultiPoint"&&b++}w==="LineString"&&b++;break;case"Polygon":case"MultiLineString":for(r=0;r<l.length;r++){for(i=0;i<l[r].length-u;i++){if(e(l[r][i],c,z,b,x)===!1)return!1;c++}w==="MultiLineString"&&b++,w==="Polygon"&&x++}w==="Polygon"&&b++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(x=0,i=0;i<l[r].length;i++){for(o=0;o<l[r][i].length-u;o++){if(e(l[r][i][o],c,z,b,x)===!1)return!1;c++}x++}b++}break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(ve(s.geometries[r],e,n)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Wr(t){var e=[];return ve(t,function(n){e.push(n)}),e}function Xr(t,e){var n,r,i,o,s,a,l,f,u,c,h=0,m=t.type==="FeatureCollection",y=t.type==="Feature",M=m?t.features.length:1;for(n=0;n<M;n++){for(a=m?t.features[n].geometry:y?t.geometry:t,f=m?t.features[n].properties:y?t.properties:{},u=m?t.features[n].bbox:y?t.bbox:void 0,c=m?t.features[n].id:y?t.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(o=l?a.geometries[i]:a,o===null){if(e(null,h,f,u,c)===!1)return!1;continue}switch(o.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(e(o,h,f,u,c)===!1)return!1;break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(e(o.geometries[r],h,f,u,c)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}h++}}function Yr(t,e,n){var r=n;return Xr(t,function(i,o,s,a,l){o===0&&n===void 0?r=i:r=e(r,i,o,s,a,l)}),r}var Hr=be(((t,e)=>{(function(n,r){typeof t=="object"&&typeof e<"u"?e.exports=r():typeof define=="function"&&define.amd?define(r):(n=n||self).RBush=r()})(t,function(){"use strict";function n(g,b,x,w,p){(function v(P,V,_,D,T){for(;D>_;){if(D-_>600){var E=D-_+1,A=V-_+1,I=Math.log(E),B=.5*Math.exp(2*I/3),k=.5*Math.sqrt(I*B*(E-B)/E)*(A-E/2<0?-1:1);v(P,V,Math.max(_,Math.floor(V-A*B/E+k)),Math.min(D,Math.floor(V+(E-A)*B/E+k)),T)}var L=P[V],O=_,C=D;for(r(P,_,V),T(P[D],L)>0&&r(P,_,D);O<C;){for(r(P,O,C),O++,C--;T(P[O],L)<0;)O++;for(;T(P[C],L)>0;)C--}T(P[_],L)===0?r(P,_,C):r(P,++C,D),C<=V&&(_=C+1),V<=C&&(D=C-1)}})(g,b,x||0,w||g.length-1,p||i)}function r(g,b,x){var w=g[b];g[b]=g[x],g[x]=w}function i(g,b){return g<b?-1:g>b?1:0}var o=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,b,x){if(!x)return b.indexOf(g);for(var w=0;w<b.length;w++)if(x(g,b[w]))return w;return-1}function a(g,b){l(g,0,g.children.length,b,g)}function l(g,b,x,w,p){p||(p=S(null)),p.minX=1/0,p.minY=1/0,p.maxX=-1/0,p.maxY=-1/0;for(var v=b;v<x;v++){var P=g.children[v];f(p,g.leaf?w(P):P)}return p}function f(g,b){return g.minX=Math.min(g.minX,b.minX),g.minY=Math.min(g.minY,b.minY),g.maxX=Math.max(g.maxX,b.maxX),g.maxY=Math.max(g.maxY,b.maxY),g}function u(g,b){return g.minX-b.minX}function c(g,b){return g.minY-b.minY}function h(g){return(g.maxX-g.minX)*(g.maxY-g.minY)}function m(g){return g.maxX-g.minX+(g.maxY-g.minY)}function y(g,b){return g.minX<=b.minX&&g.minY<=b.minY&&b.maxX<=g.maxX&&b.maxY<=g.maxY}function M(g,b){return b.minX<=g.maxX&&b.minY<=g.maxY&&b.maxX>=g.minX&&b.maxY>=g.minY}function S(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function z(g,b,x,w,p){for(var v=[b,x];v.length;)if(!((x=v.pop())-(b=v.pop())<=w)){var P=b+Math.ceil((x-b)/w/2)*w;n(g,P,b,x,p),v.push(b,P,P,x)}}return o.prototype.all=function(){return this._all(this.data,[])},o.prototype.search=function(g){var b=this.data,x=[];if(!M(g,b))return x;for(var w=this.toBBox,p=[];b;){for(var v=0;v<b.children.length;v++){var P=b.children[v],V=b.leaf?w(P):P;M(g,V)&&(b.leaf?x.push(P):y(g,V)?this._all(P,x):p.push(P))}b=p.pop()}return x},o.prototype.collides=function(g){var b=this.data;if(!M(g,b))return!1;for(var x=[];b;){for(var w=0;w<b.children.length;w++){var p=b.children[w],v=b.leaf?this.toBBox(p):p;if(M(g,v)){if(b.leaf||y(g,v))return!0;x.push(p)}}b=x.pop()}return!1},o.prototype.load=function(g){if(!g||!g.length)return this;if(g.length<this._minEntries){for(var b=0;b<g.length;b++)this.insert(g[b]);return this}var x=this._build(g.slice(),0,g.length-1,0);if(this.data.children.length)if(this.data.height===x.height)this._splitRoot(this.data,x);else{if(this.data.height<x.height){var w=this.data;this.data=x,x=w}this._insert(x,this.data.height-x.height-1,!0)}else this.data=x;return this},o.prototype.insert=function(g){return g&&this._insert(g,this.data.height-1),this},o.prototype.clear=function(){return this.data=S([]),this},o.prototype.remove=function(g,b){if(!g)return this;for(var x,w,p,v=this.data,P=this.toBBox(g),V=[],_=[];v||V.length;){if(v||(v=V.pop(),w=V[V.length-1],x=_.pop(),p=!0),v.leaf){var D=s(g,v.children,b);if(D!==-1)return v.children.splice(D,1),V.push(v),this._condense(V),this}p||v.leaf||!y(v,P)?w?(x++,v=w.children[x],p=!1):v=null:(V.push(v),_.push(x),x=0,w=v,v=v.children[0])}return this},o.prototype.toBBox=function(g){return g},o.prototype.compareMinX=function(g,b){return g.minX-b.minX},o.prototype.compareMinY=function(g,b){return g.minY-b.minY},o.prototype.toJSON=function(){return this.data},o.prototype.fromJSON=function(g){return this.data=g,this},o.prototype._all=function(g,b){for(var x=[];g;)g.leaf?b.push.apply(b,g.children):x.push.apply(x,g.children),g=x.pop();return b},o.prototype._build=function(g,b,x,w){var p,v=x-b+1,P=this._maxEntries;if(v<=P)return a(p=S(g.slice(b,x+1)),this.toBBox),p;w||(w=Math.ceil(Math.log(v)/Math.log(P)),P=Math.ceil(v/Math.pow(P,w-1))),(p=S([])).leaf=!1,p.height=w;var V=Math.ceil(v/P),_=V*Math.ceil(Math.sqrt(P));z(g,b,x,_,this.compareMinX);for(var D=b;D<=x;D+=_){var T=Math.min(D+_-1,x);z(g,D,T,V,this.compareMinY);for(var E=D;E<=T;E+=V){var A=Math.min(E+V-1,T);p.children.push(this._build(g,E,A,w-1))}}return a(p,this.toBBox),p},o.prototype._chooseSubtree=function(g,b,x,w){for(;w.push(b),!b.leaf&&w.length-1!==x;){for(var p=1/0,v=1/0,P=void 0,V=0;V<b.children.length;V++){var _=b.children[V],D=h(_),T=(E=g,A=_,(Math.max(A.maxX,E.maxX)-Math.min(A.minX,E.minX))*(Math.max(A.maxY,E.maxY)-Math.min(A.minY,E.minY))-D);T<v?(v=T,p=D<p?D:p,P=_):T===v&&D<p&&(p=D,P=_)}b=P||b.children[0]}var E,A;return b},o.prototype._insert=function(g,b,x){var w=x?g:this.toBBox(g),p=[],v=this._chooseSubtree(w,this.data,b,p);for(v.children.push(g),f(v,w);b>=0&&p[b].children.length>this._maxEntries;)this._split(p,b),b--;this._adjustParentBBoxes(w,p,b)},o.prototype._split=function(g,b){var x=g[b],w=x.children.length,p=this._minEntries;this._chooseSplitAxis(x,p,w);var v=this._chooseSplitIndex(x,p,w),P=S(x.children.splice(v,x.children.length-v));P.height=x.height,P.leaf=x.leaf,a(x,this.toBBox),a(P,this.toBBox),b?g[b-1].children.push(P):this._splitRoot(x,P)},o.prototype._splitRoot=function(g,b){this.data=S([g,b]),this.data.height=g.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},o.prototype._chooseSplitIndex=function(g,b,x){for(var w,p,v,P,V,_,D,T=1/0,E=1/0,A=b;A<=x-b;A++){var I=l(g,0,A,this.toBBox),B=l(g,A,x,this.toBBox),k=(p=I,v=B,P=void 0,V=void 0,_=void 0,D=void 0,P=Math.max(p.minX,v.minX),V=Math.max(p.minY,v.minY),_=Math.min(p.maxX,v.maxX),D=Math.min(p.maxY,v.maxY),Math.max(0,_-P)*Math.max(0,D-V)),L=h(I)+h(B);k<T?(T=k,w=A,E=L<E?L:E):k===T&&L<E&&(E=L,w=A)}return w||x-b},o.prototype._chooseSplitAxis=function(g,b,x){var w=g.leaf?this.compareMinX:u,p=g.leaf?this.compareMinY:c;this._allDistMargin(g,b,x,w)<this._allDistMargin(g,b,x,p)&&g.children.sort(w)},o.prototype._allDistMargin=function(g,b,x,w){g.children.sort(w);for(var p=this.toBBox,v=l(g,0,b,p),P=l(g,x-b,x,p),V=m(v)+m(P),_=b;_<x-b;_++){var D=g.children[_];f(v,g.leaf?p(D):D),V+=m(v)}for(var T=x-b-1;T>=b;T--){var E=g.children[T];f(P,g.leaf?p(E):E),V+=m(P)}return V},o.prototype._adjustParentBBoxes=function(g,b,x){for(var w=x;w>=0;w--)f(b[w],g)},o.prototype._condense=function(g){for(var b=g.length-1,x=void 0;b>=0;b--)g[b].children.length===0?b>0?(x=g[b-1].children).splice(x.indexOf(g[b]),1):this.clear():a(g[b],this.toBBox)},o})})),Gr=Xn({default:()=>En});function jr(t,e){return t<e?-1:t>e?1:0}var En,Ur=Wn((()=>{En=class{constructor(t=[],e=jr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let n=(this.length>>1)-1;n>=0;n--)this._down(n)}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:n}=this,r=e[t];for(;t>0;){const i=t-1>>1,o=e[i];if(n(r,o)>=0)break;e[t]=o,t=i}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,i=e[t];for(;t<r;){let o=(t<<1)+1,s=e[o];const a=o+1;if(a<this.length&&n(e[a],s)<0&&(o=a,s=e[a]),n(s,i)>=0)break;e[t]=s,t=o}e[t]=i}}})),Zr=be(((t,e)=>{e.exports=function(r,i,o,s){var a=r[0],l=r[1],f=!1;o===void 0&&(o=0),s===void 0&&(s=i.length);for(var u=(s-o)/2,c=0,h=u-1;c<u;h=c++){var m=i[o+c*2+0],y=i[o+c*2+1],M=i[o+h*2+0],S=i[o+h*2+1];y>l!=S>l&&a<(M-m)*(l-y)/(S-y)+m&&(f=!f)}return f}})),Kr=be(((t,e)=>{e.exports=function(r,i,o,s){var a=r[0],l=r[1],f=!1;o===void 0&&(o=0),s===void 0&&(s=i.length);for(var u=s-o,c=0,h=u-1;c<u;h=c++){var m=i[c+o][0],y=i[c+o][1],M=i[h+o][0],S=i[h+o][1];y>l!=S>l&&a<(M-m)*(l-y)/(S-y)+m&&(f=!f)}return f}})),Qr=be(((t,e)=>{var n=Zr(),r=Kr();e.exports=function(o,s,a,l){return s.length>0&&Array.isArray(s[0])?r(o,s,a,l):n(o,s,a,l)},e.exports.nested=r,e.exports.flat=n})),Jr=be(((t,e)=>{(function(n,r){typeof t=="object"&&typeof e<"u"?r(t):typeof define=="function"&&define.amd?define(["exports"],r):r((n=n||self).predicates={})})(t,function(n){"use strict";const i=33306690738754706e-32;function o(M,S,z,g,b){let x,w,p,v,P=S[0],V=g[0],_=0,D=0;V>P==V>-P?(x=P,P=S[++_]):(x=V,V=g[++D]);let T=0;if(_<M&&D<z)for(V>P==V>-P?(p=x-((w=P+x)-P),P=S[++_]):(p=x-((w=V+x)-V),V=g[++D]),x=w,p!==0&&(b[T++]=p);_<M&&D<z;)V>P==V>-P?(p=x-((w=x+P)-(v=w-x))+(P-v),P=S[++_]):(p=x-((w=x+V)-(v=w-x))+(V-v),V=g[++D]),x=w,p!==0&&(b[T++]=p);for(;_<M;)p=x-((w=x+P)-(v=w-x))+(P-v),P=S[++_],x=w,p!==0&&(b[T++]=p);for(;D<z;)p=x-((w=x+V)-(v=w-x))+(V-v),V=g[++D],x=w,p!==0&&(b[T++]=p);return x===0&&T!==0||(b[T++]=x),T}function s(M){return new Float64Array(M)}const a=33306690738754716e-32,l=22204460492503146e-32,f=11093356479670487e-47,u=s(4),c=s(8),h=s(12),m=s(16),y=s(4);n.orient2d=function(M,S,z,g,b,x){const w=(S-x)*(z-b),p=(M-b)*(g-x),v=w-p;if(w===0||p===0||w>0!=p>0)return v;const P=Math.abs(w+p);return Math.abs(v)>=a*P?v:-(function(V,_,D,T,E,A,I){let B,k,L,O,C,N,W,q,H,nt,K,et,rt,$,Y,dt,Xt,Rt;const kt=V-E,Vt=D-E,Mt=_-A,At=T-A;C=(Y=(q=kt-(W=(N=134217729*kt)-(N-kt)))*(nt=At-(H=(N=134217729*At)-(N-At)))-(($=kt*At)-W*H-q*H-W*nt))-(K=Y-(Xt=(q=Mt-(W=(N=134217729*Mt)-(N-Mt)))*(nt=Vt-(H=(N=134217729*Vt)-(N-Vt)))-((dt=Mt*Vt)-W*H-q*H-W*nt))),u[0]=Y-(K+C)+(C-Xt),C=(rt=$-((et=$+K)-(C=et-$))+(K-C))-(K=rt-dt),u[1]=rt-(K+C)+(C-dt),C=(Rt=et+K)-et,u[2]=et-(Rt-C)+(K-C),u[3]=Rt;let J=(function(ae,Ht){let qt=Ht[0];for(let Q=1;Q<ae;Q++)qt+=Ht[Q];return qt})(4,u),at=l*I;if(J>=at||-J>=at||(B=V-(kt+(C=V-kt))+(C-E),L=D-(Vt+(C=D-Vt))+(C-E),k=_-(Mt+(C=_-Mt))+(C-A),O=T-(At+(C=T-At))+(C-A),B===0&&k===0&&L===0&&O===0)||(at=f*I+i*Math.abs(J),(J+=kt*O+At*B-(Mt*L+Vt*k))>=at||-J>=at))return J;C=(Y=(q=B-(W=(N=134217729*B)-(N-B)))*(nt=At-(H=(N=134217729*At)-(N-At)))-(($=B*At)-W*H-q*H-W*nt))-(K=Y-(Xt=(q=k-(W=(N=134217729*k)-(N-k)))*(nt=Vt-(H=(N=134217729*Vt)-(N-Vt)))-((dt=k*Vt)-W*H-q*H-W*nt))),y[0]=Y-(K+C)+(C-Xt),C=(rt=$-((et=$+K)-(C=et-$))+(K-C))-(K=rt-dt),y[1]=rt-(K+C)+(C-dt),C=(Rt=et+K)-et,y[2]=et-(Rt-C)+(K-C),y[3]=Rt;const X=o(4,u,4,y,c);C=(Y=(q=kt-(W=(N=134217729*kt)-(N-kt)))*(nt=O-(H=(N=134217729*O)-(N-O)))-(($=kt*O)-W*H-q*H-W*nt))-(K=Y-(Xt=(q=Mt-(W=(N=134217729*Mt)-(N-Mt)))*(nt=L-(H=(N=134217729*L)-(N-L)))-((dt=Mt*L)-W*H-q*H-W*nt))),y[0]=Y-(K+C)+(C-Xt),C=(rt=$-((et=$+K)-(C=et-$))+(K-C))-(K=rt-dt),y[1]=rt-(K+C)+(C-dt),C=(Rt=et+K)-et,y[2]=et-(Rt-C)+(K-C),y[3]=Rt;const Z=o(X,c,4,y,h);return C=(Y=(q=B-(W=(N=134217729*B)-(N-B)))*(nt=O-(H=(N=134217729*O)-(N-O)))-(($=B*O)-W*H-q*H-W*nt))-(K=Y-(Xt=(q=k-(W=(N=134217729*k)-(N-k)))*(nt=L-(H=(N=134217729*L)-(N-L)))-((dt=k*L)-W*H-q*H-W*nt))),y[0]=Y-(K+C)+(C-Xt),C=(rt=$-((et=$+K)-(C=et-$))+(K-C))-(K=rt-dt),y[1]=rt-(K+C)+(C-dt),C=(Rt=et+K)-et,y[2]=et-(Rt-C)+(K-C),y[3]=Rt,m[o(Z,h,4,y,m)-1]})(M,S,z,g,b,x,P)},n.orient2dfast=function(M,S,z,g,b,x){return(S-x)*(z-b)-(M-b)*(g-x)},Object.defineProperty(n,"__esModule",{value:!0})})})),to=be(((t,e)=>{var n=Hr(),r=(Ur(),Yn(Gr)),i=Qr(),o=Jr().orient2d;r.default&&(r=r.default),e.exports=s,e.exports.default=s;function s(p,v,P){v=Math.max(0,v===void 0?2:v),P=P||0;var V=M(p),_=new n(16);_.toBBox=function(H){return{minX:H[0],minY:H[1],maxX:H[0],maxY:H[1]}},_.compareMinX=function(H,nt){return H[0]-nt[0]},_.compareMinY=function(H,nt){return H[1]-nt[1]},_.load(p);for(var D=[],T=0,E;T<V.length;T++){var A=V[T];_.remove(A),E=S(A,E),D.push(E)}var I=new n(16);for(T=0;T<D.length;T++)I.insert(y(D[T]));for(var B=v*v,k=P*P;D.length;){var L=D.shift(),O=L.p,C=L.next.p,N=z(O,C);if(!(N<k)){var W=N/B;A=a(_,L.prev.p,O,C,L.next.next.p,W,I),A&&Math.min(z(A,O),z(A,C))<=W&&(D.push(L),D.push(S(A,L)),_.remove(A),I.remove(L),I.insert(y(L)),I.insert(y(L.next)))}}L=E;var q=[];do q.push(L.p),L=L.next;while(L!==E);return q.push(L.p),q}function a(p,v,P,V,_,D,T){for(var E=new r([],l),A=p.data;A;){for(var I=0;I<A.children.length;I++){var B=A.children[I],k=A.leaf?g(B,P,V):f(P,V,B);k>D||E.push({node:B,dist:k})}for(;E.length&&!E.peek().node.children;){var L=E.pop(),O=L.node,C=g(O,v,P),N=g(O,V,_);if(L.dist<C&&L.dist<N&&c(P,O,T)&&c(V,O,T))return O}A=E.pop(),A&&(A=A.node)}return null}function l(p,v){return p.dist-v.dist}function f(p,v,P){if(u(p,P)||u(v,P))return 0;var V=b(p[0],p[1],v[0],v[1],P.minX,P.minY,P.maxX,P.minY);if(V===0)return 0;var _=b(p[0],p[1],v[0],v[1],P.minX,P.minY,P.minX,P.maxY);if(_===0)return 0;var D=b(p[0],p[1],v[0],v[1],P.maxX,P.minY,P.maxX,P.maxY);if(D===0)return 0;var T=b(p[0],p[1],v[0],v[1],P.minX,P.maxY,P.maxX,P.maxY);return T===0?0:Math.min(V,_,D,T)}function u(p,v){return p[0]>=v.minX&&p[0]<=v.maxX&&p[1]>=v.minY&&p[1]<=v.maxY}function c(p,v,P){for(var V=Math.min(p[0],v[0]),_=Math.min(p[1],v[1]),D=Math.max(p[0],v[0]),T=Math.max(p[1],v[1]),E=P.search({minX:V,minY:_,maxX:D,maxY:T}),A=0;A<E.length;A++)if(m(E[A].p,E[A].next.p,p,v))return!1;return!0}function h(p,v,P){return o(p[0],p[1],v[0],v[1],P[0],P[1])}function m(p,v,P,V){return p!==V&&v!==P&&h(p,v,P)>0!=h(p,v,V)>0&&h(P,V,p)>0!=h(P,V,v)>0}function y(p){var v=p.p,P=p.next.p;return p.minX=Math.min(v[0],P[0]),p.minY=Math.min(v[1],P[1]),p.maxX=Math.max(v[0],P[0]),p.maxY=Math.max(v[1],P[1]),p}function M(p){for(var v=p[0],P=p[0],V=p[0],_=p[0],D=0;D<p.length;D++){var T=p[D];T[0]<v[0]&&(v=T),T[0]>V[0]&&(V=T),T[1]<P[1]&&(P=T),T[1]>_[1]&&(_=T)}var E=[v,P,V,_],A=E.slice();for(D=0;D<p.length;D++)i(p[D],E)||A.push(p[D]);return w(A)}function S(p,v){var P={p,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return v?(P.next=v.next,P.prev=v,v.next.prev=P,v.next=P):(P.prev=P,P.next=P),P}function z(p,v){var P=p[0]-v[0],V=p[1]-v[1];return P*P+V*V}function g(p,v,P){var V=v[0],_=v[1],D=P[0]-V,T=P[1]-_;if(D!==0||T!==0){var E=((p[0]-V)*D+(p[1]-_)*T)/(D*D+T*T);E>1?(V=P[0],_=P[1]):E>0&&(V+=D*E,_+=T*E)}return D=p[0]-V,T=p[1]-_,D*D+T*T}function b(p,v,P,V,_,D,T,E){var A=P-p,I=V-v,B=T-_,k=E-D,L=p-_,O=v-D,C=A*A+I*I,N=A*B+I*k,W=B*B+k*k,q=A*L+I*O,H=B*L+k*O,nt=C*W-N*N,K,et,rt,$,Y=nt,dt=nt;nt===0?(et=0,Y=1,$=H,dt=W):(et=N*H-W*q,$=C*H-N*q,et<0?(et=0,$=H,dt=W):et>Y&&(et=Y,$=H+N,dt=W)),$<0?($=0,-q<0?et=0:-q>C?et=Y:(et=-q,Y=C)):$>dt&&($=dt,-q+N<0?et=0:-q+N>C?et=Y:(et=-q+N,Y=C)),K=et===0?0:et/Y,rt=$===0?0:$/dt;var Xt=(1-K)*p+K*P,Rt=(1-K)*v+K*V,kt=(1-rt)*_+rt*T,Vt=(1-rt)*D+rt*E,Mt=kt-Xt,At=Vt-Rt;return Mt*Mt+At*At}function x(p,v){return p[0]===v[0]?p[1]-v[1]:p[0]-v[0]}function w(p){p.sort(x);for(var v=[],P=0;P<p.length;P++){for(;v.length>=2&&h(v[v.length-2],v[v.length-1],p[P])<=0;)v.pop();v.push(p[P])}for(var V=[],_=p.length-1;_>=0;_--){for(;V.length>=2&&h(V[V.length-2],V[V.length-1],p[_])<=0;)V.pop();V.push(p[_])}return V.pop(),v.pop(),v.concat(V)}})),eo=wn(to(),1);function no(t,e={}){e.concavity=e.concavity||1/0;const n=[];if(ve(t,i=>{n.push([i[0],i[1]])}),!n.length)return null;const r=(0,eo.default)(n,e.concavity);return r.length>3?_n([r]):null}function An(t,e={}){let n=0,r=0,i=0;return ve(t,function(o){n+=o[0],r+=o[1],i++},!0),Sn([n/i,r/i],e.properties)}function se(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if(t.type==="Feature"&&t.geometry!==null&&t.geometry.type==="Point")return[...t.geometry.coordinates];if(t.type==="Point")return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ro(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function oo(t,e,n={}){let r;return n.final?r=ln(se(e),se(t)):r=ln(se(t),se(e)),r>180?-(360-r):r}function ln(t,e){const n=ie(t[1]),r=ie(e[1]);let i=ie(e[0]-t[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const o=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4));return(Dn(Math.atan2(i,o))+360)%360}function io(t,e,n={}){const r=se(t),i=se(e);return i[0]+=i[0]-r[0]>180?-360:r[0]-i[0]>180?360:0,Tn(so(r,i),"meters",n.units)}function so(t,e,n){n=n===void 0?Wt:Number(n);const r=n,i=t[1]*Math.PI/180,o=e[1]*Math.PI/180,s=o-i;let a=Math.abs(e[0]-t[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),f=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+f*f*a*a)*r}function ao(t,e,n,r={}){const i=e<0;let o=Tn(Math.abs(e),r.units,"meters");i&&(o=-Math.abs(o));const s=se(t),a=lo(s,o,n);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,Sn(a,r.properties)}function lo(t,e,n,r){r=r===void 0?Wt:Number(r);const i=e/r,o=t[0]*Math.PI/180,s=ie(t[1]),a=ie(n),l=i*Math.cos(a);let f=s+l;Math.abs(f)>Math.PI/2&&(f=f>0?Math.PI-f:-Math.PI-f);const u=Math.log(Math.tan(f/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),c=Math.abs(u)>1e-11?l/u:Math.cos(s);return[((o+i*Math.sin(a)/c)*180/Math.PI+540)%360-180,f*180/Math.PI]}function co(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return Bn(t);case"FeatureCollection":return uo(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return qe(t);default:throw new Error("unknown GeoJSON type")}}function Bn(t){const e={type:"Feature"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:e[n]=t[n]}}),e.properties=In(t.properties),t.geometry==null?e.geometry=null:e.geometry=qe(t.geometry),e}function In(t){const e={};return t&&Object.keys(t).forEach(n=>{const r=t[n];typeof r=="object"?r===null?e[n]=null:Array.isArray(r)?e[n]=r.map(i=>i):e[n]=In(r):e[n]=r}),e}function uo(t){const e={type:"FeatureCollection"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"features":return;default:e[n]=t[n]}}),e.features=t.features.map(n=>Bn(n)),e}function qe(t){const e={type:t.type};return t.bbox&&(e.bbox=t.bbox),t.type==="GeometryCollection"?(e.geometries=t.geometries.map(n=>qe(n)),e):(e.coordinates=kn(t.coordinates),e)}function kn(t){const e=t;return typeof e[0]!="object"?e.slice():e.map(n=>kn(n))}function cn(t,e,n){if(n=n||{},!Nr(n))throw new Error("options is invalid");const r=n.pivot,i=n.mutate;if(!t)throw new Error("geojson is required");if(e==null||isNaN(e))throw new Error("angle is required");if(e===0)return t;const o=r??An(t);return(i===!1||i===void 0)&&(t=co(t)),ve(t,function(s){const a=oo(o,s)+e,l=ro(ao(o,io(o,s),a));s[0]=l[0],s[1]=l[1]}),t}function Cn(t,e,n={}){if(n.final===!0)return ho(t,e);const r=se(t),i=se(e),o=ie(r[0]),s=ie(i[0]),a=ie(r[1]),l=ie(i[1]),f=Math.sin(s-o)*Math.cos(l),u=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-o);return Dn(Math.atan2(f,u))}function ho(t,e){let n=Cn(e,t);return n=(n+180)%360,n}function fo(t,e={}){if(t.bbox!=null&&e.recompute!==!0)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return ve(t,r=>{n[0]>r[0]&&(n[0]=r[0]),n[1]>r[1]&&(n[1]=r[1]),n[2]<r[0]&&(n[2]=r[0]),n[3]<r[1]&&(n[3]=r[1])}),n}function mo(t,e={}){const n=Number(t[0]),r=Number(t[1]),i=Number(t[2]),o=Number(t[3]);if(t.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[n,r];return _n([[s,[i,r],[i,o],[n,o],s]],e.properties,{bbox:t,id:e.id})}function go(t){return mo(fo(t))}function po(t){return Yr(t,(e,n)=>e+yo(n),0)}function yo(t){let e=0,n;switch(t.type){case"Polygon":return un(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=un(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function un(t){let e=0;if(t&&t.length>0){e+=Math.abs(hn(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(hn(t[n]))}return e}var xo=Wt*Wt/2,Re=Math.PI/180;function hn(t){const e=t.length-1;if(e<=2)return 0;let n=0,r=0;for(;r<e;){const i=t[r],o=t[r+1===e?0:r+1],s=t[r+2>=e?(r+2)%e:r+2],a=i[0]*Re,l=o[1]*Re,f=s[0]*Re;n+=(f-a)*Math.sin(l),r++}return n*xo}function wo(t){const e=no(t);if(!e)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const n=An(e),r=Wr(e);let i=Number.MAX_SAFE_INTEGER,o=null;for(let s=0;s<r.length-1;s++){let a=Cn(r[s],r[s+1]),l=go(cn(e,-1*a,{pivot:n})),f=po(l);f<i&&(i=f,o=cn(l,a,{pivot:n}))}return o}function fn(t,e){const n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)}function bo(t){let e=1/0,n=-1/0,r=1/0,i=-1/0;for(const[o,s]of t)o<e&&(e=o),o>n&&(n=o),s<r&&(r=s),s>i&&(i=s);return[(n+e)*.5,(i+r)*.5]}var vo=class Oe extends Mn{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new d.Vector3);const e=this.halfSize.clone().multiplyScalar(2),n=new d.Mesh(new d.BoxGeometry(e.x,e.y,e.z));return n.position.copy(this.center),n.rotation.setFromQuaternion(fe),n}getBoxEdge(e=16776960){const n=this.getBoxMesh();Mo.setFromObject(n);const r=new d.EdgesGeometry(n.geometry.clone().applyMatrix4(n.matrixWorld));return new d.LineSegments(r,new d.LineBasicMaterial({color:e,toneMapped:!1}))}toJson(){return le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new d.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:fe.toArray()}}static from(e,n,r,i=new Oe){if(r instanceof d.Euler)fe.setFromEuler(r);else if(r instanceof d.Quaternion)fe.copy(r);else throw new Error("传入的旋转不是欧拉角或者四元数");return le.compose(n,fe,Po),i.center.copy(n),i.halfSize.copy(e.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(e,n,r,i=new Oe){const o=wo({type:"Polygon",coordinates:[e.map(h=>[h.x,h.y])]});if(!o)throw new Error("2d obb 获取失败");const s=o.geometry.coordinates[0],a=fn(s[0],s[1]),l=fn(s[1],s[2]),f=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Ee.set(a,l,r),dn.set(0,0,f);const[u,c]=bo(s);return n.x=u,n.y=c,this.from(Ee,n,dn,i)}},le=new d.Matrix4,fe=new d.Quaternion,dn=new d.Euler,Po=new d.Vector3(1,1,1),Ee=new d.Vector3,Mo=new d.Box3;function Vo(t,e,n=.005,r=.2){if(!t.length||!e.length)return 0;const i=Math.max(n,.03),o=n*n,s=new Map,a=(c,h,m)=>`${Math.floor(c/i)},${Math.floor(h/i)},${Math.floor(m/i)}`;for(const c of e){const h=a(c.x,c.y,c.z);s.has(h)||s.set(h,[]),s.get(h).push(c)}let l=0;const f=Math.ceil(n/i)+1,u=[];for(let c=-f;c<=f;c++)for(let h=-f;h<=f;h++)for(let m=-f;m<=f;m++)c*c+h*h+m*m<=f*f&&u.push([c,h,m]);for(const c of t){const h=Math.floor(c.x/i),m=Math.floor(c.y/i),y=Math.floor(c.z/i);let M=!1;for(const[S,z,g]of u){const b=`${h+S},${m+z},${y+g}`;if(s.has(b)){for(const x of s.get(b))if(c.distanceToSquared(x)<o){M=!0;break}if(M)break}}if(M&&(l++,l/t.length>r))return l/t.length}return l/t.length}function pe(t,e,n=.5){let r=0,i=0;for(const o of t)if(e.containsPoint(o)&&(r++,i=r/t.length,i>n))break;return i}function Le(t,e,n,r){if(t.intersectsOBB(e))return!0;{const i=xe(t,r),o=xe(e,n);if(i||o)return!0}return!1}function mn(t,e){const n=new d.Vector3,r=new d.Vector3;t.getSize(n),e.getSize(r);const i=n.x*n.y*n.z,o=r.x*r.y*r.z;return i>o?1:i<o?-1:0}function xe(t,e){let n=!0;for(let r=0;r<e.length;r++)if(!t.containsPoint(e[r])){n=!1;break}return n}function gn(t){if(t.length===0)return{x:0,y:0,z:0,h:0};let e=0,n=0,r=-1/0,i=1/0;for(const o of t)e+=o.x,n+=o.y,r=Math.max(r,o.z),i=Math.min(i,o.z);return{x:e/t.length,y:n/t.length,z:0,maxz:r,minz:i,h:r-i}}function pn(t,e,n,r){const i=[];for(let s=0;s<t.length;s++)i.push(new d.Vector3(t[s][0],t[s][1],0));if(i.length==0)return null;const o=vo.fromByPath2D(i,e,n);return o.center.z=r,o}var zo=t=>{if(t.length==0)return[];const e=[],n=new Map;for(let o=0;o<t.length;o++){let s=t[o].points.map(S=>[S.x,S.y]),a=t[o].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,f=a.lastIndexOf("_"),u=a.substring(l,f);if(u==="wall")continue;let c=[];for(let S=0;S<t[o].points.length;S++)c.push(new d.Vector3(t[o].points[S].x,t[o].points[S].y,t[o].points[S].z));let h=-99999;if(u==="floor"){let S=new Map;for(let g=0;g<t[o].points.length;g++){let b=t[o].points[g].z;if(b=Math.floor(b*10)/10,S.has(b)){const x=S.get(b);x.num+=1,x.points.push(t[o].points[g]),S.set(b,x)}else S.set(b,{num:1,points:[t[o].points[g]]})}let z=[...S.entries()].reduce((g,b)=>b[1].num>g[1].num?b:g);s=[],s=z[1].points.map(g=>[g.x,g.y]),c=[],c=z[1].points.map(g=>new d.Vector3(g.x,g.y,g.z)),h=z[0]}const m=gn(c),y={points:c,path:$e(s),h:m.h,minz:m.minz,maxz:m.maxz,center:{x:m.x,y:m.y,z:m.z},obj_id:t[o].obj_id,type:u,averagePz:t[o].averagePz,obb:null,isDel:!1,obj_id:a,positionArr:[t[o].position]};if(y.obb=pn(y.path,y.center,y.h,(y.maxz+y.minz)/2),y.obb==null)continue;let M=-1;for(let S=0;S<e.length;S++)if(e[S].type==u){M=S;break}if(M!=-1?e[M].array.push(y):e.push({type:u,array:[y]}),u=="floor"&&h!=-99999)if(n.has(h)){const S=n.get(h);S.num+=y.points.length,S.datas.push(y),n.set(h,S)}else n.set(h,{num:y.points.length,datas:[y]})}let r=-1/0;if(n.size>0){let o=[];for(const[s,a]of n.entries()){const{num:l,datas:f}=a;l>3e3&&(s>r&&(r=s),o.push(...f))}for(let s=0;s<e.length;s++)if(e[s].type=="floor"){e[s].array=o;break}}for(let o=0;o<e.length;o++){const s=e[o].array,a=[],l=[];for(let u=0;u<s.length;u++){if(s[u].obb==null||a.includes(u))continue;const c={...s[u],obb:s[u].obb.clone()};for(let h=u+1;h<s.length;h++)if(!(s[h].obb==null||a.includes(h))&&c.obb.intersectsOBB(s[h].obb)){a.push(h);for(let y=0;y<s[h].points.length;y++)(s[h].points[y].z>r&&s[h].points[y].z-r>.1||c.type=="floor")&&c.points.push(s[h].points[y]);c.path=$e(c.points.map(y=>[y.x,y.y]));const m=gn(c.points);c.h=m.h,c.minz=m.minz,c.maxz=m.maxz,c.center={x:m.x,y:m.y,z:m.z},c.obb=pn(c.path,c.center,c.h,(c.maxz+c.minz)/2),c.positionArr.push(...s[h].positionArr),h=u}c.path.length>s[u].path.length&&(a.push(u),l.push(c))}const f=[];for(let u=0;u<s.length;u++)a.includes(u)||f.push(s[u]);f.push(...l),e[o].array=f}for(let o=0;o<e.length;o++){const s=e[o].type;if(s==="people"||s==="floor")continue;const a=e[o].array;for(let l=0;l<a.length;l++){const f=a[l].obb,u=a[l].minz;a[l].maxz;const c=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const h=new d.Vector3;f.getSize(h);const m=[h.x,h.y,h.z];let y=0;for(const M of m)if(M<.2&&(y++,y===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let h=o+1;h<e.length;h++){const m=e[h].type;if(m==="people"||m==="floor")continue;const y=e[h].array;for(let M=0;M<y.length;M++){if(y[M].isDel)continue;const S=y[M].obb,z=y[M].minz;if(y[M].maxz,f.intersectsOBB(S)){pe(y[M].points,f);const g=pe(a[l].points,S),b=mn(f,S);if(g>=.3&&b==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(m==="balcony railing"&&xe(f,y[M].points)){y[M].isDel=!0;continue}if(m==="balcony railing"&&xe(S,a[l].points)){a[l].isDel=!0;break}if(m==="balcony railing"&&Le(f,S,a[l].points,y[M].points)&&(Math.abs(u-z)<.1||Math.abs(z-c)>.3)){y[M].isDel=!0;continue}}else if(s==="balcony railing"){if(m==="window"&&xe(f,y[M].points)){y[M].isDel=!0;continue}if(m==="window"&&xe(S,a[l].points)){a[l].isDel=!0;break}if(m==="window"&&Le(f,S,a[l].points,y[M].points)&&(Math.abs(u-z)<.1||Math.abs(u-c)>.3)){a[l].isDel=!0;break}}let x=!1,w=[],p=[];const v=a[l].points,P=y[M].points;if(v.length>P.length?(x=!0,w=v,p=P):(w=P,p=v),Vo(p,w,.03,.5)>.5)if(x)y[M].isDel=!0;else{a[l].isDel=!0;break}else if(Le(f,S)){const V=mn(f,S);if(V===1||V===0){if(m==="switch")continue;v.length>P.length?pe(p,f)>=.5&&(y[M].isDel=!0):pe(w,f)>=.5&&(y[M].isDel=!0)}else{if(s==="switch")continue;if(v.length>P.length){if(pe(w,S)>=.5){a[l].isDel=!0;break}}else if(pe(p,S)>=.5){a[l].isDel=!0;break}}}}}}if(a[l].isDel)break}}}for(let o=0;o<e.length;o++){const s=e[o].type,a=e[o].array;for(let l=0;l<a.length;l++){let f=a[l].maxz,u=a[l].minz,c=s==="switch"?.1:.3;const h=a[l].averagePz;if(Math.abs(f-h)<c){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const m=Math.abs(f-h),y=Math.abs(u-h);(s==="tv"&&y<1.6||s!=="window"&&m<1.6)&&(a[l].isDel=!0),s==="window"&&m<1&&(a[l].isDel=!0)}if(s==="chair"){const m=new d.Vector3;a[l].obb.getSize(m),(m.x<.1||m.y<.1||m.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(f-u)<.4&&(a[l].isDel=!0),(u<h&&Math.abs(u-h)>1||u>h&&Math.abs(u-h)>1)&&(a[l].isDel=!0),f<h&&(a[l].isDel=!0)),s==="people"&&(Math.abs(f-u)<1&&(a[l].isDel=!0),u>h&&u-h>.3&&(a[l].isDel=!0),f<h&&(a[l].isDel=!0)),s==="floor"&&a[l].points.length<500&&(a[l].isDel=!0)}}for(let o=0;o<e.length;o++)e[o].array=e[o].array.filter(s=>!s.isDel);const i=[];for(let o=0;o<e.length;o++){const s=e[o].array;for(let a=0;a<s.length;a++)i.push({obbBox:s[a].obb,box:new d.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 So(t,e,n,r){return 1+(t[e][0]===0||t[n][0]===0||t[r][0]===0?1:0)}function _o(t){if(!t.length)return 0;const e=[...t].sort((r,i)=>r-i),n=Math.floor(e.length/2);return e.length%2?e[n]:(e[n-1]+e[n])/2}function Do(t,e,n,r,i,o){const s=Math.hypot(n-i,r-o),a=Math.hypot(t-i,e-o),l=Math.hypot(t-n,e-r),f=Math.abs((n-t)*(o-e)-(i-t)*(r-e))/2,u=Math.max(s,a,l);return f===0?{radius:1/0,maxEdge:u}:{radius:s*a*l/(4*f),maxEdge:u}}function To(t,e){const n=[],r=new Set,i=(o,s)=>o<s?`${o}_${s}`:`${s}_${o}`;for(let o=0;o<e.length;o+=3){const s=e[o],a=e[o+1],l=e[o+2],f=[[s,a],[a,l],[l,s]];for(const[u,c]of f){const h=i(u,c);if(r.has(h))continue;r.add(h);const[m,y]=t[u],[M,S]=t[c],z=Math.hypot(M-m,S-y);Number.isFinite(z)&&z>0&&n.push(z)}}return _o(n)}function Eo(t){const e=new Set,n=[];for(const r of t){if(!r||r.length<2)continue;const i=r[0],o=r[1];if(!Number.isFinite(i)||!Number.isFinite(o))continue;const s=`${i}_${o}`;e.has(s)||(e.add(s),n.push([i,o]))}return n}function Ao(t){const e=new Map;for(const[n,r]of t)e.has(n)||e.set(n,[]),e.has(r)||e.set(r,[]),e.get(n).push(r),e.get(r).push(n);return e}function Bo(t,e){if(!e.length)return[];const n=Ao(e),r=e[0][0],i=[],o=new Set;let s=r,a=-1;do{i.push(t[s]),o.add(s);const l=n.get(s)||[];let f=l.find(u=>u!==a&&!o.has(u));if(f===void 0&&(f=l.find(u=>u!==a)),f===void 0)break;a=s,s=f}while(s!==r&&i.length<=e.length+1);return i}function Io(t,e={}){const{edgeFactor:n=20,alphaScale:r=2}=e;if(!t||t.length<3)return[];const i=Eo(t);if(i.length<3)return[];const{triangles:o}=new vn(Float64Array.from(i.flat()));if(!o.length)return[];const s=To(i,o);if(!Number.isFinite(s)||s<=0)return[];const a=s*n,l=new Map,f=(c,h)=>c<h?`${c}_${h}`:`${h}_${c}`;for(let c=0;c<o.length;c+=3){const h=o[c],m=o[c+1],y=o[c+2],[M,S]=i[h],[z,g]=i[m],[b,x]=i[y],{radius:w,maxEdge:p}=Do(M,S,z,g,b,x);if(w<=1/(So(i,h,m,y)*r)&&p<=a){const v=[[h,m],[m,y],[y,h]];for(const[P,V]of v){const _=f(P,V);l.set(_,(l.get(_)||0)+1)}}}const u=[];for(const[c,h]of l)h===1&&u.push(c.split("_").map(Number));return u.length?Bo(i,u):[]}function we(t,e){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function ko(t){let e=0,n=0,r=0;for(let i=0;i<4;i++){const o=t[i],s=t[(i+1)%4],a=s.x-o.x,l=s.y-o.y,f=Math.sqrt(a*a+l*l);f>e&&(e=f,n=a/f,r=l/f)}return{longSide:e,dirX:n,dirY:r}}function Ne(t,e,n){const i=[];for(const o of t){const s=(o.start.x+o.end.x)/2,a=(o.start.y+o.end.y)/2,l=s-e,f=a-n;l*l+f*f<=9&&i.push(o.start.z,o.end.z)}if(i.length===0){const o=[];for(const s of t)o.push(s.start.z,s.end.z);return o.length?(o.sort((s,a)=>s-a),o[Math.floor(o.length/2)]):-1/0}return i.sort((o,s)=>o-s),i[Math.floor(i.length/2)]}function Rn(t,e,n,r,i,o){const s=i-n,a=o-r,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((t-n)**2+(e-r)**2),t:0};const f=t-n,u=e-r,c=(f*s+u*a)/l,h=n+c*s,m=r+c*a;return{dist:Math.sqrt((t-h)**2+(e-m)**2),t:c}}function Co(t,e,n=.15){let r=0,i=0;for(const s of e)s!==t&&((we(t.start,s.start)<=n||we(t.start,s.end)<=n)&&r++,(we(t.end,s.start)<=n||we(t.end,s.end)<=n)&&i++);let o=0;return r>=1&&i>=1?o=5:(r>=1||i>=1)&&(o=2),{left:r,right:i,score:o}}function Ro(t,e){const n=[],{start:r,end:i}=t;for(const a of e){const{dist:l}=Rn(a.x,a.y,r.x,r.y,i.x,i.y);n.push(l)}const o=n.reduce((a,l)=>a+l,0)/n.length,s=n.reduce((a,l)=>a+(l-o)**2,0)/n.length;return s<.01?3:s<.05?2:s<.1?1:0}function Lo(t,e,n=.15){const r=t.end.x-t.start.x,i=t.end.y-t.start.y,o=Math.sqrt(r*r+i*i);if(o<1e-12)return 0;const s=-i/o,a=r/o,l=[[],[]];for(let u=0;u<2;u++){const c=u===0?t.start:t.end;for(const h of e){if(h===t)continue;const m=we(c,h.start),y=we(c,h.end);let M=null;if(m<=n?M=h.end:y<=n&&(M=h.start),!M)continue;const S=h.end.x-h.start.x,z=h.end.y-h.start.y,g=Math.sqrt(S*S+z*z);if(g<1e-12||Math.abs(r*S+i*z)/(o*g)>=.342)continue;const b=(M.x-c.x)*s+(M.y-c.y)*a;l[u].push(b>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const f=[...l[0],...l[1]];return f.every(u=>u===f[0])?2:1}function Fo(t,e,n){const r=Co(t,n),i=Ro(t,e),o=Lo(t,n);return{score:r.score*3+i*2+o*2,details:{conn:r.score,variance:i,sameSide:o}}}function $o(t){const e=t.end.x-t.start.x,n=t.end.y-t.start.y;let r=Math.atan2(n,e)*(180/Math.PI);return r<0&&(r+=180),r}function Oo(t,e){const n=[];for(const r of t){let i=!1;for(const o of n){const s=Math.abs(r.angle-o[0].angle);if(Math.min(s,180-s)<=e){o.push(r),i=!0;break}}i||n.push([r])}return n}function qo(t,e=.05){const n=[];for(const r of t){let i=!1;for(const o of n)if(Math.abs(r.offset-o[0].offset)<=e){o.push(r),i=!0;break}i||n.push([r])}return n}function No(t,e,n,r,i){const o=[];for(const a of t){const l=a.seg,f=(l.start.x-e.start.x)*n+(l.start.y-e.start.y)*r,u=(l.end.x-e.start.x)*n+(l.end.y-e.start.y)*r;o.push({l:Math.min(f,u),r:Math.max(f,u),idx:a.idx})}o.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:f}of o){if(s.length===0){s.push({l:a,r:l,srcIdxs:[f]});continue}const u=s[s.length-1];a<=u.r+i?(u.r=Math.max(u.r,l),u.srcIdxs.includes(f)||u.srcIdxs.push(f)):s.push({l:a,r:l,srcIdxs:[f]})}return s}function Wo(t,e,n,r,i,o,s){const a=n-e,l={...t};return l.start={x:t.start.x+e*r,y:t.start.y+e*i,z:t.start.z},l.end={x:t.start.x+n*r,y:t.start.y+n*i,z:t.start.z},l.length=a,l.direction={x:r,y:i,z:0},l.rooftopPz=o,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function Xo(t,e){let n=!0;for(;n;){n=!1;for(let r=0;r<t.length;r++)for(let i=r+1;i<t.length;i++){const o=t[r],s=t[i];if(o.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(o.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(o.end.x-s.start.x)<.001&&Math.abs(o.end.y-s.start.y)<.001,l=Math.abs(o.start.x-s.end.x)<.001&&Math.abs(o.start.y-s.end.y)<.001,f=Math.abs(o.end.x-s.end.x)<.001&&Math.abs(o.end.y-s.end.y)<.001,u=Math.abs(o.start.x-s.start.x)<.001&&Math.abs(o.start.y-s.start.y)<.001;if(!(a||l||f||u)||o.direction.x*s.direction.x+o.direction.y*s.direction.y<.98)continue;let c=o.start,h=o.end;a?h=s.end:l?c=s.start:f?h=s.start:u&&(c=s.end);const m=Math.hypot(h.x-c.x,h.y-c.y),y={...o};y.start=c,y.end=h,y.length=m,y.direction={x:(h.x-c.x)/m,y:(h.y-c.y)/m,z:0},o.rooftopPz!==void 0&&s.rooftopPz!==void 0?y.rooftopPz=Math.max(o.rooftopPz,s.rooftopPz):y.rooftopPz=o.rooftopPz!==void 0?o.rooftopPz:s.rooftopPz,y.buildRosource=o.buildRosource||s.buildRosource,y.isRebuild=!1,y.doorAndBeamData||(y.doorAndBeamData=[]),y.insetionArr||(y.insetionArr=[]),t[r]=y,e[r]=[...new Set([...e[r],...e[i]])],t.splice(i,1),e.splice(i,1),i--,n=!0}}return{segments:t,sourceMap:e}}function We(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((l,f)=>[f])};const r=t.map((l,f)=>({seg:l,angle:$o(l),idx:f}));r.sort((l,f)=>l.angle-f.angle);const i=Oo(r,e),o=[],s=[],a=[];for(const l of i){let f=l[0].seg;for(const z of l)z.seg.length>f.length&&(f=z.seg);const u=f.end.x-f.start.x,c=f.end.y-f.start.y,h=Math.sqrt(u*u+c*c);if(h<1e-12)continue;const m=-c/h,y=u/h,M=l.map(z=>{const g=z.seg.start.x-f.start.x,b=z.seg.start.y-f.start.y;return{seg:z.seg,offset:Math.abs(g*m+b*y),idx:z.idx}});M.sort((z,g)=>z.offset-g.offset);const S=qo(M);for(const z of S){let g=z[0].seg;for(const T of z)T.seg.length>g.length&&(g=T.seg);const b=g.end.x-g.start.x,x=g.end.y-g.start.y,w=Math.sqrt(b*b+x*x);if(w<1e-12)continue;const p=b/w,v=x/w,P=z.map(T=>T.seg.rooftopPz??0),V=Math.max(...P),_=[...new Set(P.map(T=>T.toFixed(3)))];if(_.length>1){const T=z.map(E=>({idx:E.idx,start:{x:E.seg.start.x,y:E.seg.start.y,z:E.seg.start.z},end:{x:E.seg.end.x,y:E.seg.end.y,z:E.seg.end.z},length:E.seg.length,rooftopPz:E.seg.rooftopPz??0}));a.push({values:[..._],segments:T})}[...new Set(z.map(T=>String(T.seg.buildRosource)))];const D=No(z,g,p,v,n);for(const{l:T,r:E,srcIdxs:A}of D){if(E-T<.01)continue;const I=Wo(g,T,E,p,v,V,g.buildRosource);o.push(I),s.push(A)}}}return{...Xo(o,s),debugRPZGroups:a}}function Yo(t){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...t}}function Ho(t,e,n){return[{x:e,y:n,z:0},{x:t[0].x,y:t[0].y,z:0},{x:t[1].x,y:t[1].y,z:0},{x:t[2].x,y:t[2].y,z:0},{x:t[3].x,y:t[3].y,z:0}]}function Go(t,e,n,r,i,o,s){const a=[{margin:o.projectionMargin,maxDist:o.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const f of a){if(l.length>0)break;for(const u of t){const c=e*o.minLengthRatio;if(u.length<c)continue;const{start:h,end:m}=u;let y=!1,M=1/0;for(const v of i){const{dist:P,t:V}=Rn(v.x,v.y,h.x,h.y,m.x,m.y);V>=-f.margin&&V<=1+f.margin&&P<=f.maxDist&&(y=!0,M=Math.min(M,P))}if(!y){`${f.maxDist}${(-f.margin).toFixed(1)}${(1+f.margin).toFixed(1)}`;continue}const S=Math.sqrt((m.x-h.x)**2+(m.y-h.y)**2);if(S<1e-12)continue;const z=(m.x-h.x)/S,g=(m.y-h.y)/S,b=Math.abs(n*z+r*g),x=Math.abs(-r*z+n*g),w=Math.acos(Math.min(Math.max(b,x),1))*(180/Math.PI);if(w>o.angleThreshold){`${w.toFixed(1)}${o.angleThreshold}`;continue}let p=0;if(S>.01){const v=[];for(let _=1;_<=4;_++){const D=i[_],T=D.x-h.x,E=D.y-h.y,A=(T*z+E*g)/S;v.push(A)}const P=Math.min(...v),V=Math.max(...v);V>P&&(p=Math.max(0,Math.min(1,V)-Math.max(0,P))/(V-P))}l.push({seg:u,minDist:M,embedRatio:p,ratio:u.length/e,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function jo(t,e,n,r){if(t.length<=1)return t.length===1&&(t[0].score=-1),t;for(const i of t){const{score:o,details:s}=Fo(i.seg,e,n);i.score=o,i.details=s}return t.sort((i,o)=>o.embedRatio-i.embedRatio||o.score-i.score||i.minDist-o.minDist),t}function Uo(t,e,n,r){const i=t.end.x-t.start.x,o=t.end.y-t.start.y,s=Math.sqrt(i*i+o*o),a=i/s,l=o/s,f=e.map(p=>{const v=p.x-t.start.x,P=p.y-t.start.y;return(v*a+P*l)/s}),u=Math.min(...f),c=Math.max(...f),h=(c-u)*s,m=(u+c)/2,y=t.start.x+m*i,M=t.start.y+m*o,S=n.box.min.z,z=n.box.max.z,g=Math.abs(z-S),b=Ne(r,t.start.x,t.start.y),x=Math.max(0,S-b),w=u<=0&&c>=1;return{p:{x:y,y:M,z:t.start.z+m*(t.end.z-t.start.z)},width:h,full:w,height:g,groundClearance:x}}function Ln(t,e,n){const r=e.map(c=>n[c]),i=[],o=[],s=[],a=[],l=[];let f,u;for(const c of r){if(c.points?.length)for(const h of c.points)i.push(h);if(c.originalPoints?.length)for(const h of c.originalPoints)o.push(h);if(c.doorAndBeamData?.length)for(const h of c.doorAndBeamData)s.push(h);if(c.insetionArr?.length)for(const h of c.insetionArr)a.push(h);if(c.drawWindow?.length)for(const h of c.drawWindow)l.push(h);c.boxData&&!f&&(f=c.boxData),c.rooftopPz!==void 0&&(u===void 0||c.rooftopPz>u)&&(u=c.rooftopPz)}i.length&&(t.points=i),o.length&&(t.originalPoints=o),s.length&&(t.doorAndBeamData=s),a.length&&(t.insetionArr=a),l.length&&(t.drawWindow=l),f&&(t.boxData=f),u!==void 0&&(t.rooftopPz=u)}function Fn(t,e,n,r){const i=Yo(n),o=[],{segments:s,sourceMap:a}=r??We(e),l=s;for(const f of t){const u=f.coordinatesByArea?.coordinates;if(!u||u.length<4)continue;const c=u.slice(0,4),h=c.reduce((v,P)=>v+P.x,0)/4,m=c.reduce((v,P)=>v+P.y,0)/4,{longSide:y,dirX:M,dirY:S}=ko(c);if(y<.01||c.reduce((v,P)=>v+P.z,0)/4<Ne(e,h,m)-.3)continue;const z=Ho(c,h,m);f.name;let g=Go(l,y,M,S,z,i,f.name);g=jo(g,z,e,f.name);let b=null,x=1/0,w=0;if(g.length>0){const v=g[0];b=v.seg,x=v.minDist,w=v.ratio}let p;if(b&&(p=Uo(b,c,f,s),!i.printOnly)){const v=b;v.drawWindow||(v.drawWindow=[]),v.drawWindow.push(p)}b&&o.push({windowName:f.name,windowCategory:f.category,windowCenter:f.center,wallSegment:b,distance:x,wallLengthRatio:w,drawWindow:p})}for(const f of o){const u=f.wallSegment,c=s.indexOf(u);if(c===-1)continue;const h=a[c];!h||h.length<=1||Ln(u,h,e)}return o}function Zo(t,e,n){const r={printOnly:!1,...n},i=Array.isArray(e)?e.filter(h=>h&&h.category==="window"&&!h.isBayWindowObj):[],{segments:o,sourceMap:s}=We(t),a=Fn(i,t,r,{segments:o,sourceMap:s}),l=new Set;for(const h of a){const m=o.indexOf(h.wallSegment);m>=0&&l.add(m)}const f=[],u=new Set;for(const h of l){const m=s[h];if(m){Ln(o[h],m,t);for(const y of m)u.add(y)}f.push(o[h])}for(let h=0;h<t.length;h++)u.has(h)||f.push(t[h]);const c=new Set(a.map(h=>h.windowName));for(const h of e)h&&h.category==="window"&&!h.isBayWindowObj&&(c.has(h.name)?delete h.AbnormalWindow:h.AbnormalWindow=!0);for(const h of a)h.drawWindow&&h.wallSegment&&(h.wallSegment.drawWindow||(h.wallSegment.drawWindow=[]),h.wallSegment.drawWindow.push(h.drawWindow));return{segments:f,matches:a}}exports.computeContour=$e;exports.computeContourNew=Io;exports.computeLocalFloorZ=Ne;exports.findWindowWalls=Fn;exports.getAllGeometry=sr;exports.getBeamLine=gr;exports.getColLine=pr;exports.getMergeMeaning=zo;exports.mergeCollinearSegments=We;exports.processData=Zo;exports.updateStEdPoint=ar;
|
|
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;
|