rm-graphical-computing 1.0.57 → 1.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 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),ee=I<0?-I:0,te=I>0?I:0,L=F>0?te/F:0,R=A(e,t,n,r),z=h<=o&&x<s,B;return z?B=L>.5?`collinear_overlap`:`collinear_gap`:h<=a&&(B=`parallel_offset`),{type:B,angleDeg:g,avgPerpendicularDistance:x,maxPerpendicularDistance:S,gap:ee,overlap:te,closestDistance:R}};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)),ee=(e,t,n=1e-6)=>{let r=new f.Vector3;return e.closestPointToPoint(t,!0,r),r.distanceTo(t)<n},te=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},L=(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,R=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),B(t)})},z=()=>`#${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 B(e){for(;e.children&&e.children.length>0;){let t=e.children[0];e.remove(t),B(t)}e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>ne(e)):ne(e.material))}function ne(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 re=(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},ie=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}}},V=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 ie,{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=V(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(L(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:z(),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)=>{R(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:z(),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:ee,AiProjectionGroup2:te}=C(w);return l.add(ee),l.rotateX(-Math.PI/2),r.add(l),u.add(te),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=.2;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),L=[],R=new f.Vector3;a.points.forEach(e=>{F.closestPointToPoint(e,!0,R).distanceTo(e)<a.gridHeight+.01&&L.push(e)});let z=[],B=[];for(;;){let e=[];for(let t=0;t<L.length;t++)B.includes(t)||e.length==0&&(e.push(L[t]),B.push(t));for(let t=0;t<L.length;t++)if(!B.includes(t)){for(let n=0;n<e.length;n++)if(L[t].distanceTo(e[n])<a.gridWidth+.01){e.push(L[t]),B.push(t),t=-1;break}}if(e.length==0)break;z.push(e)}let ne=[];for(let e=0;e<z.length;e++){let t={lineSt:new f.Vector3,lineEd:new f.Vector3,facePoints:[]},n=te(z[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)),ne.push(t))}y+=a.area;let ie=0;if(C!=0&&(ie=a.gridHeight*a.gridWidth*C),(a.area-ie)/S*100>70&&ne.length==1||ne.length>1)for(let y=0;y<ne.length;y++){let x=ne[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=[],L=x.facePoints[2].clone(),R=x.facePoints[3].clone(),z=x.facePoints[0].clone(),B=x.facePoints[1].clone(),ie=!1,V=-1;if(Math.abs(x.facePoints[0].z-i.start.z)<.25){if(S>.17&&i.length>.5){let t=I(h,z),n=I(h,B),a=I(g,z),o=I(g,B),s=.1;if(t<s||n<s){let{newOriginalPoints:n}=P(z,B,i.originalPoints),a=[],o=[];if(n.forEach(e=>{e.z>=L.z?a.push(e):e.z<=z.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(z.x,z.y,0),t=new f.Vector3(B.x,B.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&&(ie=!0,t<s?(R=R.addScaledVector(o,l),z=z.addScaledVector(o,l)):(L=L.addScaledVector(o,l),B=B.addScaledVector(o,l)));else if(!d&&!p&&i.length-S>.1)continue}else continue}if(a<s||o<s){let{newOriginalPoints:t}=P(z,B,i.originalPoints),n=[],o=[];if(t.forEach(e=>{e.z>=L.z?n.push(e):e.z<=z.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(z.x,z.y,0),t=new f.Vector3(B.x,B.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&&(ie=!0,a<s?(R=R.addScaledVector(o,l),z=z.addScaledVector(o,l)):(L=L.addScaledVector(o,l),B=B.addScaledVector(o,l)));else if(!d&&!p&&i.length-S>.1)continue}else continue}S=R.distanceTo(L)}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,V=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?(L=x.facePoints[2].clone().addScaledVector(u,d),R=x.facePoints[3].clone(),z=R.clone(),B=L.clone(),z.z=B.z=x.facePoints[0].z):(L=x.facePoints[2].clone(),R=x.facePoints[3].clone().addScaledVector(u,d),z=R.clone(),B=L.clone(),z.z=B.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(),L=x.facePoints[2].clone().addScaledVector(p,m),R=x.facePoints[3].clone(),z=R.clone(),B=L.clone(),z.z=B.z=x.facePoints[0].z):(L=x.facePoints[2].clone(),R=x.facePoints[3].clone().addScaledVector(p,m),z=R.clone(),B=L.clone(),z.z=B.z=x.facePoints[0].z)}j=!0,M=!0,F.push(s[e].index),s[e].isFind=!0,n[s[e].index].isFindBeam=!0,V=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,V=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,z,B);if(n&&n.type==`collinear_overlap`&&n.maxPerpendicularDistance<.01){t=!0;break}}if(t){V!=-1&&(n[s[V].index].isFindBeam=!1,s[V].isFind=!1);continue}d.push({start:z,end:B});{new f.PointsMaterial({color:65535,size:.01});let e=new f.Vector3().subVectors(z,B),t=new f.Vector3().subVectors(B,z),n=1/0,r=1/0,a=z.clone(),o=B.clone(),s=[],c=[],l=new f.Line3(L,R),u=new f.Vector3,d=999999;if(i.originalPoints.forEach(n=>{if(n.z-z.z<C/2+.1&&n.z-z.z>C/2-.1&&s.push(n),n.z>L.z){let r=l.closestPointToPoint(n,!0,u),i=new f.Vector3().subVectors(r,L),a=b(e,new f.Vector3().subVectors(r,R)),o=b(t,i);a&&a.parallel&&!a.sameDirection&&o&&o.parallel&&!o.sameDirection&&c.push(n)}}),s.length>0){let{newProjectPoints:i}=P(z,B,s);for(let e of i)e.z=z.z;i.forEach(i=>{let s=new f.Vector3(i.x,i.y,z.z),c=new f.Vector3().subVectors(s,B),l=b(e,new f.Vector3().subVectors(s,z)),u=b(t,c);if(l&&l.parallel&&l.sameDirection){let e=s.distanceTo(z);e<n&&(n=e,a=s)}else if(u&&u.parallel&&u.sameDirection){let e=s.distanceTo(B);e<r&&(r=e,o=s)}})}if(a.equals(z)||(z=a,R=new f.Vector3(z.x,z.y,R.z)),o.equals(B)||(B=o,L=new f.Vector3(B.x,B.y,L.z)),c.length>10){let{newOnLinePoints:e}=P(R,L,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)}L.z+=d,R.z+=d,C+=d}}let o=B.distanceTo(z);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:L,beamEnd:R,beamHeight:i.rooftopPz-L.z,doorStart:z,doorEnd:B,doorHeight:C,nearId:-1,type:m,isExtend:ie,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(L.clone(),R.clone(),n.beamStart.clone(),n.beamEnd.clone());if(r&&r.isParallel){let e=L.distanceTo(R),r=n.beamStart.distanceTo(n.beamEnd),i=new f.Line3(L.clone(),R.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(L,R,!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=L.clone().addScaledVector(p,u),n.beamEnd=R.clone().addScaledVector(p,u),n.doorStart=z.clone().addScaledVector(p,u),n.doorEnd=B.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=L.clone().addScaledVector(p,u),n.beamEnd=R.clone().addScaledVector(p,u),n.doorStart=z.clone().addScaledVector(p,u),n.doorEnd=B.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=L.clone().addScaledVector(d,u),n.beamEnd=R.clone().addScaledVector(d,u),n.doorStart=z.clone().addScaledVector(d,u),n.doorEnd=B.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(z.clone(),B.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,z,B),u=T(o,c,z,B),d=N(e[a]);if(l&&l.maxPerpendicularDistance<.5){if(u&&u.isParallel){let e=new f.Line3(o,c),t=new f.Vector3(z.x,z.y,o.z),n=e.closestPointToPoint(t,!0,new f.Vector3),r=E(n,t,z,B);r&&r.angle>85&&(h.beamNearWallVec=new f.Vector3().subVectors(n,t).normalize())}let r=[];e[a].originalPoints.forEach(e=>{e.z>z.z+.2&&e.z<z.z+C/2&&r.push(new f.Vector3(e.x,e.y,z.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++)ee(i,m[e])&&p.push(m[e]);if(p=m,p=re(p),p.length<150)continue;let g=te(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(z.x,z.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,V!=-1&&(n[s[V].index].isFindBeam=!1,s[V].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:L,beamEnd:R}),I=!0),I));e++);I||p.push([{id:c,beamStart:L,beamEnd:R}]);let ne=h.doorStart.distanceTo(h.doorEnd);if(m=j?`door`:ne>1.8||A&&ne>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=E(b,x,S,C),k=r.distanceTo(l)>i.distanceTo(l)?i:r,A=k.distanceTo(l),j=k.distanceTo(u);if((A<m||j<m)&&w&&!w.isParallel&&D&&D.angle<85){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 b=new f.Vector3(e[y].start.x,e[y].start.y,0),x=new f.Vector3(e[y].end.x,e[y].end.y,0),S=new f.Vector3().subVectors(b,x).normalize(),C=S.clone().negate(),w=b.clone().addScaledVector(S,5),D=x.clone().addScaledVector(C,5),k=E(l,u,b,x),A=O(l,u,b,x),j=_(l,u,w,D),M=!0;if(j!=null&&(M=j.point.distanceTo(l)<m||j.point.distanceTo(u)<m),(k&&k.angle>85||A&&A.type==`collinear_gap`)&&M){let m=new f.Line3(l,u),_=new f.Vector3,S=m.closestPointToPoint(b,!0,_),C=m.closestPointToPoint(x,!0,_),w=S.distanceTo(b),E=C.distanceTo(x),D,k;if(w>E&&E>h)D=x,k=C;else if(w<E&&w>h)D=b,k=S;else continue;if(w=a.distanceTo(b),E=a.distanceTo(x),w>2&&E>2)continue;let A=T(D,k,b,x);if(!A||!A.isParallel)continue;let j=O(r,i,D,k);if(j&&j.type==`collinear_overlap`&&j.maxPerpendicularDistance<.2)continue;D.z=k.z=e[y].start.z;let M=!1;for(let e=0;e<v.length;e++){let t=O(v[e].start,v[e].end,D,k);if(t&&t.type==`collinear_overlap`&&t.maxPerpendicularDistance<.2){M=!0;break}}if(M)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),D,k);if(n&&n.type==`collinear_overlap`&&n.maxPerpendicularDistance<.1){M=!0;break}}if(M)continue;v.push({start:D,end:k}),g.push(y);let N=e[y].rooftopPz-e[y].start.z,P=e[o].rooftopPz-e[o].start.z,F=N<P?N:P;e[y].doorAndBeamData||(e[y].doorAndBeamData=[]),e[y].doorAndBeamData.push({id:c,beamStart:D,beamEnd:k,beamHeight:F,doorStart:D,doorEnd:k,doorHeight:F,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:D,beamEnd:k}]),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=L(g,l),x=L(g,u),S=L(_,l),C=L(_,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=L(v,m),C=L(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=L(h,w),x=L(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=L(S,l),T=L(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=L(r,l),s=L(a,l),c=L(r,u),m=L(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 _=L(p,u),v=L(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=L(_,y),C=L(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=L(n,_),o=L(r,_),s=L(n,v),c=L(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),ee=22204460492503146e-32*p;if(I>=ee||-I>=ee||(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)||(ee=11093356479670487e-47*p+33306690738754706e-32*Math.abs(I),(I+=M*_+F*m-(P*g+N*h))>=ee||-I>=ee))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 te=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 L=n(te,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(L,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){console.warn(`[merge] inconsistent rooftopPz: ${p.join(`/`)} max=${f.toFixed(3)} count=${e.length}`);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})}let m=[...new Set(e.map(e=>String(e.seg.buildRosource)))];m.length>1&&e.length>1&&console.warn(`[merge] buildRosource src: ${m.join(`/`)}`);let h=qn(e,t,l,u,n);for(let{l:e,r:n,srcIdxs:r}of h){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){if(![`_008`,`_002`,`_014`,`_015`,`_020`].some(t=>e.includes(t)))return;let l=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}});l.sort((e,t)=>e.lineDist-t.lineDist),console.warn(`[${e}扫查] 按无限直线距离排序的前 15 条候选: (需长≥${(a*c.minLengthRatio).toFixed(2)})`);for(let e=0;e<Math.min(15,l.length);e++){let t=l[e],n=t.length>=a*c.minLengthRatio?`✓`:`✗(需${(a*c.minLengthRatio).toFixed(2)})`,r=Math.abs(t.t)<=1.4?`✓`:`✗`,i=t.lineDist<=.65?`✓`:`✗`,o=t.angle<=45?`✓`:`✗`;console.warn(` #${e} 距=${t.lineDist.toFixed(3)}m t=${t.t.toFixed(3)} 角=${t.angle.toFixed(1)}° 长=${t.length.toFixed(3)}m [长度${n} 投影${r} 距离${i} 角度${o}] 起点(${t.seg.start.x.toFixed(3)},${t.seg.start.y.toFixed(3)})→(${t.seg.end.x.toFixed(3)},${t.seg.end.y.toFixed(3)}) | 5点: ${t.pts.join(` | `)}`)}}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}})}s.length>0&&console.log(`[findWindowWall] 候选 ${c.label}模式: ${s.length} 条`)}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}e.sort((e,t)=>t.score-e.score||e.minDist-t.minDist);let i=e.map(e=>`评分=${e.score}(conn=${e.details.conn}/var=${e.details.variance}/side=${e.details.sameSide}) dist=${e.minDist.toFixed(3)}`).join(` | `);console.log(`[findWindowWall] ${r} 评分排序: ${i}`);let a=e[0];return console.log(`[findWindowWall] ${r} → 选中评分=${a.score}(conn=${a.details.conn}/var=${a.details.variance}/side=${a.details.sameSide}) dist=${a.minDist.toFixed(3)}m`),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),c.length>0&&console.log(`[dataMerge] wall (${e.start.x.toFixed(3)},${e.start.y.toFixed(3)})->(${e.end.x.toFixed(3)},${e.end.y.toFixed(3)}) merged from ${t.length} segments drawWindow=${c.length} items`)}function ir(e){let t=e.filter(e=>e.drawWindow&&e.drawWindow.length>0);if(t.length!==0){console.log(`[findWindowWall] 合并后携带 drawWindow 的墙段数量=${t.length}`);for(let e of t){console.log(`[findWindowWall] 墙段: (${e.start.x.toFixed(3)},${e.start.y.toFixed(3)})->(${e.end.x.toFixed(3)},${e.end.y.toFixed(3)}) len=${e.length.toFixed(3)}m rooftopPz=${e.rooftopPz===void 0?`N/A`:e.rooftopPz.toFixed(3)}`);for(let t=0;t<e.drawWindow.length;t++){let n=e.drawWindow[t];console.log(` [drawWindow #${t}] p=(${n.p.x.toFixed(3)},${n.p.y.toFixed(3)}) width=${n.width.toFixed(3)}m height=${n.height.toFixed(3)}m groundClearance=${n.groundClearance.toFixed(3)}m full=${n.full}`)}}}}function ar(e,t,n){let r=Zn(n),i=[],{segments:a,sourceMap:o}=Xn(t);console.log(`[findWindowWall] 墙线段共线合并: ${t.length} → ${a.length} 条`);let s=[...a,...t];for(let n of e){let e=n.coordinatesByArea?.coordinates;if(!e||e.length<4){console.warn(`[findWindowWall] ${n.name} 缺少 coordinatesByArea.coordinates,跳过`);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){console.warn(`[findWindowWall] ${n.name} 四边形边长过短 (${u.toFixed(3)}),跳过`);continue}let p=o.reduce((e,t)=>e+t.z,0)/4,m=Rn(t,c,l);if(p<m-.3){console.warn(`[findWindowWall] ${n.name} 高度异常(z=${p.toFixed(3)},附近地面=${m.toFixed(3)}),跳过`);continue}let h=Qn(o,c,l);$n(n.name,s,c,l,h,u,d,f,r);let g=er(s,u,d,f,h,r);g=tr(g,h,t,n.name);let _=null,v=1/0,y=0;if(g.length>0){let e=g[0];_=e.seg,v=e.minDist,y=e.ratio}let b;if(_&&(b=nr(_,o,n,a),console.log(`[drawWindow]`,n.name,JSON.stringify(b)),!r.printOnly)){let e=_;e.drawWindow||=[],e.drawWindow.push(b)}_?i.push({windowName:n.name,windowCategory:n.category,windowCenter:n.center,wallSegment:_,distance:v,wallLengthRatio:y,drawWindow:b}):console.warn(`[findWindowWall] ${n.name} 未找到匹配的墙线段`)}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 ir(a),i}function or(e,t,n){let r={printOnly:!1,...n},i=ar(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=ar,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=or,exports.removeNoisePoints=F,exports.segmentsIntersect2D=_,exports.updateStEdPoint=se,exports.usegetBeamLine=_e;
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;
package/dist/index.js CHANGED
@@ -1563,7 +1563,7 @@ var De = async (t, n, r, i) => {
1563
1563
  } else continue;
1564
1564
  }
1565
1565
  }
1566
- let l = 0, u = [], d = [], f = [], p = [], m = .2;
1566
+ let l = 0, u = [], d = [], f = [], p = [], m = .15;
1567
1567
  for (let i = 0; i < t.length; i++) {
1568
1568
  let a = t[i];
1569
1569
  if (a.noDetection || (a.doorAndBeamData = [], !a.mergeCheckRegion || a.mergeCheckRegion.length == 0)) continue;
@@ -1830,7 +1830,7 @@ var De = async (t, n, r, i) => {
1830
1830
  for (let o = 0; o < t.length; o++) {
1831
1831
  if (t[o].length < .5 || o == i) continue;
1832
1832
  let s = new e.Vector3(t[o].start.x, t[o].start.y, t[o].start.z), l = new e.Vector3(t[o].end.x, t[o].end.y, t[o].end.z), u = z(s, l, M, P), d = I(s, l, M, P), f = re(t[o]);
1833
- if (u && u.maxPerpendicularDistance < .5) {
1833
+ if (console.log("x", o, "result", u), u && u.maxPerpendicularDistance < .5) {
1834
1834
  if (d && d.isParallel) {
1835
1835
  let t = new e.Line3(s, l), n = new e.Vector3(M.x, M.y, s.z), r = t.closestPointToPoint(n, !0, new e.Vector3()), i = L(r, n, M, P);
1836
1836
  i && i.angle > 85 && (h.beamNearWallVec = new e.Vector3().subVectors(r, n).normalize());
@@ -1883,7 +1883,7 @@ var De = async (t, n, r, i) => {
1883
1883
  beamEnd: A
1884
1884
  }]);
1885
1885
  let ee = h.doorStart.distanceTo(h.doorEnd);
1886
- if (m = T ? "door" : ee > 1.8 || w && ee > 1 ? "beam" : "hole", h.type = m, h.nearId != -1 && m == "hole") {
1886
+ if (console.log("id:", l, i, ee), m = T ? "door" : ee > 1.8 || w && ee > 1 ? "beam" : "hole", h.type = m, h.nearId != -1 && m == "hole") {
1887
1887
  let e = !1;
1888
1888
  for (let n = 0; n < t.length; n++) if (t[n].doorAndBeamData) {
1889
1889
  for (let r = 0; r < t[n].doorAndBeamData.length; r++) if (t[n].doorAndBeamData[r].nearId == l && t[n].doorAndBeamData[r].type == "beam") {
@@ -1936,62 +1936,62 @@ var De = async (t, n, r, i) => {
1936
1936
  if (t[s].length < .7 || t[s].completePointAreaPercentage > 60) continue;
1937
1937
  let u = new e.Vector3(t[s].start.x, t[s].start.y, 0), d = new e.Vector3(t[s].end.x, t[s].end.y, 0), f = new e.Vector3().subVectors(u, d).normalize(), v = .3, y = i.clone().addScaledVector(o, v), b = a.clone().addScaledVector(o.clone().negate(), v), x = u.clone().addScaledVector(f, v), S = d.clone().addScaledVector(f.clone().negate(), v);
1938
1938
  O(y, b, x, S);
1939
- let C = I(y, b, x, S), w = L(y, b, x, S), T = i.distanceTo(u) > a.distanceTo(u) ? a : i, E = T.distanceTo(u), D = T.distanceTo(d);
1940
- if ((E < m || D < m) && C && !C.isParallel && w && w.angle < 85) {
1939
+ let C = I(y, b, x, S), w = i.distanceTo(u) > a.distanceTo(u) ? a : i, T = w.distanceTo(u), E = w.distanceTo(d);
1940
+ if ((T < m || E < m) && C && !C.isParallel) {
1941
1941
  let o = i.distanceTo(u) < i.distanceTo(d) ? u : d, f = !1;
1942
1942
  for (let v = 0; v < t.length; v++) {
1943
1943
  if (v == s || g.includes(v) || t[v].length < .7) continue;
1944
- let y = new e.Vector3(t[v].start.x, t[v].start.y, 0), b = new e.Vector3(t[v].end.x, t[v].end.y, 0), x = new e.Vector3().subVectors(y, b).normalize(), S = x.clone().negate(), C = y.clone().addScaledVector(x, 5), w = b.clone().addScaledVector(S, 5), T = L(u, d, y, b), E = z(u, d, y, b), D = O(u, d, C, w), k = !0;
1945
- if (D != null && (k = D.point.distanceTo(u) < m || D.point.distanceTo(d) < m), (T && T.angle > 85 || E && E.type == "collinear_gap") && k) {
1946
- let m = new e.Line3(u, d), x = new e.Vector3(), S = m.closestPointToPoint(y, !0, x), C = m.closestPointToPoint(b, !0, x), w = S.distanceTo(y), T = C.distanceTo(b), E, D;
1947
- if (w > T && T > h) E = b, D = C;
1948
- else if (w < T && w > h) E = y, D = S;
1944
+ let x = new e.Vector3(t[v].start.x, t[v].start.y, 0), S = new e.Vector3(t[v].end.x, t[v].end.y, 0), C = new e.Vector3().subVectors(x, S).normalize(), w = C.clone().negate(), T = x.clone().addScaledVector(C, 5), E = S.clone().addScaledVector(w, 5), D = L(u, d, x, S), k = z(u, d, x, S), A = O(u, d, T, E), j = !0;
1945
+ if (A != null && (j = A.point.distanceTo(u) < m || A.point.distanceTo(d) < m), (D && D.angle > 85 || k && k.type == "collinear_gap") && j) {
1946
+ let m = new e.Line3(u, d), C = new e.Vector3(), w = m.closestPointToPoint(x, !0, C), T = m.closestPointToPoint(S, !0, C), E = w.distanceTo(x), D = T.distanceTo(S), O, k;
1947
+ if (E > D && D > h) O = S, k = T;
1948
+ else if (E < D && E > h) O = x, k = w;
1949
1949
  else continue;
1950
- if (w = o.distanceTo(y), T = o.distanceTo(b), w > 2 && T > 2) continue;
1951
- let O = I(E, D, y, b);
1952
- if (!O || !O.isParallel) continue;
1953
- let k = z(i, a, E, D);
1954
- if (k && k.type == "collinear_overlap" && k.maxPerpendicularDistance < .2) continue;
1955
- E.z = D.z = t[v].start.z;
1956
- let A = !1;
1950
+ if (E = o.distanceTo(x), D = o.distanceTo(S), E > 2 && D > 2) continue;
1951
+ let A = I(O, k, x, S), j = I(O, k, y, b);
1952
+ if (j && j.isParallel || !A || !A.isParallel) continue;
1953
+ let M = z(i, a, O, k);
1954
+ if (M && M.type == "collinear_overlap" && M.maxPerpendicularDistance < .2) continue;
1955
+ O.z = k.z = t[v].start.z;
1956
+ let N = !1;
1957
1957
  for (let e = 0; e < _.length; e++) {
1958
- let t = z(_[e].start, _[e].end, E, D);
1958
+ let t = z(_[e].start, _[e].end, O, k);
1959
1959
  if (t && t.type == "collinear_overlap" && t.maxPerpendicularDistance < .2) {
1960
- A = !0;
1960
+ N = !0;
1961
1961
  break;
1962
1962
  }
1963
1963
  }
1964
- if (A) continue;
1964
+ if (N) continue;
1965
1965
  for (let n = 0; n < t.length; n++) {
1966
1966
  if (t[n].length < .5) continue;
1967
- let r = z(new e.Vector3(t[n].start.x, t[n].start.y, t[n].start.z), new e.Vector3(t[n].end.x, t[n].end.y, t[n].end.z), E, D);
1967
+ let r = z(new e.Vector3(t[n].start.x, t[n].start.y, t[n].start.z), new e.Vector3(t[n].end.x, t[n].end.y, t[n].end.z), O, k);
1968
1968
  if (r && r.type == "collinear_overlap" && r.maxPerpendicularDistance < .1) {
1969
- A = !0;
1969
+ N = !0;
1970
1970
  break;
1971
1971
  }
1972
1972
  }
1973
- if (A) continue;
1973
+ if (N) continue;
1974
1974
  _.push({
1975
- start: E,
1976
- end: D
1975
+ start: O,
1976
+ end: k
1977
1977
  }), g.push(v);
1978
- let j = t[v].rooftopPz - t[v].start.z, M = t[s].rooftopPz - t[s].start.z, N = j < M ? j : M;
1978
+ let P = t[v].rooftopPz - t[v].start.z, F = t[s].rooftopPz - t[s].start.z, L = P < F ? P : F;
1979
1979
  t[v].doorAndBeamData || (t[v].doorAndBeamData = []), t[v].doorAndBeamData.push({
1980
1980
  id: l,
1981
- beamStart: E,
1982
- beamEnd: D,
1983
- beamHeight: N,
1984
- doorStart: E,
1985
- doorEnd: D,
1986
- doorHeight: N,
1981
+ beamStart: O,
1982
+ beamEnd: k,
1983
+ beamHeight: L,
1984
+ doorStart: O,
1985
+ doorEnd: k,
1986
+ doorHeight: L,
1987
1987
  nearId: -1,
1988
1988
  type: "onlyDoor",
1989
1989
  isDoor: !0,
1990
1990
  beamNearWallVec: new e.Vector3(0, 0, 0)
1991
1991
  }), r[c[n].index].isFindBeam = !0, r[c[n].index].isFindOnlyDoor = !0, p.push([{
1992
1992
  id: l,
1993
- beamStart: E,
1994
- beamEnd: D
1993
+ beamStart: O,
1994
+ beamEnd: k
1995
1995
  }]), l++, f = !0;
1996
1996
  break;
1997
1997
  }
@@ -4513,7 +4513,6 @@ function sr(e, t = 5, n = .05) {
4513
4513
  if (c < 1e-12) continue;
4514
4514
  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)))];
4515
4515
  if (p.length > 1) {
4516
- console.warn(`[merge] inconsistent rooftopPz: ${p.join("/")} max=${f.toFixed(3)} count=${e.length}`);
4517
4516
  let t = e.map((e) => ({
4518
4517
  idx: e.idx,
4519
4518
  start: {
@@ -4534,10 +4533,9 @@ function sr(e, t = 5, n = .05) {
4534
4533
  segments: t
4535
4534
  });
4536
4535
  }
4537
- let m = [...new Set(e.map((e) => String(e.seg.buildRosource)))];
4538
- m.length > 1 && e.length > 1 && console.warn(`[merge] buildRosource src: ${m.join("/")}`);
4539
- let h = ir(e, t, l, u, n);
4540
- for (let { l: e, r: n, srcIdxs: r } of h) {
4536
+ [...new Set(e.map((e) => String(e.seg.buildRosource)))];
4537
+ let m = ir(e, t, l, u, n);
4538
+ for (let { l: e, r: n, srcIdxs: r } of m) {
4541
4539
  if (n - e < .01) continue;
4542
4540
  let i = ar(t, e, n, l, u, f, t.buildRosource);
4543
4541
  a.push(i), o.push(r);
@@ -4591,14 +4589,13 @@ function lr(e, t, n) {
4591
4589
  ];
4592
4590
  }
4593
4591
  function ur(e, t, n, r, i, a, o, s, c) {
4594
- if (![
4592
+ [
4595
4593
  "_008",
4596
4594
  "_002",
4597
4595
  "_014",
4598
4596
  "_015",
4599
4597
  "_020"
4600
- ].some((t) => e.includes(t))) return;
4601
- let l = t.map((e) => {
4598
+ ].some((t) => e.includes(t)) && t.map((e) => {
4602
4599
  let { start: t, end: a } = e, c = Xn(n, r, t.x, t.y, a.x, a.y), l = i.map((e) => {
4603
4600
  let n = Xn(e.x, e.y, t.x, t.y, a.x, a.y);
4604
4601
  return `t=${n.t.toFixed(3)},d=${n.dist.toFixed(3)}`;
@@ -4611,12 +4608,7 @@ function ur(e, t, n, r, i, a, o, s, c) {
4611
4608
  angle: m,
4612
4609
  length: e.length
4613
4610
  };
4614
- });
4615
- l.sort((e, t) => e.lineDist - t.lineDist), console.warn(`[${e}扫查] 按无限直线距离排序的前 15 条候选: (需长≥${(a * c.minLengthRatio).toFixed(2)})`);
4616
- for (let e = 0; e < Math.min(15, l.length); e++) {
4617
- let t = l[e], n = t.length >= a * c.minLengthRatio ? "✓" : `✗(需${(a * c.minLengthRatio).toFixed(2)})`, r = Math.abs(t.t) <= 1.4 ? "✓" : "✗", i = t.lineDist <= .65 ? "✓" : "✗", o = t.angle <= 45 ? "✓" : "✗";
4618
- console.warn(` #${e} 距=${t.lineDist.toFixed(3)}m t=${t.t.toFixed(3)} 角=${t.angle.toFixed(1)}° 长=${t.length.toFixed(3)}m [长度${n} 投影${r} 距离${i} 角度${o}] 起点(${t.seg.start.x.toFixed(3)},${t.seg.start.y.toFixed(3)})→(${t.seg.end.x.toFixed(3)},${t.seg.end.y.toFixed(3)}) | 5点: ${t.pts.join(" | ")}`);
4619
- }
4611
+ }).sort((e, t) => e.lineDist - t.lineDist);
4620
4612
  }
4621
4613
  function dr(e, t, n, r, i, a) {
4622
4614
  let o = [{
@@ -4653,7 +4645,6 @@ function dr(e, t, n, r, i, a) {
4653
4645
  }
4654
4646
  });
4655
4647
  }
4656
- s.length > 0 && console.log(`[findWindowWall] 候选 ${c.label}模式: ${s.length} 条`);
4657
4648
  }
4658
4649
  return s;
4659
4650
  }
@@ -4663,11 +4654,7 @@ function fr(e, t, n, r) {
4663
4654
  let { score: e, details: i } = er(r.seg, t, n);
4664
4655
  r.score = e, r.details = i;
4665
4656
  }
4666
- e.sort((e, t) => t.score - e.score || e.minDist - t.minDist);
4667
- let i = e.map((e) => `评分=${e.score}(conn=${e.details.conn}/var=${e.details.variance}/side=${e.details.sameSide}) dist=${e.minDist.toFixed(3)}`).join(" | ");
4668
- console.log(`[findWindowWall] ${r} 评分排序: ${i}`);
4669
- let a = e[0];
4670
- return console.log(`[findWindowWall] ${r} → 选中评分=${a.score}(conn=${a.details.conn}/var=${a.details.variance}/side=${a.details.sameSide}) dist=${a.minDist.toFixed(3)}m`), e;
4657
+ return e.sort((e, t) => t.score - e.score || e.minDist - t.minDist), e;
4671
4658
  }
4672
4659
  function pr(e, t, n, r) {
4673
4660
  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) => {
@@ -4696,64 +4683,38 @@ function mr(e, t, n) {
4696
4683
  if (e.drawWindow?.length) for (let t of e.drawWindow) c.push(t);
4697
4684
  e.boxData && !l && (l = e.boxData);
4698
4685
  }
4699
- 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), c.length > 0 && console.log(`[dataMerge] wall (${e.start.x.toFixed(3)},${e.start.y.toFixed(3)})->(${e.end.x.toFixed(3)},${e.end.y.toFixed(3)}) merged from ${t.length} segments drawWindow=${c.length} items`);
4700
- }
4701
- function hr(e) {
4702
- let t = e.filter((e) => e.drawWindow && e.drawWindow.length > 0);
4703
- if (t.length !== 0) {
4704
- console.log(`[findWindowWall] 合并后携带 drawWindow 的墙段数量=${t.length}`);
4705
- for (let e of t) {
4706
- console.log(`[findWindowWall] 墙段: (${e.start.x.toFixed(3)},${e.start.y.toFixed(3)})->(${e.end.x.toFixed(3)},${e.end.y.toFixed(3)}) len=${e.length.toFixed(3)}m rooftopPz=${e.rooftopPz === void 0 ? "N/A" : e.rooftopPz.toFixed(3)}`);
4707
- for (let t = 0; t < e.drawWindow.length; t++) {
4708
- let n = e.drawWindow[t];
4709
- console.log(` [drawWindow #${t}] p=(${n.p.x.toFixed(3)},${n.p.y.toFixed(3)}) width=${n.width.toFixed(3)}m height=${n.height.toFixed(3)}m groundClearance=${n.groundClearance.toFixed(3)}m full=${n.full}`);
4710
- }
4711
- }
4712
- }
4686
+ 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);
4713
4687
  }
4714
- function gr(e, t, n) {
4715
- let r = cr(n), i = [], { segments: a, sourceMap: o } = sr(t);
4716
- console.log(`[findWindowWall] 墙线段共线合并: ${t.length} → ${a.length} 条`);
4717
- let s = [...a, ...t];
4688
+ function hr(e, t, n) {
4689
+ let r = cr(n), i = [], { segments: a, sourceMap: o } = sr(t), s = [...a, ...t];
4718
4690
  for (let n of e) {
4719
4691
  let e = n.coordinatesByArea?.coordinates;
4720
- if (!e || e.length < 4) {
4721
- console.warn(`[findWindowWall] ${n.name} 缺少 coordinatesByArea.coordinates,跳过`);
4722
- continue;
4723
- }
4692
+ if (!e || e.length < 4) continue;
4724
4693
  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 } = Jn(o);
4725
- if (u < .01) {
4726
- console.warn(`[findWindowWall] ${n.name} 四边形边长过短 (${u.toFixed(3)}),跳过`);
4727
- continue;
4728
- }
4729
- let p = o.reduce((e, t) => e + t.z, 0) / 4, m = Yn(t, c, l);
4730
- if (p < m - .3) {
4731
- console.warn(`[findWindowWall] ${n.name} 高度异常(z=${p.toFixed(3)},附近地面=${m.toFixed(3)}),跳过`);
4732
- continue;
4694
+ if (u < .01 || o.reduce((e, t) => e + t.z, 0) / 4 < Yn(t, c, l) - .3) continue;
4695
+ let p = lr(o, c, l);
4696
+ ur(n.name, s, c, l, p, u, d, f, r);
4697
+ let m = dr(s, u, d, f, p, r);
4698
+ m = fr(m, p, t, n.name);
4699
+ let h = null, g = Infinity, _ = 0;
4700
+ if (m.length > 0) {
4701
+ let e = m[0];
4702
+ h = e.seg, g = e.minDist, _ = e.ratio;
4733
4703
  }
4734
- let h = lr(o, c, l);
4735
- ur(n.name, s, c, l, h, u, d, f, r);
4736
- let g = dr(s, u, d, f, h, r);
4737
- g = fr(g, h, t, n.name);
4738
- let _ = null, v = Infinity, y = 0;
4739
- if (g.length > 0) {
4740
- let e = g[0];
4741
- _ = e.seg, v = e.minDist, y = e.ratio;
4704
+ let v;
4705
+ if (h && (v = pr(h, o, n, a), !r.printOnly)) {
4706
+ let e = h;
4707
+ e.drawWindow ||= [], e.drawWindow.push(v);
4742
4708
  }
4743
- let b;
4744
- if (_ && (b = pr(_, o, n, a), console.log("[drawWindow]", n.name, JSON.stringify(b)), !r.printOnly)) {
4745
- let e = _;
4746
- e.drawWindow ||= [], e.drawWindow.push(b);
4747
- }
4748
- _ ? i.push({
4709
+ h && i.push({
4749
4710
  windowName: n.name,
4750
4711
  windowCategory: n.category,
4751
4712
  windowCenter: n.center,
4752
- wallSegment: _,
4753
- distance: v,
4754
- wallLengthRatio: y,
4755
- drawWindow: b
4756
- }) : console.warn(`[findWindowWall] ${n.name} 未找到匹配的墙线段`);
4713
+ wallSegment: h,
4714
+ distance: g,
4715
+ wallLengthRatio: _,
4716
+ drawWindow: v
4717
+ });
4757
4718
  }
4758
4719
  for (let e of i) {
4759
4720
  let n = e.wallSegment, r = a.indexOf(n);
@@ -4761,15 +4722,15 @@ function gr(e, t, n) {
4761
4722
  let i = o[r];
4762
4723
  !i || i.length <= 1 || mr(n, i, t);
4763
4724
  }
4764
- return hr(a), i;
4725
+ return i;
4765
4726
  }
4766
4727
  //#endregion
4767
4728
  //#region src/wall-window-matcher/entry.ts
4768
- function _r(e, t, n) {
4729
+ function gr(e, t, n) {
4769
4730
  let r = {
4770
4731
  printOnly: !1,
4771
4732
  ...n
4772
- }, i = gr(Array.isArray(t) ? t.filter((e) => e && e.category === "window") : [], e, r), { segments: a, sourceMap: o } = sr(e);
4733
+ }, i = hr(Array.isArray(t) ? t.filter((e) => e && e.category === "window") : [], e, r), { segments: a, sourceMap: o } = sr(e);
4773
4734
  for (let e of i) if (e.drawWindow) {
4774
4735
  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);
4775
4736
  t && (t.drawWindow ||= [], t.drawWindow.push(e.drawWindow));
@@ -4781,4 +4742,4 @@ function _r(e, t, n) {
4781
4742
  };
4782
4743
  }
4783
4744
  //#endregion
4784
- export { z as classifySegments, Yn as computeLocalFloorZ, gr as findWindowWalls, ge as getAllGeometry, Oe as getBeamLine, Ae as getColLine, ke as getMainBeamLine, Kn as getMergeMeaning, I as getParallelism, re as getPointCloudMinMax, te as getPointCoverageOnQuad, j as isParallel, sr as mergeCollinearSegments, L as perpendicularInfo, _r as processData, ae as removeNoisePoints, O as segmentsIntersect2D, _e as updateStEdPoint, De as usegetBeamLine };
4745
+ export { z as classifySegments, Yn as computeLocalFloorZ, hr as findWindowWalls, ge as getAllGeometry, Oe as getBeamLine, Ae as getColLine, ke as getMainBeamLine, Kn as getMergeMeaning, I as getParallelism, re as getPointCloudMinMax, te as getPointCoverageOnQuad, j as isParallel, sr as mergeCollinearSegments, L as perpendicularInfo, gr as processData, ae as removeNoisePoints, O as segmentsIntersect2D, _e as updateStEdPoint, De as usegetBeamLine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rm-graphical-computing",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Three.js wall segment processing utilities.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",