rm-graphical-computing 1.0.58 → 1.0.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +4933 -4623
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(e&&(t=e(e=0)),t),s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,a)=>(a=n==null?{}:e(i(n)),l(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e);let f=require(`three`);f=u(f);function p(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new f.BufferGeometry,l=0;for(let u=0;u<e.length;++u){let d=e[u],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(let e in d.attributes){if(!r.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`),null;a[e]===void 0&&(a[e]=[]),a[e].push(d.attributes[e]),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(let e in d.morphAttributes){if(!i.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. .morphAttributes must be consistent throughout all geometries.`),null;o[e]===void 0&&(o[e]=[]),o[e].push(d.morphAttributes[e])}if(t){let e;if(n)e=d.index.count;else if(d.attributes.position!==void 0)e=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;c.addGroup(l,e,u),l+=e}}if(n){let t=0,n=[];for(let r=0;r<e.length;++r){let i=e[r].index;for(let e=0;e<i.count;++e)n.push(i.getX(e)+t);t+=e[r].attributes.position.count}c.setIndex(n)}for(let e in a){let t=m(a[e]);if(!t)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` attribute.`),null;c.setAttribute(e,t)}for(let e in o){let t=o[e][0].length;if(t===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[e]=[];for(let n=0;n<t;++n){let t=[];for(let r=0;r<o[e].length;++r)t.push(o[e][r][n]);let r=m(t);if(!r)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` morphAttribute.`),null;c.morphAttributes[e].push(r)}}return c}function m(e){let t,n,r,i=-1,a=0;for(let o=0;o<e.length;++o){let s=e[o];if(t===void 0&&(t=s.array.constructor),t!==s.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=s.itemSize),n!==s.itemSize)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.`),null;if(r===void 0&&(r=s.normalized),r!==s.normalized)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.`),null;if(i===-1&&(i=s.gpuType),i!==s.gpuType)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.`),null;a+=s.count*n}let o=new t(a),s=new f.BufferAttribute(o,n,r),c=0;for(let t=0;t<e.length;++t){let r=e[t];if(r.isInterleavedBufferAttribute){let e=c/n;for(let t=0,i=r.count;t<i;t++)for(let i=0;i<n;i++){let n=r.getComponent(t,i);s.setComponent(t+e,i,n)}}else o.set(r.array,c);c+=r.count*n}return i!==void 0&&(s.gpuType=i),s}var h=class extends f.Object3D{constructor(e=document.createElement(`div`)){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position=`absolute`,this.element.style.userSelect=`none`,this.element.setAttribute(`draggable`,!1),this.center=new f.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(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this.center=e.center,this}};new f.Vector3,new f.Matrix4,new f.Matrix4,new f.Vector3,new f.Vector3;var g=(e,t,n)=>{let r=new f.LineBasicMaterial({color:`#0011ff`}),i=[];i.push(e),i.push(t);let a=new f.BufferGeometry;a.setFromPoints(i),a.rotateX(-Math.PI/2),n.add(new f.Line(a,r))},_=(e,t,n,r,i=1e-8)=>{let a=t.x-e.x,o=t.y-e.y,s=r.x-n.x,c=r.y-n.y,l=a*c-o*s;if(Math.abs(l)<i)return null;let u=((n.x-e.x)*c-(n.y-e.y)*s)/l,d=((n.x-e.x)*o-(n.y-e.y)*a)/l;return u<-i||u>1+i||d<-i||d>1+i?null:{point:new f.Vector3(e.x+u*a,e.y+u*o,e.z)}},v=(e,t,n={})=>{let{fontSize:r=36,fontFamily:i=`sans-serif`,backgroundColor:a=`rgba(0,0,0,0)`,textColor:o=`#ffffff`,padding:s=10,maxWidth:c=256}=n,l=document.createElement(`canvas`).getContext(`2d`);l.font=`bold ${r}px ${i}`;let u=l.measureText(e).width,d=Math.min(u+s*2,c),p=r+s*2,m=document.createElement(`canvas`);m.width=d,m.height=p;let h=m.getContext(`2d`);h.fillStyle=a,h.fillRect(0,0,d,p),h.fillStyle=o,h.font=`bold ${r}px ${i}`,h.textAlign=`center`,h.textBaseline=`middle`,u>c-s*2?y(h,e,d/2,p/2,c,r):h.fillText(e,d/2,p/2);let g=new f.CanvasTexture(m),_=new f.SpriteMaterial({map:g,depthTest:!1,transparent:!0}),v=new f.Sprite(_);v.position.set(t.x,t.y,t.z);let b=.005;return v.scale.set(d*b,p*b,1),v};function y(e,t,n,r,i,a){let o=t.split(``),s=``,c=a*1.2,l=r;for(let t=0;t<o.length;t++){let r=s+o[t];e.measureText(r).width>i&&t>0?(e.fillText(s,n,l),s=o[t],l+=c):s=r}e.fillText(s,n,l)}var b=(e,t,n=.01)=>{let r=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z),i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(r<1e-10||i<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};let a={x:e.x/r,y:e.y/r,z:e.z/r},o={x:t.x/i,y:t.y/i,z:t.z/i},s=a.x*o.x+a.y*o.y+a.z*o.z;s=Math.max(-1,Math.min(1,s));let c=Math.acos(Math.abs(s)),l=c<=n;return{parallel:l,sameDirection:l?s>0:null,angle:c}};function x(e,t,n){let r=new f.BufferGeometry,i=[],a=[];e.forEach(e=>i.push(e.x,e.y,e.z)),t.forEach(e=>i.push(e.x,e.y,e.z)),a.push(0,2,1,0,3,2),a.push(4,5,6,4,6,7),a.push(0,1,5,0,5,4),a.push(1,2,6,1,6,5),a.push(2,3,7,2,7,6),a.push(3,0,4,3,4,7),r.setAttribute(`position`,new f.Float32BufferAttribute(i,3)),r.setIndex(a),r.computeVertexNormals();let o=new f.MeshBasicMaterial({color:n==`door`?`green`:`#a7cc00`,transparent:!0,opacity:.5,side:f.DoubleSide});return new f.Mesh(r,o)}var S=class{constructor(e={}){this.config={value:e.value||`0.0000m`,position:e.position||new f.Vector3(0,0,0),style:{fontFamily:e.style?.fontFamily||`Arial, sans-serif`,fontSize:e.style?.fontSize||`16px`,fontWeight:e.style?.fontWeight||`normal`,fontStyle:e.style?.fontStyle||`normal`},backgroundOpacity:e.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 h(this.labelElement),this.label.position.copy(this.config.position),this.label}applyBlackWhiteStyle(){let e=this.labelElement.style,t=this.config;e.fontFamily=t.style.fontFamily,e.fontSize=t.style.fontSize,e.fontWeight=t.style.fontWeight,e.fontStyle=t.style.fontStyle,e.color=`#FFFFFF`,e.textShadow=`0 1px 2px rgba(0, 0, 0, 0.5)`,e.backgroundColor=`rgba(0, 0, 0, ${t.backgroundOpacity})`,e.padding=`6px 12px`,e.borderRadius=`4px`,e.position=`absolute`,e.whiteSpace=`nowrap`,e.userSelect=`none`,e.pointerEvents=`none`,e.zIndex=`1000`,e.textAlign=`center`,e.lineHeight=`1.2`}updateValue(e){this.labelElement&&(this.labelElement.textContent=e)}updatePosition(e){this.label&&this.label.position.copy(e)}updateFontStyle(e){if(this.labelElement){let t=this.labelElement.style;e.fontFamily&&(t.fontFamily=e.fontFamily),e.fontSize&&(t.fontSize=e.fontSize),e.fontWeight&&(t.fontWeight=e.fontWeight),e.fontStyle&&(t.fontStyle=e.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}},C=e=>{let t=new f.Group,n=new f.Group;if(e&&e.length){let 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`.split(`.`);e.forEach((e,i)=>{let a=r[i],o=new f.Group,{pcdPoints:s,category:c,name:l,center:u,box:d,obbBox:p,contour:m,nline:h,coordinatesByWidth:g,coordinatesByArea:_}=e,v=s.length,y=new f.Box3(new f.Vector3(d.min.x,d.min.y,d.min.z),new f.Vector3(d.max.x,d.max.y,d.max.z)),b=new f.Box3Helper(y,a);o.add(b);let C=new S({value:l,position:new f.Vector3(u.x,u.y,u.z)}).getLabel();o.add(C);let w=new f.InstancedMesh(new f.SphereGeometry(.007,8,8),new f.MeshBasicMaterial({color:a}),v);o.add(w);let T=new f.Matrix4,E=0;if(s.forEach(e=>{T.setPosition(e.x,e.y,e.z),w.setMatrixAt(E,T),E++}),w.instanceMatrix.needsUpdate=!0,h){let e=new f.BufferGeometry;e.setFromPoints([new f.Vector3(h.start.x,h.start.y,h.start.z),new f.Vector3(h.end.x,h.end.y,h.end.z)]);let t=new f.LineBasicMaterial({color:`red`,depthTest:!1,depthWrite:!1});new f.Line(e,t);let n=new f.Vector3().copy(new f.Vector3(h.start.x,h.start.y,h.start.z)).add(new f.Vector3(h.end.x,h.end.y,h.end.z)).multiplyScalar(.5),r=new f.Vector3(h.centerDir.x,h.centerDir.y,h.centerDir.z);new f.ArrowHelper(r,n,1,`red`)}if(m){let e=[];m.forEach((t,n)=>{e.push(new f.Vector3(t.x,t.y,t.z))});let r=new f.BufferGeometry;r.setFromPoints(e);let i=new f.LineBasicMaterial({color:`yellow`,depthTest:!1,depthWrite:!1}),a=new f.Line(r,i);c==`door`?t.add(a):n.add(a)}if(_){let e=[],r=[];_.coordinates.forEach((t,n)=>{e.push(new f.Vector3(t.x,t.y,t.z)),r.length<4&&r.push(new f.Vector3(t.x,t.y,t.z))});let i=new f.BufferGeometry;i.setFromPoints(e);let a=new f.LineBasicMaterial({color:`green`,depthTest:!1,depthWrite:!1}),o=new f.Line(i,a);c==`door`?t.add(o):n.add(o);let s=x(r.map(e=>new f.Vector3(e.x,e.y,_.heightData.minZ)),r.map(e=>new f.Vector3(e.x,e.y,e.z)),c);c==`door`?t.add(s):n.add(s);let[l,u,d]=e,p=l.distanceTo(u),m=new f.Vector3().copy(l).add(u).multiplyScalar(.5);new S({value:String(p.toFixed(3)),position:m}).getLabel();let h=u.distanceTo(d),g=new f.Vector3().copy(u).add(d).multiplyScalar(.5);new S({value:String(h.toFixed(3)),position:g}).getLabel()}if(p&&p.size&&p.center&&p.rotation){let e=new f.BoxGeometry(p.size.x,p.size.y,p.size.z),r=new f.LineBasicMaterial({color:a,linewidth:2}),i=new f.EdgesGeometry(e),o=new f.LineSegments(i,r),s=new Vector3(p.center.x,p.center.y,p.center.z),l=new Quaternion(p.rotation.x,p.rotation.y,p.rotation.z,p.rotation.w);o.position.copy(s),o.quaternion.copy(l),c==`door`?t.add(o):n.add(o)}})}return{AiProjectionGroup:t,AiProjectionGroup2:n}},w=(e,t,n,r)=>{let i=e,a=[];if(r&&r.length&&(a=r.map(e=>e.clone())),!i||i.length<4)return{};let o=new f.Vector3().subVectors(i[1],i[0]).normalize(),s=new f.Vector3().subVectors(i[3],i[0]).normalize(),c=o.clone().cross(s).normalize(),l=1/0,u=-1/0,d=1/0,p=-1/0;for(let e of i){let t=e.dot(o),n=e.dot(s);t<l&&(l=t),t>u&&(u=t),n<d&&(d=n),n>p&&(p=n)}let m=i[0].dot(c),h=o.clone().multiplyScalar(l).add(s.clone().multiplyScalar(d)).add(c.clone().multiplyScalar(m)),g=o.clone().multiplyScalar(u).add(s.clone().multiplyScalar(d)).add(c.clone().multiplyScalar(m)),_=o.clone().multiplyScalar(u).add(s.clone().multiplyScalar(p)).add(c.clone().multiplyScalar(m)),v=o.clone().multiplyScalar(l).add(s.clone().multiplyScalar(p)).add(c.clone().multiplyScalar(m)),y=[h,g,_,v],x=b(new f.Vector3().subVectors(h,g),new f.Vector3(0,0,1));x&&x.parallel&&(y=[h,v,_,g]);let S=0;if(r.length>0){let e=new f.Vector3().subVectors(y[1],y[0]).normalize(),r=e.clone().negate(),i=new f.Vector3().subVectors(y[3],y[0]).normalize(),o=i.clone().negate(),s=y[0].distanceTo(y[1]),c=y[0].distanceTo(y[3]),l=s/t,u=c/n,d=.001;for(let r=0;r<l;r++){let r=y[0],o=0;for(let s=0;s<u;s++){let s=r.clone().addScaledVector(e,t),c=s.clone().addScaledVector(i,n),l=r.clone().addScaledVector(i,n),u=new f.Vector3().add(r).add(s).add(c).add(l).multiplyScalar(.25);for(let e=0;e<a.length;e++)if(a[e].distanceTo(u)<d){o++;break}r=l}if(o>=u/2)break;S+=o,y[0]=y[0].addScaledVector(e,t),y[3]=y[3].addScaledVector(e,t)}s=y[0].distanceTo(y[1]),l=s/t;for(let e=0;e<l;e++){let e=y[1],o=0;for(let s=0;s<u;s++){let s=e.clone().addScaledVector(r,t),c=s.clone().addScaledVector(i,n),l=e.clone().addScaledVector(i,n),u=new f.Vector3().add(e).add(s).add(c).add(l).multiplyScalar(.25);for(let e=0;e<a.length;e++)if(a[e].distanceTo(u)<d){o++;break}e=l}if(o>=u/2)break;S+=o,y[1]=y[1].addScaledVector(r,t),y[2]=y[2].addScaledVector(r,t)}s=y[0].distanceTo(y[1]),l=s/t;for(let r=0;r<u;r++){let r=y[3],i=0;for(let s=0;s<l;s++){let s=r.clone().addScaledVector(e,t),c=s.clone().addScaledVector(o,n),l=r.clone().addScaledVector(o,n),u=new f.Vector3().add(r).add(s).add(c).add(l).multiplyScalar(.25);for(let e=0;e<a.length;e++)if(a[e].distanceTo(u)<d){i++;break}r=s}if(i>=l/2)break;S+=i,y[2]=y[2].addScaledVector(o,n),y[3]=y[3].addScaledVector(o,n)}}let C=y[0].distanceTo(y[1])*y[0].distanceTo(y[3]);return{facePoints:y,boxArea:C,totalInPlaneNum:S}},T=(e,t,n,r,i=f.MathUtils.degToRad(8))=>{let a=new f.Vector3,o=new f.Vector3;a.subVectors(new f.Vector3(t.x,t.y,0),new f.Vector3(e.x,e.y,0)).normalize(),o.subVectors(new f.Vector3(r.x,r.y,0),new f.Vector3(n.x,n.y,0)).normalize();let s=a.dot(o),c=Math.acos(Math.min(Math.abs(s),1)),l=1-Math.min(c/i,1),u=s>0?`same`:`opposite`;return{parallelism:l,angle:c,angleDeg:f.MathUtils.radToDeg(c),isParallel:c<i,direction:u,vectors:{v1:a,v2:o}}},E=(e,t,n,r)=>{let i=new f.Vector3().subVectors(t,e),a=new f.Vector3().subVectors(r,n),o=i.length(),s=a.length();if(o===0||s===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};i.normalize(),a.normalize();let c=Math.abs(i.dot(a)),l=Math.min(1,Math.max(0,c)),u=Math.acos(l),d=f.MathUtils.radToDeg(u),p=1-l;return{rate:p,percent:`${(p*100).toFixed(2)}%`,angle:d,isPerpendicular:Math.abs(d-90)<.01,isParallel:d<.01}},D=(e,t,n=!1)=>new f.Vector3((e.x+t.x)/2,(e.y+t.y)/2,n?0:(e.z+t.z)/2),O=(e,t,n,r,i={})=>{let{parallelAngleMax:a=f.MathUtils.degToRad(10),collinearAngleMax:o=f.MathUtils.degToRad(7),distanceThreshold:s=2,overlapThreshold:c=.01}=i,l=new f.Vector3().subVectors(t,e),u=new f.Vector3().subVectors(r,n),d=l.clone().normalize(),p=u.clone().normalize(),m=f.MathUtils.clamp(d.dot(p),-1,1),h=Math.acos(Math.abs(m)),g=f.MathUtils.radToDeg(h);if(h>a)return{type:`not_parallel`,angleDeg:g,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};m<0&&p.negate();let _=new f.Vector3().addVectors(d,p).normalize(),v=new f.Vector3().addVectors(e,t).multiplyScalar(.5),y=k(n,v,d),b=k(r,v,d),x=(y+b)/2,S=Math.max(y,b),C=e.dot(_),w=t.dot(_),T=n.dot(_),E=r.dot(_),D=Math.min(C,w),O=Math.max(C,w),j=Math.min(T,E),M=Math.max(T,E),N=O-D,P=M-j,F=Math.min(N,P),I=Math.min(O,M)-Math.max(D,j),L=I<0?-I:0,ee=I>0?I:0,R=F>0?ee/F:0,z=A(e,t,n,r),B=h<=o&&x<s,V;return B?V=R>.5?`collinear_overlap`:`collinear_gap`:h<=a&&(V=`parallel_offset`),{type:V,angleDeg:g,avgPerpendicularDistance:x,maxPerpendicularDistance:S,gap:L,overlap:ee,closestDistance:z}};function k(e,t,n){let r=new f.Vector3().subVectors(e,t),i=r.dot(n),a=n.clone().multiplyScalar(i);return new f.Vector3().subVectors(r,a).length()}function A(e,t,n,r){let i=new f.Vector3().subVectors(t,e),a=new f.Vector3().subVectors(r,n),o=new f.Vector3().subVectors(n,e),s=i.dot(i),c=i.dot(a),l=a.dot(a),u=i.dot(o),d=a.dot(o),p=s*l-c*c,m,h;p<1e-10?(m=0,h=l===0?0:d/l):(m=(c*d-l*u)/p,h=(s*d-c*u)/p),m=f.MathUtils.clamp(m,0,1),h=l===0?0:f.MathUtils.clamp((c*m+d)/l,0,1),m=s===0?0:f.MathUtils.clamp((c*h-u)/s,0,1);let g=e.clone().add(i.clone().multiplyScalar(m)),_=n.clone().add(a.clone().multiplyScalar(h));return g.distanceTo(_)}var j=(e,t,n,r=.05,i=.02)=>{let[a,o,s,c]=e,l=new f.Vector3().subVectors(o,a),u=new f.Vector3().subVectors(c,a),d=new f.Vector3().crossVectors(l,u).normalize(),p=l.length(),m=u.length(),h=l.clone().normalize(),g=u.clone().normalize(),_=n-r,v=n+r,y=new f.Vector3,b=[],x=Math.ceil(p/i),S=Math.ceil(m/i),C=p/x,w=m/S,T=new Uint8Array(x*S);for(let e=0;e<t.length;e++){y.subVectors(t[e],a);let n=Math.abs(y.dot(d));if(n<_||n>v)continue;let r=y.dot(h),i=y.dot(g);if(r<0||r>p||i<0||i>m)continue;b.push(new f.Vector3(t[e].x,t[e].y,t[e].z));let o=Math.min(Math.floor(r/C),x-1),s=Math.min(Math.floor(i/w),S-1);T[s*x+o]=1}let E=0;for(let e=0;e<T.length;e++)T[e]&&E++;let D=x*S,O=p*m,k=E==0||D==0?0:E/D*O;return{filteredPoints:b,coveragePercent:E==0||D==0?0:E/D*100,quadArea:O,coveredArea:k}},M=(e,t)=>Math.round(Math.max(5,Math.min(350,t*Math.sqrt(e)))),N=e=>{let t=new f.Vector3(e.start.x,e.start.y,e.start.z),n=new f.Vector3(e.end.x,e.end.y,e.end.z),r=t.distanceTo(n),i=e.rooftopPz-e.start.z,a=M(r,100),o=M(i,70),s=i/o,c=new Map;for(let e=0;e<o;e++)c.set((e+1)*s,{count:0,minZ:1/0,maxZ:-1/0});let l=new f.Line3(t,n),u=e.originalPoints,d=new f.Vector3;for(let e=0;e<u.length;e++){let t=u[e],n=l.closestPointToPoint(t,!0,d).distanceTo(t),r=Math.floor(n/s);if(r<o){let e=c.get((r+1)*s);e.count++,t.z<e.minZ&&(e.minZ=t.z),t.z>e.maxZ&&(e.maxZ=t.z)}}let p,m,h=a/2;for(let[e,t]of c)if(t.count>=h){p=t.minZ;break}for(let[e,t]of[...c.entries()].reverse())if(t.count>=h){m=t.maxZ;break}return{minZ:p,maxZ:m}},P=(e,t,n)=>{let r=new f.Plane,i=new f.Vector3(e.x,e.y,e.z),a=new f.Vector3(t.x,t.y,t.z),o=new f.Vector3(t.x,t.y,t.z+5);r.setFromCoplanarPoints(i,a,o);let s=[],c=[];n.forEach(e=>{let t=new f.Vector3;r.projectPoint(e,t),c.push(t.clone()),t.z=i.z,s.push(t)});let l=new f.Vector3,u=new f.Vector3;r.projectPoint(i,l),r.projectPoint(a,u);let d=new f.Line3(l,u),p=[],m=[],h=[],g=new f.Vector3;return s.forEach((e,t)=>{d.closestPointToPoint(e,!0,g).distanceTo(e)<.001?(p.push(n[t]),m.push(c[t])):h.push(e)}),{newOriginalPoints:p,newProjectPoints:h,newOnLinePoints:m}},F=e=>{function t(e,t,n,r,i,a,o,s,c){let l=new f.Line3(e,t),u=new Map,d=new f.Vector3,p=e.clone(),m=t.clone(),h=0;for(;;){let g=new Map,_=0;for(let e=0;e<c.checkResults.length;e++)if(!(c.checkResults[e].allCenterPoints.length/s*100<1))for(let t=0;t<c.checkResults[e].allCenterPoints.length;t++){if(u.has(e)&&u.get(e).removePtsIndex.includes(t))continue;let n=c.checkResults[e].allCenterPoints[t];n=new f.Vector3(n.x,n.y,n.z);let r=l.closestPointToPoint(n,!0,d),a=n.distanceTo(r);Math.abs(a-i)<.01&&(_++,g.has(e)?g.get(e).removePtsIndex.push(t):g.set(e,{index:e,removePtsIndex:[t]}))}if(h==o){e=p,t=m;break}if(_<a/20*18||_==0){g.clear(),o-h<5&&(e=p,t=m,u.clear());break}else{h++;for(let[e,t]of g)u.has(e)?u.get(e).removePtsIndex.push(...t.removePtsIndex):u.set(e,t);g.clear(),e=e.addScaledVector(n,r),t=t.addScaledVector(n,r),l.set(e,t)}}if(u.size>0&&h!=o)for(let[e,t]of u){let n=[],r=[];for(let i=0;i<c.checkResults[e].allCenterPoints.length;i++)t.removePtsIndex.includes(i)||(n.push(c.checkResults[e].allCenterPoints[i]),r.push(c.checkResults[e].originalVertices[i]));c.checkResults[e].allCenterPoints=n,c.checkResults[e].originalVertices=r}}for(let n=0;n<e.length;n++){let r=e[n];if(r.length<.5)continue;let i=-1,a=-1;if(!r.checkResults||r.checkResults.length<=0)continue;if(r.checkResults[0].originalVertices&&r.checkResults[0].originalVertices.length>0){let[e,t,n,o]=r.checkResults[0].originalVertices[0];e=new f.Vector3(e.x,e.y,e.z),t=new f.Vector3(t.x,t.y,t.z),n=new f.Vector3(n.x,n.y,n.z),o=new f.Vector3(o.x,o.y,o.z),i=e.distanceTo(t),a=e.distanceTo(o);let s=b(new f.Vector3().subVectors(e,t).normalize(),new f.Vector3(0,0,1));s&&s.parallel&&([a,i]=[i,a])}if(i<0||a<0)continue;let o=new f.Vector3(r.start.x,r.start.y,r.start.z),s=new f.Vector3(r.end.x,r.end.y,r.end.z),c=o.distanceTo(s),l=r.rooftopPz-r.start.z,u=Math.ceil(c/i),d=Math.ceil(l/a),p=o.clone(),m=s.clone(),h=m.clone().add(new f.Vector3(0,0,l)),g=p.clone().add(new f.Vector3(0,0,l)),_=new f.Vector3().subVectors(m,p).normalize(),v=_.clone().negate();new f.Vector3().subVectors(h,p).normalize().clone().negate();let y=i/2;a/2;let x=c*l/(i*a);t(p,g,_,i,y,d,u,x,r),t(m,h,v,i,y,d,u,x,r),r.start=p,r.end=m;let{newOriginalPoints:S}=P(p,m,r.originalPoints);r.originalPoints=S}},I=(e,t)=>new f.Vector3(e.x,e.y,0).distanceTo(new f.Vector3(t.x,t.y,0)),L=(e,t,n=1e-6)=>{let r=new f.Vector3;return e.closestPointToPoint(t,!0,r),r.distanceTo(t)<n},ee=e=>{let t=0,n=[];for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++){let a=e[r].distanceTo(e[i]);a>t&&(t=a,n=[e[r],e[i]])}return n},R=(e,t,n=.03)=>Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n&&Math.abs(e.z-t.z)<n,z=e=>{let t=[];e.children.forEach(e=>{e.type==`GridHelper`||e.type==`DirectionalLight`||e.type==`AmbientLight`||t.push(e)}),t.forEach(t=>{e.remove(t),V(t)})},B=()=>`#${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 V(e){for(;e.children&&e.children.length>0;){let t=e.children[0];e.remove(t),V(t)}e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>te(e)):te(e.material))}function te(e){for(let t of Object.keys(e)){let n=e[t];n&&typeof n==`object`&&typeof n.dispose==`function`&&n.dispose()}e.dispose()}var ne=(e,t=.001)=>{let n=new Map,r=[];for(let i of e){let e=`${Math.round(i.x/t)},${Math.round(i.y/t)},${Math.round(i.z/t)}`;n.has(e)||(n.set(e,!0),r.push(i))}return r},re=class{results;clusterResults;constructor(){this.results=null}initLimits1(e,t){let n,r;return n=e<.3?5:e<.5?8:e<.8?10:e<1?15:e<2?30:e<3?35:e<4?40:e<5?45:e<6?50:e<7?60:e<8.5?70:e<10?80:e<15?100:e<20?120:e<25?140:e<30?160:e<35?180:e<40?200:e<45?230:e<50?250:350,t<1?r=30:t<2?r=40:t<2.5?r=45:t<3?r=60:t<3.6?r=70:t<4&&(r=80),{horizontalSubdivisions:n,verticalSubdivisions:r}}initLimits2(e,t){return{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,e/.08))),verticalSubdivisions:Math.round(Math.max(30,Math.min(80,t/.06)))}}initLimits4(e,t){return{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,65*Math.sqrt(e))))*1,verticalSubdivisions:Math.round(Math.max(30,Math.min(80,15*Math.sqrt(t))))*1}}initLimits3(e,t){let n;return n=e<2?.06:e<10?.1:.15,{horizontalSubdivisions:Math.round(Math.max(5,Math.min(350,e/n))),verticalSubdivisions:Math.round(Math.max(30,Math.min(80,t/.06)))}}createWallPlaneMeshFromFourPoints(e,t,n,r,i,a,o=16777215){let s=[e,t,n,r];for(let e=0;e<s.length;e++)this.isValidVector3(s[e])||(console.error(`点${e+1}包含无效数据:`,s[e]),s[e]=new f.Vector3(e,0,e));let c=new f.BufferGeometry,l=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]);c.setAttribute(`position`,new f.BufferAttribute(l,3)),c.setAttribute(`uv`,new f.BufferAttribute(d,2)),c.setIndex(u),c.computeVertexNormals();let p=new f.Mesh(c,i),m=new f.EdgesGeometry(c),h=new f.LineSegments(m,new f.LineBasicMaterial({color:o}));return a.add(h),p}createSubdividedWallPlane(e,t,n,r,i){let a=[];if(!e||!e.start||!e.end||isNaN(e.rooftopPz))return a;let o=new f.Vector3(e.start.x,e.start.y,e.start.z),s=new f.Vector3(e.end.x,e.end.y,e.end.z),c=[o,s,new f.Vector3(e.end.x,e.end.y,e.rooftopPz),new f.Vector3(e.start.x,e.start.y,e.rooftopPz)];for(let e=0;e<c.length;e++)if(!this.isValidVector3(c[e]))return console.error(`墙体基础点${e}无效:`,c[e]),a;let l=o.distanceTo(s),u=Math.abs(e.rooftopPz-e.start.z);if(l===0||u===0)return console.error(`墙体宽度或高度为0`),console.log(`line.rooftopPz`,e.rooftopPz),console.log(`bottomLeft`,o),console.log(`bottomRight`,s),console.log(e.length),a;let d=l/n,p=u/t,m=new f.Vector3().subVectors(s,o).normalize(),h=new f.Vector3(0,0,1);for(let e=0;e<t;e++)for(let t=0;t<n;t++)try{let n={points:[new f.Vector3().copy(o).add(m.clone().multiplyScalar(t*d)).add(h.clone().multiplyScalar(e*p)),new f.Vector3().copy(o).add(m.clone().multiplyScalar((t+1)*d)).add(h.clone().multiplyScalar(e*p)),new f.Vector3().copy(o).add(m.clone().multiplyScalar((t+1)*d)).add(h.clone().multiplyScalar((e+1)*p)),new f.Vector3().copy(o).add(m.clone().multiplyScalar(t*d)).add(h.clone().multiplyScalar((e+1)*p))],userData:{}};n.userData={type:`wallSegment`,row:e,col:t,originalMaterial:r,width:d,height:p},a.push(n)}catch(n){console.error(`创建墙体小平面(${e}, ${t})时出错:`,n)}return a}calculateMinRequiredPoints(e){let t=Math.floor(Math.log1p(e)*.5);return Math.max(1,t)}calculateExpectedDensity(e){return e<1?10:e<4?5:2}evaluateSegmentByArea(e,t,n,r){if(t===0)return!1;let i=e.area,a=e.minRequiredPoints,o=e.expectedDensity,s=t/Math.max(i,.001),c=t>=a,l=s>=o*.3,u=!0;return i<.5&&t>0&&(u=this.checkSmallAreaDistribution(e,n,r)),c&&l&&u}checkSmallAreaDistribution(e,t,n){if(t.length<2)return!0;let r=t.map(e=>n[e]);e.bounds;let i=e.center,a=0,o=Math.sqrt(e.area)*.3;return r.forEach(e=>{e.distanceTo(i)<=o&&a++}),a/r.length>=.3}getFailureReason(e,t){let n=e.area,r=e.minRequiredPoints,i=e.expectedDensity,a=t/Math.max(n,.001),o=[];return t===0?o.push(`无点`):(t<r&&o.push(`点数不足: ${t}/${r}`),a<i*.3&&o.push(`密度不足: ${a.toFixed(2)}/${i.toFixed(2)}`),n<.5&&t>0&&(this.checkSmallAreaDistribution(e,[],[])||o.push(`小平面分布不均`))),o.length>0?o.join(`, `):`未知原因`}calculateMedian(e){let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==0?(t[n-1]+t[n])/2:t[n]}isPointInBoundingBox(e,t,n=.1){return e.x>=t.min[0]-n&&e.x<=t.max[0]+n&&e.y>=t.min[1]-n&&e.y<=t.max[1]+n&&e.z>=t.min[2]-n&&e.z<=t.max[2]+n}getSegmentPlane(e){let t=e.geometry;if(!t||!t.attributes.position)return null;let n=t.attributes.position;if(n.count<3)return null;let r=new f.Vector3().fromBufferAttribute(n,0),i=new f.Vector3().fromBufferAttribute(n,1),a=new f.Vector3().fromBufferAttribute(n,2);r.applyMatrix4(e.matrixWorld),i.applyMatrix4(e.matrixWorld),a.applyMatrix4(e.matrixWorld);let o=new f.Plane;return o.setFromCoplanarPoints(r,i,a),o}analyzePointDistribution(e,t,n=.01){this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:n,analysisTime:null};let r=performance.now(),i=[];e.forEach(e=>{if(e.userData&&e.userData.type===`wallSegment`){let t=this.getWorldVerticesNew(e.points);if(t.length<4)return;let n=new f.Vector3().add(t[0]).add(t[1]).add(t[2]).add(t[3]).multiplyScalar(.25);e.userData.center=n,e.vertices=t,i.push(e)}}),this.results.totalSegments=i.length;for(let e of i){if(e.vertices.length<4)continue;let r=e.userData.center,i=`row${e.userData.row}_col${e.userData.col}`,[a,o,s,c]=e.vertices,l=new f.Vector3().subVectors(o,a).normalize(),u=new f.Vector3().subVectors(c,a).normalize(),d=a.distanceTo(o),p=a.distanceTo(c),m=new f.Plane;m.setFromCoplanarPoints(a,o,c);let h=d/2,g=p/2;for(let e=0;e<t.length;e++)this.isPointInWallSegmentOptimized(t[e],r,m,a,l,u,d,p,h,g,n)&&(this.results.pointsInSegments.has(i)||this.results.pointsInSegments.set(i,[]),this.results.pointsInSegments.get(i).push(e))}return i.forEach(e=>{let t=`row${e.userData.row}_col${e.userData.col}`,n=this.results.pointsInSegments.has(t)?this.results.pointsInSegments.get(t).length:0;n>=1?this.results.segmentsWithPoints++:(this.results.segmentsWithoutPoints++,this.results.missingSegments.push({row:e.userData.row,col:e.userData.col,width:e.userData.width,height:e.userData.height,segmentKey:t,vertices:e.vertices,center:e.userData.center,mesh:e,pointCount:n,hasPointsButNotEnough:n>0&&n<1}))}),this.results.analysisTime=performance.now()-r,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(e,t,n,r,i,a,o,s,c,l,u){if(Math.abs(n.distanceToPoint(e))>u)return!1;let d=new f.Vector3().subVectors(e,t),p=Math.abs(d.dot(i)),m=Math.abs(d.dot(a));if(p>c&&m>l)return!1;let h=new f.Vector3().subVectors(e,r),g=h.dot(i),_=h.dot(a),v=g>=-u&&g<=o+u,y=_>=-u&&_<=s+u;return v&&y}isPointInWallSegment(e,t,n,r=.1){if(!e.geometry)return!1;try{let i=this.getWorldVertices(e);return i.length<4?!1:this.isPointInRotatedWall(i,t,n,r)}catch(e){return console.error(`判断点是否在墙体平面内时出错:`,e),!1}}isPointInRotatedWall(e,t,n,r=.1){let[i,a,o,s]=e,c=new f.Plane;if(c.setFromCoplanarPoints(i,a,s),Math.abs(c.distanceToPoint(t))>r)return!1;let l=new f.Vector3().subVectors(a,i).normalize(),u=new f.Vector3().subVectors(s,i).normalize();new f.Vector3().crossVectors(l,u).normalize();let d=new f.Vector3().subVectors(t,i),p=d.dot(l),m=d.dot(u),h=i.distanceTo(a),g=i.distanceTo(s),_=p>=-r&&p<=h+r,v=m>=-r&&m<=g+r;return _&&v&&n.distanceTo(t)<h/2&&n.distanceTo(t)<g/2}getWorldVertices(e){if(e._cachedWorldVertices&&e.matrixWorld.equals(e._cachedMatrixWorld))return e._cachedWorldVertices;let t=e.geometry.getAttribute(`position`),n=[];for(let r=0;r<Math.min(4,t.count);r++){let i=new f.Vector3;i.fromBufferAttribute(t,r),i.applyMatrix4(e.matrixWorld),n.push(i)}return e._cachedWorldVertices=n,e._cachedMatrixWorld=e.matrixWorld.clone(),n}getWorldVerticesNew(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].clone();t.push(r)}return t}getWallSegmentBounds(e){if(!e.geometry)return null;let t=e.geometry.getAttribute(`position`),n=new f.Box3;for(let r=0;r<t.count;r++){let i=new f.Vector3;i.fromBufferAttribute(t,r),i.applyMatrix4(e.matrixWorld),n.expandByPoint(i)}return{min:n.min.toArray(),max:n.max.toArray(),center:n.getCenter(new f.Vector3).toArray(),size:n.getSize(new f.Vector3).toArray()}}highlightEmptySegments(e,t,n,r=1){if(!this.results){console.warn(`请先运行分析函数`);return}let i=new Map,a=new Map;this.results.missingSegments.forEach(e=>{i.set(e.segmentKey,e),a.has(e.row)||a.set(e.row,new Map),a.get(e.row).set(e.col,{segmentKey:e.segmentKey,isEmpty:!0,visited:!1})}),e.forEach(e=>{if(e.userData&&e.userData.type===`wallSegment`){let t=`row${e.userData.row}_col${e.userData.col}`,n=i.has(t);a.has(e.userData.row)||a.set(e.userData.row,new Map),a.get(e.userData.row).has(e.userData.col)||a.get(e.userData.row).set(e.userData.col,{segmentKey:t,isEmpty:n,visited:!1})}});let o=[],s=[[0,1],[1,0],[0,-1],[-1,0]];for(let[e,t]of i){let e=a.get(t.row)?.get(t.col);if(e&&!e.visited){let n=[],c=[[t.row,t.col]];for(e.visited=!0;c.length>0;){let[e,t]=c.shift(),r=`row${e}_col${t}`;i.has(r)&&n.push(i.get(r));for(let[n,r]of s){let i=e+n,o=t+r;if(a.has(i)&&a.get(i).has(o)){let e=a.get(i).get(o);!e.visited&&e.isEmpty&&(e.visited=!0,c.push([i,o]))}}}n.length>=r&&o.push(n)}}let c=this.createClusterMaterials(o.length),l=[];return this.clusterResults={clusters:o.sort((e,t)=>t.length-e.length),highlightedMeshes:l,clusterMaterials:c,totalClusters:o.length,totalHighlighted:l.length},this.clusterResults}calculateBoundaryRegularity(e,t,n,r,i){let a=0,o=0,s=t,c=!0;for(let t=r;t<=i;t++)e.has(s)&&e.get(s).has(t)?o++:c=!1;c&&a++;let l=n,u=!0;for(let t=r;t<=i;t++)e.has(l)&&e.get(l).has(t)?o++:u=!1;u&&a++;let d=r,f=!0;for(let r=t;r<=n;r++)e.has(r)&&e.get(r).has(d)?o++:f=!1;f&&a++;let p=i,m=!0;for(let r=t;r<=n;r++)e.has(r)&&e.get(r).has(p)?o++:m=!1;return m&&a++,a/4}calculateClusterQualityScore(e){let t=1/Math.max(1,e.aspectRatio);return e.compactness*.4+e.boundaryRegularity*.4+t*.2}calculateStrictClusterBounds(e){if(e.length===0)return{width:0,height:0};let t=[];if(e.forEach(e=>{e.vertices&&e.vertices.length>0&&t.push(...e.vertices)}),t.length===0){let t=[...new Set(e.map(e=>e.row))];return{width:[...new Set(e.map(e=>e.col))].length*(e[0].bounds?.width||1),height:t.length*(e[0].bounds?.height||1)}}let n=Math.min(...t.map(e=>e.x)),r=Math.max(...t.map(e=>e.x)),i=Math.min(...t.map(e=>e.y)),a=Math.max(...t.map(e=>e.y)),o=Math.min(...t.map(e=>e.z)),s=Math.max(...t.map(e=>e.z));return{width:Math.abs(r-n),height:Math.max(Math.abs(a-i),Math.abs(s-o))}}createClusterMaterials(e){let t=[],n=[16711935,65535,16753920,16738740,9055202,3329330,`lavenderblush`,`lawngreen`,`lemonchiffon`,`lightblue`,`lightcoral`];for(let r=0;r<e;r++){let e=n[r%n.length],i=new f.MeshBasicMaterial({color:e,transparent:!0,opacity:.6,side:f.DoubleSide});t.push(i)}return t}clearHighlights(e){this.clusterResults&&this.clusterResults.highlightedMeshes&&(this.clusterResults.highlightedMeshes.forEach(t=>{e.remove(t),t.material&&t.material.dispose()}),this.results&&this.results.segmentDetails&&this.results.segmentDetails.forEach((e,t)=>{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((e,t)=>({clusterIndex:t,size:e.length,segments:e.map(e=>e.segmentKey)})),largestCluster:Math.max(...this.clusterResults.clusters.map(e=>e.length)),smallestCluster:Math.min(...this.clusterResults.clusters.map(e=>e.length))}:null}restoreOriginalMaterials(e){let t=0;e.traverse(e=>{e.userData&&e.userData.originalMaterial&&(e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,t++)}),console.log(`恢复了 ${t} 个平面的原始材质`)}createDebugHelpers(e){let t=new f.Group;return e.traverse(e=>{if(e.userData&&e.userData.type===`wallSegment`){let n=this.getWorldVertices(e);if(n.length<4)return;let r=new f.Vector3().add(n[0]).add(n[1]).add(n[2]).add(n[3]).multiplyScalar(.25),i=new f.Vector3().subVectors(n[1],n[0]).normalize(),a=new f.Vector3().subVectors(n[3],n[0]).normalize(),o=new f.Vector3().crossVectors(i,a).normalize(),s=new f.ArrowHelper(o,r,.3,16711680),c=new f.ArrowHelper(i,r,.2,65280),l=new f.ArrowHelper(a,r,.2,255);t.add(s),t.add(c),t.add(l)}}),t}printAnalysisResults(){if(!this.results){console.warn(`没有可用的分析结果`);return}this.results.missingSegments.length>0&&this.results.missingSegments.forEach(e=>{}),this.results.pointsInSegments.forEach((e,t)=>{})}isValidVector3(e){return e&&!isNaN(e.x)&&!isNaN(e.y)&&!isNaN(e.z)&&isFinite(e.x)&&isFinite(e.y)&&isFinite(e.z)}mergeWallGroupMeshes(e){let t=[];if(e.traverse(e=>{e.isMesh&&e.geometry&&t.push(e)}),t.length===0)return null;try{let e=t.map(e=>e.geometry);e.forEach((e,n)=>{e.applyMatrix4(t[n].matrixWorld)});let n=p(e),r=t[0].material.clone(),i=new f.Mesh(n,r);return i.name=`mergedWalls`,i}catch(e){return console.error(`合并网格时出错:`,e),null}}},ie=e=>{let t={},n=[],r=[],i=[];return e[0].width,e[0].height,e.forEach(e=>{r.push(...e.vertices),i.push(e.center),n.push(e.vertices)}),t.originalVertices=n,t.allCenterPoints=i,t},ae=e=>{let t=new f.Vector3().copy(e.start).add(e.end).multiplyScalar(.5),n=new f.Vector3().subVectors(new f.Vector3(t.x,t.y,t.z+1),t).normalize(),r=new f.Vector3(e.direction.x,e.direction.y,0);r.applyAxisAngle(n,Math.PI/2);let i=new f.Vector3().copy(t).add(r.clone().multiplyScalar(e.length)),a=new f.Vector3().copy(t).sub(r.clone().multiplyScalar(e.length));return t.z=e.start.z,i.z=e.start.z,a.z=e.start.z,{start:i,end:a,center:t,direction:r}},oe=(e,t,n=!0)=>{let r=[];if(!e)return[];for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=new f.Vector3(a.start.x,a.start.y,a.start.z);o.applyEuler(new f.Euler(-Math.PI/2,0,0));let s=new f.Vector3(a.end.x,a.end.y,a.end.z);if(s.applyEuler(new f.Euler(-Math.PI/2,0,0)),t.add(v(String(i),new f.Vector3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2))),(a.isBayWindow||a.isWindow)&&n)continue;let c=new f.Plane().setFromCoplanarPoints(new f.Vector3(a.start.x,a.start.y,a.start.z),new f.Vector3(a.end.x,a.end.y,a.end.z),new f.Vector3(a.start.x,a.start.y,a.rooftopPz)),l=[];a.originalPoints.forEach((e,t)=>{let n=new f.Vector3;c.projectPoint(e,n),l.push(n)});let u=new f.Vector3(a.start.x,a.start.y,a.start.z).distanceTo(new f.Vector3(a.end.x,a.end.y,a.end.z)),d=Math.abs(a.rooftopPz-a.start.z),p=new f.MeshBasicMaterial({color:`red`,side:f.DoubleSide,wireframe:!1,transparent:!0,opacity:.5}),m=new f.Group,h=new re,{horizontalSubdivisions:g,verticalSubdivisions:_}=h.initLimits4(u,d),y=h.createSubdividedWallPlane(a,_,g,p,m);h.analyzePointDistribution(y,l,.01);let b=new f.MeshBasicMaterial({color:`black`,transparent:!0,opacity:.8,side:f.DoubleSide}),x=h.highlightEmptySegments(y,b,m),S=[];for(let e of x.clusters){let t=ie(e);t&&S.push(t)}let C=ae(a).direction;a.checkResults=S,a.verticalDirection=C,a.originaIndex=i,r.push(a)}return r},se=(e,t)=>{console.log(`lines`,e);for(let n=0;n<e.length;n++){let r=e[n],i=[];r.originalPoints.forEach(e=>{let t=new f.Vector3(e.x,e.y,0),n=!1;for(let e=0;e<i.length;e++)if(R(t,i[e],.01)){n=!0;break}n||i.push(t)});let a=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(r.length)))),o=new f.Vector3(r.start.x,r.start.y,r.start.z),s=new f.Vector3(r.end.x,r.end.y,r.end.z),c=new f.Vector3().subVectors(s,o).normalize(),l=c.clone().cross(new f.Vector3(0,0,1)).normalize(),u=l.clone().negate(),d=[],p=[],m=r.length/a;console.log(m);for(let e=0;e<a;e++){let e=[];e.push(o.clone().addScaledVector(l,1)),e.push(e[0].clone().addScaledVector(c,m)),e.push(e[1].clone().addScaledVector(u,2)),e.push(o.clone().addScaledVector(u,m));let t=[];for(let n=0;n<i.length;n++)d.includes(n)||ue(i[n],e)&&(d.push(n),t.push(i[n]));t.length>0&&p.push(de(t)),o=o.addScaledVector(c,m)}let h=new Float32Array(i.length*3);i.forEach((e,t)=>{h[t*3]=e.x,h[t*3+1]=e.y,h[t*3+2]=e.z});let _=new f.BufferGeometry;_.setAttribute(`position`,new f.BufferAttribute(h,3)),_.rotateX(-Math.PI/2),t.add(new f.Points(_,new f.PointsMaterial({color:B(),size:.02})));let[v,y]=ge(p,{plane:`xy`,trimRatio:0});g(v,y,t)}};function ce(e,t=`xy`){if(t===`xy`)return{x:e.x,y:e.y};if(t===`xz`)return{x:e.x,y:e.z};if(t===`yz`)return{x:e.y,y:e.z};throw Error(`Unsupported plane: ${t}`)}function le(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=n.x-e.x;return r*(n.y-e.y)-i*a}function ue(e,t,n=`xy`){if(!t||t.length!==4)throw Error(`rectPoints must contain 4 points`);let r=ce(e,n),i=t.map(e=>ce(e,n)),a=!1,o=!1;for(let e=0;e<4;e++){let t=i[e],n=i[(e+1)%4],s=le(t,n,r);if(s>1e-9&&(a=!0),s<-1e-9&&(o=!0),a&&o)return!1}return!0}function de(e){if(!e||e.length===0)return null;let t=new f.Vector3(0,0,0);for(let n of e)Array.isArray(n)?(t.x+=n[0],t.y+=n[1],t.z+=n[2]):(t.x+=n.x,t.y+=n.y,t.z+=n.z);return t.divideScalar(e.length),t}function fe(e){return e instanceof f.Vector3?e.clone():Array.isArray(e)?new f.Vector3(e[0],e[1],e[2]):new f.Vector3(e.x,e.y,e.z)}function pe(e,t=`xy`){let n=fe(e);if(t===`xy`)return{x:n.x,y:n.y,up:n.z};if(t===`xz`)return{x:n.x,y:n.z,up:n.y};if(t===`yz`)return{x:n.y,y:n.z,up:n.x};throw Error(`Unsupported plane: ${t}`)}function me(e,t,n,r=`xy`){if(r===`xy`)return new f.Vector3(e,t,n);if(r===`xz`)return new f.Vector3(e,n,t);if(r===`yz`)return new f.Vector3(n,e,t);throw Error(`Unsupported plane: ${r}`)}function he(e,t,n){let r=1e-12;if(Math.abs(t)<r)return e>=n?{x:1,y:0}:{x:0,y:1};let i=e+n,a=e*n-t*t,o=Math.sqrt(Math.max(0,i*i*.25-a)),s=i*.5+o,c=t,l=s-e,u=Math.hypot(c,l);return u<r?{x:1,y:0}:{x:c/u,y:l/u}}function ge(e,t={}){let{plane:n=`xy`,trimRatio:r=0}=t;if(!e||e.length<2)return null;let i=e.map(e=>pe(e,n)),a=0,o=0,s=0;for(let e of i)a+=e.x,o+=e.y,s+=e.up;a/=i.length,o/=i.length,s/=i.length;let c=0,l=0,u=0;for(let e of i){let t=e.x-a,n=e.y-o;c+=t*t,l+=t*n,u+=n*n}c/=i.length,l/=i.length,u/=i.length;let d=he(c,l,u),f={x:-d.y,y:d.x},p=[];for(let e of i){let t=e.x-a,n=e.y-o,r=t*d.x+n*d.y,i=t*f.x+n*f.y;p.push({s:r,t:i,up:e.up})}p.sort((e,t)=>e.s-t.s);let m=p.length,h=Math.floor(m*r),g=Math.ceil(m*(1-r))-1;h=Math.max(0,Math.min(m-1,h)),g=Math.max(0,Math.min(m-1,g));let _=p[h],v=p[g],y=(()=>{let e=p.map(e=>e.t).sort((e,t)=>e-t),t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])*.5:e[t]})(),b=(()=>{let e=p.map(e=>e.up).sort((e,t)=>e-t),t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])*.5:e[t]})(),x=_.s,S=v.s,C=y,w=y,T=b,E=b,D=a+d.x*x+f.x*C,O=o+d.y*x+f.y*C,k=a+d.x*S+f.x*w,A=o+d.y*S+f.y*w;return[me(D,O,T,n),me(k,A,E,n)]}var _e=async(e,t,n,r)=>{z(r);let i=await fetch(e);if(!i)return;let a=await i.json(),o=new f.Group,s=new f.Group,c=new f.Group,l=new f.Group,u=new f.Group,d=new f.Group,m=new f.Group,h=new f.Group,g=await fetch(`/src/data/beamData/epu/forBeamLines.json`);if(console.log(g),!g)return;let _=await g.json();for(let e=0;e<a.length;e++){let t=a[e];if(!t)continue;let n=new f.Vector3(t.start.x,t.start.y,t.start.z);n.applyEuler(new f.Euler(-Math.PI/2,0,0));let r=new f.Vector3(t.end.x,t.end.y,t.end.z);r.applyEuler(new f.Euler(-Math.PI/2,0,0)),h.add(v(String(e),new f.Vector3((n.x+r.x)/2,(n.y+r.y)/2,(n.z+r.z)/2)))}a.sort((e,t)=>e.originalIndex-t.originalIndex),console.log(`lins`,a);let y=await fetch(t);if(!y)return;let b=await y.json(),x=Array.isArray(b)?b:Object.values(b),S=await fetch(n);if(console.log(`respcd`,S),!S)return;let w=await S.json(),T=0;for(let e=0;e<w.length;e++){let t=w[e];if(t.isFindBeam=!1,t.category==`door`){let e=new f.Vector3(t.center.x,t.center.y,t.center.z);e.applyEuler(new f.Euler(-Math.PI/2,0,0)),h.add(v(`door:${T}`,e)),T++}}r.add(h),console.log(_),console.time();let{beamGroup:E}=await ve(a,x,w,_,r);console.timeEnd(),console.log(`beamGroup`,E);let D=new f.MeshBasicMaterial({color:`#cffd00`,transparent:!0,opacity:.4,side:f.DoubleSide}),O=new f.MeshBasicMaterial({color:`#ff0000`,transparent:!0,opacity:.4,side:f.DoubleSide}),k=new f.MeshBasicMaterial({color:`#e100ff`,transparent:!0,opacity:.4,side:f.DoubleSide}),A=new f.MeshBasicMaterial({color:`#0400ff`,transparent:!0,opacity:.4,side:f.DoubleSide}),j=new f.LineBasicMaterial({color:`#cffd00`}),M=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.checkResults)for(let e of t.checkResults)for(let t of e.originalVertices){let[e,n,r,i]=t,a=new f.BufferGeometry,o=new Float32Array([e.x,e.y,e.z,n.x,n.y,n.z,r.x,r.y,r.z,i.x,i.y,i.z]);a.setAttribute(`position`,new f.BufferAttribute(o,3)),a.setIndex([0,1,2,0,2,3]),a.computeVertexNormals();let s=new f.EdgesGeometry(a,1);M.push(s)}}if(M.length>0){let e=p(M,!1);e.rotateX(-Math.PI/2),o.add(new f.LineSegments(e,j)),o.visible=!1,r.add(o),M.forEach(e=>e.dispose())}new f.PointsMaterial({color:65535,size:.01});for(let e of a){if(!e.originalPoints||e.originalPoints.length===0)continue;let t=new Float32Array(e.originalPoints.length*3);e.originalPoints.forEach((e,n)=>{t[n*3]=e.x,t[n*3+1]=e.y,t[n*3+2]=e.z});let n=new f.BufferGeometry;n.setAttribute(`position`,new f.BufferAttribute(t,3)),n.rotateX(-Math.PI/2),s.add(new f.Points(n,new f.PointsMaterial({color:B(),size:.02})));let r=[];r.push(new f.Vector3(e.start.x,e.start.y,e.start.z)),r.push(new f.Vector3(e.end.x,e.end.y,e.end.z));let i=new f.BufferGeometry;i.setFromPoints(r),i.rotateX(-Math.PI/2),d.add(new f.Line(i,j))}d.visible=!1,r.add(s),r.add(d);let N=[],P=[],F=new f.LineBasicMaterial({color:`#f30606`}),I=new f.MeshBasicMaterial({color:`#071ac4`});for(let e=0;e<x.length;e++){let t=new f.SphereGeometry(.05);t.translate(x[e].x,x[e].y,x[e].z);let n=[],r=new f.Vector3(x[e].x,x[e].y,x[e].z),i=new f.Quaternion(x[e].qx,x[e].qy,x[e].qz,x[e].qw),a=new f.Vector3(0,0,-1).applyQuaternion(i),o=r.clone().addScaledVector(a,.001);n.push(r),n.push(o);let s=new f.BufferGeometry;s.setFromPoints(n),P.push(s),N.push(t)}if(N.length>0){let e=p(N,!1);e.rotateX(-Math.PI/2),c.add(new f.Mesh(e,I)),N.forEach(e=>e.dispose())}if(P.length>0){let e=p(P,!1);e.rotateX(-Math.PI/2),c.add(new f.Line(e,F)),P.forEach(e=>e.dispose())}r.add(c);let{AiProjectionGroup:L,AiProjectionGroup2:ee}=C(w);return l.add(L),l.rotateX(-Math.PI/2),r.add(l),u.add(ee),u.visible=!1,u.rotateX(-Math.PI/2),r.add(u),console.log(`jsonpcdData`,w),a.forEach(e=>{e.doorAndBeamData&&e.doorAndBeamData.length>0&&(e.doorAndBeamData.forEach(e=>{if(e.beamStart){let t=new f.BufferGeometry,n=new Float32Array([e.beamStart.x,e.beamStart.y,e.beamStart.z,e.beamEnd.x,e.beamEnd.y,e.beamEnd.z,e.beamEnd.x,e.beamEnd.y,e.beamEnd.z+e.beamHeight,e.beamStart.x,e.beamStart.y,e.beamStart.z+e.beamHeight]);t.setAttribute(`position`,new f.BufferAttribute(n,3)),t.setIndex([0,1,2,0,2,3]),t.computeVertexNormals(),t.rotateX(-Math.PI/2),m.add(new f.Mesh(t,D))}let t=new f.BufferGeometry,n=new Float32Array([e.doorStart.x,e.doorStart.y,e.doorStart.z,e.doorEnd.x,e.doorEnd.y,e.doorEnd.z,e.doorEnd.x,e.doorEnd.y,e.doorEnd.z+e.doorHeight,e.doorStart.x,e.doorStart.y,e.doorStart.z+e.doorHeight]);t.setAttribute(`position`,new f.BufferAttribute(n,3)),t.setIndex([0,1,2,0,2,3]),t.computeVertexNormals(),t.rotateX(-Math.PI/2),e.isDoor?m.add(new f.Mesh(t,A)):e.type==`beam`?m.add(new f.Mesh(t,k)):m.add(new f.Mesh(t,O));let r=`id:${e.id},Nid:${e.nearId}`,i=new f.Vector3((e.doorStart.x+e.doorEnd.x)/2,(e.doorStart.y+e.doorEnd.y)/2,e.doorStart.z+e.doorHeight);i.applyEuler(new f.Euler(-Math.PI/2,0,0)),m.add(v(r,i))}),r.add(m))}),{checkResultGroup:o,pointCloudGroup:s,runData:c,pcdGroup:l,pcdGroup2:u,pointLineGroup:d,beamDoorGroup:m,lineIndexGroup:h}},ve=async(e,t,n,r,i)=>{if(r&&r.length>0)for(let t=0;t<r.length;t++){let n=r[t];n.isLine2=!0,e.push(n)}if(F(e,i),e.length<=0||t.length<=0)return e;n||=[];for(let t of e){let e=[];if(!(!t.checkResults||t.checkResults.length<=0)){for(let n=0;n<t.checkResults.length;n++){let r=t.checkResults[n];if(r.isDoor=!1,!r.originalVertices||r.originalVertices.length==0)continue;let i=[];r.originalVertices.forEach(e=>{let t=[];e.forEach(e=>{t.push(new f.Vector3(e.x,e.y,e.z))}),i.push(t)});let a=i.length,o=Array.from({length:a},(e,t)=>t);function s(e){for(;o[e]!==e;)o[e]=o[o[e]],e=o[e];return e}for(let e=0;e<a;e++)for(let t=e+1;t<a;t++){let n=i[e],r=i[t];if(n.some(e=>r.some(t=>e.equals(t)))){let n=s(e),r=s(t);n!==r&&(o[n]=r)}}let c=new Map,l=-1,u=-1;for(let e=0;e<a;e++){let t=s(e);c.has(t)||c.set(t,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});let r=c.get(t),[a,o,d,p]=i[e],m=new f.Vector3().add(a).add(o).add(d).add(p).multiplyScalar(.25);if(r.points.push(...i[e]),r.area+=a.distanceTo(o)*a.distanceTo(p),r.originalVertices.push(i[e]),r.index=n,r.centerPts.push(m),l==-1||u==-1){let e=new f.Vector3().subVectors(a,o).normalize();u=a.distanceTo(p),l=a.distanceTo(o);let t=b(e,new f.Vector3(0,0,1));t&&t.parallel&&([u,l]=[l,u])}r.gridWidth=l,r.gridHeight=u}e.push(...c.values())}t.mergeCheckRegion=e}}let a=new Map;for(let t of e){if(t.length<.3)continue;let e=t.rooftopPz-t.start.z,n=Math.floor(t.rooftopPz-t.start.z);a.has(n)?a.set(n,{num:a.get(n).num+1,totalHeight:a.get(n).totalHeight+e}):a.set(n,{num:1,totalHeight:e})}let o=[...a.entries()].reduce((e,t)=>t[1].num>e[1].num?t:e);o[0],o[1].totalHeight/o[1].num;let s=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.isFindBeam=!1,t.category==`door`){let n=[];t.coordinatesByArea.coordinates.forEach(e=>{n.push(new f.Vector3(e.x,e.y,e.z))}),n[0].equals(n[n.length-1])&&n.pop();let r=n[0].distanceTo(n[1]),i=n[0].distanceTo(n[3]);i>r&&([r,i]=[i,r],n=[n[0],n[3],n[2],n[1]]);let a=D(n[0],n[3],!0),o=D(n[1],n[2],!0);s.push({doorStartPt:a,doorEndPt:o,boxPoints:n,minZ:t.coordinatesByArea.heightData.minZ,maxZ:t.coordinatesByArea.heightData.maxZ,index:e,isFind:!1,inWall:!1})}}for(let t=0;t<s.length;t++){let n=s[t];for(let t=0;t<e.length;t++){if(e[t].length<.5)continue;let r=[],i=D(e[t].start,e[t].end,!0);r.push(i),r.push(D(i,e[t].start,!0)),r.push(D(i,e[t].end,!0));let a=!1,o=n.boxPoints.length;for(let e=0;e<r.length;e++){let t=r[e].x,i=r[e].y;for(let e=0,r=o-1;e<o;r=e++){let o=n.boxPoints[e].x,s=n.boxPoints[e].y,c=n.boxPoints[r].x,l=n.boxPoints[r].y;s>i!=l>i&&t<(c-o)*(i-s)/(l-s)+o&&(a=!a)}if(a)break}if(a){let r=new f.Vector3(e[t].start.x,e[t].start.y,0),i=new f.Vector3(e[t].end.x,e[t].end.y,0),a=n.doorStartPt.distanceTo(n.doorEndPt),o=r.distanceTo(i),s=T(n.doorStartPt,n.doorEndPt,r,i);if(Math.abs(o-a)<.5&&s&&s.angleDeg<15){n.doorStartPt=new f.Vector3(e[t].start.x,e[t].start.y,0),n.doorEndPt=new f.Vector3(e[t].end.x,e[t].end.y,0);break}else if(Math.abs(o-a)>1.3&&s&&s.angleDeg<15){let e=O(n.doorStartPt,n.doorEndPt,r,i,{parallelAngleMax:f.MathUtils.degToRad(15)}),t=n.doorStartPt.distanceTo(r),a=n.doorStartPt.distanceTo(i),o=n.doorEndPt.distanceTo(r),s=n.doorEndPt.distanceTo(i),c=t<.2||a<.2||o<.2||s<.2;if(e&&e.type==`collinear_overlap`&&e.maxPerpendicularDistance<.1&&!c){n.inWall=!0;break}else{let e=new f.Line3(r,i),t=e.closestPointToPoint(n.doorStartPt,!0,new f.Vector3),a=e.closestPointToPoint(n.doorEndPt,!0,new f.Vector3),o=t.distanceTo(n.doorStartPt),s=a.distanceTo(n.doorEndPt);if(o<.1||s<.1){n.inWall=!0;break}}}}else continue}}let c=0,l=[],u=[],d=[],p=[],m=.15;for(let r=0;r<e.length;r++){let i=e[r];if(i.noDetection||(i.doorAndBeamData=[],!i.mergeCheckRegion||i.mergeCheckRegion.length==0))continue;i.completePointAreaPercentage=-1;let a=new f.Box3;a.setFromPoints(i.originalPoints);let o=a.max.z;a.min.z;let h=new f.Vector3(i.start.x,i.start.y,i.start.z),g=new f.Vector3(i.end.x,i.end.y,i.end.z),v=i.rooftopPz-i.start.z,y=0;for(let a of i.mergeCheckRegion){let{facePoints:x,boxArea:S,totalInPlaneNum:C}=w(a.points,a.gridWidth,a.gridHeight,a.centerPts);if(!x||x.length<=0)continue;x[0].distanceTo(x[1]);let k=x[0].distanceTo(x[3]),A=a.gridHeight*(k/a.gridHeight/3*2)+a.gridHeight/2,j=new f.Vector3(x[0].x,x[0].y,x[0].z+A),M=new f.Vector3(x[1].x,x[1].y,x[1].z+A),F=new f.Line3(j,M),R=[],z=new f.Vector3;a.points.forEach(e=>{F.closestPointToPoint(e,!0,z).distanceTo(e)<a.gridHeight+.01&&R.push(e)});let B=[],V=[];for(;;){let e=[];for(let t=0;t<R.length;t++)V.includes(t)||e.length==0&&(e.push(R[t]),V.push(t));for(let t=0;t<R.length;t++)if(!V.includes(t)){for(let n=0;n<e.length;n++)if(R[t].distanceTo(e[n])<a.gridWidth+.01){e.push(R[t]),V.push(t),t=-1;break}}if(e.length==0)break;B.push(e)}let te=[];for(let e=0;e<B.length;e++){let t={lineSt:new f.Vector3,lineEd:new f.Vector3,facePoints:[]},n=ee(B[e]);Array.isArray(n)&&n.length==2&&(t.lineSt=n[0],t.lineEd=n[1],t.facePoints.push(new f.Vector3(n[0].x,n[0].y,x[0].z)),t.facePoints.push(new f.Vector3(n[1].x,n[1].y,x[0].z)),t.facePoints.push(new f.Vector3(n[1].x,n[1].y,x[2].z)),t.facePoints.push(new f.Vector3(n[0].x,n[0].y,x[2].z)),te.push(t))}y+=a.area;let re=0;if(C!=0&&(re=a.gridHeight*a.gridWidth*C),(a.area-re)/S*100>70&&te.length==1||te.length>1)for(let y=0;y<te.length;y++){let x=te[y],S=x.facePoints[0].distanceTo(x.facePoints[1]),C=x.facePoints[0].distanceTo(x.facePoints[3]),w=S/i.length*100,k=i.rooftopPz-x.facePoints[2].z;if(C<1.5||o<x.facePoints[2].z||k>v/3*2)continue;let A=!1,j=!1,M=!1,F=[],R=x.facePoints[2].clone(),z=x.facePoints[3].clone(),B=x.facePoints[0].clone(),V=x.facePoints[1].clone(),re=!1,ie=-1;if(Math.abs(x.facePoints[0].z-i.start.z)<.25){if(S>.17&&i.length>.5){let t=I(h,B),n=I(h,V),a=I(g,B),o=I(g,V),s=.1;if(t<s||n<s){let{newOriginalPoints:n}=P(B,V,i.originalPoints),a=[],o=[];if(n.forEach(e=>{e.z>=R.z?a.push(e):e.z<=B.z&&o.push(e)}),a.length>10){let n=new f.Vector3(i.start.x,i.start.y,0),a=new f.Vector3(i.end.x,i.end.y,0),o=new f.Vector3().subVectors(n,a).normalize(),c=new f.Vector3,l=1/0,u=-1,d=!1,p=!1;for(let t=0;t<e.length;t++){if(t==r)continue;let i=new f.Vector3(e[t].start.x,e[t].start.y,0),s=new f.Vector3(e[t].end.x,e[t].end.y,0),m=_(n,a,i,s),h=E(n,a,i,s);if(m!=null){if(h&&h.angle>85){let e=m.point.distanceTo(n);if(m.point.distanceTo(a),e<.3){p=!0,l=1/0,u=-1;break}}continue}if(h&&h.angle>85){let e=T(n,a,new f.Line3(i,s).closestPointToPoint(n,!0,c),n);if(!e||e.direction!=`same`)continue;let r=n.clone().addScaledVector(o,10),d=a.clone().addScaledVector(o.clone().negate(),10),p=new f.Vector3().subVectors(s,i).normalize(),m=_(r,d,i.clone().addScaledVector(p.clone().negate(),.03),s.clone().addScaledVector(p,.03));if(m==null)continue;let h=n.distanceTo(m.point);h<l&&(l=h,u=t)}else if(h&&h.angle<5){let e=new f.Vector3(B.x,B.y,0),t=new f.Vector3(V.x,V.y,0),n=I(e,i),r=I(e,s),a=I(t,i),o=I(t,s);if(n<.08||r<.08||a<.08||o<.08){d=!0,l=1/0,u=-1;break}}}if(l!=1/0&&l<2&&i.length-S>.2&&l<S*3)e[u].length>.25&&S+l>.5&&(re=!0,t<s?(z=z.addScaledVector(o,l),B=B.addScaledVector(o,l)):(R=R.addScaledVector(o,l),V=V.addScaledVector(o,l)));else if(!d&&!p&&i.length-S>.1)continue}else continue}if(a<s||o<s){let{newOriginalPoints:t}=P(B,V,i.originalPoints),n=[],o=[];if(t.forEach(e=>{e.z>=R.z?n.push(e):e.z<=B.z&&o.push(e)}),n.length>10){let t=new f.Vector3(i.start.x,i.start.y,0),n=new f.Vector3(i.end.x,i.end.y,0),o=new f.Vector3().subVectors(n,t).normalize(),c=new f.Vector3,l=1/0,u=-1,d=!1,p=!1;for(let i=0;i<e.length;i++){if(i==r)continue;let a=new f.Vector3(e[i].start.x,e[i].start.y,0),s=new f.Vector3(e[i].end.x,e[i].end.y,0),m=_(t,n,a,s),h=E(t,n,a,s);if(m!=null){if(h&&h.angle>85&&(m.point.distanceTo(t),m.point.distanceTo(n)<.3)){p=!0,l=1/0,u=-1;break}continue}if(h&&h.angle>85){let e=T(n,t,new f.Line3(a,s).closestPointToPoint(n,!0,c),n);if(!e||e.direction!=`same`)continue;let r=t.clone().addScaledVector(o.clone().negate(),10),d=n.clone().addScaledVector(o,10),p=new f.Vector3().subVectors(s,a).normalize(),m=_(r,d,a.clone().addScaledVector(p.clone().negate(),.03),s.clone().addScaledVector(p,.03));if(m==null)continue;let h=n.distanceTo(m.point);h<l&&(l=h,u=i)}else if(h&&h.angle<5){let e=new f.Vector3(B.x,B.y,0),t=new f.Vector3(V.x,V.y,0),n=I(e,a),r=I(e,s),i=I(t,a),o=I(t,s);if(n<.08||r<.08||i<.08||o<.08){d=!0,l=1/0,u=-1;break}}}if(l!=1/0&&l<2&&i.length-S>.2&&l<S*3)e[u].length>.25&&S+l>.5&&(re=!0,a<s?(z=z.addScaledVector(o,l),B=B.addScaledVector(o,l)):(R=R.addScaledVector(o,l),V=V.addScaledVector(o,l)));else if(!d&&!p&&i.length-S>.1)continue}else continue}S=z.distanceTo(R)}if(w<85&&S>.3||S>.7&&C>v-v/3){let e=!1;for(let n=0;n<t.length;n++){let r=n+1;if(r>=t.length)continue;let i=new f.Vector3(t[n].x,t[n].y,t[n].z),a=new f.Vector3(t[r].x,t[r].y,t[r].z);if(_(new f.Vector3(i.x,i.y,0),new f.Vector3(a.x,a.y,0),new f.Vector3(x.facePoints[0].x,x.facePoints[0].y,0),new f.Vector3(x.facePoints[1].x,x.facePoints[1].y,0),.1)!=null){e=!0;break}}for(let e=0;e<s.length;e++){let t=new f.Vector3(s[e].doorStartPt.x,s[e].doorStartPt.y,0),r=new f.Vector3(s[e].doorEndPt.x,s[e].doorEndPt.y,0),a=new f.Vector3(x.facePoints[0].x,x.facePoints[0].y,0),o=new f.Vector3(x.facePoints[1].x,x.facePoints[1].y,0),c=x.facePoints[2].z<s[e].maxZ||Math.abs(x.facePoints[2].z-s[e].maxZ)<.3;if(Math.abs(x.facePoints[2].z-s[e].maxZ),c){let c=O(t.clone(),r.clone(),a.clone(),o.clone(),{distanceThreshold:2});if(c&&c.type==`collinear_gap`){let l=D(t,r),u=new f.Line3(new f.Vector3(i.start.x,i.start.y,0),new f.Vector3(i.end.x,i.end.y,0)),d=new f.Vector3,p=u.closestPointToPoint(l,!0,d);if(l.distanceTo(p)<.15){let i=a.distanceTo(t),l=o.distanceTo(t);if(i>.25&&l>.25){let e=a.distanceTo(r),t=o.distanceTo(r);if(e>.2&&t>.2)continue}j=!0,M=!0,F.push(s[e].index),s[e].isFind=!0,ie=e,n[s[e].index].isFindBeam=!0;let u=new f.Vector3().subVectors(a,o).normalize(),d=t.distanceTo(r)-c.overlap;l<i&&u.negate(),i>l?(R=x.facePoints[2].clone().addScaledVector(u,d),z=x.facePoints[3].clone(),B=z.clone(),V=R.clone(),B.z=V.z=x.facePoints[0].z):(R=x.facePoints[2].clone(),z=x.facePoints[3].clone().addScaledVector(u,d),B=z.clone(),V=R.clone(),B.z=V.z=x.facePoints[0].z)}}else if(c&&c.type==`collinear_overlap`&&c.maxPerpendicularDistance<.35){let i=a.distanceTo(o),l=r.distanceTo(t);if(Math.abs(i-c.overlap)<.25||Math.abs(l-c.overlap)<.25){if(l>i&&Math.abs(l-c.overlap)>1){let e=a.distanceTo(t),n=a.distanceTo(r),i=o.distanceTo(t),s=o.distanceTo(r),u=e<n?e:n,d=i<s?i:s,p=new f.Vector3().subVectors(a,o).normalize(),m=l-c.overlap;u<d?(p.negate(),R=x.facePoints[2].clone().addScaledVector(p,m),z=x.facePoints[3].clone(),B=z.clone(),V=R.clone(),B.z=V.z=x.facePoints[0].z):(R=x.facePoints[2].clone(),z=x.facePoints[3].clone().addScaledVector(p,m),B=z.clone(),V=R.clone(),B.z=V.z=x.facePoints[0].z)}j=!0,M=!0,F.push(s[e].index),s[e].isFind=!0,n[s[e].index].isFindBeam=!0,ie=e}}}}if(!M&&S<1.5)for(let e=0;e<s.length;e++){if(s[e].inWall)continue;let t=new f.Vector3(s[e].doorStartPt.x,s[e].doorStartPt.y,0),r=new f.Vector3(s[e].doorEndPt.x,s[e].doorEndPt.y,0),i=new f.Vector3(x.facePoints[0].x,x.facePoints[0].y,0),a=new f.Vector3(x.facePoints[1].x,x.facePoints[1].y,0),o=new f.Vector3().subVectors(t,r).normalize(),c=new f.Vector3().subVectors(i,a).normalize(),l=.25,u=_(t.clone().addScaledVector(o,l),r.clone().addScaledVector(o.clone().negate(),l),i.clone().addScaledVector(c,l),a.clone().addScaledVector(c.clone().negate(),l)),d=t.distanceTo(i),p=t.distanceTo(a),h=r.distanceTo(i),g=r.distanceTo(a);(d<m||p<m||h<m||g<m||u)&&(n[s[e].index].isFindBeam=!0,j=!0,s[e].isFind=!0,ie=e)}(j||e||Math.abs(C-v)>.1&&C>v/2&&S>.3)&&(A=!0)}}if(A){let t=!1;for(let e=0;e<d.length;e++){let n=O(d[e].start,d[e].end,B,V);if(n&&n.type==`collinear_overlap`&&n.maxPerpendicularDistance<.01){t=!0;break}}if(t){ie!=-1&&(n[s[ie].index].isFindBeam=!1,s[ie].isFind=!1);continue}d.push({start:B,end:V});{new f.PointsMaterial({color:65535,size:.01});let e=new f.Vector3().subVectors(B,V),t=new f.Vector3().subVectors(V,B),n=1/0,r=1/0,a=B.clone(),o=V.clone(),s=[],c=[],l=new f.Line3(R,z),u=new f.Vector3,d=999999;if(i.originalPoints.forEach(n=>{if(n.z-B.z<C/2+.1&&n.z-B.z>C/2-.1&&s.push(n),n.z>R.z){let r=l.closestPointToPoint(n,!0,u),i=new f.Vector3().subVectors(r,R),a=b(e,new f.Vector3().subVectors(r,z)),o=b(t,i);a&&a.parallel&&!a.sameDirection&&o&&o.parallel&&!o.sameDirection&&c.push(n)}}),s.length>0){let{newProjectPoints:i}=P(B,V,s);for(let e of i)e.z=B.z;i.forEach(i=>{let s=new f.Vector3(i.x,i.y,B.z),c=new f.Vector3().subVectors(s,V),l=b(e,new f.Vector3().subVectors(s,B)),u=b(t,c);if(l&&l.parallel&&l.sameDirection){let e=s.distanceTo(B);e<n&&(n=e,a=s)}else if(u&&u.parallel&&u.sameDirection){let e=s.distanceTo(V);e<r&&(r=e,o=s)}})}if(a.equals(B)||(B=a,z=new f.Vector3(B.x,B.y,z.z)),o.equals(V)||(V=o,R=new f.Vector3(V.x,V.y,R.z)),c.length>10){let{newOnLinePoints:e}=P(z,R,c);for(let t=0;t<e.length;t++){let n=l.closestPointToPoint(e[t],!0,u).distanceTo(e[t]);n>.02&&d>n&&(d=n)}R.z+=d,z.z+=d,C+=d}}let o=V.distanceTo(B);if(o<.4&&!j||o<.3&&j)continue;u.includes(r)||u.push(r),i.checkResults[a.index].isDoor=!0;let m=``,h={id:c,beamStart:R,beamEnd:z,beamHeight:i.rooftopPz-R.z,doorStart:B,doorEnd:V,doorHeight:C,nearId:-1,type:m,isExtend:re,isDoor:j,isPullOutDoor:M,pcbDoorIndexs:F,beamNearWallVec:new f.Vector3(0,0,0)},g=!1,v=new f.Vector3,y=new f.Vector3,x=-1,w=-1,k=-1;for(let t=0;t<l.length;t++){let n=e[l[t].linesIndex].doorAndBeamData[l[t].doorIndex];if(n.nearId!=-1)continue;let r=T(R.clone(),z.clone(),n.beamStart.clone(),n.beamEnd.clone());if(r&&r.isParallel){let e=R.distanceTo(z),r=n.beamStart.distanceTo(n.beamEnd),i=new f.Line3(R.clone(),z.clone());i.start.z=0,i.end.z=0;let a=D(n.beamStart,n.beamEnd,!0);r>e&&(i.start=new f.Vector3(n.beamStart.x,n.beamStart.y,0),i.end=new f.Vector3(n.beamEnd.x,n.beamEnd.y,0),a=D(R,z,!0));let o=new f.Vector3,s=i.closestPointToPoint(a,!0,o),u=s.distanceTo(a),d=new f.Vector3().subVectors(a,s).normalize(),p=d.clone().negate(),m=a.clone().addScaledVector(p,u+.1),b=_(i.start,i.end,a,m),S=!j&&!n.isDoor&&(e>r*2||r>e*2);if(u<.4&&b!=null&&!S){n.nearId=c,h.nearId=n.id;let i=.8;(n.isDoor||h.isDoor)&&(n.isDoor=!0,h.isDoor=!0);let a=F.some(e=>n.pcbDoorIndexs.includes(e));e<r?e>i&&!n.isPullOutDoor?(n.beamStart=R.clone().addScaledVector(p,u),n.beamEnd=z.clone().addScaledVector(p,u),n.doorStart=B.clone().addScaledVector(p,u),n.doorEnd=V.clone().addScaledVector(p,u),n.doorHeight=h.doorHeight,n.beamStart.z=n.beamEnd.z=n.doorStart.z+n.doorHeight):!M||M&&n.isPullOutDoor&&a?(h.beamStart=n.beamStart.clone().addScaledVector(d,u),h.beamEnd=n.beamEnd.clone().addScaledVector(d,u),h.doorStart=n.doorStart.clone().addScaledVector(d,u),h.doorEnd=n.doorEnd.clone().addScaledVector(d,u),h.doorHeight=n.doorHeight,h.beamStart.z=h.beamEnd.z=h.doorStart.z+h.doorHeight):(n.beamStart=R.clone().addScaledVector(p,u),n.beamEnd=z.clone().addScaledVector(p,u),n.doorStart=B.clone().addScaledVector(p,u),n.doorEnd=V.clone().addScaledVector(p,u),n.doorHeight=h.doorHeight,n.beamStart.z=n.beamEnd.z=n.doorStart.z+n.doorHeight):e>r&&(r>i&&!M?(h.beamStart=n.beamStart.clone().addScaledVector(p,u),h.beamEnd=n.beamEnd.clone().addScaledVector(p,u),h.doorStart=n.doorStart.clone().addScaledVector(p,u),h.doorEnd=n.doorEnd.clone().addScaledVector(p,u),h.doorHeight=n.doorHeight,h.beamStart.z=h.beamEnd.z=h.doorStart.z+h.doorHeight):!n.isPullOutDoor||M&&n.isPullOutDoor&&a?(n.beamStart=R.clone().addScaledVector(d,u),n.beamEnd=z.clone().addScaledVector(d,u),n.doorStart=B.clone().addScaledVector(d,u),n.doorEnd=V.clone().addScaledVector(d,u),n.doorHeight=h.doorHeight,n.beamStart.z=n.beamEnd.z=n.doorStart.z+n.doorHeight):(h.beamStart=n.beamStart.clone().addScaledVector(p,u),h.beamEnd=n.beamEnd.clone().addScaledVector(p,u),h.doorStart=n.doorStart.clone().addScaledVector(p,u),h.doorEnd=n.doorEnd.clone().addScaledVector(p,u),h.doorHeight=n.doorHeight,h.beamStart.z=h.beamEnd.z=h.doorStart.z+h.doorHeight)),x=h.nearId,v=n.beamStart.clone(),y=n.beamEnd.clone(),g=!0,w=l[t].linesIndex,k=l[t].doorIndex;break}}}let A=!1;if(!g){let i=new f.Line3(B.clone(),V.clone());for(let a=0;a<e.length;a++){if(e[a].length<.5||a==r)continue;let o=new f.Vector3(e[a].start.x,e[a].start.y,e[a].start.z),c=new f.Vector3(e[a].end.x,e[a].end.y,e[a].end.z),l=O(o,c,B,V),u=T(o,c,B,V),d=N(e[a]);if(console.log(`x`,a,`result`,l),l&&l.maxPerpendicularDistance<.5){if(u&&u.isParallel){let e=new f.Line3(o,c),t=new f.Vector3(B.x,B.y,o.z),n=e.closestPointToPoint(t,!0,new f.Vector3),r=E(n,t,B,V);r&&r.angle>85&&(h.beamNearWallVec=new f.Vector3().subVectors(n,t).normalize())}let r=[];e[a].originalPoints.forEach(e=>{e.z>B.z+.2&&e.z<B.z+C/2&&r.push(new f.Vector3(e.x,e.y,B.z))});let l=new f.Vector3,p=[],m=[];for(let e=0;e<r.length;e++){let t=i.closestPointToPoint(r[e],!0,l);t.distanceTo(r[e])<.15&&(p.push(r[e]),m.push(t.clone()))}for(let e=0;e<m.length;e++)L(i,m[e])&&p.push(m[e]);if(p=m,p=ne(p),p.length<150)continue;let g=ee(p);if(g.length==2){let r=g[0].distanceTo(g[1]);if(Math.abs(r-i.distance())<.3){let r=new f.Line3(o,c),i=new f.Vector3(B.x,B.y,o.z),a=r.closestPointToPoint(i,!0,new f.Vector3);if(h.beamNearWallVec=new f.Vector3().subVectors(a,i).normalize(),h.beamStart.z>d.maxZ-.03&&S>1)A=!0;else if(t=!0,ie!=-1&&(n[s[ie].index].isFindBeam=!1,s[ie].isFind=!1),w!=-1&&k!=-1){let t=e[w].doorAndBeamData[k];t.nearId=-1}break}}if(t)break}else l&&l.type==`collinear_overlap`&&l.maxPerpendicularDistance>.3&&l.maxPerpendicularDistance<.7&&(A=!0)}if(t){if(S<2)continue;A=!0}}let I=!1;if(x!=-1)for(let e=0;e<p.length&&!(p[e].length==1&&(p[e][0].id==c?(p[e].push({id:x,beamStart:v,beamEnd:y}),I=!0):p[e][0].id==x&&(p[e].push({id:c,beamStart:R,beamEnd:z}),I=!0),I));e++);I||p.push([{id:c,beamStart:R,beamEnd:z}]);let te=h.doorStart.distanceTo(h.doorEnd);if(console.log(`id:`,c,r,te),m=j?`door`:te>1.8||A&&te>1?`beam`:`hole`,h.type=m,h.nearId!=-1&&m==`hole`){let t=!1;for(let n=0;n<e.length;n++)if(e[n].doorAndBeamData){for(let r=0;r<e[n].doorAndBeamData.length;r++)if(e[n].doorAndBeamData[r].nearId==c&&e[n].doorAndBeamData[r].type==`beam`){e[n].doorAndBeamData[r].type=m,t=!0;break}if(t)break}}if(i.doorAndBeamData.push(h),l.push({linesIndex:r,doorIndex:i.doorAndBeamData.length-1}),c++,M&&S<2)break}}}let x=i.length*(i.rooftopPz-i.start.z);i.completePointAreaPercentage=y/x*100}if(u.length>1)for(let t=0;t<u.length;t++){let n=[];for(let r=0;r<e[u[t]].doorAndBeamData.length;r++){let i=!1;if(e[u[t]].doorAndBeamData[r].type===`beam`&&e[u[t]].doorAndBeamData[r].beamNearWallVec.x==0&&e[u[t]].doorAndBeamData[r].beamNearWallVec.y==0&&e[u[t]].doorAndBeamData[r].beamNearWallVec.z==0&&e[u[t]].doorAndBeamData[r].nearId==-1&&(i=!0),!i){let n=e[u[t]].doorAndBeamData[r].doorStart.clone(),a=e[u[t]].doorAndBeamData[r].doorEnd.clone();n.z=a.z=0;let o=n.distanceTo(a);for(let s=0;s<u.length;s++)if(t!=s)for(let c=0;c<e[u[s]].doorAndBeamData.length;c++){let l=e[u[s]].doorAndBeamData[c].doorStart.clone(),d=e[u[s]].doorAndBeamData[c].doorEnd.clone();l.z=d.z=0,l.distanceTo(d);let p=O(n,a,l,d);if(p.type==`collinear_overlap`&&p.maxPerpendicularDistance<.2){let m=new f.Line3(l,d),h=D(n,a),g=m.closestPointToPoint(h,!0,new f.Vector3),_=h.distanceTo(g);if(Math.abs(o-p.overlap)<.1&&_<.04){e[u[s]].doorAndBeamData[c].nearId==e[u[t]].doorAndBeamData[r].id&&(e[u[s]].doorAndBeamData[c].nearId=-1),i=!0;break}}}}i||n.push(e[u[t]].doorAndBeamData[r])}n.length!=e[u[t]].doorAndBeamData.length&&(e[u[t]].doorAndBeamData=n)}let h=.65,g=[],v=[];for(let t=0;t<s.length;t++){if(s[t].isFind||s[t].inWall)continue;let r=new f.Vector3(s[t].doorStartPt.x,s[t].doorStartPt.y,0),i=new f.Vector3(s[t].doorEndPt.x,s[t].doorEndPt.y,0),a=new f.Vector3().subVectors(r,i).normalize();for(let o=0;o<e.length;o++){if(e[o].length<.7||e[o].completePointAreaPercentage>60)continue;let l=new f.Vector3(e[o].start.x,e[o].start.y,0),u=new f.Vector3(e[o].end.x,e[o].end.y,0),d=new f.Vector3().subVectors(l,u).normalize(),y=.3,b=r.clone().addScaledVector(a,y),x=i.clone().addScaledVector(a.clone().negate(),y),S=l.clone().addScaledVector(d,y),C=u.clone().addScaledVector(d.clone().negate(),y);_(b,x,S,C);let w=T(b,x,S,C),D=r.distanceTo(l)>i.distanceTo(l)?i:r,k=D.distanceTo(l),A=D.distanceTo(u);if((k<m||A<m)&&w&&!w.isParallel){let a=r.distanceTo(l)<r.distanceTo(u)?l:u,d=!1;for(let y=0;y<e.length;y++){if(y==o||g.includes(y)||e[y].length<.7)continue;let S=new f.Vector3(e[y].start.x,e[y].start.y,0),C=new f.Vector3(e[y].end.x,e[y].end.y,0),w=new f.Vector3().subVectors(S,C).normalize(),D=w.clone().negate(),k=S.clone().addScaledVector(w,5),A=C.clone().addScaledVector(D,5),j=E(l,u,S,C),M=O(l,u,S,C),N=_(l,u,k,A),P=!0;if(N!=null&&(P=N.point.distanceTo(l)<m||N.point.distanceTo(u)<m),(j&&j.angle>85||M&&M.type==`collinear_gap`)&&P){let m=new f.Line3(l,u),_=new f.Vector3,w=m.closestPointToPoint(S,!0,_),E=m.closestPointToPoint(C,!0,_),D=w.distanceTo(S),k=E.distanceTo(C),A,j;if(D>k&&k>h)A=C,j=E;else if(D<k&&D>h)A=S,j=w;else continue;if(D=a.distanceTo(S),k=a.distanceTo(C),D>2&&k>2)continue;let M=T(A,j,S,C),N=T(A,j,b,x);if(N&&N.isParallel||!M||!M.isParallel)continue;let P=O(r,i,A,j);if(P&&P.type==`collinear_overlap`&&P.maxPerpendicularDistance<.2)continue;A.z=j.z=e[y].start.z;let F=!1;for(let e=0;e<v.length;e++){let t=O(v[e].start,v[e].end,A,j);if(t&&t.type==`collinear_overlap`&&t.maxPerpendicularDistance<.2){F=!0;break}}if(F)continue;for(let t=0;t<e.length;t++){if(e[t].length<.5)continue;let n=O(new f.Vector3(e[t].start.x,e[t].start.y,e[t].start.z),new f.Vector3(e[t].end.x,e[t].end.y,e[t].end.z),A,j);if(n&&n.type==`collinear_overlap`&&n.maxPerpendicularDistance<.1){F=!0;break}}if(F)continue;v.push({start:A,end:j}),g.push(y);let I=e[y].rooftopPz-e[y].start.z,L=e[o].rooftopPz-e[o].start.z,ee=I<L?I:L;e[y].doorAndBeamData||(e[y].doorAndBeamData=[]),e[y].doorAndBeamData.push({id:c,beamStart:A,beamEnd:j,beamHeight:ee,doorStart:A,doorEnd:j,doorHeight:ee,nearId:-1,type:`onlyDoor`,isDoor:!0,beamNearWallVec:new f.Vector3(0,0,0)}),n[s[t].index].isFindBeam=!0,n[s[t].index].isFindOnlyDoor=!0,p.push([{id:c,beamStart:A,beamEnd:j}]),c++,d=!0;break}}if(d)break}}}let y=[];for(let t=0;t<e.length;t++)e[t].isLine2||y.push(e[t]),e[t].isLine2&&e[t].doorAndBeamData.length!=0&&y.push(e[t]);return e.length=0,e.push(...y),{lines:e,beamGroup:p}},ye=(e,t)=>{if(e.length<=0)return e;for(let t of e){let e=[];for(let n=0;n<t.checkResults.length;n++){let r=t.checkResults[n];if(r.isDoor=!1,!r.originalVertices||r.originalVertices.length==0)continue;let i=[];r.originalVertices.forEach(e=>{let t=[];e.forEach(e=>{t.push(new f.Vector3(e.x,e.y,e.z))}),i.push(t)});let a=i.length,o=Array.from({length:a},(e,t)=>t);function s(e){for(;o[e]!==e;)o[e]=o[o[e]],e=o[e];return e}for(let e=0;e<a;e++)for(let t=e+1;t<a;t++){let n=i[e],r=i[t];if(n.some(e=>r.some(t=>e.equals(t)))){let n=s(e),r=s(t);n!==r&&(o[n]=r)}}let c=new Map,l=-1,u=-1;for(let e=0;e<a;e++){let t=s(e);c.has(t)||c.set(t,{points:[],area:0,originalVertices:[],index:-1,gridWidth:-1,gridHeight:-1,centerPts:[]});let r=c.get(t),[a,o,d,p]=i[e],m=new f.Vector3().add(a).add(o).add(d).add(p).multiplyScalar(.25);if(r.points.push(...i[e]),r.area+=a.distanceTo(o)*a.distanceTo(p),r.originalVertices.push(i[e]),r.index=n,r.centerPts.push(m),l==-1||u==-1){let e=new f.Vector3().subVectors(a,o).normalize();u=a.distanceTo(p),l=a.distanceTo(o);let t=b(e,new f.Vector3(0,0,1));t&&t.parallel&&([u,l]=[l,u])}r.gridWidth=l,r.gridHeight=u}e.push(...c.values())}t.mergeCheckRegion=e}let n=new Map;for(let t of e){let e=t.rooftopPz-t.start.z,r=Math.floor(t.rooftopPz-t.start.z);n.has(r)?n.set(r,{num:n.get(r).num+1,totalHeight:n.get(r).totalHeight+e}):n.set(r,{num:1,totalHeight:e})}let r=[...n.entries()].reduce((e,t)=>t[1].num>e[1].num?t:e),i=r[0];r[1].totalHeight/r[1].num,new f.MeshBasicMaterial({color:`#cffd00`,transparent:!0,opacity:.4,side:f.DoubleSide}),new f.PointsMaterial({color:65535,size:.01});for(let n=0;n<e.length;n++){let r=e[n],{minZ:a,maxZ:o}=N(r);if(a==null||o==null)continue;r.doorAndBeamData=[],r.completePointAreaPercentage=-1,o-a;let s=r.rooftopPz-r.start.z;if(s<i-.5||s>i+2||Math.abs(a-r.start.z)>.3||r.length<1)continue;let c=new f.Vector3(r.start.x,r.start.y,0),l=new f.Vector3(r.end.x,r.end.y,0);for(let r=0;r<e.length;r++){if(r==n||e[r].length<1)continue;let i=e[r],a=new f.Vector3(i.start.x,i.start.y,0),s=new f.Vector3(i.end.x,i.end.y,0),u=T(c,l,a,s),d=D(c,l),p=new f.Line3(a,s).closestPointToPoint(d,!0,new f.Vector3),m=d.distanceTo(p),h=N(i);if(!(h.minZ===void 0||h.maxZ===void 0)&&!(h.maxZ-h.minZ>1)&&u&&u.isParallel&&m<.25&&Math.abs(o-h.minZ)<.1){let i=D(c,l),o=D(a,s);i.z=o.z=1,i.applyEuler(new f.Euler(-Math.PI/2,0,0)),o.applyEuler(new f.Euler(-Math.PI/2,0,0));let u=`w:${e[n].originaIndex},b:${e[r].originaIndex}`,d=`b:${e[r].originaIndex},w:${e[n].originaIndex}`;t.add(v(u,i,{textColor:`#fd0000`})),t.add(v(d,o,{textColor:`#fd0000`}))}}}return e},be=(e,t)=>{if(!e||e.length<=0)return;let n={rectangles:[],threeEdgeRect:[]},r=new Set,i=.2,a=1.5,o=.15;if(!e[0].uuid){let t=1e4;for(let n=0;n<e.length;n++)e[n].uuid=t++}for(let t=0;t<e.length;t++){let s=e[t].length;if(r.has(e[t].uuid)||s<i||s>a)continue;let c=[],l=new f.Vector3(e[t].start.x,e[t].start.y,e[t].start.z),u=new f.Vector3(e[t].end.x,e[t].end.y,e[t].end.z),d=new f.Vector3().subVectors(u,l).normalize().clone().negate(),p=new f.Vector3,m=new f.Vector3,h=new f.Vector3;new f.Vector3;for(let n=0;n<e.length;n++){let r=e[n].length;if(n==t||r<i||r>a)continue;let g=new f.Vector3(e[n].start.x,e[n].start.y,e[n].start.z),_=new f.Vector3(e[n].end.x,e[n].end.y,e[n].end.z),v=E(l,u,g,_);if(!v||v.angle<85)continue;let y=R(g,l),x=R(g,u),S=R(_,l),C=R(_,u);if(!(!y&&!x&&!S&&!C)){y||x?(p=g.clone(),m=_.clone()):(p=_.clone(),m=g.clone()),h=new f.Vector3().subVectors(m,p).normalize(),h.clone().negate();for(let p=0;p<e.length;p++){let h=e[p].length;if(p==t||p==n||h<i||h>a)continue;let v=new f.Vector3(e[p].start.x,e[p].start.y,e[p].start.z),y=new f.Vector3(e[p].end.x,e[p].end.y,e[p].end.z),x=E(g,_,v,y);if(!x||x.angle<85)continue;let S=R(v,m),C=R(y,m);if(!S&&!C)continue;new f.Vector3;let w=new f.Vector3,T=new f.Vector3;S?(T=new f.Vector3().subVectors(y,v).normalize(),v.clone(),w=y.clone()):(T=new f.Vector3().subVectors(v,y).normalize(),y.clone(),w=v.clone());let D=b(d,T,.1);if(!(!D||!D.parallel||!D.sameDirection)){for(let d=0;d<e.length;d++){let m=e[d].length;if(d==t||d==n||d==p||m<i||m>a)continue;let h=new f.Vector3(e[d].start.x,e[d].start.y,e[d].start.z),g=new f.Vector3(e[d].end.x,e[d].end.y,e[d].end.z),_=E(h,g,v,y);if(!_||_.angle<85)continue;let b=R(h,w),x=R(g,w);if(!b&&!x)continue;new f.Vector3;let S=new f.Vector3;b?(h.clone(),S=g.clone()):(g.clone(),S=h.clone());let C=R(S,l),T=R(S,u);if(!C&&!T)continue;let D=s*r;if(!(D<o||D>2)){c=[e[t].uuid,e[n].uuid,e[p].uuid,e[d].uuid];break}}if(c.length==4)break}}if(c.length==4)break}}c.length==4&&(c.forEach(e=>r.add(e)),n.rectangles.push(c))}for(let t=0;t<e.length;t++){let s=e[t].length;if(r.has(e[t].uuid)||s<i||s>a)continue;let c={indexs:[],missingEdge:{start:new f.Vector3,end:new f.Vector3}},l=new f.Vector3(e[t].start.x,e[t].start.y,e[t].start.z),u=new f.Vector3(e[t].end.x,e[t].end.y,e[t].end.z),d=!0,p=!0;for(let n=0;n<e.length;n++){if(n==t||e[n].length<i)continue;let r=new f.Vector3(e[n].start.x,e[n].start.y,e[n].start.z),a=new f.Vector3(e[n].end.x,e[n].end.y,e[n].end.z),o=R(r,l),s=R(a,l),c=R(r,u),m=R(a,u);if(o||s?d=!1:(c||m)&&(p=!1),!d&&!p)break}if(!d&&!p)continue;let m=new f.Vector3;d||([l,u]=[u,l]),m=new f.Vector3().subVectors(u,l).normalize();let h=m.clone().negate();for(let n=0;n<e.length;n++){let d=e[n].length;if(n==t||r.has(n)||d<i||d>a)continue;let p=new f.Vector3(e[n].start.x,e[n].start.y,e[n].start.z),m=new f.Vector3(e[n].end.x,e[n].end.y,e[n].end.z),g=E(l,u,p,m);if(!g||g.angle<85)continue;let _=R(p,u),v=R(m,u);if(!_&&!v)continue;new f.Vector3;let y=new f.Vector3;_?(p.clone(),y=m.clone()):(m.clone(),y=p.clone());for(let u=0;u<e.length;u++){let g=e[u].length;if(u==t||u==n||r.has(u)||g<i||g>a)continue;let _=new f.Vector3(e[u].start.x,e[u].start.y,e[u].start.z),v=new f.Vector3(e[u].end.x,e[u].end.y,e[u].end.z),x=E(p,m,_,v);if(!x||x.angle<85)continue;let S=R(_,y),C=R(v,y);if(!S&&!C)continue;let w=new f.Vector3,T=new f.Vector3;S?(w=_.clone(),T=v.clone()):(w=v.clone(),T=_.clone());let D=b(h,new f.Vector3().subVectors(T,w).normalize(),.1);if(!D||!D.parallel||!D.sameDirection)continue;let O=!0,k=!0;for(let t=0;t<e.length;t++){if(t==u||e[t].length<i)continue;let n=new f.Vector3(e[t].start.x,e[t].start.y,e[t].start.z),r=new f.Vector3(e[t].end.x,e[t].end.y,e[t].end.z),a=R(n,_),o=R(r,_),s=R(n,v),c=R(r,v);if(a||o?O=!1:(s||c)&&(k=!1),!O&&!k)break}if(!O&&!k)continue;let A=s*d;if(!(A<o||A>2)){c.indexs=[e[t].uuid,e[n].uuid,e[u].uuid],c.missingEdge.start=T,c.missingEdge.end=l;break}}if(c.indexs.length==3)break}c.indexs.length==3&&(c.indexs.forEach(e=>r.add(e)),n.threeEdgeRect.push(c))}return n},H=11102230246251565e-32,U=134217729,xe=(3+8*H)*H;function Se(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function Ce(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function W(e){return new Float64Array(e)}var we=(3+16*H)*H,Te=(2+12*H)*H,Ee=(9+64*H)*H*H,De=W(4),Oe=W(8),ke=W(12),Ae=W(16),G=W(4);function je(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=U*T,p=f-(f-T),m=T-p,f=U*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=U*D,p=f-(f-D),m=D-p,f=U*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,De[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,De[1]=y-(_+d)+(d-S),w=v+_,d=w-v,De[2]=v-(w-d)+(_-d),De[3]=w;let k=Ce(4,De),A=Te*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=Ee*o+xe*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=U*s,p=f-(f-s),m=s-p,f=U*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=U*c,p=f-(f-c),m=c-p,f=U*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,G[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,G[1]=y-(_+d)+(d-S),w=v+_,d=w-v,G[2]=v-(w-d)+(_-d),G[3]=w;let j=Se(4,De,4,G,Oe);b=T*u,f=U*T,p=f-(f-T),m=T-p,f=U*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=U*D,p=f-(f-D),m=D-p,f=U*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,G[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,G[1]=y-(_+d)+(d-S),w=v+_,d=w-v,G[2]=v-(w-d)+(_-d),G[3]=w;let M=Se(j,Oe,4,G,ke);return b=s*u,f=U*s,p=f-(f-s),m=s-p,f=U*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=U*c,p=f-(f-c),m=c-p,f=U*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,G[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,G[1]=y-(_+d)+(d-S),w=v+_,d=w-v,G[2]=v-(w-d)+(_-d),G[3]=w,Ae[Se(M,ke,4,G,Ae)-1]}function Me(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=we*l?c:-je(e,t,n,r,i,a,l)}(7+56*H)*H,(3+28*H)*H,(26+288*H)*H*H,W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(8),W(8),W(8),W(4),W(8),W(8),W(16),W(12),W(192),W(192),(10+96*H)*H,(4+48*H)*H,(44+576*H)*H*H,W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(8),W(8),W(8),W(8),W(8),W(8),W(8),W(8),W(8),W(4),W(4),W(4),W(8),W(16),W(16),W(16),W(32),W(32),W(48),W(64),W(1152),W(1152),(16+224*H)*H,(5+72*H)*H,(71+1408*H)*H*H,W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(4),W(24),W(24),W(24),W(24),W(24),W(24),W(24),W(24),W(24),W(24),W(1152),W(1152),W(1152),W(1152),W(1152),W(2304),W(2304),W(3456),W(5760),W(8),W(8),W(8),W(16),W(24),W(48),W(48),W(96),W(192),W(384),W(384),W(384),W(768),W(96),W(96),W(96),W(1152);var Ne=2**-52,Pe=new Uint32Array(512),Fe=class e{static from(t,n=Ue,r=We){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),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(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=Le(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=Le(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=ze(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];Ve(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(Me(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=Be(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=Le(e[2*t],e[2*t+1],S.x,S.y);Ve(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=Ne&&Math.abs(u-s)<=Ne||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],Me(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],Me(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],Me(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(Ie(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=Pe[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(Re(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<Pe.length&&(Pe[i++]=s)}else{if(i===0)break;e=Pe[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function Ie(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function Le(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function Re(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function ze(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function Be(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function Ve(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;He(e,i,a),t[e[n]]>t[e[r]]&&He(e,n,r),t[e[a]]>t[e[r]]&&He(e,a,r),t[e[n]]>t[e[a]]&&He(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;He(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(Ve(e,t,a,r),Ve(e,t,n,o-1)):(Ve(e,t,n,o-1),Ve(e,t,a,r))}}function He(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function Ue(e){return e[0]}function We(e){return e[1]}var Ge=1e-6,Ke=class{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=``}moveTo(e,t){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+=`Z`)}lineTo(e,t){this._+=`L${this._x1=+e},${this._y1=+t}`}arc(e,t,n){e=+e,t=+t,n=+n;let r=e+n,i=t;if(n<0)throw Error(`negative radius`);this._x1===null?this._+=`M${r},${i}`:(Math.abs(this._x1-r)>Ge||Math.abs(this._y1-i)>Ge)&&(this._+=`L`+r+`,`+i),n&&(this._+=`A${n},${n},0,1,1,${e-n},${t}A${n},${n},0,1,1,${this._x1=r},${this._y1=i}`)}rect(e,t,n,r){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${+n}v${+r}h${-n}Z`}value(){return this._||null}},qe=class{constructor(){this._=[]}moveTo(e,t){this._.push([e,t])}closePath(){this._.push(this._[0].slice())}lineTo(e,t){this._.push([e,t])}value(){return this._.length?this._:null}},Je=class{constructor(e,[t,n,r,i]=[0,0,960,500]){if(!((r=+r)>=(t=+t))||!((i=+i)>=(n=+n)))throw Error(`invalid bounds`);this.delaunay=e,this._circumcenters=new Float64Array(e.points.length*2),this.vectors=new Float64Array(e.points.length*2),this.xmax=r,this.xmin=t,this.ymax=i,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){let{delaunay:{points:e,hull:t,triangles:n},vectors:r}=this,i,a,o=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let r=0,s=0,c=n.length,l,u;r<c;r+=3,s+=2){let c=n[r]*2,d=n[r+1]*2,f=n[r+2]*2,p=e[c],m=e[c+1],h=e[d],g=e[d+1],_=e[f],v=e[f+1],y=h-p,b=g-m,x=_-p,S=v-m,C=(y*S-b*x)*2;if(Math.abs(C)<1e-9){if(i===void 0){i=a=0;for(let n of t)i+=e[n*2],a+=e[n*2+1];i/=t.length,a/=t.length}let n=1e9*Math.sign((i-p)*S-(a-m)*x);l=(p+_)/2-n*S,u=(m+v)/2+n*x}else{let e=1/C,t=y*y+b*b,n=x*x+S*S;l=p+(S*t-b*n)*e,u=m+(y*n-x*t)*e}o[s]=l,o[s+1]=u}let s=t[t.length-1],c,l=s*4,u,d=e[2*s],f,p=e[2*s+1];r.fill(0);for(let n=0;n<t.length;++n)s=t[n],c=l,u=d,f=p,l=s*4,d=e[2*s],p=e[2*s+1],r[c+2]=r[l]=f-p,r[c+3]=r[l+1]=d-u}render(e){let t=e==null?e=new Ke:void 0,{delaunay:{halfedges:n,inedges:r,hull:i},circumcenters:a,vectors:o}=this;if(i.length<=1)return null;for(let t=0,r=n.length;t<r;++t){let r=n[t];if(r<t)continue;let i=Math.floor(t/3)*2,o=Math.floor(r/3)*2,s=a[i],c=a[i+1],l=a[o],u=a[o+1];this._renderSegment(s,c,l,u,e)}let s,c=i[i.length-1];for(let t=0;t<i.length;++t){s=c,c=i[t];let n=Math.floor(r[c]/3)*2,l=a[n],u=a[n+1],d=s*4,f=this._project(l,u,o[d+2],o[d+3]);f&&this._renderSegment(l,u,f[0],f[1],e)}return t&&t.value()}renderBounds(e){let t=e==null?e=new Ke:void 0;return e.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),t&&t.value()}renderCell(e,t){let n=t==null?t=new Ke:void 0,r=this._clip(e);if(r===null||!r.length)return;t.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 e=2;e<i;e+=2)(r[e]!==r[e-2]||r[e+1]!==r[e-1])&&t.lineTo(r[e],r[e+1]);return t.closePath(),n&&n.value()}*cellPolygons(){let{delaunay:{points:e}}=this;for(let t=0,n=e.length/2;t<n;++t){let e=this.cellPolygon(t);e&&(e.index=t,yield e)}}cellPolygon(e){let t=new qe;return this.renderCell(e,t),t.value()}_renderSegment(e,t,n,r,i){let a,o=this._regioncode(e,t),s=this._regioncode(n,r);o===0&&s===0?(i.moveTo(e,t),i.lineTo(n,r)):(a=this._clipSegment(e,t,n,r,o,s))&&(i.moveTo(a[0],a[1]),i.lineTo(a[2],a[3]))}contains(e,t,n){return(t=+t,t!==t)||(n=+n,n!==n)?!1:this.delaunay._step(e,t,n)===e}*neighbors(e){let t=this._clip(e);if(t)for(let n of this.delaunay.neighbors(e)){let e=this._clip(n);if(e){loop:for(let r=0,i=t.length;r<i;r+=2)for(let a=0,o=e.length;a<o;a+=2)if(t[r]===e[a]&&t[r+1]===e[a+1]&&t[(r+2)%i]===e[(a+o-2)%o]&&t[(r+3)%i]===e[(a+o-1)%o]){yield n;break loop}}}}_cell(e){let{circumcenters:t,delaunay:{inedges:n,halfedges:r,triangles:i}}=this,a=n[e];if(a===-1)return null;let o=[],s=a;do{let n=Math.floor(s/3);if(o.push(t[n*2],t[n*2+1]),s=s%3==2?s-2:s+1,i[s]!==e)break;s=r[s]}while(s!==a&&s!==-1);return o}_clip(e){if(e===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];let t=this._cell(e);if(t===null)return null;let{vectors:n}=this,r=e*4;return this._simplify(n[r]||n[r+1]?this._clipInfinite(e,t,n[r],n[r+1],n[r+2],n[r+3]):this._clipFinite(e,t))}_clipFinite(e,t){let n=t.length,r=null,i,a,o=t[n-2],s=t[n-1],c,l=this._regioncode(o,s),u,d=0;for(let f=0;f<n;f+=2)if(i=o,a=s,o=t[f],s=t[f+1],c=l,l=this._regioncode(o,s),c===0&&l===0)u=d,d=0,r?r.push(o,s):r=[o,s];else{let t,n,f,p,m;if(c===0){if((t=this._clipSegment(i,a,o,s,c,l))===null)continue;[n,f,p,m]=t}else{if((t=this._clipSegment(o,s,i,a,l,c))===null)continue;[p,m,n,f]=t,u=d,d=this._edgecode(n,f),u&&d&&this._edge(e,u,d,r,r.length),r?r.push(n,f):r=[n,f]}u=d,d=this._edgecode(p,m),u&&d&&this._edge(e,u,d,r,r.length),r?r.push(p,m):r=[p,m]}if(r)u=d,d=this._edgecode(r[0],r[1]),u&&d&&this._edge(e,u,d,r,r.length);else if(this.contains(e,(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(e,t,n,r,i,a){let o=i<a;for(o&&([e,t,n,r,i,a]=[n,r,e,t,a,i]);;){if(i===0&&a===0)return o?[n,r,e,t]:[e,t,n,r];if(i&a)return null;let s,c,l=i||a;l&8?(s=e+(n-e)*(this.ymax-t)/(r-t),c=this.ymax):l&4?(s=e+(n-e)*(this.ymin-t)/(r-t),c=this.ymin):l&2?(c=t+(r-t)*(this.xmax-e)/(n-e),s=this.xmax):(c=t+(r-t)*(this.xmin-e)/(n-e),s=this.xmin),i?(e=s,t=c,i=this._regioncode(e,t)):(n=s,r=c,a=this._regioncode(n,r))}}_clipInfinite(e,t,n,r,i,a){let o=Array.from(t),s;if((s=this._project(o[0],o[1],n,r))&&o.unshift(s[0],s[1]),(s=this._project(o[o.length-2],o[o.length-1],i,a))&&o.push(s[0],s[1]),o=this._clipFinite(e,o))for(let t=0,n=o.length,r,i=this._edgecode(o[n-2],o[n-1]);t<n;t+=2)r=i,i=this._edgecode(o[t],o[t+1]),r&&i&&(t=this._edge(e,r,i,o,t),n=o.length);else this.contains(e,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(o=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return o}_edge(e,t,n,r,i){for(;t!==n;){let n,a;switch(t){case 5:t=4;continue;case 4:t=6,n=this.xmax,a=this.ymin;break;case 6:t=2;continue;case 2:t=10,n=this.xmax,a=this.ymax;break;case 10:t=8;continue;case 8:t=9,n=this.xmin,a=this.ymax;break;case 9:t=1;continue;case 1:t=5,n=this.xmin,a=this.ymin;break}(r[i]!==n||r[i+1]!==a)&&this.contains(e,n,a)&&(r.splice(i,0,n,a),i+=2)}return i}_project(e,t,n,r){let i=1/0,a,o,s;if(r<0){if(t<=this.ymin)return null;(a=(this.ymin-t)/r)<i&&(s=this.ymin,o=e+(i=a)*n)}else if(r>0){if(t>=this.ymax)return null;(a=(this.ymax-t)/r)<i&&(s=this.ymax,o=e+(i=a)*n)}if(n>0){if(e>=this.xmax)return null;(a=(this.xmax-e)/n)<i&&(o=this.xmax,s=t+(i=a)*r)}else if(n<0){if(e<=this.xmin)return null;(a=(this.xmin-e)/n)<i&&(o=this.xmin,s=t+(i=a)*r)}return[o,s]}_edgecode(e,t){return(e===this.xmin?1:e===this.xmax?2:0)|(t===this.ymin?4:t===this.ymax?8:0)}_regioncode(e,t){return(e<this.xmin?1:e>this.xmax?2:0)|(t<this.ymin?4:t>this.ymax?8:0)}_simplify(e){if(e&&e.length>4){for(let t=0;t<e.length;t+=2){let n=(t+2)%e.length,r=(t+4)%e.length;(e[t]===e[n]&&e[n]===e[r]||e[t+1]===e[n+1]&&e[n+1]===e[r+1])&&(e.splice(n,2),t-=2)}e.length||(e=null)}return e}},Ye=2*Math.PI,Xe=Math.pow;function Ze(e){return e[0]}function Qe(e){return e[1]}function $e(e){let{triangles:t,coords:n}=e;for(let e=0;e<t.length;e+=3){let r=2*t[e],i=2*t[e+1],a=2*t[e+2];if((n[a]-n[r])*(n[i+1]-n[r+1])-(n[i]-n[r])*(n[a+1]-n[r+1])>1e-10)return!1}return!0}function et(e,t,n){return[e+Math.sin(e+t)*n,t+Math.cos(e-t)*n]}var tt=class e{static from(t,n=Ze,r=Qe,i){return new e(`length`in t?nt(t,n,r,i):Float64Array.from(rt(t,n,r,i)))}constructor(e){this._delaunator=new Fe(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(){let e=this._delaunator,t=this.points;if(e.hull&&e.hull.length>2&&$e(e)){this.collinear=Int32Array.from({length:t.length/2},(e,t)=>t).sort((e,n)=>t[2*e]-t[2*n]||t[2*e+1]-t[2*n+1]);let e=this.collinear[0],n=this.collinear[this.collinear.length-1],r=[t[2*e],t[2*e+1],t[2*n],t[2*n+1]],i=1e-8*Math.hypot(r[3]-r[1],r[2]-r[0]);for(let e=0,n=t.length/2;e<n;++e){let n=et(t[2*e],t[2*e+1],i);t[2*e]=n[0],t[2*e+1]=n[1]}this._delaunator=new Fe(t)}else delete this.collinear;let n=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,i=this.triangles=this._delaunator.triangles,a=this.inedges.fill(-1),o=this._hullIndex.fill(-1);for(let e=0,t=n.length;e<t;++e){let t=i[e%3==2?e-2:e+1];(n[e]===-1||a[t]===-1)&&(a[t]=e)}for(let e=0,t=r.length;e<t;++e)o[r[e]]=e;r.length<=2&&r.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=r[0],a[r[0]]=1,r.length===2&&(a[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(e){return new Je(this,e)}*neighbors(e){let{inedges:t,hull:n,_hullIndex:r,halfedges:i,triangles:a,collinear:o}=this;if(o){let t=o.indexOf(e);t>0&&(yield o[t-1]),t<o.length-1&&(yield o[t+1]);return}let s=t[e];if(s===-1)return;let c=s,l=-1;do{if(yield l=a[c],c=c%3==2?c-2:c+1,a[c]!==e)return;if(c=i[c],c===-1){let t=n[(r[e]+1)%n.length];t!==l&&(yield t);return}}while(c!==s)}find(e,t,n=0){if((e=+e,e!==e)||(t=+t,t!==t))return-1;let r=n,i;for(;(i=this._step(n,e,t))>=0&&i!==n&&i!==r;)n=i;return i}_step(e,t,n){let{inedges:r,hull:i,_hullIndex:a,halfedges:o,triangles:s,points:c}=this;if(r[e]===-1||!c.length)return(e+1)%(c.length>>1);let l=e,u=Xe(t-c[e*2],2)+Xe(n-c[e*2+1],2),d=r[e],f=d;do{let r=s[f],d=Xe(t-c[r*2],2)+Xe(n-c[r*2+1],2);if(d<u&&(u=d,l=r),f=f%3==2?f-2:f+1,s[f]!==e)break;if(f=o[f],f===-1){if(f=i[(a[e]+1)%i.length],f!==r&&Xe(t-c[f*2],2)+Xe(n-c[f*2+1],2)<u)return f;break}}while(f!==d);return l}render(e){let t=e==null?e=new Ke:void 0,{points:n,halfedges:r,triangles:i}=this;for(let t=0,a=r.length;t<a;++t){let a=r[t];if(a<t)continue;let o=i[t]*2,s=i[a]*2;e.moveTo(n[o],n[o+1]),e.lineTo(n[s],n[s+1])}return this.renderHull(e),t&&t.value()}renderPoints(e,t){t===void 0&&(!e||typeof e.moveTo!=`function`)&&(t=e,e=null),t=t==null?2:+t;let n=e==null?e=new Ke:void 0,{points:r}=this;for(let n=0,i=r.length;n<i;n+=2){let i=r[n],a=r[n+1];e.moveTo(i+t,a),e.arc(i,a,t,0,Ye)}return n&&n.value()}renderHull(e){let t=e==null?e=new Ke:void 0,{hull:n,points:r}=this,i=n[0]*2,a=n.length;e.moveTo(r[i],r[i+1]);for(let t=1;t<a;++t){let i=2*n[t];e.lineTo(r[i],r[i+1])}return e.closePath(),t&&t.value()}hullPolygon(){let e=new qe;return this.renderHull(e),e.value()}renderTriangle(e,t){let n=t==null?t=new Ke:void 0,{points:r,triangles:i}=this,a=i[e*=3]*2,o=i[e+1]*2,s=i[e+2]*2;return t.moveTo(r[a],r[a+1]),t.lineTo(r[o],r[o+1]),t.lineTo(r[s],r[s+1]),t.closePath(),n&&n.value()}*trianglePolygons(){let{triangles:e}=this;for(let t=0,n=e.length/3;t<n;++t)yield this.trianglePolygon(t)}trianglePolygon(e){let t=new qe;return this.renderTriangle(e,t),t.value()}};function nt(e,t,n,r){let i=e.length,a=new Float64Array(i*2);for(let o=0;o<i;++o){let i=e[o];a[o*2]=t.call(r,i,o,e),a[o*2+1]=n.call(r,i,o,e)}return a}function*rt(e,t,n,r){let i=0;for(let a of e)yield t.call(r,a,i,e),yield n.call(r,a,i,e),++i}function it(e,t,n,r){return 1+(e[t][0]===0||e[n][0]===0||e[r][0]===0?1:0)}function at(e,t,n,r,i,a){let o=Math.hypot(n-i,r-a),s=Math.hypot(e-i,t-a),c=Math.hypot(e-n,t-r),l=Math.abs((n-e)*(a-t)-(i-e)*(r-t))/2;return l===0?1/0:o*s*c/(4*l)}function ot(e){if(!e||e.length<3)return[];let t=new Set,n=[];for(let r of e){let e=`${r[0]}_${r[1]}`;t.has(e)||(t.add(e),n.push(r))}if(n.length<3)return[];let{triangles:r}=new tt(Float64Array.from(n.flat()));if(!r.length)return[];let i=new Map,a=(e,t)=>e<t?`${e}_${t}`:`${t}_${e}`;for(let e=0;e<r.length;e+=3){let t=r[e],o=r[e+1],s=r[e+2],[c,l]=n[t],[u,d]=n[o],[f,p]=n[s];if(at(c,l,u,d,f,p)<=1/it(n,t,o,s))for(let[e,n]of[[t,o],[o,s],[s,t]]){let t=a(e,n);i.set(t,(i.get(t)||0)+1)}}let o=[];for(let[e,t]of i)t===1&&o.push(e.split(`_`).map(Number));if(!o.length)return[];let s=new Map;for(let[e,t]of o)(s.get(e)||s.set(e,[]).get(e)).push(t),(s.get(t)||s.set(t,[]).get(t)).push(e);let c=o[0][0],l=[],u=new Set,d=c,f=-1;do{l.push(n[d]),u.add(d);let e=s.get(d)||[],t=e.find(e=>e!==f&&!u.has(e));if(t===void 0&&(t=e.find(e=>e!==f)),t===void 0)break;f=d,d=t}while(d!==c&&l.length<=o.length+1);return l}var K={c:null,u:[new f.Vector3,new f.Vector3,new f.Vector3],e:[]},q={c:null,u:[new f.Vector3,new f.Vector3,new f.Vector3],e:[]},J=[[],[],[]],Y=[[],[],[]],X=[],st=new f.Vector3,ct=new f.Vector3,lt=new f.Vector3,Z=new f.Vector3,ut=new f.Vector3,dt=new f.Vector3,Q=new f.Matrix3,ft=new f.Box3,pt=new f.Matrix4,mt=new f.Matrix4,ht=new f.Ray,gt=class{constructor(e=new f.Vector3,t=new f.Vector3,n=new f.Matrix3){this.center=e,this.halfSize=t,this.rotation=n}set(e,t,n){return this.center=e,this.halfSize=t,this.rotation=n,this}copy(e){return this.center.copy(e.center),this.halfSize.copy(e.halfSize),this.rotation.copy(e.rotation),this}clone(){return new this.constructor().copy(this)}getSize(e){return e.copy(this.halfSize).multiplyScalar(2)}clampPoint(e,t){let n=this.halfSize;Z.subVectors(e,this.center),this.rotation.extractBasis(st,ct,lt),t.copy(this.center);let r=f.MathUtils.clamp(Z.dot(st),-n.x,n.x);t.add(st.multiplyScalar(r));let i=f.MathUtils.clamp(Z.dot(ct),-n.y,n.y);t.add(ct.multiplyScalar(i));let a=f.MathUtils.clamp(Z.dot(lt),-n.z,n.z);return t.add(lt.multiplyScalar(a)),t}containsPoint(e){return Z.subVectors(e,this.center),this.rotation.extractBasis(st,ct,lt),Math.abs(Z.dot(st))<=this.halfSize.x&&Math.abs(Z.dot(ct))<=this.halfSize.y&&Math.abs(Z.dot(lt))<=this.halfSize.z}intersectsBox3(e){return this.intersectsOBB(_t.fromBox3(e))}intersectsSphere(e){return this.clampPoint(e.center,dt),dt.distanceToSquared(e.center)<=e.radius*e.radius}intersectsOBB(e,t=2**-52){K.c=this.center,K.e[0]=this.halfSize.x,K.e[1]=this.halfSize.y,K.e[2]=this.halfSize.z,this.rotation.extractBasis(K.u[0],K.u[1],K.u[2]),q.c=e.center,q.e[0]=e.halfSize.x,q.e[1]=e.halfSize.y,q.e[2]=e.halfSize.z,e.rotation.extractBasis(q.u[0],q.u[1],q.u[2]);for(let e=0;e<3;e++)for(let t=0;t<3;t++)J[e][t]=K.u[e].dot(q.u[t]);Z.subVectors(q.c,K.c),X[0]=Z.dot(K.u[0]),X[1]=Z.dot(K.u[1]),X[2]=Z.dot(K.u[2]);for(let e=0;e<3;e++)for(let n=0;n<3;n++)Y[e][n]=Math.abs(J[e][n])+t;let n,r;for(let e=0;e<3;e++)if(n=K.e[e],r=q.e[0]*Y[e][0]+q.e[1]*Y[e][1]+q.e[2]*Y[e][2],Math.abs(X[e])>n+r)return!1;for(let e=0;e<3;e++)if(n=K.e[0]*Y[0][e]+K.e[1]*Y[1][e]+K.e[2]*Y[2][e],r=q.e[e],Math.abs(X[0]*J[0][e]+X[1]*J[1][e]+X[2]*J[2][e])>n+r)return!1;return n=K.e[1]*Y[2][0]+K.e[2]*Y[1][0],r=q.e[1]*Y[0][2]+q.e[2]*Y[0][1],!(Math.abs(X[2]*J[1][0]-X[1]*J[2][0])>n+r||(n=K.e[1]*Y[2][1]+K.e[2]*Y[1][1],r=q.e[0]*Y[0][2]+q.e[2]*Y[0][0],Math.abs(X[2]*J[1][1]-X[1]*J[2][1])>n+r)||(n=K.e[1]*Y[2][2]+K.e[2]*Y[1][2],r=q.e[0]*Y[0][1]+q.e[1]*Y[0][0],Math.abs(X[2]*J[1][2]-X[1]*J[2][2])>n+r)||(n=K.e[0]*Y[2][0]+K.e[2]*Y[0][0],r=q.e[1]*Y[1][2]+q.e[2]*Y[1][1],Math.abs(X[0]*J[2][0]-X[2]*J[0][0])>n+r)||(n=K.e[0]*Y[2][1]+K.e[2]*Y[0][1],r=q.e[0]*Y[1][2]+q.e[2]*Y[1][0],Math.abs(X[0]*J[2][1]-X[2]*J[0][1])>n+r)||(n=K.e[0]*Y[2][2]+K.e[2]*Y[0][2],r=q.e[0]*Y[1][1]+q.e[1]*Y[1][0],Math.abs(X[0]*J[2][2]-X[2]*J[0][2])>n+r)||(n=K.e[0]*Y[1][0]+K.e[1]*Y[0][0],r=q.e[1]*Y[2][2]+q.e[2]*Y[2][1],Math.abs(X[1]*J[0][0]-X[0]*J[1][0])>n+r)||(n=K.e[0]*Y[1][1]+K.e[1]*Y[0][1],r=q.e[0]*Y[2][2]+q.e[2]*Y[2][0],Math.abs(X[1]*J[0][1]-X[0]*J[1][1])>n+r)||(n=K.e[0]*Y[1][2]+K.e[1]*Y[0][2],r=q.e[0]*Y[2][1]+q.e[1]*Y[2][0],Math.abs(X[1]*J[0][2]-X[0]*J[1][2])>n+r))}intersectsPlane(e){this.rotation.extractBasis(st,ct,lt);let t=this.halfSize.x*Math.abs(e.normal.dot(st))+this.halfSize.y*Math.abs(e.normal.dot(ct))+this.halfSize.z*Math.abs(e.normal.dot(lt)),n=e.normal.dot(this.center)-e.constant;return Math.abs(n)<=t}intersectRay(e,t){return this.getSize(ut),ft.setFromCenterAndSize(Z.set(0,0,0),ut),pt.setFromMatrix3(this.rotation),pt.setPosition(this.center),mt.copy(pt).invert(),ht.copy(e).applyMatrix4(mt),ht.intersectBox(ft,t)?t.applyMatrix4(pt):null}intersectsRay(e){return this.intersectRay(e,Z)!==null}fromBox3(e){return e.getCenter(this.center),e.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(e){return e.center.equals(this.center)&&e.halfSize.equals(this.halfSize)&&e.rotation.equals(this.rotation)}applyMatrix4(e){let t=e.elements,n=Z.set(t[0],t[1],t[2]).length(),r=Z.set(t[4],t[5],t[6]).length(),i=Z.set(t[8],t[9],t[10]).length();e.determinant()<0&&(n=-n),Q.setFromMatrix4(e);let a=1/n,o=1/r,s=1/i;return Q.elements[0]*=a,Q.elements[1]*=a,Q.elements[2]*=a,Q.elements[3]*=o,Q.elements[4]*=o,Q.elements[5]*=o,Q.elements[6]*=s,Q.elements[7]*=s,Q.elements[8]*=s,this.rotation.multiply(Q),this.halfSize.x*=n,this.halfSize.y*=r,this.halfSize.z*=i,Z.setFromMatrixPosition(e),this.center.add(Z),this}},_t=new gt,$=6371008.8,vt={centimeters:$*100,centimetres:$*100,degrees:360/(2*Math.PI),feet:$*3.28084,inches:$*39.37,kilometers:$/1e3,kilometres:$/1e3,meters:$,metres:$,miles:$/1609.344,millimeters:$*1e3,millimetres:$*1e3,nauticalmiles:$/1852,radians:1,yards:$*1.0936};function yt(e,t,n={}){let r={type:`Feature`};return(n.id===0||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function bt(e,t,n={}){if(!e)throw Error(`coordinates is required`);if(!Array.isArray(e))throw Error(`coordinates must be an Array`);if(e.length<2)throw Error(`coordinates must be at least 2 numbers long`);if(!Dt(e[0])||!Dt(e[1]))throw Error(`coordinates must contain numbers`);return yt({type:`Point`,coordinates:e},t,n)}function xt(e,t,n={}){for(let t of e){if(t.length<4)throw Error(`Each LinearRing of a Polygon must have 4 or more Positions.`);if(t[t.length-1].length!==t[0].length)throw Error(`First and last Position are not equivalent.`);for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw Error(`First and last Position are not equivalent.`)}return yt({type:`Polygon`,coordinates:e},t,n)}function St(e,t=`kilometers`){let n=vt[t];if(!n)throw Error(t+` units is invalid`);return e*n}function Ct(e,t=`kilometers`){let n=vt[t];if(!n)throw Error(t+` units is invalid`);return e/n}function wt(e){return e%(2*Math.PI)*180/Math.PI}function Tt(e){return e%360*Math.PI/180}function Et(e,t=`kilometers`,n=`kilometers`){if(!(e>=0))throw Error(`length must be a positive number`);return St(Ct(e,t),n)}function Dt(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e,t,n){if(e!==null)for(var r,i,a,o,s,c,l,u=0,d=0,f,p=e.type,m=p===`FeatureCollection`,h=p===`Feature`,g=m?e.features.length:1,_=0;_<g;_++){l=m?e.features[_].geometry:h?e.geometry:e,f=l?l.type===`GeometryCollection`:!1,s=f?l.geometries.length:1;for(var v=0;v<s;v++){var y=0,b=0;if(o=f?l.geometries[v]:l,o!==null){c=o.coordinates;var x=o.type;switch(u=n&&(x===`Polygon`||x===`MultiPolygon`)?1:0,x){case null:break;case`Point`:if(t(c,d,_,y,b)===!1)return!1;d++,y++;break;case`LineString`:case`MultiPoint`:for(r=0;r<c.length;r++){if(t(c[r],d,_,y,b)===!1)return!1;d++,x===`MultiPoint`&&y++}x===`LineString`&&y++;break;case`Polygon`:case`MultiLineString`:for(r=0;r<c.length;r++){for(i=0;i<c[r].length-u;i++){if(t(c[r][i],d,_,y,b)===!1)return!1;d++}x===`MultiLineString`&&y++,x===`Polygon`&&b++}x===`Polygon`&&y++;break;case`MultiPolygon`:for(r=0;r<c.length;r++){for(b=0,i=0;i<c[r].length;i++){for(a=0;a<c[r][i].length-u;a++){if(t(c[r][i][a],d,_,y,b)===!1)return!1;d++}b++}y++}break;case`GeometryCollection`:for(r=0;r<o.geometries.length;r++)if(kt(o.geometries[r],t,n)===!1)return!1;break;default:throw Error(`Unknown Geometry Type`)}}}}}function At(e){var t=[];return kt(e,function(e){t.push(e)}),t}function jt(e,t){var n,r,i,a,o,s,c,l,u,d,f=0,p=e.type===`FeatureCollection`,m=e.type===`Feature`,h=p?e.features.length:1;for(n=0;n<h;n++){for(s=p?e.features[n].geometry:m?e.geometry:e,l=p?e.features[n].properties:m?e.properties:{},u=p?e.features[n].bbox:m?e.bbox:void 0,d=p?e.features[n].id:m?e.id:void 0,c=s?s.type===`GeometryCollection`:!1,o=c?s.geometries.length:1,i=0;i<o;i++){if(a=c?s.geometries[i]:s,a===null){if(t(null,f,l,u,d)===!1)return!1;continue}switch(a.type){case`Point`:case`LineString`:case`MultiPoint`:case`Polygon`:case`MultiLineString`:case`MultiPolygon`:if(t(a,f,l,u,d)===!1)return!1;break;case`GeometryCollection`:for(r=0;r<a.geometries.length;r++)if(t(a.geometries[r],f,l,u,d)===!1)return!1;break;default:throw Error(`Unknown Geometry Type`)}}f++}}function Mt(e,t,n){var r=n;return jt(e,function(e,i,a,o,s){r=i===0&&n===void 0?e:t(r,e,i,a,o,s)}),r}var Nt=s(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self).RBush=r()})(e,function(){"use strict";function e(e,r,i,a,o){(function e(n,r,i,a,o){for(;a>i;){if(a-i>600){var s=a-i+1,c=r-i+1,l=Math.log(s),u=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*u*(s-u)/s)*(c-s/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-c*u/s+d)),Math.min(a,Math.floor(r+(s-c)*u/s+d)),o)}var f=n[r],p=i,m=a;for(t(n,i,r),o(n[a],f)>0&&t(n,i,a);p<m;){for(t(n,p,m),p++,m--;o(n[p],f)<0;)p++;for(;o(n[m],f)>0;)m--}o(n[i],f)===0?t(n,i,m):t(n,++m,a),m<=r&&(i=m+1),r<=m&&(a=m-1)}})(e,r,i||0,a||e.length-1,o||n)}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return e<t?-1:e>t?1:0}var r=function(e){e===void 0&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function i(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function a(e,t){o(e,0,e.children.length,t,e)}function o(e,t,n,r,i){i||=m(null),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var a=t;a<n;a++){var o=e.children[a];s(i,e.leaf?r(o):o)}return i}function s(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function c(e,t){return e.minX-t.minX}function l(e,t){return e.minY-t.minY}function u(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function d(e){return e.maxX-e.minX+(e.maxY-e.minY)}function f(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function p(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function m(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function h(t,n,r,i,a){for(var o=[n,r];o.length;)if(!((r=o.pop())-(n=o.pop())<=i)){var s=n+Math.ceil((r-n)/i/2)*i;e(t,s,n,r,a),o.push(n,s,s,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(e){var t=this.data,n=[];if(!p(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var a=0;a<t.children.length;a++){var o=t.children[a],s=t.leaf?r(o):o;p(e,s)&&(t.leaf?n.push(o):f(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n},r.prototype.collides=function(e){var t=this.data;if(!p(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],a=t.leaf?this.toBBox(i):i;if(p(e,a)){if(t.leaf||f(e,a))return!0;n.push(i)}}t=n.pop()}return!1},r.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},r.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(e,t){if(!e)return this;for(var n,r,a,o=this.data,s=this.toBBox(e),c=[],l=[];o||c.length;){if(o||(o=c.pop(),r=c[c.length-1],n=l.pop(),a=!0),o.leaf){var u=i(e,o.children,t);if(u!==-1)return o.children.splice(u,1),c.push(o),this._condense(c),this}a||o.leaf||!f(o,s)?r?(n++,o=r.children[n],a=!1):o=null:(c.push(o),l.push(n),n=0,r=o,o=o.children[0])}return this},r.prototype.toBBox=function(e){return e},r.prototype.compareMinX=function(e,t){return e.minX-t.minX},r.prototype.compareMinY=function(e,t){return e.minY-t.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(e){return this.data=e,this},r.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},r.prototype._build=function(e,t,n,r){var i,o=n-t+1,s=this._maxEntries;if(o<=s)return a(i=m(e.slice(t,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/s**(r-1))),(i=m([])).leaf=!1,i.height=r;var c=Math.ceil(o/s),l=c*Math.ceil(Math.sqrt(s));h(e,t,n,l,this.compareMinX);for(var u=t;u<=n;u+=l){var d=Math.min(u+l-1,n);h(e,u,d,c,this.compareMinY);for(var f=u;f<=d;f+=c){var p=Math.min(f+c-1,d);i.children.push(this._build(e,f,p,r-1))}}return a(i,this.toBBox),i},r.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,a=1/0,o=void 0,s=0;s<t.children.length;s++){var c=t.children[s],l=u(c),d=(f=e,p=c,(Math.max(p.maxX,f.maxX)-Math.min(p.minX,f.minX))*(Math.max(p.maxY,f.maxY)-Math.min(p.minY,f.minY))-l);d<a?(a=d,i=l<i?l:i,o=c):d===a&&l<i&&(i=l,o=c)}t=o||t.children[0]}var f,p;return t},r.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),s(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},r.prototype._split=function(e,t){var n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var o=this._chooseSplitIndex(n,i,r),s=m(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,a(n,this.toBBox),a(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)},r.prototype._splitRoot=function(e,t){this.data=m([e,t]),this.data.height=e.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(e,t,n){for(var r,i,a,s,c,l,d,f=1/0,p=1/0,m=t;m<=n-t;m++){var h=o(e,0,m,this.toBBox),g=o(e,m,n,this.toBBox),_=(i=h,a=g,s=void 0,c=void 0,l=void 0,d=void 0,s=Math.max(i.minX,a.minX),c=Math.max(i.minY,a.minY),l=Math.min(i.maxX,a.maxX),d=Math.min(i.maxY,a.maxY),Math.max(0,l-s)*Math.max(0,d-c)),v=u(h)+u(g);_<f?(f=_,r=m,p=v<p?v:p):_===f&&v<p&&(p=v,r=m)}return r||n-t},r.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:c,i=e.leaf?this.compareMinY:l;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},r.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var i=this.toBBox,a=o(e,0,t,i),c=o(e,n-t,n,i),l=d(a)+d(c),u=t;u<n-t;u++){var f=e.children[u];s(a,e.leaf?i(f):f),l+=d(a)}for(var p=n-t-1;p>=t;p--){var m=e.children[p];s(c,e.leaf?i(m):m),l+=d(c)}return l},r.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)s(t[r],e)},r.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():a(e[t],this.toBBox)},r})})),Pt=c({default:()=>It});function Ft(e,t){return e<t?-1:e>t?1:0}var It,Lt=o((()=>{It=class{constructor(e=[],t=Ft){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;let e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){let{data:t,compare:n}=this,r=t[e];for(;e>0;){let i=e-1>>1,a=t[i];if(n(r,a)>=0)break;t[e]=a,e=i}t[e]=r}_down(e){let{data:t,compare:n}=this,r=this.length>>1,i=t[e];for(;e<r;){let r=(e<<1)+1,a=t[r],o=r+1;if(o<this.length&&n(t[o],a)<0&&(r=o,a=t[o]),n(a,i)>=0)break;t[e]=a,e=r}t[e]=i}}})),Rt=s(((e,t)=>{t.exports=function(e,t,n,r){var i=e[0],a=e[1],o=!1;n===void 0&&(n=0),r===void 0&&(r=t.length);for(var s=(r-n)/2,c=0,l=s-1;c<s;l=c++){var u=t[n+c*2+0],d=t[n+c*2+1],f=t[n+l*2+0],p=t[n+l*2+1];d>a!=p>a&&i<(f-u)*(a-d)/(p-d)+u&&(o=!o)}return o}})),zt=s(((e,t)=>{t.exports=function(e,t,n,r){var i=e[0],a=e[1],o=!1;n===void 0&&(n=0),r===void 0&&(r=t.length);for(var s=r-n,c=0,l=s-1;c<s;l=c++){var u=t[c+n][0],d=t[c+n][1],f=t[l+n][0],p=t[l+n][1];d>a!=p>a&&i<(f-u)*(a-d)/(p-d)+u&&(o=!o)}return o}})),Bt=s(((e,t)=>{var n=Rt(),r=zt();t.exports=function(e,t,i,a){return t.length>0&&Array.isArray(t[0])?r(e,t,i,a):n(e,t,i,a)},t.exports.nested=r,t.exports.flat=n})),Vt=s(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):r((n||=self).predicates={})})(e,function(e){"use strict";let t=134217729;function n(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(s=a-((o=l+a)-l),l=t[++d]):(s=a-((o=u+a)-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(s=a-((o=a+l)-(c=o-a))+(l-c),l=t[++d]):(s=a-((o=a+u)-(c=o-a))+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)s=a-((o=a+l)-(c=o-a))+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)s=a-((o=a+u)-(c=o-a))+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return a===0&&p!==0||(i[p++]=a),p}function r(e){return new Float64Array(e)}let i=r(4),a=r(8),o=r(12),s=r(16),c=r(4);e.orient2d=function(e,r,l,u,d,f){let p=(r-f)*(l-d),m=(e-d)*(u-f),h=p-m;if(p===0||m===0||p>0!=m>0)return h;let g=Math.abs(p+m);return Math.abs(h)>=33306690738754716e-32*g?h:-function(e,r,l,u,d,f,p){let m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=e-d,N=l-d,P=r-f,F=u-f;v=(O=(x=M-(b=(y=t*M)-(y-M)))*(C=F-(S=(y=t*F)-(y-F)))-((D=M*F)-b*S-x*S-b*C))-(w=O-(A=(x=P-(b=(y=t*P)-(y-P)))*(C=N-(S=(y=t*N)-(y-N)))-((k=P*N)-b*S-x*S-b*C))),i[0]=O-(w+v)+(v-A),v=(E=D-((T=D+w)-(v=T-D))+(w-v))-(w=E-k),i[1]=E-(w+v)+(v-k),v=(j=T+w)-T,i[2]=T-(j-v)+(w-v),i[3]=j;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,i),L=22204460492503146e-32*p;if(I>=L||-I>=L||(m=e-(M+(v=e-M))+(v-d),g=l-(N+(v=l-N))+(v-d),h=r-(P+(v=r-P))+(v-f),_=u-(F+(v=u-F))+(v-f),m===0&&h===0&&g===0&&_===0)||(L=11093356479670487e-47*p+33306690738754706e-32*Math.abs(I),(I+=M*_+F*m-(P*g+N*h))>=L||-I>=L))return I;v=(O=(x=m-(b=(y=t*m)-(y-m)))*(C=F-(S=(y=t*F)-(y-F)))-((D=m*F)-b*S-x*S-b*C))-(w=O-(A=(x=h-(b=(y=t*h)-(y-h)))*(C=N-(S=(y=t*N)-(y-N)))-((k=h*N)-b*S-x*S-b*C))),c[0]=O-(w+v)+(v-A),v=(E=D-((T=D+w)-(v=T-D))+(w-v))-(w=E-k),c[1]=E-(w+v)+(v-k),v=(j=T+w)-T,c[2]=T-(j-v)+(w-v),c[3]=j;let ee=n(4,i,4,c,a);v=(O=(x=M-(b=(y=t*M)-(y-M)))*(C=_-(S=(y=t*_)-(y-_)))-((D=M*_)-b*S-x*S-b*C))-(w=O-(A=(x=P-(b=(y=t*P)-(y-P)))*(C=g-(S=(y=t*g)-(y-g)))-((k=P*g)-b*S-x*S-b*C))),c[0]=O-(w+v)+(v-A),v=(E=D-((T=D+w)-(v=T-D))+(w-v))-(w=E-k),c[1]=E-(w+v)+(v-k),v=(j=T+w)-T,c[2]=T-(j-v)+(w-v),c[3]=j;let R=n(ee,a,4,c,o);return v=(O=(x=m-(b=(y=t*m)-(y-m)))*(C=_-(S=(y=t*_)-(y-_)))-((D=m*_)-b*S-x*S-b*C))-(w=O-(A=(x=h-(b=(y=t*h)-(y-h)))*(C=g-(S=(y=t*g)-(y-g)))-((k=h*g)-b*S-x*S-b*C))),c[0]=O-(w+v)+(v-A),v=(E=D-((T=D+w)-(v=T-D))+(w-v))-(w=E-k),c[1]=E-(w+v)+(v-k),v=(j=T+w)-T,c[2]=T-(j-v)+(w-v),c[3]=j,s[n(R,o,4,c,s)-1]}(e,r,l,u,d,f,g)},e.orient2dfast=function(e,t,n,r,i,a){return(t-a)*(n-i)-(e-i)*(r-a)},Object.defineProperty(e,`__esModule`,{value:!0})})})),Ht=u(s(((e,t)=>{var n=Nt(),r=(Lt(),d(Pt)),i=Bt(),a=Vt().orient2d;r.default&&(r=r.default),t.exports=o,t.exports.default=o;function o(e,t,r){t=Math.max(0,t===void 0?2:t),r||=0;var i=g(e),a=new n(16);a.toBBox=function(e){return{minX:e[0],minY:e[1],maxX:e[0],maxY:e[1]}},a.compareMinX=function(e,t){return e[0]-t[0]},a.compareMinY=function(e,t){return e[1]-t[1]},a.load(e);for(var o=[],c=0,l;c<i.length;c++){var u=i[c];a.remove(u),l=_(u,l),o.push(l)}var d=new n(16);for(c=0;c<o.length;c++)d.insert(h(o[c]));for(var f=t*t,p=r*r;o.length;){var m=o.shift(),y=m.p,b=m.next.p,x=v(y,b);if(!(x<p)){var S=x/f;u=s(a,m.prev.p,y,b,m.next.next.p,S,d),u&&Math.min(v(u,y),v(u,b))<=S&&(o.push(m),o.push(_(u,m)),a.remove(u),d.remove(m),d.insert(h(m)),d.insert(h(m.next)))}}m=l;var C=[];do C.push(m.p),m=m.next;while(m!==l);return C.push(m.p),C}function s(e,t,n,i,a,o,s){for(var u=new r([],c),d=e.data;d;){for(var p=0;p<d.children.length;p++){var m=d.children[p],h=d.leaf?y(m,n,i):l(n,i,m);h>o||u.push({node:m,dist:h})}for(;u.length&&!u.peek().node.children;){var g=u.pop(),_=g.node,v=y(_,t,n),b=y(_,i,a);if(g.dist<v&&g.dist<b&&f(n,_,s)&&f(i,_,s))return _}d=u.pop(),d&&=d.node}return null}function c(e,t){return e.dist-t.dist}function l(e,t,n){if(u(e,n)||u(t,n))return 0;var r=b(e[0],e[1],t[0],t[1],n.minX,n.minY,n.maxX,n.minY);if(r===0)return 0;var i=b(e[0],e[1],t[0],t[1],n.minX,n.minY,n.minX,n.maxY);if(i===0)return 0;var a=b(e[0],e[1],t[0],t[1],n.maxX,n.minY,n.maxX,n.maxY);if(a===0)return 0;var o=b(e[0],e[1],t[0],t[1],n.minX,n.maxY,n.maxX,n.maxY);return o===0?0:Math.min(r,i,a,o)}function u(e,t){return e[0]>=t.minX&&e[0]<=t.maxX&&e[1]>=t.minY&&e[1]<=t.maxY}function f(e,t,n){for(var r=Math.min(e[0],t[0]),i=Math.min(e[1],t[1]),a=Math.max(e[0],t[0]),o=Math.max(e[1],t[1]),s=n.search({minX:r,minY:i,maxX:a,maxY:o}),c=0;c<s.length;c++)if(m(s[c].p,s[c].next.p,e,t))return!1;return!0}function p(e,t,n){return a(e[0],e[1],t[0],t[1],n[0],n[1])}function m(e,t,n,r){return e!==r&&t!==n&&p(e,t,n)>0!=p(e,t,r)>0&&p(n,r,e)>0!=p(n,r,t)>0}function h(e){var t=e.p,n=e.next.p;return e.minX=Math.min(t[0],n[0]),e.minY=Math.min(t[1],n[1]),e.maxX=Math.max(t[0],n[0]),e.maxY=Math.max(t[1],n[1]),e}function g(e){for(var t=e[0],n=e[0],r=e[0],a=e[0],o=0;o<e.length;o++){var s=e[o];s[0]<t[0]&&(t=s),s[0]>r[0]&&(r=s),s[1]<n[1]&&(n=s),s[1]>a[1]&&(a=s)}var c=[t,n,r,a],l=c.slice();for(o=0;o<e.length;o++)i(e[o],c)||l.push(e[o]);return S(l)}function _(e,t){var n={p:e,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(n.next=t.next,n.prev=t,t.next.prev=n,t.next=n):(n.prev=n,n.next=n),n}function v(e,t){var n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function y(e,t,n){var r=t[0],i=t[1],a=n[0]-r,o=n[1]-i;if(a!==0||o!==0){var s=((e[0]-r)*a+(e[1]-i)*o)/(a*a+o*o);s>1?(r=n[0],i=n[1]):s>0&&(r+=a*s,i+=o*s)}return a=e[0]-r,o=e[1]-i,a*a+o*o}function b(e,t,n,r,i,a,o,s){var c=n-e,l=r-t,u=o-i,d=s-a,f=e-i,p=t-a,m=c*c+l*l,h=c*u+l*d,g=u*u+d*d,_=c*f+l*p,v=u*f+d*p,y=m*g-h*h,b,x,S,C,w=y,T=y;y===0?(x=0,w=1,C=v,T=g):(x=h*v-g*_,C=m*v-h*_,x<0?(x=0,C=v,T=g):x>w&&(x=w,C=v+h,T=g)),C<0?(C=0,-_<0?x=0:-_>m?x=w:(x=-_,w=m)):C>T&&(C=T,-_+h<0?x=0:-_+h>m?x=w:(x=-_+h,w=m)),b=x===0?0:x/w,S=C===0?0:C/T;var E=(1-b)*e+b*n,D=(1-b)*t+b*r,O=(1-S)*i+S*o,k=(1-S)*a+S*s,A=O-E,j=k-D;return A*A+j*j}function x(e,t){return e[0]===t[0]?e[1]-t[1]:e[0]-t[0]}function S(e){e.sort(x);for(var t=[],n=0;n<e.length;n++){for(;t.length>=2&&p(t[t.length-2],t[t.length-1],e[n])<=0;)t.pop();t.push(e[n])}for(var r=[],i=e.length-1;i>=0;i--){for(;r.length>=2&&p(r[r.length-2],r[r.length-1],e[i])<=0;)r.pop();r.push(e[i])}return r.pop(),t.pop(),t.concat(r)}}))(),1);function Ut(e,t={}){t.concavity=t.concavity||1/0;let n=[];if(kt(e,e=>{n.push([e[0],e[1]])}),!n.length)return null;let r=(0,Ht.default)(n,t.concavity);return r.length>3?xt([r]):null}function Wt(e,t={}){let n=0,r=0,i=0;return kt(e,function(e){n+=e[0],r+=e[1],i++},!0),bt([n/i,r/i],t.properties)}function Gt(e){if(!e)throw Error(`coord is required`);if(!Array.isArray(e)){if(e.type===`Feature`&&e.geometry!==null&&e.geometry.type===`Point`)return[...e.geometry.coordinates];if(e.type===`Point`)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw Error(`coord must be GeoJSON Point or an Array of numbers`)}function Kt(e){if(Array.isArray(e))return e;if(e.type===`Feature`){if(e.geometry!==null)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw Error(`coords must be GeoJSON Feature, Geometry Object or an Array`)}function qt(e,t,n={}){let r;return r=n.final?Jt(Gt(t),Gt(e)):Jt(Gt(e),Gt(t)),r>180?-(360-r):r}function Jt(e,t){let n=Tt(e[1]),r=Tt(t[1]),i=Tt(t[0]-e[0]);i>Math.PI&&(i-=2*Math.PI),i<-Math.PI&&(i+=2*Math.PI);let a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4));return(wt(Math.atan2(i,a))+360)%360}function Yt(e,t,n={}){let r=Gt(e),i=Gt(t);return i[0]+=i[0]-r[0]>180?-360:r[0]-i[0]>180?360:0,Et(Xt(r,i),`meters`,n.units)}function Xt(e,t,n){n=n===void 0?$:Number(n);let r=n,i=e[1]*Math.PI/180,a=t[1]*Math.PI/180,o=a-i,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);let c=Math.log(Math.tan(a/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),l=Math.abs(c)>1e-11?o/c:Math.cos(i);return Math.sqrt(o*o+l*l*s*s)*r}function Zt(e,t,n,r={}){let i=t<0,a=Et(Math.abs(t),r.units,`meters`);i&&(a=-Math.abs(a));let o=Gt(e),s=Qt(o,a,n);return s[0]+=s[0]-o[0]>180?-360:o[0]-s[0]>180?360:0,bt(s,r.properties)}function Qt(e,t,n,r){r=r===void 0?$:Number(r);let i=t/r,a=e[0]*Math.PI/180,o=Tt(e[1]),s=Tt(n),c=i*Math.cos(s),l=o+c;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);let u=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(u)>1e-11?c/u:Math.cos(o);return[((a+i*Math.sin(s)/d)*180/Math.PI+540)%360-180,l*180/Math.PI]}function $t(e){if(!e)throw Error(`geojson is required`);switch(e.type){case`Feature`:return en(e);case`FeatureCollection`:return nn(e);case`Point`:case`LineString`:case`Polygon`:case`MultiPoint`:case`MultiLineString`:case`MultiPolygon`:case`GeometryCollection`:return rn(e);default:throw Error(`unknown GeoJSON type`)}}function en(e){let t={type:`Feature`};return Object.keys(e).forEach(n=>{switch(n){case`type`:case`properties`:case`geometry`:return;default:t[n]=e[n]}}),t.properties=tn(e.properties),e.geometry==null?t.geometry=null:t.geometry=rn(e.geometry),t}function tn(e){let t={};return e&&Object.keys(e).forEach(n=>{let r=e[n];typeof r==`object`?r===null?t[n]=null:Array.isArray(r)?t[n]=r.map(e=>e):t[n]=tn(r):t[n]=r}),t}function nn(e){let t={type:`FeatureCollection`};return Object.keys(e).forEach(n=>{switch(n){case`type`:case`features`:return;default:t[n]=e[n]}}),t.features=e.features.map(e=>en(e)),t}function rn(e){let t={type:e.type};return e.bbox&&(t.bbox=e.bbox),e.type===`GeometryCollection`?(t.geometries=e.geometries.map(e=>rn(e)),t):(t.coordinates=an(e.coordinates),t)}function an(e){let t=e;return typeof t[0]==`object`?t.map(e=>an(e)):t.slice()}function on(e,t,n){if(n||={},!Ot(n))throw Error(`options is invalid`);let r=n.pivot,i=n.mutate;if(!e)throw Error(`geojson is required`);if(t==null||isNaN(t))throw Error(`angle is required`);if(t===0)return e;let a=r??Wt(e);return(i===!1||i===void 0)&&(e=$t(e)),kt(e,function(e){let n=qt(a,e)+t,r=Kt(Zt(a,Yt(a,e),n));e[0]=r[0],e[1]=r[1]}),e}function sn(e,t,n={}){if(n.final===!0)return cn(e,t);let r=Gt(e),i=Gt(t),a=Tt(r[0]),o=Tt(i[0]),s=Tt(r[1]),c=Tt(i[1]),l=Math.sin(o-a)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(o-a);return wt(Math.atan2(l,u))}function cn(e,t){let n=sn(t,e);return n=(n+180)%360,n}function ln(e,t={}){if(e.bbox!=null&&!0!==t.recompute)return e.bbox;let n=[1/0,1/0,-1/0,-1/0];return kt(e,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}function un(e,t={}){let n=Number(e[0]),r=Number(e[1]),i=Number(e[2]),a=Number(e[3]);if(e.length===6)throw Error(`@turf/bbox-polygon does not support BBox with 6 positions`);let o=[n,r];return xt([[o,[i,r],[i,a],[n,a],o]],t.properties,{bbox:e,id:t.id})}function dn(e){return un(ln(e))}function fn(e){return Mt(e,(e,t)=>e+pn(t),0)}function pn(e){let t=0,n;switch(e.type){case`Polygon`:return mn(e.coordinates);case`MultiPolygon`:for(n=0;n<e.coordinates.length;n++)t+=mn(e.coordinates[n]);return t;case`Point`:case`MultiPoint`:case`LineString`:case`MultiLineString`:return 0}return 0}function mn(e){let t=0;if(e&&e.length>0){t+=Math.abs(_n(e[0]));for(let n=1;n<e.length;n++)t-=Math.abs(_n(e[n]))}return t}var hn=$*$/2,gn=Math.PI/180;function _n(e){let t=e.length-1;if(t<=2)return 0;let n=0,r=0;for(;r<t;){let i=e[r],a=e[r+1===t?0:r+1],o=e[r+2>=t?(r+2)%t:r+2],s=i[0]*gn,c=a[1]*gn,l=o[0]*gn;n+=(l-s)*Math.sin(c),r++}return n*hn}function vn(e){let t=Ut(e);if(!t)throw Error(`Can't calculate smallestSurroundingRectangleByArea for given geometry`);let n=Wt(t),r=At(t),i=2**53-1,a=null;for(let e=0;e<r.length-1;e++){let o=sn(r[e],r[e+1]),s=dn(on(t,-1*o,{pivot:n})),c=fn(s);c<i&&(i=c,a=on(s,o,{pivot:n}))}return a}function yn(e,t){let n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)}function bn(e){let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let[a,o]of e)a<t&&(t=a),a>n&&(n=a),o<r&&(r=o),o>i&&(i=o);return[(n+t)*.5,(i+r)*.5]}var xn=class e extends gt{getBoxMesh(){Sn.identity(),Sn.setFromMatrix3(this.rotation),Sn.decompose(En,Cn,new f.Vector3);let e=this.halfSize.clone().multiplyScalar(2),t=new f.Mesh(new f.BoxGeometry(e.x,e.y,e.z));return t.position.copy(this.center),t.rotation.setFromQuaternion(Cn),t}getBoxEdge(e=16776960){let t=this.getBoxMesh();Dn.setFromObject(t);let n=new f.EdgesGeometry(t.geometry.clone().applyMatrix4(t.matrixWorld));return new f.LineSegments(n,new f.LineBasicMaterial({color:e,toneMapped:!1}))}toJson(){return Sn.identity(),Sn.setFromMatrix3(this.rotation),Sn.decompose(En,Cn,new f.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:Cn.toArray()}}static from(t,n,r,i=new e){if(r instanceof f.Euler)Cn.setFromEuler(r);else if(r instanceof f.Quaternion)Cn.copy(r);else throw Error(`传入的旋转不是欧拉角或者四元数`);return Sn.compose(n,Cn,Tn),i.center.copy(n),i.halfSize.copy(t.multiplyScalar(.5)),i.rotation.setFromMatrix4(Sn),i}static fromByPath2D(t,n,r,i=new e){let a=vn({type:`Polygon`,coordinates:[t.map(e=>[e.x,e.y])]});if(!a)throw Error(`2d obb 获取失败`);let o=a.geometry.coordinates[0],s=yn(o[0],o[1]),c=yn(o[1],o[2]),l=Math.atan2(o[1][1]-o[0][1],o[1][0]-o[0][0]);En.set(s,c,r),wn.set(0,0,l);let[u,d]=bn(o);return n.x=u,n.y=d,this.from(En,n,wn,i)}},Sn=new f.Matrix4,Cn=new f.Quaternion,wn=new f.Euler,Tn=new f.Vector3(1,1,1),En=new f.Vector3,Dn=new f.Box3;function On(e,t,n=.005,r=.2){if(!e.length||!t.length)return 0;let i=Math.max(n,.03),a=n*n,o=new Map,s=(e,t,n)=>`${Math.floor(e/i)},${Math.floor(t/i)},${Math.floor(n/i)}`;for(let e of t){let t=s(e.x,e.y,e.z);o.has(t)||o.set(t,[]),o.get(t).push(e)}let c=0,l=Math.ceil(n/i)+1,u=[];for(let e=-l;e<=l;e++)for(let t=-l;t<=l;t++)for(let n=-l;n<=l;n++)e*e+t*t+n*n<=l*l&&u.push([e,t,n]);for(let t of e){let n=Math.floor(t.x/i),s=Math.floor(t.y/i),l=Math.floor(t.z/i),d=!1;for(let[e,r,i]of u){let c=`${n+e},${s+r},${l+i}`;if(o.has(c)){for(let e of o.get(c))if(t.distanceToSquared(e)<a){d=!0;break}if(d)break}}if(d&&(c++,c/e.length>r))return c/e.length}return c/e.length}function kn(e,t,n=.5){let r=0,i=0;for(let a of e)if(t.containsPoint(a)&&(r++,i=r/e.length,i>n))break;return i}function An(e,t,n,r){if(e.intersectsOBB(t))return!0;{let i=Mn(e,r),a=Mn(t,n);if(i||a)return!0}return!1}function jn(e,t){let n=new f.Vector3,r=new f.Vector3;e.getSize(n),t.getSize(r);let i=n.x*n.y*n.z,a=r.x*r.y*r.z;return i>a?1:i<a?-1:0}function Mn(e,t){let n=!0;for(let r=0;r<t.length;r++)if(!e.containsPoint(t[r])){n=!1;break}return n}function Nn(e){if(e.length===0)return{x:0,y:0,z:0,h:0};let t=0,n=0,r=-1/0,i=1/0;for(let a of e)t+=a.x,n+=a.y,r=Math.max(r,a.z),i=Math.min(i,a.z);return{x:t/e.length,y:n/e.length,z:0,maxz:r,minz:i,h:r-i}}function Pn(e,t,n,r){let i=[];for(let t=0;t<e.length;t++)i.push(new f.Vector3(e[t][0],e[t][1],0));if(i.length==0)return null;let a=xn.fromByPath2D(i,t,n);return a.center.z=r,a}var Fn=e=>{if(e.length==0)return[];let t=[],n=new Map;for(let r=0;r<e.length;r++){let i=e[r].points.map(e=>[e.x,e.y]),a=e[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];let o=a.indexOf(`_`)+1,s=a.lastIndexOf(`_`),c=a.substring(o,s);if(c===`wall`)continue;let l=[];for(let t=0;t<e[r].points.length;t++)l.push(new f.Vector3(e[r].points[t].x,e[r].points[t].y,e[r].points[t].z));let u=-99999;if(c===`floor`){let t=new Map;for(let n=0;n<e[r].points.length;n++){let i=e[r].points[n].z;if(i=Math.floor(i*10)/10,t.has(i)){let a=t.get(i);a.num+=1,a.points.push(e[r].points[n]),t.set(i,a)}else t.set(i,{num:1,points:[e[r].points[n]]})}let n=[...t.entries()].reduce((e,t)=>t[1].num>e[1].num?t:e);i=[],i=n[1].points.map(e=>[e.x,e.y]),l=[],l=n[1].points.map(e=>new f.Vector3(e.x,e.y,e.z)),u=n[0]}let d=Nn(l),p={points:l,path:ot(i),h:d.h,minz:d.minz,maxz:d.maxz,center:{x:d.x,y:d.y,z:d.z},obj_id:e[r].obj_id,type:c,averagePz:e[r].averagePz,obb:null,isDel:!1,obj_id:a,positionArr:[e[r].position]};if(p.obb=Pn(p.path,p.center,p.h,(p.maxz+p.minz)/2),p.obb==null)continue;let m=-1;for(let e=0;e<t.length;e++)if(t[e].type==c){m=e;break}if(m==-1?t.push({type:c,array:[p]}):t[m].array.push(p),c==`floor`&&u!=-99999)if(n.has(u)){let e=n.get(u);e.num+=p.points.length,e.datas.push(p),n.set(u,e)}else n.set(u,{num:p.points.length,datas:[p]})}let r=-1/0;if(n.size>0){let e=[];for(let[t,i]of n.entries()){let{num:n,datas:a}=i;n>3e3&&(t>r&&(r=t),e.push(...a))}for(let n=0;n<t.length;n++)if(t[n].type==`floor`){t[n].array=e;break}}for(let e=0;e<t.length;e++){let n=t[e].array,i=[],a=[];for(let e=0;e<n.length;e++){if(n[e].obb==null||i.includes(e))continue;let t={...n[e],obb:n[e].obb.clone()};for(let a=e+1;a<n.length;a++)if(!(n[a].obb==null||i.includes(a))&&t.obb.intersectsOBB(n[a].obb)){i.push(a);for(let e=0;e<n[a].points.length;e++)(n[a].points[e].z>r&&n[a].points[e].z-r>.1||t.type==`floor`)&&t.points.push(n[a].points[e]);t.path=ot(t.points.map(e=>[e.x,e.y]));let o=Nn(t.points);t.h=o.h,t.minz=o.minz,t.maxz=o.maxz,t.center={x:o.x,y:o.y,z:o.z},t.obb=Pn(t.path,t.center,t.h,(t.maxz+t.minz)/2),t.positionArr.push(...n[a].positionArr),a=e}t.path.length>n[e].path.length&&(i.push(e),a.push(t))}let o=[];for(let e=0;e<n.length;e++)i.includes(e)||o.push(n[e]);o.push(...a),t[e].array=o}for(let e=0;e<t.length;e++){let n=t[e].type;if(n===`people`||n===`floor`)continue;let r=t[e].array;for(let i=0;i<r.length;i++){let a=r[i].obb,o=r[i].minz;r[i].maxz;let s=r[i].averagePz;if(n===`window`||n===`door`||n===`tv`||n===`chair`||n===`cabinet`||n===`table`){let e=new f.Vector3;a.getSize(e);let t=[e.x,e.y,e.z],n=0;for(let e of t)if(e<.2&&(n++,n===2)){r[i].isDel=!0;break}}if(!r[i].isDel)for(let c=e+1;c<t.length;c++){let e=t[c].type;if(e===`people`||e===`floor`)continue;let l=t[c].array;for(let t=0;t<l.length;t++){if(l[t].isDel)continue;let c=l[t].obb,u=l[t].minz;if(l[t].maxz,a.intersectsOBB(c)){kn(l[t].points,a);let d=kn(r[i].points,c),f=jn(a,c);if(d>=.3&&f==-1){r[i].isDel=!0;break}if(n!==`wall`&&n!==`floor`&&n!==`roof`){if(n===`window`){if(e===`balcony railing`&&Mn(a,l[t].points)){l[t].isDel=!0;continue}if(e===`balcony railing`&&Mn(c,r[i].points)){r[i].isDel=!0;break}if(e===`balcony railing`&&An(a,c,r[i].points,l[t].points)&&(Math.abs(o-u)<.1||Math.abs(u-s)>.3)){l[t].isDel=!0;continue}}else if(n===`balcony railing`){if(e===`window`&&Mn(a,l[t].points)){l[t].isDel=!0;continue}if(e===`window`&&Mn(c,r[i].points)){r[i].isDel=!0;break}if(e===`window`&&An(a,c,r[i].points,l[t].points)&&(Math.abs(o-u)<.1||Math.abs(o-s)>.3)){r[i].isDel=!0;break}}let d=!1,f=[],p=[],m=r[i].points,h=l[t].points;if(m.length>h.length?(d=!0,f=m,p=h):(f=h,p=m),On(p,f,.03,.5)>.5)if(d)l[t].isDel=!0;else{r[i].isDel=!0;break}else if(An(a,c)){let o=jn(a,c);if(o===1||o===0){if(e===`switch`)continue;m.length>h.length?kn(p,a)>=.5&&(l[t].isDel=!0):kn(f,a)>=.5&&(l[t].isDel=!0)}else{if(n===`switch`)continue;if(m.length>h.length){if(kn(f,c)>=.5){r[i].isDel=!0;break}}else if(kn(p,c)>=.5){r[i].isDel=!0;break}}}}}}if(r[i].isDel)break}}}for(let e=0;e<t.length;e++){let n=t[e].type,r=t[e].array;for(let e=0;e<r.length;e++){let t=r[e].maxz,i=r[e].minz,a=n===`switch`?.1:.3,o=r[e].averagePz;if(Math.abs(t-o)<a){r[e].isDel=!0;continue}if(n===`window`||n===`door`||n===`tv`){let a=Math.abs(t-o),s=Math.abs(i-o);(n===`tv`&&s<1.6||n!==`window`&&a<1.6)&&(r[e].isDel=!0),n===`window`&&a<1&&(r[e].isDel=!0)}if(n===`chair`){let t=new f.Vector3;r[e].obb.getSize(t),(t.x<.1||t.y<.1||t.z<.2)&&(r[e].isDel=!0)}n===`balcony railing`&&(Math.abs(t-i)<.4&&(r[e].isDel=!0),(i<o&&Math.abs(i-o)>1||i>o&&Math.abs(i-o)>1)&&(r[e].isDel=!0),t<o&&(r[e].isDel=!0)),n===`people`&&(Math.abs(t-i)<1&&(r[e].isDel=!0),i>o&&i-o>.3&&(r[e].isDel=!0),t<o&&(r[e].isDel=!0)),n===`floor`&&r[e].points.length<500&&(r[e].isDel=!0)}}for(let e=0;e<t.length;e++)t[e].array=t[e].array.filter(e=>!e.isDel);let i=[];for(let e=0;e<t.length;e++){let n=t[e].array;for(let e=0;e<n.length;e++)i.push({obbBox:n[e].obb,box:new f.Box3().setFromPoints(n[e].points),category:n[e].type,center:{x:n[e].center.x,y:n[e].center.y,z:(n[e].minz+n[e].maxz)/2},name:n[e].obj_id,obj_id:n[e].obj_id,pcdPoints:n[e].points,positionArr:n[e].positionArr})}return i};function In(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Ln(e){let t=0,n=0,r=0;for(let i=0;i<4;i++){let a=e[i],o=e[(i+1)%4],s=o.x-a.x,c=o.y-a.y,l=Math.sqrt(s*s+c*c);l>t&&(t=l,n=s/l,r=c/l)}return{longSide:t,dirX:n,dirY:r}}function Rn(e,t,n){let r=[];for(let i of e){let e=(i.start.x+i.end.x)/2,a=(i.start.y+i.end.y)/2,o=e-t,s=a-n;o*o+s*s<=9&&r.push(i.start.z,i.end.z)}if(r.length===0){let t=[];for(let n of e)t.push(n.start.z,n.end.z);return t.length?(t.sort((e,t)=>e-t),t[Math.floor(t.length/2)]):-1/0}return r.sort((e,t)=>e-t),r[Math.floor(r.length/2)]}function zn(e,t,n,r,i,a){let o=i-n,s=a-r,c=o*o+s*s;if(c<1e-12)return{dist:Math.sqrt((e-n)**2+(t-r)**2),t:0};let l=e-n,u=t-r,d=(l*o+u*s)/c,f=n+d*o,p=r+d*s;return{dist:Math.sqrt((e-f)**2+(t-p)**2),t:d}}function Bn(e,t,n=.15){let r=0,i=0;for(let a of t)a!==e&&((In(e.start,a.start)<=n||In(e.start,a.end)<=n)&&r++,(In(e.end,a.start)<=n||In(e.end,a.end)<=n)&&i++);let a=0;return r>=1&&i>=1?a=5:(r>=1||i>=1)&&(a=2),{left:r,right:i,score:a}}function Vn(e,t){let n=[],{start:r,end:i}=e;for(let e of t){let{dist:t}=zn(e.x,e.y,r.x,r.y,i.x,i.y);n.push(t)}let a=n.reduce((e,t)=>e+t,0)/n.length,o=n.reduce((e,t)=>e+(t-a)**2,0)/n.length;return o<.01?3:o<.05?2:o<.1?1:0}function Hn(e,t,n=.15){let r=e.end.x-e.start.x,i=e.end.y-e.start.y,a=Math.sqrt(r*r+i*i);if(a<1e-12)return 0;let o=-i/a,s=r/a,c=[[],[]];for(let l=0;l<2;l++){let u=l===0?e.start:e.end;for(let d of t){if(d===e)continue;let t=In(u,d.start),f=In(u,d.end),p=null;if(t<=n?p=d.end:f<=n&&(p=d.start),!p)continue;let m=d.end.x-d.start.x,h=d.end.y-d.start.y,g=Math.sqrt(m*m+h*h);if(g<1e-12||Math.abs(r*m+i*h)/(a*g)>=.342)continue;let _=(p.x-u.x)*o+(p.y-u.y)*s;c[l].push(_>0?1:-1)}}if(c[0].length===0||c[1].length===0)return 0;let l=[...c[0],...c[1]];return l.every(e=>e===l[0])?2:1}function Un(e,t,n){let r=Bn(e,n),i=Vn(e,t),a=Hn(e,n);return{score:r.score*3+i*2+a*2,details:{conn:r.score,variance:i,sameSide:a}}}function Wn(e){let t=e.end.x-e.start.x,n=e.end.y-e.start.y,r=180/Math.PI*Math.atan2(n,t);return r<0&&(r+=180),r}function Gn(e,t){let n=[];for(let r of e){let e=!1;for(let i of n){let n=Math.abs(r.angle-i[0].angle);if(Math.min(n,180-n)<=t){i.push(r),e=!0;break}}e||n.push([r])}return n}function Kn(e,t=.05){let n=[];for(let r of e){let e=!1;for(let i of n)if(Math.abs(r.offset-i[0].offset)<=t){i.push(r),e=!0;break}e||n.push([r])}return n}function qn(e,t,n,r,i){let a=[];for(let i of e){let e=i.seg,o=(e.start.x-t.start.x)*n+(e.start.y-t.start.y)*r,s=(e.end.x-t.start.x)*n+(e.end.y-t.start.y)*r;a.push({l:Math.min(o,s),r:Math.max(o,s),idx:i.idx})}a.sort((e,t)=>e.l-t.l);let o=[];for(let{l:e,r:t,idx:n}of a){if(o.length===0){o.push({l:e,r:t,srcIdxs:[n]});continue}let r=o[o.length-1];e<=r.r+i?(r.r=Math.max(r.r,t),r.srcIdxs.includes(n)||r.srcIdxs.push(n)):o.push({l:e,r:t,srcIdxs:[n]})}return o}function Jn(e,t,n,r,i,a,o){let s=n-t,c={...e};return c.start={x:e.start.x+t*r,y:e.start.y+t*i,z:e.start.z},c.end={x:e.start.x+n*r,y:e.start.y+n*i,z:e.start.z},c.length=s,c.direction={x:r,y:i,z:0},c.rooftopPz=a,c.buildRosource=o,c.isRebuild=!1,c.doorAndBeamData||=[],c.insetionArr||=[],c}function Yn(e,t){let n=!0;for(;n;){n=!1;for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++){let a=e[r],o=e[i];if(a.rooftopPz!==void 0&&o.rooftopPz!==void 0&&Math.abs(a.rooftopPz-o.rooftopPz)>.05)continue;let s=Math.abs(a.end.x-o.start.x)<.001&&Math.abs(a.end.y-o.start.y)<.001,c=Math.abs(a.start.x-o.end.x)<.001&&Math.abs(a.start.y-o.end.y)<.001,l=Math.abs(a.end.x-o.end.x)<.001&&Math.abs(a.end.y-o.end.y)<.001,u=Math.abs(a.start.x-o.start.x)<.001&&Math.abs(a.start.y-o.start.y)<.001;if(!(s||c||l||u)||a.direction.x*o.direction.x+a.direction.y*o.direction.y<.98)continue;let d=a.start,f=a.end;s?f=o.end:c?d=o.start:l?f=o.start:u&&(d=o.end);let p=Math.hypot(f.x-d.x,f.y-d.y),m={...a};m.start=d,m.end=f,m.length=p,m.direction={x:(f.x-d.x)/p,y:(f.y-d.y)/p,z:0},m.rooftopPz=a.rooftopPz===void 0?o.rooftopPz:a.rooftopPz,m.buildRosource=a.buildRosource||o.buildRosource,m.isRebuild=!1,m.doorAndBeamData||=[],m.insetionArr||=[],e[r]=m,t[r]=[...new Set([...t[r],...t[i]])],e.splice(i,1),t.splice(i,1),i--,n=!0}}return{segments:e,sourceMap:t}}function Xn(e,t=5,n=.05){if(e.length<=1)return{segments:e,sourceMap:e.map((e,t)=>[t])};let r=e.map((e,t)=>({seg:e,angle:Wn(e),idx:t}));r.sort((e,t)=>e.angle-t.angle);let i=Gn(r,t),a=[],o=[],s=[];for(let e of i){let t=e[0].seg;for(let n of e)n.seg.length>t.length&&(t=n.seg);let r=t.end.x-t.start.x,i=t.end.y-t.start.y,c=Math.sqrt(r*r+i*i);if(c<1e-12)continue;let l=-i/c,u=r/c,d=e.map(e=>{let n=e.seg.start.x-t.start.x,r=e.seg.start.y-t.start.y;return{seg:e.seg,offset:Math.abs(n*l+r*u),idx:e.idx}});d.sort((e,t)=>e.offset-t.offset);let f=Kn(d);for(let e of f){let t=e[0].seg;for(let n of e)n.seg.length>t.length&&(t=n.seg);let r=t.end.x-t.start.x,i=t.end.y-t.start.y,c=Math.sqrt(r*r+i*i);if(c<1e-12)continue;let l=r/c,u=i/c,d=e.map(e=>e.seg.rooftopPz??0),f=Math.max(...d),p=[...new Set(d.map(e=>e.toFixed(3)))];if(p.length>1){let t=e.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}));s.push({values:[...p],segments:t})}[...new Set(e.map(e=>String(e.seg.buildRosource)))];let m=qn(e,t,l,u,n);for(let{l:e,r:n,srcIdxs:r}of m){if(n-e<.01)continue;let i=Jn(t,e,n,l,u,f,t.buildRosource);a.push(i),o.push(r)}}}return{...Yn(a,o),debugRPZGroups:s}}function Zn(e){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,...e}}function Qn(e,t,n){return[{x:t,y:n,z:0},{x:e[0].x,y:e[0].y,z:0},{x:e[1].x,y:e[1].y,z:0},{x:e[2].x,y:e[2].y,z:0},{x:e[3].x,y:e[3].y,z:0}]}function $n(e,t,n,r,i,a,o,s,c){[`_008`,`_002`,`_014`,`_015`,`_020`].some(t=>e.includes(t))&&t.map(e=>{let{start:t,end:a}=e,c=zn(n,r,t.x,t.y,a.x,a.y),l=i.map(e=>{let n=zn(e.x,e.y,t.x,t.y,a.x,a.y);return`t=${n.t.toFixed(3)},d=${n.dist.toFixed(3)}`}),u=a.x-t.x,d=a.y-t.y,f=Math.sqrt(u*u+d*d)||1,p=Math.abs(u/f*o+d/f*s),m=180/Math.PI*Math.acos(Math.min(p,1));return{seg:e,lineDist:c.dist,t:c.t,pts:l,angle:m,length:e.length}}).sort((e,t)=>e.lineDist-t.lineDist)}function er(e,t,n,r,i,a){let o=[{margin:a.projectionMargin,maxDist:a.maxDistance,label:`严格`},{margin:.4,maxDist:.65,label:`宽松`}],s=[];for(let c of o){if(s.length>0)break;for(let o of e){if(o.length<t*a.minLengthRatio)continue;let{start:e,end:l}=o,u=!1,d=1/0;for(let t of i){let{dist:n,t:r}=zn(t.x,t.y,e.x,e.y,l.x,l.y);r>=-c.margin&&r<=1+c.margin&&n<=c.maxDist&&(u=!0,d=Math.min(d,n))}if(!u)continue;let f=Math.sqrt((l.x-e.x)**2+(l.y-e.y)**2);if(f<1e-12)continue;let p=(l.x-e.x)/f,m=(l.y-e.y)/f,h=Math.abs(n*p+r*m);180/Math.PI*Math.acos(Math.min(h,1))>a.angleThreshold||s.push({seg:o,minDist:d,ratio:o.length/t,score:0,details:{conn:0,variance:0,sameSide:0}})}}return s}function tr(e,t,n,r){if(e.length<=1)return e.length===1&&(e[0].score=-1),e;for(let r of e){let{score:e,details:i}=Un(r.seg,t,n);r.score=e,r.details=i}return e.sort((e,t)=>t.score-e.score||e.minDist-t.minDist),e}function nr(e,t,n,r){let i=e.end.x-e.start.x,a=e.end.y-e.start.y,o=Math.sqrt(i*i+a*a),s=i/o,c=a/o,l=t.map(t=>{let n=t.x-e.start.x,r=t.y-e.start.y;return(n*s+r*c)/o}),u=Math.min(...l),d=Math.max(...l),f=(d-u)*o,p=(u+d)/2,m=e.start.x+p*i,h=e.start.y+p*a,g=n.box.min.z,_=n.box.max.z,v=Math.abs(_-g),y=Rn(r,e.start.x,e.start.y),b=Math.max(0,g-y),x=u<=0&&d>=1;return{p:{x:m,y:h,z:g+v/2},width:f,full:x,height:v,groundClearance:b}}function rr(e,t,n){let r=t.map(e=>n[e]),i=[],a=[],o=[],s=[],c=[],l;for(let e of r){if(e.points?.length)for(let t of e.points)i.push(t);if(e.originalPoints?.length)for(let t of e.originalPoints)a.push(t);if(e.doorAndBeamData?.length)for(let t of e.doorAndBeamData)o.push(t);if(e.insetionArr?.length)for(let t of e.insetionArr)s.push(t);if(e.drawWindow?.length)for(let t of e.drawWindow)c.push(t);e.boxData&&!l&&(l=e.boxData)}i.length&&(e.points=i),a.length&&(e.originalPoints=a),o.length&&(e.doorAndBeamData=o),s.length&&(e.insetionArr=s),c.length&&(e.drawWindow=c),l&&(e.boxData=l)}function ir(e,t,n){let r=Zn(n),i=[],{segments:a,sourceMap:o}=Xn(t),s=[...a,...t];for(let n of e){let e=n.coordinatesByArea?.coordinates;if(!e||e.length<4)continue;let o=e.slice(0,4),c=o.reduce((e,t)=>e+t.x,0)/4,l=o.reduce((e,t)=>e+t.y,0)/4,{longSide:u,dirX:d,dirY:f}=Ln(o);if(u<.01||o.reduce((e,t)=>e+t.z,0)/4<Rn(t,c,l)-.3)continue;let p=Qn(o,c,l);$n(n.name,s,c,l,p,u,d,f,r);let m=er(s,u,d,f,p,r);m=tr(m,p,t,n.name);let h=null,g=1/0,_=0;if(m.length>0){let e=m[0];h=e.seg,g=e.minDist,_=e.ratio}let v;if(h&&(v=nr(h,o,n,a),!r.printOnly)){let e=h;e.drawWindow||=[],e.drawWindow.push(v)}h&&i.push({windowName:n.name,windowCategory:n.category,windowCenter:n.center,wallSegment:h,distance:g,wallLengthRatio:_,drawWindow:v})}for(let e of i){let n=e.wallSegment,r=a.indexOf(n);if(r===-1)continue;let i=o[r];!i||i.length<=1||rr(n,i,t)}return i}function ar(e,t,n){let r={printOnly:!1,...n},i=ir(Array.isArray(t)?t.filter(e=>e&&e.category===`window`):[],e,r),{segments:a,sourceMap:o}=Xn(e);for(let e of i)if(e.drawWindow){let t=a.find(t=>Math.abs(t.start.x-e.wallSegment.start.x)<.01&&Math.abs(t.start.y-e.wallSegment.start.y)<.01&&Math.abs(t.end.x-e.wallSegment.end.x)<.01&&Math.abs(t.end.y-e.wallSegment.end.y)<.01);t&&(t.drawWindow||=[],t.drawWindow.push(e.drawWindow))}return{segments:a,matches:i,sourceMap:o}}exports.classifySegments=O,exports.computeLocalFloorZ=Rn,exports.findWindowWalls=ir,exports.getAllGeometry=oe,exports.getBeamLine=ve,exports.getColLine=be,exports.getMainBeamLine=ye,exports.getMergeMeaning=Fn,exports.getParallelism=T,exports.getPointCloudMinMax=N,exports.getPointCoverageOnQuad=j,exports.isParallel=b,exports.mergeCollinearSegments=Xn,exports.perpendicularInfo=E,exports.processData=ar,exports.removeNoisePoints=F,exports.segmentsIntersect2D=_,exports.updateStEdPoint=se,exports.usegetBeamLine=_e;
|
|
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&>>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&<!=-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;
|