rm-graphical-computing 1.0.61 → 1.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +4064 -4047
  3. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Wn=Object.create,Pe=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Nn=Object.getOwnPropertyNames,Hn=Object.getPrototypeOf,pn=Object.prototype.hasOwnProperty,$n=(t,e)=>()=>(t&&(e=t(t=0)),e),we=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xn=(t,e)=>{let n={};for(var r in t)Pe(n,r,{get:t[r],enumerable:!0});return e||Pe(n,Symbol.toStringTag,{value:"Module"}),n},yn=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(var i=Nn(e),o=0,a=i.length,s;o<a;o++)s=i[o],!pn.call(t,s)&&s!==n&&Pe(t,s,{get:(l=>e[l]).bind(null,s),enumerable:!(r=On(e,s))||r.enumerable});return t},xn=(t,e,n)=>(n=t!=null?Wn(Hn(t)):{},yn(e||!t||!t.__esModule?Pe(n,"default",{value:t,enumerable:!0}):n,t)),Yn=t=>pn.call(t,"module.exports")?t["module.exports"]:yn(Pe({},"__esModule",{value:!0}),t);let c=require("three");c=xn(c);function De(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={},a={},s=t[0].morphTargetsRelative,l=new c.BufferGeometry;let h=0;for(let u=0;u<t.length;++u){const d=t[u];let f=0;if(n!==(d.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 d.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(d.attributes[m]),f++}if(f!==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(s!==d.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 d.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;a[m]===void 0&&(a[m]=[]),a[m].push(d.morphAttributes[m])}if(e){let m;if(n)m=d.index.count;else if(d.attributes.position!==void 0)m=d.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(h,m,u),h+=m}}if(n){let u=0;const d=[];for(let f=0;f<t.length;++f){const m=t[f].index;for(let b=0;b<m.count;++b)d.push(m.getX(b)+u);u+=t[f].attributes.position.count}l.setIndex(d)}for(const u in o){const d=qe(o[u]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" attribute."),null;l.setAttribute(u,d)}for(const u in a){const d=a[u][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[u]=[];for(let f=0;f<d;++f){const m=[];for(let w=0;w<a[u].length;++w)m.push(a[u][w][f]);const b=qe(m);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;l.morphAttributes[u].push(b)}}return l}function qe(t){let e,n,r,i=-1,o=0;for(let h=0;h<t.length;++h){const u=t[h];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 a=new e(o),s=new c.BufferAttribute(a,n,r);let l=0;for(let h=0;h<t.length;++h){const u=t[h];if(u.isInterleavedBufferAttribute){const d=l/n;for(let f=0,m=u.count;f<m;f++)for(let b=0;b<n;b++){const w=u.getComponent(f,b);s.setComponent(f+d,b,w)}}else a.set(u.array,l);l+=u.count*n}return i!==void 0&&(s.gpuType=i),s}var jn=class extends c.Object3D{constructor(t=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=t,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.center=new c.Vector2(.5,.5),this.addEventListener("removed",function(){this.traverse(function(e){e.element&&e.element instanceof e.element.ownerDocument.defaultView.Element&&e.element.parentNode!==null&&e.element.remove()})})}copy(t,e){return super.copy(t,e),this.element=t.element.cloneNode(!0),this.center=t.center,this}},Yo=new c.Vector3,jo=new c.Matrix4,Uo=new c.Matrix4,Zo=new c.Vector3,Ko=new c.Vector3,Un=(t,e,n)=>{let r=new c.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(t),i.push(e);let o=new c.BufferGeometry;o.setFromPoints(i),o.rotateX(-Math.PI/2),n.add(new c.Line(o,r))},Jt=(t,e,n,r,i=1e-8)=>{const o=e.x-t.x,a=e.y-t.y,s=r.x-n.x,l=r.y-n.y,h=o*l-a*s;if(Math.abs(h)<i)return null;const u=((n.x-t.x)*l-(n.y-t.y)*s)/h,d=((n.x-t.x)*a-(n.y-t.y)*o)/h;return u<-i||u>1+i||d<-i||d>1+i?null:{point:new c.Vector3(t.x+u*o,t.y+u*a,t.z)}},xe=(t,e,n={})=>{const{fontSize:r=36,fontFamily:i="sans-serif",backgroundColor:o="rgba(0,0,0,0)",textColor:a="#ffffff",padding:s=10,maxWidth:l=256}=n,h=document.createElement("canvas").getContext("2d");h.font=`bold ${r}px ${i}`;const u=h.measureText(t).width;let d=Math.min(u+s*2,l),f=r+s*2;const m=document.createElement("canvas");m.width=d,m.height=f;const b=m.getContext("2d");b.fillStyle=o,b.fillRect(0,0,d,f),b.fillStyle=a,b.font=`bold ${r}px ${i}`,b.textAlign="center",b.textBaseline="middle",u>l-s*2?Zn(b,t,d/2,f/2,l,r):b.fillText(t,d/2,f/2);const w=new c.CanvasTexture(m),_=new c.SpriteMaterial({map:w,depthTest:!1,transparent:!0}),M=new c.Sprite(_);M.position.set(e.x,e.y,e.z);const g=.005;return M.scale.set(d*g,f*g,1),M};function Zn(t,e,n,r,i,o){const a=e.split("");let s="",l=o*1.2,h=r;for(let u=0;u<a.length;u++){const d=s+a[u];t.measureText(d).width>i&&u>0?(t.fillText(s,n,h),s=a[u],h+=l):s=d}t.fillText(s,n,h)}var Kt=(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},a={x:e.x/i,y:e.y/i,z:e.z/i};let s=o.x*a.x+o.y*a.y+o.z*a.z;s=Math.max(-1,Math.min(1,s));const l=Math.acos(Math.abs(s)),h=l<=n;return{parallel:h,sameDirection:h?s>0:null,angle:l}};function Kn(t,e,n){const r=new c.BufferGeometry,i=[],o=[];t.forEach(s=>i.push(s.x,s.y,s.z)),e.forEach(s=>i.push(s.x,s.y,s.z)),o.push(0,2,1,0,3,2),o.push(4,5,6,4,6,7),o.push(0,1,5,0,5,4),o.push(1,2,6,1,6,5),o.push(2,3,7,2,7,6),o.push(3,0,4,3,4,7),r.setAttribute("position",new c.Float32BufferAttribute(i,3)),r.setIndex(o),r.computeVertexNormals();const a=new c.MeshBasicMaterial({color:n=="door"?"green":"#a7cc00",transparent:!0,opacity:.5,side:c.DoubleSide});return new c.Mesh(r,a)}var Ae=class{constructor(t={}){this.config={value:t.value||"0.0000m",position:t.position||new c.Vector3(0,0,0),style:{fontFamily:t.style?.fontFamily||"Arial, sans-serif",fontSize:t.style?.fontSize||"16px",fontWeight:t.style?.fontWeight||"normal",fontStyle:t.style?.fontStyle||"normal"},backgroundOpacity:t.backgroundOpacity||.7},this.label=null,this.labelElement=null,this.createLabel()}createLabel(){return this.labelElement=document.createElement("div"),this.labelElement.textContent=this.config.value,this.applyBlackWhiteStyle(),this.label=new jn(this.labelElement),this.label.position.copy(this.config.position),this.label}applyBlackWhiteStyle(){const t=this.labelElement.style,e=this.config;t.fontFamily=e.style.fontFamily,t.fontSize=e.style.fontSize,t.fontWeight=e.style.fontWeight,t.fontStyle=e.style.fontStyle,t.color="#FFFFFF",t.textShadow="0 1px 2px rgba(0, 0, 0, 0.5)",t.backgroundColor=`rgba(0, 0, 0, ${e.backgroundOpacity})`,t.padding="6px 12px",t.borderRadius="4px",t.position="absolute",t.whiteSpace="nowrap",t.userSelect="none",t.pointerEvents="none",t.zIndex="1000",t.textAlign="center",t.lineHeight="1.2"}updateValue(t){this.labelElement&&(this.labelElement.textContent=t)}updatePosition(t){this.label&&this.label.position.copy(t)}updateFontStyle(t){if(this.labelElement){const e=this.labelElement.style;t.fontFamily&&(e.fontFamily=t.fontFamily),t.fontSize&&(e.fontSize=t.fontSize),t.fontWeight&&(e.fontWeight=t.fontWeight),t.fontStyle&&(e.fontStyle=t.fontStyle)}}getLabel(){return this.label}getLabelElement(){return this.labelElement}dispose(){this.labelElement&&this.labelElement.parentNode&&this.labelElement.parentNode.removeChild(this.labelElement),this.label=null,this.labelElement=null}},Qn=t=>{const e=new c.Group,n=new c.Group;if(t&&t.length){const r=["green","red","pink","white","azure","yellow","bisque","grey","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","aliceblue","greenyellow","black","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","yellow","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];t.forEach((i,o)=>{const a=r[o],s=new c.Group,{pcdPoints:l,category:h,name:u,center:d,box:f,obbBox:m,contour:b,nline:w,coordinatesByWidth:_,coordinatesByArea:M}=i;let g=l.length;const v=new c.Box3(new c.Vector3(f.min.x,f.min.y,f.min.z),new c.Vector3(f.max.x,f.max.y,f.max.z)),y=new c.Box3Helper(v,a);s.add(y);const x=new Ae({value:u,position:new c.Vector3(d.x,d.y,d.z)}).getLabel();s.add(x);const p=new c.InstancedMesh(new c.SphereGeometry(.007,8,8),new c.MeshBasicMaterial({color:a}),g);s.add(p);const P=new c.Matrix4;let V=0;if(l.forEach(z=>{P.setPosition(z.x,z.y,z.z),p.setMatrixAt(V,P),V++}),p.instanceMatrix.needsUpdate=!0,w){const z=new c.BufferGeometry;z.setFromPoints([new c.Vector3(w.start.x,w.start.y,w.start.z),new c.Vector3(w.end.x,w.end.y,w.end.z)]);const S="red",E=new c.LineBasicMaterial({color:S,depthTest:!1,depthWrite:!1});new c.Line(z,E);const D=new c.Vector3().copy(new c.Vector3(w.start.x,w.start.y,w.start.z)).add(new c.Vector3(w.end.x,w.end.y,w.end.z)).multiplyScalar(.5),T=new c.Vector3(w.centerDir.x,w.centerDir.y,w.centerDir.z);new c.ArrowHelper(T,D,1,S)}if(b){const z=[];b.forEach((T,B)=>{z.push(new c.Vector3(T.x,T.y,T.z))});const S=new c.BufferGeometry;S.setFromPoints(z);const E=new c.LineBasicMaterial({color:"yellow",depthTest:!1,depthWrite:!1}),D=new c.Line(S,E);h!="door"?n.add(D):e.add(D)}if(M){const z=[],S=[];M.coordinates.forEach((q,H)=>{z.push(new c.Vector3(q.x,q.y,q.z)),S.length<4&&S.push(new c.Vector3(q.x,q.y,q.z))});const E=new c.BufferGeometry;E.setFromPoints(z);const D=new c.LineBasicMaterial({color:"green",depthTest:!1,depthWrite:!1}),T=new c.Line(E,D);h!="door"?n.add(T):e.add(T);const B=Kn(S.map(q=>new c.Vector3(q.x,q.y,M.heightData.minZ)),S.map(q=>new c.Vector3(q.x,q.y,q.z)),h);h!="door"?n.add(B):e.add(B);const[L,I,C]=z,F=L.distanceTo(I),k=new c.Vector3().copy(L).add(I).multiplyScalar(.5);new Ae({value:String(F.toFixed(3)),position:k}).getLabel();const A=I.distanceTo(C),G=new c.Vector3().copy(I).add(C).multiplyScalar(.5);new Ae({value:String(A.toFixed(3)),position:G}).getLabel()}if(m&&m.size&&m.center&&m.rotation){const z=new c.BoxGeometry(m.size.x,m.size.y,m.size.z),S=new c.LineBasicMaterial({color:a,linewidth:2}),E=new c.EdgesGeometry(z),D=new c.LineSegments(E,S),T=new Vector3(m.center.x,m.center.y,m.center.z),B=new Quaternion(m.rotation.x,m.rotation.y,m.rotation.z,m.rotation.w);D.position.copy(T),D.quaternion.copy(B),h!="door"?n.add(D):e.add(D)}})}return{AiProjectionGroup:e,AiProjectionGroup2:n}},Jn=(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 a=new c.Vector3().subVectors(i[1],i[0]).normalize(),s=new c.Vector3().subVectors(i[3],i[0]).normalize(),l=a.clone().cross(s).normalize();let h=1/0,u=-1/0,d=1/0,f=-1/0;for(const p of i){const P=p.dot(a),V=p.dot(s);P<h&&(h=P),P>u&&(u=P),V<d&&(d=V),V>f&&(f=V)}const m=i[0].dot(l),b=a.clone().multiplyScalar(h).add(s.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(m)),w=a.clone().multiplyScalar(u).add(s.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(m)),_=a.clone().multiplyScalar(u).add(s.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(m)),M=a.clone().multiplyScalar(h).add(s.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(m));let g=[b,w,_,M],v=Kt(new c.Vector3().subVectors(b,w),new c.Vector3(0,0,1));v&&v.parallel&&(g=[b,M,_,w]);let y=0;if(r.length>0){const p=new c.Vector3().subVectors(g[1],g[0]).normalize(),P=p.clone().negate(),V=new c.Vector3().subVectors(g[3],g[0]).normalize(),z=V.clone().negate();let S=g[0].distanceTo(g[1]),E=g[0].distanceTo(g[3]),D=S/e,T=E/n,B=.001;for(let L=0;L<D;L++){let I=g[0],C=0;for(let F=0;F<T;F++){let k=I.clone().addScaledVector(p,e),A=k.clone().addScaledVector(V,n),G=I.clone().addScaledVector(V,n),q=new c.Vector3().add(I).add(k).add(A).add(G).multiplyScalar(.25);for(let H=0;H<o.length;H++)if(o[H].distanceTo(q)<B){C++;break}I=G}if(C>=T/2)break;y+=C,g[0]=g[0].addScaledVector(p,e),g[3]=g[3].addScaledVector(p,e)}S=g[0].distanceTo(g[1]),D=S/e;for(let L=0;L<D;L++){let I=g[1],C=0;for(let F=0;F<T;F++){let k=I.clone().addScaledVector(P,e),A=k.clone().addScaledVector(V,n),G=I.clone().addScaledVector(V,n),q=new c.Vector3().add(I).add(k).add(A).add(G).multiplyScalar(.25);for(let H=0;H<o.length;H++)if(o[H].distanceTo(q)<B){C++;break}I=G}if(C>=T/2)break;y+=C,g[1]=g[1].addScaledVector(P,e),g[2]=g[2].addScaledVector(P,e)}S=g[0].distanceTo(g[1]),D=S/e;for(let L=0;L<T;L++){let I=g[3],C=0;for(let F=0;F<D;F++){let k=I.clone().addScaledVector(p,e),A=k.clone().addScaledVector(z,n),G=I.clone().addScaledVector(z,n),q=new c.Vector3().add(I).add(k).add(A).add(G).multiplyScalar(.25);for(let H=0;H<o.length;H++)if(o[H].distanceTo(q)<B){C++;break}I=k}if(C>=D/2)break;y+=C,g[2]=g[2].addScaledVector(z,n),g[3]=g[3].addScaledVector(z,n)}}const x=g[0].distanceTo(g[1])*g[0].distanceTo(g[3]);return{facePoints:g,boxArea:x,totalInPlaneNum:y}},ee=(t,e,n,r,i=c.MathUtils.degToRad(8))=>{const o=new c.Vector3,a=new c.Vector3;o.subVectors(new c.Vector3(e.x,e.y,0),new c.Vector3(t.x,t.y,0)).normalize(),a.subVectors(new c.Vector3(r.x,r.y,0),new c.Vector3(n.x,n.y,0)).normalize();const s=o.dot(a),l=Math.acos(Math.min(Math.abs(s),1)),h=1-Math.min(l/i,1),u=s>0?"same":"opposite";return{parallelism:h,angle:l,angleDeg:c.MathUtils.radToDeg(l),isParallel:l<i,direction:u,vectors:{v1:o,v2:a}}},Qt=(t,e,n,r)=>{const i=new c.Vector3().subVectors(e,t),o=new c.Vector3().subVectors(r,n),a=i.length(),s=o.length();if(a===0||s===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),o.normalize();const l=Math.abs(i.dot(o)),h=Math.min(1,Math.max(0,l)),u=Math.acos(h),d=c.MathUtils.radToDeg(u),f=1-h;return{rate:f,percent:`${(f*100).toFixed(2)}%`,angle:d,isPerpendicular:Math.abs(d-90)<.01,isParallel:d<.01}},Ut=(t,e,n=!1)=>new c.Vector3((t.x+e.x)/2,(t.y+e.y)/2,n?0:(t.z+e.z)/2),te=(t,e,n,r,i={})=>{const{parallelAngleMax:o=c.MathUtils.degToRad(10),collinearAngleMax:a=c.MathUtils.degToRad(7),distanceThreshold:s=2,overlapThreshold:l=.01}=i,h=new c.Vector3().subVectors(e,t),u=new c.Vector3().subVectors(r,n),d=h.clone().normalize(),f=u.clone().normalize();let m=c.MathUtils.clamp(d.dot(f),-1,1);const b=Math.acos(Math.abs(m)),w=c.MathUtils.radToDeg(b);if(b>o)return{type:"not_parallel",angleDeg:w,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};m<0&&f.negate();const _=new c.Vector3().addVectors(d,f).normalize(),M=new c.Vector3().addVectors(t,e).multiplyScalar(.5),g=We(n,M,d),v=We(r,M,d),y=(g+v)/2,x=Math.max(g,v),p=t.dot(_),P=e.dot(_),V=n.dot(_),z=r.dot(_),S=Math.min(p,P),E=Math.max(p,P),D=Math.min(V,z),T=Math.max(V,z),B=E-S,L=T-D,I=Math.min(B,L),C=Math.min(E,T)-Math.max(S,D),F=C<0?-C:0,k=C>0?C:0,A=I>0?k/I:0,G=tr(t,e,n,r),q=b<=a&&y<s;let H;return q?H=A>.5?"collinear_overlap":"collinear_gap":b<=o&&(H="parallel_offset"),{type:H,angleDeg:w,avgPerpendicularDistance:y,maxPerpendicularDistance:x,gap:F,overlap:k,closestDistance:G}};function We(t,e,n){const r=new c.Vector3().subVectors(t,e),i=r.dot(n),o=n.clone().multiplyScalar(i);return new c.Vector3().subVectors(r,o).length()}function tr(t,e,n,r){const i=new c.Vector3().subVectors(e,t),o=new c.Vector3().subVectors(r,n),a=new c.Vector3().subVectors(n,t),s=i.dot(i),l=i.dot(o),h=o.dot(o),u=i.dot(a),d=o.dot(a),f=s*h-l*l;let m,b;f<1e-10?(m=0,b=h!==0?d/h:0):(m=(l*d-h*u)/f,b=(s*d-l*u)/f),m=c.MathUtils.clamp(m,0,1),b=h!==0?c.MathUtils.clamp((l*m+d)/h,0,1):0,m=s!==0?c.MathUtils.clamp((l*b-u)/s,0,1):0;const w=t.clone().add(i.clone().multiplyScalar(m)),_=n.clone().add(o.clone().multiplyScalar(b));return w.distanceTo(_)}var er=(t,e,n,r=.05,i=.02)=>{const[o,a,s,l]=t,h=new c.Vector3().subVectors(a,o),u=new c.Vector3().subVectors(l,o),d=new c.Vector3().crossVectors(h,u).normalize(),f=h.length(),m=u.length(),b=h.clone().normalize(),w=u.clone().normalize(),_=n-r,M=n+r,g=new c.Vector3,v=[],y=Math.ceil(f/i),x=Math.ceil(m/i),p=f/y,P=m/x,V=new Uint8Array(y*x);for(let T=0;T<e.length;T++){g.subVectors(e[T],o);const B=Math.abs(g.dot(d));if(B<_||B>M)continue;const L=g.dot(b),I=g.dot(w);if(L<0||L>f||I<0||I>m)continue;v.push(new c.Vector3(e[T].x,e[T].y,e[T].z));const C=Math.min(Math.floor(L/p),y-1),F=Math.min(Math.floor(I/P),x-1);V[F*y+C]=1}let z=0;for(let T=0;T<V.length;T++)V[T]&&z++;const S=y*x,E=f*m,D=z==0||S==0?0:z/S*E;return{filteredPoints:v,coveragePercent:z==0||S==0?0:z/S*100,quadArea:E,coveredArea:D}},Oe=(t,e)=>Math.round(Math.max(5,Math.min(350,e*Math.sqrt(t)))),Ee=t=>{let e=new c.Vector3(t.start.x,t.start.y,t.start.z),n=new c.Vector3(t.end.x,t.end.y,t.end.z),r=e.distanceTo(n),i=t.rooftopPz-t.start.z,o=Oe(r,100),a=Oe(i,70),s=i/a,l=new Map;for(let w=0;w<a;w++)l.set((w+1)*s,{count:0,minZ:1/0,maxZ:-1/0});let h=new c.Line3(e,n);const u=t.originalPoints,d=new c.Vector3;for(let w=0;w<u.length;w++){const _=u[w];let M=h.closestPointToPoint(_,!0,d).distanceTo(_);const g=Math.floor(M/s);if(g<a){const v=l.get((g+1)*s);v.count++,_.z<v.minZ&&(v.minZ=_.z),_.z>v.maxZ&&(v.maxZ=_.z)}}let f,m,b=o/2;for(const[w,_]of l)if(_.count>=b){f=_.minZ;break}for(const[w,_]of[...l.entries()].reverse())if(_.count>=b){m=_.maxZ;break}return{minZ:f,maxZ:m}},Me=(t,e,n)=>{let r=new c.Plane;const i=new c.Vector3(t.x,t.y,t.z),o=new c.Vector3(e.x,e.y,e.z),a=new c.Vector3(e.x,e.y,e.z+5);r.setFromCoplanarPoints(i,o,a);const s=[],l=[];n.forEach(_=>{const M=new c.Vector3;r.projectPoint(_,M),l.push(M.clone()),M.z=i.z,s.push(M)});let h=new c.Vector3,u=new c.Vector3;r.projectPoint(i,h),r.projectPoint(o,u);const d=new c.Line3(h,u),f=[],m=[],b=[];let w=new c.Vector3;return s.forEach((_,M)=>{d.closestPointToPoint(_,!0,w).distanceTo(_)<.001?(f.push(n[M]),m.push(l[M])):b.push(_)}),{newOriginalPoints:f,newProjectPoints:b,newOnLinePoints:m}},wn=t=>{function e(n,r,i,o,a,s,l,h,u){let d=new c.Line3(n,r),f=new Map,m=new c.Vector3,b=n.clone(),w=r.clone(),_=0;for(;;){let M=new Map,g=0;for(let v=0;v<u.checkResults.length;v++)if(!(u.checkResults[v].allCenterPoints.length/h*100<1))for(let y=0;y<u.checkResults[v].allCenterPoints.length;y++){if(f.has(v)&&f.get(v).removePtsIndex.includes(y))continue;let x=u.checkResults[v].allCenterPoints[y];x=new c.Vector3(x.x,x.y,x.z);let p=d.closestPointToPoint(x,!0,m),P=x.distanceTo(p);Math.abs(P-a)<.01&&(g++,M.has(v)?M.get(v).removePtsIndex.push(y):M.set(v,{index:v,removePtsIndex:[y]}))}if(_==l){n=b,r=w;break}if(g<s/20*18||g==0){M.clear(),l-_<5&&(n=b,r=w,f.clear());break}else{_++;for(const[v,y]of M)f.has(v)?f.get(v).removePtsIndex.push(...y.removePtsIndex):f.set(v,y);M.clear(),n=n.addScaledVector(i,o),r=r.addScaledVector(i,o),d.set(n,r)}}if(f.size>0&&_!=l)for(const[M,g]of f){let v=[],y=[];for(let x=0;x<u.checkResults[M].allCenterPoints.length;x++)g.removePtsIndex.includes(x)||(v.push(u.checkResults[M].allCenterPoints[x]),y.push(u.checkResults[M].originalVertices[x]));u.checkResults[M].allCenterPoints=v,u.checkResults[M].originalVertices=y}}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[x,p,P,V]=r.checkResults[0].originalVertices[0];x=new c.Vector3(x.x,x.y,x.z),p=new c.Vector3(p.x,p.y,p.z),P=new c.Vector3(P.x,P.y,P.z),V=new c.Vector3(V.x,V.y,V.z),i=x.distanceTo(p),o=x.distanceTo(V);let z=Kt(new c.Vector3().subVectors(x,p).normalize(),new c.Vector3(0,0,1));z&&z.parallel&&([o,i]=[i,o])}if(i<0||o<0)continue;let a=new c.Vector3(r.start.x,r.start.y,r.start.z),s=new c.Vector3(r.end.x,r.end.y,r.end.z);const l=a.distanceTo(s),h=r.rooftopPz-r.start.z,u=Math.ceil(l/i),d=Math.ceil(h/o);let f=a.clone(),m=s.clone(),b=m.clone().add(new c.Vector3(0,0,h)),w=f.clone().add(new c.Vector3(0,0,h)),_=new c.Vector3().subVectors(m,f).normalize(),M=_.clone().negate();new c.Vector3().subVectors(b,f).normalize().clone().negate();let g=i/2;o/2;let v=l*h/(i*o);e(f,w,_,i,g,d,u,v,r),e(m,b,M,i,g,d,u,v,r),r.start=f,r.end=m;const{newOriginalPoints:y}=Me(f,m,r.originalPoints);r.originalPoints=y}},jt=(t,e)=>new c.Vector3(t.x,t.y,0).distanceTo(new c.Vector3(e.x,e.y,0)),nr=(t,e,n=1e-6)=>{const r=new c.Vector3;return t.closestPointToPoint(e,!0,r),r.distanceTo(e)<n},Ne=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},At=(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,rr=t=>{const e=[];t.children.forEach(n=>{n.type=="GridHelper"||n.type=="DirectionalLight"||n.type=="AmbientLight"||e.push(n)}),e.forEach(n=>{t.remove(n),vn(n)})},bn=()=>`#${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")}`;function vn(t){for(;t.children&&t.children.length>0;){const e=t.children[0];t.remove(e),vn(e)}t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(e=>He(e)):He(t.material))}function He(t){for(const e of Object.keys(t)){const n=t[e];n&&typeof n=="object"&&typeof n.dispose=="function"&&n.dispose()}t.dispose()}var or=(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},ir=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,a=16777215){const s=[t,e,n,r];for(let w=0;w<s.length;w++)this.isValidVector3(s[w])||(console.error(`点${w+1}包含无效数据:`,s[w]),s[w]=new c.Vector3(w,0,w));const l=new c.BufferGeometry,h=new Float32Array([s[0].x,s[0].y,s[0].z,s[1].x,s[1].y,s[1].z,s[2].x,s[2].y,s[2].z,s[3].x,s[3].y,s[3].z]),u=[0,1,2,0,2,3],d=new Float32Array([0,0,1,0,1,1,0,1]);l.setAttribute("position",new c.BufferAttribute(h,3)),l.setAttribute("uv",new c.BufferAttribute(d,2)),l.setIndex(u),l.computeVertexNormals();const f=new c.Mesh(l,i),m=new c.EdgesGeometry(l),b=new c.LineSegments(m,new c.LineBasicMaterial({color:a}));return o.add(b),f}createSubdividedWallPlane(t,e,n,r,i){const o=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return o;const a=new c.Vector3(t.start.x,t.start.y,t.start.z),s=new c.Vector3(t.end.x,t.end.y,t.end.z),l=[a,s,new c.Vector3(t.end.x,t.end.y,t.rooftopPz),new c.Vector3(t.start.x,t.start.y,t.rooftopPz)];for(let w=0;w<l.length;w++)if(!this.isValidVector3(l[w]))return console.error(`墙体基础点${w}无效:`,l[w]),o;const h=a.distanceTo(s),u=Math.abs(t.rooftopPz-t.start.z);if(h===0||u===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",s),console.log(t.length),o;const d=h/n,f=u/e,m=new c.Vector3().subVectors(s,a).normalize(),b=new c.Vector3(0,0,1);for(let w=0;w<e;w++)for(let _=0;_<n;_++)try{const M={points:[new c.Vector3().copy(a).add(m.clone().multiplyScalar(_*d)).add(b.clone().multiplyScalar(w*f)),new c.Vector3().copy(a).add(m.clone().multiplyScalar((_+1)*d)).add(b.clone().multiplyScalar(w*f)),new c.Vector3().copy(a).add(m.clone().multiplyScalar((_+1)*d)).add(b.clone().multiplyScalar((w+1)*f)),new c.Vector3().copy(a).add(m.clone().multiplyScalar(_*d)).add(b.clone().multiplyScalar((w+1)*f))],userData:{}};M.userData={type:"wallSegment",row:w,col:_,originalMaterial:r,width:d,height:f},o.push(M)}catch(M){console.error(`创建墙体小平面(${w}, ${_})时出错:`,M)}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,a=t.expectedDensity,s=e/Math.max(i,.001),l=e>=o,h=s>=a*.3;let u=!0;return i<.5&&e>0&&(u=this.checkSmallAreaDistribution(t,n,r)),l&&h&&u}checkSmallAreaDistribution(t,e,n){if(e.length<2)return!0;const r=e.map(s=>n[s]);t.bounds;const i=t.center;let o=0;const a=Math.sqrt(t.area)*.3;return r.forEach(s=>{s.distanceTo(i)<=a&&o++}),o/r.length>=.3}getFailureReason(t,e){const n=t.area,r=t.minRequiredPoints,i=t.expectedDensity,o=e/Math.max(n,.001),a=[];return e===0?a.push("无点"):(e<r&&a.push(`点数不足: ${e}/${r}`),o<i*.3&&a.push(`密度不足: ${o.toFixed(2)}/${i.toFixed(2)}`),n<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.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 c.Vector3().fromBufferAttribute(n,0),i=new c.Vector3().fromBufferAttribute(n,1),o=new c.Vector3().fromBufferAttribute(n,2);r.applyMatrix4(t.matrixWorld),i.applyMatrix4(t.matrixWorld),o.applyMatrix4(t.matrixWorld);const a=new c.Plane;return a.setFromCoplanarPoints(r,i,o),a}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 a=this.getWorldVerticesNew(o.points);if(a.length<4)return;const s=new c.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);o.userData.center=s,o.vertices=a,i.push(o)}}),this.results.totalSegments=i.length;for(const o of i){if(o.vertices.length<4)continue;const a=o.userData.center,s=`row${o.userData.row}_col${o.userData.col}`,[l,h,u,d]=o.vertices,f=new c.Vector3().subVectors(h,l).normalize(),m=new c.Vector3().subVectors(d,l).normalize(),b=l.distanceTo(h),w=l.distanceTo(d),_=new c.Plane;_.setFromCoplanarPoints(l,h,d);const M=b/2,g=w/2;for(let v=0;v<e.length;v++)this.isPointInWallSegmentOptimized(e[v],a,_,l,f,m,b,w,M,g,n)&&(this.results.pointsInSegments.has(s)||this.results.pointsInSegments.set(s,[]),this.results.pointsInSegments.get(s).push(v))}return i.forEach(o=>{const a=`row${o.userData.row}_col${o.userData.col}`,s=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;s>=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:a,vertices:o.vertices,center:o.userData.center,mesh:o,pointCount:s,hasPointsButNotEnough:s>0&&s<1}))}),this.results.analysisTime=performance.now()-r,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,n,r,i,o,a,s,l,h,u){if(Math.abs(n.distanceToPoint(t))>u)return!1;const d=new c.Vector3().subVectors(t,e),f=Math.abs(d.dot(i)),m=Math.abs(d.dot(o));if(f>l&&m>h)return!1;const b=new c.Vector3().subVectors(t,r),w=b.dot(i),_=b.dot(o),M=w>=-u&&w<=a+u,g=_>=-u&&_<=s+u;return M&&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,a,s]=t,l=new c.Plane;if(l.setFromCoplanarPoints(i,o,s),Math.abs(l.distanceToPoint(e))>r)return!1;const h=new c.Vector3().subVectors(o,i).normalize(),u=new c.Vector3().subVectors(s,i).normalize();new c.Vector3().crossVectors(h,u).normalize();const d=new c.Vector3().subVectors(e,i),f=d.dot(h),m=d.dot(u),b=i.distanceTo(o),w=i.distanceTo(s),_=f>=-r&&f<=b+r,M=m>=-r&&m<=w+r;return _&&M&&n.distanceTo(e)<b/2&&n.distanceTo(e)<w/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 c.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 c.Box3;for(let r=0;r<e.count;r++){const i=new c.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 c.Vector3).toArray(),size:n.getSize(new c.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 d=`row${u.userData.row}_col${u.userData.col}`,f=i.has(d);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:d,isEmpty:f,visited:!1})}});const a=[],s=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,d]of i){const f=o.get(d.row)?.get(d.col);if(f&&!f.visited){const m=[],b=[[d.row,d.col]];for(f.visited=!0;b.length>0;){const[w,_]=b.shift(),M=`row${w}_col${_}`;i.has(M)&&m.push(i.get(M));for(const[g,v]of s){const y=w+g,x=_+v;if(o.has(y)&&o.get(y).has(x)){const p=o.get(y).get(x);!p.visited&&p.isEmpty&&(p.visited=!0,b.push([y,x]))}}}m.length>=r&&a.push(m)}}const l=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((u,d)=>d.length-u.length),highlightedMeshes:h,clusterMaterials:l,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,n,r,i){let o=0,a=0;const s=e;let l=!0;for(let w=r;w<=i;w++)t.has(s)&&t.get(s).has(w)?a++:l=!1;l&&o++;const h=n;let u=!0;for(let w=r;w<=i;w++)t.has(h)&&t.get(h).has(w)?a++:u=!1;u&&o++;const d=r;let f=!0;for(let w=e;w<=n;w++)t.has(w)&&t.get(w).has(d)?a++:f=!1;f&&o++;const m=i;let b=!0;for(let w=e;w<=n;w++)t.has(w)&&t.get(w).has(m)?a++:b=!1;return b&&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(h=>h.row))];return{width:[...new Set(t.map(h=>h.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)),a=Math.min(...e.map(l=>l.z)),s=Math.max(...e.map(l=>l.z));return{width:Math.abs(r-n),height:Math.max(Math.abs(o-i),Math.abs(s-a))}}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 c.MeshBasicMaterial({color:i,transparent:!0,opacity:.6,side:c.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 c.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 c.Vector3().add(r[0]).add(r[1]).add(r[2]).add(r[3]).multiplyScalar(.25),o=new c.Vector3().subVectors(r[1],r[0]).normalize(),a=new c.Vector3().subVectors(r[3],r[0]).normalize(),s=new c.Vector3().crossVectors(o,a).normalize(),l=new c.ArrowHelper(s,i,.3,16711680),h=new c.ArrowHelper(o,i,.2,65280),u=new c.ArrowHelper(a,i,.2,255);e.add(l),e.add(h),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(a=>a.geometry);n.forEach((a,s)=>{a.applyMatrix4(e[s].matrixWorld)});const r=De(n),i=e[0].material.clone(),o=new c.Mesh(r,i);return o.name="mergedWalls",o}catch(n){return console.error("合并网格时出错:",n),null}}},ar=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},sr=t=>{const e=new c.Vector3().copy(t.start).add(t.end).multiplyScalar(.5),n=new c.Vector3().subVectors(new c.Vector3(e.x,e.y,e.z+1),e).normalize(),r=new c.Vector3(t.direction.x,t.direction.y,0);r.applyAxisAngle(n,Math.PI/2);const i=new c.Vector3().copy(e).add(r.clone().multiplyScalar(t.length)),o=new c.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}},lr=(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 a=new c.Vector3(o.start.x,o.start.y,o.start.z);a.applyEuler(new c.Euler(-Math.PI/2,0,0));let s=new c.Vector3(o.end.x,o.end.y,o.end.z);if(s.applyEuler(new c.Euler(-Math.PI/2,0,0)),e.add(xe(String(i),new c.Vector3((a.x+s.x)/2,(a.y+s.y)/2,(a.z+s.z)/2))),(o.isBayWindow||o.isWindow)&&n)continue;const l=new c.Plane().setFromCoplanarPoints(new c.Vector3(o.start.x,o.start.y,o.start.z),new c.Vector3(o.end.x,o.end.y,o.end.z),new c.Vector3(o.start.x,o.start.y,o.rooftopPz)),h=[];o.originalPoints.forEach((p,P)=>{const V=new c.Vector3;l.projectPoint(p,V),h.push(V)});const u=new c.Vector3(o.start.x,o.start.y,o.start.z).distanceTo(new c.Vector3(o.end.x,o.end.y,o.end.z)),d=Math.abs(o.rooftopPz-o.start.z),f=new c.MeshBasicMaterial({color:"red",side:c.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),m=new c.Group,b=new ir,{horizontalSubdivisions:w,verticalSubdivisions:_}=b.initLimits4(u,d),M=b.createSubdividedWallPlane(o,_,w,f,m);b.analyzePointDistribution(M,h,.01);const g=new c.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:c.DoubleSide}),v=b.highlightEmptySegments(M,g,m),y=[];for(const p of v.clusters){const P=ar(p);P&&y.push(P)}const x=sr(o).direction;o.checkResults=y,o.verticalDirection=x,o.originaIndex=i,r.push(o)}return r},cr=(t,e)=>{console.log("lines",t);for(let n=0;n<t.length;n++){const r=t[n],i=[];r.originalPoints.forEach(v=>{let y=new c.Vector3(v.x,v.y,0),x=!1;for(let p=0;p<i.length;p++)if(At(y,i[p],.01)){x=!0;break}x||i.push(y)});const o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(r.length)))),a=1;let s=new c.Vector3(r.start.x,r.start.y,r.start.z),l=new c.Vector3(r.end.x,r.end.y,r.end.z),h=new c.Vector3().subVectors(l,s).normalize(),u=h.clone().cross(new c.Vector3(0,0,1)).normalize(),d=u.clone().negate(),f=[];const m=[];let b=r.length/o;console.log(b);for(let v=0;v<o;v++){const y=[];y.push(s.clone().addScaledVector(u,a)),y.push(y[0].clone().addScaledVector(h,b)),y.push(y[1].clone().addScaledVector(d,a*2)),y.push(s.clone().addScaledVector(d,b));let x=[];for(let p=0;p<i.length;p++)f.includes(p)||hr(i[p],y)&&(f.push(p),x.push(i[p]));x.length>0&&m.push(dr(x)),s=s.addScaledVector(h,b)}const w=new Float32Array(i.length*3);i.forEach((v,y)=>{w[y*3]=v.x,w[y*3+1]=v.y,w[y*3+2]=v.z});const _=new c.BufferGeometry;_.setAttribute("position",new c.BufferAttribute(w,3)),_.rotateX(-Math.PI/2),e.add(new c.Points(_,new c.PointsMaterial({color:bn(),size:.02})));const[M,g]=pr(m,{plane:"xy",trimRatio:0});Un(M,g,e)}};function $e(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 ur(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 hr(t,e,n="xy"){if(!e||e.length!==4)throw new Error("rectPoints must contain 4 points");const r=$e(t,n),i=e.map(s=>$e(s,n));let o=!1,a=!1;for(let s=0;s<4;s++){const l=i[s],h=i[(s+1)%4],u=ur(l,h,r);if(u>1e-9&&(o=!0),u<-1e-9&&(a=!0),o&&a)return!1}return!0}function dr(t){if(!t||t.length===0)return null;const e=new c.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 fr(t){return t instanceof c.Vector3?t.clone():Array.isArray(t)?new c.Vector3(t[0],t[1],t[2]):new c.Vector3(t.x,t.y,t.z)}function mr(t,e="xy"){const n=fr(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 Xe(t,e,n,r="xy"){if(r==="xy")return new c.Vector3(t,e,n);if(r==="xz")return new c.Vector3(t,n,e);if(r==="yz")return new c.Vector3(n,t,e);throw new Error(`Unsupported plane: ${r}`)}function gr(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,a=Math.sqrt(Math.max(0,i*i*.25-o)),s=i*.5+a;let l=e,h=s-t;const u=Math.hypot(l,h);return u<1e-12?{x:1,y:0}:{x:l/u,y:h/u}}function pr(t,e={}){const{plane:n="xy",trimRatio:r=0}=e;if(!t||t.length<2)return null;const i=t.map(L=>mr(L,n));let o=0,a=0,s=0;for(const L of i)o+=L.x,a+=L.y,s+=L.up;o/=i.length,a/=i.length,s/=i.length;let l=0,h=0,u=0;for(const L of i){const I=L.x-o,C=L.y-a;l+=I*I,h+=I*C,u+=C*C}l/=i.length,h/=i.length,u/=i.length;const d=gr(l,h,u),f={x:-d.y,y:d.x},m=[];for(const L of i){const I=L.x-o,C=L.y-a,F=I*d.x+C*d.y,k=I*f.x+C*f.y;m.push({s:F,t:k,up:L.up})}m.sort((L,I)=>L.s-I.s);const b=m.length;let w=Math.floor(b*r),_=Math.ceil(b*(1-r))-1;w=Math.max(0,Math.min(b-1,w)),_=Math.max(0,Math.min(b-1,_));const M=m[w],g=m[_],v=(()=>{const L=m.map(C=>C.t).sort((C,F)=>C-F),I=Math.floor(L.length/2);return L.length%2===0?(L[I-1]+L[I])*.5:L[I]})(),y=(()=>{const L=m.map(C=>C.up).sort((C,F)=>C-F),I=Math.floor(L.length/2);return L.length%2===0?(L[I-1]+L[I])*.5:L[I]})(),x=M.s,p=g.s,P=v,V=v,z=y,S=y,E=o+d.x*x+f.x*P,D=a+d.y*x+f.y*P,T=o+d.x*p+f.x*V,B=a+d.y*p+f.y*V;return[Xe(E,D,z,n),Xe(T,B,S,n)]}var yr=async(t,e,n,r)=>{rr(r);let i=await fetch(t);if(!i)return;let o=await i.json();const a=new c.Group,s=new c.Group,l=new c.Group,h=new c.Group,u=new c.Group,d=new c.Group,f=new c.Group,m=new c.Group;let b=await fetch("/src/data/beamData/epu/forBeamLines.json");if(console.log(b),!b)return;let w=await b.json();for(let k=0;k<o.length;k++){const A=o[k];if(!A)continue;let G=new c.Vector3(A.start.x,A.start.y,A.start.z);G.applyEuler(new c.Euler(-Math.PI/2,0,0));let q=new c.Vector3(A.end.x,A.end.y,A.end.z);q.applyEuler(new c.Euler(-Math.PI/2,0,0)),m.add(xe(String(k),new c.Vector3((G.x+q.x)/2,(G.y+q.y)/2,(G.z+q.z)/2)))}o.sort((k,A)=>k.originalIndex-A.originalIndex),console.log("lins",o);let _=await fetch(e);if(!_)return;let M=await _.json();const g=Array.isArray(M)?M:Object.values(M);let v=await fetch(n);if(console.log("respcd",v),!v)return;let y=await v.json(),x=0;for(let k=0;k<y.length;k++){const A=y[k];if(A.isFindBeam=!1,A.category=="door"){let G=new c.Vector3(A.center.x,A.center.y,A.center.z);G.applyEuler(new c.Euler(-Math.PI/2,0,0)),m.add(xe(`door:${x}`,G)),x++}}r.add(m),console.log(w),console.time();const{beamGroup:p}=await Mn(o,g,y,w,r);console.timeEnd(),console.log("beamGroup",p);const P=new c.MeshBasicMaterial({color:"#cffd00",transparent:!0,opacity:.4,side:c.DoubleSide}),V=new c.MeshBasicMaterial({color:"#ff0000",transparent:!0,opacity:.4,side:c.DoubleSide}),z=new c.MeshBasicMaterial({color:"#e100ff",transparent:!0,opacity:.4,side:c.DoubleSide}),S=new c.MeshBasicMaterial({color:"#0400ff",transparent:!0,opacity:.4,side:c.DoubleSide}),E=new c.LineBasicMaterial({color:"#cffd00"}),D=[];for(let k=0;k<o.length;k++){let A=o[k];if(A.checkResults)for(const G of A.checkResults)for(const q of G.originalVertices){const[H,N,U,$]=q,Q=new c.BufferGeometry,et=new Float32Array([H.x,H.y,H.z,N.x,N.y,N.z,U.x,U.y,U.z,$.x,$.y,$.z]);Q.setAttribute("position",new c.BufferAttribute(et,3)),Q.setIndex([0,1,2,0,2,3]),Q.computeVertexNormals();const O=new c.EdgesGeometry(Q,1);D.push(O)}}if(D.length>0){const k=De(D,!1);k.rotateX(-Math.PI/2),a.add(new c.LineSegments(k,E)),a.visible=!1,r.add(a),D.forEach(A=>A.dispose())}new c.PointsMaterial({color:65535,size:.01});for(const k of o){if(!k.originalPoints||k.originalPoints.length===0)continue;const A=new Float32Array(k.originalPoints.length*3);k.originalPoints.forEach((N,U)=>{A[U*3]=N.x,A[U*3+1]=N.y,A[U*3+2]=N.z});const G=new c.BufferGeometry;G.setAttribute("position",new c.BufferAttribute(A,3)),G.rotateX(-Math.PI/2),s.add(new c.Points(G,new c.PointsMaterial({color:bn(),size:.02})));let q=[];q.push(new c.Vector3(k.start.x,k.start.y,k.start.z)),q.push(new c.Vector3(k.end.x,k.end.y,k.end.z));const H=new c.BufferGeometry;H.setFromPoints(q),H.rotateX(-Math.PI/2),d.add(new c.Line(H,E))}d.visible=!1,r.add(s),r.add(d);let T=[],B=[],L=new c.LineBasicMaterial({color:"#f30606"}),I=new c.MeshBasicMaterial({color:"#071ac4"});for(let k=0;k<g.length;k++){let A=new c.SphereGeometry(.05);A.translate(g[k].x,g[k].y,g[k].z);let G=[],q=new c.Vector3(g[k].x,g[k].y,g[k].z);const H=new c.Quaternion(g[k].qx,g[k].qy,g[k].qz,g[k].qw),N=new c.Vector3(0,0,-1).applyQuaternion(H),U=q.clone().addScaledVector(N,.001);G.push(q),G.push(U);let $=new c.BufferGeometry;$.setFromPoints(G),B.push($),T.push(A)}if(T.length>0){const k=De(T,!1);k.rotateX(-Math.PI/2),l.add(new c.Mesh(k,I)),T.forEach(A=>A.dispose())}if(B.length>0){const k=De(B,!1);k.rotateX(-Math.PI/2),l.add(new c.Line(k,L)),B.forEach(A=>A.dispose())}r.add(l);const{AiProjectionGroup:C,AiProjectionGroup2:F}=Qn(y);return h.add(C),h.rotateX(-Math.PI/2),r.add(h),u.add(F),u.visible=!1,u.rotateX(-Math.PI/2),r.add(u),console.log("jsonpcdData",y),o.forEach(k=>{k.doorAndBeamData&&k.doorAndBeamData.length>0&&(k.doorAndBeamData.forEach(A=>{if(A.beamStart){let U=new c.BufferGeometry;const $=new Float32Array([A.beamStart.x,A.beamStart.y,A.beamStart.z,A.beamEnd.x,A.beamEnd.y,A.beamEnd.z,A.beamEnd.x,A.beamEnd.y,A.beamEnd.z+A.beamHeight,A.beamStart.x,A.beamStart.y,A.beamStart.z+A.beamHeight]);U.setAttribute("position",new c.BufferAttribute($,3)),U.setIndex([0,1,2,0,2,3]),U.computeVertexNormals(),U.rotateX(-Math.PI/2),f.add(new c.Mesh(U,P))}let G=new c.BufferGeometry;const q=new Float32Array([A.doorStart.x,A.doorStart.y,A.doorStart.z,A.doorEnd.x,A.doorEnd.y,A.doorEnd.z,A.doorEnd.x,A.doorEnd.y,A.doorEnd.z+A.doorHeight,A.doorStart.x,A.doorStart.y,A.doorStart.z+A.doorHeight]);G.setAttribute("position",new c.BufferAttribute(q,3)),G.setIndex([0,1,2,0,2,3]),G.computeVertexNormals(),G.rotateX(-Math.PI/2),A.isDoor?f.add(new c.Mesh(G,S)):A.type=="beam"?f.add(new c.Mesh(G,z)):f.add(new c.Mesh(G,V));let H=`id:${A.id},Nid:${A.nearId}`,N=new c.Vector3((A.doorStart.x+A.doorEnd.x)/2,(A.doorStart.y+A.doorEnd.y)/2,A.doorStart.z+A.doorHeight);N.applyEuler(new c.Euler(-Math.PI/2,0,0)),f.add(xe(H,N))}),r.add(f))}),{checkResultGroup:a,pointCloudGroup:s,runData:l,pcdGroup:h,pcdGroup2:u,pointLineGroup:d,beamDoorGroup:f,lineIndexGroup:m}},Mn=async(t,e,n,r,i)=>{if(r&&r.length>0)for(let y=0;y<r.length;y++){const x=r[y];x.isLine2=!0,t.push(x)}if(wn(t,i),t.length<=0||e.length<=0)return t;n||(n=[]);for(const y of t){let x=[];if(!(!y.checkResults||y.checkResults.length<=0)){for(let p=0;p<y.checkResults.length;p++){let E=function(L){for(;S[L]!==L;)S[L]=S[S[L]],L=S[L];return L};var v=E;const P=y.checkResults[p];if(P.isDoor=!1,!P.originalVertices||P.originalVertices.length==0)continue;const V=[];P.originalVertices.forEach(L=>{let I=[];L.forEach(C=>{I.push(new c.Vector3(C.x,C.y,C.z))}),V.push(I)});const z=V.length,S=Array.from({length:z},(L,I)=>I);for(let L=0;L<z;L++)for(let I=L+1;I<z;I++){const C=V[L],F=V[I];if(C.some(k=>F.some(A=>k.equals(A)))){const k=E(L),A=E(I);k!==A&&(S[k]=A)}}const D=new Map;let T=-1,B=-1;for(let L=0;L<z;L++){const I=E(L);D.has(I)||D.set(I,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const C=D.get(I);let[F,k,A,G]=V[L];const q=new c.Vector3().add(F).add(k).add(A).add(G).multiplyScalar(.25);if(C.points.push(...V[L]),C.area+=F.distanceTo(k)*F.distanceTo(G),C.originalVertices.push(V[L]),C.index=p,C.centerPts.push(q),T==-1||B==-1){let H=new c.Vector3().subVectors(F,k).normalize();B=F.distanceTo(G),T=F.distanceTo(k);let N=Kt(H,new c.Vector3(0,0,1));N&&N.parallel&&([B,T]=[T,B])}C.gridWidth=T,C.gridHeight=B}x.push(...D.values())}y.mergeCheckRegion=x}}let o=new Map;for(const y of t){if(y.length<.3)continue;let x=y.rooftopPz-y.start.z,p=Math.floor(y.rooftopPz-y.start.z);o.has(p)?o.set(p,{num:o.get(p).num+1,totalHeight:o.get(p).totalHeight+x}):o.set(p,{num:1,totalHeight:x})}let a=[...o.entries()].reduce((y,x)=>x[1].num>y[1].num?x:y);a[0],a[1].totalHeight/a[1].num;const s=[];for(let y=0;y<n.length;y++){const x=n[y];if(x.isFindBeam=!1,x.category=="door"){let p=[];x.coordinatesByArea.coordinates.forEach(E=>{p.push(new c.Vector3(E.x,E.y,E.z))}),p[0].equals(p[p.length-1])&&p.pop();let P=p[0].distanceTo(p[1]),V=p[0].distanceTo(p[3]);V>P&&([P,V]=[V,P],p=[p[0],p[3],p[2],p[1]]);let z=Ut(p[0],p[3],!0),S=Ut(p[1],p[2],!0);s.push({doorStartPt:z,doorEndPt:S,boxPoints:p,minZ:x.coordinatesByArea.heightData.minZ,maxZ:x.coordinatesByArea.heightData.maxZ,index:y,isFind:!1,inWall:!1})}}for(let y=0;y<s.length;y++){const x=s[y];for(let p=0;p<t.length;p++){if(t[p].length<.5)continue;let P=[];const V=Ut(t[p].start,t[p].end,!0);P.push(V),P.push(Ut(V,t[p].start,!0)),P.push(Ut(V,t[p].end,!0));let z=!1;const S=x.boxPoints.length;for(let E=0;E<P.length;E++){const D=P[E].x,T=P[E].y;for(let B=0,L=S-1;B<S;L=B++){const I=x.boxPoints[B].x,C=x.boxPoints[B].y,F=x.boxPoints[L].x,k=x.boxPoints[L].y;C>T!=k>T&&D<(F-I)*(T-C)/(k-C)+I&&(z=!z)}if(z)break}if(z){let E=new c.Vector3(t[p].start.x,t[p].start.y,0),D=new c.Vector3(t[p].end.x,t[p].end.y,0),T=x.doorStartPt.distanceTo(x.doorEndPt),B=E.distanceTo(D),L=ee(x.doorStartPt,x.doorEndPt,E,D);if(Math.abs(B-T)<.5&&L&&L.angleDeg<15){x.doorStartPt=new c.Vector3(t[p].start.x,t[p].start.y,0),x.doorEndPt=new c.Vector3(t[p].end.x,t[p].end.y,0);break}else if(Math.abs(B-T)>1.3&&L&&L.angleDeg<15){let I=te(x.doorStartPt,x.doorEndPt,E,D,{parallelAngleMax:c.MathUtils.degToRad(15)}),C=x.doorStartPt.distanceTo(E),F=x.doorStartPt.distanceTo(D),k=x.doorEndPt.distanceTo(E),A=x.doorEndPt.distanceTo(D),G=C<.2||F<.2||k<.2||A<.2;if(I&&I.type=="collinear_overlap"&&I.maxPerpendicularDistance<.1&&!G){x.inWall=!0;break}else{let q=new c.Line3(E,D),H=q.closestPointToPoint(x.doorStartPt,!0,new c.Vector3),N=q.closestPointToPoint(x.doorEndPt,!0,new c.Vector3),U=H.distanceTo(x.doorStartPt),$=N.distanceTo(x.doorEndPt);if(U<.1||$<.1){x.inWall=!0;break}}}}else continue}}let l=0,h=[],u=[],d=[];const f=[];let m=.2;for(let y=0;y<t.length;y++){const x=t[y];if(x.doorAndBeamData=[],!x.mergeCheckRegion||x.mergeCheckRegion.length==0)continue;x.completePointAreaPercentage=-1;let p=new c.Box3;p.setFromPoints(x.originalPoints);let P=p.max.z;p.min.z;const V=new c.Vector3(x.start.x,x.start.y,x.start.z),z=new c.Vector3(x.end.x,x.end.y,x.end.z);let S=x.rooftopPz-x.start.z,E=0;for(const T of x.mergeCheckRegion){const{facePoints:B,boxArea:L,totalInPlaneNum:I}=Jn(T.points,T.gridWidth,T.gridHeight,T.centerPts);if(!B||B.length<=0)continue;B[0].distanceTo(B[1]);let C=B[0].distanceTo(B[3]);const F=T.gridHeight*(C/T.gridHeight/3*2)+T.gridHeight/2;let k=new c.Vector3(B[0].x,B[0].y,B[0].z+F),A=new c.Vector3(B[1].x,B[1].y,B[1].z+F);const G=new c.Line3(k,A),q=[];let H=new c.Vector3;T.points.forEach(et=>{G.closestPointToPoint(et,!0,H).distanceTo(et)<T.gridHeight+.01&&q.push(et)});let N=[],U=[];for(;;){let et=[];for(let O=0;O<q.length;O++)U.includes(O)||et.length==0&&(et.push(q[O]),U.push(O));for(let O=0;O<q.length;O++)if(!U.includes(O)){for(let j=0;j<et.length;j++)if(q[O].distanceTo(et[j])<T.gridWidth+.01){et.push(q[O]),U.push(O),O=-1;break}}if(et.length==0)break;N.push(et)}const $=[];for(let et=0;et<N.length;et++){const O={lineSt:new c.Vector3,lineEd:new c.Vector3,facePoints:[]};let j=Ne(N[et]);Array.isArray(j)&&j.length==2&&(O.lineSt=j[0],O.lineEd=j[1],O.facePoints.push(new c.Vector3(j[0].x,j[0].y,B[0].z)),O.facePoints.push(new c.Vector3(j[1].x,j[1].y,B[0].z)),O.facePoints.push(new c.Vector3(j[1].x,j[1].y,B[2].z)),O.facePoints.push(new c.Vector3(j[0].x,j[0].y,B[2].z)),$.push(O))}E+=T.area;let Q=0;if(I!=0&&(Q=T.gridHeight*T.gridWidth*I),(T.area-Q)/L*100>70&&$.length==1||$.length>1)for(let et=0;et<$.length;et++){const O=$[et];let j=O.facePoints[0].distanceTo(O.facePoints[1]),dt=O.facePoints[0].distanceTo(O.facePoints[3]),Nt=j/x.length*100,It=x.rooftopPz-O.facePoints[2].z;if(dt<1.5||P<O.facePoints[2].z||It>S/3*2)continue;let kt=!1,Pt=!1,Mt=!1,Tt=[],nt=O.facePoints[2].clone(),at=O.facePoints[3].clone(),Z=O.facePoints[0].clone(),K=O.facePoints[1].clone(),qt=!1,Ht=-1;if(Math.abs(O.facePoints[0].z-x.start.z)<.25){if(j>.17&&x.length>.5){let Ft=jt(V,Z),tt=jt(V,K),ft=jt(z,Z),Y=jt(z,K);const wt=.1,ct=10;if(Ft<wt||tt<wt){const{newOriginalPoints:Lt}=Me(Z,K,x.originalPoints),_t=[],Gt=[];if(Lt.forEach(lt=>{lt.z>=nt.z?_t.push(lt):lt.z<=Z.z&&Gt.push(lt)}),_t.length>10){const lt=new c.Vector3(x.start.x,x.start.y,0),bt=new c.Vector3(x.end.x,x.end.y,0),zt=new c.Vector3().subVectors(lt,bt).normalize();let $t=new c.Vector3,X=1/0,R=-1,mt=!1,Vt=!1;for(let st=0;st<t.length;st++){if(st==y)continue;const yt=new c.Vector3(t[st].start.x,t[st].start.y,0),vt=new c.Vector3(t[st].end.x,t[st].end.y,0),Ct=Jt(lt,bt,yt,vt);let Bt=Qt(lt,bt,yt,vt);if(Ct!=null){if(Bt&&Bt.angle>85){let J=Ct.point.distanceTo(lt);if(Ct.point.distanceTo(bt),J<.3){Vt=!0,X=1/0,R=-1;break}}continue}if(Bt&&Bt.angle>85){let J=ee(lt,bt,new c.Line3(yt,vt).closestPointToPoint(lt,!0,$t),lt);if(!J||J.direction!="same")continue;const gt=lt.clone().addScaledVector(zt,ct),ot=bt.clone().addScaledVector(zt.clone().negate(),ct);let rt=new c.Vector3().subVectors(vt,yt).normalize();const ht=Jt(gt,ot,yt.clone().addScaledVector(rt.clone().negate(),.03),vt.clone().addScaledVector(rt,.03));if(ht==null)continue;let Dt=lt.distanceTo(ht.point);Dt<X&&(X=Dt,R=st)}else if(Bt&&Bt.angle<5){const J=new c.Vector3(Z.x,Z.y,0),gt=new c.Vector3(K.x,K.y,0);let ot=jt(J,yt),rt=jt(J,vt),ht=jt(gt,yt),Dt=jt(gt,vt);if(ot<.08||rt<.08||ht<.08||Dt<.08){mt=!0,X=1/0,R=-1;break}}}if(y==33&&console.log("1",X,mt,x.length-j),X!=1/0&&X<2&&x.length-j>.2&&X<j*3)t[R].length>.25&&j+X>.5&&(qt=!0,Ft<wt?(at=at.addScaledVector(zt,X),Z=Z.addScaledVector(zt,X)):(nt=nt.addScaledVector(zt,X),K=K.addScaledVector(zt,X)));else if(!mt&&!Vt&&x.length-j>.1)continue}else continue}if(ft<wt||Y<wt){const{newOriginalPoints:Lt}=Me(Z,K,x.originalPoints),_t=[],Gt=[];if(Lt.forEach(lt=>{lt.z>=nt.z?_t.push(lt):lt.z<=Z.z&&Gt.push(lt)}),_t.length>10){const lt=new c.Vector3(x.start.x,x.start.y,0),bt=new c.Vector3(x.end.x,x.end.y,0),zt=new c.Vector3().subVectors(bt,lt).normalize();let $t=new c.Vector3,X=1/0,R=-1,mt=!1,Vt=!1;for(let st=0;st<t.length;st++){if(st==y)continue;const yt=new c.Vector3(t[st].start.x,t[st].start.y,0),vt=new c.Vector3(t[st].end.x,t[st].end.y,0),Ct=Jt(lt,bt,yt,vt);let Bt=Qt(lt,bt,yt,vt);if(Ct!=null){if(Bt&&Bt.angle>85&&(Ct.point.distanceTo(lt),Ct.point.distanceTo(bt)<.3)){Vt=!0,X=1/0,R=-1;break}continue}if(Bt&&Bt.angle>85){let J=ee(bt,lt,new c.Line3(yt,vt).closestPointToPoint(bt,!0,$t),bt);if(!J||J.direction!="same")continue;const gt=lt.clone().addScaledVector(zt.clone().negate(),ct),ot=bt.clone().addScaledVector(zt,ct);let rt=new c.Vector3().subVectors(vt,yt).normalize();const ht=Jt(gt,ot,yt.clone().addScaledVector(rt.clone().negate(),.03),vt.clone().addScaledVector(rt,.03));if(ht==null)continue;let Dt=bt.distanceTo(ht.point);Dt<X&&(X=Dt,R=st)}else if(Bt&&Bt.angle<5){const J=new c.Vector3(Z.x,Z.y,0),gt=new c.Vector3(K.x,K.y,0);let ot=jt(J,yt),rt=jt(J,vt),ht=jt(gt,yt),Dt=jt(gt,vt);if(ot<.08||rt<.08||ht<.08||Dt<.08){mt=!0,X=1/0,R=-1;break}}}if(y==33&&console.log("2",X,mt),X!=1/0&&X<2&&x.length-j>.2&&X<j*3)t[R].length>.25&&j+X>.5&&(qt=!0,ft<wt?(at=at.addScaledVector(zt,X),Z=Z.addScaledVector(zt,X)):(nt=nt.addScaledVector(zt,X),K=K.addScaledVector(zt,X)));else if(!mt&&!Vt&&x.length-j>.1)continue}else continue}j=at.distanceTo(nt)}if(Nt<85&&j>.3||j>.7&&dt>S-S/3){let Ft=!1;for(let tt=0;tt<e.length;tt++){let ft=tt+1;if(ft>=e.length)continue;let Y=new c.Vector3(e[tt].x,e[tt].y,e[tt].z),wt=new c.Vector3(e[ft].x,e[ft].y,e[ft].z);if(Jt(new c.Vector3(Y.x,Y.y,0),new c.Vector3(wt.x,wt.y,0),new c.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),new c.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),.1)!=null){Ft=!0;break}}for(let tt=0;tt<s.length;tt++){let ft=new c.Vector3(s[tt].doorStartPt.x,s[tt].doorStartPt.y,0),Y=new c.Vector3(s[tt].doorEndPt.x,s[tt].doorEndPt.y,0),wt=new c.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),ct=new c.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Lt=O.facePoints[2].z<s[tt].maxZ||Math.abs(O.facePoints[2].z-s[tt].maxZ)<.3;if(Math.abs(O.facePoints[2].z-s[tt].maxZ),Lt){let _t=te(ft.clone(),Y.clone(),wt.clone(),ct.clone(),{distanceThreshold:2});if(_t&&_t.type=="collinear_gap"){let Gt=Ut(ft,Y),lt=new c.Line3(new c.Vector3(x.start.x,x.start.y,0),new c.Vector3(x.end.x,x.end.y,0)),bt=new c.Vector3,zt=lt.closestPointToPoint(Gt,!0,bt);if(Gt.distanceTo(zt)<.15){let $t=wt.distanceTo(ft),X=ct.distanceTo(ft);if($t>.25&&X>.25){let Vt=wt.distanceTo(Y),st=ct.distanceTo(Y);if(Vt>.2&&st>.2)continue}Pt=!0,Mt=!0,Tt.push(s[tt].index),s[tt].isFind=!0,Ht=tt,n[s[tt].index].isFindBeam=!0;let R=new c.Vector3().subVectors(wt,ct).normalize(),mt=ft.distanceTo(Y)-_t.overlap;X<$t&&R.negate(),$t>X?(nt=O.facePoints[2].clone().addScaledVector(R,mt),at=O.facePoints[3].clone(),Z=at.clone(),K=nt.clone(),Z.z=K.z=O.facePoints[0].z):(nt=O.facePoints[2].clone(),at=O.facePoints[3].clone().addScaledVector(R,mt),Z=at.clone(),K=nt.clone(),Z.z=K.z=O.facePoints[0].z)}}else if(_t&&_t.type=="collinear_overlap"&&_t.maxPerpendicularDistance<.35){let Gt=wt.distanceTo(ct),lt=Y.distanceTo(ft);if(Math.abs(Gt-_t.overlap)<.25||Math.abs(lt-_t.overlap)<.25){if(lt>Gt&&Math.abs(lt-_t.overlap)>1){let bt=wt.distanceTo(ft),zt=wt.distanceTo(Y),$t=ct.distanceTo(ft),X=ct.distanceTo(Y),R=bt<zt?bt:zt,mt=$t<X?$t:X,Vt=new c.Vector3().subVectors(wt,ct).normalize(),st=lt-_t.overlap;R<mt?(Vt.negate(),nt=O.facePoints[2].clone().addScaledVector(Vt,st),at=O.facePoints[3].clone(),Z=at.clone(),K=nt.clone(),Z.z=K.z=O.facePoints[0].z):(nt=O.facePoints[2].clone(),at=O.facePoints[3].clone().addScaledVector(Vt,st),Z=at.clone(),K=nt.clone(),Z.z=K.z=O.facePoints[0].z)}Pt=!0,Mt=!0,Tt.push(s[tt].index),s[tt].isFind=!0,n[s[tt].index].isFindBeam=!0,Ht=tt}}}}if(!Mt&&j<1.5)for(let tt=0;tt<s.length;tt++){if(s[tt].inWall)continue;let ft=new c.Vector3(s[tt].doorStartPt.x,s[tt].doorStartPt.y,0),Y=new c.Vector3(s[tt].doorEndPt.x,s[tt].doorEndPt.y,0),wt=new c.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),ct=new c.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Lt=new c.Vector3().subVectors(ft,Y).normalize(),_t=new c.Vector3().subVectors(wt,ct).normalize(),Gt=.25,lt=Jt(ft.clone().addScaledVector(Lt,Gt),Y.clone().addScaledVector(Lt.clone().negate(),Gt),wt.clone().addScaledVector(_t,Gt),ct.clone().addScaledVector(_t.clone().negate(),Gt)),bt=!0,zt=ft.distanceTo(wt),$t=ft.distanceTo(ct),X=Y.distanceTo(wt),R=Y.distanceTo(ct);(zt<m||$t<m||X<m||R<m||lt)&&bt&&(n[s[tt].index].isFindBeam=!0,Pt=!0,s[tt].isFind=!0,Ht=tt)}(Pt||Ft||Math.abs(dt-S)>.1&&dt>S/2&&j>.3)&&(kt=!0)}}if(kt){let Ft=!1;for(let X=0;X<d.length;X++){let R=te(d[X].start,d[X].end,Z,K);if(R&&R.type=="collinear_overlap"&&R.maxPerpendicularDistance<.01){Ft=!0;break}}if(Ft){Ht!=-1&&(n[s[Ht].index].isFindBeam=!1,s[Ht].isFind=!1);continue}d.push({start:Z,end:K});{new c.PointsMaterial({color:65535,size:.01});let X=new c.Vector3().subVectors(Z,K),R=new c.Vector3().subVectors(K,Z),mt=1/0,Vt=1/0,st=Z.clone(),yt=K.clone();const vt=[],Ct=[];let Bt=new c.Line3(nt,at),J=new c.Vector3,gt=999999;if(x.originalPoints.forEach(ot=>{if(ot.z-Z.z<dt/2+.1&&ot.z-Z.z>dt/2-.1&&vt.push(ot),ot.z>nt.z){let rt=Bt.closestPointToPoint(ot,!0,J),ht=new c.Vector3().subVectors(rt,nt),Dt=Kt(X,new c.Vector3().subVectors(rt,at)),Xt=Kt(R,ht);Dt&&Dt.parallel&&!Dt.sameDirection&&Xt&&Xt.parallel&&!Xt.sameDirection&&Ct.push(ot)}}),vt.length>0){const{newProjectPoints:ot}=Me(Z,K,vt);for(const rt of ot)rt.z=Z.z;ot.forEach(rt=>{let ht=new c.Vector3(rt.x,rt.y,Z.z),Dt=new c.Vector3().subVectors(ht,K),Xt=Kt(X,new c.Vector3().subVectors(ht,Z)),oe=Kt(R,Dt);if(Xt&&Xt.parallel&&Xt.sameDirection){let ae=ht.distanceTo(Z);ae<mt&&(mt=ae,st=ht)}else if(oe&&oe.parallel&&oe.sameDirection){let ae=ht.distanceTo(K);ae<Vt&&(Vt=ae,yt=ht)}})}if(st.equals(Z)||(Z=st,at=new c.Vector3(Z.x,Z.y,at.z)),yt.equals(K)||(K=yt,nt=new c.Vector3(K.x,K.y,nt.z)),Ct.length>10){const{newOnLinePoints:ot}=Me(at,nt,Ct);for(let rt=0;rt<ot.length;rt++){let ht=Bt.closestPointToPoint(ot[rt],!0,J).distanceTo(ot[rt]);ht>.02&&gt>ht&&(gt=ht)}nt.z+=gt,at.z+=gt,dt+=gt}}let tt=K.distanceTo(Z);if(tt<.4&&!Pt||tt<.3&&Pt)continue;u.includes(y)||u.push(y),x.checkResults[T.index].isDoor=!0;let ft="",Y={id:l,beamStart:nt,beamEnd:at,beamHeight:x.rooftopPz-nt.z,doorStart:Z,doorEnd:K,doorHeight:dt,nearId:-1,type:ft,isExtend:qt,isDoor:Pt,isPullOutDoor:Mt,pcbDoorIndexs:Tt,beamNearWallVec:new c.Vector3(0,0,0)},wt=!1,ct=new c.Vector3,Lt=new c.Vector3,_t=-1,Gt=-1,lt=-1;for(let X=0;X<h.length;X++){const R=t[h[X].linesIndex].doorAndBeamData[h[X].doorIndex];if(R.nearId!=-1)continue;let mt=ee(nt.clone(),at.clone(),R.beamStart.clone(),R.beamEnd.clone());if(mt&&mt.isParallel){let Vt=nt.distanceTo(at),st=R.beamStart.distanceTo(R.beamEnd),yt=new c.Line3(nt.clone(),at.clone());yt.start.z=0,yt.end.z=0;let vt=Ut(R.beamStart,R.beamEnd,!0);st>Vt&&(yt.start=new c.Vector3(R.beamStart.x,R.beamStart.y,0),yt.end=new c.Vector3(R.beamEnd.x,R.beamEnd.y,0),vt=Ut(nt,at,!0));let Ct=new c.Vector3,Bt=yt.closestPointToPoint(vt,!0,Ct),J=Bt.distanceTo(vt),gt=new c.Vector3().subVectors(vt,Bt).normalize(),ot=gt.clone().negate(),rt=vt.clone().addScaledVector(ot,J+.1),ht=Jt(yt.start,yt.end,vt,rt),Dt=!Pt&&!R.isDoor&&(Vt>st*2||st>Vt*2);if(J<.4&&ht!=null&&!Dt){R.nearId=l,Y.nearId=R.id;let Xt=.8;(R.isDoor||Y.isDoor)&&(R.isDoor=!0,Y.isDoor=!0);const oe=Tt.some(ae=>R.pcbDoorIndexs.includes(ae));Vt<st?Vt>Xt&&!R.isPullOutDoor?(R.beamStart=nt.clone().addScaledVector(ot,J),R.beamEnd=at.clone().addScaledVector(ot,J),R.doorStart=Z.clone().addScaledVector(ot,J),R.doorEnd=K.clone().addScaledVector(ot,J),R.doorHeight=Y.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):!Mt||Mt&&R.isPullOutDoor&&oe?(Y.beamStart=R.beamStart.clone().addScaledVector(gt,J),Y.beamEnd=R.beamEnd.clone().addScaledVector(gt,J),Y.doorStart=R.doorStart.clone().addScaledVector(gt,J),Y.doorEnd=R.doorEnd.clone().addScaledVector(gt,J),Y.doorHeight=R.doorHeight,Y.beamStart.z=Y.beamEnd.z=Y.doorStart.z+Y.doorHeight):(R.beamStart=nt.clone().addScaledVector(ot,J),R.beamEnd=at.clone().addScaledVector(ot,J),R.doorStart=Z.clone().addScaledVector(ot,J),R.doorEnd=K.clone().addScaledVector(ot,J),R.doorHeight=Y.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):Vt>st&&(st>Xt&&!Mt?(Y.beamStart=R.beamStart.clone().addScaledVector(ot,J),Y.beamEnd=R.beamEnd.clone().addScaledVector(ot,J),Y.doorStart=R.doorStart.clone().addScaledVector(ot,J),Y.doorEnd=R.doorEnd.clone().addScaledVector(ot,J),Y.doorHeight=R.doorHeight,Y.beamStart.z=Y.beamEnd.z=Y.doorStart.z+Y.doorHeight):!R.isPullOutDoor||Mt&&R.isPullOutDoor&&oe?(R.beamStart=nt.clone().addScaledVector(gt,J),R.beamEnd=at.clone().addScaledVector(gt,J),R.doorStart=Z.clone().addScaledVector(gt,J),R.doorEnd=K.clone().addScaledVector(gt,J),R.doorHeight=Y.doorHeight,R.beamStart.z=R.beamEnd.z=R.doorStart.z+R.doorHeight):(Y.beamStart=R.beamStart.clone().addScaledVector(ot,J),Y.beamEnd=R.beamEnd.clone().addScaledVector(ot,J),Y.doorStart=R.doorStart.clone().addScaledVector(ot,J),Y.doorEnd=R.doorEnd.clone().addScaledVector(ot,J),Y.doorHeight=R.doorHeight,Y.beamStart.z=Y.beamEnd.z=Y.doorStart.z+Y.doorHeight)),_t=Y.nearId,ct=R.beamStart.clone(),Lt=R.beamEnd.clone(),wt=!0,Gt=h[X].linesIndex,lt=h[X].doorIndex;break}}}let bt=!1;if(!wt){let X=new c.Line3(Z.clone(),K.clone());for(let R=0;R<t.length;R++){if(t[R].length<.5||R==y)continue;let mt=new c.Vector3(t[R].start.x,t[R].start.y,t[R].start.z),Vt=new c.Vector3(t[R].end.x,t[R].end.y,t[R].end.z),st=te(mt,Vt,Z,K),yt=ee(mt,Vt,Z,K);const vt=Ee(t[R]);if(st&&st.maxPerpendicularDistance<.5){if(yt&&yt.isParallel){let rt=new c.Line3(mt,Vt),ht=new c.Vector3(Z.x,Z.y,mt.z),Dt=rt.closestPointToPoint(ht,!0,new c.Vector3),Xt=Qt(Dt,ht,Z,K);Xt&&Xt.angle>85&&(Y.beamNearWallVec=new c.Vector3().subVectors(Dt,ht).normalize())}const Ct=[];t[R].originalPoints.forEach(rt=>{rt.z>Z.z+.2&&rt.z<Z.z+dt/2&&Ct.push(new c.Vector3(rt.x,rt.y,Z.z))});const Bt=new c.Vector3;let J=[],gt=[];for(let rt=0;rt<Ct.length;rt++){let ht=X.closestPointToPoint(Ct[rt],!0,Bt);ht.distanceTo(Ct[rt])<.15&&(J.push(Ct[rt]),gt.push(ht.clone()))}for(let rt=0;rt<gt.length;rt++)nr(X,gt[rt])&&J.push(gt[rt]);if(J=gt,J=or(J),J.length<150)continue;let ot=Ne(J);if(ot.length==2){let rt=ot[0].distanceTo(ot[1]);if(Math.abs(rt-X.distance())<.3){let ht=new c.Line3(mt,Vt),Dt=new c.Vector3(Z.x,Z.y,mt.z),Xt=ht.closestPointToPoint(Dt,!0,new c.Vector3);if(Y.beamNearWallVec=new c.Vector3().subVectors(Xt,Dt).normalize(),Y.beamStart.z>vt.maxZ-.03&&j>1)bt=!0;else if(Ft=!0,Ht!=-1&&(n[s[Ht].index].isFindBeam=!1,s[Ht].isFind=!1),Gt!=-1&&lt!=-1){const oe=t[Gt].doorAndBeamData[lt];oe.nearId=-1}break}}if(Ft)break}else st&&st.type=="collinear_overlap"&&st.maxPerpendicularDistance>.3&&st.maxPerpendicularDistance<.7&&(bt=!0)}if(Ft){if(j<2)continue;bt=!0}}let zt=!1;if(_t!=-1)for(let X=0;X<f.length&&!(f[X].length==1&&(f[X][0].id==l?(f[X].push({id:_t,beamStart:ct,beamEnd:Lt}),zt=!0):f[X][0].id==_t&&(f[X].push({id:l,beamStart:nt,beamEnd:at}),zt=!0),zt));X++);zt||f.push([{id:l,beamStart:nt,beamEnd:at}]);const $t=Y.doorStart.distanceTo(Y.doorEnd);if(Pt?ft="door":$t>1.8?ft="beam":ft=bt&&$t>1?"beam":"hole",Y.type=ft,Y.nearId!=-1&&ft=="hole"){let X=!1;for(let R=0;R<t.length;R++)if(t[R].doorAndBeamData){for(let mt=0;mt<t[R].doorAndBeamData.length;mt++)if(t[R].doorAndBeamData[mt].nearId==l&&t[R].doorAndBeamData[mt].type=="beam"){t[R].doorAndBeamData[mt].type=ft,X=!0;break}if(X)break}}if(x.doorAndBeamData.push(Y),h.push({linesIndex:y,doorIndex:x.doorAndBeamData.length-1}),l++,Mt&&j<2)break}}}let D=x.length*(x.rooftopPz-x.start.z);x.completePointAreaPercentage=E/D*100}if(u.length>1)for(let y=0;y<u.length;y++){let x=[];for(let p=0;p<t[u[y]].doorAndBeamData.length;p++){let P=!1;if(t[u[y]].doorAndBeamData[p].type==="beam"&&t[u[y]].doorAndBeamData[p].beamNearWallVec.x==0&&t[u[y]].doorAndBeamData[p].beamNearWallVec.y==0&&t[u[y]].doorAndBeamData[p].beamNearWallVec.z==0&&t[u[y]].doorAndBeamData[p].nearId==-1&&(P=!0),!P){let V=t[u[y]].doorAndBeamData[p].doorStart.clone(),z=t[u[y]].doorAndBeamData[p].doorEnd.clone();V.z=z.z=0;let S=V.distanceTo(z);for(let E=0;E<u.length;E++)if(y!=E)for(let D=0;D<t[u[E]].doorAndBeamData.length;D++){let T=t[u[E]].doorAndBeamData[D].doorStart.clone(),B=t[u[E]].doorAndBeamData[D].doorEnd.clone();T.z=B.z=0,T.distanceTo(B);let L=te(V,z,T,B);if(L.type=="collinear_overlap"&&L.maxPerpendicularDistance<.2){let I=new c.Line3(T,B),C=Ut(V,z),F=I.closestPointToPoint(C,!0,new c.Vector3),k=C.distanceTo(F);if(Math.abs(S-L.overlap)<.1&&k<.04){t[u[E]].doorAndBeamData[D].nearId==t[u[y]].doorAndBeamData[p].id&&(t[u[E]].doorAndBeamData[D].nearId=-1),P=!0;break}}}}P||x.push(t[u[y]].doorAndBeamData[p])}x.length!=t[u[y]].doorAndBeamData.length&&(t[u[y]].doorAndBeamData=x)}let b=.65,w=2,_=[],M=[];for(let y=0;y<s.length;y++){if(s[y].isFind||s[y].inWall)continue;let x=new c.Vector3(s[y].doorStartPt.x,s[y].doorStartPt.y,0),p=new c.Vector3(s[y].doorEndPt.x,s[y].doorEndPt.y,0),P=new c.Vector3().subVectors(x,p).normalize();for(let V=0;V<t.length;V++){if(t[V].length<.7||t[V].completePointAreaPercentage>60)continue;let z=new c.Vector3(t[V].start.x,t[V].start.y,0),S=new c.Vector3(t[V].end.x,t[V].end.y,0),E=new c.Vector3().subVectors(z,S).normalize(),D=.3,T=x.clone().addScaledVector(P,D),B=p.clone().addScaledVector(P.clone().negate(),D),L=z.clone().addScaledVector(E,D),I=S.clone().addScaledVector(E.clone().negate(),D);Jt(T,B,L,I);let C=ee(T,B,L,I),F=Qt(T,B,L,I),k=x.distanceTo(z)>p.distanceTo(z)?p:x,A=k.distanceTo(z),G=k.distanceTo(S);if((A<m||G<m)&&C&&!C.isParallel&&F&&F.angle<85){let q=x.distanceTo(z)<x.distanceTo(S)?z:S,H=!1;for(let N=0;N<t.length;N++){if(N==V||_.includes(N)||t[N].length<.7)continue;let U=new c.Vector3(t[N].start.x,t[N].start.y,0),$=new c.Vector3(t[N].end.x,t[N].end.y,0),Q=new c.Vector3().subVectors(U,$).normalize(),et=Q.clone().negate(),O=U.clone().addScaledVector(Q,5),j=$.clone().addScaledVector(et,5),dt=Qt(z,S,U,$),Nt=te(z,S,U,$),It=Jt(z,S,O,j),kt=!0;if(It!=null&&(kt=It.point.distanceTo(z)<m||It.point.distanceTo(S)<m),(dt&&dt.angle>85||Nt&&Nt.type=="collinear_gap")&&kt){let Pt=new c.Line3(z,S),Mt=new c.Vector3,Tt=Pt.closestPointToPoint(U,!0,Mt),nt=Pt.closestPointToPoint($,!0,Mt),at=Tt.distanceTo(U),Z=nt.distanceTo($),K,qt;if(at>Z&&Z>b)K=$,qt=nt;else if(at<Z&&at>b)K=U,qt=Tt;else continue;if(at=q.distanceTo(U),Z=q.distanceTo($),at>w&&Z>w)continue;let Ht=ee(K,qt,U,$);if(!Ht||!Ht.isParallel)continue;let Ft=te(x,p,K,qt);if(Ft&&Ft.type=="collinear_overlap"&&Ft.maxPerpendicularDistance<.2)continue;K.z=qt.z=t[N].start.z;let tt=!1;for(let ct=0;ct<M.length;ct++){let Lt=te(M[ct].start,M[ct].end,K,qt);if(Lt&&Lt.type=="collinear_overlap"&&Lt.maxPerpendicularDistance<.2){tt=!0;break}}if(tt)continue;for(let ct=0;ct<t.length;ct++){if(t[ct].length<.5)continue;let Lt=te(new c.Vector3(t[ct].start.x,t[ct].start.y,t[ct].start.z),new c.Vector3(t[ct].end.x,t[ct].end.y,t[ct].end.z),K,qt);if(Lt&&Lt.type=="collinear_overlap"&&Lt.maxPerpendicularDistance<.1){tt=!0;break}}if(tt)continue;M.push({start:K,end:qt}),_.push(N);let ft=t[N].rooftopPz-t[N].start.z,Y=t[V].rooftopPz-t[V].start.z,wt=ft<Y?ft:Y;t[N].doorAndBeamData||(t[N].doorAndBeamData=[]),t[N].doorAndBeamData.push({id:l,beamStart:K,beamEnd:qt,beamHeight:wt,doorStart:K,doorEnd:qt,doorHeight:wt,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new c.Vector3(0,0,0)}),n[s[y].index].isFindBeam=!0,n[s[y].index].isFindOnlyDoor=!0,f.push([{id:l,beamStart:K,beamEnd:qt}]),l++,H=!0;break}}if(H)break}}}let g=[];for(let y=0;y<t.length;y++)t[y].isLine2||g.push(t[y]),t[y].isLine2&&t[y].doorAndBeamData.length!=0&&g.push(t[y]);return t.length=0,t.push(...g),{lines:t,beamGroup:f}},xr=(t,e)=>{if(t.length<=0)return t;for(const a of t){let s=[];for(let l=0;l<a.checkResults.length;l++){let m=function(M){for(;f[M]!==M;)f[M]=f[f[M]],M=f[M];return M};var o=m;const h=a.checkResults[l];if(h.isDoor=!1,!h.originalVertices||h.originalVertices.length==0)continue;const u=[];h.originalVertices.forEach(M=>{let g=[];M.forEach(v=>{g.push(new c.Vector3(v.x,v.y,v.z))}),u.push(g)});const d=u.length,f=Array.from({length:d},(M,g)=>g);for(let M=0;M<d;M++)for(let g=M+1;g<d;g++){const v=u[M],y=u[g];if(v.some(x=>y.some(p=>x.equals(p)))){const x=m(M),p=m(g);x!==p&&(f[x]=p)}}const b=new Map;let w=-1,_=-1;for(let M=0;M<d;M++){const g=m(M);b.has(g)||b.set(g,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const v=b.get(g);let[y,x,p,P]=u[M];const V=new c.Vector3().add(y).add(x).add(p).add(P).multiplyScalar(.25);if(v.points.push(...u[M]),v.area+=y.distanceTo(x)*y.distanceTo(P),v.originalVertices.push(u[M]),v.index=l,v.centerPts.push(V),w==-1||_==-1){let z=new c.Vector3().subVectors(y,x).normalize();_=y.distanceTo(P),w=y.distanceTo(x);let S=Kt(z,new c.Vector3(0,0,1));S&&S.parallel&&([_,w]=[w,_])}v.gridWidth=w,v.gridHeight=_}s.push(...b.values())}a.mergeCheckRegion=s}let n=new Map;for(const a of t){let s=a.rooftopPz-a.start.z,l=Math.floor(a.rooftopPz-a.start.z);n.has(l)?n.set(l,{num:n.get(l).num+1,totalHeight:n.get(l).totalHeight+s}):n.set(l,{num:1,totalHeight:s})}let r=[...n.entries()].reduce((a,s)=>s[1].num>a[1].num?s:a),i=r[0];r[1].totalHeight/r[1].num,new c.MeshBasicMaterial({color:"#cffd00",transparent:!0,opacity:.4,side:c.DoubleSide}),new c.PointsMaterial({color:65535,size:.01});for(let a=0;a<t.length;a++){const s=t[a],{minZ:l,maxZ:h}=Ee(s);if(l==null||h==null)continue;s.doorAndBeamData=[],s.completePointAreaPercentage=-1,h-l;let u=s.rooftopPz-s.start.z;if(u<i-.5||u>i+2||Math.abs(l-s.start.z)>.3||s.length<1)continue;let d=new c.Vector3(s.start.x,s.start.y,0),f=new c.Vector3(s.end.x,s.end.y,0);for(let m=0;m<t.length;m++){if(m==a||t[m].length<1)continue;const b=t[m];let w=new c.Vector3(b.start.x,b.start.y,0),_=new c.Vector3(b.end.x,b.end.y,0),M=ee(d,f,w,_),g=Ut(d,f),v=new c.Line3(w,_).closestPointToPoint(g,!0,new c.Vector3),y=g.distanceTo(v);const x=Ee(b);if(!(x.minZ===void 0||x.maxZ===void 0)&&!(x.maxZ-x.minZ>1)&&M&&M.isParallel&&y<.25&&Math.abs(h-x.minZ)<.1){let p=Ut(d,f),P=Ut(w,_);p.z=P.z=1,p.applyEuler(new c.Euler(-Math.PI/2,0,0)),P.applyEuler(new c.Euler(-Math.PI/2,0,0));let V=`w:${t[a].originaIndex},b:${t[m].originaIndex}`,z=`b:${t[m].originaIndex},w:${t[a].originaIndex}`;e.add(xe(V,p,{textColor:"#fd0000"})),e.add(xe(z,P,{textColor:"#fd0000"}))}}}return t},wr=(t,e)=>{if(!t||t.length<=0)return;let n={rectangles:[],threeEdgeRect:[]},r=new Set,i=.2,o=1.5,a=.15,s=2;if(!t[0].uuid){let l=1e4;for(let h=0;h<t.length;h++)t[h].uuid=l++}for(let l=0;l<t.length;l++){let h=t[l].length;if(r.has(t[l].uuid)||h<i||h>o)continue;let u=[],d=new c.Vector3(t[l].start.x,t[l].start.y,t[l].start.z),f=new c.Vector3(t[l].end.x,t[l].end.y,t[l].end.z),m=new c.Vector3().subVectors(f,d).normalize().clone().negate(),b=new c.Vector3,w=new c.Vector3,_=new c.Vector3;new c.Vector3;for(let M=0;M<t.length;M++){let g=t[M].length;if(M==l||g<i||g>o)continue;let v=new c.Vector3(t[M].start.x,t[M].start.y,t[M].start.z),y=new c.Vector3(t[M].end.x,t[M].end.y,t[M].end.z),x=Qt(d,f,v,y);if(!x||x.angle<85)continue;let p=At(v,d),P=At(v,f),V=At(y,d),z=At(y,f);if(!(!p&&!P&&!V&&!z)){p||P?(b=v.clone(),w=y.clone()):(b=y.clone(),w=v.clone()),_=new c.Vector3().subVectors(w,b).normalize(),_.clone().negate();for(let S=0;S<t.length;S++){let E=t[S].length;if(S==l||S==M||E<i||E>o)continue;let D=new c.Vector3(t[S].start.x,t[S].start.y,t[S].start.z),T=new c.Vector3(t[S].end.x,t[S].end.y,t[S].end.z),B=Qt(v,y,D,T);if(!B||B.angle<85)continue;let L=At(D,w),I=At(T,w);if(!L&&!I)continue;new c.Vector3;let C=new c.Vector3,F=new c.Vector3;L?(F=new c.Vector3().subVectors(T,D).normalize(),D.clone(),C=T.clone()):(F=new c.Vector3().subVectors(D,T).normalize(),T.clone(),C=D.clone());let k=Kt(m,F,.1);if(!(!k||!k.parallel||!k.sameDirection)){for(let A=0;A<t.length;A++){let G=t[A].length;if(A==l||A==M||A==S||G<i||G>o)continue;let q=new c.Vector3(t[A].start.x,t[A].start.y,t[A].start.z),H=new c.Vector3(t[A].end.x,t[A].end.y,t[A].end.z),N=Qt(q,H,D,T);if(!N||N.angle<85)continue;let U=At(q,C),$=At(H,C);if(!U&&!$)continue;new c.Vector3;let Q=new c.Vector3;U?(q.clone(),Q=H.clone()):(H.clone(),Q=q.clone());let et=At(Q,d),O=At(Q,f);if(!et&&!O)continue;let j=h*g;if(!(j<a||j>s)){u=[t[l].uuid,t[M].uuid,t[S].uuid,t[A].uuid];break}}if(u.length==4)break}}if(u.length==4)break}}u.length==4&&(u.forEach(M=>r.add(M)),n.rectangles.push(u))}for(let l=0;l<t.length;l++){let h=t[l].length;if(r.has(t[l].uuid)||h<i||h>o)continue;let u={indexs:[],missingEdge:{start:new c.Vector3,end:new c.Vector3}},d=new c.Vector3(t[l].start.x,t[l].start.y,t[l].start.z),f=new c.Vector3(t[l].end.x,t[l].end.y,t[l].end.z),m=!0,b=!0;for(let M=0;M<t.length;M++){if(M==l||t[M].length<i)continue;let g=new c.Vector3(t[M].start.x,t[M].start.y,t[M].start.z),v=new c.Vector3(t[M].end.x,t[M].end.y,t[M].end.z),y=At(g,d),x=At(v,d),p=At(g,f),P=At(v,f);if(y||x?m=!1:(p||P)&&(b=!1),!m&&!b)break}if(!m&&!b)continue;let w=new c.Vector3;m||([d,f]=[f,d]),w=new c.Vector3().subVectors(f,d).normalize();let _=w.clone().negate();for(let M=0;M<t.length;M++){let g=t[M].length;if(M==l||r.has(M)||g<i||g>o)continue;let v=new c.Vector3(t[M].start.x,t[M].start.y,t[M].start.z),y=new c.Vector3(t[M].end.x,t[M].end.y,t[M].end.z),x=Qt(d,f,v,y);if(!x||x.angle<85)continue;let p=At(v,f),P=At(y,f);if(!p&&!P)continue;new c.Vector3;let V=new c.Vector3;p?(v.clone(),V=y.clone()):(y.clone(),V=v.clone());for(let z=0;z<t.length;z++){let S=t[z].length;if(z==l||z==M||r.has(z)||S<i||S>o)continue;let E=new c.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),D=new c.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),T=Qt(v,y,E,D);if(!T||T.angle<85)continue;let B=At(E,V),L=At(D,V);if(!B&&!L)continue;let I=new c.Vector3,C=new c.Vector3;B?(I=E.clone(),C=D.clone()):(I=D.clone(),C=E.clone());let F=Kt(_,new c.Vector3().subVectors(C,I).normalize(),.1);if(!F||!F.parallel||!F.sameDirection)continue;let k=!0,A=!0;for(let q=0;q<t.length;q++){if(q==z||t[q].length<i)continue;let H=new c.Vector3(t[q].start.x,t[q].start.y,t[q].start.z),N=new c.Vector3(t[q].end.x,t[q].end.y,t[q].end.z),U=At(H,E),$=At(N,E),Q=At(H,D),et=At(N,D);if(U||$?k=!1:(Q||et)&&(A=!1),!k&&!A)break}if(!k&&!A)continue;let G=h*g;if(!(G<a||G>s)){u.indexs=[t[l].uuid,t[M].uuid,t[z].uuid],u.missingEdge.start=C,u.missingEdge.end=d;break}}if(u.indexs.length==3)break}u.indexs.length==3&&(u.indexs.forEach(M=>r.add(M)),n.threeEdgeRect.push(u))}return n},xt=11102230246251565e-32,Ot=134217729,br=(3+8*xt)*xt;function Te(t,e,n,r,i){let o,a,s,l,h=e[0],u=r[0],d=0,f=0;u>h==u>-h?(o=h,h=e[++d]):(o=u,u=r[++f]);let m=0;if(d<t&&f<n)for(u>h==u>-h?(a=h+o,s=o-(a-h),h=e[++d]):(a=u+o,s=o-(a-u),u=r[++f]),o=a,s!==0&&(i[m++]=s);d<t&&f<n;)u>h==u>-h?(a=o+h,l=a-o,s=o-(a-l)+(h-l),h=e[++d]):(a=o+u,l=a-o,s=o-(a-l)+(u-l),u=r[++f]),o=a,s!==0&&(i[m++]=s);for(;d<t;)a=o+h,l=a-o,s=o-(a-l)+(h-l),h=e[++d],o=a,s!==0&&(i[m++]=s);for(;f<n;)a=o+u,l=a-o,s=o-(a-l)+(u-l),u=r[++f],o=a,s!==0&&(i[m++]=s);return(o!==0||m===0)&&(i[m++]=o),m}function vr(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}function W(t){return new Float64Array(t)}var Mr=(3+16*xt)*xt,Pr=(2+12*xt)*xt,Vr=(9+64*xt)*xt*xt,de=W(4),Ye=W(8),je=W(12),Ue=W(16),Yt=W(4);function zr(t,e,n,r,i,o,a){let s,l,h,u,d,f,m,b,w,_,M,g,v,y,x,p,P,V;const z=t-i,S=n-i,E=e-o,D=r-o;y=z*D,f=Ot*z,m=f-(f-z),b=z-m,f=Ot*D,w=f-(f-D),_=D-w,x=b*_-(y-m*w-b*w-m*_),p=E*S,f=Ot*E,m=f-(f-E),b=E-m,f=Ot*S,w=f-(f-S),_=S-w,P=b*_-(p-m*w-b*w-m*_),M=x-P,d=x-M,de[0]=x-(M+d)+(d-P),g=y+M,d=g-y,v=y-(g-d)+(M-d),M=v-p,d=v-M,de[1]=v-(M+d)+(d-p),V=g+M,d=V-g,de[2]=g-(V-d)+(M-d),de[3]=V;let T=vr(4,de),B=Pr*a;if(T>=B||-T>=B||(d=t-z,s=t-(z+d)+(d-i),d=n-S,h=n-(S+d)+(d-i),d=e-E,l=e-(E+d)+(d-o),d=r-D,u=r-(D+d)+(d-o),s===0&&l===0&&h===0&&u===0)||(B=Vr*a+br*Math.abs(T),T+=z*u+D*s-(E*h+S*l),T>=B||-T>=B))return T;y=s*D,f=Ot*s,m=f-(f-s),b=s-m,f=Ot*D,w=f-(f-D),_=D-w,x=b*_-(y-m*w-b*w-m*_),p=l*S,f=Ot*l,m=f-(f-l),b=l-m,f=Ot*S,w=f-(f-S),_=S-w,P=b*_-(p-m*w-b*w-m*_),M=x-P,d=x-M,Yt[0]=x-(M+d)+(d-P),g=y+M,d=g-y,v=y-(g-d)+(M-d),M=v-p,d=v-M,Yt[1]=v-(M+d)+(d-p),V=g+M,d=V-g,Yt[2]=g-(V-d)+(M-d),Yt[3]=V;const L=Te(4,de,4,Yt,Ye);y=z*u,f=Ot*z,m=f-(f-z),b=z-m,f=Ot*u,w=f-(f-u),_=u-w,x=b*_-(y-m*w-b*w-m*_),p=E*h,f=Ot*E,m=f-(f-E),b=E-m,f=Ot*h,w=f-(f-h),_=h-w,P=b*_-(p-m*w-b*w-m*_),M=x-P,d=x-M,Yt[0]=x-(M+d)+(d-P),g=y+M,d=g-y,v=y-(g-d)+(M-d),M=v-p,d=v-M,Yt[1]=v-(M+d)+(d-p),V=g+M,d=V-g,Yt[2]=g-(V-d)+(M-d),Yt[3]=V;const I=Te(L,Ye,4,Yt,je);return y=s*u,f=Ot*s,m=f-(f-s),b=s-m,f=Ot*u,w=f-(f-u),_=u-w,x=b*_-(y-m*w-b*w-m*_),p=l*h,f=Ot*l,m=f-(f-l),b=l-m,f=Ot*h,w=f-(f-h),_=h-w,P=b*_-(p-m*w-b*w-m*_),M=x-P,d=x-M,Yt[0]=x-(M+d)+(d-P),g=y+M,d=g-y,v=y-(g-d)+(M-d),M=v-p,d=v-M,Yt[1]=v-(M+d)+(d-p),V=g+M,d=V-g,Yt[2]=g-(V-d)+(M-d),Yt[3]=V,Ue[Te(I,je,4,Yt,Ue)-1]}function Ve(t,e,n,r,i,o){const a=(e-o)*(n-i),s=(t-i)*(r-o),l=a-s,h=Math.abs(a+s);return Math.abs(l)>=Mr*h?l:-zr(t,e,n,r,i,o,h)}var Qo=(7+56*xt)*xt,Jo=(3+28*xt)*xt,ti=(26+288*xt)*xt*xt,ei=W(4),ni=W(4),ri=W(4),oi=W(4),ii=W(4),ai=W(4),si=W(4),li=W(4),ci=W(4),ui=W(8),hi=W(8),di=W(8),fi=W(4),mi=W(8),gi=W(8),pi=W(16),yi=W(12),xi=W(192),wi=W(192),bi=(10+96*xt)*xt,vi=(4+48*xt)*xt,Mi=(44+576*xt)*xt*xt,Pi=W(4),Vi=W(4),zi=W(4),Si=W(4),_i=W(4),Di=W(4),Ei=W(4),Ai=W(4),Ti=W(8),Bi=W(8),Ii=W(8),ki=W(8),Li=W(8),Ci=W(8),Ri=W(8),Fi=W(8),Gi=W(8),qi=W(4),Wi=W(4),Oi=W(4),Ni=W(8),Hi=W(16),$i=W(16),Xi=W(16),Yi=W(32),ji=W(32),Ui=W(48),Zi=W(64),Ki=W(1152),Qi=W(1152),Ji=(16+224*xt)*xt,ta=(5+72*xt)*xt,ea=(71+1408*xt)*xt*xt,na=W(4),ra=W(4),oa=W(4),ia=W(4),aa=W(4),sa=W(4),la=W(4),ca=W(4),ua=W(4),ha=W(4),da=W(24),fa=W(24),ma=W(24),ga=W(24),pa=W(24),ya=W(24),xa=W(24),wa=W(24),ba=W(24),va=W(24),Ma=W(1152),Pa=W(1152),Va=W(1152),za=W(1152),Sa=W(1152),_a=W(2304),Da=W(2304),Ea=W(3456),Aa=W(5760),Ta=W(8),Ba=W(8),Ia=W(8),ka=W(16),La=W(24),Ca=W(48),Ra=W(48),Fa=W(96),Ga=W(192),qa=W(384),Wa=W(384),Oa=W(384),Na=W(768),Ha=W(96),$a=W(96),Xa=W(96),Ya=W(1152),Ze=Math.pow(2,-52),ze=new Uint32Array(512),Ke=class Pn{static from(e,n=Ar,r=Tr){const i=e.length,o=new Float64Array(i*2);for(let a=0;a<i;a++){const s=e[a];o[2*a]=n(s),o[2*a+1]=r(s)}return new Pn(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,a=e.length>>1;let s=1/0,l=1/0,h=-1/0,u=-1/0;for(let z=0;z<a;z++){const S=e[2*z],E=e[2*z+1];S<s&&(s=S),E<l&&(l=E),S>h&&(h=S),E>u&&(u=E),this._ids[z]=z}const d=(s+h)/2,f=(l+u)/2;let m=0,b=0,w=0;for(let z=0,S=1/0;z<a;z++){const E=Be(d,f,e[2*z],e[2*z+1]);E<S&&(m=z,S=E)}const _=e[2*m],M=e[2*m+1];for(let z=0,S=1/0;z<a;z++){if(z===m)continue;const E=Be(_,M,e[2*z],e[2*z+1]);E<S&&E>0&&(b=z,S=E)}let g=e[2*b],v=e[2*b+1],y=1/0;for(let z=0;z<a;z++){if(z===m||z===b)continue;const S=Dr(_,M,g,v,e[2*z],e[2*z+1]);S<y&&(w=z,y=S)}let x=e[2*w],p=e[2*w+1];if(y===1/0){for(let E=0;E<a;E++)this._dists[E]=e[2*E]-e[0]||e[2*E+1]-e[1];ge(this._ids,this._dists,0,a-1);const z=new Uint32Array(a);let S=0;for(let E=0,D=-1/0;E<a;E++){const T=this._ids[E],B=this._dists[T];B>D&&(z[S++]=T,D=B)}this.hull=z.subarray(0,S),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(Ve(_,M,g,v,x,p)<0){const z=b,S=g,E=v;b=w,g=x,v=p,w=z,x=S,p=E}const P=Er(_,M,g,v,x,p);this._cx=P.x,this._cy=P.y;for(let z=0;z<a;z++)this._dists[z]=Be(e[2*z],e[2*z+1],P.x,P.y);ge(this._ids,this._dists,0,a-1),this._hullStart=m;let V=3;r[m]=n[w]=b,r[b]=n[m]=w,r[w]=n[b]=m,i[m]=0,i[b]=1,i[w]=2,o.fill(-1),o[this._hashKey(_,M)]=m,o[this._hashKey(g,v)]=b,o[this._hashKey(x,p)]=w,this.trianglesLen=0,this._addTriangle(m,b,w,-1,-1,-1);for(let z=0,S=0,E=0;z<this._ids.length;z++){const D=this._ids[z],T=e[2*D],B=e[2*D+1];if(z>0&&Math.abs(T-S)<=Ze&&Math.abs(B-E)<=Ze||(S=T,E=B,D===m||D===b||D===w))continue;let L=0;for(let A=0,G=this._hashKey(T,B);A<this._hashSize&&(L=o[(G+A)%this._hashSize],!(L!==-1&&L!==r[L]));A++);L=n[L];let I=L,C;for(;C=r[I],Ve(T,B,e[2*I],e[2*I+1],e[2*C],e[2*C+1])>=0;)if(I=C,I===L){I=-1;break}if(I===-1)continue;let F=this._addTriangle(I,D,r[I],-1,-1,i[I]);i[D]=this._legalize(F+2),i[I]=F,V++;let k=r[I];for(;C=r[k],Ve(T,B,e[2*k],e[2*k+1],e[2*C],e[2*C+1])<0;)F=this._addTriangle(k,D,C,i[D],-1,i[k]),i[D]=this._legalize(F+2),r[k]=k,V--,k=C;if(I===L)for(;C=n[I],Ve(T,B,e[2*C],e[2*C+1],e[2*I],e[2*I+1])<0;)F=this._addTriangle(C,D,I,-1,i[I],i[C]),this._legalize(F+2),i[C]=F,r[I]=I,V--,I=C;this._hullStart=n[D]=I,r[I]=n[k]=D,r[D]=k,o[this._hashKey(T,B)]=D,o[this._hashKey(e[2*I],e[2*I+1])]=I}this.hull=new Uint32Array(V);for(let z=0,S=this._hullStart;z<V;z++)this.hull[z]=S,S=r[S];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,n){return Math.floor(Sr(e-this._cx,n-this._cy)*this._hashSize)%this._hashSize}_legalize(e){const{_triangles:n,_halfedges:r,coords:i}=this;let o=0,a=0;for(;;){const s=r[e],l=e-e%3;if(a=l+(e+2)%3,s===-1){if(o===0)break;e=ze[--o];continue}const h=s-s%3,u=l+(e+1)%3,d=h+(s+2)%3,f=n[a],m=n[e],b=n[u],w=n[d];if(_r(i[2*f],i[2*f+1],i[2*m],i[2*m+1],i[2*b],i[2*b+1],i[2*w],i[2*w+1])){n[e]=w,n[s]=f;const _=r[d];if(_===-1){let g=this._hullStart;do{if(this._hullTri[g]===d){this._hullTri[g]=e;break}g=this._hullPrev[g]}while(g!==this._hullStart)}this._link(e,_),this._link(s,r[a]),this._link(a,d);const M=h+(s+1)%3;o<ze.length&&(ze[o++]=M)}else{if(o===0)break;e=ze[--o]}}return a}_link(e,n){this._halfedges[e]=n,n!==-1&&(this._halfedges[n]=e)}_addTriangle(e,n,r,i,o,a){const s=this.trianglesLen;return this._triangles[s]=e,this._triangles[s+1]=n,this._triangles[s+2]=r,this._link(s,i),this._link(s+1,o),this._link(s+2,a),this.trianglesLen+=3,s}};function Sr(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}function Be(t,e,n,r){const i=t-n,o=e-r;return i*i+o*o}function _r(t,e,n,r,i,o,a,s){const l=t-a,h=e-s,u=n-a,d=r-s,f=i-a,m=o-s,b=l*l+h*h,w=u*u+d*d,_=f*f+m*m;return l*(d*_-w*m)-h*(u*_-w*f)+b*(u*m-d*f)<0}function Dr(t,e,n,r,i,o){const a=n-t,s=r-e,l=i-t,h=o-e,u=a*a+s*s,d=l*l+h*h,f=.5/(a*h-s*l),m=(h*u-s*d)*f,b=(a*d-l*u)*f;return m*m+b*b}function Er(t,e,n,r,i,o){const a=n-t,s=r-e,l=i-t,h=o-e,u=a*a+s*s,d=l*l+h*h,f=.5/(a*h-s*l);return{x:t+(h*u-s*d)*f,y:e+(a*d-l*u)*f}}function ge(t,e,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){const o=t[i],a=e[o];let s=i-1;for(;s>=n&&e[t[s]]>a;)t[s+1]=t[s--];t[s+1]=o}else{const i=n+r>>1;let o=n+1,a=r;ve(t,i,o),e[t[n]]>e[t[r]]&&ve(t,n,r),e[t[o]]>e[t[r]]&&ve(t,o,r),e[t[n]]>e[t[o]]&&ve(t,n,o);const s=t[o],l=e[s];for(;;){do o++;while(e[t[o]]<l);do a--;while(e[t[a]]>l);if(a<o)break;ve(t,o,a)}t[n+1]=t[a],t[a]=s,r-o+1>=a-n?(ge(t,e,o,r),ge(t,e,n,a-1)):(ge(t,e,n,a-1),ge(t,e,o,r))}}function ve(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Ar(t){return t[0]}function Tr(t){return t[1]}var Qe=1e-6,he=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)>Qe||Math.abs(this._y1-i)>Qe)&&(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}},Le=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}},Br=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 a=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let b=0,w=0,_=n.length,M,g;b<_;b+=3,w+=2){const v=n[b]*2,y=n[b+1]*2,x=n[b+2]*2,p=t[v],P=t[v+1],V=t[y],z=t[y+1],S=t[x],E=t[x+1],D=V-p,T=z-P,B=S-p,L=E-P,I=(D*L-T*B)*2;if(Math.abs(I)<1e-9){if(i===void 0){i=o=0;for(const F of e)i+=t[F*2],o+=t[F*2+1];i/=e.length,o/=e.length}const C=1e9*Math.sign((i-p)*L-(o-P)*B);M=(p+S)/2-C*L,g=(P+E)/2+C*B}else{const C=1/I,F=D*D+T*T,k=B*B+L*L;M=p+(L*F-T*k)*C,g=P+(D*k-B*F)*C}a[w]=M,a[w+1]=g}let s=e[e.length-1],l,h=s*4,u,d=t[2*s],f,m=t[2*s+1];r.fill(0);for(let b=0;b<e.length;++b)s=e[b],l=h,u=d,f=m,h=s*4,d=t[2*s],m=t[2*s+1],r[l+2]=r[h]=f-m,r[l+3]=r[h+1]=d-u}render(t){const e=t==null?t=new he:void 0,{delaunay:{halfedges:n,inedges:r,hull:i},circumcenters:o,vectors:a}=this;if(i.length<=1)return null;for(let h=0,u=n.length;h<u;++h){const d=n[h];if(d<h)continue;const f=Math.floor(h/3)*2,m=Math.floor(d/3)*2,b=o[f],w=o[f+1],_=o[m],M=o[m+1];this._renderSegment(b,w,_,M,t)}let s,l=i[i.length-1];for(let h=0;h<i.length;++h){s=l,l=i[h];const u=Math.floor(r[l]/3)*2,d=o[u],f=o[u+1],m=s*4,b=this._project(d,f,a[m+2],a[m+3]);b&&this._renderSegment(d,f,b[0],b[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new he:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=e==null?e=new he: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 Le;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,r,i){let o;const a=this._regioncode(t,e),s=this._regioncode(n,r);a===0&&s===0?(i.moveTo(t,e),i.lineTo(n,r)):(o=this._clipSegment(t,e,n,r,a,s))&&(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 a=0,s=r.length;a<s;a+=2)if(e[i]===r[a]&&e[i+1]===r[a+1]&&e[(i+2)%o]===r[(a+s-2)%s]&&e[(i+3)%o]===r[(a+s-1)%s]){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 a=[];let s=o;do{const l=Math.floor(s/3);if(a.push(e[l*2],e[l*2+1]),s=s%3===2?s-2:s+1,i[s]!==t)break;s=r[s]}while(s!==o&&s!==-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: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,a=e[n-2],s=e[n-1],l,h=this._regioncode(a,s),u,d=0;for(let f=0;f<n;f+=2)if(i=a,o=s,a=e[f],s=e[f+1],l=h,h=this._regioncode(a,s),l===0&&h===0)u=d,d=0,r?r.push(a,s):r=[a,s];else{let m,b,w,_,M;if(l===0){if((m=this._clipSegment(i,o,a,s,l,h))===null)continue;[b,w,_,M]=m}else{if((m=this._clipSegment(a,s,i,o,h,l))===null)continue;[_,M,b,w]=m,u=d,d=this._edgecode(b,w),u&&d&&this._edge(t,u,d,r,r.length),r?r.push(b,w):r=[b,w]}u=d,d=this._edgecode(_,M),u&&d&&this._edge(t,u,d,r,r.length),r?r.push(_,M):r=[_,M]}if(r)u=d,d=this._edgecode(r[0],r[1]),u&&d&&this._edge(t,u,d,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 a=i<o;for(a&&([t,e,n,r,i,o]=[n,r,t,e,o,i]);;){if(i===0&&o===0)return a?[n,r,t,e]:[t,e,n,r];if(i&o)return null;let s,l,h=i||o;h&8?(s=t+(n-t)*(this.ymax-e)/(r-e),l=this.ymax):h&4?(s=t+(n-t)*(this.ymin-e)/(r-e),l=this.ymin):h&2?(l=e+(r-e)*(this.xmax-t)/(n-t),s=this.xmax):(l=e+(r-e)*(this.xmin-t)/(n-t),s=this.xmin),i?(t=s,e=l,i=this._regioncode(t,e)):(n=s,r=l,o=this._regioncode(n,r))}}_clipInfinite(t,e,n,r,i,o){let a=Array.from(e),s;if((s=this._project(a[0],a[1],n,r))&&a.unshift(s[0],s[1]),(s=this._project(a[a.length-2],a[a.length-1],i,o))&&a.push(s[0],s[1]),a=this._clipFinite(t,a))for(let l=0,h=a.length,u,d=this._edgecode(a[h-2],a[h-1]);l<h;l+=2)u=d,d=this._edgecode(a[l],a[l+1]),u&&d&&(l=this._edge(t,u,d,a,l),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,n,r,i){for(;e!==n;){let o,a;switch(e){case 5:e=4;continue;case 4:e=6,o=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,o=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,o=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,o=this.xmin,a=this.ymin;break}(r[i]!==o||r[i+1]!==a)&&this.contains(t,o,a)&&(r.splice(i,0,o,a),i+=2)}return i}_project(t,e,n,r){let i=1/0,o,a,s;if(r<0){if(e<=this.ymin)return null;(o=(this.ymin-e)/r)<i&&(s=this.ymin,a=t+(i=o)*n)}else if(r>0){if(e>=this.ymax)return null;(o=(this.ymax-e)/r)<i&&(s=this.ymax,a=t+(i=o)*n)}if(n>0){if(t>=this.xmax)return null;(o=(this.xmax-t)/n)<i&&(a=this.xmax,s=e+(i=o)*r)}else if(n<0){if(t<=this.xmin)return null;(o=(this.xmin-t)/n)<i&&(a=this.xmin,s=e+(i=o)*r)}return[a,s]}_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}},Ir=2*Math.PI,fe=Math.pow;function kr(t){return t[0]}function Lr(t){return t[1]}function Cr(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],a=2*e[r+2];if((n[a]-n[i])*(n[o+1]-n[i+1])-(n[o]-n[i])*(n[a+1]-n[i+1])>1e-10)return!1}return!0}function Rr(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}var Fr=class Vn{static from(e,n=kr,r=Lr,i){return new Vn("length"in e?Gr(e,n,r,i):Float64Array.from(qr(e,n,r,i)))}constructor(e){this._delaunator=new Ke(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&&Cr(e)){this.collinear=Int32Array.from({length:n.length/2},(f,m)=>m).sort((f,m)=>n[2*f]-n[2*m]||n[2*f+1]-n[2*m+1]);const l=this.collinear[0],h=this.collinear[this.collinear.length-1],u=[n[2*l],n[2*l+1],n[2*h],n[2*h+1]],d=1e-8*Math.hypot(u[3]-u[1],u[2]-u[0]);for(let f=0,m=n.length/2;f<m;++f){const b=Rr(n[2*f],n[2*f+1],d);n[2*f]=b[0],n[2*f+1]=b[1]}this._delaunator=new Ke(n)}else delete this.collinear;const r=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,o=this.triangles=this._delaunator.triangles,a=this.inedges.fill(-1),s=this._hullIndex.fill(-1);for(let l=0,h=r.length;l<h;++l){const u=o[l%3===2?l-2:l+1];(r[l]===-1||a[u]===-1)&&(a[u]=l)}for(let l=0,h=i.length;l<h;++l)s[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],a[i[0]]=1,i.length===2&&(a[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(e){return new Br(this,e)}*neighbors(e){const{inedges:n,hull:r,_hullIndex:i,halfedges:o,triangles:a,collinear:s}=this;if(s){const d=s.indexOf(e);d>0&&(yield s[d-1]),d<s.length-1&&(yield s[d+1]);return}const l=n[e];if(l===-1)return;let h=l,u=-1;do{if(yield u=a[h],h=h%3===2?h-2:h+1,a[h]!==e)return;if(h=o[h],h===-1){const d=r[(i[e]+1)%r.length];d!==u&&(yield d);return}}while(h!==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:a,halfedges:s,triangles:l,points:h}=this;if(i[e]===-1||!h.length)return(e+1)%(h.length>>1);let u=e,d=fe(n-h[e*2],2)+fe(r-h[e*2+1],2);const f=i[e];let m=f;do{let b=l[m];const w=fe(n-h[b*2],2)+fe(r-h[b*2+1],2);if(w<d&&(d=w,u=b),m=m%3===2?m-2:m+1,l[m]!==e)break;if(m=s[m],m===-1){if(m=o[(a[e]+1)%o.length],m!==b&&fe(n-h[m*2],2)+fe(r-h[m*2+1],2)<d)return m;break}}while(m!==f);return u}render(e){const n=e==null?e=new he:void 0,{points:r,halfedges:i,triangles:o}=this;for(let a=0,s=i.length;a<s;++a){const l=i[a];if(l<a)continue;const h=o[a]*2,u=o[l]*2;e.moveTo(r[h],r[h+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 he:void 0,{points:i}=this;for(let o=0,a=i.length;o<a;o+=2){const s=i[o],l=i[o+1];e.moveTo(s+n,l),e.arc(s,l,n,0,Ir)}return r&&r.value()}renderHull(e){const n=e==null?e=new he:void 0,{hull:r,points:i}=this,o=r[0]*2,a=r.length;e.moveTo(i[o],i[o+1]);for(let s=1;s<a;++s){const l=2*r[s];e.lineTo(i[l],i[l+1])}return e.closePath(),n&&n.value()}hullPolygon(){const e=new Le;return this.renderHull(e),e.value()}renderTriangle(e,n){const r=n==null?n=new he:void 0,{points:i,triangles:o}=this,a=o[e*=3]*2,s=o[e+1]*2,l=o[e+2]*2;return n.moveTo(i[a],i[a+1]),n.lineTo(i[s],i[s+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 Le;return this.renderTriangle(e,n),n.value()}};function Gr(t,e,n,r){const i=t.length,o=new Float64Array(i*2);for(let a=0;a<i;++a){const s=t[a];o[a*2]=e.call(r,s,a,t),o[a*2+1]=n.call(r,s,a,t)}return o}function*qr(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 Wr(t,e,n,r){return 1+(t[e][0]===0||t[n][0]===0||t[r][0]===0?1:0)}function Or(t,e,n,r,i,o){const a=Math.hypot(n-i,r-o),s=Math.hypot(t-i,e-o),l=Math.hypot(t-n,e-r),h=Math.abs((n-t)*(o-e)-(i-t)*(r-e))/2;return h===0?1/0:a*s*l/(4*h)}function Je(t){if(!t||t.length<3)return[];const e=new Set,n=[];for(const m of t){const b=`${m[0]}_${m[1]}`;e.has(b)||(e.add(b),n.push(m))}if(n.length<3)return[];const{triangles:r}=new Fr(Float64Array.from(n.flat()));if(!r.length)return[];const i=new Map,o=(m,b)=>m<b?`${m}_${b}`:`${b}_${m}`;for(let m=0;m<r.length;m+=3){const b=r[m],w=r[m+1],_=r[m+2],[M,g]=n[b],[v,y]=n[w],[x,p]=n[_];if(Or(M,g,v,y,x,p)<=1/Wr(n,b,w,_))for(const[P,V]of[[b,w],[w,_],[_,b]]){const z=o(P,V);i.set(z,(i.get(z)||0)+1)}}const a=[];for(const[m,b]of i)b===1&&a.push(m.split("_").map(Number));if(!a.length)return[];const s=new Map;for(const[m,b]of a)(s.get(m)||s.set(m,[]).get(m)).push(b),(s.get(b)||s.set(b,[]).get(b)).push(m);const l=a[0][0],h=[],u=new Set;let d=l,f=-1;do{h.push(n[d]),u.add(d);const m=s.get(d)||[];let b=m.find(w=>w!==f&&!u.has(w));if(b===void 0&&(b=m.find(w=>w!==f)),b===void 0)break;f=d,d=b}while(d!==l&&h.length<=a.length+1);return h}var ut={c:null,u:[new c.Vector3,new c.Vector3,new c.Vector3],e:[]},pt={c:null,u:[new c.Vector3,new c.Vector3,new c.Vector3],e:[]},Et=[[],[],[]],it=[[],[],[]],St=[],se=new c.Vector3,le=new c.Vector3,ce=new c.Vector3,Rt=new c.Vector3,tn=new c.Vector3,en=new c.Vector3,Zt=new c.Matrix3,nn=new c.Box3,Se=new c.Matrix4,rn=new c.Matrix4,on=new c.Ray,zn=class{constructor(t=new c.Vector3,e=new c.Vector3,n=new c.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;Rt.subVectors(t,this.center),this.rotation.extractBasis(se,le,ce),e.copy(this.center);const r=c.MathUtils.clamp(Rt.dot(se),-n.x,n.x);e.add(se.multiplyScalar(r));const i=c.MathUtils.clamp(Rt.dot(le),-n.y,n.y);e.add(le.multiplyScalar(i));const o=c.MathUtils.clamp(Rt.dot(ce),-n.z,n.z);return e.add(ce.multiplyScalar(o)),e}containsPoint(t){return Rt.subVectors(t,this.center),this.rotation.extractBasis(se,le,ce),Math.abs(Rt.dot(se))<=this.halfSize.x&&Math.abs(Rt.dot(le))<=this.halfSize.y&&Math.abs(Rt.dot(ce))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Nr.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,en),en.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){ut.c=this.center,ut.e[0]=this.halfSize.x,ut.e[1]=this.halfSize.y,ut.e[2]=this.halfSize.z,this.rotation.extractBasis(ut.u[0],ut.u[1],ut.u[2]),pt.c=t.center,pt.e[0]=t.halfSize.x,pt.e[1]=t.halfSize.y,pt.e[2]=t.halfSize.z,t.rotation.extractBasis(pt.u[0],pt.u[1],pt.u[2]);for(let i=0;i<3;i++)for(let o=0;o<3;o++)Et[i][o]=ut.u[i].dot(pt.u[o]);Rt.subVectors(pt.c,ut.c),St[0]=Rt.dot(ut.u[0]),St[1]=Rt.dot(ut.u[1]),St[2]=Rt.dot(ut.u[2]);for(let i=0;i<3;i++)for(let o=0;o<3;o++)it[i][o]=Math.abs(Et[i][o])+e;let n,r;for(let i=0;i<3;i++)if(n=ut.e[i],r=pt.e[0]*it[i][0]+pt.e[1]*it[i][1]+pt.e[2]*it[i][2],Math.abs(St[i])>n+r)return!1;for(let i=0;i<3;i++)if(n=ut.e[0]*it[0][i]+ut.e[1]*it[1][i]+ut.e[2]*it[2][i],r=pt.e[i],Math.abs(St[0]*Et[0][i]+St[1]*Et[1][i]+St[2]*Et[2][i])>n+r)return!1;return n=ut.e[1]*it[2][0]+ut.e[2]*it[1][0],r=pt.e[1]*it[0][2]+pt.e[2]*it[0][1],!(Math.abs(St[2]*Et[1][0]-St[1]*Et[2][0])>n+r||(n=ut.e[1]*it[2][1]+ut.e[2]*it[1][1],r=pt.e[0]*it[0][2]+pt.e[2]*it[0][0],Math.abs(St[2]*Et[1][1]-St[1]*Et[2][1])>n+r)||(n=ut.e[1]*it[2][2]+ut.e[2]*it[1][2],r=pt.e[0]*it[0][1]+pt.e[1]*it[0][0],Math.abs(St[2]*Et[1][2]-St[1]*Et[2][2])>n+r)||(n=ut.e[0]*it[2][0]+ut.e[2]*it[0][0],r=pt.e[1]*it[1][2]+pt.e[2]*it[1][1],Math.abs(St[0]*Et[2][0]-St[2]*Et[0][0])>n+r)||(n=ut.e[0]*it[2][1]+ut.e[2]*it[0][1],r=pt.e[0]*it[1][2]+pt.e[2]*it[1][0],Math.abs(St[0]*Et[2][1]-St[2]*Et[0][1])>n+r)||(n=ut.e[0]*it[2][2]+ut.e[2]*it[0][2],r=pt.e[0]*it[1][1]+pt.e[1]*it[1][0],Math.abs(St[0]*Et[2][2]-St[2]*Et[0][2])>n+r)||(n=ut.e[0]*it[1][0]+ut.e[1]*it[0][0],r=pt.e[1]*it[2][2]+pt.e[2]*it[2][1],Math.abs(St[1]*Et[0][0]-St[0]*Et[1][0])>n+r)||(n=ut.e[0]*it[1][1]+ut.e[1]*it[0][1],r=pt.e[0]*it[2][2]+pt.e[2]*it[2][0],Math.abs(St[1]*Et[0][1]-St[0]*Et[1][1])>n+r)||(n=ut.e[0]*it[1][2]+ut.e[1]*it[0][2],r=pt.e[0]*it[2][1]+pt.e[1]*it[2][0],Math.abs(St[1]*Et[0][2]-St[0]*Et[1][2])>n+r))}intersectsPlane(t){this.rotation.extractBasis(se,le,ce);const e=this.halfSize.x*Math.abs(t.normal.dot(se))+this.halfSize.y*Math.abs(t.normal.dot(le))+this.halfSize.z*Math.abs(t.normal.dot(ce)),n=t.normal.dot(this.center)-t.constant;return Math.abs(n)<=e}intersectRay(t,e){return this.getSize(tn),nn.setFromCenterAndSize(Rt.set(0,0,0),tn),Se.setFromMatrix3(this.rotation),Se.setPosition(this.center),rn.copy(Se).invert(),on.copy(t).applyMatrix4(rn),on.intersectBox(nn,e)?e.applyMatrix4(Se):null}intersectsRay(t){return this.intersectRay(t,Rt)!==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=Rt.set(e[0],e[1],e[2]).length();const r=Rt.set(e[4],e[5],e[6]).length(),i=Rt.set(e[8],e[9],e[10]).length();t.determinant()<0&&(n=-n),Zt.setFromMatrix4(t);const o=1/n,a=1/r,s=1/i;return Zt.elements[0]*=o,Zt.elements[1]*=o,Zt.elements[2]*=o,Zt.elements[3]*=a,Zt.elements[4]*=a,Zt.elements[5]*=a,Zt.elements[6]*=s,Zt.elements[7]*=s,Zt.elements[8]*=s,this.rotation.multiply(Zt),this.halfSize.x*=n,this.halfSize.y*=r,this.halfSize.z*=i,Rt.setFromMatrixPosition(t),this.center.add(Rt),this}},Nr=new zn,Wt=63710088e-1,Sn={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 _n(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 Dn(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 _n({type:"Point",coordinates:t},e,n)}function En(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 _n({type:"Polygon",coordinates:t},e,n)}function Hr(t,e="kilometers"){const n=Sn[e];if(!n)throw new Error(e+" units is invalid");return t*n}function $r(t,e="kilometers"){const n=Sn[e];if(!n)throw new Error(e+" units is invalid");return t/n}function An(t){return t%(2*Math.PI)*180/Math.PI}function ne(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 Hr($r(t,e),n)}function an(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function Xr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function be(t,e,n){if(t!==null)for(var r,i,o,a,s,l,h,u=0,d=0,f,m=t.type,b=m==="FeatureCollection",w=m==="Feature",_=b?t.features.length:1,M=0;M<_;M++){h=b?t.features[M].geometry:w?t.geometry:t,f=h?h.type==="GeometryCollection":!1,s=f?h.geometries.length:1;for(var g=0;g<s;g++){var v=0,y=0;if(a=f?h.geometries[g]:h,a!==null){l=a.coordinates;var x=a.type;switch(u=n&&(x==="Polygon"||x==="MultiPolygon")?1:0,x){case null:break;case"Point":if(e(l,d,M,v,y)===!1)return!1;d++,v++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(e(l[r],d,M,v,y)===!1)return!1;d++,x==="MultiPoint"&&v++}x==="LineString"&&v++;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],d,M,v,y)===!1)return!1;d++}x==="MultiLineString"&&v++,x==="Polygon"&&y++}x==="Polygon"&&v++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(y=0,i=0;i<l[r].length;i++){for(o=0;o<l[r][i].length-u;o++){if(e(l[r][i][o],d,M,v,y)===!1)return!1;d++}y++}v++}break;case"GeometryCollection":for(r=0;r<a.geometries.length;r++)if(be(a.geometries[r],e,n)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Yr(t){var e=[];return be(t,function(n){e.push(n)}),e}function jr(t,e){var n,r,i,o,a,s,l,h,u,d,f=0,m=t.type==="FeatureCollection",b=t.type==="Feature",w=m?t.features.length:1;for(n=0;n<w;n++){for(s=m?t.features[n].geometry:b?t.geometry:t,h=m?t.features[n].properties:b?t.properties:{},u=m?t.features[n].bbox:b?t.bbox:void 0,d=m?t.features[n].id:b?t.id:void 0,l=s?s.type==="GeometryCollection":!1,a=l?s.geometries.length:1,i=0;i<a;i++){if(o=l?s.geometries[i]:s,o===null){if(e(null,f,h,u,d)===!1)return!1;continue}switch(o.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(e(o,f,h,u,d)===!1)return!1;break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(e(o.geometries[r],f,h,u,d)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}f++}}function Ur(t,e,n){var r=n;return jr(t,function(i,o,a,s,l){o===0&&n===void 0?r=i:r=e(r,i,o,a,s,l)}),r}var Zr=we(((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,v,y,x,p){(function P(V,z,S,E,D){for(;E>S;){if(E-S>600){var T=E-S+1,B=z-S+1,L=Math.log(T),I=.5*Math.exp(2*L/3),C=.5*Math.sqrt(L*I*(T-I)/T)*(B-T/2<0?-1:1);P(V,z,Math.max(S,Math.floor(z-B*I/T+C)),Math.min(E,Math.floor(z+(T-B)*I/T+C)),D)}var F=V[z],k=S,A=E;for(r(V,S,z),D(V[E],F)>0&&r(V,S,E);k<A;){for(r(V,k,A),k++,A--;D(V[k],F)<0;)k++;for(;D(V[A],F)>0;)A--}D(V[S],F)===0?r(V,S,A):r(V,++A,E),A<=z&&(S=A+1),z<=A&&(E=A-1)}})(g,v,y||0,x||g.length-1,p||i)}function r(g,v,y){var x=g[v];g[v]=g[y],g[y]=x}function i(g,v){return g<v?-1:g>v?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 a(g,v,y){if(!y)return v.indexOf(g);for(var x=0;x<v.length;x++)if(y(g,v[x]))return x;return-1}function s(g,v){l(g,0,g.children.length,v,g)}function l(g,v,y,x,p){p||(p=_(null)),p.minX=1/0,p.minY=1/0,p.maxX=-1/0,p.maxY=-1/0;for(var P=v;P<y;P++){var V=g.children[P];h(p,g.leaf?x(V):V)}return p}function h(g,v){return g.minX=Math.min(g.minX,v.minX),g.minY=Math.min(g.minY,v.minY),g.maxX=Math.max(g.maxX,v.maxX),g.maxY=Math.max(g.maxY,v.maxY),g}function u(g,v){return g.minX-v.minX}function d(g,v){return g.minY-v.minY}function f(g){return(g.maxX-g.minX)*(g.maxY-g.minY)}function m(g){return g.maxX-g.minX+(g.maxY-g.minY)}function b(g,v){return g.minX<=v.minX&&g.minY<=v.minY&&v.maxX<=g.maxX&&v.maxY<=g.maxY}function w(g,v){return v.minX<=g.maxX&&v.minY<=g.maxY&&v.maxX>=g.minX&&v.maxY>=g.minY}function _(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(g,v,y,x,p){for(var P=[v,y];P.length;)if(!((y=P.pop())-(v=P.pop())<=x)){var V=v+Math.ceil((y-v)/x/2)*x;n(g,V,v,y,p),P.push(v,V,V,y)}}return o.prototype.all=function(){return this._all(this.data,[])},o.prototype.search=function(g){var v=this.data,y=[];if(!w(g,v))return y;for(var x=this.toBBox,p=[];v;){for(var P=0;P<v.children.length;P++){var V=v.children[P],z=v.leaf?x(V):V;w(g,z)&&(v.leaf?y.push(V):b(g,z)?this._all(V,y):p.push(V))}v=p.pop()}return y},o.prototype.collides=function(g){var v=this.data;if(!w(g,v))return!1;for(var y=[];v;){for(var x=0;x<v.children.length;x++){var p=v.children[x],P=v.leaf?this.toBBox(p):p;if(w(g,P)){if(v.leaf||b(g,P))return!0;y.push(p)}}v=y.pop()}return!1},o.prototype.load=function(g){if(!g||!g.length)return this;if(g.length<this._minEntries){for(var v=0;v<g.length;v++)this.insert(g[v]);return this}var y=this._build(g.slice(),0,g.length-1,0);if(this.data.children.length)if(this.data.height===y.height)this._splitRoot(this.data,y);else{if(this.data.height<y.height){var x=this.data;this.data=y,y=x}this._insert(y,this.data.height-y.height-1,!0)}else this.data=y;return this},o.prototype.insert=function(g){return g&&this._insert(g,this.data.height-1),this},o.prototype.clear=function(){return this.data=_([]),this},o.prototype.remove=function(g,v){if(!g)return this;for(var y,x,p,P=this.data,V=this.toBBox(g),z=[],S=[];P||z.length;){if(P||(P=z.pop(),x=z[z.length-1],y=S.pop(),p=!0),P.leaf){var E=a(g,P.children,v);if(E!==-1)return P.children.splice(E,1),z.push(P),this._condense(z),this}p||P.leaf||!b(P,V)?x?(y++,P=x.children[y],p=!1):P=null:(z.push(P),S.push(y),y=0,x=P,P=P.children[0])}return this},o.prototype.toBBox=function(g){return g},o.prototype.compareMinX=function(g,v){return g.minX-v.minX},o.prototype.compareMinY=function(g,v){return g.minY-v.minY},o.prototype.toJSON=function(){return this.data},o.prototype.fromJSON=function(g){return this.data=g,this},o.prototype._all=function(g,v){for(var y=[];g;)g.leaf?v.push.apply(v,g.children):y.push.apply(y,g.children),g=y.pop();return v},o.prototype._build=function(g,v,y,x){var p,P=y-v+1,V=this._maxEntries;if(P<=V)return s(p=_(g.slice(v,y+1)),this.toBBox),p;x||(x=Math.ceil(Math.log(P)/Math.log(V)),V=Math.ceil(P/Math.pow(V,x-1))),(p=_([])).leaf=!1,p.height=x;var z=Math.ceil(P/V),S=z*Math.ceil(Math.sqrt(V));M(g,v,y,S,this.compareMinX);for(var E=v;E<=y;E+=S){var D=Math.min(E+S-1,y);M(g,E,D,z,this.compareMinY);for(var T=E;T<=D;T+=z){var B=Math.min(T+z-1,D);p.children.push(this._build(g,T,B,x-1))}}return s(p,this.toBBox),p},o.prototype._chooseSubtree=function(g,v,y,x){for(;x.push(v),!v.leaf&&x.length-1!==y;){for(var p=1/0,P=1/0,V=void 0,z=0;z<v.children.length;z++){var S=v.children[z],E=f(S),D=(T=g,B=S,(Math.max(B.maxX,T.maxX)-Math.min(B.minX,T.minX))*(Math.max(B.maxY,T.maxY)-Math.min(B.minY,T.minY))-E);D<P?(P=D,p=E<p?E:p,V=S):D===P&&E<p&&(p=E,V=S)}v=V||v.children[0]}var T,B;return v},o.prototype._insert=function(g,v,y){var x=y?g:this.toBBox(g),p=[],P=this._chooseSubtree(x,this.data,v,p);for(P.children.push(g),h(P,x);v>=0&&p[v].children.length>this._maxEntries;)this._split(p,v),v--;this._adjustParentBBoxes(x,p,v)},o.prototype._split=function(g,v){var y=g[v],x=y.children.length,p=this._minEntries;this._chooseSplitAxis(y,p,x);var P=this._chooseSplitIndex(y,p,x),V=_(y.children.splice(P,y.children.length-P));V.height=y.height,V.leaf=y.leaf,s(y,this.toBBox),s(V,this.toBBox),v?g[v-1].children.push(V):this._splitRoot(y,V)},o.prototype._splitRoot=function(g,v){this.data=_([g,v]),this.data.height=g.height+1,this.data.leaf=!1,s(this.data,this.toBBox)},o.prototype._chooseSplitIndex=function(g,v,y){for(var x,p,P,V,z,S,E,D=1/0,T=1/0,B=v;B<=y-v;B++){var L=l(g,0,B,this.toBBox),I=l(g,B,y,this.toBBox),C=(p=L,P=I,V=void 0,z=void 0,S=void 0,E=void 0,V=Math.max(p.minX,P.minX),z=Math.max(p.minY,P.minY),S=Math.min(p.maxX,P.maxX),E=Math.min(p.maxY,P.maxY),Math.max(0,S-V)*Math.max(0,E-z)),F=f(L)+f(I);C<D?(D=C,x=B,T=F<T?F:T):C===D&&F<T&&(T=F,x=B)}return x||y-v},o.prototype._chooseSplitAxis=function(g,v,y){var x=g.leaf?this.compareMinX:u,p=g.leaf?this.compareMinY:d;this._allDistMargin(g,v,y,x)<this._allDistMargin(g,v,y,p)&&g.children.sort(x)},o.prototype._allDistMargin=function(g,v,y,x){g.children.sort(x);for(var p=this.toBBox,P=l(g,0,v,p),V=l(g,y-v,y,p),z=m(P)+m(V),S=v;S<y-v;S++){var E=g.children[S];h(P,g.leaf?p(E):E),z+=m(P)}for(var D=y-v-1;D>=v;D--){var T=g.children[D];h(V,g.leaf?p(T):T),z+=m(V)}return z},o.prototype._adjustParentBBoxes=function(g,v,y){for(var x=y;x>=0;x--)h(v[x],g)},o.prototype._condense=function(g){for(var v=g.length-1,y=void 0;v>=0;v--)g[v].children.length===0?v>0?(y=g[v-1].children).splice(y.indexOf(g[v]),1):this.clear():s(g[v],this.toBBox)},o})})),Kr=Xn({default:()=>Bn});function Qr(t,e){return t<e?-1:t>e?1:0}var Bn,Jr=$n((()=>{Bn=class{constructor(t=[],e=Qr){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,a=e[o];const s=o+1;if(s<this.length&&n(e[s],a)<0&&(o=s,a=e[s]),n(a,i)>=0)break;e[t]=a,t=o}e[t]=i}}})),to=we(((t,e)=>{e.exports=function(r,i,o,a){var s=r[0],l=r[1],h=!1;o===void 0&&(o=0),a===void 0&&(a=i.length);for(var u=(a-o)/2,d=0,f=u-1;d<u;f=d++){var m=i[o+d*2+0],b=i[o+d*2+1],w=i[o+f*2+0],_=i[o+f*2+1];b>l!=_>l&&s<(w-m)*(l-b)/(_-b)+m&&(h=!h)}return h}})),eo=we(((t,e)=>{e.exports=function(r,i,o,a){var s=r[0],l=r[1],h=!1;o===void 0&&(o=0),a===void 0&&(a=i.length);for(var u=a-o,d=0,f=u-1;d<u;f=d++){var m=i[d+o][0],b=i[d+o][1],w=i[f+o][0],_=i[f+o][1];b>l!=_>l&&s<(w-m)*(l-b)/(_-b)+m&&(h=!h)}return h}})),no=we(((t,e)=>{var n=to(),r=eo();e.exports=function(o,a,s,l){return a.length>0&&Array.isArray(a[0])?r(o,a,s,l):n(o,a,s,l)},e.exports.nested=r,e.exports.flat=n})),ro=we(((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(w,_,M,g,v){let y,x,p,P,V=_[0],z=g[0],S=0,E=0;z>V==z>-V?(y=V,V=_[++S]):(y=z,z=g[++E]);let D=0;if(S<w&&E<M)for(z>V==z>-V?(p=y-((x=V+y)-V),V=_[++S]):(p=y-((x=z+y)-z),z=g[++E]),y=x,p!==0&&(v[D++]=p);S<w&&E<M;)z>V==z>-V?(p=y-((x=y+V)-(P=x-y))+(V-P),V=_[++S]):(p=y-((x=y+z)-(P=x-y))+(z-P),z=g[++E]),y=x,p!==0&&(v[D++]=p);for(;S<w;)p=y-((x=y+V)-(P=x-y))+(V-P),V=_[++S],y=x,p!==0&&(v[D++]=p);for(;E<M;)p=y-((x=y+z)-(P=x-y))+(z-P),z=g[++E],y=x,p!==0&&(v[D++]=p);return y===0&&D!==0||(v[D++]=y),D}function a(w){return new Float64Array(w)}const s=33306690738754716e-32,l=22204460492503146e-32,h=11093356479670487e-47,u=a(4),d=a(8),f=a(12),m=a(16),b=a(4);n.orient2d=function(w,_,M,g,v,y){const x=(_-y)*(M-v),p=(w-v)*(g-y),P=x-p;if(x===0||p===0||x>0!=p>0)return P;const V=Math.abs(x+p);return Math.abs(P)>=s*V?P:-(function(z,S,E,D,T,B,L){let I,C,F,k,A,G,q,H,N,U,$,Q,et,O,j,dt,Nt,It;const kt=z-T,Pt=E-T,Mt=S-B,Tt=D-B;A=(j=(H=kt-(q=(G=134217729*kt)-(G-kt)))*(U=Tt-(N=(G=134217729*Tt)-(G-Tt)))-((O=kt*Tt)-q*N-H*N-q*U))-($=j-(Nt=(H=Mt-(q=(G=134217729*Mt)-(G-Mt)))*(U=Pt-(N=(G=134217729*Pt)-(G-Pt)))-((dt=Mt*Pt)-q*N-H*N-q*U))),u[0]=j-($+A)+(A-Nt),A=(et=O-((Q=O+$)-(A=Q-O))+($-A))-($=et-dt),u[1]=et-($+A)+(A-dt),A=(It=Q+$)-Q,u[2]=Q-(It-A)+($-A),u[3]=It;let nt=(function(qt,Ht){let Ft=Ht[0];for(let tt=1;tt<qt;tt++)Ft+=Ht[tt];return Ft})(4,u),at=l*L;if(nt>=at||-nt>=at||(I=z-(kt+(A=z-kt))+(A-T),F=E-(Pt+(A=E-Pt))+(A-T),C=S-(Mt+(A=S-Mt))+(A-B),k=D-(Tt+(A=D-Tt))+(A-B),I===0&&C===0&&F===0&&k===0)||(at=h*L+i*Math.abs(nt),(nt+=kt*k+Tt*I-(Mt*F+Pt*C))>=at||-nt>=at))return nt;A=(j=(H=I-(q=(G=134217729*I)-(G-I)))*(U=Tt-(N=(G=134217729*Tt)-(G-Tt)))-((O=I*Tt)-q*N-H*N-q*U))-($=j-(Nt=(H=C-(q=(G=134217729*C)-(G-C)))*(U=Pt-(N=(G=134217729*Pt)-(G-Pt)))-((dt=C*Pt)-q*N-H*N-q*U))),b[0]=j-($+A)+(A-Nt),A=(et=O-((Q=O+$)-(A=Q-O))+($-A))-($=et-dt),b[1]=et-($+A)+(A-dt),A=(It=Q+$)-Q,b[2]=Q-(It-A)+($-A),b[3]=It;const Z=o(4,u,4,b,d);A=(j=(H=kt-(q=(G=134217729*kt)-(G-kt)))*(U=k-(N=(G=134217729*k)-(G-k)))-((O=kt*k)-q*N-H*N-q*U))-($=j-(Nt=(H=Mt-(q=(G=134217729*Mt)-(G-Mt)))*(U=F-(N=(G=134217729*F)-(G-F)))-((dt=Mt*F)-q*N-H*N-q*U))),b[0]=j-($+A)+(A-Nt),A=(et=O-((Q=O+$)-(A=Q-O))+($-A))-($=et-dt),b[1]=et-($+A)+(A-dt),A=(It=Q+$)-Q,b[2]=Q-(It-A)+($-A),b[3]=It;const K=o(Z,d,4,b,f);return A=(j=(H=I-(q=(G=134217729*I)-(G-I)))*(U=k-(N=(G=134217729*k)-(G-k)))-((O=I*k)-q*N-H*N-q*U))-($=j-(Nt=(H=C-(q=(G=134217729*C)-(G-C)))*(U=F-(N=(G=134217729*F)-(G-F)))-((dt=C*F)-q*N-H*N-q*U))),b[0]=j-($+A)+(A-Nt),A=(et=O-((Q=O+$)-(A=Q-O))+($-A))-($=et-dt),b[1]=et-($+A)+(A-dt),A=(It=Q+$)-Q,b[2]=Q-(It-A)+($-A),b[3]=It,m[o(K,f,4,b,m)-1]})(w,_,M,g,v,y,V)},n.orient2dfast=function(w,_,M,g,v,y){return(_-y)*(M-v)-(w-v)*(g-y)},Object.defineProperty(n,"__esModule",{value:!0})})})),oo=we(((t,e)=>{var n=Zr(),r=(Jr(),Yn(Kr)),i=no(),o=ro().orient2d;r.default&&(r=r.default),e.exports=a,e.exports.default=a;function a(p,P,V){P=Math.max(0,P===void 0?2:P),V=V||0;var z=w(p),S=new n(16);S.toBBox=function(N){return{minX:N[0],minY:N[1],maxX:N[0],maxY:N[1]}},S.compareMinX=function(N,U){return N[0]-U[0]},S.compareMinY=function(N,U){return N[1]-U[1]},S.load(p);for(var E=[],D=0,T;D<z.length;D++){var B=z[D];S.remove(B),T=_(B,T),E.push(T)}var L=new n(16);for(D=0;D<E.length;D++)L.insert(b(E[D]));for(var I=P*P,C=V*V;E.length;){var F=E.shift(),k=F.p,A=F.next.p,G=M(k,A);if(!(G<C)){var q=G/I;B=s(S,F.prev.p,k,A,F.next.next.p,q,L),B&&Math.min(M(B,k),M(B,A))<=q&&(E.push(F),E.push(_(B,F)),S.remove(B),L.remove(F),L.insert(b(F)),L.insert(b(F.next)))}}F=T;var H=[];do H.push(F.p),F=F.next;while(F!==T);return H.push(F.p),H}function s(p,P,V,z,S,E,D){for(var T=new r([],l),B=p.data;B;){for(var L=0;L<B.children.length;L++){var I=B.children[L],C=B.leaf?g(I,V,z):h(V,z,I);C>E||T.push({node:I,dist:C})}for(;T.length&&!T.peek().node.children;){var F=T.pop(),k=F.node,A=g(k,P,V),G=g(k,z,S);if(F.dist<A&&F.dist<G&&d(V,k,D)&&d(z,k,D))return k}B=T.pop(),B&&(B=B.node)}return null}function l(p,P){return p.dist-P.dist}function h(p,P,V){if(u(p,V)||u(P,V))return 0;var z=v(p[0],p[1],P[0],P[1],V.minX,V.minY,V.maxX,V.minY);if(z===0)return 0;var S=v(p[0],p[1],P[0],P[1],V.minX,V.minY,V.minX,V.maxY);if(S===0)return 0;var E=v(p[0],p[1],P[0],P[1],V.maxX,V.minY,V.maxX,V.maxY);if(E===0)return 0;var D=v(p[0],p[1],P[0],P[1],V.minX,V.maxY,V.maxX,V.maxY);return D===0?0:Math.min(z,S,E,D)}function u(p,P){return p[0]>=P.minX&&p[0]<=P.maxX&&p[1]>=P.minY&&p[1]<=P.maxY}function d(p,P,V){for(var z=Math.min(p[0],P[0]),S=Math.min(p[1],P[1]),E=Math.max(p[0],P[0]),D=Math.max(p[1],P[1]),T=V.search({minX:z,minY:S,maxX:E,maxY:D}),B=0;B<T.length;B++)if(m(T[B].p,T[B].next.p,p,P))return!1;return!0}function f(p,P,V){return o(p[0],p[1],P[0],P[1],V[0],V[1])}function m(p,P,V,z){return p!==z&&P!==V&&f(p,P,V)>0!=f(p,P,z)>0&&f(V,z,p)>0!=f(V,z,P)>0}function b(p){var P=p.p,V=p.next.p;return p.minX=Math.min(P[0],V[0]),p.minY=Math.min(P[1],V[1]),p.maxX=Math.max(P[0],V[0]),p.maxY=Math.max(P[1],V[1]),p}function w(p){for(var P=p[0],V=p[0],z=p[0],S=p[0],E=0;E<p.length;E++){var D=p[E];D[0]<P[0]&&(P=D),D[0]>z[0]&&(z=D),D[1]<V[1]&&(V=D),D[1]>S[1]&&(S=D)}var T=[P,V,z,S],B=T.slice();for(E=0;E<p.length;E++)i(p[E],T)||B.push(p[E]);return x(B)}function _(p,P){var V={p,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return P?(V.next=P.next,V.prev=P,P.next.prev=V,P.next=V):(V.prev=V,V.next=V),V}function M(p,P){var V=p[0]-P[0],z=p[1]-P[1];return V*V+z*z}function g(p,P,V){var z=P[0],S=P[1],E=V[0]-z,D=V[1]-S;if(E!==0||D!==0){var T=((p[0]-z)*E+(p[1]-S)*D)/(E*E+D*D);T>1?(z=V[0],S=V[1]):T>0&&(z+=E*T,S+=D*T)}return E=p[0]-z,D=p[1]-S,E*E+D*D}function v(p,P,V,z,S,E,D,T){var B=V-p,L=z-P,I=D-S,C=T-E,F=p-S,k=P-E,A=B*B+L*L,G=B*I+L*C,q=I*I+C*C,H=B*F+L*k,N=I*F+C*k,U=A*q-G*G,$,Q,et,O,j=U,dt=U;U===0?(Q=0,j=1,O=N,dt=q):(Q=G*N-q*H,O=A*N-G*H,Q<0?(Q=0,O=N,dt=q):Q>j&&(Q=j,O=N+G,dt=q)),O<0?(O=0,-H<0?Q=0:-H>A?Q=j:(Q=-H,j=A)):O>dt&&(O=dt,-H+G<0?Q=0:-H+G>A?Q=j:(Q=-H+G,j=A)),$=Q===0?0:Q/j,et=O===0?0:O/dt;var Nt=(1-$)*p+$*V,It=(1-$)*P+$*z,kt=(1-et)*S+et*D,Pt=(1-et)*E+et*T,Mt=kt-Nt,Tt=Pt-It;return Mt*Mt+Tt*Tt}function y(p,P){return p[0]===P[0]?p[1]-P[1]:p[0]-P[0]}function x(p){p.sort(y);for(var P=[],V=0;V<p.length;V++){for(;P.length>=2&&f(P[P.length-2],P[P.length-1],p[V])<=0;)P.pop();P.push(p[V])}for(var z=[],S=p.length-1;S>=0;S--){for(;z.length>=2&&f(z[z.length-2],z[z.length-1],p[S])<=0;)z.pop();z.push(p[S])}return z.pop(),P.pop(),P.concat(z)}})),io=xn(oo(),1);function ao(t,e={}){e.concavity=e.concavity||1/0;const n=[];if(be(t,i=>{n.push([i[0],i[1]])}),!n.length)return null;const r=(0,io.default)(n,e.concavity);return r.length>3?En([r]):null}function In(t,e={}){let n=0,r=0,i=0;return be(t,function(o){n+=o[0],r+=o[1],i++},!0),Dn([n/i,r/i],e.properties)}function re(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 so(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 lo(t,e,n={}){let r;return n.final?r=sn(re(e),re(t)):r=sn(re(t),re(e)),r>180?-(360-r):r}function sn(t,e){const n=ne(t[1]),r=ne(e[1]);let i=ne(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(An(Math.atan2(i,o))+360)%360}function co(t,e,n={}){const r=re(t),i=re(e);return i[0]+=i[0]-r[0]>180?-360:r[0]-i[0]>180?360:0,Tn(uo(r,i),"meters",n.units)}function uo(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,a=o-i;let s=Math.abs(e[0]-t[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);const l=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),h=Math.abs(l)>1e-11?a/l:Math.cos(i);return Math.sqrt(a*a+h*h*s*s)*r}function ho(t,e,n,r={}){const i=e<0;let o=Tn(Math.abs(e),r.units,"meters");i&&(o=-Math.abs(o));const a=re(t),s=fo(a,o,n);return s[0]+=s[0]-a[0]>180?-360:a[0]-s[0]>180?360:0,Dn(s,r.properties)}function fo(t,e,n,r){r=r===void 0?Wt:Number(r);const i=e/r,o=t[0]*Math.PI/180,a=ne(t[1]),s=ne(n),l=i*Math.cos(s);let h=a+l;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);const u=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(a/2+Math.PI/4)),d=Math.abs(u)>1e-11?l/u:Math.cos(a);return[((o+i*Math.sin(s)/d)*180/Math.PI+540)%360-180,h*180/Math.PI]}function mo(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return kn(t);case"FeatureCollection":return go(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Re(t);default:throw new Error("unknown GeoJSON type")}}function kn(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=Ln(t.properties),t.geometry==null?e.geometry=null:e.geometry=Re(t.geometry),e}function Ln(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]=Ln(r):e[n]=r}),e}function go(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=>kn(n)),e}function Re(t){const e={type:t.type};return t.bbox&&(e.bbox=t.bbox),t.type==="GeometryCollection"?(e.geometries=t.geometries.map(n=>Re(n)),e):(e.coordinates=Cn(t.coordinates),e)}function Cn(t){const e=t;return typeof e[0]!="object"?e.slice():e.map(n=>Cn(n))}function ln(t,e,n){if(n=n||{},!Xr(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??In(t);return(i===!1||i===void 0)&&(t=mo(t)),be(t,function(a){const s=lo(o,a)+e,l=so(ho(o,co(o,a),s));a[0]=l[0],a[1]=l[1]}),t}function Rn(t,e,n={}){if(n.final===!0)return po(t,e);const r=re(t),i=re(e),o=ne(r[0]),a=ne(i[0]),s=ne(r[1]),l=ne(i[1]),h=Math.sin(a-o)*Math.cos(l),u=Math.cos(s)*Math.sin(l)-Math.sin(s)*Math.cos(l)*Math.cos(a-o);return An(Math.atan2(h,u))}function po(t,e){let n=Rn(e,t);return n=(n+180)%360,n}function yo(t,e={}){if(t.bbox!=null&&e.recompute!==!0)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return be(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 xo(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 a=[n,r];return En([[a,[i,r],[i,o],[n,o],a]],e.properties,{bbox:t,id:e.id})}function wo(t){return xo(yo(t))}function bo(t){return Ur(t,(e,n)=>e+vo(n),0)}function vo(t){let e=0,n;switch(t.type){case"Polygon":return cn(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=cn(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function cn(t){let e=0;if(t&&t.length>0){e+=Math.abs(un(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(un(t[n]))}return e}var Mo=Wt*Wt/2,Ie=Math.PI/180;function un(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],a=t[r+2>=e?(r+2)%e:r+2],s=i[0]*Ie,l=o[1]*Ie,h=a[0]*Ie;n+=(h-s)*Math.sin(l),r++}return n*Mo}function Po(t){const e=ao(t);if(!e)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const n=In(e),r=Yr(e);let i=Number.MAX_SAFE_INTEGER,o=null;for(let a=0;a<r.length-1;a++){let s=Rn(r[a],r[a+1]),l=wo(ln(e,-1*s,{pivot:n})),h=bo(l);h<i&&(i=h,o=ln(l,s,{pivot:n}))}return o}function hn(t,e){const n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)}function Vo(t){let e=1/0,n=-1/0,r=1/0,i=-1/0;for(const[o,a]of t)o<e&&(e=o),o>n&&(n=o),a<r&&(r=a),a>i&&(i=a);return[(n+e)*.5,(i+r)*.5]}var zo=class Ce extends zn{getBoxMesh(){ie.identity(),ie.setFromMatrix3(this.rotation),ie.decompose(_e,ue,new c.Vector3);const e=this.halfSize.clone().multiplyScalar(2),n=new c.Mesh(new c.BoxGeometry(e.x,e.y,e.z));return n.position.copy(this.center),n.rotation.setFromQuaternion(ue),n}getBoxEdge(e=16776960){const n=this.getBoxMesh();_o.setFromObject(n);const r=new c.EdgesGeometry(n.geometry.clone().applyMatrix4(n.matrixWorld));return new c.LineSegments(r,new c.LineBasicMaterial({color:e,toneMapped:!1}))}toJson(){return ie.identity(),ie.setFromMatrix3(this.rotation),ie.decompose(_e,ue,new c.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:ue.toArray()}}static from(e,n,r,i=new Ce){if(r instanceof c.Euler)ue.setFromEuler(r);else if(r instanceof c.Quaternion)ue.copy(r);else throw new Error("传入的旋转不是欧拉角或者四元数");return ie.compose(n,ue,So),i.center.copy(n),i.halfSize.copy(e.multiplyScalar(.5)),i.rotation.setFromMatrix4(ie),i}static fromByPath2D(e,n,r,i=new Ce){const o=Po({type:"Polygon",coordinates:[e.map(f=>[f.x,f.y])]});if(!o)throw new Error("2d obb 获取失败");const a=o.geometry.coordinates[0],s=hn(a[0],a[1]),l=hn(a[1],a[2]),h=Math.atan2(a[1][1]-a[0][1],a[1][0]-a[0][0]);_e.set(s,l,r),dn.set(0,0,h);const[u,d]=Vo(a);return n.x=u,n.y=d,this.from(_e,n,dn,i)}},ie=new c.Matrix4,ue=new c.Quaternion,dn=new c.Euler,So=new c.Vector3(1,1,1),_e=new c.Vector3,_o=new c.Box3;function Do(t,e,n=.005,r=.2){if(!t.length||!e.length)return 0;const i=Math.max(n,.03),o=n*n,a=new Map,s=(d,f,m)=>`${Math.floor(d/i)},${Math.floor(f/i)},${Math.floor(m/i)}`;for(const d of e){const f=s(d.x,d.y,d.z);a.has(f)||a.set(f,[]),a.get(f).push(d)}let l=0;const h=Math.ceil(n/i)+1,u=[];for(let d=-h;d<=h;d++)for(let f=-h;f<=h;f++)for(let m=-h;m<=h;m++)d*d+f*f+m*m<=h*h&&u.push([d,f,m]);for(const d of t){const f=Math.floor(d.x/i),m=Math.floor(d.y/i),b=Math.floor(d.z/i);let w=!1;for(const[_,M,g]of u){const v=`${f+_},${m+M},${b+g}`;if(a.has(v)){for(const y of a.get(v))if(d.distanceToSquared(y)<o){w=!0;break}if(w)break}}if(w&&(l++,l/t.length>r))return l/t.length}return l/t.length}function me(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 ke(t,e,n,r){if(t.intersectsOBB(e))return!0;{const i=pe(t,r),o=pe(e,n);if(i||o)return!0}return!1}function fn(t,e){const n=new c.Vector3,r=new c.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 pe(t,e){let n=!0;for(let r=0;r<e.length;r++)if(!t.containsPoint(e[r])){n=!1;break}return n}function mn(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 gn(t,e,n,r){const i=[];for(let a=0;a<t.length;a++)i.push(new c.Vector3(t[a][0],t[a][1],0));if(i.length==0)return null;const o=zo.fromByPath2D(i,e,n);return o.center.z=r,o}var Eo=t=>{if(t.length==0)return[];const e=[],n=new Map;for(let i=0;i<t.length;i++){let o=t[i].points.map(w=>[w.x,w.y]),a=t[i].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 s=a.indexOf("_")+1,l=a.lastIndexOf("_"),h=a.substring(s,l);if(h==="wall")continue;let u=[];for(let w=0;w<t[i].points.length;w++)u.push(new c.Vector3(t[i].points[w].x,t[i].points[w].y,t[i].points[w].z));let d=-99999;if(h==="floor"){let w=new Map;for(let M=0;M<t[i].points.length;M++){let g=t[i].points[M].z;if(g=Math.floor(g*10)/10,w.has(g)){const v=w.get(g);v.num+=1,v.points.push(t[i].points[M]),w.set(g,v)}else w.set(g,{num:1,points:[t[i].points[M]]})}let _=[...w.entries()].reduce((M,g)=>g[1].num>M[1].num?g:M);o=[],o=_[1].points.map(M=>[M.x,M.y]),u=[],u=_[1].points.map(M=>new c.Vector3(M.x,M.y,M.z)),d=_[0]}const f=mn(u),m={points:u,path:Je(o),h:f.h,minz:f.minz,maxz:f.maxz,center:{x:f.x,y:f.y,z:f.z},obj_id:t[i].obj_id,type:h,averagePz:t[i].averagePz,obb:null,isDel:!1,obj_id:a,positionArr:[t[i].position]};if(m.obb=gn(m.path,m.center,m.h,(m.maxz+m.minz)/2),m.obb==null)continue;let b=-1;for(let w=0;w<e.length;w++)if(e[w].type==h){b=w;break}if(b!=-1?e[b].array.push(m):e.push({type:h,array:[m]}),h=="floor"&&d!=-99999)if(n.has(d)){const w=n.get(d);w.num+=m.points.length,w.datas.push(m),n.set(d,w)}else n.set(d,{num:m.points.length,datas:[m]})}if(n.size>0){let i=[];for(const[o,a]of n.entries()){const{num:s,datas:l}=a;s>3e3&&i.push(...l)}for(let o=0;o<e.length;o++)if(e[o].type=="floor"){e[o].array=i;break}}for(let i=0;i<e.length;i++){const o=e[i].array,a=[],s=[];for(let h=0;h<o.length;h++){if(o[h].obb==null||a.includes(h))continue;const u={...o[h],obb:o[h].obb.clone()};for(let d=h+1;d<o.length;d++)if(!(o[d].obb==null||a.includes(d))&&u.obb.intersectsOBB(o[d].obb)){a.push(d),u.points.push(...o[d].points),u.path=Je(u.points.map(m=>[m.x,m.y]));const f=mn(u.points);u.h=f.h,u.minz=f.minz,u.maxz=f.maxz,u.center={x:f.x,y:f.y,z:f.z},u.obb=gn(u.path,u.center,u.h,(u.maxz+u.minz)/2),u.positionArr.push(...o[d].positionArr),d=h}u.path.length>o[h].path.length&&(a.push(h),s.push(u))}const l=[];for(let h=0;h<o.length;h++)a.includes(h)||l.push(o[h]);l.push(...s),e[i].array=l}for(let i=0;i<e.length;i++){const o=e[i].type;if(o==="people"||o==="floor")continue;const a=e[i].array;for(let s=0;s<a.length;s++){const l=a[s].obb,h=a[s].minz;a[s].maxz;const u=a[s].averagePz;if(o==="window"||o==="door"||o==="tv"||o==="chair"||o==="cabinet"||o==="table"){const d=new c.Vector3;l.getSize(d);const f=[d.x,d.y,d.z];let m=0;for(const b of f)if(b<.2&&(m++,m===2)){a[s].isDel=!0;break}}if(!a[s].isDel)for(let d=i+1;d<e.length;d++){const f=e[d].type;if(f==="people"||f==="floor")continue;const m=e[d].array;for(let b=0;b<m.length;b++){if(m[b].isDel)continue;const w=m[b].obb,_=m[b].minz;if(m[b].maxz,l.intersectsOBB(w)){me(m[b].points,l);const M=me(a[s].points,w),g=fn(l,w);if(M>=.3&&g==-1){a[s].isDel=!0;break}if(o!=="wall"&&o!=="floor"&&o!=="roof"){if(o==="window"){if(f==="balcony railing"&&pe(l,m[b].points)){m[b].isDel=!0;continue}if(f==="balcony railing"&&pe(w,a[s].points)){a[s].isDel=!0;break}if(f==="balcony railing"&&ke(l,w,a[s].points,m[b].points)&&(Math.abs(h-_)<.1||Math.abs(_-u)>.3)){m[b].isDel=!0;continue}}else if(o==="balcony railing"){if(f==="window"&&pe(l,m[b].points)){m[b].isDel=!0;continue}if(f==="window"&&pe(w,a[s].points)){a[s].isDel=!0;break}if(f==="window"&&ke(l,w,a[s].points,m[b].points)&&(Math.abs(h-_)<.1||Math.abs(h-u)>.3)){a[s].isDel=!0;break}}let v=!1,y=[],x=[];const p=a[s].points,P=m[b].points;if(p.length>P.length?(v=!0,y=p,x=P):(y=P,x=p),Do(x,y,.03,.5)>.5)if(v)m[b].isDel=!0;else{a[s].isDel=!0;break}else if(ke(l,w)){const V=fn(l,w);if(V===1||V===0){if(f==="switch")continue;p.length>P.length?me(x,l)>=.5&&(m[b].isDel=!0):me(y,l)>=.5&&(m[b].isDel=!0)}else{if(o==="switch")continue;if(p.length>P.length){if(me(y,w)>=.5){a[s].isDel=!0;break}}else if(me(x,w)>=.5){a[s].isDel=!0;break}}}}}}if(a[s].isDel)break}}}for(let i=0;i<e.length;i++){const o=e[i].type,a=e[i].array;for(let s=0;s<a.length;s++){let l=a[s].maxz,h=a[s].minz,u=o==="switch"?.1:.3;const d=a[s].averagePz;if(Math.abs(l-d)<u){a[s].isDel=!0;continue}if(o==="window"||o==="door"||o==="tv"){const f=Math.abs(l-d),m=Math.abs(h-d);(o==="tv"&&m<1.6||o!=="window"&&f<1.6)&&(a[s].isDel=!0),o==="window"&&f<1&&(a[s].isDel=!0)}if(o==="chair"){const f=new c.Vector3;a[s].obb.getSize(f),(f.x<.1||f.y<.1||f.z<.2)&&(a[s].isDel=!0)}o==="balcony railing"&&(Math.abs(l-h)<.4&&(a[s].isDel=!0),(h<d&&Math.abs(h-d)>1||h>d&&Math.abs(h-d)>1)&&(a[s].isDel=!0),l<d&&(a[s].isDel=!0)),o==="people"&&(Math.abs(l-h)<1&&(a[s].isDel=!0),h>d&&h-d>.3&&(a[s].isDel=!0),l<d&&(a[s].isDel=!0)),o==="floor"&&a[s].points.length<500&&(a[s].isDel=!0)}}for(let i=0;i<e.length;i++)e[i].array=e[i].array.filter(o=>!o.isDel);const r=[];for(let i=0;i<e.length;i++){const o=e[i].array;for(let a=0;a<o.length;a++)r.push({obbBox:o[a].obb,box:new c.Box3().setFromPoints(o[a].points),category:o[a].type,center:{x:o[a].center.x,y:o[a].center.y,z:(o[a].minz+o[a].maxz)/2},name:o[a].obj_id,obj_id:o[a].obj_id,pcdPoints:o[a].points,positionArr:o[a].positionArr})}return r};function ye(t,e){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function Ao(t){let e=0,n=0,r=0;for(let i=0;i<4;i++){const o=t[i],a=t[(i+1)%4],s=a.x-o.x,l=a.y-o.y,h=Math.sqrt(s*s+l*l);h>e&&(e=h,n=s/h,r=l/h)}return{longSide:e,dirX:n,dirY:r}}function Fe(t,e,n){const i=[];for(const o of t){const a=(o.start.x+o.end.x)/2,s=(o.start.y+o.end.y)/2,l=a-e,h=s-n;l*l+h*h<=9&&i.push(o.start.z,o.end.z)}if(i.length===0){const o=[];for(const a of t)o.push(a.start.z,a.end.z);return o.length?(o.sort((a,s)=>a-s),o[Math.floor(o.length/2)]):-1/0}return i.sort((o,a)=>o-a),i[Math.floor(i.length/2)]}function Fn(t,e,n,r,i,o){const a=i-n,s=o-r,l=a*a+s*s;if(l<1e-12)return{dist:Math.sqrt((t-n)**2+(e-r)**2),t:0};const h=t-n,u=e-r,d=(h*a+u*s)/l,f=n+d*a,m=r+d*s;return{dist:Math.sqrt((t-f)**2+(e-m)**2),t:d}}function To(t,e,n=.15){let r=0,i=0;for(const a of e)a!==t&&((ye(t.start,a.start)<=n||ye(t.start,a.end)<=n)&&r++,(ye(t.end,a.start)<=n||ye(t.end,a.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 Bo(t,e){const n=[],{start:r,end:i}=t;for(const s of e){const{dist:l}=Fn(s.x,s.y,r.x,r.y,i.x,i.y);n.push(l)}const o=n.reduce((s,l)=>s+l,0)/n.length,a=n.reduce((s,l)=>s+(l-o)**2,0)/n.length;return a<.01?3:a<.05?2:a<.1?1:0}function Io(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 a=-i/o,s=r/o,l=[[],[]];for(let u=0;u<2;u++){const d=u===0?t.start:t.end;for(const f of e){if(f===t)continue;const m=ye(d,f.start),b=ye(d,f.end);let w=null;if(m<=n?w=f.end:b<=n&&(w=f.start),!w)continue;const _=f.end.x-f.start.x,M=f.end.y-f.start.y,g=Math.sqrt(_*_+M*M);if(g<1e-12||Math.abs(r*_+i*M)/(o*g)>=.342)continue;const v=(w.x-d.x)*a+(w.y-d.y)*s;l[u].push(v>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const h=[...l[0],...l[1]];return h.every(u=>u===h[0])?2:1}function ko(t,e,n){const r=To(t,n),i=Bo(t,e),o=Io(t,n);return{score:r.score*3+i*2+o*2,details:{conn:r.score,variance:i,sameSide:o}}}function Lo(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 Co(t,e){const n=[];for(const r of t){let i=!1;for(const o of n){const a=Math.abs(r.angle-o[0].angle);if(Math.min(a,180-a)<=e){o.push(r),i=!0;break}}i||n.push([r])}return n}function Ro(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 Fo(t,e,n,r,i){const o=[];for(const s of t){const l=s.seg,h=(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(h,u),r:Math.max(h,u),idx:s.idx})}o.sort((s,l)=>s.l-l.l);const a=[];for(const{l:s,r:l,idx:h}of o){if(a.length===0){a.push({l:s,r:l,srcIdxs:[h]});continue}const u=a[a.length-1];s<=u.r+i?(u.r=Math.max(u.r,l),u.srcIdxs.includes(h)||u.srcIdxs.push(h)):a.push({l:s,r:l,srcIdxs:[h]})}return a}function Go(t,e,n,r,i,o,a){const s=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=s,l.direction={x:r,y:i,z:0},l.rooftopPz=o,l.buildRosource=a,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function qo(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],a=t[i];if(o.rooftopPz!==void 0&&a.rooftopPz!==void 0&&Math.abs(o.rooftopPz-a.rooftopPz)>.05)continue;const s=Math.abs(o.end.x-a.start.x)<.001&&Math.abs(o.end.y-a.start.y)<.001,l=Math.abs(o.start.x-a.end.x)<.001&&Math.abs(o.start.y-a.end.y)<.001,h=Math.abs(o.end.x-a.end.x)<.001&&Math.abs(o.end.y-a.end.y)<.001,u=Math.abs(o.start.x-a.start.x)<.001&&Math.abs(o.start.y-a.start.y)<.001;if(!(s||l||h||u)||o.direction.x*a.direction.x+o.direction.y*a.direction.y<.98)continue;let d=o.start,f=o.end;s?f=a.end:l?d=a.start:h?f=a.start:u&&(d=a.end);const m=Math.hypot(f.x-d.x,f.y-d.y),b={...o};b.start=d,b.end=f,b.length=m,b.direction={x:(f.x-d.x)/m,y:(f.y-d.y)/m,z:0},b.rooftopPz=o.rooftopPz!==void 0?o.rooftopPz:a.rooftopPz,b.buildRosource=o.buildRosource||a.buildRosource,b.isRebuild=!1,b.doorAndBeamData||(b.doorAndBeamData=[]),b.insetionArr||(b.insetionArr=[]),t[r]=b,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 Ge(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((l,h)=>[h])};const r=t.map((l,h)=>({seg:l,angle:Lo(l),idx:h}));r.sort((l,h)=>l.angle-h.angle);const i=Co(r,e),o=[],a=[],s=[];for(const l of i){let h=l[0].seg;for(const M of l)M.seg.length>h.length&&(h=M.seg);const u=h.end.x-h.start.x,d=h.end.y-h.start.y,f=Math.sqrt(u*u+d*d);if(f<1e-12)continue;const m=-d/f,b=u/f,w=l.map(M=>{const g=M.seg.start.x-h.start.x,v=M.seg.start.y-h.start.y;return{seg:M.seg,offset:Math.abs(g*m+v*b),idx:M.idx}});w.sort((M,g)=>M.offset-g.offset);const _=Ro(w);for(const M of _){let g=M[0].seg;for(const D of M)D.seg.length>g.length&&(g=D.seg);const v=g.end.x-g.start.x,y=g.end.y-g.start.y,x=Math.sqrt(v*v+y*y);if(x<1e-12)continue;const p=v/x,P=y/x,V=M.map(D=>D.seg.rooftopPz??0),z=Math.max(...V),S=[...new Set(V.map(D=>D.toFixed(3)))];if(S.length>1){const D=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}));s.push({values:[...S],segments:D})}[...new Set(M.map(D=>String(D.seg.buildRosource)))];const E=Fo(M,g,p,P,n);for(const{l:D,r:T,srcIdxs:B}of E){if(T-D<.01)continue;const L=Go(g,D,T,p,P,z,g.buildRosource);o.push(L),a.push(B)}}}return{...qo(o,a),debugRPZGroups:s}}function Wo(t){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...t}}function Oo(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 No(t,e,n,r,i,o,a){const s=[{margin:o.projectionMargin,maxDist:o.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const h of s){if(l.length>0)break;for(const u of t){let d=!1,f=!1,m=!1;const b=e*o.minLengthRatio;if(u.length<b){continue}d=!0;const{start:w,end:_}=u;let M=!1,g=1/0;for(const S of i){const{dist:E,t:D}=Fn(S.x,S.y,w.x,w.y,_.x,_.y);D>=-h.margin&&D<=1+h.margin&&E<=h.maxDist&&(M=!0,g=Math.min(g,E))}if(!M){`${h.maxDist}${(-h.margin).toFixed(1)}${(1+h.margin).toFixed(1)}`;continue}f=!0;const v=Math.sqrt((_.x-w.x)**2+(_.y-w.y)**2);if(v<1e-12)continue;const y=(_.x-w.x)/v,x=(_.y-w.y)/v,p=Math.abs(n*y+r*x),P=Math.abs(-r*y+n*x),V=Math.acos(Math.min(Math.max(p,P),1))*(180/Math.PI);if(V>o.angleThreshold){`${V.toFixed(1)}${o.angleThreshold}`;continue}m=!0;let z=0;if(v>.01){const S=[];for(let T=1;T<=4;T++){const B=i[T],L=B.x-w.x,I=B.y-w.y,C=(L*y+I*x)/v;S.push(C)}const E=Math.min(...S),D=Math.max(...S);D>E&&(z=Math.max(0,Math.min(1,D)-Math.max(0,E))/(D-E))}l.push({seg:u,minDist:g,embedRatio:z,ratio:u.length/e,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function Ho(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:a}=ko(i.seg,e,n);i.score=o,i.details=a}return t.sort((i,o)=>o.embedRatio-i.embedRatio||o.score-i.score||i.minDist-o.minDist),t}function $o(t,e,n,r){const i=t.end.x-t.start.x,o=t.end.y-t.start.y,a=Math.sqrt(i*i+o*o),s=i/a,l=o/a,h=e.map(p=>{const P=p.x-t.start.x,V=p.y-t.start.y;return(P*s+V*l)/a}),u=Math.min(...h),d=Math.max(...h),f=(d-u)*a,m=(u+d)/2,b=t.start.x+m*i,w=t.start.y+m*o,_=n.box.min.z,M=n.box.max.z,g=Math.abs(M-_),v=Fe(r,t.start.x,t.start.y),y=Math.max(0,_-v),x=u<=0&&d>=1;return{p:{x:b,y:w,z:t.start.z+m*(t.end.z-t.start.z)},width:f,full:x,height:g,groundClearance:y}}function Gn(t,e,n){const r=e.map(u=>n[u]),i=[],o=[],a=[],s=[],l=[];let h;for(const u of r){if(u.points?.length)for(const d of u.points)i.push(d);if(u.originalPoints?.length)for(const d of u.originalPoints)o.push(d);if(u.doorAndBeamData?.length)for(const d of u.doorAndBeamData)a.push(d);if(u.insetionArr?.length)for(const d of u.insetionArr)s.push(d);if(u.drawWindow?.length)for(const d of u.drawWindow)l.push(d);u.boxData&&!h&&(h=u.boxData)}i.length&&(t.points=i),o.length&&(t.originalPoints=o),a.length&&(t.doorAndBeamData=a),s.length&&(t.insetionArr=s),l.length&&(t.drawWindow=l),h&&(t.boxData=h)}function qn(t,e,n){const r=Wo(n),i=[],{segments:o,sourceMap:a}=Ge(e),s=o;for(const l of t){const h=l.coordinatesByArea?.coordinates;if(!h||h.length<4)continue;const u=h.slice(0,4),d=u.reduce((p,P)=>p+P.x,0)/4,f=u.reduce((p,P)=>p+P.y,0)/4,{longSide:m,dirX:b,dirY:w}=Ao(u);if(m<.01||u.reduce((p,P)=>p+P.z,0)/4<Fe(e,d,f)-.3)continue;const _=Oo(u,d,f);l.name;let M=No(s,m,b,w,_,r,l.name);M=Ho(M,_,e,l.name);let g=null,v=1/0,y=0;if(M.length>0){const p=M[0];g=p.seg,v=p.minDist,y=p.ratio}let x;if(g&&(x=$o(g,u,l,o),!r.printOnly)){const p=g;p.drawWindow||(p.drawWindow=[]),p.drawWindow.push(x)}g&&i.push({windowName:l.name,windowCategory:l.category,windowCenter:l.center,wallSegment:g,distance:v,wallLengthRatio:y,drawWindow:x})}for(const l of i){const h=l.wallSegment,u=o.indexOf(h);if(u===-1)continue;const d=a[u];!d||d.length<=1||Gn(h,d,e)}return i}function Xo(t,e,n){const r={printOnly:!1,...n},i=qn(Array.isArray(e)?e.filter(l=>l&&l.category==="window"&&!l.isBayWindowObj):[],t,r),{segments:o,sourceMap:a}=Ge(t);for(let l=0;l<o.length;l++){const h=a[l];h&&Gn(o[l],h,t)}const s=new Set(i.map(l=>l.windowName));for(const l of e)l&&l.category==="window"&&!l.isBayWindowObj&&(s.has(l.name)?delete l.AbnormalWindow:l.AbnormalWindow=!0);for(const l of i)if(l.drawWindow){const h=o.find(u=>Math.abs(u.start.x-l.wallSegment.start.x)<.01&&Math.abs(u.start.y-l.wallSegment.start.y)<.01&&Math.abs(u.end.x-l.wallSegment.end.x)<.01&&Math.abs(u.end.y-l.wallSegment.end.y)<.01);h&&(h.drawWindow||(h.drawWindow=[]),h.drawWindow.push(l.drawWindow))}return{segments:o,matches:i,sourceMap:a}}exports.classifySegments=te;exports.computeLocalFloorZ=Fe;exports.findWindowWalls=qn;exports.getAllGeometry=lr;exports.getBeamLine=Mn;exports.getColLine=wr;exports.getMainBeamLine=xr;exports.getMergeMeaning=Eo;exports.getParallelism=ee;exports.getPointCloudMinMax=Ee;exports.getPointCoverageOnQuad=er;exports.isParallel=Kt;exports.mergeCollinearSegments=Ge;exports.perpendicularInfo=Qt;exports.processData=Xo;exports.removeNoisePoints=wn;exports.segmentsIntersect2D=Jt;exports.updateStEdPoint=cr;exports.usegetBeamLine=yr;
1
+ "use strict";var Zn=Object.defineProperty;var Kn=(n,t,e)=>t in n?Zn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Oe=(n,t,e)=>Kn(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const lt=require("three");function Qn(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const y=Qn(lt);function Jn(n,t=!1){const e=n[0].index!==null,o=new Set(Object.keys(n[0].attributes)),i=new Set(Object.keys(n[0].morphAttributes)),r={},s={},a=n[0].morphTargetsRelative,l=new lt.BufferGeometry;let c=0;for(let h=0;h<n.length;++h){const f=n[h];let u=0;if(e!==(f.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in f.attributes){if(!o.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(f.attributes[p]),u++}if(u!==o.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==f.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in f.morphAttributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;s[p]===void 0&&(s[p]=[]),s[p].push(f.morphAttributes[p])}if(t){let p;if(e)p=f.index.count;else if(f.attributes.position!==void 0)p=f.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,p,h),c+=p}}if(e){let h=0;const f=[];for(let u=0;u<n.length;++u){const p=n[u].index;for(let w=0;w<p.count;++w)f.push(p.getX(w)+h);h+=n[u].attributes.position.count}l.setIndex(f)}for(const h in r){const f=tn(r[h]);if(!f)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,f)}for(const h in s){const f=s[h][0].length;if(f===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let u=0;u<f;++u){const p=[];for(let x=0;x<s[h].length;++x)p.push(s[h][x][u]);const w=tn(p);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(w)}}return l}function tn(n){let t,e,o,i=-1,r=0;for(let c=0;c<n.length;++c){const h=n[c];if(t===void 0&&(t=h.array.constructor),t!==h.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=h.itemSize),e!==h.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(o===void 0&&(o=h.normalized),o!==h.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=h.gpuType),i!==h.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=h.count*e}const s=new t(r),a=new lt.BufferAttribute(s,e,o);let l=0;for(let c=0;c<n.length;++c){const h=n[c];if(h.isInterleavedBufferAttribute){const f=l/e;for(let u=0,p=h.count;u<p;u++)for(let w=0;w<e;w++){const x=h.getComponent(u,w);a.setComponent(u+f,w,x)}}else s.set(h.array,l);l+=h.count*e}return i!==void 0&&(a.gpuType=i),a}const to=(n,t,e)=>{let o=new y.LineBasicMaterial({color:"#0011ff"}),i=[];i.push(n),i.push(t);let r=new y.BufferGeometry;r.setFromPoints(i),r.rotateX(-Math.PI/2),e.add(new y.Line(r,o))},te=(n,t,e,o,i=1e-8)=>{const r=t.x-n.x,s=t.y-n.y,a=o.x-e.x,l=o.y-e.y,c=r*l-s*a;if(Math.abs(c)<i)return null;const h=((e.x-n.x)*l-(e.y-n.y)*a)/c,f=((e.x-n.x)*s-(e.y-n.y)*r)/c;return h<-i||h>1+i||f<-i||f>1+i?null:{point:new y.Vector3(n.x+h*r,n.y+h*s,n.z)}},eo=(n,t,e={})=>{const{fontSize:o=36,fontFamily:i="sans-serif",backgroundColor:r="rgba(0,0,0,0)",textColor:s="#ffffff",padding:a=10,maxWidth:l=256}=e,h=document.createElement("canvas").getContext("2d");h.font=`bold ${o}px ${i}`;const u=h.measureText(n).width;let p=Math.min(u+a*2,l),w=o+a*2;const x=document.createElement("canvas");x.width=p,x.height=w;const P=x.getContext("2d");P.fillStyle=r,P.fillRect(0,0,p,w),P.fillStyle=s,P.font=`bold ${o}px ${i}`,P.textAlign="center",P.textBaseline="middle",u>l-a*2?no(P,n,p/2,w/2,l,o):P.fillText(n,p/2,w/2);const M=new y.CanvasTexture(x),m=new y.SpriteMaterial({map:M,depthTest:!1,transparent:!0}),d=new y.Sprite(m);d.position.set(t.x,t.y,t.z);const g=.005;return d.scale.set(p*g,w*g,1),d};function no(n,t,e,o,i,r){const s=t.split("");let a="",l=r*1.2,c=o;for(let h=0;h<s.length;h++){const f=a+s[h];n.measureText(f).width>i&&h>0?(n.fillText(a,e,c),a=s[h],c+=l):a=f}n.fillText(a,e,c)}const oe=(n,t,e=.01)=>{const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(o<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};const r={x:n.x/o,y:n.y/o,z:n.z/o},s={x:t.x/i,y:t.y/i,z:t.z/i};let a=r.x*s.x+r.y*s.y+r.z*s.z;a=Math.max(-1,Math.min(1,a));const l=Math.acos(Math.abs(a)),c=l<=e;return{parallel:c,sameDirection:c?a>0:null,angle:l}},oo=(n,t,e,o)=>{const i=n;let r=[];if(o&&o.length&&(r=o.map(z=>z.clone())),!i||i.length<4)return{};const s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=s.clone().cross(a).normalize();let c=1/0,h=-1/0,f=1/0,u=-1/0;for(const z of i){const v=z.dot(s),S=z.dot(a);v<c&&(c=v),v>h&&(h=v),S<f&&(f=S),S>u&&(u=S)}const p=i[0].dot(l),w=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(p)),x=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(p)),P=s.clone().multiplyScalar(h).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(p)),M=s.clone().multiplyScalar(c).add(a.clone().multiplyScalar(u)).add(l.clone().multiplyScalar(p));let m=[w,x,P,M],d=oe(new y.Vector3().subVectors(w,x),new y.Vector3(0,0,1));d&&d.parallel&&(m=[w,M,P,x]);let g=0;if(o.length>0){const z=new y.Vector3().subVectors(m[1],m[0]).normalize(),v=z.clone().negate(),S=new y.Vector3().subVectors(m[3],m[0]).normalize(),V=S.clone().negate();let D=m[0].distanceTo(m[1]),_=m[0].distanceTo(m[3]),T=D/t,E=_/e,A=.001;for(let F=0;F<T;F++){let I=m[0],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(z,t),C=W.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=R}if(B>=E/2)break;g+=B,m[0]=m[0].addScaledVector(z,t),m[3]=m[3].addScaledVector(z,t)}D=m[0].distanceTo(m[1]),T=D/t;for(let F=0;F<T;F++){let I=m[1],B=0;for(let L=0;L<E;L++){let W=I.clone().addScaledVector(v,t),C=W.clone().addScaledVector(S,e),R=I.clone().addScaledVector(S,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=R}if(B>=E/2)break;g+=B,m[1]=m[1].addScaledVector(v,t),m[2]=m[2].addScaledVector(v,t)}D=m[0].distanceTo(m[1]),T=D/t;for(let F=0;F<E;F++){let I=m[3],B=0;for(let L=0;L<T;L++){let W=I.clone().addScaledVector(z,t),C=W.clone().addScaledVector(V,e),R=I.clone().addScaledVector(V,e),H=new y.Vector3().add(I).add(W).add(C).add(R).multiplyScalar(.25);for(let X=0;X<r.length;X++)if(r[X].distanceTo(H)<A){B++;break}I=W}if(B>=T/2)break;g+=B,m[2]=m[2].addScaledVector(V,e),m[3]=m[3].addScaledVector(V,e)}}const b=m[0].distanceTo(m[1])*m[0].distanceTo(m[3]);return{facePoints:m,boxArea:b,totalInPlaneNum:g}},Jt=(n,t,e,o,i=y.MathUtils.degToRad(8))=>{const r=new y.Vector3,s=new y.Vector3;r.subVectors(new y.Vector3(t.x,t.y,0),new y.Vector3(n.x,n.y,0)).normalize(),s.subVectors(new y.Vector3(o.x,o.y,0),new y.Vector3(e.x,e.y,0)).normalize();const a=r.dot(s),l=Math.acos(Math.min(Math.abs(a),1)),c=1-Math.min(l/i,1),h=a>0?"same":"opposite";return{parallelism:c,angle:l,angleDeg:y.MathUtils.radToDeg(l),isParallel:l<i,direction:h,vectors:{v1:r,v2:s}}},re=(n,t,e,o)=>{const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=i.length(),a=r.length();if(s===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),r.normalize();const l=Math.abs(i.dot(r)),c=Math.min(1,Math.max(0,l)),h=Math.acos(c),f=y.MathUtils.radToDeg(h),u=1-c;return{rate:u,percent:`${(u*100).toFixed(2)}%`,angle:f,isPerpendicular:Math.abs(f-90)<.01,isParallel:f<.01}},ee=(n,t,e=!1)=>new y.Vector3((n.x+t.x)/2,(n.y+t.y)/2,e?0:(n.z+t.z)/2),ne=(n,t,e,o,i={})=>{const{parallelAngleMax:r=y.MathUtils.degToRad(10),collinearAngleMax:s=y.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:l=.01}=i,c=new y.Vector3().subVectors(t,n),h=new y.Vector3().subVectors(o,e),f=c.clone().normalize(),u=h.clone().normalize();let p=y.MathUtils.clamp(f.dot(u),-1,1);const w=Math.acos(Math.abs(p)),x=y.MathUtils.radToDeg(w);if(w>r)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};p<0&&u.negate();const P=new y.Vector3().addVectors(f,u).normalize(),M=new y.Vector3().addVectors(n,t).multiplyScalar(.5),m=en(e,M,f),d=en(o,M,f),g=(m+d)/2,b=Math.max(m,d),z=n.dot(P),v=t.dot(P),S=e.dot(P),V=o.dot(P),D=Math.min(z,v),_=Math.max(z,v),T=Math.min(S,V),E=Math.max(S,V),A=_-D,F=E-T,I=Math.min(A,F),B=Math.min(_,E)-Math.max(D,T),L=B<0?-B:0,W=B>0?B:0,C=I>0?W/I:0,R=ro(n,t,e,o),H=w<=s&&g<a;let X;return H?X=C>.5?"collinear_overlap":"collinear_gap":w<=r&&(X="parallel_offset"),{type:X,angleDeg:x,avgPerpendicularDistance:g,maxPerpendicularDistance:b,gap:L,overlap:W,closestDistance:R}};function en(n,t,e){const o=new y.Vector3().subVectors(n,t),i=o.dot(e),r=e.clone().multiplyScalar(i);return new y.Vector3().subVectors(o,r).length()}function ro(n,t,e,o){const i=new y.Vector3().subVectors(t,n),r=new y.Vector3().subVectors(o,e),s=new y.Vector3().subVectors(e,n),a=i.dot(i),l=i.dot(r),c=r.dot(r),h=i.dot(s),f=r.dot(s),u=a*c-l*l;let p,w;u<1e-10?(p=0,w=c!==0?f/c:0):(p=(l*f-c*h)/u,w=(a*f-l*h)/u),p=y.MathUtils.clamp(p,0,1),w=c!==0?y.MathUtils.clamp((l*p+f)/c,0,1):0,p=a!==0?y.MathUtils.clamp((l*w-h)/a,0,1):0;const x=n.clone().add(i.clone().multiplyScalar(p)),P=e.clone().add(r.clone().multiplyScalar(w));return x.distanceTo(P)}const nn=(n,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(n)))),io=n=>{let t=new y.Vector3(n.start.x,n.start.y,n.start.z),e=new y.Vector3(n.end.x,n.end.y,n.end.z),o=t.distanceTo(e),i=n.rooftopPz-n.start.z,r=nn(o,100),s=nn(i,70),a=i/s,l=new Map;for(let x=0;x<s;x++)l.set((x+1)*a,{count:0,minZ:1/0,maxZ:-1/0});let c=new y.Line3(t,e);const h=n.originalPoints,f=new y.Vector3;for(let x=0;x<h.length;x++){const P=h[x];let m=c.closestPointToPoint(P,!0,f).distanceTo(P);const d=Math.floor(m/a);if(d<s){const g=l.get((d+1)*a);g.count++,P.z<g.minZ&&(g.minZ=P.z),P.z>g.maxZ&&(g.maxZ=P.z)}}let u,p,w=r/2;for(const[x,P]of l)if(P.count>=w){u=P.minZ;break}for(const[x,P]of[...l.entries()].reverse())if(P.count>=w){p=P.maxZ;break}return{minZ:u,maxZ:p}},Ve=(n,t,e)=>{let o=new y.Plane;const i=new y.Vector3(n.x,n.y,n.z),r=new y.Vector3(t.x,t.y,t.z),s=new y.Vector3(t.x,t.y,t.z+5);o.setFromCoplanarPoints(i,r,s);const a=[],l=[];e.forEach(P=>{const M=new y.Vector3;o.projectPoint(P,M),l.push(M.clone()),M.z=i.z,a.push(M)});let c=new y.Vector3,h=new y.Vector3;o.projectPoint(i,c),o.projectPoint(r,h);const f=new y.Line3(c,h),u=[],p=[],w=[];let x=new y.Vector3;return a.forEach((P,M)=>{f.closestPointToPoint(P,!0,x).distanceTo(P)<.001?(u.push(e[M]),p.push(l[M])):w.push(P)}),{newOriginalPoints:u,newProjectPoints:w,newOnLinePoints:p}},so=n=>{function t(e,o,i,r,s,a,l,c,h){let f=new y.Line3(e,o),u=new Map,p=new y.Vector3,w=e.clone(),x=o.clone(),P=0;for(;;){let M=new Map,m=0;for(let d=0;d<h.checkResults.length;d++)if(!(h.checkResults[d].allCenterPoints.length/c*100<1))for(let b=0;b<h.checkResults[d].allCenterPoints.length;b++){if(u.has(d)&&u.get(d).removePtsIndex.includes(b))continue;let z=h.checkResults[d].allCenterPoints[b];z=new y.Vector3(z.x,z.y,z.z);let v=f.closestPointToPoint(z,!0,p),S=z.distanceTo(v);Math.abs(S-s)<.01&&(m++,M.has(d)?M.get(d).removePtsIndex.push(b):M.set(d,{index:d,removePtsIndex:[b]}))}if(P==l){e=w,o=x;break}if(m<a/20*18||m==0){M.clear(),l-P<5&&(e=w,o=x,u.clear());break}else{P++;for(const[d,g]of M)u.has(d)?u.get(d).removePtsIndex.push(...g.removePtsIndex):u.set(d,g);M.clear(),e=e.addScaledVector(i,r),o=o.addScaledVector(i,r),f.set(e,o)}}if(u.size>0&&P!=l)for(const[M,m]of u){let d=[],g=[];for(let b=0;b<h.checkResults[M].allCenterPoints.length;b++)m.removePtsIndex.includes(b)||(d.push(h.checkResults[M].allCenterPoints[b]),g.push(h.checkResults[M].originalVertices[b]));h.checkResults[M].allCenterPoints=d,h.checkResults[M].originalVertices=g}}for(let e=0;e<n.length;e++){const o=n[e];if(o.length<.5)continue;let i=-1,r=-1;if(!o.checkResults||o.checkResults.length<=0)continue;if(o.checkResults[0].originalVertices&&o.checkResults[0].originalVertices.length>0){const S=o.checkResults[0].originalVertices[0];let[V,D,_,T]=S;V=new y.Vector3(V.x,V.y,V.z),D=new y.Vector3(D.x,D.y,D.z),_=new y.Vector3(_.x,_.y,_.z),T=new y.Vector3(T.x,T.y,T.z),i=V.distanceTo(D),r=V.distanceTo(T);let E=new y.Vector3().subVectors(V,D).normalize(),A=oe(E,new y.Vector3(0,0,1));A&&A.parallel&&([r,i]=[i,r])}if(i<0||r<0)continue;let s=new y.Vector3(o.start.x,o.start.y,o.start.z),a=new y.Vector3(o.end.x,o.end.y,o.end.z);const l=s.distanceTo(a),c=o.rooftopPz-o.start.z,h=Math.ceil(l/i),f=Math.ceil(c/r);let u=s.clone(),p=a.clone(),w=p.clone().add(new y.Vector3(0,0,c)),x=u.clone().add(new y.Vector3(0,0,c)),P=new y.Vector3().subVectors(p,u).normalize(),M=P.clone().negate();new y.Vector3().subVectors(w,u).normalize().clone().negate();let d=i/2,g=l*c,b=i*r,z=g/b;t(u,x,P,i,d,f,h,z,o),t(p,w,M,i,d,f,h,z,o),o.start=u,o.end=p;const{newOriginalPoints:v}=Ve(u,p,o.originalPoints);o.originalPoints=v}},Lt=(n,t)=>new y.Vector3(n.x,n.y,0).distanceTo(new y.Vector3(t.x,t.y,0)),ao=(n,t,e=1e-6)=>{const o=new y.Vector3;return n.closestPointToPoint(t,!0,o),o.distanceTo(t)<e},Se=n=>{let t=0,e=[];for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o].distanceTo(n[i]);r>t&&(t=r,e=[n[o],n[i]])}return e},kt=(n,t,e=.03)=>Math.abs(n.x-t.x)<e&&Math.abs(n.y-t.y)<e&&Math.abs(n.z-t.z)<e,lo=()=>{const n=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),t=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),e=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0");return`#${n}${t}${e}`},co=(n,t=.001)=>{const e=new Map,o=[];for(const i of n){const r=Math.round(i.x/t),s=Math.round(i.y/t),a=Math.round(i.z/t),l=`${r},${s},${a}`;e.has(l)||(e.set(l,!0),o.push(i))}return o};class uo{constructor(){Oe(this,"results");Oe(this,"clusterResults");this.results=null}initLimits1(t,e){let o,i;return t<.3?o=5:t<.5?o=8:t<.8?o=10:t<1?o=15:t<2?o=30:t<3?o=35:t<4?o=40:t<5?o=45:t<6?o=50:t<7?o=60:t<8.5?o=70:t<10?o=80:t<15?o=100:t<20?o=120:t<25?o=140:t<30?o=160:t<35?o=180:t<40?o=200:t<45?o=230:t<50?o=250:o=350,e<1?i=30:e<2?i=40:e<2.5?i=45:e<3?i=60:e<3.6?i=70:e<4&&(i=80),{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits2(t,e){const r=Math.round(Math.max(5,Math.min(350,t/.08))),s=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(t,e){const o=Math.round(Math.max(5,Math.min(350,65*Math.sqrt(t))))*1,i=Math.round(Math.max(30,Math.min(80,15*Math.sqrt(e))))*1;return{horizontalSubdivisions:o,verticalSubdivisions:i}}initLimits3(t,e){let o;t<2?o=.06:t<10?o=.1:o=.15;const i=Math.round(Math.max(5,Math.min(350,t/o))),r=Math.round(Math.max(30,Math.min(80,e/.06)));return{horizontalSubdivisions:i,verticalSubdivisions:r}}createWallPlaneMeshFromFourPoints(t,e,o,i,r,s,a=16777215){const l=[t,e,o,i];for(let P=0;P<l.length;P++)this.isValidVector3(l[P])||(console.error(`点${P+1}包含无效数据:`,l[P]),l[P]=new y.Vector3(P,0,P));const c=new y.BufferGeometry,h=new Float32Array([l[0].x,l[0].y,l[0].z,l[1].x,l[1].y,l[1].z,l[2].x,l[2].y,l[2].z,l[3].x,l[3].y,l[3].z]),f=[0,1,2,0,2,3],u=new Float32Array([0,0,1,0,1,1,0,1]);c.setAttribute("position",new y.BufferAttribute(h,3)),c.setAttribute("uv",new y.BufferAttribute(u,2)),c.setIndex(f),c.computeVertexNormals();const p=new y.Mesh(c,r),w=new y.EdgesGeometry(c),x=new y.LineSegments(w,new y.LineBasicMaterial({color:a}));return s.add(x),p}createSubdividedWallPlane(t,e,o,i,r){const s=[];if(!t||!t.start||!t.end||isNaN(t.rooftopPz))return s;const a=new y.Vector3(t.start.x,t.start.y,t.start.z),l=new y.Vector3(t.end.x,t.end.y,t.end.z),c=new y.Vector3(t.end.x,t.end.y,t.rooftopPz),h=new y.Vector3(t.start.x,t.start.y,t.rooftopPz),f=[a,l,c,h];for(let m=0;m<f.length;m++)if(!this.isValidVector3(f[m]))return console.error(`墙体基础点${m}无效:`,f[m]),s;const u=a.distanceTo(l),p=Math.abs(t.rooftopPz-t.start.z);if(u===0||p===0)return console.error("墙体宽度或高度为0"),console.log("line.rooftopPz",t.rooftopPz),console.log("bottomLeft",a),console.log("bottomRight",l),console.log(t.length),s;const w=u/o,x=p/e,P=new y.Vector3().subVectors(l,a).normalize(),M=new y.Vector3(0,0,1);for(let m=0;m<e;m++)for(let d=0;d<o;d++)try{const g=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar(m*x)),b=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar(m*x)),z=new y.Vector3().copy(a).add(P.clone().multiplyScalar((d+1)*w)).add(M.clone().multiplyScalar((m+1)*x)),v=new y.Vector3().copy(a).add(P.clone().multiplyScalar(d*w)).add(M.clone().multiplyScalar((m+1)*x)),S={points:[g,b,z,v],userData:{}};S.userData={type:"wallSegment",row:m,col:d,originalMaterial:i,width:w,height:x},s.push(S)}catch(g){console.error(`创建墙体小平面(${m}, ${d})时出错:`,g)}return s}calculateMinRequiredPoints(t){const i=Math.floor(Math.log1p(t)*.5);return Math.max(1,i)}calculateExpectedDensity(t){return t<1?10:t<4?5:2}evaluateSegmentByArea(t,e,o,i){if(e===0)return!1;const r=t.area,s=t.minRequiredPoints,a=t.expectedDensity,l=e/Math.max(r,.001),c=e>=s,h=l>=a*.3;let f=!0;return r<.5&&e>0&&(f=this.checkSmallAreaDistribution(t,o,i)),c&&h&&f}checkSmallAreaDistribution(t,e,o){if(e.length<2)return!0;const i=e.map(l=>o[l]);t.bounds;const r=t.center;let s=0;const a=Math.sqrt(t.area)*.3;return i.forEach(l=>{l.distanceTo(r)<=a&&s++}),s/i.length>=.3}getFailureReason(t,e){const o=t.area,i=t.minRequiredPoints,r=t.expectedDensity,s=e/Math.max(o,.001),a=[];return e===0?a.push("无点"):(e<i&&a.push(`点数不足: ${e}/${i}`),s<r*.3&&a.push(`密度不足: ${s.toFixed(2)}/${r.toFixed(2)}`),o<.5&&e>0&&(this.checkSmallAreaDistribution(t,[],[])||a.push("小平面分布不均"))),a.length>0?a.join(", "):"未知原因"}calculateMedian(t){const e=[...t].sort((i,r)=>i-r),o=Math.floor(e.length/2);return e.length%2!==0?e[o]:(e[o-1]+e[o])/2}isPointInBoundingBox(t,e,o=.1){return t.x>=e.min[0]-o&&t.x<=e.max[0]+o&&t.y>=e.min[1]-o&&t.y<=e.max[1]+o&&t.z>=e.min[2]-o&&t.z<=e.max[2]+o}getSegmentPlane(t){const e=t.geometry;if(!e||!e.attributes.position)return null;const o=e.attributes.position;if(o.count<3)return null;const i=new y.Vector3().fromBufferAttribute(o,0),r=new y.Vector3().fromBufferAttribute(o,1),s=new y.Vector3().fromBufferAttribute(o,2);i.applyMatrix4(t.matrixWorld),r.applyMatrix4(t.matrixWorld),s.applyMatrix4(t.matrixWorld);const a=new y.Plane;return a.setFromCoplanarPoints(i,r,s),a}analyzePointDistribution(t,e,o=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};const i=performance.now(),r=[];t.forEach(s=>{if(s.userData&&s.userData.type==="wallSegment"){const a=this.getWorldVerticesNew(s.points);if(a.length<4)return;const l=new y.Vector3().add(a[0]).add(a[1]).add(a[2]).add(a[3]).multiplyScalar(.25);s.userData.center=l,s.vertices=a,r.push(s)}}),this.results.totalSegments=r.length;for(const s of r){if(s.vertices.length<4)continue;const a=s.userData.center,l=`row${s.userData.row}_col${s.userData.col}`,[c,h,f,u]=s.vertices,p=new y.Vector3().subVectors(h,c).normalize(),w=new y.Vector3().subVectors(u,c).normalize(),x=c.distanceTo(h),P=c.distanceTo(u),M=new y.Plane;M.setFromCoplanarPoints(c,h,u);const m=x/2,d=P/2;for(let g=0;g<e.length;g++)this.isPointInWallSegmentOptimized(e[g],a,M,c,p,w,x,P,m,d,o)&&(this.results.pointsInSegments.has(l)||this.results.pointsInSegments.set(l,[]),this.results.pointsInSegments.get(l).push(g))}return r.forEach(s=>{const a=`row${s.userData.row}_col${s.userData.col}`,l=this.results.pointsInSegments.has(a)?this.results.pointsInSegments.get(a).length:0;l>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:s.userData.row,col:s.userData.col,width:s.userData.width,height:s.userData.height,segmentKey:a,vertices:s.vertices,center:s.userData.center,mesh:s,pointCount:l,hasPointsButNotEnough:l>0&&l<1}))}),this.results.analysisTime=performance.now()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(t,e,o,i,r,s,a,l,c,h,f){if(Math.abs(o.distanceToPoint(t))>f)return!1;const p=new y.Vector3().subVectors(t,e),w=Math.abs(p.dot(r)),x=Math.abs(p.dot(s));if(w>c&&x>h)return!1;const P=new y.Vector3().subVectors(t,i),M=P.dot(r),m=P.dot(s),d=M>=-f&&M<=a+f,g=m>=-f&&m<=l+f;return d&&g}isPointInWallSegment(t,e,o,i=.1){if(!t.geometry)return!1;try{const r=this.getWorldVertices(t);return r.length<4?!1:this.isPointInRotatedWall(r,e,o,i)}catch(r){return console.error("判断点是否在墙体平面内时出错:",r),!1}}isPointInRotatedWall(t,e,o,i=.1){const[r,s,a,l]=t,c=new y.Plane;if(c.setFromCoplanarPoints(r,s,l),Math.abs(c.distanceToPoint(e))>i)return!1;const f=new y.Vector3().subVectors(s,r).normalize(),u=new y.Vector3().subVectors(l,r).normalize();new y.Vector3().crossVectors(f,u).normalize();const p=new y.Vector3().subVectors(e,r),w=p.dot(f),x=p.dot(u),P=r.distanceTo(s),M=r.distanceTo(l),m=w>=-i&&w<=P+i,d=x>=-i&&x<=M+i;return m&&d&&o.distanceTo(e)<P/2&&o.distanceTo(e)<M/2}getWorldVertices(t){if(t._cachedWorldVertices&&t.matrixWorld.equals(t._cachedMatrixWorld))return t._cachedWorldVertices;const e=t.geometry.getAttribute("position"),o=[];for(let i=0;i<Math.min(4,e.count);i++){const r=new y.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.push(r)}return t._cachedWorldVertices=o,t._cachedMatrixWorld=t.matrixWorld.clone(),o}getWorldVerticesNew(t){const e=[];for(let o=0;o<t.length;o++){const i=t[o].clone();e.push(i)}return e}getWallSegmentBounds(t){if(!t.geometry)return null;const e=t.geometry.getAttribute("position"),o=new y.Box3;for(let i=0;i<e.count;i++){const r=new y.Vector3;r.fromBufferAttribute(e,i),r.applyMatrix4(t.matrixWorld),o.expandByPoint(r)}return{min:o.min.toArray(),max:o.max.toArray(),center:o.getCenter(new y.Vector3).toArray(),size:o.getSize(new y.Vector3).toArray()}}highlightEmptySegments(t,e,o,i=1){var f;if(!this.results){console.warn("请先运行分析函数");return}const r=new Map,s=new Map;this.results.missingSegments.forEach(u=>{r.set(u.segmentKey,u),s.has(u.row)||s.set(u.row,new Map),s.get(u.row).set(u.col,{segmentKey:u.segmentKey,isEmpty:!0,visited:!1})}),t.forEach(u=>{if(u.userData&&u.userData.type==="wallSegment"){const p=`row${u.userData.row}_col${u.userData.col}`,w=r.has(p);s.has(u.userData.row)||s.set(u.userData.row,new Map),s.get(u.userData.row).has(u.userData.col)||s.get(u.userData.row).set(u.userData.col,{segmentKey:p,isEmpty:w,visited:!1})}});const a=[],l=[[0,1],[1,0],[0,-1],[-1,0]];for(const[u,p]of r){const w=(f=s.get(p.row))==null?void 0:f.get(p.col);if(w&&!w.visited){const x=[],P=[[p.row,p.col]];for(w.visited=!0;P.length>0;){const[M,m]=P.shift(),d=`row${M}_col${m}`;r.has(d)&&x.push(r.get(d));for(const[g,b]of l){const z=M+g,v=m+b;if(s.has(z)&&s.get(z).has(v)){const S=s.get(z).get(v);!S.visited&&S.isEmpty&&(S.visited=!0,P.push([z,v]))}}}x.length>=i&&a.push(x)}}const c=this.createClusterMaterials(a.length),h=[];return this.clusterResults={clusters:a.sort((u,p)=>p.length-u.length),highlightedMeshes:h,clusterMaterials:c,totalClusters:a.length,totalHighlighted:h.length},this.clusterResults}calculateBoundaryRegularity(t,e,o,i,r){let s=0;const a=e;let l=!0;for(let x=i;x<=r;x++)t.has(a)&&t.get(a).has(x)||(l=!1);l&&s++;const c=o;let h=!0;for(let x=i;x<=r;x++)t.has(c)&&t.get(c).has(x)||(h=!1);h&&s++;const f=i;let u=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(f)||(u=!1);u&&s++;const p=r;let w=!0;for(let x=e;x<=o;x++)t.has(x)&&t.get(x).has(p)||(w=!1);return w&&s++,s/4}calculateClusterQualityScore(t){const r=1/Math.max(1,t.aspectRatio);return t.compactness*.4+t.boundaryRegularity*.4+r*.2}calculateStrictClusterBounds(t){var f,u;if(t.length===0)return{width:0,height:0};const e=[];if(t.forEach(p=>{p.vertices&&p.vertices.length>0&&e.push(...p.vertices)}),e.length===0){const p=[...new Set(t.map(x=>x.row))];return{width:[...new Set(t.map(x=>x.col))].length*(((f=t[0].bounds)==null?void 0:f.width)||1),height:p.length*(((u=t[0].bounds)==null?void 0:u.height)||1)}}const o=Math.min(...e.map(p=>p.x)),i=Math.max(...e.map(p=>p.x)),r=Math.min(...e.map(p=>p.y)),s=Math.max(...e.map(p=>p.y)),a=Math.min(...e.map(p=>p.z)),l=Math.max(...e.map(p=>p.z)),c=Math.abs(i-o),h=Math.max(Math.abs(s-r),Math.abs(l-a));return{width:c,height:h}}createClusterMaterials(t){const e=[],o=[16711935,65535,16753920,16738740,9055202,3329330,"lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral"];for(let i=0;i<t;i++){const r=o[i%o.length],s=new y.MeshBasicMaterial({color:r,transparent:!0,opacity:.6,side:y.DoubleSide});e.push(s)}return e}clearHighlights(t){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(e=>{t.remove(e),e.material&&e.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,o)=>{e.mesh&&e.mesh.userData.originalMaterial&&(e.mesh.material=e.mesh.userData.originalMaterial)}),this.clusterResults.highlightedMeshes=[])}getClusterInfo(){return this.clusterResults?{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((t,e)=>({clusterIndex:e,size:t.length,segments:t.map(o=>o.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(t=>t.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(t=>t.length))}:null}restoreOriginalMaterials(t){let e=0;t.traverse(o=>{o.userData&&o.userData.originalMaterial&&(o.material=o.userData.originalMaterial,delete o.userData.originalMaterial,e++)}),console.log(`恢复了 ${e} 个平面的原始材质`)}createDebugHelpers(t){const e=new y.Group;return t.traverse(o=>{if(o.userData&&o.userData.type==="wallSegment"){const i=this.getWorldVertices(o);if(i.length<4)return;const r=new y.Vector3().add(i[0]).add(i[1]).add(i[2]).add(i[3]).multiplyScalar(.25),s=new y.Vector3().subVectors(i[1],i[0]).normalize(),a=new y.Vector3().subVectors(i[3],i[0]).normalize(),l=new y.Vector3().crossVectors(s,a).normalize(),c=new y.ArrowHelper(l,r,.3,16711680),h=new y.ArrowHelper(s,r,.2,65280),f=new y.ArrowHelper(a,r,.2,255);e.add(c),e.add(h),e.add(f)}}),e}printAnalysisResults(){if(!this.results){console.warn("没有可用的分析结果");return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(t=>{}),this.results.pointsInSegments.forEach((t,e)=>{})}isValidVector3(t){return t&&!isNaN(t.x)&&!isNaN(t.y)&&!isNaN(t.z)&&isFinite(t.x)&&isFinite(t.y)&&isFinite(t.z)}mergeWallGroupMeshes(t){const e=[];if(t.traverse(o=>{o.isMesh&&o.geometry&&e.push(o)}),e.length===0)return null;try{const o=e.map(a=>a.geometry);o.forEach((a,l)=>{a.applyMatrix4(e[l].matrixWorld)});const i=Jn(o),r=e[0].material.clone(),s=new y.Mesh(i,r);return s.name="mergedWalls",s}catch(o){return console.error("合并网格时出错:",o),null}}}const ho=n=>{let t={};const e=[],o=[],i=[];return n[0].width,n[0].height,n.forEach(r=>{o.push(...r.vertices),i.push(r.center),e.push(r.vertices)}),t.originalVertices=e,t.allCenterPoints=i,t},fo=n=>{const t=new lt.Vector3().copy(n.start).add(n.end).multiplyScalar(.5),e=new lt.Vector3().subVectors(new lt.Vector3(t.x,t.y,t.z+1),t).normalize(),o=new lt.Vector3(n.direction.x,n.direction.y,0);o.applyAxisAngle(e,Math.PI/2);const i=new lt.Vector3().copy(t).add(o.clone().multiplyScalar(n.length)),r=new lt.Vector3().copy(t).sub(o.clone().multiplyScalar(n.length));return t.z=n.start.z,i.z=n.start.z,r.z=n.start.z,{start:i,end:r,center:t,direction:o}},mo=(n,t,e=!0)=>{let o=[];if(!n)return[];for(let i=0;i<n.length;i++){const r=n[i];if(!r)continue;let s=new y.Vector3(r.start.x,r.start.y,r.start.z);s.applyEuler(new y.Euler(-Math.PI/2,0,0));let a=new y.Vector3(r.end.x,r.end.y,r.end.z);if(a.applyEuler(new y.Euler(-Math.PI/2,0,0)),t.add(eo(String(i),new y.Vector3((s.x+a.x)/2,(s.y+a.y)/2,(s.z+a.z)/2))),(r.isBayWindow||r.isWindow)&&e)continue;const l=new lt.Plane().setFromCoplanarPoints(new lt.Vector3(r.start.x,r.start.y,r.start.z),new lt.Vector3(r.end.x,r.end.y,r.end.z),new lt.Vector3(r.start.x,r.start.y,r.rooftopPz)),c=[];r.originalPoints.forEach((v,S)=>{const V=new lt.Vector3;l.projectPoint(v,V),c.push(V)});const h=new lt.Vector3(r.start.x,r.start.y,r.start.z).distanceTo(new lt.Vector3(r.end.x,r.end.y,r.end.z)),f=Math.abs(r.rooftopPz-r.start.z),u=new y.MeshBasicMaterial({color:"red",side:y.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),p=new y.Group,w=new uo,{horizontalSubdivisions:x,verticalSubdivisions:P}=w.initLimits4(h,f),M=w.createSubdividedWallPlane(r,P,x,u,p);w.analyzePointDistribution(M,c,.01);const m=new y.MeshBasicMaterial({color:"black",transparent:!0,opacity:.8,side:y.DoubleSide}),d=w.highlightEmptySegments(M,m,p),g=[];for(const v of d.clusters){const S=ho(v);S&&g.push(S)}const z=fo(r).direction;r.checkResults=g,r.verticalDirection=z,r.originaIndex=i,o.push(r)}return o},go=(n,t)=>{console.log("lines",n);for(let e=0;e<n.length;e++){const o=n[e],i=[];o.originalPoints.forEach(d=>{let g=new y.Vector3(d.x,d.y,0),b=!1;for(let z=0;z<i.length;z++)if(kt(g,i[z],.01)){b=!0;break}b||i.push(g)});const r=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),s=1;let a=new y.Vector3(o.start.x,o.start.y,o.start.z),l=new y.Vector3(o.end.x,o.end.y,o.end.z),c=new y.Vector3().subVectors(l,a).normalize(),h=c.clone().cross(new y.Vector3(0,0,1)).normalize(),f=h.clone().negate(),u=[];const p=[];let w=o.length/r;console.log(w);for(let d=0;d<r;d++){const g=[];g.push(a.clone().addScaledVector(h,s)),g.push(g[0].clone().addScaledVector(c,w)),g.push(g[1].clone().addScaledVector(f,s*2)),g.push(a.clone().addScaledVector(f,w));let b=[];for(let z=0;z<i.length;z++)u.includes(z)||yo(i[z],g)&&(u.push(z),b.push(i[z]));b.length>0&&p.push(xo(b)),a=a.addScaledVector(c,w)}const x=new Float32Array(i.length*3);i.forEach((d,g)=>{x[g*3]=d.x,x[g*3+1]=d.y,x[g*3+2]=d.z});const P=new y.BufferGeometry;P.setAttribute("position",new y.BufferAttribute(x,3)),P.rotateX(-Math.PI/2),t.add(new y.Points(P,new y.PointsMaterial({color:lo(),size:.02})));const[M,m]=Mo(p,{plane:"xy",trimRatio:0});to(M,m,t)}};function on(n,t="xy"){if(t==="xy")return{x:n.x,y:n.y};if(t==="xz")return{x:n.x,y:n.z};if(t==="yz")return{x:n.y,y:n.z};throw new Error(`Unsupported plane: ${t}`)}function po(n,t,e){const o=t.x-n.x,i=t.y-n.y,r=e.x-n.x,s=e.y-n.y;return o*s-i*r}function yo(n,t,e="xy"){if(!t||t.length!==4)throw new Error("rectPoints must contain 4 points");const o=on(n,e),i=t.map(a=>on(a,e));let r=!1,s=!1;for(let a=0;a<4;a++){const l=i[a],c=i[(a+1)%4],h=po(l,c,o);if(h>1e-9&&(r=!0),h<-1e-9&&(s=!0),r&&s)return!1}return!0}function xo(n){if(!n||n.length===0)return null;const t=new y.Vector3(0,0,0);for(const e of n)Array.isArray(e)?(t.x+=e[0],t.y+=e[1],t.z+=e[2]):(t.x+=e.x,t.y+=e.y,t.z+=e.z);return t.divideScalar(n.length),t}function wo(n){return n instanceof y.Vector3?n.clone():Array.isArray(n)?new y.Vector3(n[0],n[1],n[2]):new y.Vector3(n.x,n.y,n.z)}function bo(n,t="xy"){const e=wo(n);if(t==="xy")return{x:e.x,y:e.y,up:e.z};if(t==="xz")return{x:e.x,y:e.z,up:e.y};if(t==="yz")return{x:e.y,y:e.z,up:e.x};throw new Error(`Unsupported plane: ${t}`)}function rn(n,t,e,o="xy"){if(o==="xy")return new y.Vector3(n,t,e);if(o==="xz")return new y.Vector3(n,e,t);if(o==="yz")return new y.Vector3(e,n,t);throw new Error(`Unsupported plane: ${o}`)}function Po(n,t,e){if(Math.abs(t)<1e-12)return n>=e?{x:1,y:0}:{x:0,y:1};const i=n+e,r=n*e-t*t,s=Math.sqrt(Math.max(0,i*i*.25-r)),a=i*.5+s;let l=t,c=a-n;const h=Math.hypot(l,c);return h<1e-12?{x:1,y:0}:{x:l/h,y:c/h}}function Mo(n,t={}){const{plane:e="xy",trimRatio:o=0}=t;if(!n||n.length<2)return null;const i=n.map(B=>bo(B,e));let r=0,s=0,a=0;for(const B of i)r+=B.x,s+=B.y,a+=B.up;r/=i.length,s/=i.length,a/=i.length;let l=0,c=0,h=0;for(const B of i){const L=B.x-r,W=B.y-s;l+=L*L,c+=L*W,h+=W*W}l/=i.length,c/=i.length,h/=i.length;const f=Po(l,c,h),u={x:-f.y,y:f.x},p=[];for(const B of i){const L=B.x-r,W=B.y-s,C=L*f.x+W*f.y,R=L*u.x+W*u.y;p.push({s:C,t:R,up:B.up})}p.sort((B,L)=>B.s-L.s);const w=p.length;let x=Math.floor(w*o),P=Math.ceil(w*(1-o))-1;x=Math.max(0,Math.min(w-1,x)),P=Math.max(0,Math.min(w-1,P));const M=p[x],m=p[P],d=(()=>{const B=p.map(W=>W.t).sort((W,C)=>W-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),g=(()=>{const B=p.map(W=>W.up).sort((W,C)=>W-C),L=Math.floor(B.length/2);return B.length%2===0?(B[L-1]+B[L])*.5:B[L]})(),b=M.s,z=m.s,v=d,S=d,V=g,D=g,_=r+f.x*b+u.x*v,T=s+f.y*b+u.y*v,E=r+f.x*z+u.x*S,A=s+f.y*z+u.y*S,F=rn(_,T,V,e),I=rn(E,A,D,e);return[F,I]}const Vo=async(n,t,e,o,i)=>{if(o&&o.length>0)for(let d=0;d<o.length;d++){const g=o[d];g.isLine2=!0,n.push(g)}if(so(n),n.length<=0||t.length<=0)return n;e||(e=[]);for(const d of n){let g=[];if(!(!d.checkResults||d.checkResults.length<=0)){for(let b=0;b<d.checkResults.length;b++){let D=function(A){for(;V[A]!==A;)V[A]=V[V[A]],A=V[A];return A};const z=d.checkResults[b];if(z.isDoor=!1,!z.originalVertices||z.originalVertices.length==0)continue;const v=[];z.originalVertices.forEach(A=>{let F=[];A.forEach(I=>{F.push(new y.Vector3(I.x,I.y,I.z))}),v.push(F)});const S=v.length,V=Array.from({length:S},(A,F)=>F);for(let A=0;A<S;A++)for(let F=A+1;F<S;F++){const I=v[A],B=v[F];if(I.some(W=>B.some(C=>W.equals(C)))){const W=D(A),C=D(F);W!==C&&(V[W]=C)}}const _=new Map;let T=-1,E=-1;for(let A=0;A<S;A++){const F=D(A);_.has(F)||_.set(F,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});const I=_.get(F);let[B,L,W,C]=v[A];const R=new y.Vector3().add(B).add(L).add(W).add(C).multiplyScalar(.25);if(I.points.push(...v[A]),I.area+=B.distanceTo(L)*B.distanceTo(C),I.originalVertices.push(v[A]),I.index=b,I.centerPts.push(R),T==-1||E==-1){let H=new y.Vector3().subVectors(B,L).normalize();E=B.distanceTo(C),T=B.distanceTo(L);let X=oe(H,new y.Vector3(0,0,1));X&&X.parallel&&([E,T]=[T,E])}I.gridWidth=T,I.gridHeight=E}g.push(..._.values())}d.mergeCheckRegion=g}}let r=new Map;for(const d of n){if(d.length<.3)continue;let g=d.rooftopPz-d.start.z,b=Math.floor(d.rooftopPz-d.start.z);r.has(b)?r.set(b,{num:r.get(b).num+1,totalHeight:r.get(b).totalHeight+g}):r.set(b,{num:1,totalHeight:g})}let s=[...r.entries()].reduce((d,g)=>g[1].num>d[1].num?g:d);s[0],s[1].totalHeight/s[1].num;const a=[];for(let d=0;d<e.length;d++){const g=e[d];if(g.isFindBeam=!1,g.category=="door"){let b=[];g.coordinatesByArea.coordinates.forEach(D=>{b.push(new y.Vector3(D.x,D.y,D.z))}),b[0].equals(b[b.length-1])&&b.pop();let z=b[0].distanceTo(b[1]),v=b[0].distanceTo(b[3]);v>z&&([z,v]=[v,z],b=[b[0],b[3],b[2],b[1]]);let S=ee(b[0],b[3],!0),V=ee(b[1],b[2],!0);a.push({doorStartPt:S,doorEndPt:V,boxPoints:b,minZ:g.coordinatesByArea.heightData.minZ,maxZ:g.coordinatesByArea.heightData.maxZ,index:d,isFind:!1,inWall:!1})}}for(let d=0;d<a.length;d++){const g=a[d];for(let b=0;b<n.length;b++){if(n[b].length<.5)continue;let z=[];const v=ee(n[b].start,n[b].end,!0);z.push(v),z.push(ee(v,n[b].start,!0)),z.push(ee(v,n[b].end,!0));let S=!1;const V=g.boxPoints.length;for(let D=0;D<z.length;D++){const _=z[D].x,T=z[D].y;for(let E=0,A=V-1;E<V;A=E++){const F=g.boxPoints[E].x,I=g.boxPoints[E].y,B=g.boxPoints[A].x,L=g.boxPoints[A].y;I>T!=L>T&&_<(B-F)*(T-I)/(L-I)+F&&(S=!S)}if(S)break}if(S){let D=new y.Vector3(n[b].start.x,n[b].start.y,0),_=new y.Vector3(n[b].end.x,n[b].end.y,0),T=g.doorStartPt.distanceTo(g.doorEndPt),E=D.distanceTo(_),A=Jt(g.doorStartPt,g.doorEndPt,D,_);if(Math.abs(E-T)<.5&&A&&A.angleDeg<15){g.doorStartPt=new y.Vector3(n[b].start.x,n[b].start.y,0),g.doorEndPt=new y.Vector3(n[b].end.x,n[b].end.y,0);break}else if(Math.abs(E-T)>1.3&&A&&A.angleDeg<15){let F=ne(g.doorStartPt,g.doorEndPt,D,_,{parallelAngleMax:y.MathUtils.degToRad(15)}),I=g.doorStartPt.distanceTo(D),B=g.doorStartPt.distanceTo(_),L=g.doorEndPt.distanceTo(D),W=g.doorEndPt.distanceTo(_),C=I<.2||B<.2||L<.2||W<.2;if(F&&F.type=="collinear_overlap"&&F.maxPerpendicularDistance<.1&&!C){g.inWall=!0;break}else{let R=new y.Line3(D,_),H=R.closestPointToPoint(g.doorStartPt,!0,new y.Vector3),X=R.closestPointToPoint(g.doorEndPt,!0,new y.Vector3),ot=H.distanceTo(g.doorStartPt),K=X.distanceTo(g.doorEndPt);if(ot<.1||K<.1){g.inWall=!0;break}}}}else continue}}let l=0,c=[],h=[],f=[];const u=[];let p=.15;for(let d=0;d<n.length;d++){const g=n[d];if(g.noDetection||(g.doorAndBeamData=[],!g.mergeCheckRegion||g.mergeCheckRegion.length==0))continue;g.completePointAreaPercentage=-1;let b=new y.Box3;b.setFromPoints(g.originalPoints);let z=b.max.z;b.min.z;const v=new y.Vector3(g.start.x,g.start.y,g.start.z),S=new y.Vector3(g.end.x,g.end.y,g.end.z);let V=g.rooftopPz-g.start.z,D=0;for(const T of g.mergeCheckRegion){const{facePoints:E,boxArea:A,totalInPlaneNum:F}=oo(T.points,T.gridWidth,T.gridHeight,T.centerPts);if(!E||E.length<=0)continue;E[0].distanceTo(E[1]);let I=E[0].distanceTo(E[3]);const B=T.gridHeight*(I/T.gridHeight/3*2)+T.gridHeight/2;let L=new y.Vector3(E[0].x,E[0].y,E[0].z+B),W=new y.Vector3(E[1].x,E[1].y,E[1].z+B);const C=new y.Line3(L,W),R=[];let H=new y.Vector3;T.points.forEach(rt=>{C.closestPointToPoint(rt,!0,H).distanceTo(rt)<T.gridHeight+.01&&R.push(rt)});let X=[],ot=[];for(;;){let rt=[];for(let O=0;O<R.length;O++)ot.includes(O)||rt.length==0&&(rt.push(R[O]),ot.push(O));for(let O=0;O<R.length;O++)if(!ot.includes(O)){for(let Y=0;Y<rt.length;Y++)if(R[O].distanceTo(rt[Y])<T.gridWidth+.01){rt.push(R[O]),ot.push(O),O=-1;break}}if(rt.length==0)break;X.push(rt)}const K=[];for(let rt=0;rt<X.length;rt++){const O={lineSt:new y.Vector3,lineEd:new y.Vector3,facePoints:[]};let Y=Se(X[rt]);Array.isArray(Y)&&Y.length==2&&(O.lineSt=Y[0],O.lineEd=Y[1],O.facePoints.push(new y.Vector3(Y[0].x,Y[0].y,E[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,E[0].z)),O.facePoints.push(new y.Vector3(Y[1].x,Y[1].y,E[2].z)),O.facePoints.push(new y.Vector3(Y[0].x,Y[0].y,E[2].z)),K.push(O))}D+=T.area;let G=0;if(F!=0&&(G=T.gridHeight*T.gridWidth*F),(T.area-G)/A*100>70&&K.length==1||K.length>1)for(let rt=0;rt<K.length;rt++){const O=K[rt];let Y=O.facePoints[0].distanceTo(O.facePoints[1]),Vt=O.facePoints[0].distanceTo(O.facePoints[3]),Zt=Y/g.length*100,Nt=g.rooftopPz-O.facePoints[2].z;if(Vt<1.5||z<O.facePoints[2].z||Nt>V/3*2)continue;let Rt=!1,_t=!1,Tt=!1,Ot=[],tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone(),q=O.facePoints[0].clone(),j=O.facePoints[1].clone(),Wt=!1,Et=-1;if(Math.abs(O.facePoints[0].z-g.start.z)<.25){if(Y>.17&&g.length>.5){let qt=Lt(v,q),J=Lt(v,j),ut=Lt(S,q),N=Lt(S,j);const Pt=.1,zt=10;if(qt<Pt||J<Pt){const{newOriginalPoints:Ut}=Ve(q,j,g.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=q.z}),at.length>10){const Q=new y.Vector3(g.start.x,g.start.y,0),pt=new y.Vector3(g.end.x,g.end.y,0),Mt=new y.Vector3().subVectors(Q,pt).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==d)continue;const it=new y.Vector3(n[U].start.x,n[U].start.y,0),mt=new y.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85){let At=Ct.point.distanceTo(Q);if(Ct.point.distanceTo(pt),At<.3){dt=!0,ft=1/0,Z=-1;break}}continue}if(St&&St.angle>85){const $=new y.Line3(it,mt).closestPointToPoint(Q,!0,Gt);let yt=Jt(Q,pt,$,Q);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt,zt),st=pt.clone().addScaledVector(Mt.clone().negate(),zt);let wt=new y.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=Q.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new y.Vector3(q.x,q.y,0),$=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt($,it),wt=Lt($,mt),vt=Jt(Q,pt,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let Ht=Se(Xt);if(Ht.length==2){let Kt=Lt(At,Ht[0]),Ce=Lt(At,Ht[1]),Le=Lt($,Ht[0]),Re=Lt($,Ht[1]);if(Kt<.2||Ce<.2||Le<.2||Re<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(g.length-Y>.2||g.length-Y<.02)&&ft<Y*3)n[Z].length>.25&&Y+ft>.5&&(Wt=!0,qt<Pt?(ct=ct.addScaledVector(Mt,ft),q=q.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&g.length-Y>.1)continue;if(!k&&!dt&&g.length-Y<.1&&g.length<1.8)continue}}else continue}if(ut<Pt||N<Pt){const{newOriginalPoints:Ut}=Ve(q,j,g.originalPoints),at=[];if(Ut.forEach(Q=>{Q.z>=tt.z?at.push(Q):Q.z<=q.z}),at.length>10){const Q=new y.Vector3(g.start.x,g.start.y,0),pt=new y.Vector3(g.end.x,g.end.y,0),Mt=new y.Vector3().subVectors(pt,Q).normalize();let Gt=new y.Vector3,ft=1/0,Z=-1,k=!1,dt=!1;for(let U=0;U<n.length;U++){if(U==d)continue;const it=new y.Vector3(n[U].start.x,n[U].start.y,0),mt=new y.Vector3(n[U].end.x,n[U].end.y,0),Ct=te(Q,pt,it,mt);let St=re(Q,pt,it,mt);if(Ct!=null){if(St&&St.angle>85&&(Ct.point.distanceTo(Q),Ct.point.distanceTo(pt)<.3)){dt=!0,ft=1/0,Z=-1;break}continue}if(St&&St.angle>85){const $=new y.Line3(it,mt).closestPointToPoint(pt,!0,Gt);let yt=Jt(pt,Q,$,pt);if(!yt||yt.direction!="same")continue;const et=Q.clone().addScaledVector(Mt.clone().negate(),zt),st=pt.clone().addScaledVector(Mt,zt);let wt=new y.Vector3().subVectors(mt,it).normalize(),vt=it.clone().addScaledVector(wt.clone().negate(),.03),Bt=mt.clone().addScaledVector(wt,.03);const bt=te(et,st,vt,Bt);if(bt==null)continue;let Xt=pt.distanceTo(bt.point);Xt<ft&&(ft=Xt,Z=U)}else if(St&&St.angle<5){const At=new y.Vector3(q.x,q.y,0),$=new y.Vector3(j.x,j.y,0);let yt=Lt(At,it),et=Lt(At,mt),st=Lt($,it),wt=Lt($,mt),vt=Jt(pt,Q,it,At),Bt=!1;for(let bt=0;bt<n[U].checkResults.length;bt++){let Xt=[];for(let Kt=0;Kt<n[U].checkResults[bt].allCenterPoints.length;Kt++)Xt.push(new y.Vector3(n[U].checkResults[bt].allCenterPoints[Kt].x,n[U].checkResults[bt].allCenterPoints[Kt].y,0));let Ht=Se(Xt);if(Ht.length==2){let Kt=Lt(At,Ht[0]),Ce=Lt(At,Ht[1]),Le=Lt($,Ht[0]),Re=Lt($,Ht[1]);if(Kt<.2||Ce<.2||Le<.2||Re<.2){Bt=!0;break}}}if(vt&&vt.direction=="same"&&!Bt&&(yt<.1||et<.1||st<.1||wt<.1)){k=!0,ft=1/0,Z=-1;break}}}if(ft!=1/0&&ft<2&&(g.length-Y>.2||g.length-Y<.02)&&ft<Y*3)n[Z].length>.25&&Y+ft>.5&&(Wt=!0,ut<Pt?(ct=ct.addScaledVector(Mt,ft),q=q.addScaledVector(Mt,ft)):(tt=tt.addScaledVector(Mt,ft),j=j.addScaledVector(Mt,ft)));else{if(!k&&!dt&&g.length-Y>.1)continue;if(!k&&!dt&&g.length-Y<.1&&g.length<1.8)continue}}else continue}Y=ct.distanceTo(tt)}if(Zt<85&&Y>.3||Y>.7&&Vt>V-V/3){let qt=!1;for(let J=0;J<t.length;J++){let ut=J+1;if(ut>=t.length)continue;let N=new y.Vector3(t[J].x,t[J].y,t[J].z),Pt=new y.Vector3(t[ut].x,t[ut].y,t[ut].z);if(te(new y.Vector3(N.x,N.y,0),new y.Vector3(Pt.x,Pt.y,0),new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),.1)!=null){qt=!0;break}}for(let J=0;J<a.length;J++){let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),N=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),zt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Ut=O.facePoints[2].z<a[J].maxZ||Math.abs(O.facePoints[2].z-a[J].maxZ)<.3;if(Math.abs(O.facePoints[2].z-a[J].maxZ)>.2,Ut){let at=ne(ut.clone(),N.clone(),Pt.clone(),zt.clone(),{distanceThreshold:2});if(at&&at.type=="collinear_gap"){let Q=ee(ut,N),pt=new y.Line3(new y.Vector3(g.start.x,g.start.y,0),new y.Vector3(g.end.x,g.end.y,0)),Mt=new y.Vector3,Gt=pt.closestPointToPoint(Q,!0,Mt);if(Q.distanceTo(Gt)<.15){let Z=Pt.distanceTo(ut),k=zt.distanceTo(ut);if(Z>.25&&k>.25){let it=Pt.distanceTo(N),mt=zt.distanceTo(N);if(it>.2&&mt>.2)continue}_t=!0,Tt=!0,Ot.push(a[J].index),a[J].isFind=!0,Et=J,e[a[J].index].isFindBeam=!0;let dt=new y.Vector3().subVectors(Pt,zt).normalize(),U=ut.distanceTo(N)-at.overlap;k<Z&&dt.negate(),Z>k?(tt=O.facePoints[2].clone().addScaledVector(dt,U),ct=O.facePoints[3].clone(),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z):(tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(dt,U),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z)}}else if(at&&at.type=="collinear_overlap"&&at.maxPerpendicularDistance<.35){let Q=Pt.distanceTo(zt),pt=N.distanceTo(ut);if(Math.abs(Q-at.overlap)<.25||Math.abs(pt-at.overlap)<.25){if(pt>Q&&Math.abs(pt-at.overlap)>1){let Mt=Pt.distanceTo(ut),Gt=Pt.distanceTo(N),ft=zt.distanceTo(ut),Z=zt.distanceTo(N),k=Mt<Gt?Mt:Gt,dt=ft<Z?ft:Z,U=new y.Vector3().subVectors(Pt,zt).normalize(),it=pt-at.overlap;k<dt?(U.negate(),tt=O.facePoints[2].clone().addScaledVector(U,it),ct=O.facePoints[3].clone(),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z):(tt=O.facePoints[2].clone(),ct=O.facePoints[3].clone().addScaledVector(U,it),q=ct.clone(),j=tt.clone(),q.z=j.z=O.facePoints[0].z)}_t=!0,Tt=!0,Ot.push(a[J].index),a[J].isFind=!0,e[a[J].index].isFindBeam=!0,Et=J}}}}if(!Tt&&Y<1.5)for(let J=0;J<a.length;J++){if(a[J].inWall)continue;let ut=new y.Vector3(a[J].doorStartPt.x,a[J].doorStartPt.y,0),N=new y.Vector3(a[J].doorEndPt.x,a[J].doorEndPt.y,0),Pt=new y.Vector3(O.facePoints[0].x,O.facePoints[0].y,0),zt=new y.Vector3(O.facePoints[1].x,O.facePoints[1].y,0),Ut=new y.Vector3().subVectors(ut,N).normalize(),at=new y.Vector3().subVectors(Pt,zt).normalize(),Q=.25,pt=ut.clone().addScaledVector(Ut,Q),Mt=N.clone().addScaledVector(Ut.clone().negate(),Q),Gt=Pt.clone().addScaledVector(at,Q),ft=zt.clone().addScaledVector(at.clone().negate(),Q),Z=te(pt,Mt,Gt,ft),k=!0,dt=ut.distanceTo(Pt),U=ut.distanceTo(zt),it=N.distanceTo(Pt),mt=N.distanceTo(zt);(dt<p||U<p||it<p||mt<p||Z)&&k&&(e[a[J].index].isFindBeam=!0,_t=!0,a[J].isFind=!0,Et=J)}(_t||qt||Math.abs(Vt-V)>.1&&Vt>V/2&&Y>.3)&&(Rt=!0)}}if(Rt){let qt=!1;for(let Z=0;Z<f.length;Z++){let k=ne(f[Z].start,f[Z].end,q,j);if(k&&k.type=="collinear_overlap"&&k.maxPerpendicularDistance<.01){qt=!0;break}}if(qt){Et!=-1&&(e[a[Et].index].isFindBeam=!1,a[Et].isFind=!1);continue}f.push({start:q,end:j});{new y.PointsMaterial({color:65535,size:.01});let Z=new y.Vector3().subVectors(q,j),k=new y.Vector3().subVectors(j,q),dt=1/0,U=1/0,it=q.clone(),mt=j.clone();const Ct=[],St=[];let At=new y.Line3(tt,ct),$=new y.Vector3,yt=999999;if(g.originalPoints.forEach(et=>{if(et.z-q.z<Vt/2+.1&&et.z-q.z>Vt/2-.1&&Ct.push(et),et.z>tt.z){let st=At.closestPointToPoint(et,!0,$),wt=new y.Vector3().subVectors(st,tt),vt=new y.Vector3().subVectors(st,ct),Bt=oe(Z,vt),bt=oe(k,wt);Bt&&Bt.parallel&&!Bt.sameDirection&&bt&&bt.parallel&&!bt.sameDirection&&St.push(et)}}),Ct.length>0){const{newProjectPoints:et}=Ve(q,j,Ct);for(const st of et)st.z=q.z;et.forEach(st=>{let wt=new y.Vector3(st.x,st.y,q.z),vt=new y.Vector3().subVectors(wt,j),Bt=new y.Vector3().subVectors(wt,q),bt=oe(Z,Bt),Xt=oe(k,vt);if(bt&&bt.parallel&&bt.sameDirection){let Ht=wt.distanceTo(q);Ht<dt&&(dt=Ht,it=wt)}else if(Xt&&Xt.parallel&&Xt.sameDirection){let Ht=wt.distanceTo(j);Ht<U&&(U=Ht,mt=wt)}})}if(it.equals(q)||(q=it,ct=new y.Vector3(q.x,q.y,ct.z)),mt.equals(j)||(j=mt,tt=new y.Vector3(j.x,j.y,tt.z)),St.length>10){const{newOnLinePoints:et}=Ve(ct,tt,St);for(let st=0;st<et.length;st++){let vt=At.closestPointToPoint(et[st],!0,$).distanceTo(et[st]);vt>.02&&yt>vt&&(yt=vt)}tt.z+=yt,ct.z+=yt,Vt+=yt}}let J=j.distanceTo(q);if(J<.4&&!_t||J<.3&&_t)continue;h.includes(d)||h.push(d),g.checkResults[T.index].isDoor=!0;let ut="",N={id:l,beamStart:tt,beamEnd:ct,beamHeight:g.rooftopPz-tt.z,doorStart:q,doorEnd:j,doorHeight:Vt,nearId:-1,type:ut,isExtend:Wt,isDoor:_t,isPullOutDoor:Tt,pcbDoorIndexs:Ot,beamNearWallVec:new y.Vector3(0,0,0)},Pt=!1,zt=new y.Vector3,Ut=new y.Vector3,at=-1,Q=-1,pt=-1;for(let Z=0;Z<c.length;Z++){const k=n[c[Z].linesIndex].doorAndBeamData[c[Z].doorIndex];if(k.nearId!=-1)continue;let dt=Jt(tt.clone(),ct.clone(),k.beamStart.clone(),k.beamEnd.clone());if(dt&&dt.isParallel){let U=tt.distanceTo(ct),it=k.beamStart.distanceTo(k.beamEnd),mt=new y.Line3(tt.clone(),ct.clone());mt.start.z=0,mt.end.z=0;let Ct=ee(k.beamStart,k.beamEnd,!0);it>U&&(mt.start=new y.Vector3(k.beamStart.x,k.beamStart.y,0),mt.end=new y.Vector3(k.beamEnd.x,k.beamEnd.y,0),Ct=ee(tt,ct,!0));let St=new y.Vector3,At=mt.closestPointToPoint(Ct,!0,St),$=At.distanceTo(Ct),yt=new y.Vector3().subVectors(Ct,At).normalize(),et=yt.clone().negate(),st=Ct.clone().addScaledVector(et,$+.1),wt=te(mt.start,mt.end,Ct,st),vt=!_t&&!k.isDoor&&(U>it*2||it>U*2);if($<.4&&wt!=null&&!vt){k.nearId=l,N.nearId=k.id;let Bt=.8;(k.isDoor||N.isDoor)&&(k.isDoor=!0,N.isDoor=!0);const bt=Ot.some(Xt=>k.pcbDoorIndexs.includes(Xt));U<it?U>Bt&&!k.isPullOutDoor?(k.beamStart=tt.clone().addScaledVector(et,$),k.beamEnd=ct.clone().addScaledVector(et,$),k.doorStart=q.clone().addScaledVector(et,$),k.doorEnd=j.clone().addScaledVector(et,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):!Tt||Tt&&k.isPullOutDoor&&bt?(N.beamStart=k.beamStart.clone().addScaledVector(yt,$),N.beamEnd=k.beamEnd.clone().addScaledVector(yt,$),N.doorStart=k.doorStart.clone().addScaledVector(yt,$),N.doorEnd=k.doorEnd.clone().addScaledVector(yt,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):(k.beamStart=tt.clone().addScaledVector(et,$),k.beamEnd=ct.clone().addScaledVector(et,$),k.doorStart=q.clone().addScaledVector(et,$),k.doorEnd=j.clone().addScaledVector(et,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):U>it&&(it>Bt&&!Tt?(N.beamStart=k.beamStart.clone().addScaledVector(et,$),N.beamEnd=k.beamEnd.clone().addScaledVector(et,$),N.doorStart=k.doorStart.clone().addScaledVector(et,$),N.doorEnd=k.doorEnd.clone().addScaledVector(et,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight):!k.isPullOutDoor||Tt&&k.isPullOutDoor&&bt?(k.beamStart=tt.clone().addScaledVector(yt,$),k.beamEnd=ct.clone().addScaledVector(yt,$),k.doorStart=q.clone().addScaledVector(yt,$),k.doorEnd=j.clone().addScaledVector(yt,$),k.doorHeight=N.doorHeight,k.beamStart.z=k.beamEnd.z=k.doorStart.z+k.doorHeight):(N.beamStart=k.beamStart.clone().addScaledVector(et,$),N.beamEnd=k.beamEnd.clone().addScaledVector(et,$),N.doorStart=k.doorStart.clone().addScaledVector(et,$),N.doorEnd=k.doorEnd.clone().addScaledVector(et,$),N.doorHeight=k.doorHeight,N.beamStart.z=N.beamEnd.z=N.doorStart.z+N.doorHeight)),at=N.nearId,zt=k.beamStart.clone(),Ut=k.beamEnd.clone(),Pt=!0,Q=c[Z].linesIndex,pt=c[Z].doorIndex;break}}}let Mt=!1;if(!Pt){let Z=new y.Line3(q.clone(),j.clone());for(let k=0;k<n.length;k++){if(n[k].length<.5||k==d)continue;let dt=new y.Vector3(n[k].start.x,n[k].start.y,n[k].start.z),U=new y.Vector3(n[k].end.x,n[k].end.y,n[k].end.z),it=ne(dt,U,q,j),mt=Jt(dt,U,q,j);const Ct=io(n[k]);if(it&&it.maxPerpendicularDistance<.5){if(mt&&mt.isParallel){let st=new y.Line3(dt,U),wt=new y.Vector3(q.x,q.y,dt.z),vt=st.closestPointToPoint(wt,!0,new y.Vector3),Bt=re(vt,wt,q,j);Bt&&Bt.angle>85&&(N.beamNearWallVec=new y.Vector3().subVectors(vt,wt).normalize())}const St=[];n[k].originalPoints.forEach(st=>{st.z>q.z+.2&&st.z<q.z+Vt/2&&St.push(new y.Vector3(st.x,st.y,q.z))});const At=new y.Vector3;let $=[],yt=[];for(let st=0;st<St.length;st++){let wt=Z.closestPointToPoint(St[st],!0,At);wt.distanceTo(St[st])<.15&&($.push(St[st]),yt.push(wt.clone()))}for(let st=0;st<yt.length;st++)ao(Z,yt[st])&&$.push(yt[st]);if($=yt,$=co($),$.length<150)continue;let et=Se($);if(et.length==2){let st=et[0].distanceTo(et[1]);if(Math.abs(st-Z.distance())<.3){let wt=new y.Line3(dt,U),vt=new y.Vector3(q.x,q.y,dt.z),Bt=wt.closestPointToPoint(vt,!0,new y.Vector3);if(N.beamNearWallVec=new y.Vector3().subVectors(Bt,vt).normalize(),N.beamStart.z>Ct.maxZ-.03&&Y>1)Mt=!0;else if(qt=!0,Et!=-1&&(e[a[Et].index].isFindBeam=!1,a[Et].isFind=!1),Q!=-1&&pt!=-1){const bt=n[Q].doorAndBeamData[pt];bt.nearId=-1}break}}if(qt)break}else it&&it.type=="collinear_overlap"&&it.maxPerpendicularDistance>.3&&it.maxPerpendicularDistance<.7&&(Mt=!0)}if(qt){if(Y<1.8)continue;Mt=!0}}let Gt=!1;if(at!=-1)for(let Z=0;Z<u.length&&!(u[Z].length==1&&(u[Z][0].id==l?(u[Z].push({id:at,beamStart:zt,beamEnd:Ut}),Gt=!0):u[Z][0].id==at&&(u[Z].push({id:l,beamStart:tt,beamEnd:ct}),Gt=!0),Gt));Z++);Gt||u.push([{id:l,beamStart:tt,beamEnd:ct}]);const ft=N.doorStart.distanceTo(N.doorEnd);if(_t?ut="door":ft>1.8?ut="beam":ut=Mt&&ft>1?"beam":"hole",N.type=ut,N.nearId!=-1&&ut=="hole"){let Z=!1;for(let k=0;k<n.length;k++)if(n[k].doorAndBeamData){for(let dt=0;dt<n[k].doorAndBeamData.length;dt++)if(n[k].doorAndBeamData[dt].nearId==l&&n[k].doorAndBeamData[dt].type=="beam"){n[k].doorAndBeamData[dt].type=ut,Z=!0;break}if(Z)break}}if(g.doorAndBeamData.push(N),c.push({linesIndex:d,doorIndex:g.doorAndBeamData.length-1}),l++,Tt&&Y<2)break}}}let _=g.length*(g.rooftopPz-g.start.z);g.completePointAreaPercentage=D/_*100}if(h.length>1)for(let d=0;d<h.length;d++){let g=[];for(let b=0;b<n[h[d]].doorAndBeamData.length;b++){let z=!1;if(n[h[d]].doorAndBeamData[b].type==="beam"&&n[h[d]].doorAndBeamData[b].beamNearWallVec.x==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.y==0&&n[h[d]].doorAndBeamData[b].beamNearWallVec.z==0&&n[h[d]].doorAndBeamData[b].nearId==-1&&(z=!0),!z){let v=n[h[d]].doorAndBeamData[b].doorStart.clone(),S=n[h[d]].doorAndBeamData[b].doorEnd.clone();v.z=S.z=0;let V=v.distanceTo(S);for(let D=0;D<h.length;D++)if(d!=D)for(let _=0;_<n[h[D]].doorAndBeamData.length;_++){let T=n[h[D]].doorAndBeamData[_].doorStart.clone(),E=n[h[D]].doorAndBeamData[_].doorEnd.clone();T.z=E.z=0,T.distanceTo(E);let A=ne(v,S,T,E);if(A.type=="collinear_overlap"&&A.maxPerpendicularDistance<.2){let F=new y.Line3(T,E),I=ee(v,S),B=F.closestPointToPoint(I,!0,new y.Vector3),L=I.distanceTo(B);if(Math.abs(V-A.overlap)<.1&&L<.04){n[h[D]].doorAndBeamData[_].nearId==n[h[d]].doorAndBeamData[b].id&&(n[h[D]].doorAndBeamData[_].nearId=-1),z=!0;break}}}}z||g.push(n[h[d]].doorAndBeamData[b])}g.length!=n[h[d]].doorAndBeamData.length&&(n[h[d]].doorAndBeamData=g)}let w=.65,x=2,P=[],M=[];for(let d=0;d<a.length;d++){if(a[d].isFind||a[d].inWall)continue;let g=new y.Vector3(a[d].doorStartPt.x,a[d].doorStartPt.y,0),b=new y.Vector3(a[d].doorEndPt.x,a[d].doorEndPt.y,0),z=new y.Vector3().subVectors(g,b).normalize();for(let v=0;v<n.length;v++){if(n[v].length<.7||n[v].completePointAreaPercentage>60)continue;let S=new y.Vector3(n[v].start.x,n[v].start.y,0),V=new y.Vector3(n[v].end.x,n[v].end.y,0),D=new y.Vector3().subVectors(S,V).normalize(),_=.3,T=g.clone().addScaledVector(z,_),E=b.clone().addScaledVector(z.clone().negate(),_),A=S.clone().addScaledVector(D,_),F=V.clone().addScaledVector(D.clone().negate(),_);te(T,E,A,F);let I=Jt(T,E,A,F),B=g.distanceTo(S)>b.distanceTo(S)?b:g,L=B.distanceTo(S),W=B.distanceTo(V);if((L<p||W<p)&&I&&!I.isParallel){let R=g.distanceTo(S),H=g.distanceTo(V),X=R<H?S:V,ot=!1;for(let K=0;K<n.length;K++){if(K==v||P.includes(K)||n[K].length<.7)continue;let G=new y.Vector3(n[K].start.x,n[K].start.y,0),ht=new y.Vector3(n[K].end.x,n[K].end.y,0),rt=new y.Vector3().subVectors(G,ht).normalize(),O=rt.clone().negate(),Y=G.clone().addScaledVector(rt,5),Vt=ht.clone().addScaledVector(O,5),Zt=re(S,V,G,ht),Nt=ne(S,V,G,ht),Rt=te(S,V,Y,Vt),_t=!0;if(Rt!=null&&(_t=Rt.point.distanceTo(S)<p||Rt.point.distanceTo(V)<p),(Zt&&Zt.angle>85||Nt&&Nt.type=="collinear_gap")&&_t){let Tt=new y.Line3(S,V),Ot=new y.Vector3,tt=Tt.closestPointToPoint(G,!0,Ot),ct=Tt.closestPointToPoint(ht,!0,Ot),q=tt.distanceTo(G),j=ct.distanceTo(ht),Wt,Et;if(q>j&&j>w)Wt=ht,Et=ct;else if(q<j&&q>w)Wt=G,Et=tt;else continue;if(q=X.distanceTo(G),j=X.distanceTo(ht),q>x&&j>x)continue;let qt=Jt(Wt,Et,G,ht),J=Jt(Wt,Et,T,E);if(J&&J.isParallel||!qt||!qt.isParallel)continue;let ut=ne(g,b,Wt,Et);if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.2)continue;Wt.z=Et.z=n[K].start.z;let N=!1;for(let at=0;at<M.length;at++){let Q=ne(M[at].start,M[at].end,Wt,Et);if(Q&&Q.type=="collinear_overlap"&&Q.maxPerpendicularDistance<.2){N=!0;break}}if(N)continue;for(let at=0;at<n.length;at++){if(n[at].length<.5)continue;let Q=new y.Vector3(n[at].start.x,n[at].start.y,n[at].start.z),pt=new y.Vector3(n[at].end.x,n[at].end.y,n[at].end.z),Mt=ne(Q,pt,Wt,Et);if(Mt&&Mt.type=="collinear_overlap"&&Mt.maxPerpendicularDistance<.1){N=!0;break}}if(N)continue;M.push({start:Wt,end:Et}),P.push(K);let Pt=n[K].rooftopPz-n[K].start.z,zt=n[v].rooftopPz-n[v].start.z,Ut=Pt<zt?Pt:zt;n[K].doorAndBeamData||(n[K].doorAndBeamData=[]),n[K].doorAndBeamData.push({id:l,beamStart:Wt,beamEnd:Et,beamHeight:Ut,doorStart:Wt,doorEnd:Et,doorHeight:Ut,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new y.Vector3(0,0,0)}),e[a[d].index].isFindBeam=!0,e[a[d].index].isFindOnlyDoor=!0,u.push([{id:l,beamStart:Wt,beamEnd:Et}]),l++,ot=!0;break}}if(ot)break}}}let m=[];for(let d=0;d<n.length;d++)n[d].isLine2||m.push(n[d]),n[d].isLine2&&n[d].doorAndBeamData.length!=0&&m.push(n[d]);return n.length=0,n.push(...m),{lines:n,beamGroup:u}},zo=(n,t)=>{if(!n||n.length<=0)return;let e={rectangles:[],threeEdgeRect:[]},o=new Set,i=.2,r=1.5,s=.15,a=2;if(!n[0].uuid){let l=1e4;for(let c=0;c<n.length;c++)n[c].uuid=l++}for(let l=0;l<n.length;l++){let c=n[l].length;if(o.has(n[l].uuid)||c<i||c>r)continue;let h=[],f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),w=new y.Vector3().subVectors(u,f).normalize().clone().negate(),x=new y.Vector3,P=new y.Vector3,M=new y.Vector3;new y.Vector3;for(let m=0;m<n.length;m++){let d=n[m].length;if(m==l||d<i||d>r)continue;let g=new y.Vector3(n[m].start.x,n[m].start.y,n[m].start.z),b=new y.Vector3(n[m].end.x,n[m].end.y,n[m].end.z),z=re(f,u,g,b);if(!z||z.angle<85)continue;let v=kt(g,f),S=kt(g,u),V=kt(b,f),D=kt(b,u);if(!(!v&&!S&&!V&&!D)){v||S?(x=g.clone(),P=b.clone()):(x=b.clone(),P=g.clone()),M=new y.Vector3().subVectors(P,x).normalize(),M.clone().negate();for(let _=0;_<n.length;_++){let T=n[_].length;if(_==l||_==m||T<i||T>r)continue;let E=new y.Vector3(n[_].start.x,n[_].start.y,n[_].start.z),A=new y.Vector3(n[_].end.x,n[_].end.y,n[_].end.z),F=re(g,b,E,A);if(!F||F.angle<85)continue;let I=kt(E,P),B=kt(A,P);if(!I&&!B)continue;new y.Vector3;let L=new y.Vector3,W=new y.Vector3;I?(W=new y.Vector3().subVectors(A,E).normalize(),E.clone(),L=A.clone()):(W=new y.Vector3().subVectors(E,A).normalize(),A.clone(),L=E.clone());let C=oe(w,W,.1);if(!(!C||!C.parallel||!C.sameDirection)){for(let R=0;R<n.length;R++){let H=n[R].length;if(R==l||R==m||R==_||H<i||H>r)continue;let X=new y.Vector3(n[R].start.x,n[R].start.y,n[R].start.z),ot=new y.Vector3(n[R].end.x,n[R].end.y,n[R].end.z),K=re(X,ot,E,A);if(!K||K.angle<85)continue;let G=kt(X,L),ht=kt(ot,L);if(!G&&!ht)continue;new y.Vector3;let rt=new y.Vector3;G?(X.clone(),rt=ot.clone()):(ot.clone(),rt=X.clone());let O=kt(rt,f),Y=kt(rt,u);if(!O&&!Y)continue;let Vt=c*d;if(!(Vt<s||Vt>a)){h=[n[l].uuid,n[m].uuid,n[_].uuid,n[R].uuid];break}}if(h.length==4)break}}if(h.length==4)break}}h.length==4&&(h.forEach(m=>o.add(m)),e.rectangles.push(h))}for(let l=0;l<n.length;l++){let c=n[l].length;if(o.has(n[l].uuid)||c<i||c>r)continue;let h={indexs:[],missingEdge:{start:new y.Vector3,end:new y.Vector3}},f=new y.Vector3(n[l].start.x,n[l].start.y,n[l].start.z),u=new y.Vector3(n[l].end.x,n[l].end.y,n[l].end.z),p=!0,w=!0;for(let M=0;M<n.length;M++){if(M==l||n[M].length<i)continue;let m=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),d=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),g=kt(m,f),b=kt(d,f),z=kt(m,u),v=kt(d,u);if(g||b?p=!1:(z||v)&&(w=!1),!p&&!w)break}if(!p&&!w)continue;let x=new y.Vector3;p||([f,u]=[u,f]),x=new y.Vector3().subVectors(u,f).normalize();let P=x.clone().negate();for(let M=0;M<n.length;M++){let m=n[M].length;if(M==l||o.has(M)||m<i||m>r)continue;let d=new y.Vector3(n[M].start.x,n[M].start.y,n[M].start.z),g=new y.Vector3(n[M].end.x,n[M].end.y,n[M].end.z),b=re(f,u,d,g);if(!b||b.angle<85)continue;let z=kt(d,u),v=kt(g,u);if(!z&&!v)continue;new y.Vector3;let S=new y.Vector3;z?(d.clone(),S=g.clone()):(g.clone(),S=d.clone());for(let V=0;V<n.length;V++){let D=n[V].length;if(V==l||V==M||o.has(V)||D<i||D>r)continue;let _=new y.Vector3(n[V].start.x,n[V].start.y,n[V].start.z),T=new y.Vector3(n[V].end.x,n[V].end.y,n[V].end.z),E=re(d,g,_,T);if(!E||E.angle<85)continue;let A=kt(_,S),F=kt(T,S);if(!A&&!F)continue;let I=new y.Vector3,B=new y.Vector3;A?(I=_.clone(),B=T.clone()):(I=T.clone(),B=_.clone());let L=new y.Vector3().subVectors(B,I).normalize(),W=oe(P,L,.1);if(!W||!W.parallel||!W.sameDirection)continue;let C=!0,R=!0;for(let X=0;X<n.length;X++){if(X==V||n[X].length<i)continue;let ot=new y.Vector3(n[X].start.x,n[X].start.y,n[X].start.z),K=new y.Vector3(n[X].end.x,n[X].end.y,n[X].end.z),G=kt(ot,_),ht=kt(K,_),rt=kt(ot,T),O=kt(K,T);if(G||ht?C=!1:(rt||O)&&(R=!1),!C&&!R)break}if(!C&&!R)continue;let H=c*m;if(!(H<s||H>a)){h.indexs=[n[l].uuid,n[M].uuid,n[V].uuid],h.missingEdge.start=B,h.missingEdge.end=f;break}}if(h.indexs.length==3)break}h.indexs.length==3&&(h.indexs.forEach(M=>o.add(M)),e.threeEdgeRect.push(h))}return e},ae=11102230246251565e-32,$t=134217729,So=(3+8*ae)*ae;function Fe(n,t,e,o,i){let r,s,a,l,c=t[0],h=o[0],f=0,u=0;h>c==h>-c?(r=c,c=t[++f]):(r=h,h=o[++u]);let p=0;if(f<n&&u<e)for(h>c==h>-c?(s=c+r,a=r-(s-c),c=t[++f]):(s=h+r,a=r-(s-h),h=o[++u]),r=s,a!==0&&(i[p++]=a);f<n&&u<e;)h>c==h>-c?(s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f]):(s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u]),r=s,a!==0&&(i[p++]=a);for(;f<n;)s=r+c,l=s-r,a=r-(s-l)+(c-l),c=t[++f],r=s,a!==0&&(i[p++]=a);for(;u<e;)s=r+h,l=s-r,a=r-(s-l)+(h-l),h=o[++u],r=s,a!==0&&(i[p++]=a);return(r!==0||p===0)&&(i[p++]=r),p}function vo(n,t){let e=t[0];for(let o=1;o<n;o++)e+=t[o];return e}function ze(n){return new Float64Array(n)}const Do=(3+16*ae)*ae,_o=(2+12*ae)*ae,To=(9+64*ae)*ae*ae,me=ze(4),sn=ze(8),an=ze(12),ln=ze(16),jt=ze(4);function Eo(n,t,e,o,i,r,s){let a,l,c,h,f,u,p,w,x,P,M,m,d,g,b,z,v,S;const V=n-i,D=e-i,_=t-r,T=o-r;g=V*T,u=$t*V,p=u-(u-V),w=V-p,u=$t*T,x=u-(u-T),P=T-x,b=w*P-(g-p*x-w*x-p*P),z=_*D,u=$t*_,p=u-(u-_),w=_-p,u=$t*D,x=u-(u-D),P=D-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,me[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,me[1]=d-(M+f)+(f-z),S=m+M,f=S-m,me[2]=m-(S-f)+(M-f),me[3]=S;let E=vo(4,me),A=_o*s;if(E>=A||-E>=A||(f=n-V,a=n-(V+f)+(f-i),f=e-D,c=e-(D+f)+(f-i),f=t-_,l=t-(_+f)+(f-r),f=o-T,h=o-(T+f)+(f-r),a===0&&l===0&&c===0&&h===0)||(A=To*s+So*Math.abs(E),E+=V*h+T*a-(_*c+D*l),E>=A||-E>=A))return E;g=a*T,u=$t*a,p=u-(u-a),w=a-p,u=$t*T,x=u-(u-T),P=T-x,b=w*P-(g-p*x-w*x-p*P),z=l*D,u=$t*l,p=u-(u-l),w=l-p,u=$t*D,x=u-(u-D),P=D-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),jt[3]=S;const F=Fe(4,me,4,jt,sn);g=V*h,u=$t*V,p=u-(u-V),w=V-p,u=$t*h,x=u-(u-h),P=h-x,b=w*P-(g-p*x-w*x-p*P),z=_*c,u=$t*_,p=u-(u-_),w=_-p,u=$t*c,x=u-(u-c),P=c-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),jt[3]=S;const I=Fe(F,sn,4,jt,an);g=a*h,u=$t*a,p=u-(u-a),w=a-p,u=$t*h,x=u-(u-h),P=h-x,b=w*P-(g-p*x-w*x-p*P),z=l*c,u=$t*l,p=u-(u-l),w=l-p,u=$t*c,x=u-(u-c),P=c-x,v=w*P-(z-p*x-w*x-p*P),M=b-v,f=b-M,jt[0]=b-(M+f)+(f-v),m=g+M,f=m-g,d=g-(m-f)+(M-f),M=d-z,f=d-M,jt[1]=d-(M+f)+(f-z),S=m+M,f=S-m,jt[2]=m-(S-f)+(M-f),jt[3]=S;const B=Fe(I,an,4,jt,ln);return ln[B-1]}function ve(n,t,e,o,i,r){const s=(t-r)*(e-i),a=(n-i)*(o-r),l=s-a,c=Math.abs(s+a);return Math.abs(l)>=Do*c?l:-Eo(n,t,e,o,i,r,c)}const cn=Math.pow(2,-52),De=new Uint32Array(512);class Be{static from(t,e=Co,o=Lo){const i=t.length,r=new Float64Array(i*2);for(let s=0;s<i;s++){const a=t[s];r[2*s]=e(a),r[2*s+1]=o(a)}return new Be(r)}constructor(t){const e=t.length>>1;if(e>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const o=Math.max(2*e-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:o,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let a=1/0,l=1/0,c=-1/0,h=-1/0;for(let V=0;V<s;V++){const D=t[2*V],_=t[2*V+1];D<a&&(a=D),_<l&&(l=_),D>c&&(c=D),_>h&&(h=_),this._ids[V]=V}const f=(a+c)/2,u=(l+h)/2;let p=0,w=0,x=0;for(let V=0,D=1/0;V<s;V++){const _=We(f,u,t[2*V],t[2*V+1]);_<D&&(p=V,D=_)}const P=t[2*p],M=t[2*p+1];for(let V=0,D=1/0;V<s;V++){if(V===p)continue;const _=We(P,M,t[2*V],t[2*V+1]);_<D&&_>0&&(w=V,D=_)}let m=t[2*w],d=t[2*w+1],g=1/0;for(let V=0;V<s;V++){if(V===p||V===w)continue;const D=Io(P,M,m,d,t[2*V],t[2*V+1]);D<g&&(x=V,g=D)}let b=t[2*x],z=t[2*x+1];if(g===1/0){for(let _=0;_<s;_++)this._dists[_]=t[2*_]-t[0]||t[2*_+1]-t[1];ye(this._ids,this._dists,0,s-1);const V=new Uint32Array(s);let D=0;for(let _=0,T=-1/0;_<s;_++){const E=this._ids[_],A=this._dists[E];A>T&&(V[D++]=E,T=A)}this.hull=V.subarray(0,D),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(ve(P,M,m,d,b,z)<0){const V=w,D=m,_=d;w=x,m=b,d=z,x=V,b=D,z=_}const v=ko(P,M,m,d,b,z);this._cx=v.x,this._cy=v.y;for(let V=0;V<s;V++)this._dists[V]=We(t[2*V],t[2*V+1],v.x,v.y);ye(this._ids,this._dists,0,s-1),this._hullStart=p;let S=3;o[p]=e[x]=w,o[w]=e[p]=x,o[x]=e[w]=p,i[p]=0,i[w]=1,i[x]=2,r.fill(-1),r[this._hashKey(P,M)]=p,r[this._hashKey(m,d)]=w,r[this._hashKey(b,z)]=x,this.trianglesLen=0,this._addTriangle(p,w,x,-1,-1,-1);for(let V=0,D=0,_=0;V<this._ids.length;V++){const T=this._ids[V],E=t[2*T],A=t[2*T+1];if(V>0&&Math.abs(E-D)<=cn&&Math.abs(A-_)<=cn||(D=E,_=A,T===p||T===w||T===x))continue;let F=0;for(let C=0,R=this._hashKey(E,A);C<this._hashSize&&(F=r[(R+C)%this._hashSize],!(F!==-1&&F!==o[F]));C++);F=e[F];let I=F,B;for(;B=o[I],ve(E,A,t[2*I],t[2*I+1],t[2*B],t[2*B+1])>=0;)if(I=B,I===F){I=-1;break}if(I===-1)continue;let L=this._addTriangle(I,T,o[I],-1,-1,i[I]);i[T]=this._legalize(L+2),i[I]=L,S++;let W=o[I];for(;B=o[W],ve(E,A,t[2*W],t[2*W+1],t[2*B],t[2*B+1])<0;)L=this._addTriangle(W,T,B,i[T],-1,i[W]),i[T]=this._legalize(L+2),o[W]=W,S--,W=B;if(I===F)for(;B=e[I],ve(E,A,t[2*B],t[2*B+1],t[2*I],t[2*I+1])<0;)L=this._addTriangle(B,T,I,-1,i[I],i[B]),this._legalize(L+2),i[B]=L,o[I]=I,S--,I=B;this._hullStart=e[T]=I,o[I]=e[W]=T,o[T]=W,r[this._hashKey(E,A)]=T,r[this._hashKey(t[2*I],t[2*I+1])]=I}this.hull=new Uint32Array(S);for(let V=0,D=this._hullStart;V<S;V++)this.hull[V]=D,D=o[D];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(Ao(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:o,coords:i}=this;let r=0,s=0;for(;;){const a=o[t],l=t-t%3;if(s=l+(t+2)%3,a===-1){if(r===0)break;t=De[--r];continue}const c=a-a%3,h=l+(t+1)%3,f=c+(a+2)%3,u=e[s],p=e[t],w=e[h],x=e[f];if(Bo(i[2*u],i[2*u+1],i[2*p],i[2*p+1],i[2*w],i[2*w+1],i[2*x],i[2*x+1])){e[t]=x,e[a]=u;const M=o[f];if(M===-1){let d=this._hullStart;do{if(this._hullTri[d]===f){this._hullTri[d]=t;break}d=this._hullPrev[d]}while(d!==this._hullStart)}this._link(t,M),this._link(a,o[s]),this._link(s,f);const m=c+(a+1)%3;r<De.length&&(De[r++]=m)}else{if(r===0)break;t=De[--r]}}return s}_link(t,e){this._halfedges[t]=e,e!==-1&&(this._halfedges[e]=t)}_addTriangle(t,e,o,i,r,s){const a=this.trianglesLen;return this._triangles[a]=t,this._triangles[a+1]=e,this._triangles[a+2]=o,this._link(a,i),this._link(a+1,r),this._link(a+2,s),this.trianglesLen+=3,a}}function Ao(n,t){const e=n/(Math.abs(n)+Math.abs(t));return(t>0?3-e:1+e)/4}function We(n,t,e,o){const i=n-e,r=t-o;return i*i+r*r}function Bo(n,t,e,o,i,r,s,a){const l=n-s,c=t-a,h=e-s,f=o-a,u=i-s,p=r-a,w=l*l+c*c,x=h*h+f*f,P=u*u+p*p;return l*(f*P-x*p)-c*(h*P-x*u)+w*(h*p-f*u)<0}function Io(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,f=l*l+c*c,u=.5/(s*c-a*l),p=(c*h-a*f)*u,w=(s*f-l*h)*u;return p*p+w*w}function ko(n,t,e,o,i,r){const s=e-n,a=o-t,l=i-n,c=r-t,h=s*s+a*a,f=l*l+c*c,u=.5/(s*c-a*l),p=n+(c*h-a*f)*u,w=t+(s*f-l*h)*u;return{x:p,y:w}}function ye(n,t,e,o){if(o-e<=20)for(let i=e+1;i<=o;i++){const r=n[i],s=t[r];let a=i-1;for(;a>=e&&t[n[a]]>s;)n[a+1]=n[a--];n[a+1]=r}else{const i=e+o>>1;let r=e+1,s=o;Me(n,i,r),t[n[e]]>t[n[o]]&&Me(n,e,o),t[n[r]]>t[n[o]]&&Me(n,r,o),t[n[e]]>t[n[r]]&&Me(n,e,r);const a=n[r],l=t[a];for(;;){do r++;while(t[n[r]]<l);do s--;while(t[n[s]]>l);if(s<r)break;Me(n,r,s)}n[e+1]=n[s],n[s]=a,o-r+1>=s-e?(ye(n,t,r,o),ye(n,t,e,s-1)):(ye(n,t,e,s-1),ye(n,t,r,o))}}function Me(n,t,e){const o=n[t];n[t]=n[e],n[e]=o}function Co(n){return n[0]}function Lo(n){return n[1]}const un=1e-6;class de{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,o){t=+t,e=+e,o=+o;const i=t+o,r=e;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>un||Math.abs(this._y1-r)>un)&&(this._+="L"+i+","+r),o&&(this._+=`A${o},${o},0,1,1,${t-o},${e}A${o},${o},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,o,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+o}v${+i}h${-o}Z`}value(){return this._||null}}class $e{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class Ro{constructor(t,[e,o,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e))||!((r=+r)>=(o=+o)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:o},vectors:i}=this;let r,s;const a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let x=0,P=0,M=o.length,m,d;x<M;x+=3,P+=2){const g=o[x]*2,b=o[x+1]*2,z=o[x+2]*2,v=t[g],S=t[g+1],V=t[b],D=t[b+1],_=t[z],T=t[z+1],E=V-v,A=D-S,F=_-v,I=T-S,B=(E*I-A*F)*2;if(Math.abs(B)<1e-9){if(r===void 0){r=s=0;for(const W of e)r+=t[W*2],s+=t[W*2+1];r/=e.length,s/=e.length}const L=1e9*Math.sign((r-v)*I-(s-S)*F);m=(v+_)/2-L*I,d=(S+T)/2+L*F}else{const L=1/B,W=E*E+A*A,C=F*F+I*I;m=v+(I*W-A*C)*L,d=S+(E*C-F*W)*L}a[P]=m,a[P+1]=d}let l=e[e.length-1],c,h=l*4,f,u=t[2*l],p,w=t[2*l+1];i.fill(0);for(let x=0;x<e.length;++x)l=e[x],c=h,f=u,p=w,h=l*4,u=t[2*l],w=t[2*l+1],i[c+2]=i[h]=p-w,i[c+3]=i[h+1]=u-f}render(t){const e=t==null?t=new de:void 0,{delaunay:{halfedges:o,inedges:i,hull:r},circumcenters:s,vectors:a}=this;if(r.length<=1)return null;for(let h=0,f=o.length;h<f;++h){const u=o[h];if(u<h)continue;const p=Math.floor(h/3)*2,w=Math.floor(u/3)*2,x=s[p],P=s[p+1],M=s[w],m=s[w+1];this._renderSegment(x,P,M,m,t)}let l,c=r[r.length-1];for(let h=0;h<r.length;++h){l=c,c=r[h];const f=Math.floor(i[c]/3)*2,u=s[f],p=s[f+1],w=l*4,x=this._project(u,p,a[w+2],a[w+3]);x&&this._renderSegment(u,p,x[0],x[1],t)}return e&&e.value()}renderBounds(t){const e=t==null?t=new de:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const o=e==null?e=new de:void 0,i=this._clip(t);if(i===null||!i.length)return;e.moveTo(i[0],i[1]);let r=i.length;for(;i[0]===i[r-2]&&i[1]===i[r-1]&&r>1;)r-=2;for(let s=2;s<r;s+=2)(i[s]!==i[s-2]||i[s+1]!==i[s-1])&&e.lineTo(i[s],i[s+1]);return e.closePath(),o&&o.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,o=t.length/2;e<o;++e){const i=this.cellPolygon(e);i&&(i.index=e,yield i)}}cellPolygon(t){const e=new $e;return this.renderCell(t,e),e.value()}_renderSegment(t,e,o,i,r){let s;const a=this._regioncode(t,e),l=this._regioncode(o,i);a===0&&l===0?(r.moveTo(t,e),r.lineTo(o,i)):(s=this._clipSegment(t,e,o,i,a,l))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,o){return e=+e,e!==e||(o=+o,o!==o)?!1:this.delaunay._step(t,e,o)===t}*neighbors(t){const e=this._clip(t);if(e)for(const o of this.delaunay.neighbors(t)){const i=this._clip(o);if(i){t:for(let r=0,s=e.length;r<s;r+=2)for(let a=0,l=i.length;a<l;a+=2)if(e[r]===i[a]&&e[r+1]===i[a+1]&&e[(r+2)%s]===i[(a+l-2)%l]&&e[(r+3)%s]===i[(a+l-1)%l]){yield o;break t}}}}_cell(t){const{circumcenters:e,delaunay:{inedges:o,halfedges:i,triangles:r}}=this,s=o[t];if(s===-1)return null;const a=[];let l=s;do{const c=Math.floor(l/3);if(a.push(e[c*2],e[c*2+1]),l=l%3===2?l-2:l+1,r[l]!==t)break;l=i[l]}while(l!==s&&l!==-1);return a}_clip(t){if(t===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(e===null)return null;const{vectors:o}=this,i=t*4;return this._simplify(o[i]||o[i+1]?this._clipInfinite(t,e,o[i],o[i+1],o[i+2],o[i+3]):this._clipFinite(t,e))}_clipFinite(t,e){const o=e.length;let i=null,r,s,a=e[o-2],l=e[o-1],c,h=this._regioncode(a,l),f,u=0;for(let p=0;p<o;p+=2)if(r=a,s=l,a=e[p],l=e[p+1],c=h,h=this._regioncode(a,l),c===0&&h===0)f=u,u=0,i?i.push(a,l):i=[a,l];else{let w,x,P,M,m;if(c===0){if((w=this._clipSegment(r,s,a,l,c,h))===null)continue;[x,P,M,m]=w}else{if((w=this._clipSegment(a,l,r,s,h,c))===null)continue;[M,m,x,P]=w,f=u,u=this._edgecode(x,P),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(x,P):i=[x,P]}f=u,u=this._edgecode(M,m),f&&u&&this._edge(t,f,u,i,i.length),i?i.push(M,m):i=[M,m]}if(i)f=u,u=this._edgecode(i[0],i[1]),f&&u&&this._edge(t,f,u,i,i.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(t,e,o,i,r,s){const a=r<s;for(a&&([t,e,o,i,r,s]=[o,i,t,e,s,r]);;){if(r===0&&s===0)return a?[o,i,t,e]:[t,e,o,i];if(r&s)return null;let l,c,h=r||s;h&8?(l=t+(o-t)*(this.ymax-e)/(i-e),c=this.ymax):h&4?(l=t+(o-t)*(this.ymin-e)/(i-e),c=this.ymin):h&2?(c=e+(i-e)*(this.xmax-t)/(o-t),l=this.xmax):(c=e+(i-e)*(this.xmin-t)/(o-t),l=this.xmin),r?(t=l,e=c,r=this._regioncode(t,e)):(o=l,i=c,s=this._regioncode(o,i))}}_clipInfinite(t,e,o,i,r,s){let a=Array.from(e),l;if((l=this._project(a[0],a[1],o,i))&&a.unshift(l[0],l[1]),(l=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(l[0],l[1]),a=this._clipFinite(t,a))for(let c=0,h=a.length,f,u=this._edgecode(a[h-2],a[h-1]);c<h;c+=2)f=u,u=this._edgecode(a[c],a[c+1]),f&&u&&(c=this._edge(t,f,u,a,c),h=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,o,i,r){for(;e!==o;){let s,a;switch(e){case 5:e=4;continue;case 4:e=6,s=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,s=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,s=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,s=this.xmin,a=this.ymin;break}(i[r]!==s||i[r+1]!==a)&&this.contains(t,s,a)&&(i.splice(r,0,s,a),r+=2)}return r}_project(t,e,o,i){let r=1/0,s,a,l;if(i<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/i)<r&&(l=this.ymin,a=t+(r=s)*o)}else if(i>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/i)<r&&(l=this.ymax,a=t+(r=s)*o)}if(o>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/o)<r&&(a=this.xmax,l=e+(r=s)*i)}else if(o<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/o)<r&&(a=this.xmin,l=e+(r=s)*i)}return[a,l]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let e=0;e<t.length;e+=2){const o=(e+2)%t.length,i=(e+4)%t.length;(t[e]===t[o]&&t[o]===t[i]||t[e+1]===t[o+1]&&t[o+1]===t[i+1])&&(t.splice(o,2),e-=2)}t.length||(t=null)}return t}}const Oo=2*Math.PI,ge=Math.pow;function Fo(n){return n[0]}function Wo(n){return n[1]}function No(n){const{triangles:t,coords:e}=n;for(let o=0;o<t.length;o+=3){const i=2*t[o],r=2*t[o+1],s=2*t[o+2];if((e[s]-e[i])*(e[r+1]-e[i+1])-(e[r]-e[i])*(e[s+1]-e[i+1])>1e-10)return!1}return!0}function qo(n,t,e){return[n+Math.sin(n+t)*e,t+Math.cos(n-t)*e]}class Ue{static from(t,e=Fo,o=Wo,i){return new Ue("length"in t?Xo(t,e,o,i):Float64Array.from(Ho(t,e,o,i)))}constructor(t){this._delaunator=new Be(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&No(t)){this.collinear=Int32Array.from({length:e.length/2},(u,p)=>p).sort((u,p)=>e[2*u]-e[2*p]||e[2*u+1]-e[2*p+1]);const l=this.collinear[0],c=this.collinear[this.collinear.length-1],h=[e[2*l],e[2*l+1],e[2*c],e[2*c+1]],f=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let u=0,p=e.length/2;u<p;++u){const w=qo(e[2*u],e[2*u+1],f);e[2*u]=w[0],e[2*u+1]=w[1]}this._delaunator=new Be(e)}else delete this.collinear;const o=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let l=0,c=o.length;l<c;++l){const h=r[l%3===2?l-2:l+1];(o[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,c=i.length;l<c;++l)a[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new Ro(this,t)}*neighbors(t){const{inedges:e,hull:o,_hullIndex:i,halfedges:r,triangles:s,collinear:a}=this;if(a){const f=a.indexOf(t);f>0&&(yield a[f-1]),f<a.length-1&&(yield a[f+1]);return}const l=e[t];if(l===-1)return;let c=l,h=-1;do{if(yield h=s[c],c=c%3===2?c-2:c+1,s[c]!==t)return;if(c=r[c],c===-1){const f=o[(i[t]+1)%o.length];f!==h&&(yield f);return}}while(c!==l)}find(t,e,o=0){if(t=+t,t!==t||(e=+e,e!==e))return-1;const i=o;let r;for(;(r=this._step(o,t,e))>=0&&r!==o&&r!==i;)o=r;return r}_step(t,e,o){const{inedges:i,hull:r,_hullIndex:s,halfedges:a,triangles:l,points:c}=this;if(i[t]===-1||!c.length)return(t+1)%(c.length>>1);let h=t,f=ge(e-c[t*2],2)+ge(o-c[t*2+1],2);const u=i[t];let p=u;do{let w=l[p];const x=ge(e-c[w*2],2)+ge(o-c[w*2+1],2);if(x<f&&(f=x,h=w),p=p%3===2?p-2:p+1,l[p]!==t)break;if(p=a[p],p===-1){if(p=r[(s[t]+1)%r.length],p!==w&&ge(e-c[p*2],2)+ge(o-c[p*2+1],2)<f)return p;break}}while(p!==u);return h}render(t){const e=t==null?t=new de:void 0,{points:o,halfedges:i,triangles:r}=this;for(let s=0,a=i.length;s<a;++s){const l=i[s];if(l<s)continue;const c=r[s]*2,h=r[l]*2;t.moveTo(o[c],o[c+1]),t.lineTo(o[h],o[h+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){e===void 0&&(!t||typeof t.moveTo!="function")&&(e=t,t=null),e=e==null?2:+e;const o=t==null?t=new de:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const a=i[r],l=i[r+1];t.moveTo(a+e,l),t.arc(a,l,e,0,Oo)}return o&&o.value()}renderHull(t){const e=t==null?t=new de:void 0,{hull:o,points:i}=this,r=o[0]*2,s=o.length;t.moveTo(i[r],i[r+1]);for(let a=1;a<s;++a){const l=2*o[a];t.lineTo(i[l],i[l+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new $e;return this.renderHull(t),t.value()}renderTriangle(t,e){const o=e==null?e=new de:void 0,{points:i,triangles:r}=this,s=r[t*=3]*2,a=r[t+1]*2,l=r[t+2]*2;return e.moveTo(i[s],i[s+1]),e.lineTo(i[a],i[a+1]),e.lineTo(i[l],i[l+1]),e.closePath(),o&&o.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,o=t.length/3;e<o;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new $e;return this.renderTriangle(t,e),e.value()}}function Xo(n,t,e,o){const i=n.length,r=new Float64Array(i*2);for(let s=0;s<i;++s){const a=n[s];r[s*2]=t.call(o,a,s,n),r[s*2+1]=e.call(o,a,s,n)}return r}function*Ho(n,t,e,o){let i=0;for(const r of n)yield t.call(o,r,i,n),yield e.call(o,r,i,n),++i}function Yo(n,t,e,o){return 1+(n[t][0]===0||n[e][0]===0||n[o][0]===0?1:0)}function $o(n,t,e,o,i,r){const s=Math.hypot(e-i,o-r),a=Math.hypot(n-i,t-r),l=Math.hypot(n-e,t-o),c=Math.abs((e-n)*(r-t)-(i-n)*(o-t))/2;return c===0?1/0:s*a*l/(4*c)}function Ge(n){if(!n||n.length<3)return[];const t=new Set,e=[];for(const w of n){const x=`${w[0]}_${w[1]}`;t.has(x)||(t.add(x),e.push(w))}if(e.length<3)return[];const o=new Ue(Float64Array.from(e.flat())),{triangles:i}=o;if(!i.length)return[];const r=new Map,s=(w,x)=>w<x?`${w}_${x}`:`${x}_${w}`;for(let w=0;w<i.length;w+=3){const x=i[w],P=i[w+1],M=i[w+2],[m,d]=e[x],[g,b]=e[P],[z,v]=e[M],S=$o(m,d,g,b,z,v),V=Yo(e,x,P,M);if(S<=1/V)for(const[D,_]of[[x,P],[P,M],[M,x]]){const T=s(D,_);r.set(T,(r.get(T)||0)+1)}}const a=[];for(const[w,x]of r)x===1&&a.push(w.split("_").map(Number));if(!a.length)return[];const l=new Map;for(const[w,x]of a)(l.get(w)||l.set(w,[]).get(w)).push(x),(l.get(x)||l.set(x,[]).get(x)).push(w);const c=a[0][0],h=[],f=new Set;let u=c,p=-1;do{h.push(e[u]),f.add(u);const w=l.get(u)||[];let x=w.find(P=>P!==p&&!f.has(P));if(x===void 0&&(x=w.find(P=>P!==p)),x===void 0)break;p=u,u=x}while(u!==c&&h.length<=a.length+1);return h}const gt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},xt={c:null,u:[new lt.Vector3,new lt.Vector3,new lt.Vector3],e:[]},It=[[],[],[]],nt=[[],[],[]],Dt=[],ce=new lt.Vector3,ue=new lt.Vector3,he=new lt.Vector3,Ft=new lt.Vector3,hn=new lt.Vector3,fn=new lt.Vector3,Qt=new lt.Matrix3,dn=new lt.Box3,_e=new lt.Matrix4,mn=new lt.Matrix4,gn=new lt.Ray;let En=class{constructor(t=new lt.Vector3,e=new lt.Vector3,o=new lt.Matrix3){this.center=t,this.halfSize=e,this.rotation=o}set(t,e,o){return this.center=t,this.halfSize=e,this.rotation=o,this}copy(t){return this.center.copy(t.center),this.halfSize.copy(t.halfSize),this.rotation.copy(t.rotation),this}clone(){return new this.constructor().copy(this)}getSize(t){return t.copy(this.halfSize).multiplyScalar(2)}clampPoint(t,e){const o=this.halfSize;Ft.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),e.copy(this.center);const i=lt.MathUtils.clamp(Ft.dot(ce),-o.x,o.x);e.add(ce.multiplyScalar(i));const r=lt.MathUtils.clamp(Ft.dot(ue),-o.y,o.y);e.add(ue.multiplyScalar(r));const s=lt.MathUtils.clamp(Ft.dot(he),-o.z,o.z);return e.add(he.multiplyScalar(s)),e}containsPoint(t){return Ft.subVectors(t,this.center),this.rotation.extractBasis(ce,ue,he),Math.abs(Ft.dot(ce))<=this.halfSize.x&&Math.abs(Ft.dot(ue))<=this.halfSize.y&&Math.abs(Ft.dot(he))<=this.halfSize.z}intersectsBox3(t){return this.intersectsOBB(Go.fromBox3(t))}intersectsSphere(t){return this.clampPoint(t.center,fn),fn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsOBB(t,e=Number.EPSILON){gt.c=this.center,gt.e[0]=this.halfSize.x,gt.e[1]=this.halfSize.y,gt.e[2]=this.halfSize.z,this.rotation.extractBasis(gt.u[0],gt.u[1],gt.u[2]),xt.c=t.center,xt.e[0]=t.halfSize.x,xt.e[1]=t.halfSize.y,xt.e[2]=t.halfSize.z,t.rotation.extractBasis(xt.u[0],xt.u[1],xt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)It[r][s]=gt.u[r].dot(xt.u[s]);Ft.subVectors(xt.c,gt.c),Dt[0]=Ft.dot(gt.u[0]),Dt[1]=Ft.dot(gt.u[1]),Dt[2]=Ft.dot(gt.u[2]);for(let r=0;r<3;r++)for(let s=0;s<3;s++)nt[r][s]=Math.abs(It[r][s])+e;let o,i;for(let r=0;r<3;r++)if(o=gt.e[r],i=xt.e[0]*nt[r][0]+xt.e[1]*nt[r][1]+xt.e[2]*nt[r][2],Math.abs(Dt[r])>o+i)return!1;for(let r=0;r<3;r++)if(o=gt.e[0]*nt[0][r]+gt.e[1]*nt[1][r]+gt.e[2]*nt[2][r],i=xt.e[r],Math.abs(Dt[0]*It[0][r]+Dt[1]*It[1][r]+Dt[2]*It[2][r])>o+i)return!1;return o=gt.e[1]*nt[2][0]+gt.e[2]*nt[1][0],i=xt.e[1]*nt[0][2]+xt.e[2]*nt[0][1],!(Math.abs(Dt[2]*It[1][0]-Dt[1]*It[2][0])>o+i||(o=gt.e[1]*nt[2][1]+gt.e[2]*nt[1][1],i=xt.e[0]*nt[0][2]+xt.e[2]*nt[0][0],Math.abs(Dt[2]*It[1][1]-Dt[1]*It[2][1])>o+i)||(o=gt.e[1]*nt[2][2]+gt.e[2]*nt[1][2],i=xt.e[0]*nt[0][1]+xt.e[1]*nt[0][0],Math.abs(Dt[2]*It[1][2]-Dt[1]*It[2][2])>o+i)||(o=gt.e[0]*nt[2][0]+gt.e[2]*nt[0][0],i=xt.e[1]*nt[1][2]+xt.e[2]*nt[1][1],Math.abs(Dt[0]*It[2][0]-Dt[2]*It[0][0])>o+i)||(o=gt.e[0]*nt[2][1]+gt.e[2]*nt[0][1],i=xt.e[0]*nt[1][2]+xt.e[2]*nt[1][0],Math.abs(Dt[0]*It[2][1]-Dt[2]*It[0][1])>o+i)||(o=gt.e[0]*nt[2][2]+gt.e[2]*nt[0][2],i=xt.e[0]*nt[1][1]+xt.e[1]*nt[1][0],Math.abs(Dt[0]*It[2][2]-Dt[2]*It[0][2])>o+i)||(o=gt.e[0]*nt[1][0]+gt.e[1]*nt[0][0],i=xt.e[1]*nt[2][2]+xt.e[2]*nt[2][1],Math.abs(Dt[1]*It[0][0]-Dt[0]*It[1][0])>o+i)||(o=gt.e[0]*nt[1][1]+gt.e[1]*nt[0][1],i=xt.e[0]*nt[2][2]+xt.e[2]*nt[2][0],Math.abs(Dt[1]*It[0][1]-Dt[0]*It[1][1])>o+i)||(o=gt.e[0]*nt[1][2]+gt.e[1]*nt[0][2],i=xt.e[0]*nt[2][1]+xt.e[1]*nt[2][0],Math.abs(Dt[1]*It[0][2]-Dt[0]*It[1][2])>o+i))}intersectsPlane(t){this.rotation.extractBasis(ce,ue,he);const e=this.halfSize.x*Math.abs(t.normal.dot(ce))+this.halfSize.y*Math.abs(t.normal.dot(ue))+this.halfSize.z*Math.abs(t.normal.dot(he)),o=t.normal.dot(this.center)-t.constant;return Math.abs(o)<=e}intersectRay(t,e){return this.getSize(hn),dn.setFromCenterAndSize(Ft.set(0,0,0),hn),_e.setFromMatrix3(this.rotation),_e.setPosition(this.center),mn.copy(_e).invert(),gn.copy(t).applyMatrix4(mn),gn.intersectBox(dn,e)?e.applyMatrix4(_e):null}intersectsRay(t){return this.intersectRay(t,Ft)!==null}fromBox3(t){return t.getCenter(this.center),t.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(t){return t.center.equals(this.center)&&t.halfSize.equals(this.halfSize)&&t.rotation.equals(this.rotation)}applyMatrix4(t){const e=t.elements;let o=Ft.set(e[0],e[1],e[2]).length();const i=Ft.set(e[4],e[5],e[6]).length(),r=Ft.set(e[8],e[9],e[10]).length();t.determinant()<0&&(o=-o),Qt.setFromMatrix4(t);const a=1/o,l=1/i,c=1/r;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[3]*=l,Qt.elements[4]*=l,Qt.elements[5]*=l,Qt.elements[6]*=c,Qt.elements[7]*=c,Qt.elements[8]*=c,this.rotation.multiply(Qt),this.halfSize.x*=o,this.halfSize.y*=i,this.halfSize.z*=r,Ft.setFromMatrixPosition(t),this.center.add(Ft),this}};const Go=new En;var Yt=63710088e-1,An={centimeters:Yt*100,centimetres:Yt*100,degrees:360/(2*Math.PI),feet:Yt*3.28084,inches:Yt*39.37,kilometers:Yt/1e3,kilometres:Yt/1e3,meters:Yt,metres:Yt,miles:Yt/1609.344,millimeters:Yt*1e3,millimetres:Yt*1e3,nauticalmiles:Yt/1852,radians:1,yards:Yt*1.0936};function Bn(n,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=n,o}function In(n,t,e={}){if(!n)throw new Error("coordinates is required");if(!Array.isArray(n))throw new Error("coordinates must be an Array");if(n.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!pn(n[0])||!pn(n[1]))throw new Error("coordinates must contain numbers");return Bn({type:"Point",coordinates:n},t,e)}function kn(n,t,e={}){for(const i of n){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<i[i.length-1].length;r++)if(i[i.length-1][r]!==i[0][r])throw new Error("First and last Position are not equivalent.")}return Bn({type:"Polygon",coordinates:n},t,e)}function jo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n*e}function Uo(n,t="kilometers"){const e=An[t];if(!e)throw new Error(t+" units is invalid");return n/e}function Cn(n){return n%(2*Math.PI)*180/Math.PI}function ie(n){return n%360*Math.PI/180}function Ln(n,t="kilometers",e="kilometers"){if(!(n>=0))throw new Error("length must be a positive number");return jo(Uo(n,t),e)}function pn(n){return!isNaN(n)&&n!==null&&!Array.isArray(n)}function Zo(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function Pe(n,t,e){if(n!==null)for(var o,i,r,s,a,l,c,h=0,f=0,u,p=n.type,w=p==="FeatureCollection",x=p==="Feature",P=w?n.features.length:1,M=0;M<P;M++){c=w?n.features[M].geometry:x?n.geometry:n,u=c?c.type==="GeometryCollection":!1,a=u?c.geometries.length:1;for(var m=0;m<a;m++){var d=0,g=0;if(s=u?c.geometries[m]:c,s!==null){l=s.coordinates;var b=s.type;switch(h=e&&(b==="Polygon"||b==="MultiPolygon")?1:0,b){case null:break;case"Point":if(t(l,f,M,d,g)===!1)return!1;f++,d++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(t(l[o],f,M,d,g)===!1)return!1;f++,b==="MultiPoint"&&d++}b==="LineString"&&d++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-h;i++){if(t(l[o][i],f,M,d,g)===!1)return!1;f++}b==="MultiLineString"&&d++,b==="Polygon"&&g++}b==="Polygon"&&d++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(g=0,i=0;i<l[o].length;i++){for(r=0;r<l[o][i].length-h;r++){if(t(l[o][i][r],f,M,d,g)===!1)return!1;f++}g++}d++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(Pe(s.geometries[o],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ko(n){var t=[];return Pe(n,function(e){t.push(e)}),t}function Qo(n,t){var e,o,i,r,s,a,l,c,h,f,u=0,p=n.type==="FeatureCollection",w=n.type==="Feature",x=p?n.features.length:1;for(e=0;e<x;e++){for(a=p?n.features[e].geometry:w?n.geometry:n,c=p?n.features[e].properties:w?n.properties:{},h=p?n.features[e].bbox:w?n.bbox:void 0,f=p?n.features[e].id:w?n.id:void 0,l=a?a.type==="GeometryCollection":!1,s=l?a.geometries.length:1,i=0;i<s;i++){if(r=l?a.geometries[i]:a,r===null){if(t(null,u,c,h,f)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,u,c,h,f)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<r.geometries.length;o++)if(t(r.geometries[o],u,c,h,f)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}u++}}function Jo(n,t,e){var o=e;return Qo(n,function(i,r,s,a,l){r===0&&e===void 0?o=i:o=t(o,i,r,s,a,l)}),o}var Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function er(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function o(){return this instanceof o?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(o){var i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:function(){return n[o]}})}),e}var Ze={exports:{}},On={exports:{}};(function(n,t){(function(e,o){n.exports=o()})(Rn,function(){function e(m,d,g,b,z){(function v(S,V,D,_,T){for(;_>D;){if(_-D>600){var E=_-D+1,A=V-D+1,F=Math.log(E),I=.5*Math.exp(2*F/3),B=.5*Math.sqrt(F*I*(E-I)/E)*(A-E/2<0?-1:1),L=Math.max(D,Math.floor(V-A*I/E+B)),W=Math.min(_,Math.floor(V+(E-A)*I/E+B));v(S,V,L,W,T)}var C=S[V],R=D,H=_;for(o(S,D,V),T(S[_],C)>0&&o(S,D,_);R<H;){for(o(S,R,H),R++,H--;T(S[R],C)<0;)R++;for(;T(S[H],C)>0;)H--}T(S[D],C)===0?o(S,D,H):o(S,++H,_),H<=V&&(D=H+1),V<=H&&(_=H-1)}})(m,d,g||0,b||m.length-1,z||i)}function o(m,d,g){var b=m[d];m[d]=m[g],m[g]=b}function i(m,d){return m<d?-1:m>d?1:0}var r=function(m){m===void 0&&(m=9),this._maxEntries=Math.max(4,m),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function s(m,d,g){if(!g)return d.indexOf(m);for(var b=0;b<d.length;b++)if(g(m,d[b]))return b;return-1}function a(m,d){l(m,0,m.children.length,d,m)}function l(m,d,g,b,z){z||(z=P(null)),z.minX=1/0,z.minY=1/0,z.maxX=-1/0,z.maxY=-1/0;for(var v=d;v<g;v++){var S=m.children[v];c(z,m.leaf?b(S):S)}return z}function c(m,d){return m.minX=Math.min(m.minX,d.minX),m.minY=Math.min(m.minY,d.minY),m.maxX=Math.max(m.maxX,d.maxX),m.maxY=Math.max(m.maxY,d.maxY),m}function h(m,d){return m.minX-d.minX}function f(m,d){return m.minY-d.minY}function u(m){return(m.maxX-m.minX)*(m.maxY-m.minY)}function p(m){return m.maxX-m.minX+(m.maxY-m.minY)}function w(m,d){return m.minX<=d.minX&&m.minY<=d.minY&&d.maxX<=m.maxX&&d.maxY<=m.maxY}function x(m,d){return d.minX<=m.maxX&&d.minY<=m.maxY&&d.maxX>=m.minX&&d.maxY>=m.minY}function P(m){return{children:m,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(m,d,g,b,z){for(var v=[d,g];v.length;)if(!((g=v.pop())-(d=v.pop())<=b)){var S=d+Math.ceil((g-d)/b/2)*b;e(m,S,d,g,z),v.push(d,S,S,g)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(m){var d=this.data,g=[];if(!x(m,d))return g;for(var b=this.toBBox,z=[];d;){for(var v=0;v<d.children.length;v++){var S=d.children[v],V=d.leaf?b(S):S;x(m,V)&&(d.leaf?g.push(S):w(m,V)?this._all(S,g):z.push(S))}d=z.pop()}return g},r.prototype.collides=function(m){var d=this.data;if(!x(m,d))return!1;for(var g=[];d;){for(var b=0;b<d.children.length;b++){var z=d.children[b],v=d.leaf?this.toBBox(z):z;if(x(m,v)){if(d.leaf||w(m,v))return!0;g.push(z)}}d=g.pop()}return!1},r.prototype.load=function(m){if(!m||!m.length)return this;if(m.length<this._minEntries){for(var d=0;d<m.length;d++)this.insert(m[d]);return this}var g=this._build(m.slice(),0,m.length-1,0);if(this.data.children.length)if(this.data.height===g.height)this._splitRoot(this.data,g);else{if(this.data.height<g.height){var b=this.data;this.data=g,g=b}this._insert(g,this.data.height-g.height-1,!0)}else this.data=g;return this},r.prototype.insert=function(m){return m&&this._insert(m,this.data.height-1),this},r.prototype.clear=function(){return this.data=P([]),this},r.prototype.remove=function(m,d){if(!m)return this;for(var g,b,z,v=this.data,S=this.toBBox(m),V=[],D=[];v||V.length;){if(v||(v=V.pop(),b=V[V.length-1],g=D.pop(),z=!0),v.leaf){var _=s(m,v.children,d);if(_!==-1)return v.children.splice(_,1),V.push(v),this._condense(V),this}z||v.leaf||!w(v,S)?b?(g++,v=b.children[g],z=!1):v=null:(V.push(v),D.push(g),g=0,b=v,v=v.children[0])}return this},r.prototype.toBBox=function(m){return m},r.prototype.compareMinX=function(m,d){return m.minX-d.minX},r.prototype.compareMinY=function(m,d){return m.minY-d.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(m){return this.data=m,this},r.prototype._all=function(m,d){for(var g=[];m;)m.leaf?d.push.apply(d,m.children):g.push.apply(g,m.children),m=g.pop();return d},r.prototype._build=function(m,d,g,b){var z,v=g-d+1,S=this._maxEntries;if(v<=S)return a(z=P(m.slice(d,g+1)),this.toBBox),z;b||(b=Math.ceil(Math.log(v)/Math.log(S)),S=Math.ceil(v/Math.pow(S,b-1))),(z=P([])).leaf=!1,z.height=b;var V=Math.ceil(v/S),D=V*Math.ceil(Math.sqrt(S));M(m,d,g,D,this.compareMinX);for(var _=d;_<=g;_+=D){var T=Math.min(_+D-1,g);M(m,_,T,V,this.compareMinY);for(var E=_;E<=T;E+=V){var A=Math.min(E+V-1,T);z.children.push(this._build(m,E,A,b-1))}}return a(z,this.toBBox),z},r.prototype._chooseSubtree=function(m,d,g,b){for(;b.push(d),!d.leaf&&b.length-1!==g;){for(var z=1/0,v=1/0,S=void 0,V=0;V<d.children.length;V++){var D=d.children[V],_=u(D),T=(E=m,A=D,(Math.max(A.maxX,E.maxX)-Math.min(A.minX,E.minX))*(Math.max(A.maxY,E.maxY)-Math.min(A.minY,E.minY))-_);T<v?(v=T,z=_<z?_:z,S=D):T===v&&_<z&&(z=_,S=D)}d=S||d.children[0]}var E,A;return d},r.prototype._insert=function(m,d,g){var b=g?m:this.toBBox(m),z=[],v=this._chooseSubtree(b,this.data,d,z);for(v.children.push(m),c(v,b);d>=0&&z[d].children.length>this._maxEntries;)this._split(z,d),d--;this._adjustParentBBoxes(b,z,d)},r.prototype._split=function(m,d){var g=m[d],b=g.children.length,z=this._minEntries;this._chooseSplitAxis(g,z,b);var v=this._chooseSplitIndex(g,z,b),S=P(g.children.splice(v,g.children.length-v));S.height=g.height,S.leaf=g.leaf,a(g,this.toBBox),a(S,this.toBBox),d?m[d-1].children.push(S):this._splitRoot(g,S)},r.prototype._splitRoot=function(m,d){this.data=P([m,d]),this.data.height=m.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(m,d,g){for(var b,z,v,S,V,D,_,T=1/0,E=1/0,A=d;A<=g-d;A++){var F=l(m,0,A,this.toBBox),I=l(m,A,g,this.toBBox),B=(z=F,v=I,S=void 0,V=void 0,D=void 0,_=void 0,S=Math.max(z.minX,v.minX),V=Math.max(z.minY,v.minY),D=Math.min(z.maxX,v.maxX),_=Math.min(z.maxY,v.maxY),Math.max(0,D-S)*Math.max(0,_-V)),L=u(F)+u(I);B<T?(T=B,b=A,E=L<E?L:E):B===T&&L<E&&(E=L,b=A)}return b||g-d},r.prototype._chooseSplitAxis=function(m,d,g){var b=m.leaf?this.compareMinX:h,z=m.leaf?this.compareMinY:f;this._allDistMargin(m,d,g,b)<this._allDistMargin(m,d,g,z)&&m.children.sort(b)},r.prototype._allDistMargin=function(m,d,g,b){m.children.sort(b);for(var z=this.toBBox,v=l(m,0,d,z),S=l(m,g-d,g,z),V=p(v)+p(S),D=d;D<g-d;D++){var _=m.children[D];c(v,m.leaf?z(_):_),V+=p(v)}for(var T=g-d-1;T>=d;T--){var E=m.children[T];c(S,m.leaf?z(E):E),V+=p(S)}return V},r.prototype._adjustParentBBoxes=function(m,d,g){for(var b=g;b>=0;b--)c(d[b],m)},r.prototype._condense=function(m){for(var d=m.length-1,g=void 0;d>=0;d--)m[d].children.length===0?d>0?(g=m[d-1].children).splice(g.indexOf(m[d]),1):this.clear():a(m[d],this.toBBox)},r})})(On);var nr=On.exports;class or{constructor(t=[],e=rr){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let o=(this.length>>1)-1;o>=0;o--)this._down(o)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:o}=this,i=e[t];for(;t>0;){const r=t-1>>1,s=e[r];if(o(i,s)>=0)break;e[t]=s,t=r}e[t]=i}_down(t){const{data:e,compare:o}=this,i=this.length>>1,r=e[t];for(;t<i;){let s=(t<<1)+1,a=e[s];const l=s+1;if(l<this.length&&o(e[l],a)<0&&(s=l,a=e[l]),o(a,r)>=0)break;e[t]=a,t=s}e[t]=r}}function rr(n,t){return n<t?-1:n>t?1:0}const ir=Object.freeze(Object.defineProperty({__proto__:null,default:or},Symbol.toStringTag,{value:"Module"})),sr=er(ir);var ke={exports:{}},ar=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=(i-o)/2,c=0,h=l-1;c<l;h=c++){var f=e[o+c*2+0],u=e[o+c*2+1],p=e[o+h*2+0],w=e[o+h*2+1],x=u>s!=w>s&&r<(p-f)*(s-u)/(w-u)+f;x&&(a=!a)}return a},lr=function(t,e,o,i){var r=t[0],s=t[1],a=!1;o===void 0&&(o=0),i===void 0&&(i=e.length);for(var l=i-o,c=0,h=l-1;c<l;h=c++){var f=e[c+o][0],u=e[c+o][1],p=e[h+o][0],w=e[h+o][1],x=u>s!=w>s&&r<(p-f)*(s-u)/(w-u)+f;x&&(a=!a)}return a},Fn=ar,Wn=lr;ke.exports=function(t,e,o,i){return e.length>0&&Array.isArray(e[0])?Wn(t,e,o,i):Fn(t,e,o,i)};ke.exports.nested=Wn;ke.exports.flat=Fn;var cr=ke.exports,je={exports:{}};(function(n,t){(function(e,o){o(t)})(Rn,function(e){const i=33306690738754706e-32;function r(x,P,M,m,d){let g,b,z,v,S=P[0],V=m[0],D=0,_=0;V>S==V>-S?(g=S,S=P[++D]):(g=V,V=m[++_]);let T=0;if(D<x&&_<M)for(V>S==V>-S?(z=g-((b=S+g)-S),S=P[++D]):(z=g-((b=V+g)-V),V=m[++_]),g=b,z!==0&&(d[T++]=z);D<x&&_<M;)V>S==V>-S?(z=g-((b=g+S)-(v=b-g))+(S-v),S=P[++D]):(z=g-((b=g+V)-(v=b-g))+(V-v),V=m[++_]),g=b,z!==0&&(d[T++]=z);for(;D<x;)z=g-((b=g+S)-(v=b-g))+(S-v),S=P[++D],g=b,z!==0&&(d[T++]=z);for(;_<M;)z=g-((b=g+V)-(v=b-g))+(V-v),V=m[++_],g=b,z!==0&&(d[T++]=z);return g===0&&T!==0||(d[T++]=g),T}function s(x){return new Float64Array(x)}const a=33306690738754716e-32,l=22204460492503146e-32,c=11093356479670487e-47,h=s(4),f=s(8),u=s(12),p=s(16),w=s(4);e.orient2d=function(x,P,M,m,d,g){const b=(P-g)*(M-d),z=(x-d)*(m-g),v=b-z;if(b===0||z===0||b>0!=z>0)return v;const S=Math.abs(b+z);return Math.abs(v)>=a*S?v:-function(V,D,_,T,E,A,F){let I,B,L,W,C,R,H,X,ot,K,G,ht,rt,O,Y,Vt,Zt,Nt;const Rt=V-E,_t=_-E,Tt=D-A,Ot=T-A;C=(Y=(X=Rt-(H=(R=134217729*Rt)-(R-Rt)))*(K=Ot-(ot=(R=134217729*Ot)-(R-Ot)))-((O=Rt*Ot)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=Tt-(H=(R=134217729*Tt)-(R-Tt)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=Tt*_t)-H*ot-X*ot-H*K))),h[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),h[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,h[2]=ht-(Nt-C)+(G-C),h[3]=Nt;let tt=function(Et,qt){let J=qt[0];for(let ut=1;ut<Et;ut++)J+=qt[ut];return J}(4,h),ct=l*F;if(tt>=ct||-tt>=ct||(I=V-(Rt+(C=V-Rt))+(C-E),L=_-(_t+(C=_-_t))+(C-E),B=D-(Tt+(C=D-Tt))+(C-A),W=T-(Ot+(C=T-Ot))+(C-A),I===0&&B===0&&L===0&&W===0)||(ct=c*F+i*Math.abs(tt),(tt+=Rt*W+Ot*I-(Tt*L+_t*B))>=ct||-tt>=ct))return tt;C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(K=Ot-(ot=(R=134217729*Ot)-(R-Ot)))-((O=I*Ot)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=B-(H=(R=134217729*B)-(R-B)))*(K=_t-(ot=(R=134217729*_t)-(R-_t)))-((Vt=B*_t)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const q=r(4,h,4,w,f);C=(Y=(X=Rt-(H=(R=134217729*Rt)-(R-Rt)))*(K=W-(ot=(R=134217729*W)-(R-W)))-((O=Rt*W)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=Tt-(H=(R=134217729*Tt)-(R-Tt)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=Tt*L)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const j=r(q,f,4,w,u);C=(Y=(X=I-(H=(R=134217729*I)-(R-I)))*(K=W-(ot=(R=134217729*W)-(R-W)))-((O=I*W)-H*ot-X*ot-H*K))-(G=Y-(Zt=(X=B-(H=(R=134217729*B)-(R-B)))*(K=L-(ot=(R=134217729*L)-(R-L)))-((Vt=B*L)-H*ot-X*ot-H*K))),w[0]=Y-(G+C)+(C-Zt),C=(rt=O-((ht=O+G)-(C=ht-O))+(G-C))-(G=rt-Vt),w[1]=rt-(G+C)+(C-Vt),C=(Nt=ht+G)-ht,w[2]=ht-(Nt-C)+(G-C),w[3]=Nt;const Wt=r(j,u,4,w,p);return p[Wt-1]}(x,P,M,m,d,g,S)},e.orient2dfast=function(x,P,M,m,d,g){return(P-g)*(M-d)-(x-d)*(m-g)},Object.defineProperty(e,"__esModule",{value:!0})})})(je,je.exports);var ur=je.exports,yn=nr,Ae=sr,hr=cr,fr=ur.orient2d;Ae.default&&(Ae=Ae.default);Ze.exports=Nn;Ze.exports.default=Nn;function Nn(n,t,e){t=Math.max(0,t===void 0?2:t),e=e||0;var o=yr(n),i=new yn(16);i.toBBox=function(m){return{minX:m[0],minY:m[1],maxX:m[0],maxY:m[1]}},i.compareMinX=function(m,d){return m[0]-d[0]},i.compareMinY=function(m,d){return m[1]-d[1]},i.load(n);for(var r=[],s=0,a;s<o.length;s++){var l=o[s];i.remove(l),a=bn(l,a),r.push(a)}var c=new yn(16);for(s=0;s<r.length;s++)c.insert(Ne(r[s]));for(var h=t*t,f=e*e;r.length;){var u=r.shift(),p=u.p,w=u.next.p,x=qe(p,w);if(!(x<f)){var P=x/h;l=dr(i,u.prev.p,p,w,u.next.next.p,P,c),l&&Math.min(qe(l,p),qe(l,w))<=P&&(r.push(u),r.push(bn(l,u)),i.remove(l),c.remove(u),c.insert(Ne(u)),c.insert(Ne(u.next)))}}u=a;var M=[];do M.push(u.p),u=u.next;while(u!==a);return M.push(u.p),M}function dr(n,t,e,o,i,r,s){for(var a=new Ae([],mr),l=n.data;l;){for(var c=0;c<l.children.length;c++){var h=l.children[c],f=l.leaf?Xe(h,e,o):gr(e,o,h);f>r||a.push({node:h,dist:f})}for(;a.length&&!a.peek().node.children;){var u=a.pop(),p=u.node,w=Xe(p,t,e),x=Xe(p,o,i);if(u.dist<w&&u.dist<x&&wn(e,p,s)&&wn(o,p,s))return p}l=a.pop(),l&&(l=l.node)}return null}function mr(n,t){return n.dist-t.dist}function gr(n,t,e){if(xn(n,e)||xn(t,e))return 0;var o=Te(n[0],n[1],t[0],t[1],e.minX,e.minY,e.maxX,e.minY);if(o===0)return 0;var i=Te(n[0],n[1],t[0],t[1],e.minX,e.minY,e.minX,e.maxY);if(i===0)return 0;var r=Te(n[0],n[1],t[0],t[1],e.maxX,e.minY,e.maxX,e.maxY);if(r===0)return 0;var s=Te(n[0],n[1],t[0],t[1],e.minX,e.maxY,e.maxX,e.maxY);return s===0?0:Math.min(o,i,r,s)}function xn(n,t){return n[0]>=t.minX&&n[0]<=t.maxX&&n[1]>=t.minY&&n[1]<=t.maxY}function wn(n,t,e){for(var o=Math.min(n[0],t[0]),i=Math.min(n[1],t[1]),r=Math.max(n[0],t[0]),s=Math.max(n[1],t[1]),a=e.search({minX:o,minY:i,maxX:r,maxY:s}),l=0;l<a.length;l++)if(pr(a[l].p,a[l].next.p,n,t))return!1;return!0}function xe(n,t,e){return fr(n[0],n[1],t[0],t[1],e[0],e[1])}function pr(n,t,e,o){return n!==o&&t!==e&&xe(n,t,e)>0!=xe(n,t,o)>0&&xe(e,o,n)>0!=xe(e,o,t)>0}function Ne(n){var t=n.p,e=n.next.p;return n.minX=Math.min(t[0],e[0]),n.minY=Math.min(t[1],e[1]),n.maxX=Math.max(t[0],e[0]),n.maxY=Math.max(t[1],e[1]),n}function yr(n){for(var t=n[0],e=n[0],o=n[0],i=n[0],r=0;r<n.length;r++){var s=n[r];s[0]<t[0]&&(t=s),s[0]>o[0]&&(o=s),s[1]<e[1]&&(e=s),s[1]>i[1]&&(i=s)}var a=[t,e,o,i],l=a.slice();for(r=0;r<n.length;r++)hr(n[r],a)||l.push(n[r]);return wr(l)}function bn(n,t){var e={p:n,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e):(e.prev=e,e.next=e),e}function qe(n,t){var e=n[0]-t[0],o=n[1]-t[1];return e*e+o*o}function Xe(n,t,e){var o=t[0],i=t[1],r=e[0]-o,s=e[1]-i;if(r!==0||s!==0){var a=((n[0]-o)*r+(n[1]-i)*s)/(r*r+s*s);a>1?(o=e[0],i=e[1]):a>0&&(o+=r*a,i+=s*a)}return r=n[0]-o,s=n[1]-i,r*r+s*s}function Te(n,t,e,o,i,r,s,a){var l=e-n,c=o-t,h=s-i,f=a-r,u=n-i,p=t-r,w=l*l+c*c,x=l*h+c*f,P=h*h+f*f,M=l*u+c*p,m=h*u+f*p,d=w*P-x*x,g,b,z,v,S=d,V=d;d===0?(b=0,S=1,v=m,V=P):(b=x*m-P*M,v=w*m-x*M,b<0?(b=0,v=m,V=P):b>S&&(b=S,v=m+x,V=P)),v<0?(v=0,-M<0?b=0:-M>w?b=S:(b=-M,S=w)):v>V&&(v=V,-M+x<0?b=0:-M+x>w?b=S:(b=-M+x,S=w)),g=b===0?0:b/S,z=v===0?0:v/V;var D=(1-g)*n+g*e,_=(1-g)*t+g*o,T=(1-z)*i+z*s,E=(1-z)*r+z*a,A=T-D,F=E-_;return A*A+F*F}function xr(n,t){return n[0]===t[0]?n[1]-t[1]:n[0]-t[0]}function wr(n){n.sort(xr);for(var t=[],e=0;e<n.length;e++){for(;t.length>=2&&xe(t[t.length-2],t[t.length-1],n[e])<=0;)t.pop();t.push(n[e])}for(var o=[],i=n.length-1;i>=0;i--){for(;o.length>=2&&xe(o[o.length-2],o[o.length-1],n[i])<=0;)o.pop();o.push(n[i])}return o.pop(),t.pop(),t.concat(o)}var br=Ze.exports;const Pr=tr(br);function Mr(n,t={}){t.concavity=t.concavity||1/0;const e=[];if(Pe(n,i=>{e.push([i[0],i[1]])}),!e.length)return null;const o=Pr(e,t.concavity);return o.length>3?kn([o]):null}function qn(n,t={}){let e=0,o=0,i=0;return Pe(n,function(r){e+=r[0],o+=r[1],i++},!0),In([e/i,o/i],t.properties)}function se(n){if(!n)throw new Error("coord is required");if(!Array.isArray(n)){if(n.type==="Feature"&&n.geometry!==null&&n.geometry.type==="Point")return[...n.geometry.coordinates];if(n.type==="Point")return[...n.coordinates]}if(Array.isArray(n)&&n.length>=2&&!Array.isArray(n[0])&&!Array.isArray(n[1]))return[...n];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Vr(n){if(Array.isArray(n))return n;if(n.type==="Feature"){if(n.geometry!==null)return n.geometry.coordinates}else if(n.coordinates)return n.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function zr(n,t,e={}){let o;return e.final?o=Pn(se(t),se(n)):o=Pn(se(n),se(t)),o>180?-(360-o):o}function Pn(n,t){const e=ie(n[1]),o=ie(t[1]);let i=ie(t[0]-n[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(i,r);return(Cn(s)+360)%360}function Sr(n,t,e={}){const o=se(n),i=se(t);i[0]+=i[0]-o[0]>180?-360:o[0]-i[0]>180?360:0;const r=vr(o,i);return Ln(r,"meters",e.units)}function vr(n,t,e){e=e===void 0?Yt:Number(e);const o=e,i=n[1]*Math.PI/180,r=t[1]*Math.PI/180,s=r-i;let a=Math.abs(t[0]-n[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);const l=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=Math.abs(l)>1e-11?s/l:Math.cos(i);return Math.sqrt(s*s+c*c*a*a)*o}function Dr(n,t,e,o={}){const i=t<0;let r=Ln(Math.abs(t),o.units,"meters");i&&(r=-Math.abs(r));const s=se(n),a=_r(s,r,e);return a[0]+=a[0]-s[0]>180?-360:s[0]-a[0]>180?360:0,In(a,o.properties)}function _r(n,t,e,o){o=o===void 0?Yt:Number(o);const i=t/o,r=n[0]*Math.PI/180,s=ie(n[1]),a=ie(e),l=i*Math.cos(a);let c=s+l;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);const h=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),f=Math.abs(h)>1e-11?l/h:Math.cos(s),u=i*Math.sin(a)/f;return[((r+u)*180/Math.PI+540)%360-180,c*180/Math.PI]}function Tr(n){if(!n)throw new Error("geojson is required");switch(n.type){case"Feature":return Xn(n);case"FeatureCollection":return Er(n);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ke(n);default:throw new Error("unknown GeoJSON type")}}function Xn(n){const t={type:"Feature"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=n[e]}}),t.properties=Hn(n.properties),n.geometry==null?t.geometry=null:t.geometry=Ke(n.geometry),t}function Hn(n){const t={};return n&&Object.keys(n).forEach(e=>{const o=n[e];typeof o=="object"?o===null?t[e]=null:Array.isArray(o)?t[e]=o.map(i=>i):t[e]=Hn(o):t[e]=o}),t}function Er(n){const t={type:"FeatureCollection"};return Object.keys(n).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=n[e]}}),t.features=n.features.map(e=>Xn(e)),t}function Ke(n){const t={type:n.type};return n.bbox&&(t.bbox=n.bbox),n.type==="GeometryCollection"?(t.geometries=n.geometries.map(e=>Ke(e)),t):(t.coordinates=Yn(n.coordinates),t)}function Yn(n){const t=n;return typeof t[0]!="object"?t.slice():t.map(e=>Yn(e))}function Mn(n,t,e){if(e=e||{},!Zo(e))throw new Error("options is invalid");const o=e.pivot,i=e.mutate;if(!n)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("angle is required");if(t===0)return n;const r=o??qn(n);return(i===!1||i===void 0)&&(n=Tr(n)),Pe(n,function(s){const l=zr(r,s)+t,c=Sr(r,s),h=Vr(Dr(r,c,l));s[0]=h[0],s[1]=h[1]}),n}function $n(n,t,e={}){if(e.final===!0)return Ar(n,t);const o=se(n),i=se(t),r=ie(o[0]),s=ie(i[0]),a=ie(o[1]),l=ie(i[1]),c=Math.sin(s-r)*Math.cos(l),h=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(s-r);return Cn(Math.atan2(c,h))}function Ar(n,t){let e=$n(t,n);return e=(e+180)%360,e}function Br(n,t={}){if(n.bbox!=null&&t.recompute!==!0)return n.bbox;const e=[1/0,1/0,-1/0,-1/0];return Pe(n,o=>{e[0]>o[0]&&(e[0]=o[0]),e[1]>o[1]&&(e[1]=o[1]),e[2]<o[0]&&(e[2]=o[0]),e[3]<o[1]&&(e[3]=o[1])}),e}function Ir(n,t={}){const e=Number(n[0]),o=Number(n[1]),i=Number(n[2]),r=Number(n[3]);if(n.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const s=[e,o];return kn([[s,[i,o],[i,r],[e,r],s]],t.properties,{bbox:n,id:t.id})}function kr(n){return Ir(Br(n))}function Cr(n){return Jo(n,(t,e)=>t+Lr(e),0)}function Lr(n){let t=0,e;switch(n.type){case"Polygon":return Vn(n.coordinates);case"MultiPolygon":for(e=0;e<n.coordinates.length;e++)t+=Vn(n.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function Vn(n){let t=0;if(n&&n.length>0){t+=Math.abs(zn(n[0]));for(let e=1;e<n.length;e++)t-=Math.abs(zn(n[e]))}return t}var Rr=Yt*Yt/2,He=Math.PI/180;function zn(n){const t=n.length-1;if(t<=2)return 0;let e=0,o=0;for(;o<t;){const i=n[o],r=n[o+1===t?0:o+1],s=n[o+2>=t?(o+2)%t:o+2],a=i[0]*He,l=r[1]*He,c=s[0]*He;e+=(c-a)*Math.sin(l),o++}return e*Rr}function Or(n){const t=Mr(n);if(!t)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");const e=qn(t),o=Ko(t);let i=Number.MAX_SAFE_INTEGER,r=null;for(let s=0;s<o.length-1;s++){let a=$n(o[s],o[s+1]),l=Mn(t,-1*a,{pivot:e}),c=kr(l),h=Cr(c);h<i&&(i=h,r=Mn(c,a,{pivot:e}))}return r}function Sn(n,t){const e=t[0]-n[0],o=t[1]-n[1];return Math.sqrt(e*e+o*o)}function Fr(n){let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const[r,s]of n)r<t&&(t=r),r>e&&(e=r),s<o&&(o=s),s>i&&(i=s);return[(e+t)*.5,(i+o)*.5]}class Ie extends En{getBoxMesh(){le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new y.Vector3);const t=this.halfSize.clone().multiplyScalar(2),e=new y.Mesh(new y.BoxGeometry(t.x,t.y,t.z));return e.position.copy(this.center),e.rotation.setFromQuaternion(fe),e}getBoxEdge(t=16776960){const e=this.getBoxMesh();Nr.setFromObject(e);const o=new y.EdgesGeometry(e.geometry.clone().applyMatrix4(e.matrixWorld));return new y.LineSegments(o,new y.LineBasicMaterial({color:t,toneMapped:!1}))}toJson(){return le.identity(),le.setFromMatrix3(this.rotation),le.decompose(Ee,fe,new y.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:fe.toArray()}}static from(t,e,o,i=new Ie){if(o instanceof y.Euler)fe.setFromEuler(o);else if(o instanceof y.Quaternion)fe.copy(o);else throw new Error("传入的旋转不是欧拉角或者四元数");return le.compose(e,fe,Wr),i.center.copy(e),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(le),i}static fromByPath2D(t,e,o,i=new Ie){const r=Or({type:"Polygon",coordinates:[t.map(p=>[p.x,p.y])]});if(!r)throw new Error("2d obb 获取失败");const s=r.geometry.coordinates[0],a=Sn(s[0],s[1]),l=Sn(s[1],s[2]),c=Math.atan2(s[1][1]-s[0][1],s[1][0]-s[0][0]);Ee.set(a,l,o),vn.set(0,0,c);const[h,f]=Fr(s);return e.x=h,e.y=f,this.from(Ee,e,vn,i)}}const le=new y.Matrix4,fe=new y.Quaternion,vn=new y.Euler,Wr=new y.Vector3(1,1,1),Ee=new y.Vector3,Nr=new y.Box3;function qr(n,t,e=.005,o=.2){if(!n.length||!t.length)return 0;const i=Math.max(e,.03),r=e*e,s=new Map,a=(f,u,p)=>`${Math.floor(f/i)},${Math.floor(u/i)},${Math.floor(p/i)}`;for(const f of t){const u=a(f.x,f.y,f.z);s.has(u)||s.set(u,[]),s.get(u).push(f)}let l=0;const c=Math.ceil(e/i)+1,h=[];for(let f=-c;f<=c;f++)for(let u=-c;u<=c;u++)for(let p=-c;p<=c;p++)f*f+u*u+p*p<=c*c&&h.push([f,u,p]);for(const f of n){const u=Math.floor(f.x/i),p=Math.floor(f.y/i),w=Math.floor(f.z/i);let x=!1;for(const[P,M,m]of h){const d=`${u+P},${p+M},${w+m}`;if(s.has(d)){for(const g of s.get(d))if(f.distanceToSquared(g)<r){x=!0;break}if(x)break}}if(x&&(l++,l/n.length>o))return l/n.length}return l/n.length}function pe(n,t,e=.5){let o=0,i=0;for(const r of n)if(t.containsPoint(r)&&(o++,i=o/n.length,i>e))break;return i}function Ye(n,t,e,o){if(n.intersectsOBB(t))return!0;{const r=we(n,o),s=we(t,e);if(r||s)return!0}return!1}function Dn(n,t){const e=new y.Vector3,o=new y.Vector3;n.getSize(e),t.getSize(o);const i=e.x*e.y*e.z,r=o.x*o.y*o.z;return i>r?1:i<r?-1:0}function we(n,t){let e=!0;for(let o=0;o<t.length;o++)if(!n.containsPoint(t[o])){e=!1;break}return e}function _n(n){if(n.length===0)return{x:0,y:0,z:0,h:0};let t=0,e=0,o=-1/0,i=1/0;for(const r of n)t+=r.x,e+=r.y,o=Math.max(o,r.z),i=Math.min(i,r.z);return{x:t/n.length,y:e/n.length,z:0,maxz:o,minz:i,h:o-i}}function Tn(n,t,e,o){const i=[];for(let s=0;s<n.length;s++)i.push(new y.Vector3(n[s][0],n[s][1],0));if(i.length==0)return null;const r=Ie.fromByPath2D(i,t,e);return r.center.z=o,r}const Xr=n=>{if(n.length==0)return[];const t=[],e=new Map;for(let r=0;r<n.length;r++){let s=n[r].points.map(P=>[P.x,P.y]),a=n[r].obj_id;a=a.replace(/calcony railing/g,"balcony railing").replace(/glass balcony railing/g,"balcony railing").replace(/metal balcony railing/g,"balcony railing").replace(/temporary construction guardrail/g,"balcony railing").replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor"),a.split("_").slice(1,3).join("_").split(".")[0].split("_")[0];const l=a.indexOf("_")+1,c=a.lastIndexOf("_"),h=a.substring(l,c);if(h==="wall")continue;let f=[];for(let P=0;P<n[r].points.length;P++)f.push(new y.Vector3(n[r].points[P].x,n[r].points[P].y,n[r].points[P].z));let u=-99999;if(h==="floor"){let P=new Map;for(let m=0;m<n[r].points.length;m++){let d=n[r].points[m].z;if(d=Math.floor(d*10)/10,P.has(d)){const g=P.get(d);g.num+=1,g.points.push(n[r].points[m]),P.set(d,g)}else P.set(d,{num:1,points:[n[r].points[m]]})}let M=[...P.entries()].reduce((m,d)=>d[1].num>m[1].num?d:m);s=[],s=M[1].points.map(m=>[m.x,m.y]),f=[],f=M[1].points.map(m=>new y.Vector3(m.x,m.y,m.z)),u=M[0]}const p=_n(f),w={points:f,path:Ge(s),h:p.h,minz:p.minz,maxz:p.maxz,center:{x:p.x,y:p.y,z:p.z},obj_id:n[r].obj_id,type:h,averagePz:n[r].averagePz,obb:null,isDel:!1,obj_id:a,positionArr:[n[r].position]};if(w.obb=Tn(w.path,w.center,w.h,(w.maxz+w.minz)/2),w.obb==null)continue;let x=-1;for(let P=0;P<t.length;P++)if(t[P].type==h){x=P;break}if(x!=-1?t[x].array.push(w):t.push({type:h,array:[w]}),h=="floor"&&u!=-99999)if(e.has(u)){const P=e.get(u);P.num+=w.points.length,P.datas.push(w),e.set(u,P)}else e.set(u,{num:w.points.length,datas:[w]})}let o=-1/0;if(e.size>0){let r=[];for(const[s,a]of e.entries()){const{num:l,datas:c}=a;l>3e3&&(s>o&&(o=s),r.push(...c))}for(let s=0;s<t.length;s++)if(t[s].type=="floor"){t[s].array=r;break}}for(let r=0;r<t.length;r++){const s=t[r].array,a=[],l=[];for(let h=0;h<s.length;h++){if(s[h].obb==null||a.includes(h))continue;const f={...s[h],obb:s[h].obb.clone()};for(let u=h+1;u<s.length;u++){if(s[u].obb==null||a.includes(u))continue;if(f.obb.intersectsOBB(s[u].obb)){a.push(u);for(let P=0;P<s[u].points.length;P++)(s[u].points[P].z>o&&s[u].points[P].z-o>.1||f.type=="floor")&&f.points.push(s[u].points[P]);const w=f.points.map(P=>[P.x,P.y]);f.path=Ge(w);const x=_n(f.points);f.h=x.h,f.minz=x.minz,f.maxz=x.maxz,f.center={x:x.x,y:x.y,z:x.z},f.obb=Tn(f.path,f.center,f.h,(f.maxz+f.minz)/2),f.positionArr.push(...s[u].positionArr),u=h}}f.path.length>s[h].path.length&&(a.push(h),l.push(f))}const c=[];for(let h=0;h<s.length;h++)a.includes(h)||c.push(s[h]);c.push(...l),t[r].array=c}for(let r=0;r<t.length;r++){const s=t[r].type;if(s==="people"||s==="floor")continue;const a=t[r].array;for(let l=0;l<a.length;l++){const c=a[l].obb,h=a[l].minz;a[l].maxz;const f=a[l].averagePz;if(s==="window"||s==="door"||s==="tv"||s==="chair"||s==="cabinet"||s==="table"){const u=new y.Vector3;c.getSize(u);const p=[u.x,u.y,u.z];let w=0;for(const x of p)if(x<.2&&(w++,w===2)){a[l].isDel=!0;break}}if(!a[l].isDel)for(let u=r+1;u<t.length;u++){const p=t[u].type;if(p==="people"||p==="floor")continue;const w=t[u].array;for(let x=0;x<w.length;x++){if(w[x].isDel)continue;const P=w[x].obb,M=w[x].minz;if(w[x].maxz,c.intersectsOBB(P)){pe(w[x].points,c);const m=pe(a[l].points,P),d=Dn(c,P);if(m>=.3&&d==-1){a[l].isDel=!0;break}if(s!=="wall"&&s!=="floor"&&s!=="roof"){if(s==="window"){if(p==="balcony railing"&&we(c,w[x].points)){w[x].isDel=!0;continue}if(p==="balcony railing"&&we(P,a[l].points)){a[l].isDel=!0;break}if(p==="balcony railing"&&Ye(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(M-f)>.3)){w[x].isDel=!0;continue}}else if(s==="balcony railing"){if(p==="window"&&we(c,w[x].points)){w[x].isDel=!0;continue}if(p==="window"&&we(P,a[l].points)){a[l].isDel=!0;break}if(p==="window"&&Ye(c,P,a[l].points,w[x].points)&&(Math.abs(h-M)<.1||Math.abs(h-f)>.3)){a[l].isDel=!0;break}}let g=!1,b=[],z=[];const v=a[l].points,S=w[x].points;if(v.length>S.length?(g=!0,b=v,z=S):(b=S,z=v),qr(z,b,.03,.5)>.5)if(g)w[x].isDel=!0;else{a[l].isDel=!0;break}else if(Ye(c,P)){const D=Dn(c,P);if(D===1||D===0){if(p==="switch")continue;v.length>S.length?pe(z,c)>=.5&&(w[x].isDel=!0):pe(b,c)>=.5&&(w[x].isDel=!0)}else{if(s==="switch")continue;if(v.length>S.length){if(pe(b,P)>=.5){a[l].isDel=!0;break}}else if(pe(z,P)>=.5){a[l].isDel=!0;break}}}}}}if(a[l].isDel)break}}}for(let r=0;r<t.length;r++){const s=t[r].type,a=t[r].array;for(let l=0;l<a.length;l++){let c=a[l].maxz,h=a[l].minz,f=s==="switch"?.1:.3;const u=a[l].averagePz;if(Math.abs(c-u)<f){a[l].isDel=!0;continue}if(s==="window"||s==="door"||s==="tv"){const p=Math.abs(c-u),w=Math.abs(h-u);(s==="tv"&&w<1.6||s!=="window"&&p<1.6)&&(a[l].isDel=!0),s==="window"&&p<1&&(a[l].isDel=!0)}if(s==="chair"){const p=new y.Vector3;a[l].obb.getSize(p),(p.x<.1||p.y<.1||p.z<.2)&&(a[l].isDel=!0)}s==="balcony railing"&&(Math.abs(c-h)<.4&&(a[l].isDel=!0),(h<u&&Math.abs(h-u)>1||h>u&&Math.abs(h-u)>1)&&(a[l].isDel=!0),c<u&&(a[l].isDel=!0)),s==="people"&&(Math.abs(c-h)<1&&(a[l].isDel=!0),h>u&&h-u>.3&&(a[l].isDel=!0),c<u&&(a[l].isDel=!0)),s==="floor"&&a[l].points.length<500&&(a[l].isDel=!0)}}for(let r=0;r<t.length;r++)t[r].array=t[r].array.filter(s=>!s.isDel);const i=[];for(let r=0;r<t.length;r++){const s=t[r].array;for(let a=0;a<s.length;a++)i.push({obbBox:s[a].obb,box:new y.Box3().setFromPoints(s[a].points),category:s[a].type,center:{x:s[a].center.x,y:s[a].center.y,z:(s[a].minz+s[a].maxz)/2},name:s[a].obj_id,obj_id:s[a].obj_id,pcdPoints:s[a].points,positionArr:s[a].positionArr})}return i};function be(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Hr(n){let t=0,e=0,o=0;for(let i=0;i<4;i++){const r=n[i],s=n[(i+1)%4],a=s.x-r.x,l=s.y-r.y,c=Math.sqrt(a*a+l*l);c>t&&(t=c,e=a/c,o=l/c)}return{longSide:t,dirX:e,dirY:o}}function Qe(n,t,e){const i=[];for(const r of n){const s=(r.start.x+r.end.x)/2,a=(r.start.y+r.end.y)/2,l=s-t,c=a-e;l*l+c*c<=3*3&&i.push(r.start.z,r.end.z)}if(i.length===0){const r=[];for(const s of n)r.push(s.start.z,s.end.z);return r.length?(r.sort((s,a)=>s-a),r[Math.floor(r.length/2)]):-1/0}return i.sort((r,s)=>r-s),i[Math.floor(i.length/2)]}function Gn(n,t,e,o,i,r){const s=i-e,a=r-o,l=s*s+a*a;if(l<1e-12)return{dist:Math.sqrt((n-e)**2+(t-o)**2),t:0};const c=n-e,h=t-o,f=(c*s+h*a)/l,u=e+f*s,p=o+f*a;return{dist:Math.sqrt((n-u)**2+(t-p)**2),t:f}}function Yr(n,t,e=.15){let o=0,i=0;for(const s of t)s!==n&&((be(n.start,s.start)<=e||be(n.start,s.end)<=e)&&o++,(be(n.end,s.start)<=e||be(n.end,s.end)<=e)&&i++);let r=0;return o>=1&&i>=1?r=5:(o>=1||i>=1)&&(r=2),{left:o,right:i,score:r}}function $r(n,t){const e=[],{start:o,end:i}=n;for(const a of t){const{dist:l}=Gn(a.x,a.y,o.x,o.y,i.x,i.y);e.push(l)}const r=e.reduce((a,l)=>a+l,0)/e.length,s=e.reduce((a,l)=>a+(l-r)**2,0)/e.length;return s<.01?3:s<.05?2:s<.1?1:0}function Gr(n,t,e=.15){const o=n.end.x-n.start.x,i=n.end.y-n.start.y,r=Math.sqrt(o*o+i*i);if(r<1e-12)return 0;const s=-i/r,a=o/r,l=[[],[]];for(let f=0;f<2;f++){const u=f===0?n.start:n.end;for(const p of t){if(p===n)continue;const w=be(u,p.start),x=be(u,p.end);let P=null;if(w<=e?P=p.end:x<=e&&(P=p.start),!P)continue;const M=p.end.x-p.start.x,m=p.end.y-p.start.y,d=Math.sqrt(M*M+m*m);if(d<1e-12||Math.abs(o*M+i*m)/(r*d)>=.342)continue;const b=(P.x-u.x)*s+(P.y-u.y)*a;l[f].push(b>0?1:-1)}}if(l[0].length===0||l[1].length===0)return 0;const c=[...l[0],...l[1]];return c.every(f=>f===c[0])?2:1}function jr(n,t,e){const o=Yr(n,e),i=$r(n,t),r=Gr(n,e);return{score:o.score*3+i*2+r*2,details:{conn:o.score,variance:i,sameSide:r}}}function Ur(n){const t=n.end.x-n.start.x,e=n.end.y-n.start.y;let o=Math.atan2(e,t)*(180/Math.PI);return o<0&&(o+=180),o}function Zr(n,t){const e=[];for(const o of n){let i=!1;for(const r of e){const s=Math.abs(o.angle-r[0].angle);if(Math.min(s,180-s)<=t){r.push(o),i=!0;break}}i||e.push([o])}return e}function Kr(n,t=.05){const e=[];for(const o of n){let i=!1;for(const r of e)if(Math.abs(o.offset-r[0].offset)<=t){r.push(o),i=!0;break}i||e.push([o])}return e}function Qr(n,t,e,o,i){const r=[];for(const a of n){const l=a.seg,c=(l.start.x-t.start.x)*e+(l.start.y-t.start.y)*o,h=(l.end.x-t.start.x)*e+(l.end.y-t.start.y)*o;r.push({l:Math.min(c,h),r:Math.max(c,h),idx:a.idx})}r.sort((a,l)=>a.l-l.l);const s=[];for(const{l:a,r:l,idx:c}of r){if(s.length===0){s.push({l:a,r:l,srcIdxs:[c]});continue}const h=s[s.length-1];a<=h.r+i?(h.r=Math.max(h.r,l),h.srcIdxs.includes(c)||h.srcIdxs.push(c)):s.push({l:a,r:l,srcIdxs:[c]})}return s}function Jr(n,t,e,o,i,r,s){const a=e-t,l={...n};return l.start={x:n.start.x+t*o,y:n.start.y+t*i,z:n.start.z},l.end={x:n.start.x+e*o,y:n.start.y+e*i,z:n.start.z},l.length=a,l.direction={x:o,y:i,z:0},l.rooftopPz=r,l.buildRosource=s,l.isRebuild=!1,l.doorAndBeamData||(l.doorAndBeamData=[]),l.insetionArr||(l.insetionArr=[]),l}function ti(n,t){let e=!0;for(;e;){e=!1;for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){const r=n[o],s=n[i];if(r.rooftopPz!==void 0&&s.rooftopPz!==void 0&&Math.abs(r.rooftopPz-s.rooftopPz)>.05)continue;const a=Math.abs(r.end.x-s.start.x)<.001&&Math.abs(r.end.y-s.start.y)<.001,l=Math.abs(r.start.x-s.end.x)<.001&&Math.abs(r.start.y-s.end.y)<.001,c=Math.abs(r.end.x-s.end.x)<.001&&Math.abs(r.end.y-s.end.y)<.001,h=Math.abs(r.start.x-s.start.x)<.001&&Math.abs(r.start.y-s.start.y)<.001;if(!(a||l||c||h)||r.direction.x*s.direction.x+r.direction.y*s.direction.y<.98)continue;let u=r.start,p=r.end;a?p=s.end:l?u=s.start:c?p=s.start:h&&(u=s.end);const w=Math.hypot(p.x-u.x,p.y-u.y),x={...r};x.start=u,x.end=p,x.length=w,x.direction={x:(p.x-u.x)/w,y:(p.y-u.y)/w,z:0},x.rooftopPz=r.rooftopPz!==void 0?r.rooftopPz:s.rooftopPz,x.buildRosource=r.buildRosource||s.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),n[o]=x,t[o]=[...new Set([...t[o],...t[i]])],n.splice(i,1),t.splice(i,1),i--,e=!0}}return{segments:n,sourceMap:t}}function Je(n,t=5,e=.05){if(n.length<=1)return{segments:n,sourceMap:n.map((l,c)=>[c])};const o=n.map((l,c)=>({seg:l,angle:Ur(l),idx:c}));o.sort((l,c)=>l.angle-c.angle);const i=Zr(o,t),r=[],s=[],a=[];for(const l of i){let c=l[0].seg;for(const M of l)M.seg.length>c.length&&(c=M.seg);const h=c.end.x-c.start.x,f=c.end.y-c.start.y,u=Math.sqrt(h*h+f*f);if(u<1e-12)continue;const p=-f/u,w=h/u,x=l.map(M=>{const m=M.seg.start.x-c.start.x,d=M.seg.start.y-c.start.y;return{seg:M.seg,offset:Math.abs(m*p+d*w),idx:M.idx}});x.sort((M,m)=>M.offset-m.offset);const P=Kr(x);for(const M of P){let m=M[0].seg;for(const T of M)T.seg.length>m.length&&(m=T.seg);const d=m.end.x-m.start.x,g=m.end.y-m.start.y,b=Math.sqrt(d*d+g*g);if(b<1e-12)continue;const z=d/b,v=g/b,S=M.map(T=>T.seg.rooftopPz??0),V=Math.max(...S),D=[...new Set(S.map(T=>T.toFixed(3)))];if(D.length>1){const T=M.map(E=>({idx:E.idx,start:{x:E.seg.start.x,y:E.seg.start.y,z:E.seg.start.z},end:{x:E.seg.end.x,y:E.seg.end.y,z:E.seg.end.z},length:E.seg.length,rooftopPz:E.seg.rooftopPz??0}));a.push({values:[...D],segments:T})}[...new Set(M.map(T=>String(T.seg.buildRosource)))];const _=Qr(M,m,z,v,e);for(const{l:T,r:E,srcIdxs:A}of _){if(E-T<.01)continue;const F=Jr(m,T,E,z,v,V,m.buildRosource);r.push(F),s.push(A)}}}return{...ti(r,s),debugRPZGroups:a}}function ei(n){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...n}}function ni(n,t,e){return[{x:t,y:e,z:0},{x:n[0].x,y:n[0].y,z:0},{x:n[1].x,y:n[1].y,z:0},{x:n[2].x,y:n[2].y,z:0},{x:n[3].x,y:n[3].y,z:0}]}function oi(n,t,e,o,i,r,s){const a=[{margin:r.projectionMargin,maxDist:r.maxDistance,label:"严格"},{margin:.4,maxDist:.65,label:"宽松"}];let l=[];for(const c of a){if(l.length>0)break;for(const h of n){const f=t*r.minLengthRatio;if(h.length<f)continue;const{start:u,end:p}=h;let w=!1,x=1/0;for(const S of i){const{dist:V,t:D}=Gn(S.x,S.y,u.x,u.y,p.x,p.y);D>=-c.margin&&D<=1+c.margin&&V<=c.maxDist&&(w=!0,x=Math.min(x,V))}if(!w){`${c.maxDist}${(-c.margin).toFixed(1)}${(1+c.margin).toFixed(1)}`;continue}const P=Math.sqrt((p.x-u.x)**2+(p.y-u.y)**2);if(P<1e-12)continue;const M=(p.x-u.x)/P,m=(p.y-u.y)/P,d=Math.abs(e*M+o*m),g=Math.abs(-o*M+e*m),b=Math.max(d,g),z=Math.acos(Math.min(b,1))*(180/Math.PI);if(z>r.angleThreshold){`${z.toFixed(1)}${r.angleThreshold}`;continue}let v=0;if(P>.01){const S=[];for(let _=1;_<=4;_++){const T=i[_],E=T.x-u.x,A=T.y-u.y,F=(E*M+A*m)/P;S.push(F)}const V=Math.min(...S),D=Math.max(...S);D>V&&(v=Math.max(0,Math.min(1,D)-Math.max(0,V))/(D-V))}l.push({seg:h,minDist:x,embedRatio:v,ratio:h.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return l}function ri(n,t,e,o){if(n.length<=1)return n.length===1&&(n[0].score=-1),n;for(const i of n){const{score:r,details:s}=jr(i.seg,t,e);i.score=r,i.details=s}return n.sort((i,r)=>r.embedRatio-i.embedRatio||r.score-i.score||i.minDist-r.minDist),n}function ii(n,t,e,o){const i=n.end.x-n.start.x,r=n.end.y-n.start.y,s=Math.sqrt(i*i+r*r),a=i/s,l=r/s,c=t.map(v=>{const S=v.x-n.start.x,V=v.y-n.start.y;return(S*a+V*l)/s}),h=Math.min(...c),f=Math.max(...c),u=(f-h)*s,p=(h+f)/2,w=n.start.x+p*i,x=n.start.y+p*r,P=e.box.min.z,M=e.box.max.z,m=Math.abs(M-P),d=Qe(o,n.start.x,n.start.y),g=Math.max(0,P-d),b=h<=0&&f>=1,z=n.start.z+p*(n.end.z-n.start.z);return{p:{x:w,y:x,z},width:u,full:b,height:m,groundClearance:g}}function jn(n,t,e){var h,f,u,p,w;const o=t.map(x=>e[x]),i=[],r=[],s=[],a=[],l=[];let c;for(const x of o){if((h=x.points)!=null&&h.length)for(const P of x.points)i.push(P);if((f=x.originalPoints)!=null&&f.length)for(const P of x.originalPoints)r.push(P);if((u=x.doorAndBeamData)!=null&&u.length)for(const P of x.doorAndBeamData)s.push(P);if((p=x.insetionArr)!=null&&p.length)for(const P of x.insetionArr)a.push(P);if((w=x.drawWindow)!=null&&w.length)for(const P of x.drawWindow)l.push(P);x.boxData&&!c&&(c=x.boxData)}i.length&&(n.points=i),r.length&&(n.originalPoints=r),s.length&&(n.doorAndBeamData=s),a.length&&(n.insetionArr=a),l.length&&(n.drawWindow=l),c&&(n.boxData=c)}function Un(n,t,e){var l;const o=ei(e),i=[],{segments:r,sourceMap:s}=Je(t),a=r;for(const c of n){const h=(l=c.coordinatesByArea)==null?void 0:l.coordinates;if(!h||h.length<4)continue;const f=h.slice(0,4),u=f.reduce((V,D)=>V+D.x,0)/4,p=f.reduce((V,D)=>V+D.y,0)/4,{longSide:w,dirX:x,dirY:P}=Hr(f);if(w<.01)continue;const M=f.reduce((V,D)=>V+D.z,0)/4,m=Qe(t,u,p);if(M<m-.3)continue;const d=ni(f,u,p);c.name;let g=oi(a,w,x,P,d,o,c.name);g=ri(g,d,t,c.name);let b=null,z=1/0,v=0;if(g.length>0){const V=g[0];b=V.seg,z=V.minDist,v=V.ratio}let S;if(b&&(S=ii(b,f,c,r),!o.printOnly)){const V=b;V.drawWindow||(V.drawWindow=[]),V.drawWindow.push(S)}b&&i.push({windowName:c.name,windowCategory:c.category,windowCenter:c.center,wallSegment:b,distance:z,wallLengthRatio:v,drawWindow:S})}for(const c of i){const h=c.wallSegment,f=r.indexOf(h);if(f===-1)continue;const u=s[f];!u||u.length<=1||jn(h,u,t)}return i}function si(n,t,e){const o={printOnly:!1,...e},i=Array.isArray(t)?t.filter(c=>c&&c.category==="window"&&!c.isBayWindowObj):[],r=Un(i,n,o),{segments:s,sourceMap:a}=Je(n);for(let c=0;c<s.length;c++){const h=a[c];h&&jn(s[c],h,n)}const l=new Set(r.map(c=>c.windowName));for(const c of t)c&&c.category==="window"&&!c.isBayWindowObj&&(l.has(c.name)?delete c.AbnormalWindow:c.AbnormalWindow=!0);for(const c of r)if(c.drawWindow){const h=s.find(f=>Math.abs(f.start.x-c.wallSegment.start.x)<.01&&Math.abs(f.start.y-c.wallSegment.start.y)<.01&&Math.abs(f.end.x-c.wallSegment.end.x)<.01&&Math.abs(f.end.y-c.wallSegment.end.y)<.01);h&&(h.drawWindow||(h.drawWindow=[]),h.drawWindow.push(c.drawWindow))}return{segments:s,matches:r,sourceMap:a}}exports.computeContour=Ge;exports.computeLocalFloorZ=Qe;exports.findWindowWalls=Un;exports.getAllGeometry=mo;exports.getBeamLine=Vo;exports.getColLine=zo;exports.getMergeMeaning=Xr;exports.mergeCollinearSegments=Je;exports.processData=si;exports.updateStEdPoint=go;