rm-graphical-computing-node 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var xi=Object.create;var ar=Object.defineProperty;var yi=Object.getOwnPropertyDescriptor;var bi=Object.getOwnPropertyNames;var wi=Object.getPrototypeOf,zi=Object.prototype.hasOwnProperty;var Le=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Mi=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of bi(e))!zi.call(t,r)&&r!==n&&ar(t,r,{get:()=>e[r],enumerable:!(o=yi(e,r))||o.enumerable});return t};var Ei=(t,e,n)=>(n=t!=null?xi(wi(t)):{},Mi(e||!t||!t.__esModule?ar(n,"default",{value:t,enumerable:!0}):n,t));var Lr=Le((Ro,Do)=>{(function(t,e){typeof Ro=="object"&&typeof Do<"u"?Do.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self,t.RBush=e())})(Ro,function(){"use strict";function t(b,w,z,M,P){e(b,w,z||0,M||b.length-1,P||o)}function e(b,w,z,M,P){for(;M>z;){if(M-z>600){var E=M-z+1,S=w-z+1,I=Math.log(E),W=.5*Math.exp(2*I/3),v=.5*Math.sqrt(I*W*(E-W)/E)*(S-E/2<0?-1:1),T=Math.max(z,Math.floor(w-S*W/E+v)),R=Math.min(M,Math.floor(w+(E-S)*W/E+v));e(b,w,T,R,P)}var D=b[w],H=z,V=M;for(n(b,z,w),P(b[M],D)>0&&n(b,z,M);H<V;){for(n(b,H,V),H++,V--;P(b[H],D)<0;)H++;for(;P(b[V],D)>0;)V--}P(b[z],D)===0?n(b,z,V):(V++,n(b,V,M)),V<=w&&(z=V+1),w<=V&&(M=V-1)}}function n(b,w,z){var M=b[w];b[w]=b[z],b[z]=M}function o(b,w){return b<w?-1:b>w?1:0}var r=function(w){w===void 0&&(w=9),this._maxEntries=Math.max(4,w),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()};r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(w){var z=this.data,M=[];if(!y(w,z))return M;for(var P=this.toBBox,E=[];z;){for(var S=0;S<z.children.length;S++){var I=z.children[S],W=z.leaf?P(I):I;y(w,W)&&(z.leaf?M.push(I):x(w,W)?this._all(I,M):E.push(I))}z=E.pop()}return M},r.prototype.collides=function(w){var z=this.data;if(!y(w,z))return!1;for(var M=[];z;){for(var P=0;P<z.children.length;P++){var E=z.children[P],S=z.leaf?this.toBBox(E):E;if(y(w,S)){if(z.leaf||x(w,S))return!0;M.push(E)}}z=M.pop()}return!1},r.prototype.load=function(w){if(!(w&&w.length))return this;if(w.length<this._minEntries){for(var z=0;z<w.length;z++)this.insert(w[z]);return this}var M=this._build(w.slice(),0,w.length-1,0);if(!this.data.children.length)this.data=M;else if(this.data.height===M.height)this._splitRoot(this.data,M);else{if(this.data.height<M.height){var P=this.data;this.data=M,M=P}this._insert(M,this.data.height-M.height-1,!0)}return this},r.prototype.insert=function(w){return w&&this._insert(w,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(w,z){if(!w)return this;for(var M=this.data,P=this.toBBox(w),E=[],S=[],I,W,v;M||E.length;){if(M||(M=E.pop(),W=E[E.length-1],I=S.pop(),v=!0),M.leaf){var T=s(w,M.children,z);if(T!==-1)return M.children.splice(T,1),E.push(M),this._condense(E),this}!v&&!M.leaf&&x(M,P)?(E.push(M),S.push(I),I=0,W=M,M=M.children[0]):W?(I++,M=W.children[I],v=!1):M=null}return this},r.prototype.toBBox=function(w){return w},r.prototype.compareMinX=function(w,z){return w.minX-z.minX},r.prototype.compareMinY=function(w,z){return w.minY-z.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(w){return this.data=w,this},r.prototype._all=function(w,z){for(var M=[];w;)w.leaf?z.push.apply(z,w.children):M.push.apply(M,w.children),w=M.pop();return z},r.prototype._build=function(w,z,M,P){var E=M-z+1,S=this._maxEntries,I;if(E<=S)return I=m(w.slice(z,M+1)),i(I,this.toBBox),I;P||(P=Math.ceil(Math.log(E)/Math.log(S)),S=Math.ceil(E/Math.pow(S,P-1))),I=m([]),I.leaf=!1,I.height=P;var W=Math.ceil(E/S),v=W*Math.ceil(Math.sqrt(S));p(w,z,M,v,this.compareMinX);for(var T=z;T<=M;T+=v){var R=Math.min(T+v-1,M);p(w,T,R,W,this.compareMinY);for(var D=T;D<=R;D+=W){var H=Math.min(D+W-1,R);I.children.push(this._build(w,D,H,P-1))}}return i(I,this.toBBox),I},r.prototype._chooseSubtree=function(w,z,M,P){for(;P.push(z),!(z.leaf||P.length-1===M);){for(var E=1/0,S=1/0,I=void 0,W=0;W<z.children.length;W++){var v=z.children[W],T=c(v),R=h(w,v)-T;R<S?(S=R,E=T<E?T:E,I=v):R===S&&T<E&&(E=T,I=v)}z=I||z.children[0]}return z},r.prototype._insert=function(w,z,M){var P=M?w:this.toBBox(w),E=[],S=this._chooseSubtree(P,this.data,z,E);for(S.children.push(w),u(S,P);z>=0&&E[z].children.length>this._maxEntries;)this._split(E,z),z--;this._adjustParentBBoxes(P,E,z)},r.prototype._split=function(w,z){var M=w[z],P=M.children.length,E=this._minEntries;this._chooseSplitAxis(M,E,P);var S=this._chooseSplitIndex(M,E,P),I=m(M.children.splice(S,M.children.length-S));I.height=M.height,I.leaf=M.leaf,i(M,this.toBBox),i(I,this.toBBox),z?w[z-1].children.push(I):this._splitRoot(M,I)},r.prototype._splitRoot=function(w,z){this.data=m([w,z]),this.data.height=w.height+1,this.data.leaf=!1,i(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(w,z,M){for(var P,E=1/0,S=1/0,I=z;I<=M-z;I++){var W=a(w,0,I,this.toBBox),v=a(w,I,M,this.toBBox),T=g(W,v),R=c(W)+c(v);T<E?(E=T,P=I,S=R<S?R:S):T===E&&R<S&&(S=R,P=I)}return P||M-z},r.prototype._chooseSplitAxis=function(w,z,M){var P=w.leaf?this.compareMinX:d,E=w.leaf?this.compareMinY:f,S=this._allDistMargin(w,z,M,P),I=this._allDistMargin(w,z,M,E);S<I&&w.children.sort(P)},r.prototype._allDistMargin=function(w,z,M,P){w.children.sort(P);for(var E=this.toBBox,S=a(w,0,z,E),I=a(w,M-z,M,E),W=l(S)+l(I),v=z;v<M-z;v++){var T=w.children[v];u(S,w.leaf?E(T):T),W+=l(S)}for(var R=M-z-1;R>=z;R--){var D=w.children[R];u(I,w.leaf?E(D):D),W+=l(I)}return W},r.prototype._adjustParentBBoxes=function(w,z,M){for(var P=M;P>=0;P--)u(z[P],w)},r.prototype._condense=function(w){for(var z=w.length-1,M=void 0;z>=0;z--)w[z].children.length===0?z>0?(M=w[z-1].children,M.splice(M.indexOf(w[z]),1)):this.clear():i(w[z],this.toBBox)};function s(b,w,z){if(!z)return w.indexOf(b);for(var M=0;M<w.length;M++)if(z(b,w[M]))return M;return-1}function i(b,w){a(b,0,b.children.length,w,b)}function a(b,w,z,M,P){P||(P=m(null)),P.minX=1/0,P.minY=1/0,P.maxX=-1/0,P.maxY=-1/0;for(var E=w;E<z;E++){var S=b.children[E];u(P,b.leaf?M(S):S)}return P}function u(b,w){return b.minX=Math.min(b.minX,w.minX),b.minY=Math.min(b.minY,w.minY),b.maxX=Math.max(b.maxX,w.maxX),b.maxY=Math.max(b.maxY,w.maxY),b}function d(b,w){return b.minX-w.minX}function f(b,w){return b.minY-w.minY}function c(b){return(b.maxX-b.minX)*(b.maxY-b.minY)}function l(b){return b.maxX-b.minX+(b.maxY-b.minY)}function h(b,w){return(Math.max(w.maxX,b.maxX)-Math.min(w.minX,b.minX))*(Math.max(w.maxY,b.maxY)-Math.min(w.minY,b.minY))}function g(b,w){var z=Math.max(b.minX,w.minX),M=Math.max(b.minY,w.minY),P=Math.min(b.maxX,w.maxX),E=Math.min(b.maxY,w.maxY);return Math.max(0,P-z)*Math.max(0,E-M)}function x(b,w){return b.minX<=w.minX&&b.minY<=w.minY&&w.maxX<=b.maxX&&w.maxY<=b.maxY}function y(b,w){return w.minX<=b.maxX&&w.minY<=b.maxY&&w.maxX>=b.minX&&w.maxY>=b.minY}function m(b){return{children:b,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function p(b,w,z,M,P){for(var E=[w,z];E.length;)if(z=E.pop(),w=E.pop(),!(z-w<=M)){var S=w+Math.ceil((z-w)/M/2)*M;t(b,S,w,z,P),E.push(w,S,S,z)}}return r})});var kr=Le((vo,Vo)=>{(function(t,e){typeof vo=="object"&&typeof Vo<"u"?Vo.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self,t.TinyQueue=e())})(vo,function(){"use strict";var t=function(o,r){if(o===void 0&&(o=[]),r===void 0&&(r=e),this.data=o,this.length=this.data.length,this.compare=r,this.length>0)for(var s=(this.length>>1)-1;s>=0;s--)this._down(s)};t.prototype.push=function(o){this.data.push(o),this.length++,this._up(this.length-1)},t.prototype.pop=function(){if(this.length!==0){var o=this.data[0],r=this.data.pop();return this.length--,this.length>0&&(this.data[0]=r,this._down(0)),o}},t.prototype.peek=function(){return this.data[0]},t.prototype._up=function(o){for(var r=this,s=r.data,i=r.compare,a=s[o];o>0;){var u=o-1>>1,d=s[u];if(i(a,d)>=0)break;s[o]=d,o=u}s[o]=a},t.prototype._down=function(o){for(var r=this,s=r.data,i=r.compare,a=this.length>>1,u=s[o];o<a;){var d=(o<<1)+1,f=s[d],c=d+1;if(c<this.length&&i(s[c],f)<0&&(d=c,f=s[c]),i(f,u)>=0)break;s[o]=f,o=d}s[o]=u};function e(n,o){return n<o?-1:n>o?1:0}return t})});var Fr=Le((rh,Or)=>{Or.exports=function(e,n,o,r){var s=e[0],i=e[1],a=!1;o===void 0&&(o=0),r===void 0&&(r=n.length);for(var u=(r-o)/2,d=0,f=u-1;d<u;f=d++){var c=n[o+d*2+0],l=n[o+d*2+1],h=n[o+f*2+0],g=n[o+f*2+1],x=l>i!=g>i&&s<(h-c)*(i-l)/(g-l)+c;x&&(a=!a)}return a}});var qr=Le((sh,Nr)=>{Nr.exports=function(e,n,o,r){var s=e[0],i=e[1],a=!1;o===void 0&&(o=0),r===void 0&&(r=n.length);for(var u=r-o,d=0,f=u-1;d<u;f=d++){var c=n[d+o][0],l=n[d+o][1],h=n[f+o][0],g=n[f+o][1],x=l>i!=g>i&&s<(h-c)*(i-l)/(g-l)+c;x&&(a=!a)}return a}});var Xr=Le((ih,Gn)=>{var jr=Fr(),$r=qr();Gn.exports=function(e,n,o,r){return n.length>0&&Array.isArray(n[0])?$r(e,n,o,r):jr(e,n,o,r)};Gn.exports.nested=$r;Gn.exports.flat=jr});var Gr=Le((Yn,Zr)=>{(function(t,e){typeof Yn=="object"&&typeof Zr<"u"?e(Yn):typeof define=="function"&&define.amd?define(["exports"],e):e((t=t||self).predicates={})})(Yn,function(t){"use strict";let n=33306690738754706e-32;function o(h,g,x,y,m){let p,b,w,z,M=g[0],P=y[0],E=0,S=0;P>M==P>-M?(p=M,M=g[++E]):(p=P,P=y[++S]);let I=0;if(E<h&&S<x)for(P>M==P>-M?(w=p-((b=M+p)-M),M=g[++E]):(w=p-((b=P+p)-P),P=y[++S]),p=b,w!==0&&(m[I++]=w);E<h&&S<x;)P>M==P>-M?(w=p-((b=p+M)-(z=b-p))+(M-z),M=g[++E]):(w=p-((b=p+P)-(z=b-p))+(P-z),P=y[++S]),p=b,w!==0&&(m[I++]=w);for(;E<h;)w=p-((b=p+M)-(z=b-p))+(M-z),M=g[++E],p=b,w!==0&&(m[I++]=w);for(;S<x;)w=p-((b=p+P)-(z=b-p))+(P-z),P=y[++S],p=b,w!==0&&(m[I++]=w);return p===0&&I!==0||(m[I++]=p),I}function r(h){return new Float64Array(h)}let s=33306690738754716e-32,i=22204460492503146e-32,a=11093356479670487e-47,u=r(4),d=r(8),f=r(12),c=r(16),l=r(4);t.orient2d=function(h,g,x,y,m,p){let b=(g-p)*(x-m),w=(h-m)*(y-p),z=b-w;if(b===0||w===0||b>0!=w>0)return z;let M=Math.abs(b+w);return Math.abs(z)>=s*M?z:-(function(P,E,S,I,W,v,T){let R,D,H,V,C,_,A,L,k,F,B,O,$,Z,Q,j,X,U,at=P-W,mt=S-W,St=E-v,ot=I-v;C=(Q=(L=at-(A=(_=134217729*at)-(_-at)))*(F=ot-(k=(_=134217729*ot)-(_-ot)))-((Z=at*ot)-A*k-L*k-A*F))-(B=Q-(X=(L=St-(A=(_=134217729*St)-(_-St)))*(F=mt-(k=(_=134217729*mt)-(_-mt)))-((j=St*mt)-A*k-L*k-A*F))),u[0]=Q-(B+C)+(C-X),C=($=Z-((O=Z+B)-(C=O-Z))+(B-C))-(B=$-j),u[1]=$-(B+C)+(C-j),C=(U=O+B)-O,u[2]=O-(U-C)+(B-C),u[3]=U;let Mt=(function(Pt,et){let ht=et[0];for(let nt=1;nt<Pt;nt++)ht+=et[nt];return ht})(4,u),bt=i*T;if(Mt>=bt||-Mt>=bt||(R=P-(at+(C=P-at))+(C-W),H=S-(mt+(C=S-mt))+(C-W),D=E-(St+(C=E-St))+(C-v),V=I-(ot+(C=I-ot))+(C-v),R===0&&D===0&&H===0&&V===0)||(bt=a*T+n*Math.abs(Mt),(Mt+=at*V+ot*R-(St*H+mt*D))>=bt||-Mt>=bt))return Mt;C=(Q=(L=R-(A=(_=134217729*R)-(_-R)))*(F=ot-(k=(_=134217729*ot)-(_-ot)))-((Z=R*ot)-A*k-L*k-A*F))-(B=Q-(X=(L=D-(A=(_=134217729*D)-(_-D)))*(F=mt-(k=(_=134217729*mt)-(_-mt)))-((j=D*mt)-A*k-L*k-A*F))),l[0]=Q-(B+C)+(C-X),C=($=Z-((O=Z+B)-(C=O-Z))+(B-C))-(B=$-j),l[1]=$-(B+C)+(C-j),C=(U=O+B)-O,l[2]=O-(U-C)+(B-C),l[3]=U;let Ct=o(4,u,4,l,d);C=(Q=(L=at-(A=(_=134217729*at)-(_-at)))*(F=V-(k=(_=134217729*V)-(_-V)))-((Z=at*V)-A*k-L*k-A*F))-(B=Q-(X=(L=St-(A=(_=134217729*St)-(_-St)))*(F=H-(k=(_=134217729*H)-(_-H)))-((j=St*H)-A*k-L*k-A*F))),l[0]=Q-(B+C)+(C-X),C=($=Z-((O=Z+B)-(C=O-Z))+(B-C))-(B=$-j),l[1]=$-(B+C)+(C-j),C=(U=O+B)-O,l[2]=O-(U-C)+(B-C),l[3]=U;let Et=o(Ct,d,4,l,f);C=(Q=(L=R-(A=(_=134217729*R)-(_-R)))*(F=V-(k=(_=134217729*V)-(_-V)))-((Z=R*V)-A*k-L*k-A*F))-(B=Q-(X=(L=D-(A=(_=134217729*D)-(_-D)))*(F=H-(k=(_=134217729*H)-(_-H)))-((j=D*H)-A*k-L*k-A*F))),l[0]=Q-(B+C)+(C-X),C=($=Z-((O=Z+B)-(C=O-Z))+(B-C))-(B=$-j),l[1]=$-(B+C)+(C-j),C=(U=O+B)-O,l[2]=O-(U-C)+(B-C),l[3]=U;let zt=o(Et,f,4,l,c);return c[zt-1]})(h,g,x,y,m,p,M)},t.orient2dfast=function(h,g,x,y,m,p){return(g-p)*(x-m)-(h-m)*(y-p)},Object.defineProperty(t,"__esModule",{value:!0})})});var ts=Le((lh,Wo)=>{"use strict";var Yr=Lr(),Kn=kr(),bl=Xr(),wl=Gr().orient2d;Kn.default&&(Kn=Kn.default);Wo.exports=Jr;Wo.exports.default=Jr;function Jr(t,e,n){e=Math.max(0,e===void 0?2:e),n=n||0;var o=Tl(t),r=new Yr(16);r.toBBox=function(p){return{minX:p[0],minY:p[1],maxX:p[0],maxY:p[1]}},r.compareMinX=function(p,b){return p[0]-b[0]},r.compareMinY=function(p,b){return p[1]-b[1]},r.load(t);for(var s=[],i=0,a;i<o.length;i++){var u=o[i];r.remove(u),a=Qr(u,a),s.push(a)}var d=new Yr(16);for(i=0;i<s.length;i++)d.insert(Io(s[i]));for(var f=e*e,c=n*n;s.length;){var l=s.shift(),h=l.p,g=l.next.p,x=Co(h,g);if(!(x<c)){var y=x/f;u=zl(r,l.prev.p,h,g,l.next.next.p,y,d),u&&Math.min(Co(u,h),Co(u,g))<=y&&(s.push(l),s.push(Qr(u,l)),r.remove(u),d.remove(l),d.insert(Io(l)),d.insert(Io(l.next)))}}l=a;var m=[];do m.push(l.p),l=l.next;while(l!==a);return m.push(l.p),m}function zl(t,e,n,o,r,s,i){for(var a=new Kn([],Ml),u=t.data;u;){for(var d=0;d<u.children.length;d++){var f=u.children[d],c=u.leaf?Ho(f,n,o):El(n,o,f);c>s||a.push({node:f,dist:c})}for(;a.length&&!a.peek().node.children;){var l=a.pop(),h=l.node,g=Ho(h,e,n),x=Ho(h,o,r);if(l.dist<g&&l.dist<x&&Kr(n,h,i)&&Kr(o,h,i))return h}u=a.pop(),u&&(u=u.node)}return null}function Ml(t,e){return t.dist-e.dist}function El(t,e,n){if(Ur(t,n)||Ur(e,n))return 0;var o=Un(t[0],t[1],e[0],e[1],n.minX,n.minY,n.maxX,n.minY);if(o===0)return 0;var r=Un(t[0],t[1],e[0],e[1],n.minX,n.minY,n.minX,n.maxY);if(r===0)return 0;var s=Un(t[0],t[1],e[0],e[1],n.maxX,n.minY,n.maxX,n.maxY);if(s===0)return 0;var i=Un(t[0],t[1],e[0],e[1],n.minX,n.maxY,n.maxX,n.maxY);return i===0?0:Math.min(o,r,s,i)}function Ur(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function Kr(t,e,n){for(var o=Math.min(t[0],e[0]),r=Math.min(t[1],e[1]),s=Math.max(t[0],e[0]),i=Math.max(t[1],e[1]),a=n.search({minX:o,minY:r,maxX:s,maxY:i}),u=0;u<a.length;u++)if(Pl(a[u].p,a[u].next.p,t,e))return!1;return!0}function an(t,e,n){return wl(t[0],t[1],e[0],e[1],n[0],n[1])}function Pl(t,e,n,o){return t!==o&&e!==n&&an(t,e,n)>0!=an(t,e,o)>0&&an(n,o,t)>0!=an(n,o,e)>0}function Io(t){var e=t.p,n=t.next.p;return t.minX=Math.min(e[0],n[0]),t.minY=Math.min(e[1],n[1]),t.maxX=Math.max(e[0],n[0]),t.maxY=Math.max(e[1],n[1]),t}function Tl(t){for(var e=t[0],n=t[0],o=t[0],r=t[0],s=0;s<t.length;s++){var i=t[s];i[0]<e[0]&&(e=i),i[0]>o[0]&&(o=i),i[1]<n[1]&&(n=i),i[1]>r[1]&&(r=i)}var a=[e,n,o,r],u=a.slice();for(s=0;s<t.length;s++)bl(t[s],a)||u.push(t[s]);return Rl(u)}function Qr(t,e){var n={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(n.next=e.next,n.prev=e,e.next.prev=n,e.next=n):(n.prev=n,n.next=n),n}function Co(t,e){var n=t[0]-e[0],o=t[1]-e[1];return n*n+o*o}function Ho(t,e,n){var o=e[0],r=e[1],s=n[0]-o,i=n[1]-r;if(s!==0||i!==0){var a=((t[0]-o)*s+(t[1]-r)*i)/(s*s+i*i);a>1?(o=n[0],r=n[1]):a>0&&(o+=s*a,r+=i*a)}return s=t[0]-o,i=t[1]-r,s*s+i*i}function Un(t,e,n,o,r,s,i,a){var u=n-t,d=o-e,f=i-r,c=a-s,l=t-r,h=e-s,g=u*u+d*d,x=u*f+d*c,y=f*f+c*c,m=u*l+d*h,p=f*l+c*h,b=g*y-x*x,w,z,M,P,E=b,S=b;b===0?(z=0,E=1,P=p,S=y):(z=x*p-y*m,P=g*p-x*m,z<0?(z=0,P=p,S=y):z>E&&(z=E,P=p+x,S=y)),P<0?(P=0,-m<0?z=0:-m>g?z=E:(z=-m,E=g)):P>S&&(P=S,-m+x<0?z=0:-m+x>g?z=E:(z=-m+x,E=g)),w=z===0?0:z/E,M=P===0?0:P/S;var I=(1-w)*t+w*n,W=(1-w)*e+w*o,v=(1-M)*r+M*i,T=(1-M)*s+M*a,R=v-I,D=T-W;return R*R+D*D}function Sl(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}function Rl(t){t.sort(Sl);for(var e=[],n=0;n<t.length;n++){for(;e.length>=2&&an(e[e.length-2],e[e.length-1],t[n])<=0;)e.pop();e.push(t[n])}for(var o=[],r=t.length-1;r>=0;r--){for(;o.length>=2&&an(o[o.length-2],o[o.length-1],t[r])<=0;)o.pop();o.push(t[r])}return o.pop(),e.pop(),e.concat(o)}});import*as Oe from"three";import*as ke from"three";var _t=class t{constructor(e=0,n=0,o=0){this.x=e,this.y=n,this.z=o}set(e,n,o){return this.x=e,this.y=n,this.z=o,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}clone(){return new t(this.x,this.y,this.z)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}crossVectors(e,n){let o=e.x,r=e.y,s=e.z,i=n.x,a=n.y,u=n.z;return this.x=r*u-s*a,this.y=s*i-o*u,this.z=o*a-r*i,this}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.lengthSq())}normalize(){let e=this.length();return e>0&&(this.x/=e,this.y/=e,this.z/=e),this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let n=this.x-e.x,o=this.y-e.y,r=this.z-e.z;return n*n+o*o+r*r}toArray(){return[this.x,this.y,this.z]}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}applyAxisAngle(e,n){let o=this.x,r=this.y,s=this.z,i=e.x,a=e.y,u=e.z,d=Math.cos(n),f=Math.sin(n),c=i*o+a*r+u*s;return this.x=i*c*(1-d)+o*d+(-u*r+a*s)*f,this.y=a*c*(1-d)+r*d+(u*o-i*s)*f,this.z=u*c*(1-d)+s*d+(-a*o+i*r)*f,this}},An=class{constructor(e=new _t(1,0,0),n=0){this.normal=e,this.constant=n}set(e,n){return this.normal.copy(e),this.constant=n,this}setFromNormalAndCoplanarPoint(e,n){return this.normal.copy(e),this.constant=-n.dot(this.normal),this}setFromCoplanarPoints(e,n,o){let r=new _t().subVectors(n,e),s=new _t().subVectors(o,e),i=new _t().crossVectors(r,s).normalize();return this.normal.copy(i),this.constant=-e.dot(this.normal),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}projectPoint(e,n=new _t){let o=this.distanceToPoint(e);return n.copy(e),n.x-=this.normal.x*o,n.y-=this.normal.y*o,n.z-=this.normal.z*o,n}},_n=()=>typeof performance<"u"&&performance.now?performance.now():Date.now(),yo=class{constructor(){this.results=null,this.clusterResults=null}initLimits1(e,n){let o,r;return e<.3?o=5:e<.5?o=8:e<.8?o=10:e<1?o=15:e<2?o=30:e<3?o=35:e<4?o=40:e<5?o=45:e<6?o=50:e<7?o=60:e<8.5?o=70:e<10?o=80:e<15?o=100:e<20?o=120:e<25?o=140:e<30?o=160:e<35?o=180:e<40?o=200:e<45?o=230:e<50?o=250:o=350,n<1?r=30:n<2?r=40:n<2.5?r=45:n<3?r=60:n<3.6?r=70:r=80,{horizontalSubdivisions:o,verticalSubdivisions:r}}initLimits2(e,n){let s=Math.round(Math.max(5,Math.min(350,e/.08))),i=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:s,verticalSubdivisions:i}}initLimits3(e,n){let o;e<2?o=.06:e<10?o=.1:o=.15;let r=Math.round(Math.max(5,Math.min(350,e/o))),s=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(e,n){let o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(e)))),r=Math.round(Math.max(30,Math.min(80,20*Math.sqrt(n))));return{horizontalSubdivisions:o,verticalSubdivisions:r}}createSubdividedWallPlane(e,n,o,r=null){let s=[];if(!e||!e.start||!e.end||isNaN(e.rooftopPz))return s;let i=new _t(e.start.x,e.start.y,e.start.z),a=new _t(e.end.x,e.end.y,e.end.z),u=new _t(e.end.x,e.end.y,e.rooftopPz),d=new _t(e.start.x,e.start.y,e.rooftopPz),f=[i,a,u,d];for(let P=0;P<f.length;P++)if(!this.isValidVector3(f[P]))return console.error(`\u5899\u4F53\u57FA\u7840\u70B9${P}\u65E0\u6548:`,f[P]),s;let c=i.distanceTo(a),l=Math.abs(e.rooftopPz-e.start.z);if(c===0||l===0)return s;let h=c/o,g=l/n,x=new _t().subVectors(a,i).normalize(),y=i.x,m=i.y,p=i.z,b=x.x,w=x.y,z=x.z,M=(P,E)=>new _t(y+b*P,m+w*P,p+z*P+E);for(let P=0;P<n;P++){let E=P*g,S=(P+1)*g;for(let I=0;I<o;I++){let W=I*h,v=(I+1)*h;s.push({points:[M(W,E),M(v,E),M(v,S),M(W,S)],userData:{type:"wallSegment",row:P,col:I,width:h,height:g}})}}return s}analyzePointDistribution(e,n,o=.01,r={}){let s=r.projectPlane||null;this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],existSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};let i=_n(),a=[],u=new Map,d=1/0,f=-1/0,c=1/0,l=-1/0;for(let W=0;W<e.length;W++){let v=e[W];if(v.userData&&v.userData.type==="wallSegment"){let T=this.getWorldVerticesNew(v.points);if(T.length<4)continue;let R=new _t().add(T[0]).add(T[1]).add(T[2]).add(T[3]).multiplyScalar(.25);v.userData.center=R,v.vertices=T;let D=v.userData.row,H=v.userData.col,V=`row${D}_col${H}`;a.push(v),u.set(V,v),D<d&&(d=D),D>f&&(f=D),H<c&&(c=H),H>l&&(l=H)}}if(this.results.totalSegments=a.length,a.length===0)return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results;let h=`row${d}_col${c}`,g=u.get(h)||a[0];if(!g||!g.vertices||g.vertices.length<4)return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results;let x=g.vertices[0],y=g.vertices[1],m=g.vertices[3],p=new _t().subVectors(y,x).normalize(),b=new _t().subVectors(m,x).normalize(),w=g.userData.width,z=g.userData.height,M=f-d+1,P=l-c+1,E=new An;E.setFromCoplanarPoints(x,y,m);let S=new _t,I=new _t;for(let W=0;W<n.length;W+=3){let v=new _t(n[W],n[W+1],n[W+2]),T=s?s.projectPoint(v,I):v;if(Math.abs(E.distanceToPoint(T))>o)continue;S.subVectors(T,x);let D=S.dot(p),H=S.dot(b),V=Math.ceil((D-o)/w-1),C=Math.floor((D+o)/w),_=Math.ceil((H-o)/z-1),A=Math.floor((H+o)/z);if(C<0||V>P-1||A<0||_>M-1)continue;let L=Math.max(0,V),k=Math.min(P-1,C),F=Math.max(0,_),B=Math.min(M-1,A);for(let O=F;O<=B;O++){let $=d+O;for(let Z=L;Z<=k;Z++){let Q=c+Z,j=`row${$}_col${Q}`;u.has(j)&&(this.results.pointsInSegments.has(j)||this.results.pointsInSegments.set(j,[W]))}}}for(let W of a){let v=`row${W.userData.row}_col${W.userData.col}`,T=this.results.pointsInSegments.has(v)?this.results.pointsInSegments.get(v).length:0,R=T>=1,D={row:W.userData.row,col:W.userData.col,width:W.userData.width,height:W.userData.height,segmentKey:v,vertices:W.vertices,center:W.userData.center,mesh:W,pointCount:T,hasPointsButNotEnough:T>0&&T<1};R?(this.results.segmentsWithPoints++,this.results.existSegments.push(D)):(this.results.segmentsWithoutPoints++,this.results.missingSegments.push(D))}return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(e,n,o,r,s,i,a,u,d,f,c){if(Math.abs(o.distanceToPoint(e))>c)return!1;let h=new _t().subVectors(e,n),g=Math.abs(h.dot(s)),x=Math.abs(h.dot(i));if(g>d&&x>f)return!1;let y=new _t().subVectors(e,r),m=y.dot(s),p=y.dot(i),b=m>=-c&&m<=a+c,w=p>=-c&&p<=u+c;return b&&w}getWorldVerticesNew(e){return e}highlightEmptySegments(e,n=null,o=null,r=1){if(!this.results)return console.warn("\u8BF7\u5148\u8FD0\u884C\u5206\u6790\u51FD\u6570"),null;let s=new Map,i=new Map;for(let d of this.results.missingSegments)s.set(d.segmentKey,d),i.has(d.row)||i.set(d.row,new Map),i.get(d.row).set(d.col,{segmentKey:d.segmentKey,isEmpty:!0,visited:!1});for(let d of e)if(d.userData&&d.userData.type==="wallSegment"){let f=`row${d.userData.row}_col${d.userData.col}`,c=s.has(f);i.has(d.userData.row)||i.set(d.userData.row,new Map),i.get(d.userData.row).has(d.userData.col)||i.get(d.userData.row).set(d.userData.col,{segmentKey:f,isEmpty:c,visited:!1})}let a=[],u=[[0,1],[1,0],[0,-1],[-1,0]];for(let[d,f]of s){let c=i.get(f.row)?.get(f.col);if(c&&!c.visited){let l=[],h=[[f.row,f.col]],g=0;for(c.visited=!0;g<h.length;){let x=h[g++],y=x[0],m=x[1],p=`row${y}_col${m}`;s.has(p)&&l.push(s.get(p));for(let b of u){let w=y+b[0],z=m+b[1];if(i.has(w)&&i.get(w).has(z)){let M=i.get(w).get(z);!M.visited&&M.isEmpty&&(M.visited=!0,h.push([w,z]))}}}l.length>=r&&a.push(l)}}return this.clusterResults={clusters:a.sort((d,f)=>f.length-d.length),totalClusters:a.length},this.clusterResults}getClusterInfo(){if(!this.clusterResults)return null;let e=this.clusterResults.clusters.map(n=>n.length);return{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((n,o)=>({clusterIndex:o,size:n.length,segments:n.map(r=>r.segmentKey)})),largestCluster:e.length?Math.max(...e):0,smallestCluster:e.length?Math.min(...e):0}}printAnalysisResults(){if(!this.results){console.warn("\u6CA1\u6709\u53EF\u7528\u7684\u5206\u6790\u7ED3\u679C");return}}isValidVector3(e){return e&&!isNaN(e.x)&&!isNaN(e.y)&&!isNaN(e.z)&&isFinite(e.x)&&isFinite(e.y)&&isFinite(e.z)}},cr=(t,e)=>{let n={},o=[],r=[];if(!t||t.length===0)return n.originalVertices=o,n.allCenterPoints=r,n;if(e=="xyz")for(let s of t){r.push({x:s.center.x,y:s.center.y,z:s.center.z});let i=[];for(let a=0;a<s.vertices.length;a++)i.push({x:s.vertices[a].x,y:s.vertices[a].y,z:s.vertices[a].z});o.push(i)}else if(e=="three")for(let s of t){r.push(new ke.Vector3(s.center.x,s.center.y,s.center.z));let i=[];for(let a=0;a<s.vertices.length;a++)i.push(new ke.Vector3(s.vertices[a].x,s.vertices[a].y,s.vertices[a].z));o.push(i)}else if(e=="array")for(let s of t){r.push(s.center.x),r.push(s.center.y),r.push(s.center.z);let i=[];for(let a=0;a<s.vertices.length;a++)i.push(s.vertices[a].x,s.vertices[a].y,s.vertices[a].z);o.push(i)}return n.originalVertices=o,n.allCenterPoints=r,n},Pi=(t,e)=>{let n=new _t().copy(t.start).add(t.end).multiplyScalar(.5),o=new _t().subVectors(new _t(n.x,n.y,n.z+1),n).normalize(),r=new _t(t.direction.x,t.direction.y,0);r.applyAxisAngle(o,Math.PI/2);let s=new _t().copy(n).add(r.clone().multiplyScalar(t.length)),i=new _t().copy(n).sub(r.clone().multiplyScalar(t.length));if(n.z=t.start.z,s.z=t.start.z,i.z=t.start.z,e=="three")return{start:new ke.Vector3(s.x,s.y,s.z),end:new ke.Vector3(i.x,i.y,i.z),center:new ke.Vector3(n.x,n.y,n.z),direction:new ke.Vector3(r.x,r.y,r.z)};if(e=="xyz")return{start:{x:s.x,y:s.y,z:s.z},end:{x:i.x,y:i.y,z:i.z},center:{x:n.x,y:n.y,z:n.z},direction:{x:r.x,y:r.y,z:r.z}};if(e=="array")return{start:[s.x,s.y,s.z],end:[i.x,i.y,i.z],center:[n.x,n.y,n.z],direction:[r.x,r.y,r.z]}},ur=async(t,e=!0,n="three")=>{for(let o=0;o<t.length;o++){let r=t[o];await bo(r,e,n)}},bo=(t,e=!0,n="three")=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&e)return;let o=new An().setFromCoplanarPoints(new _t(t.start.x,t.start.y,t.start.z),new _t(t.end.x,t.end.y,t.end.z),new _t(t.start.x,t.start.y,t.rooftopPz)),r=new _t(t.start.x,t.start.y,t.start.z).distanceTo(new _t(t.end.x,t.end.y,t.end.z)),s=Math.abs(t.rooftopPz-t.start.z),i=new yo,{horizontalSubdivisions:a,verticalSubdivisions:u}=i.initLimits4(r,s),d=i.createSubdividedWallPlane(t,u,a,null);i.analyzePointDistribution(d,t.originalPoints,.01,{projectPlane:o});let f=i.highlightEmptySegments(d,null,null),c=[];if(f&&f.clusters)for(let g of f.clusters){let x=cr(g,n);x&&c.push(x)}let h=Pi(t,n).direction;if(t.checkResults=c,t.verticalDirection=h,t.saveExistSegments){let g=[],x=cr(i.results.existSegments,n);x&&g.push(x),t.existSegments=g}};var Vt=class t{constructor(e=0,n=0,o=0){this.x=e,this.y=n,this.z=o}set(e,n,o){return this.x=e,this.y=n,this.z=o,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}clone(){return new t(this.x,this.y,this.z)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}crossVectors(e,n){let o=e.x,r=e.y,s=e.z,i=n.x,a=n.y,u=n.z;return this.x=r*u-s*a,this.y=s*i-o*u,this.z=o*a-r*i,this}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.lengthSq())}normalize(){let e=this.length();return e>0&&(this.x/=e,this.y/=e,this.z/=e),this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let n=this.x-e.x,o=this.y-e.y,r=this.z-e.z;return n*n+o*o+r*r}toArray(){return[this.x,this.y,this.z]}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}applyAxisAngle(e,n){let o=this.x,r=this.y,s=this.z,i=e.x,a=e.y,u=e.z,d=Math.cos(n),f=Math.sin(n),c=i*o+a*r+u*s;return this.x=i*c*(1-d)+o*d+(-u*r+a*s)*f,this.y=a*c*(1-d)+r*d+(u*o-i*s)*f,this.z=u*c*(1-d)+s*d+(-a*o+i*r)*f,this}},bn=class{constructor(e=new Vt(1,0,0),n=0){this.normal=e,this.constant=n}set(e,n){return this.normal.copy(e),this.constant=n,this}setFromNormalAndCoplanarPoint(e,n){return this.normal.copy(e),this.constant=-n.dot(this.normal),this}setFromCoplanarPoints(e,n,o){let r=new Vt().subVectors(n,e),s=new Vt().subVectors(o,e),i=new Vt().crossVectors(r,s).normalize();return this.normal.copy(i),this.constant=-e.dot(this.normal),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}projectPoint(e,n=new Vt){let o=this.distanceToPoint(e);return n.copy(e),n.x-=this.normal.x*o,n.y-=this.normal.y*o,n.z-=this.normal.z*o,n}},Bn=()=>typeof performance<"u"&&performance.now?performance.now():Date.now(),Ln=class{constructor(){this.results=null,this.clusterResults=null}initLimits1(e,n){let o,r;return e<.3?o=5:e<.5?o=8:e<.8?o=10:e<1?o=15:e<2?o=30:e<3?o=35:e<4?o=40:e<5?o=45:e<6?o=50:e<7?o=60:e<8.5?o=70:e<10?o=80:e<15?o=100:e<20?o=120:e<25?o=140:e<30?o=160:e<35?o=180:e<40?o=200:e<45?o=230:e<50?o=250:o=350,n<1?r=30:n<2?r=40:n<2.5?r=45:n<3?r=60:n<3.6?r=70:r=80,{horizontalSubdivisions:o,verticalSubdivisions:r}}initLimits2(e,n){let s=Math.round(Math.max(5,Math.min(350,e/.08))),i=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:s,verticalSubdivisions:i}}initLimits3(e,n){let o;e<2?o=.06:e<10?o=.1:o=.15;let r=Math.round(Math.max(5,Math.min(350,e/o))),s=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(e,n){let o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(e)))),r=Math.round(Math.max(30,Math.min(80,20*Math.sqrt(n))));return{horizontalSubdivisions:o,verticalSubdivisions:r}}createSubdividedWallPlane(e,n,o,r=null){let s=[];if(!e||!e.start||!e.end||isNaN(e.rooftopPz))return s;let i=new Vt(e.start.x,e.start.y,e.start.z),a=new Vt(e.end.x,e.end.y,e.end.z),u=new Vt(e.end.x,e.end.y,e.rooftopPz),d=new Vt(e.start.x,e.start.y,e.rooftopPz),f=[i,a,u,d];for(let P=0;P<f.length;P++)if(!this.isValidVector3(f[P]))return console.error(`\u5899\u4F53\u57FA\u7840\u70B9${P}\u65E0\u6548:`,f[P]),s;let c=i.distanceTo(a),l=Math.abs(e.rooftopPz-e.start.z);if(c===0||l===0)return s;let h=c/o,g=l/n,x=new Vt().subVectors(a,i).normalize(),y=i.x,m=i.y,p=i.z,b=x.x,w=x.y,z=x.z,M=(P,E)=>new Vt(y+b*P,m+w*P,p+z*P+E);for(let P=0;P<n;P++){let E=P*g,S=(P+1)*g;for(let I=0;I<o;I++){let W=I*h,v=(I+1)*h;s.push({points:[M(W,E),M(v,E),M(v,S),M(W,S)],userData:{type:"wallSegment",row:P,col:I,width:h,height:g}})}}return s}analyzePointDistribution(e,n,o=.01,r={}){let s=r.projectPlane||null;this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],existSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};let i=Bn(),a=[],u=new Map,d=1/0,f=-1/0,c=1/0,l=-1/0;for(let W=0;W<e.length;W++){let v=e[W];if(v.userData&&v.userData.type==="wallSegment"){let T=this.getWorldVerticesNew(v.points);if(T.length<4)continue;let R=new Vt().add(T[0]).add(T[1]).add(T[2]).add(T[3]).multiplyScalar(.25);v.userData.center=R,v.vertices=T;let D=v.userData.row,H=v.userData.col,V=`row${D}_col${H}`;a.push(v),u.set(V,v),D<d&&(d=D),D>f&&(f=D),H<c&&(c=H),H>l&&(l=H)}}if(this.results.totalSegments=a.length,a.length===0)return this.results.analysisTime=Bn()-i,this.printAnalysisResults(),this.results;let h=`row${d}_col${c}`,g=u.get(h)||a[0];if(!g||!g.vertices||g.vertices.length<4)return this.results.analysisTime=Bn()-i,this.printAnalysisResults(),this.results;let x=g.vertices[0],y=g.vertices[1],m=g.vertices[3],p=new Vt().subVectors(y,x).normalize(),b=new Vt().subVectors(m,x).normalize(),w=g.userData.width,z=g.userData.height,M=f-d+1,P=l-c+1,E=new bn;E.setFromCoplanarPoints(x,y,m);let S=new Vt,I=new Vt;for(let W=0;W<n.length;W++){let v=n[W],T=s?s.projectPoint(v,I):v;if(Math.abs(E.distanceToPoint(T))>o)continue;S.subVectors(T,x);let D=S.dot(p),H=S.dot(b),V=Math.ceil((D-o)/w-1),C=Math.floor((D+o)/w),_=Math.ceil((H-o)/z-1),A=Math.floor((H+o)/z);if(C<0||V>P-1||A<0||_>M-1)continue;let L=Math.max(0,V),k=Math.min(P-1,C),F=Math.max(0,_),B=Math.min(M-1,A);for(let O=F;O<=B;O++){let $=d+O;for(let Z=L;Z<=k;Z++){let Q=c+Z,j=`row${$}_col${Q}`;u.has(j)&&(this.results.pointsInSegments.has(j)||this.results.pointsInSegments.set(j,[W]))}}}for(let W of a){let v=`row${W.userData.row}_col${W.userData.col}`,T=this.results.pointsInSegments.has(v)?this.results.pointsInSegments.get(v).length:0,R=T>=1,D={row:W.userData.row,col:W.userData.col,width:W.userData.width,height:W.userData.height,segmentKey:v,vertices:W.vertices,center:W.userData.center,mesh:W,pointCount:T,hasPointsButNotEnough:T>0&&T<1};R?(this.results.segmentsWithPoints++,this.results.existSegments.push(D)):(this.results.segmentsWithoutPoints++,this.results.missingSegments.push(D))}return this.results.analysisTime=Bn()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(e,n,o,r,s,i,a,u,d,f,c){if(Math.abs(o.distanceToPoint(e))>c)return!1;let h=new Vt().subVectors(e,n),g=Math.abs(h.dot(s)),x=Math.abs(h.dot(i));if(g>d&&x>f)return!1;let y=new Vt().subVectors(e,r),m=y.dot(s),p=y.dot(i),b=m>=-c&&m<=a+c,w=p>=-c&&p<=u+c;return b&&w}getWorldVerticesNew(e){return e}highlightEmptySegments(e,n=null,o=null,r=1){if(!this.results)return console.warn("\u8BF7\u5148\u8FD0\u884C\u5206\u6790\u51FD\u6570"),null;let s=new Map,i=new Map;for(let d of this.results.missingSegments)s.set(d.segmentKey,d),i.has(d.row)||i.set(d.row,new Map),i.get(d.row).set(d.col,{segmentKey:d.segmentKey,isEmpty:!0,visited:!1});for(let d of e)if(d.userData&&d.userData.type==="wallSegment"){let f=`row${d.userData.row}_col${d.userData.col}`,c=s.has(f);i.has(d.userData.row)||i.set(d.userData.row,new Map),i.get(d.userData.row).has(d.userData.col)||i.get(d.userData.row).set(d.userData.col,{segmentKey:f,isEmpty:c,visited:!1})}let a=[],u=[[0,1],[1,0],[0,-1],[-1,0]];for(let[d,f]of s){let c=i.get(f.row)?.get(f.col);if(c&&!c.visited){let l=[],h=[[f.row,f.col]],g=0;for(c.visited=!0;g<h.length;){let x=h[g++],y=x[0],m=x[1],p=`row${y}_col${m}`;s.has(p)&&l.push(s.get(p));for(let b of u){let w=y+b[0],z=m+b[1];if(i.has(w)&&i.get(w).has(z)){let M=i.get(w).get(z);!M.visited&&M.isEmpty&&(M.visited=!0,h.push([w,z]))}}}l.length>=r&&a.push(l)}}return this.clusterResults={clusters:a.sort((d,f)=>f.length-d.length),totalClusters:a.length},this.clusterResults}getClusterInfo(){if(!this.clusterResults)return null;let e=this.clusterResults.clusters.map(n=>n.length);return{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((n,o)=>({clusterIndex:o,size:n.length,segments:n.map(r=>r.segmentKey)})),largestCluster:e.length?Math.max(...e):0,smallestCluster:e.length?Math.min(...e):0}}printAnalysisResults(){if(!this.results){console.warn("\u6CA1\u6709\u53EF\u7528\u7684\u5206\u6790\u7ED3\u679C");return}}isValidVector3(e){return e&&!isNaN(e.x)&&!isNaN(e.y)&&!isNaN(e.z)&&isFinite(e.x)&&isFinite(e.y)&&isFinite(e.z)}},fr=(t,e)=>{let n={},o=[],r=[];if(!t||t.length===0)return n.originalVertices=o,n.allCenterPoints=r,n;if(e=="xyz")for(let s of t){r.push({x:s.center.x,y:s.center.y,z:s.center.z});let i=[];for(let a=0;a<s.vertices.length;a++)i.push({x:s.vertices[a].x,y:s.vertices[a].y,z:s.vertices[a].z});o.push(i)}else if(e=="three")for(let s of t){r.push(new Oe.Vector3(s.center.x,s.center.y,s.center.z));let i=[];for(let a=0;a<s.vertices.length;a++)i.push(new Oe.Vector3(s.vertices[a].x,s.vertices[a].y,s.vertices[a].z));o.push(i)}else if(e=="array")for(let s of t){r.push(s.center.x),r.push(s.center.y),r.push(s.center.z);let i=[];for(let a=0;a<s.vertices.length;a++)i.push(s.vertices[a].x,s.vertices[a].y,s.vertices[a].z);o.push(i)}return n.originalVertices=o,n.allCenterPoints=r,n},Ti=(t,e)=>{let n=new Vt().copy(t.start).add(t.end).multiplyScalar(.5),o=new Vt().subVectors(new Vt(n.x,n.y,n.z+1),n).normalize(),r=new Vt(t.direction.x,t.direction.y,0);r.applyAxisAngle(o,Math.PI/2);let s=new Vt().copy(n).add(r.clone().multiplyScalar(t.length)),i=new Vt().copy(n).sub(r.clone().multiplyScalar(t.length));if(n.z=t.start.z,s.z=t.start.z,i.z=t.start.z,e=="three")return{start:new Oe.Vector3(s.x,s.y,s.z),end:new Oe.Vector3(i.x,i.y,i.z),center:new Oe.Vector3(n.x,n.y,n.z),direction:new Oe.Vector3(r.x,r.y,r.z)};if(e=="xyz")return{start:{x:s.x,y:s.y,z:s.z},end:{x:i.x,y:i.y,z:i.z},center:{x:n.x,y:n.y,z:n.z},direction:{x:r.x,y:r.y,z:r.z}};if(e=="array")return{start:[s.x,s.y,s.z],end:[i.x,i.y,i.z],center:[n.x,n.y,n.z],direction:[r.x,r.y,r.z]}},Si=(t,e=!0,n="three",o="xyz")=>{o=="xyz"?dr(t,e,n):o=="array"&&bo(t,e,n)},Ri=(t,e=!0,n="three",o="xyz")=>{o=="xyz"?Di(t,e,n):o=="array"&&ur(t,e,n)},Di=(t,e=!0,n="three")=>{for(let o=0;o<t.length;o++){let r=t[o];dr(r,e,n)}},dr=(t,e=!0,n="three")=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&e)return;let o=new bn().setFromCoplanarPoints(new Vt(t.start.x,t.start.y,t.start.z),new Vt(t.end.x,t.end.y,t.end.z),new Vt(t.start.x,t.start.y,t.rooftopPz)),r=new Vt(t.start.x,t.start.y,t.start.z).distanceTo(new Vt(t.end.x,t.end.y,t.end.z)),s=Math.abs(t.rooftopPz-t.start.z),i=new Ln,{horizontalSubdivisions:a,verticalSubdivisions:u}=i.initLimits4(r,s),d=i.createSubdividedWallPlane(t,u,a,null);i.analyzePointDistribution(d,t.originalPoints,.01,{projectPlane:o});let f=i.highlightEmptySegments(d,null,null),c=[];if(f&&f.clusters)for(let g of f.clusters){let x=fr(g,n);x&&c.push(x)}let h=Ti(t,n).direction;if(t.checkResults=c,t.verticalDirection=h,t.saveExistSegments){let g=[],x=fr(i.results.existSegments,n);x&&g.push(x),t.existSegments=g}},vi=t=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&limit)return;let e=new bn().setFromCoplanarPoints(new Vt(t.start.x,t.start.y,t.start.z),new Vt(t.end.x,t.end.y,t.end.z),new Vt(t.start.x,t.start.y,t.rooftopPz)),n=new Vt(t.start.x,t.start.y,t.start.z).distanceTo(new Vt(t.end.x,t.end.y,t.end.z)),o=Math.abs(t.rooftopPz-t.start.z),r=new Ln,{horizontalSubdivisions:s,verticalSubdivisions:i}=r.initLimits4(n,o),a=r.createSubdividedWallPlane(t,i,s,null);return r.analyzePointDistribution(a,t.originalPoints,.01,{projectPlane:e}),r.highlightEmptySegments(a,null,null)};import*as N from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";import*as Y from"three";import{CSS2DObject as vc}from"three/examples/jsm/renderers/CSS2DRenderer.js";import"three/examples/jsm/utils/BufferGeometryUtils.js";import Ee from"path";import{fileURLToPath as Ci}from"url";import kn from"path";import{fileURLToPath as Vi}from"url";import{Vector3 as lc}from"three";var Ii=Vi(import.meta.url),wo=kn.dirname(Ii),ac=kn.resolve(wo,"./data/lines.meta.json"),cc=kn.resolve(wo,"./data/lines.bin"),uc=kn.resolve(wo,"./data/checks.bin");var Hi=Ci(import.meta.url),ve=Ee.dirname(Hi),gc=Ee.resolve(ve,"./data/lines.tmp.bin"),xc=Ee.resolve(ve,"./data/checks.tmp.bin"),yc=Ee.resolve(ve,"./data/lines.new_points.tmp.bin"),bc=Ee.resolve(ve,"./data/lines.new_points.bin"),wc=Ee.resolve(ve,"./data/lines.meta.json"),zc=Ee.resolve(ve,"./data/lines.bin"),Mc=Ee.resolve(ve,"./data/checks.bin"),Ec=Ee.resolve(ve,"./data/lines.exist_segments.bin"),Pc=Ee.resolve(ve,"./data/lines.exist_segments.tmp.bin");import{Vector3 as Wi}from"three";var On=class{points=[];_tempArr=[0,0,0];constructor(e){}initPoints(e){this.points=e}getPointByIndex(e,n){let o=e*3;return n.x=this.points[o],n.y=this.points[o+1],n.z=this.points[o+2],n}getPointArrByIndex(e){let n=e*3;return[this.points[n],this.points[n+1],this.points[n+2]]}getPoint2ArrByIndex(e){let n=e*3;return[this.points[n],this.points[n+1]]}getIndexsByIndex(e,n){n.length=0,n.push(e*3),n.push(e*3+1),n.push(e*3+2)}pointsToVector3Arr(e){let n=[];for(let o=0;o<e.length/3;o++)n.push(new Wi(e[o*3],e[o*3+1],e[o*3+2]));return n}vector3ArrToPoints(e){let n=[];for(let o=0;o<e.length;o++)n.push(e[o].x,e[o].y,e[o].z);return n}vector3ArrToFloat32Array(e){return new Float32Array(e.flatMap(o=>[o.x,o.y,o.z]))}clsoe(){this.points=[]}};var mr=(t,e,n)=>{let o=new Y.LineBasicMaterial({color:"#0011ff"}),r=[];r.push(t),r.push(e);let s=new Y.BufferGeometry;s.setFromPoints(r),s.rotateX(-Math.PI/2),n.add(new Y.Line(s,o))},Pe=(t,e,n,o,r=1e-8)=>{let s=e.x-t.x,i=e.y-t.y,a=o.x-n.x,u=o.y-n.y,d=s*u-i*a;if(Math.abs(d)<r)return null;let f=((n.x-t.x)*u-(n.y-t.y)*a)/d,c=((n.x-t.x)*i-(n.y-t.y)*s)/d;return f<-r||f>1+r||c<-r||c>1+r?null:{point:new Y.Vector3(t.x+f*s,t.y+f*i,t.z)}},pr=(t,e,n={})=>{let{fontSize:o=36,fontFamily:r="sans-serif",backgroundColor:s="rgba(0,0,0,0)",textColor:i="#ffffff",padding:a=10,maxWidth:u=256}=n,f=document.createElement("canvas").getContext("2d");f.font=`bold ${o}px ${r}`;let l=f.measureText(t).width,h=Math.min(l+a*2,u),g=o+a*2,x=document.createElement("canvas");x.width=h,x.height=g;let y=x.getContext("2d");y.fillStyle=s,y.fillRect(0,0,h,g),y.fillStyle=i,y.font=`bold ${o}px ${r}`,y.textAlign="center",y.textBaseline="middle",l>u-a*2?_i(y,t,h/2,g/2,u,o):y.fillText(t,h/2,g/2);let m=new Y.CanvasTexture(x),p=new Y.SpriteMaterial({map:m,depthTest:!1,transparent:!0}),b=new Y.Sprite(p);b.position.set(e.x,e.y,e.z);let w=.005;return b.scale.set(h*w,g*w,1),b};function _i(t,e,n,o,r,s){let i=e.split(""),a="",u=s*1.2,d=o;for(let f=0;f<i.length;f++){let c=a+i[f];t.measureText(c).width>r&&f>0?(t.fillText(a,n,d),a=i[f],d+=u):a=c}t.fillText(a,n,d)}var Xt=(t,e,n=.01)=>{let o=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(o<1e-10||r<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};let s={x:t.x/o,y:t.y/o,z:t.z/o},i={x:e.x/r,y:e.y/r,z:e.z/r},a=s.x*i.x+s.y*i.y+s.z*i.z;a=Math.max(-1,Math.min(1,a));let u=Math.acos(Math.abs(a)),d=u<=n;return{parallel:d,sameDirection:d?a>0:null,angle:u}};var gr=(t,e,n,o)=>{if(e<1e-4||n<1e-4)return{};let r=t,s=[];if(o&&o.length&&(s=o.map(M=>M.clone())),!r||r.length<4)return{};let i=new Y.Vector3().subVectors(r[1],r[0]).normalize(),a=new Y.Vector3().subVectors(r[3],r[0]).normalize(),u=i.clone().cross(a).normalize(),d=1/0,f=-1/0,c=1/0,l=-1/0;for(let M of r){let P=M.dot(i),E=M.dot(a);P<d&&(d=P),P>f&&(f=P),E<c&&(c=E),E>l&&(l=E)}let h=r[0].dot(u),g=i.clone().multiplyScalar(d).add(a.clone().multiplyScalar(c)).add(u.clone().multiplyScalar(h)),x=i.clone().multiplyScalar(f).add(a.clone().multiplyScalar(c)).add(u.clone().multiplyScalar(h)),y=i.clone().multiplyScalar(f).add(a.clone().multiplyScalar(l)).add(u.clone().multiplyScalar(h)),m=i.clone().multiplyScalar(d).add(a.clone().multiplyScalar(l)).add(u.clone().multiplyScalar(h)),p=[g,x,y,m],b=Xt(new Y.Vector3().subVectors(g,x),new Y.Vector3(0,0,1));b&&b.parallel&&(p=[g,m,y,x]);let w=0;if(o.length>0){let M=new Y.Vector3().subVectors(p[1],p[0]).normalize(),P=M.clone().negate(),E=new Y.Vector3().subVectors(p[3],p[0]).normalize(),S=E.clone().negate(),I=p[0].distanceTo(p[1]),W=p[0].distanceTo(p[3]),v=I/e,T=W/n,R=.001;for(let D=0;D<v;D++){let H=p[0],V=0;for(let C=0;C<T;C++){let _=H.clone().addScaledVector(M,e),A=_.clone().addScaledVector(E,n),L=H.clone().addScaledVector(E,n),k=new Y.Vector3().add(H).add(_).add(A).add(L).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=L}if(V>=T/2)break;w+=V,p[0]=p[0].addScaledVector(M,e),p[3]=p[3].addScaledVector(M,e)}I=p[0].distanceTo(p[1]),v=I/e;for(let D=0;D<v;D++){let H=p[1],V=0;for(let C=0;C<T;C++){let _=H.clone().addScaledVector(P,e),A=_.clone().addScaledVector(E,n),L=H.clone().addScaledVector(E,n),k=new Y.Vector3().add(H).add(_).add(A).add(L).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=L}if(V>=T/2)break;w+=V,p[1]=p[1].addScaledVector(P,e),p[2]=p[2].addScaledVector(P,e)}I=p[0].distanceTo(p[1]),v=I/e;for(let D=0;D<T;D++){let H=p[3],V=0;for(let C=0;C<v;C++){let _=H.clone().addScaledVector(M,e),A=_.clone().addScaledVector(S,n),L=H.clone().addScaledVector(S,n),k=new Y.Vector3().add(H).add(_).add(A).add(L).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=_}if(V>=v/2)break;w+=V,p[2]=p[2].addScaledVector(S,n),p[3]=p[3].addScaledVector(S,n)}}let z=p[0].distanceTo(p[1])*p[0].distanceTo(p[3]);return{facePoints:p,boxArea:z,totalInPlaneNum:w}},Zt=(t,e,n,o,r=Y.MathUtils.degToRad(8))=>{let s=new Y.Vector3,i=new Y.Vector3;s.subVectors(new Y.Vector3(e.x,e.y,0),new Y.Vector3(t.x,t.y,0)).normalize(),i.subVectors(new Y.Vector3(o.x,o.y,0),new Y.Vector3(n.x,n.y,0)).normalize();let a=s.dot(i),u=Math.acos(Math.min(Math.abs(a),1)),d=1-Math.min(u/r,1),f=a>0?"same":"opposite";return{parallelism:d,angle:u,angleDeg:Y.MathUtils.radToDeg(u),isParallel:u<r,direction:f,vectors:{v1:s,v2:i}}},ie=(t,e,n,o)=>{let r=new Y.Vector3().subVectors(e,t),s=new Y.Vector3().subVectors(o,n),i=r.length(),a=s.length();if(i===0||a===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};r.normalize(),s.normalize();let u=Math.abs(r.dot(s)),d=Math.min(1,Math.max(0,u)),f=Math.acos(d),c=Y.MathUtils.radToDeg(f),l=1-d,h=1e-6;return{rate:l,percent:`${(l*100).toFixed(2)}%`,angle:c,isPerpendicular:Math.abs(c-90)<.01,isParallel:c<.01}},At=(t,e,n=!1)=>new Y.Vector3((t.x+e.x)/2,(t.y+e.y)/2,n?0:(t.z+e.z)/2),we=(t,e,n,o,r={})=>{let{parallelAngleMax:s=Y.MathUtils.degToRad(10),collinearAngleMax:i=Y.MathUtils.degToRad(7),distanceThreshold:a=2,overlapThreshold:u=.01}=r,d=new Y.Vector3().subVectors(e,t),f=new Y.Vector3().subVectors(o,n),c=d.clone().normalize(),l=f.clone().normalize(),h=Y.MathUtils.clamp(c.dot(l),-1,1),g=Math.acos(Math.abs(h)),x=Y.MathUtils.radToDeg(g);if(g>s)return{type:"not_parallel",angleDeg:x,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};h<0&&l.negate();let y=new Y.Vector3().addVectors(c,l).normalize(),m=new Y.Vector3().addVectors(t,e).multiplyScalar(.5),p=hr(n,m,c),b=hr(o,m,c),w=(p+b)/2,z=Math.max(p,b),M=t.dot(y),P=e.dot(y),E=n.dot(y),S=o.dot(y),I=Math.min(M,P),W=Math.max(M,P),v=Math.min(E,S),T=Math.max(E,S),R=W-I,D=T-v,H=Math.min(R,D),V=Math.min(W,T)-Math.max(I,v),C=V<0?-V:0,_=V>0?V:0,A=H>0?_/H:0,L=Ai(t,e,n,o),k=g<=i&&w<a,F;return k?F=A>.5?"collinear_overlap":"collinear_gap":g<=s&&(F="parallel_offset"),{type:F,angleDeg:x,avgPerpendicularDistance:w,maxPerpendicularDistance:z,gap:C,overlap:_,closestDistance:L}};function hr(t,e,n){let o=new Y.Vector3().subVectors(t,e),r=o.dot(n),s=n.clone().multiplyScalar(r);return new Y.Vector3().subVectors(o,s).length()}function Ai(t,e,n,o){let r=new Y.Vector3().subVectors(e,t),s=new Y.Vector3().subVectors(o,n),i=new Y.Vector3().subVectors(n,t),a=r.dot(r),u=r.dot(s),d=s.dot(s),f=r.dot(i),c=s.dot(i),l=a*d-u*u,h,g;l<1e-10?(h=0,g=d!==0?c/d:0):(h=(u*c-d*f)/l,g=(a*c-u*f)/l),h=Y.MathUtils.clamp(h,0,1),g=d!==0?Y.MathUtils.clamp((u*h+c)/d,0,1):0,h=a!==0?Y.MathUtils.clamp((u*g-f)/a,0,1):0;let x=t.clone().add(r.clone().multiplyScalar(h)),y=n.clone().add(s.clone().multiplyScalar(g));return x.distanceTo(y)}var Ve=t=>{let e=999999,n=-999999,o=0;for(let r=0;r<t.length;r++)t[r].z>n&&(n=t[r].z),t[r].z<e&&(e=t[r].z),o+=t[r].z;return o=o/t.length,{minZ:e,maxZ:n,averagePz:o}},wn=(t,e,n)=>{let o=new Y.Plane,r=new Y.Vector3(t.x,t.y,t.z),s=new Y.Vector3(e.x,e.y,e.z),i=new Y.Vector3(e.x,e.y,e.z+5);o.setFromCoplanarPoints(r,s,i);let a=[],u=[];n.forEach(y=>{let m=new Y.Vector3;o.projectPoint(y,m),u.push(m.clone()),m.z=r.z,a.push(m)});let d=new Y.Vector3,f=new Y.Vector3;o.projectPoint(r,d),o.projectPoint(s,f);let c=new Y.Line3(d,f),l=[],h=[],g=[],x=new Y.Vector3;return a.forEach((y,m)=>{c.closestPointToPoint(y,!0,x).distanceTo(y)<.001?(l.push(n[m]),h.push(u[m])):g.push(y)}),{newOriginalPoints:l,newProjectPoints:g,newOnLinePoints:h}},xr=(t,e,n)=>{function o(r,s,i,a,u,d,f,c,l){let h=new Y.Line3(r,s),g=new Map,x=new Y.Vector3,y=r.clone(),m=s.clone(),p=0;for(;;){let b=new Map,w=0;for(let z=0;z<l.checkResults.length;z++)if(!(l.checkResults[z].allCenterPoints.length/c*100<1))for(let P=0;P<l.checkResults[z].allCenterPoints.length;P++){if(g.has(z)&&g.get(z).removePtsIndex.includes(P))continue;let E=l.checkResults[z].allCenterPoints[P];E=new Y.Vector3(E.x,E.y,E.z);let S=h.closestPointToPoint(E,!0,x),I=E.distanceTo(S);Math.abs(I-u)<.01&&(w++,b.has(z)?b.get(z).removePtsIndex.push(P):b.set(z,{index:z,removePtsIndex:[P]}))}if(p==f){r=y,s=m;break}if(w<d/20*19||w==0){b.clear(),f-p<5&&(r=y,s=m,g.clear());break}else{p++;for(let[z,M]of b)g.has(z)?g.get(z).removePtsIndex.push(...M.removePtsIndex):g.set(z,M);b.clear(),r=r.addScaledVector(i,a),s=s.addScaledVector(i,a),h.set(r,s)}}if(g.size>0&&p!=f)for(let[b,w]of g){let z=[],M=[];for(let P=0;P<l.checkResults[b].allCenterPoints.length;P++)w.removePtsIndex.includes(P)||(z.push(l.checkResults[b].allCenterPoints[P]),M.push(l.checkResults[b].originalVertices[P]));l.checkResults[b].allCenterPoints=z,l.checkResults[b].originalVertices=M}}for(let r=0;r<t.length;r++){let s=t[r];if(s.length<.5)continue;let i=-1,a=-1,u=e.readLineById(s.id);u.checkResults=e.getLineCheckReultsById(s.id),u.originalPoints=e.getOriginalPointsById(s.id),s.originalPoints=u.originalPoints,s.checkResults=u.checkResults,s.checkResults.allCenterPoints=[],u=null;for(let D=0;D<s.checkResults.length;D++)for(let H=0;H<s.checkResults[D].originalVertices.length;H++){let V=Fn(s.checkResults[D].originalVertices[H]);s.checkResults.allCenterPoints.push(V)}if(!s.checkResults||s.checkResults.length<=0)continue;if(s.checkResults[0].originalVertices&&s.checkResults[0].originalVertices.length>0){let D=s.checkResults[0].originalVertices[0],[H,V,C,_]=D;H=new Y.Vector3(H.x,H.y,H.z),V=new Y.Vector3(V.x,V.y,V.z),C=new Y.Vector3(C.x,C.y,C.z),_=new Y.Vector3(_.x,_.y,_.z),i=H.distanceTo(V),a=H.distanceTo(_);let A=new Y.Vector3().subVectors(H,V).normalize(),L=Xt(A,new Y.Vector3(0,0,1));L&&L.parallel&&([a,i]=[i,a])}if(i<0||a<0)continue;let d=new Y.Vector3(s.start.x,s.start.y,s.start.z),f=new Y.Vector3(s.end.x,s.end.y,s.end.z),c=d.distanceTo(f),l=s.rooftopPz-s.start.z,h=Math.ceil(c/i),g=Math.ceil(l/a),x=d.clone(),y=f.clone(),m=y.clone().add(new Y.Vector3(0,0,l)),p=x.clone().add(new Y.Vector3(0,0,l)),b=new Y.Vector3().subVectors(y,x).normalize(),w=b.clone().negate(),M=new Y.Vector3().subVectors(m,x).normalize().clone().negate(),P=i/2,E=a/2,S=c*l,I=i*a,W=S/I;o(x,p,b,i,P,g,h,W,s),o(y,m,w,i,P,g,h,W,s),s.start=x,s.end=y;let{newOriginalPoints:v}=wn(x,y,s.originalPoints);s.originalPoints=v,n.stageReplaceCheckResults(s.id,s.checkResults);let R=new On().vector3ArrToFloat32Array(s.originalPoints);n.stageReplacePoints(s.id,R),s.checkResults=null,s.originalPoints=null}n.commit()},Gt=(t,e)=>new Y.Vector3(t.x,t.y,0).distanceTo(new Y.Vector3(e.x,e.y,0)),zo=(t,e,n=1e-6)=>{let o=new Y.Vector3;return t.closestPointToPoint(e,!0,o),o.distanceTo(e)<n},yr=(t,e,n,o=1e-6)=>{let r=new Y.Line3(new Y.Vector3(t.x,t.y,t.z),new Y.Vector3(e.x,e.y,e.z)),s=new Y.Vector3;return r.closestPointToPoint(new Y.Vector3(n.x,n.y,n.z),!0,s),s.distanceTo(new Y.Vector3(n.x,n.y,n.z))<o},We=t=>{let e=0,n=[];for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o].distanceTo(t[r]);s>e&&(e=s,n=[t[o],t[r]])}return n},ct=(t,e,n=.03)=>Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n&&Math.abs(t.z-e.z)<n;var br=()=>{let t=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),e=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),n=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0");return`#${t}${e}${n}`};var Mo=(t,e=.001)=>{let n=new Map,o=[];for(let r of t){let s=Math.round(r.x/e),i=Math.round(r.y/e),a=Math.round(r.z/e),u=`${s},${i},${a}`;n.has(u)||(n.set(u,!0),o.push(r))}return o},wr=t=>{let e=t.center,n=t.halfSize,r=t.rotation.elements,s=new Y.Vector3(r[0],r[1],r[2]).multiplyScalar(n.x),i=new Y.Vector3(r[3],r[4],r[5]).multiplyScalar(n.y),a=new Y.Vector3(r[6],r[7],r[8]).multiplyScalar(n.z);function u(f,c,l){return e.clone().addScaledVector(s,f).addScaledVector(i,c).addScaledVector(a,l)}return[u(-1,-1,-1),u(1,-1,-1),u(1,1,-1),u(-1,1,-1),u(-1,-1,1),u(1,-1,1),u(1,1,1),u(-1,1,1)]},Eo=(t,e)=>{let n=t[0],o=t[1],r=t[2],s=t[3],i=new Y.Vector3().subVectors(o,n),a=new Y.Vector3().subVectors(s,n),u=i.length(),d=a.length();i.normalize(),a.normalize();let f=new Y.Vector3(0,0,1),l=new Y.Vector3().add(n).add(o).add(r).add(s).multiplyScalar(.25).clone().addScaledVector(f,e/2),h=new Y.BoxGeometry(u,d,e),g=new Y.Matrix4;return g.makeBasis(i,a,f),g.setPosition(l),h.applyMatrix4(g),h.computeVertexNormals(),h},Fn=t=>{if(!t||t.length===0)return null;let e=new Y.Vector3(0,0,0);for(let n of t)Array.isArray(n)?(e.x+=n[0],e.y+=n[1],e.z+=n[2]):(e.x+=n.x,e.y+=n.y,e.z+=n.z);return e.divideScalar(t.length),e},zr=t=>{if(!t||t.length<3)return 0;let e=Array.isArray(t[0]),n=0;for(let o=0;o<t.length;o++){let r=t[o],s=t[(o+1)%t.length];e?n+=r[0]*s[1]-s[0]*r[1]:n+=r.x*s.y-s.x*r.y}return Math.abs(n)/2};import*as Yt from"three";var Bi=(t,e)=>{console.log("lines",t);for(let n=0;n<t.length;n++){let o=t[n],r=[];o.originalPoints.forEach(b=>{let w=new Yt.Vector3(b.x,b.y,0),z=!1;for(let M=0;M<r.length;M++)if(ct(w,r[M],.01)){z=!0;break}z||r.push(w)});let s=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),i=1,a=new Yt.Vector3(o.start.x,o.start.y,o.start.z),u=new Yt.Vector3(o.end.x,o.end.y,o.end.z),d=new Yt.Vector3().subVectors(u,a).normalize(),f=d.clone().cross(new Yt.Vector3(0,0,1)).normalize(),c=f.clone().negate(),l=[],h=[],g=o.length/s;console.log(g);for(let b=0;b<s;b++){let w=[];w.push(a.clone().addScaledVector(f,i)),w.push(w[0].clone().addScaledVector(d,g)),w.push(w[1].clone().addScaledVector(c,i*2)),w.push(a.clone().addScaledVector(c,g));let z=[];for(let M=0;M<r.length;M++)l.includes(M)||ki(r[M],w)&&(l.push(M),z.push(r[M]));z.length>0&&h.push(Oi(z)),a=a.addScaledVector(d,g)}let x=new Float32Array(r.length*3);r.forEach((b,w)=>{x[w*3]=b.x,x[w*3+1]=b.y,x[w*3+2]=b.z});let y=new Yt.BufferGeometry;y.setAttribute("position",new Yt.BufferAttribute(x,3)),y.rotateX(-Math.PI/2),e.add(new Yt.Points(y,new Yt.PointsMaterial({color:br(),size:.02})));let[m,p]=ji(h,{plane:"xy",trimRatio:0});mr(m,p,e)}};function Mr(t,e="xy"){if(e==="xy")return{x:t.x,y:t.y};if(e==="xz")return{x:t.x,y:t.z};if(e==="yz")return{x:t.y,y:t.z};throw new Error(`Unsupported plane: ${e}`)}function Li(t,e,n){let o=e.x-t.x,r=e.y-t.y,s=n.x-t.x,i=n.y-t.y;return o*i-r*s}function ki(t,e,n="xy"){if(!e||e.length!==4)throw new Error("rectPoints must contain 4 points");let o=Mr(t,n),r=e.map(a=>Mr(a,n)),s=!1,i=!1;for(let a=0;a<4;a++){let u=r[a],d=r[(a+1)%4],f=Li(u,d,o);if(f>1e-9&&(s=!0),f<-1e-9&&(i=!0),s&&i)return!1}return!0}function Oi(t){if(!t||t.length===0)return null;let e=new Yt.Vector3(0,0,0);for(let n of t)Array.isArray(n)?(e.x+=n[0],e.y+=n[1],e.z+=n[2]):(e.x+=n.x,e.y+=n.y,e.z+=n.z);return e.divideScalar(t.length),e}function Fi(t){return t instanceof Yt.Vector3?t.clone():Array.isArray(t)?new Yt.Vector3(t[0],t[1],t[2]):new Yt.Vector3(t.x,t.y,t.z)}function Ni(t,e="xy"){let n=Fi(t);if(e==="xy")return{x:n.x,y:n.y,up:n.z};if(e==="xz")return{x:n.x,y:n.z,up:n.y};if(e==="yz")return{x:n.y,y:n.z,up:n.x};throw new Error(`Unsupported plane: ${e}`)}function Er(t,e,n,o="xy"){if(o==="xy")return new Yt.Vector3(t,e,n);if(o==="xz")return new Yt.Vector3(t,n,e);if(o==="yz")return new Yt.Vector3(n,t,e);throw new Error(`Unsupported plane: ${o}`)}function qi(t,e,n){if(Math.abs(e)<1e-12)return t>=n?{x:1,y:0}:{x:0,y:1};let r=t+n,s=t*n-e*e,i=Math.sqrt(Math.max(0,r*r*.25-s)),a=r*.5+i,u=e,d=a-t,f=Math.hypot(u,d);return f<1e-12?{x:1,y:0}:{x:u/f,y:d/f}}function ji(t,e={}){let{plane:n="xy",trimRatio:o=0}=e;if(!t||t.length<2)return null;let r=t.map(V=>Ni(V,n)),s=0,i=0,a=0;for(let V of r)s+=V.x,i+=V.y,a+=V.up;s/=r.length,i/=r.length,a/=r.length;let u=0,d=0,f=0;for(let V of r){let C=V.x-s,_=V.y-i;u+=C*C,d+=C*_,f+=_*_}u/=r.length,d/=r.length,f/=r.length;let c=qi(u,d,f),l={x:-c.y,y:c.x},h=[];for(let V of r){let C=V.x-s,_=V.y-i,A=C*c.x+_*c.y,L=C*l.x+_*l.y;h.push({s:A,t:L,up:V.up})}h.sort((V,C)=>V.s-C.s);let g=h.length,x=Math.floor(g*o),y=Math.ceil(g*(1-o))-1;x=Math.max(0,Math.min(g-1,x)),y=Math.max(0,Math.min(g-1,y));let m=h[x],p=h[y],b=(()=>{let V=h.map(_=>_.t).sort((_,A)=>_-A),C=Math.floor(V.length/2);return V.length%2===0?(V[C-1]+V[C])*.5:V[C]})(),w=(()=>{let V=h.map(_=>_.up).sort((_,A)=>_-A),C=Math.floor(V.length/2);return V.length%2===0?(V[C-1]+V[C])*.5:V[C]})(),z=m.s,M=p.s,P=b,E=b,S=w,I=w,W=s+c.x*z+l.x*P,v=i+c.y*z+l.y*P,T=s+c.x*M+l.x*E,R=i+c.y*M+l.y*E,D=Er(W,v,S,n),H=Er(T,R,I,n);return[D,H]}var $i=async(t,e,n,o,r)=>{if(xr(t,o,r),t.length<=0||e.length<=0)return t;n||(n=[]);for(let m of t){let p=[],b=o.readLineById(m.id);if(b.checkResults=o.getLineCheckReultsById(m.id),m.checkResults=b.checkResults,!(!m.checkResults||m.checkResults.length<=0)){for(let w=0;w<m.checkResults.length;w++){let S=function(R){for(;E[R]!==R;)E[R]=E[E[R]],R=E[R];return R},z=m.checkResults[w];if(!z.originalVertices||z.originalVertices.length==0)continue;let M=[];z.originalVertices.forEach(R=>{let D=[];R.forEach(H=>{D.push(new N.Vector3(H.x,H.y,H.z))}),M.push(D)});let P=M.length,E=Array.from({length:P},(R,D)=>D);for(let R=0;R<P;R++)for(let D=R+1;D<P;D++){let H=M[R],V=M[D];if(H.some(_=>V.some(A=>_.equals(A)))){let _=S(R),A=S(D);_!==A&&(E[_]=A)}}let I=new Map,W=-1,v=-1;for(let R=0;R<P;R++){let D=S(R);I.has(D)||I.set(D,{points:[],area:0,index:-1,gridWidth:-1,gridHeight:-1,centerPts:[],facePoints:[],boxArea:-1,totalInPlaneNum:-1});let H=I.get(D),[V,C,_,A]=M[R],L=new N.Vector3().add(V).add(C).add(_).add(A).multiplyScalar(.25);if(H.points.push(...M[R]),H.area+=V.distanceTo(C)*V.distanceTo(A),H.index=w,H.centerPts.push(L),W==-1||v==-1){let k=new N.Vector3().subVectors(V,C).normalize();v=V.distanceTo(A),W=V.distanceTo(C);let F=Xt(k,new N.Vector3(0,0,1));F&&F.parallel&&([v,W]=[W,v])}H.gridWidth=W,H.gridHeight=v}let T=I.values();for(let R of I.values()){let{facePoints:D,boxArea:H,totalInPlaneNum:V}=gr(R.points,R.gridWidth,R.gridHeight,R.centerPts);R.centerPts=null,R.facePoints=D,R.boxArea=H,R.totalInPlaneNum=V}p.push(...T)}m.checkResults=null,m.mergeCheckRegion=p}}let s=[];for(let m=0;m<n.length;m++){let p=n[m];if(p.isFindBeam=!1,p.category=="door"){let b=[];p.coordinatesByArea.coordinates.forEach(E=>{b.push(new N.Vector3(E.x,E.y,E.z))}),b[0].equals(b[b.length-1])&&b.pop();let w=b[0].distanceTo(b[1]),z=b[0].distanceTo(b[3]);z>w&&([w,z]=[z,w],b=[b[0],b[3],b[2],b[1]]);let M=At(b[0],b[3],!0),P=At(b[1],b[2],!0);s.push({doorStartPt:M,doorEndPt:P,boxPoints:b,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:m,isFind:!1,inWall:!1})}}for(let m=0;m<s.length;m++){let p=s[m];for(let b=0;b<t.length;b++){if(t[b].length<.5)continue;let w=[],z=At(t[b].start,t[b].end,!0);w.push(z),w.push(At(z,t[b].start,!0)),w.push(At(z,t[b].end,!0));let M=!1,P=p.boxPoints.length;for(let E=0;E<w.length;E++){let S=w[E].x,I=w[E].y;for(let W=0,v=P-1;W<P;v=W++){let T=p.boxPoints[W].x,R=p.boxPoints[W].y,D=p.boxPoints[v].x,H=p.boxPoints[v].y;R>I!=H>I&&S<(D-T)*(I-R)/(H-R)+T&&(M=!M)}if(M)break}if(M){let E=new N.Vector3(t[b].start.x,t[b].start.y,0),S=new N.Vector3(t[b].end.x,t[b].end.y,0),I=p.doorStartPt.distanceTo(p.doorEndPt),W=E.distanceTo(S),v=Zt(p.doorStartPt,p.doorEndPt,E,S);if(Math.abs(W-I)<.5&&v&&v.angleDeg<15){p.doorStartPt=new N.Vector3(t[b].start.x,t[b].start.y,0),p.doorEndPt=new N.Vector3(t[b].end.x,t[b].end.y,0);break}else if(Math.abs(W-I)>1.3&&v&&v.angleDeg<15){let T=we(p.doorStartPt,p.doorEndPt,E,S,{parallelAngleMax:N.MathUtils.degToRad(15)}),R=p.doorStartPt.distanceTo(E),D=p.doorStartPt.distanceTo(S),H=p.doorEndPt.distanceTo(E),V=p.doorEndPt.distanceTo(S),C=R<.2||D<.2||H<.2||V<.2;if(T&&T.type=="collinear_overlap"&&T.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let _=new N.Line3(E,S),A=_.closestPointToPoint(p.doorStartPt,!0,new N.Vector3),L=_.closestPointToPoint(p.doorEndPt,!0,new N.Vector3),k=A.distanceTo(p.doorStartPt),F=L.distanceTo(p.doorEndPt);if(k<.1||F<.1){p.inWall=!0;break}}}}else continue}}let i=0,a=[],u=[],d=[],f=[],c=.15;for(let m=0;m<t.length;m++){let p=t[m];if(p.noDetection)continue;let b=o.readLineById(p.id);if(b.originalPoints=o.getOriginalPointsById(p.id),b.checkResults=o.getLineCheckReultsById(p.id),p.originalPoints=b.originalPoints,p.checkResults=b.checkResults,b=null,p.doorAndBeamData=[],p.doorAndBeamIdToCheckResults=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0)continue;p.completePointAreaPercentage=-1;let w=new N.Box3;w.setFromPoints(p.originalPoints);let z=w.max.z,M=w.min.z,P=new N.Vector3(p.start.x,p.start.y,p.start.z),E=new N.Vector3(p.end.x,p.end.y,p.end.z),S=p.rooftopPz-p.start.z,I=0;for(let v of p.mergeCheckRegion){let T=v.facePoints,R=v.boxArea,D=v.totalInPlaneNum;if(!T||T.length<=0)continue;let H=T[0].distanceTo(T[1]),V=T[0].distanceTo(T[3]),C=v.gridHeight*(V/v.gridHeight/3*2)+v.gridHeight/2,_=new N.Vector3(T[0].x,T[0].y,T[0].z+C),A=new N.Vector3(T[1].x,T[1].y,T[1].z+C),L=new N.Line3(_,A),k=[],F=new N.Vector3;v.points.forEach(j=>{L.closestPointToPoint(j,!0,F).distanceTo(j)<v.gridHeight+.01&&k.push(j)});let B=[],O=[];for(;;){let j=[];for(let X=0;X<k.length;X++)O.includes(X)||j.length==0&&(j.push(k[X]),O.push(X));for(let X=0;X<k.length;X++)if(!O.includes(X)){for(let U=0;U<j.length;U++)if(k[X].distanceTo(j[U])<v.gridWidth+.01){j.push(k[X]),O.push(X),X=-1;break}}if(j.length==0)break;B.push(j)}let $=[];for(let j=0;j<B.length;j++){let X={lineSt:new N.Vector3,lineEd:new N.Vector3,facePoints:[]},U=We(B[j]);Array.isArray(U)&&U.length==2&&(X.lineSt=U[0],X.lineEd=U[1],X.facePoints.push(new N.Vector3(U[0].x,U[0].y,T[0].z)),X.facePoints.push(new N.Vector3(U[1].x,U[1].y,T[0].z)),X.facePoints.push(new N.Vector3(U[1].x,U[1].y,T[2].z)),X.facePoints.push(new N.Vector3(U[0].x,U[0].y,T[2].z)),$.push(X))}I+=v.area;let Z=0;if(D!=0&&(Z=v.gridHeight*v.gridWidth*D),(v.area-Z)/R*100>70&&$.length==1||$.length>1)for(let j=0;j<$.length;j++){let X=$[j],U=X.facePoints[0].distanceTo(X.facePoints[1]),at=X.facePoints[0].distanceTo(X.facePoints[3]),mt=U/p.length*100,St=p.rooftopPz-X.facePoints[2].z;if(at<1.5||z<X.facePoints[2].z||St>S/3*2)continue;let ot=!1,Mt=!1,bt=!1,Ct=new N.Vector3(0,0,0),Et=new N.Vector3(0,0,0),zt=!1,Pt=[],et=X.facePoints[2].clone(),ht=X.facePoints[3].clone(),nt=X.facePoints[0].clone(),J=X.facePoints[1].clone(),le=!1,wt=-1;if(Math.abs(X.facePoints[0].z-p.start.z)<.25){let te=!1;for(let lt=0;lt<e.length;lt++){let It=lt+1;if(It>=e.length)continue;let Ot=new N.Vector3(e[lt].x,e[lt].y,e[lt].z),Ft=new N.Vector3(e[It].x,e[It].y,e[It].z);if(Pe(new N.Vector3(Ot.x,Ot.y,0),new N.Vector3(Ft.x,Ft.y,0),new N.Vector3(X.facePoints[0].x,X.facePoints[0].y,0),new N.Vector3(X.facePoints[1].x,X.facePoints[1].y,0),.1)!=null){te=!0;break}}let{newOriginalPoints:ge}=wn(nt,J,p.originalPoints),Dt=[],ne=[];if(ge.forEach(lt=>{lt.z>=et.z?Dt.push(lt):lt.z<=nt.z&&ne.push(lt)}),Dt.length<20)continue;let xe=p.rooftopPz-et.z,tt=et.clone();tt.z+=xe;let mn=et.distanceTo(ht),Je=new N.Vector3().subVectors(ht,et).normalize(),pn=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(mn)))),gn=mn/pn,fe=[],tn=[];for(let lt=0;lt<pn;lt++)fe.push(new N.Vector3(et.x,et.y,et.z+xe/5).addScaledVector(Je,gn*lt)),fe.push(new N.Vector3(tt.x,tt.y,tt.z-xe/5).addScaledVector(Je,gn*lt));let xn=fe.length;for(let lt=0;lt<Dt.length;lt++)for(let It=0;It<fe.length;It++)if(new N.Vector3(Dt[lt].x,Dt[lt].y,Dt[lt].z).distanceTo(fe[It])<.05){tn.push(fe[It]),fe.splice(It,1);break}if(tn.length/xn<.5)continue;if(U>.17&&p.length>.5){let lt=Gt(P,nt),It=Gt(P,J),Ot=Gt(E,nt),Ft=Gt(E,J),it=.15,G=10;if(lt<it||It<it)if(Dt.length>10){let dt=new N.Vector3(p.start.x,p.start.y,0),ut=new N.Vector3(p.end.x,p.end.y,0),xt=new N.Vector3().subVectors(dt,ut).normalize(),vt=new N.Vector3,pt=1/0,Lt=-1,qt=!1,ft=!1;for(let rt=0;rt<t.length;rt++){if(rt==m)continue;let st=new N.Vector3(t[rt].start.x,t[rt].start.y,0),yt=new N.Vector3(t[rt].end.x,t[rt].end.y,0),gt=Pe(dt,ut,st,yt,.1),Rt=ie(dt,ut,st,yt);if(gt!=null){if(Rt&&Rt.angle>85){let Wt=gt.point.distanceTo(dt),Tt=gt.point.distanceTo(ut);if(Wt<.3){ft=!0,pt=1/0,Lt=-1;break}}continue}if(Rt&&Rt.angle>85){let Tt=new N.Line3(st,yt).closestPointToPoint(dt,!0,vt),kt=Zt(dt,ut,Tt,dt);if(!kt||kt.direction!="same")continue;let Ut=dt.clone().addScaledVector(xt,G),se=ut.clone().addScaledVector(xt.clone().negate(),G),$t=new N.Vector3().subVectors(yt,st).normalize(),ee=st.clone().addScaledVector($t.clone().negate(),.03),de=yt.clone().addScaledVector($t,.03),ae=Pe(Ut,se,ee,de);if(ae==null)continue;let oe=dt.distanceTo(ae.point);oe<pt&&(pt=oe,Lt=rt)}else if(Rt&&Rt.angle<5){let Wt=new N.Vector3(nt.x,nt.y,0),Tt=new N.Vector3(J.x,J.y,0),kt=Gt(Wt,st),Ut=Gt(Wt,yt),se=Gt(Tt,st),$t=Gt(Tt,yt),ee=Zt(dt,ut,st,Wt),de=!1,ae=o.readLineById(t[rt].id);if(ae.checkResults=o.getLineCheckReultsById(t[rt].id),t[rt].checkResults=ae.checkResults,ae=null,t[rt].checkResults){for(let oe=0;oe<t[rt].checkResults.length;oe++){let yn=[];for(let be=0;be<t[rt].checkResults[oe].originalVertices.length;be++){let De=Fn(t[rt].checkResults[oe].originalVertices[be]);De.z=0,yn.push(De)}let ye=We(yn);if(ye.length==2){let be=Gt(Wt,ye[0]),De=Gt(Wt,ye[1]),go=Gt(Tt,ye[0]),xo=Gt(Tt,ye[1]);if(be<.2||De<.2||go<.2||xo<.2){de=!0;break}}}t[rt].checkResults=null}if(ee&&ee.direction=="same"&&!de&&(kt<.1||Ut<.1||se<.1||$t<.1)){qt=!0,pt=1/0,Lt=-1;break}}}if(pt!=1/0&&pt<2&&(p.length-U>.2||p.length-U<.02)&&pt<U*2)t[Lt].length>.25&&U+pt>.5&&(le=!0,lt<it?(ht=ht.addScaledVector(xt,pt),nt=nt.addScaledVector(xt,pt)):(et=et.addScaledVector(xt,pt),J=J.addScaledVector(xt,pt)));else{if(!qt&&!ft&&p.length-U>.1)continue;if(!qt&&!ft&&p.length-U<.1&&p.length<1.8)continue}}else continue;if(Ot<it||Ft<it)if(Dt.length>10){let dt=new N.Vector3(p.start.x,p.start.y,0),ut=new N.Vector3(p.end.x,p.end.y,0),xt=new N.Vector3().subVectors(ut,dt).normalize(),vt=new N.Vector3,pt=1/0,Lt=-1,qt=!1,ft=!1;for(let rt=0;rt<t.length;rt++){if(rt==m)continue;let st=new N.Vector3(t[rt].start.x,t[rt].start.y,0),yt=new N.Vector3(t[rt].end.x,t[rt].end.y,0),gt=Pe(dt,ut,st,yt,.03),Rt=ie(dt,ut,st,yt);if(gt!=null){if(Rt&&Rt.angle>85){let Wt=gt.point.distanceTo(dt);if(gt.point.distanceTo(ut)<.3){ft=!0,pt=1/0,Lt=-1;break}}continue}if(Rt&&Rt.angle>85){let Tt=new N.Line3(st,yt).closestPointToPoint(ut,!0,vt),kt=Zt(ut,dt,Tt,ut);if(!kt||kt.direction!="same")continue;let Ut=dt.clone().addScaledVector(xt.clone().negate(),G),se=ut.clone().addScaledVector(xt,G),$t=new N.Vector3().subVectors(yt,st).normalize(),ee=st.clone().addScaledVector($t.clone().negate(),.03),de=yt.clone().addScaledVector($t,.03),ae=Pe(Ut,se,ee,de);if(ae==null)continue;let oe=ut.distanceTo(ae.point);oe<pt&&(pt=oe,Lt=rt)}else if(Rt&&Rt.angle<5){let Wt=new N.Vector3(nt.x,nt.y,0),Tt=new N.Vector3(J.x,J.y,0),kt=Gt(Wt,st),Ut=Gt(Wt,yt),se=Gt(Tt,st),$t=Gt(Tt,yt),ee=Zt(ut,dt,st,Wt),de=!1,ae=o.readLineById(t[rt].id);if(ae.checkResults=o.getLineCheckReultsById(t[rt].id),t[rt].checkResults=ae.checkResults,ae=null,t[rt].checkResults){for(let oe=0;oe<t[rt].checkResults.length;oe++){let yn=[];for(let be=0;be<t[rt].checkResults[oe].originalVertices.length;be++){let De=Fn(t[rt].checkResults[oe].originalVertices[be]);De.z=0,yn.push(De)}let ye=We(yn);if(ye.length==2){let be=Gt(Wt,ye[0]),De=Gt(Wt,ye[1]),go=Gt(Tt,ye[0]),xo=Gt(Tt,ye[1]);if(be<.2||De<.2||go<.2||xo<.2){de=!0;break}}}t[rt].checkResults=null}if(ee&&ee.direction=="same"&&!de&&(kt<.1||Ut<.1||se<.1||$t<.1)){qt=!0,pt=1/0,Lt=-1;break}}}if(pt!=1/0&&pt<2&&(p.length-U>.2||p.length-U<.02)&&pt<U*2)t[Lt].length>.25&&U+pt>.5&&(le=!0,Ot<it?(ht=ht.addScaledVector(xt,pt),nt=nt.addScaledVector(xt,pt)):(et=et.addScaledVector(xt,pt),J=J.addScaledVector(xt,pt)));else{if(!qt&&!ft&&p.length-U>.1)continue;if(!qt&&!ft&&p.length-U<.1&&p.length<1.8)continue}}else continue;U=ht.distanceTo(et)}if(mt<85&&U>.3||U>.7&&at>S-S/2){if(!p.isLine2){if(U<3.5)for(let lt=0;lt<s.length;lt++){let It=new N.Vector3(s[lt].doorStartPt.x,s[lt].doorStartPt.y,0),Ot=new N.Vector3(s[lt].doorEndPt.x,s[lt].doorEndPt.y,0),Ft=new N.Vector3(X.facePoints[0].x,X.facePoints[0].y,0),it=new N.Vector3(X.facePoints[1].x,X.facePoints[1].y,0),G=X.facePoints[2].z<s[lt].maxZ||Math.abs(X.facePoints[2].z-s[lt].maxZ)<.3,dt=Math.abs(X.facePoints[2].z-s[lt].maxZ)>.2;if(G){let ut=we(It.clone(),Ot.clone(),Ft.clone(),it.clone(),{distanceThreshold:2});if(ut&&ut.type=="collinear_gap"){let xt=At(It,Ot),vt=new N.Line3(new N.Vector3(p.start.x,p.start.y,0),new N.Vector3(p.end.x,p.end.y,0)),pt=new N.Vector3,Lt=vt.closestPointToPoint(xt,!0,pt);if(xt.distanceTo(Lt)<.15){let ft=Ft.distanceTo(It),rt=it.distanceTo(It);if(ft>.25&&rt>.25){let gt=Ft.distanceTo(Ot),Rt=it.distanceTo(Ot);if(gt>.2&&Rt>.2)continue}Mt=!0,zt=!0,Pt.push(s[lt].index),s[lt].isFind=!0,wt=lt,bt=n[s[lt].index].isFindBeam,n[s[lt].index].isFindBeam=!0;let st=new N.Vector3().subVectors(Ft,it).normalize(),yt=It.distanceTo(Ot)-ut.overlap;rt<ft&&st.negate(),ft>rt?(et=X.facePoints[2].clone().addScaledVector(st,yt),ht=X.facePoints[3].clone(),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z):(et=X.facePoints[2].clone(),ht=X.facePoints[3].clone().addScaledVector(st,yt),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z)}}else if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.35){let xt=Ft.distanceTo(it),vt=Ot.distanceTo(It);if(Math.abs(xt-ut.overlap)<.25||Math.abs(vt-ut.overlap)<.25){if(vt>xt&&Math.abs(vt-ut.overlap)>1){let pt=Ft.distanceTo(It),Lt=Ft.distanceTo(Ot),qt=it.distanceTo(It),ft=it.distanceTo(Ot),rt=pt<Lt?pt:Lt,st=qt<ft?qt:ft,yt=new N.Vector3().subVectors(Ft,it).normalize(),gt=vt-ut.overlap;rt<st?(yt.negate(),et=X.facePoints[2].clone().addScaledVector(yt,gt),ht=X.facePoints[3].clone(),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z):(et=X.facePoints[2].clone(),ht=X.facePoints[3].clone().addScaledVector(yt,gt),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z)}U>1.5&&(Mt=!0,zt=!0,Pt.push(s[lt].index),s[lt].isFind=!0,bt=n[s[lt].index].isFindBeam,n[s[lt].index].isFindBeam=!0,wt=lt)}}}}if(!zt&&U<1.5)for(let lt=0;lt<s.length;lt++){if(s[lt].inWall)continue;let It=new N.Vector3(s[lt].doorStartPt.x,s[lt].doorStartPt.y,0),Ot=new N.Vector3(s[lt].doorEndPt.x,s[lt].doorEndPt.y,0),Ft=new N.Vector3(ht.x,ht.y,0),it=new N.Vector3(et.x,et.y,0),G=new N.Vector3().subVectors(It,Ot).normalize(),dt=new N.Vector3().subVectors(Ft,it).normalize(),ut=.25,xt=It.clone().addScaledVector(G,ut),vt=Ot.clone().addScaledVector(G.clone().negate(),ut),pt=Ft.clone().addScaledVector(dt,ut),Lt=it.clone().addScaledVector(dt.clone().negate(),ut);if(Zt(xt,vt,pt,Lt).isParallel)continue;let ft=Pe(xt,vt,pt,Lt),rt=!0,st=It.distanceTo(Ft),yt=It.distanceTo(it),gt=Ot.distanceTo(Ft),Rt=Ot.distanceTo(it);if((st<c||yt<c||gt<c||Rt<c||ft)&&rt){let Tt=new N.Line3(Ft,it);if(st<c||gt<c)if(Ct=Ft.clone(),st<c){let kt=Tt.closestPointToPoint(Ot,!1,new N.Vector3);Et=new N.Vector3().subVectors(Ot,kt).normalize()}else{let kt=Tt.closestPointToPoint(It,!1,new N.Vector3);Et=new N.Vector3().subVectors(It,kt).normalize()}else if(yt<c||Rt<c)if(Ct=it.clone(),yt<c){let kt=Tt.closestPointToPoint(Ot,!1,new N.Vector3);Et=new N.Vector3().subVectors(Ot,kt).normalize()}else{let kt=Tt.closestPointToPoint(It,!1,new N.Vector3);Et=new N.Vector3().subVectors(It,kt).normalize()}else if(ft){let kt=ft.point.distanceTo(Ft),Ut=ft.point.distanceTo(it),se=ft.point.distanceTo(xt),$t=ft.point.distanceTo(vt);if(kt<Ut?Ct=Ft.clone():Ct=it.clone(),se<$t){let ee=Tt.closestPointToPoint(vt,!1,new N.Vector3);Et=new N.Vector3().subVectors(vt,ee).normalize()}else{let ee=Tt.closestPointToPoint(xt,!1,new N.Vector3);Et=new N.Vector3().subVectors(xt,ee).normalize()}}bt=n[s[lt].index].isFindBeam,n[s[lt].index].isFindBeam=!0,Mt=!0,s[lt].isFind=!0,wt=lt}}}(Mt||te||Math.abs(at-S)>.1&&at>S/3&&U>.3)&&(ot=!0)}}if(ot){{let it=new N.Vector3().subVectors(nt,J),G=new N.Vector3().subVectors(J,nt),dt=1/0,ut=1/0,xt=nt.clone(),vt=J.clone(),pt=[],Lt=[],qt=new N.Line3(et,ht),ft=new N.Vector3,rt=999999;if(p.originalPoints.forEach(st=>{if(st.z-nt.z<at/2+.1&&st.z-nt.z>at/2-.1&&pt.push(st),st.z>et.z){let yt=qt.closestPointToPoint(st,!0,ft),gt=new N.Vector3().subVectors(yt,et),Rt=new N.Vector3().subVectors(yt,ht),Wt=Xt(it,Rt),Tt=Xt(G,gt);Wt&&Wt.parallel&&!Wt.sameDirection&&Tt&&Tt.parallel&&!Tt.sameDirection&&Lt.push(st)}}),pt.length>0){let{newProjectPoints:st}=wn(nt,J,pt);for(let yt of st)yt.z=nt.z;st.forEach(yt=>{let gt=new N.Vector3(yt.x,yt.y,nt.z),Rt=new N.Vector3().subVectors(gt,J),Wt=new N.Vector3().subVectors(gt,nt),Tt=Xt(it,Wt),kt=Xt(G,Rt);if(Tt&&Tt.parallel&&Tt.sameDirection){let Ut=gt.distanceTo(nt);Ut<dt&&(dt=Ut,xt=gt)}else if(kt&&kt.parallel&&kt.sameDirection){let Ut=gt.distanceTo(J);Ut<ut&&(ut=Ut,vt=gt)}})}if(xt.equals(nt)||(nt=xt,ht=new N.Vector3(nt.x,nt.y,ht.z)),vt.equals(J)||(J=vt,et=new N.Vector3(J.x,J.y,et.z)),Lt.length>10){let{newOnLinePoints:st}=wn(ht,et,Lt);for(let yt=0;yt<st.length;yt++){let Rt=qt.closestPointToPoint(st[yt],!0,ft).distanceTo(st[yt]);Rt>.02&&rt>Rt&&(rt=Rt)}et.z+=rt,ht.z+=rt,at+=rt}}let te=!1;for(let it=0;it<d.length;it++){let G=we(d[it].start,d[it].end,nt,J);G&&G.type=="collinear_overlap"&&G.maxPerpendicularDistance<.07&&(te=!0)}if(te){wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1));continue}let ge=J.distanceTo(nt);if(ge<.4&&!Mt||ge<.3&&Mt)continue;u.includes(m)||u.push(m);let Dt="",ne=Mt?"singleDoor":"";ne=zt?"pullOutDoor":ne;let xe=nt.z-p.start.z>1e-4?nt.z-p.start.z:0,tt={id:i,beamStart:et,beamEnd:ht,beamHeight:p.rooftopPz-et.z,doorStart:nt,doorEnd:J,doorHeight:at,nearId:-1,type:Dt,isExtend:le,isDoor:Mt,isPullOutDoor:zt,pcbDoorIndexs:Pt,beamNearWallVec:new N.Vector3(0,0,0),doorType:ne,doorOpenEndPoint:Ct,doorOpenVector:Et,lineIsOnlyBeam:!1,groundClearance:xe};if(tt.beamHeight<.1)continue;let mn=1/0,Je=!1,pn=new N.Vector3,gn=new N.Vector3,fe=-1,tn=-1,xn=-1,en=!1,lt=!1;{let it=new N.Line3(nt.clone(),J.clone()),G=-1;for(let dt=0;dt<t.length;dt++){if(t[dt].length<.5||dt==m)continue;let ut=new N.Vector3(t[dt].start.x,t[dt].start.y,t[dt].start.z),xt=new N.Vector3(t[dt].end.x,t[dt].end.y,t[dt].end.z),vt=we(ut,xt,nt,J),pt=Zt(ut,xt,nt,J);if(vt&&vt.maxPerpendicularDistance<.5){if(pt&&pt.isParallel){let gt=new N.Line3(ut,xt),Rt=new N.Vector3(nt.x,nt.y,ut.z),Wt=gt.closestPointToPoint(Rt,!0,new N.Vector3),Tt=ie(Wt,Rt,nt,J);Tt&&Tt.angle>85&&(tt.beamNearWallVec=new N.Vector3().subVectors(Wt,Rt).normalize(),tt.beamStart.z>t[dt].rooftopPz-.03&&U>1?lt=!0:lt=!1)}let Lt=[],qt=o.readLineById(t[dt].id);qt.originalPoints=o.getOriginalPointsById(t[dt].id),t[dt].originalPoints=qt.originalPoints,qt=null,t[dt].originalPoints.forEach(gt=>{gt.z>nt.z+.2&&gt.z<nt.z+at/2&&Lt.push(new N.Vector3(gt.x,gt.y,nt.z))}),t[dt].originalPoints=null;let ft=new N.Vector3,rt=[],st=[];for(let gt=0;gt<Lt.length;gt++){let Rt=it.closestPointToPoint(Lt[gt],!0,ft);Rt.distanceTo(Lt[gt])<.15&&(rt.push(Lt[gt]),st.push(Rt.clone()))}for(let gt=0;gt<st.length;gt++)zo(it,st[gt])&&rt.push(st[gt]);if(rt=st,rt=Mo(rt),rt.length<150)continue;let yt=We(rt);if(yt.length==2){let gt=yt[0].distanceTo(yt[1]);if(Math.abs(gt-it.distance())<.3){G=vt.maxPerpendicularDistance;let Rt=new N.Line3(ut,xt),Wt=new N.Vector3(nt.x,nt.y,ut.z),Tt=Rt.closestPointToPoint(Wt,!0,new N.Vector3);if(tt.beamNearWallVec=new N.Vector3().subVectors(Tt,Wt).normalize(),tt.beamStart.z>t[dt].rooftopPz-.03&&U>.8)lt=!0,en=!0;else if(te=!0,wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1)),tn!=-1&&xn!=-1){let kt=t[tn].doorAndBeamData[xn];kt.nearId=-1}break}}if(te)break}else vt&&vt.type=="collinear_overlap"&&vt.maxPerpendicularDistance>.3&&vt.maxPerpendicularDistance<.7&&(en=!0)}if(te){if(U<1.5||G<.08)continue;en=!0}}let It=!1;if(fe!=-1)for(let it=0;it<f.length&&!(f[it].length==1&&(f[it][0].id==i?(f[it].push({id:fe,beamStart:pn,beamEnd:gn}),It=!0):f[it][0].id==fe&&(f[it].push({id:i,beamStart:et,beamEnd:ht}),It=!0),It));it++);It||f.push([{id:i,beamStart:et,beamEnd:ht}]);let Ot=tt.doorStart.distanceTo(tt.doorEnd),Ft=Ve(p.originalPoints);if(tt.lineIsOnlyBeam=Ft.minZ>p.start.z&&Ft.minZ-p.start.z>1,Mt&&en){wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1));continue}if(Mt?Dt="door":Ot>1.5||le?Dt="beam":Dt=en&&Ot>.8?"beam":"hole",Dt!="beam"&&t[m].isLine2)continue;tt.type=Dt,tt.wallBelowBeam=lt;for(let it=0;it<a.length;it++){let G=t[a[it].linesIndex].doorAndBeamData[a[it].doorIndex];if(G.nearId!=-1||tt.type=="beam"&&G.type!="beam"||tt.type!="beam"&&G.type=="beam")continue;let dt=Zt(et.clone(),ht.clone(),G.beamStart.clone(),G.beamEnd.clone());if(dt&&dt.isParallel){let ut=et.distanceTo(ht),xt=G.beamStart.distanceTo(G.beamEnd),vt=new N.Line3(et.clone(),ht.clone());vt.start.z=0,vt.end.z=0;let pt=At(G.beamStart,G.beamEnd,!0);xt>ut&&(vt.start=new N.Vector3(G.beamStart.x,G.beamStart.y,0),vt.end=new N.Vector3(G.beamEnd.x,G.beamEnd.y,0),pt=At(et,ht,!0));let Lt=new N.Vector3,qt=vt.closestPointToPoint(pt,!0,Lt),ft=qt.distanceTo(pt),rt=new N.Vector3().subVectors(pt,qt).normalize(),st=rt.clone().negate(),yt=pt.clone().addScaledVector(st,ft+.1),gt=Pe(vt.start,vt.end,pt,yt),Rt=!Mt&&!G.isDoor&&(ut>xt*2||xt>ut*2);if(ft<.4&&gt!=null&&!Rt){let Wt=!1;for(let $t=0;$t<p.doorAndBeamData.length;$t++)if(p.doorAndBeamData[$t].id==G.id){Wt=!0;break}if(Wt)continue;G.nearId=i,tt.nearId=G.id;let Tt=.8;(G.isDoor||tt.isDoor)&&(G.isDoor=!0,tt.isDoor=!0),G.doorType!=""?tt.doorType=G.doorType:tt.doorType!=""&&(G.doorType=tt.doorType),G.isPullOutDoor?tt.isPullOutDoor=!0:tt.isPullOutDoor&&(G.isPullOutDoor=!0);let kt=Pt.some($t=>G.pcbDoorIndexs.includes($t)),Ut=!1,se=!1;if(tt.type=="beam"&&G.type=="beam"){let $t=o.readLineById(t[a[it].linesIndex].id);$t.originalPoints=o.getOriginalPointsById(t[a[it].linesIndex].id),t[a[it].linesIndex].originalPoints=$t.originalPoints,$t=null;let ee=Ve(t[a[it].linesIndex].originalPoints),de=Ve(p.originalPoints);t[a[it].linesIndex].originalPoints=null,ee.minZ>t[a[it].linesIndex].start.z&&ee.minZ-t[a[it].linesIndex].start.z>1&&de.minZ>p.start.z&&de.minZ-p.start.z>1&&(Ut=ut>xt,se=ut<xt,xt>ut&&(tt.isExtend=!0),ut>xt&&(t[a[it].linesIndex].isExtend=!0))}ut<xt&&!se||Ut?(Ut&&(st=st.negate(),rt=rt.negate()),ut>Tt&&!G.isPullOutDoor?(G.beamStart=et.clone().addScaledVector(st,ft),G.beamEnd=ht.clone().addScaledVector(st,ft),G.doorStart=nt.clone().addScaledVector(st,ft),G.doorEnd=J.clone().addScaledVector(st,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone()):!zt||zt&&G.isPullOutDoor&&kt?(tt.beamStart=G.beamStart.clone().addScaledVector(rt,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(rt,ft),tt.doorStart=G.doorStart.clone().addScaledVector(rt,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(rt,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone()):(G.beamStart=et.clone().addScaledVector(st,ft),G.beamEnd=ht.clone().addScaledVector(st,ft),G.doorStart=nt.clone().addScaledVector(st,ft),G.doorEnd=J.clone().addScaledVector(st,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone())):(ut>xt&&!Ut||se)&&(se&&(st=st.negate(),rt=rt.negate()),xt>Tt&&!zt?(tt.beamStart=G.beamStart.clone().addScaledVector(st,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(st,ft),tt.doorStart=G.doorStart.clone().addScaledVector(st,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(st,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone()):!G.isPullOutDoor||zt&&G.isPullOutDoor&&kt?(G.beamStart=et.clone().addScaledVector(rt,ft),G.beamEnd=ht.clone().addScaledVector(rt,ft),G.doorStart=nt.clone().addScaledVector(rt,ft),G.doorEnd=J.clone().addScaledVector(rt,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone()):(tt.beamStart=G.beamStart.clone().addScaledVector(st,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(st,ft),tt.doorStart=G.doorStart.clone().addScaledVector(st,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(st,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone())),fe=tt.nearId,pn=G.beamStart.clone(),gn=G.beamEnd.clone(),Je=!0,tn=a[it].linesIndex,xn=a[it].doorIndex;break}}}if(tt.nearId!=-1&&Dt=="hole"){let it=!1;for(let G=0;G<t.length;G++)if(t[G].doorAndBeamData){for(let dt=0;dt<t[G].doorAndBeamData.length;dt++)if(t[G].doorAndBeamData[dt].nearId==i&&t[G].doorAndBeamData[dt].type=="beam"){t[G].doorAndBeamData[dt].type=Dt,it=!0;break}if(it)break}}if(p.doorAndBeamIdToCheckResults.push([v.index,i]),p.doorAndBeamData.push(tt),a.push({linesIndex:m,doorIndex:p.doorAndBeamData.length-1}),d.push({start:nt,end:J}),i++,zt&&U<2)break}}}let W=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=I/W*100,p.checkResults=null,p.originalPoints=null,p.mergeCheckRegion=null}if(u.length>1)for(let m=0;m<u.length;m++){let p=[];for(let b=0;b<t[u[m]].doorAndBeamData.length;b++){let w=!1;if(t[u[m]].doorAndBeamData[b].type==="beam"&&(t[u[m]].doorAndBeamData[b].beamNearWallVec.x==0&&t[u[m]].doorAndBeamData[b].beamNearWallVec.y==0&&t[u[m]].doorAndBeamData[b].beamNearWallVec.z==0&&t[u[m]].doorAndBeamData[b].nearId==-1||!t[u[m]].doorAndBeamData[b].wallBelowBeam&&t[u[m]].doorAndBeamData[b].nearId==-1)&&(t[u[m]].doorAndBeamData[b].lineIsOnlyBeam?w=!0:t[u[m]].doorAndBeamData[b].type="hole"),!w){let z=t[u[m]].doorAndBeamData[b].doorStart.clone(),M=t[u[m]].doorAndBeamData[b].doorEnd.clone();z.z=M.z=0;let P=z.distanceTo(M);for(let E=0;E<u.length;E++)if(m!=E)for(let S=0;S<t[u[E]].doorAndBeamData.length;S++){let I=t[u[E]].doorAndBeamData[S].doorStart.clone(),W=t[u[E]].doorAndBeamData[S].doorEnd.clone();I.z=W.z=0;let v=I.distanceTo(W),T=we(z,M,I,W);if(T.type=="collinear_overlap"&&T.maxPerpendicularDistance<.2){let R=new N.Line3(I,W),D=At(z,M),H=R.closestPointToPoint(D,!0,new N.Vector3),V=D.distanceTo(H);if(Math.abs(P-T.overlap)<.1&&V<.04){t[u[E]].doorAndBeamData[S].nearId==t[u[m]].doorAndBeamData[b].id&&(t[u[E]].doorAndBeamData[S].nearId=-1),w=!0;break}}}}if(w){for(let z=0;z<t[u[m]].doorAndBeamIdToCheckResults.length;z++)if(t[u[m]].doorAndBeamIdToCheckResults[1]==t[u[m]].doorAndBeamData[b].id){t[u[m]].doorAndBeamIdToCheckResults.splice(z,1);break}}w||p.push(t[u[m]].doorAndBeamData[b])}p.length!=t[u[m]].doorAndBeamData.length&&(t[u[m]].doorAndBeamData=p)}let l=.65,h=2,g=[],x=[];for(let m=0;m<s.length;m++){if(s[m].isFind||s[m].inWall)continue;let p=new N.Vector3(s[m].doorStartPt.x,s[m].doorStartPt.y,0),b=new N.Vector3(s[m].doorEndPt.x,s[m].doorEndPt.y,0),w=new N.Vector3().subVectors(p,b).normalize();for(let z=0;z<t.length;z++){if(t[z].length<.7||t[z].completePointAreaPercentage>60)continue;let M=new N.Vector3(t[z].start.x,t[z].start.y,0),P=new N.Vector3(t[z].end.x,t[z].end.y,0),E=new N.Vector3().subVectors(M,P).normalize(),S=.3,I=p.clone().addScaledVector(w,S),W=b.clone().addScaledVector(w.clone().negate(),S),v=M.clone().addScaledVector(E,S),T=P.clone().addScaledVector(E.clone().negate(),S),R=Pe(I,W,v,T),D=Zt(I,W,v,T),H=p.distanceTo(M)>b.distanceTo(M)?b:p,V=H.distanceTo(M),C=H.distanceTo(P);if((V<c||C<c)&&D&&!D.isParallel){let A=p.distanceTo(M),L=p.distanceTo(P),k=A<L?M:P,F=!1;for(let B=0;B<t.length;B++){if(B==z||g.includes(B)||t[B].length<.7)continue;let O=new N.Vector3(t[B].start.x,t[B].start.y,0),$=new N.Vector3(t[B].end.x,t[B].end.y,0),Z=new N.Vector3().subVectors(O,$).normalize(),Q=Z.clone().negate(),j=O.clone().addScaledVector(Z,5),X=$.clone().addScaledVector(Q,5),U=ie(M,P,O,$),at=we(M,P,O,$),mt=Pe(M,P,j,X),St=!0;if(mt!=null&&(St=mt.point.distanceTo(M)<c||mt.point.distanceTo(P)<c),(U&&U.angle>85||at&&at.type=="collinear_gap")&&St){let ot=new N.Line3(M,P),Mt=new N.Vector3,bt=ot.closestPointToPoint(O,!0,Mt),Ct=ot.closestPointToPoint($,!0,Mt),Et=bt.distanceTo(O),zt=Ct.distanceTo($),Pt,et;if(Et>zt&&zt>l)Pt=$,et=Ct;else if(Et<zt&&Et>l)Pt=O,et=bt;else continue;if(Et=k.distanceTo(O),zt=k.distanceTo($),Et>h&&zt>h)continue;let ht=Zt(Pt,et,O,$),nt=Zt(Pt,et,I,W);if(nt&&nt.isParallel||!ht||!ht.isParallel)continue;let J=we(p,b,Pt,et);if(J&&J.type=="collinear_overlap"&&J.maxPerpendicularDistance<.2)continue;Pt.z=et.z=t[B].start.z;let le=!1;for(let Dt=0;Dt<x.length;Dt++){let ne=we(x[Dt].start,x[Dt].end,Pt,et);if(ne&&ne.type=="collinear_overlap"&&ne.maxPerpendicularDistance<.2){le=!0;break}}if(le)continue;for(let Dt=0;Dt<t.length;Dt++){if(t[Dt].length<.5)continue;let ne=new N.Vector3(t[Dt].start.x,t[Dt].start.y,t[Dt].start.z),xe=new N.Vector3(t[Dt].end.x,t[Dt].end.y,t[Dt].end.z),tt=we(ne,xe,Pt,et);if(tt&&tt.type=="collinear_overlap"&&tt.maxPerpendicularDistance<.1){le=!0;break}}if(le)continue;x.push({start:Pt,end:et}),g.push(B);let wt=t[B].rooftopPz-t[B].start.z,te=t[z].rooftopPz-t[z].start.z,ge=wt<te?wt:te;t[B].doorAndBeamData||(t[B].doorAndBeamData=[]),t[B].doorAndBeamData.push({id:i,beamStart:Pt,beamEnd:et,beamHeight:ge,doorStart:Pt,doorEnd:et,doorHeight:ge,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new N.Vector3(0,0,0),groundClearance:0}),n[s[m].index].isFindBeam=!0,n[s[m].index].isFindOnlyDoor=!0,f.push([{id:i,beamStart:Pt,beamEnd:et}]),i++,F=!0;break}}if(F)break}}}let y=[];for(let m=0;m<t.length;m++)t[m].isLine2||y.push(t[m]),t[m].isLine2&&t[m].doorAndBeamData.length!=0&&y.push(t[m]);return t.length=0,t.push(...y),{lines:t,beamGroup:f,pcdData:n}},Xi=async(t,e)=>{for(let n=0;n<t.length;n++){let o=t[n],r=new N.Vector3(o.start.x,o.start.y,o.start.z),s=new N.Vector3(o.end.x,o.end.y,o.end.z),i=new N.Line3(r.clone(),s.clone()),a=-1;for(let u=0;u<o.doorAndBeamData.length;u++){let d=o.doorAndBeamData[u],f=d.doorHeight;d.isRebuild=!1;let c=!1,l=!1;if(!(d.nearId!=-1||d.type!="beam")){for(let h=0;h<t.length;h++){if(t[h].length<.5||h==n)continue;let g=new N.Vector3(t[h].start.x,t[h].start.y,t[h].start.z),x=new N.Vector3(t[h].end.x,t[h].end.y,t[h].end.z),y=we(g,x,r,s),m=Zt(g,x,r,s);if(y&&y.maxPerpendicularDistance<.5){if(m&&m.isParallel){let E=new N.Line3(g,x),S=new N.Vector3(r.x,r.y,g.z),I=E.closestPointToPoint(S,!0,new N.Vector3),W=ie(I,S,r,s);W&&W.angle>85&&(d.beamNearWallVec=new N.Vector3().subVectors(I,S).normalize())}let p=[],b=e.readLineById(t[h].id);b.originalPoints=e.getOriginalPointsById(t[h].id),t[h].originalPoints=b.originalPoints,b=null,t[h].originalPoints.forEach(E=>{E.z>r.z+.2&&E.z<r.z+f/2&&p.push(new N.Vector3(E.x,E.y,r.z))}),t[h].originalPoints=null;let w=new N.Vector3,z=[],M=[];for(let E=0;E<p.length;E++){let S=i.closestPointToPoint(p[E],!0,w);S.distanceTo(p[E])<.15&&(z.push(p[E]),M.push(S.clone()))}for(let E=0;E<M.length;E++)zo(i,M[E])&&z.push(M[E]);if(z=M,z=Mo(z),z.length<150)continue;let P=We(z);if(P.length==2){let E=P[0].distanceTo(P[1]);if(Math.abs(E-i.distance())<.3){a=y.maxPerpendicularDistance;let S=new N.Line3(g,x),I=new N.Vector3(r.x,r.y,g.z),W=S.closestPointToPoint(I,!0,new N.Vector3);d.beamNearWallVec=new N.Vector3().subVectors(W,I).normalize(),d.beamStart.z>t[h].rooftopPz-.03&&length>1?l=!0:c=!0;break}}if(c)break}else y&&y.type=="collinear_overlap"&&y.maxPerpendicularDistance>.3&&y.maxPerpendicularDistance<.7&&(l=!0)}if(c){if(length<1.8||a<.2)continue;l=!0}l||(d.isRebuild=!0)}}}};import*as Bt from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";var Pr=(t,e={})=>{let n=e.eps??1e-6,o=e.project??(m=>({x:m.x,y:m.z})),r=e.skipSplit??!1,s=e.insideAreaSign??"positive",i=r?t.map((m,p)=>({start:Nn(m.start),end:Nn(m.end),uuid:m.uuid,sourceIndex:p,sourceSegment:m})):Zi(t,o,n),a=[],u=new Map;function d(m){let p=Math.round(m.x/n),b=Math.round(m.y/n);return`${p},${b}`}function f(m){let p=d(m);if(u.has(p))return u.get(p);let b=a.length;return a.push({id:b,x:m.x,y:m.y}),u.set(p,b),b}let c=[],l=new Map;for(let m of i){let p=o(m.start),b=o(m.end);if(Tr(p,b)<n*n)continue;let w=f(p),z=f(b);if(w===z)continue;let M=w<z?`${w}_${z}`:`${z}_${w}`;if(l.has(M))continue;let P=c.length;c.push({id:P,a:w,b:z,uuid:m.uuid,sourceIndex:m.sourceIndex,sourceSegment:m.sourceSegment||m}),l.set(M,P)}let h=[],g=Array.from({length:a.length},()=>[]);function x(m,p,b,w,z){let M=a[m],P=a[p],E=h.length,S=Math.atan2(P.y-M.y,P.x-M.x),I={id:E,from:m,to:p,twin:null,next:null,angle:S,edgeId:b,uuid:w,sourceIndex:z,visited:!1};return h.push(I),g[m].push(E),E}for(let m of c){let p=x(m.a,m.b,m.id,m.uuid,m.sourceIndex),b=x(m.b,m.a,m.id,m.uuid,m.sourceIndex);h[p].twin=b,h[b].twin=p}for(let m of g)m.sort((p,b)=>h[p].angle-h[b].angle);for(let m of h){let p=g[m.to],b=m.twin,w=p.indexOf(b);if(w===-1)continue;let z=(w-1+p.length)%p.length;m.next=p[z]}let y=[];for(let m of h){if(m.visited)continue;let p=[],b=[],w=m.id,z=0,M=h.length+10;for(;;){let v=h[w];if(!v||v.visited)break;if(v.visited=!0,p.push(w),b.push(v.from),w=v.next,z++,z>M){console.warn("\u534A\u8FB9\u904D\u5386\u5F02\u5E38\uFF0C\u53EF\u80FD\u5B58\u5728\u975E\u5E73\u9762\u56FE\u3001\u91CD\u590D\u7EBF\u3001\u60AC\u6302\u7EBF\u6216\u810F\u6570\u636E");break}}if(p.length<3)continue;let P=b.map(v=>a[v]),E=Yi(P),S=!1;if(s==="positive"?S=E>n:S=E<-n,!S)continue;let I=p.map(v=>h[v].uuid),W=p.map(v=>h[v].sourceIndex);y.push({uuids:I,area:Math.abs(E),lineIndexes:W})}return y};function Zi(t,e,n=1e-6){let o=[];for(let r=0;r<t.length;r++){let s=t[r],i=e(s.start),a=e(s.end),u=[{t:0,point:Nn(s.start)},{t:1,point:Nn(s.end)}];for(let f=0;f<t.length;f++){if(r===f)continue;let c=t[f],l=e(c.start),h=e(c.end),g=Gi(i,a,l,h,n);g&&g.t>n&&g.t<1-n&&u.push({t:g.t,point:Ui(s.start,s.end,g.t)})}u.sort((f,c)=>f.t-c.t);let d=[];for(let f of u)(d.length===0||Math.abs(f.t-d[d.length-1].t)>n)&&d.push(f);for(let f=0;f<d.length-1;f++){let c=d[f].point,l=d[f+1].point,h=e(c),g=e(l);Tr(h,g)<n*n||o.push({start:c,end:l,uuid:s.uuid,sourceIndex:r,sourceSegment:s})}}return o}function Gi(t,e,n,o,r=1e-6){let s={x:e.x-t.x,y:e.y-t.y},i={x:o.x-n.x,y:o.y-n.y},a={x:n.x-t.x,y:n.y-t.y},u=Po(s,i);if(Math.abs(u)<r)return null;let d=Po(a,i)/u,f=Po(a,s)/u;return d>=-r&&d<=1+r&&f>=-r&&f<=1+r?{t:d,u:f,point:{x:t.x+d*s.x,y:t.y+d*s.y}}:null}function Po(t,e){return t.x*e.y-t.y*e.x}function Tr(t,e){let n=t.x-e.x,o=t.y-e.y;return n*n+o*o}function Yi(t){let e=0;for(let n=0;n<t.length;n++){let o=t[n],r=t[(n+1)%t.length];e+=o.x*r.y-r.x*o.y}return e/2}function Ui(t,e,n){return t&&typeof t.clone=="function"&&typeof t.lerp=="function"?t.clone().lerp(e,n):{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n,z:t.z!==void 0&&e.z!==void 0?t.z+(e.z-t.z)*n:void 0}}function Nn(t){return t&&typeof t.clone=="function"?t.clone():{x:t.x,y:t.y,z:t.z}}var Ki=(t,e)=>{if(!t||t.length<=0)return;let n={rectangles:[],threeEdgeRect:[]},o=new Set,r=.1,s=1.2,i=.15,a=2,u=80,d=95;if(!t[0].uuid){let l=1e4;for(let h=0;h<t.length;h++)t[h].uuid=l++}let f=[];for(let l=0;l<t.length;l++)f.push({start:t[l].start,end:t[l].end,uuid:t[l].uuid});let c=Pr(f,{eps:.035,returnDetail:!0,project:l=>({x:l.x,y:l.y})});for(let l=0;l<c.length;l++){if(c[l].uuids.length<4||c[l].area<i||c[l].area>a)continue;let h=!1;for(let g=0;g<c[l].lineIndexes.length;g++){let x=t[c[l].lineIndexes[g]].length;if(x<r||x>s)break;let y=new Bt.Vector3(t[c[l].lineIndexes[g]].start.x,t[c[l].lineIndexes[g]].start.y,t[c[l].lineIndexes[g]].start.z),m=new Bt.Vector3(t[c[l].lineIndexes[g]].end.x,t[c[l].lineIndexes[g]].end.y,t[c[l].lineIndexes[g]].end.z),p=!1,b=new Bt.Vector3(0,0,0);for(let w=g+1;w<c[l].lineIndexes.length;w++){let z=t[c[l].lineIndexes[w]].length;if(z<r||z>s)break;let M=new Bt.Vector3(t[c[l].lineIndexes[w]].start.x,t[c[l].lineIndexes[w]].start.y,t[c[l].lineIndexes[w]].start.z),P=new Bt.Vector3(t[c[l].lineIndexes[w]].end.x,t[c[l].lineIndexes[w]].end.y,t[c[l].lineIndexes[w]].end.z),E=Zt(y,m,M,P);if(E&&E.isParallel){if(x+z>s){p=!0;break}x+=z;let I=ct(y,M),W=ct(y,P),v=ct(m,M),T=ct(m,P);I?(y=m.clone(),m=P.clone()):W?(y=m.clone(),m=M.clone()):v?m=P.clone():T&&(m=M.clone());continue}let S=ie(y,m,M,P);if(!S||S.angle<u||S.angle>d){p=!0;break}for(let I=w+1;I<c[l].lineIndexes.length;I++){let W=t[c[l].lineIndexes[I]].length;if(W<r||W>s)break;let v=new Bt.Vector3(t[c[l].lineIndexes[I]].start.x,t[c[l].lineIndexes[I]].start.y,t[c[l].lineIndexes[I]].start.z),T=new Bt.Vector3(t[c[l].lineIndexes[I]].end.x,t[c[l].lineIndexes[I]].end.y,t[c[l].lineIndexes[I]].end.z),R=Zt(M,P,v,T);if(R&&R.isParallel){if(z+W>s){p=!0;break}z+=W;let H=ct(M,v),V=ct(M,T),C=ct(P,v),_=ct(P,T);H?(M=P.clone(),P=T.clone()):V?(M=P.clone(),P=v.clone()):C?P=T.clone():_&&(P=v.clone());continue}let D=ie(M,P,v,T);if(!D||D.angle<u||D.angle>d){p=!0;break}for(let H=I+1;H<c[l].lineIndexes.length;H++){let V=t[c[l].lineIndexes[H]].length;if(V<r||V>s)break;let C=new Bt.Vector3(t[c[l].lineIndexes[H]].start.x,t[c[l].lineIndexes[H]].start.y,t[c[l].lineIndexes[H]].start.z),_=new Bt.Vector3(t[c[l].lineIndexes[H]].end.x,t[c[l].lineIndexes[H]].end.y,t[c[l].lineIndexes[H]].end.z),A=Zt(v,T,C,_);if(A&&A.isParallel){if(W+V>s){p=!0;break}W+=V;let $=ct(v,C),Z=ct(v,_),Q=ct(T,C),j=ct(T,_);$?(v=T.clone(),T=_.clone()):Z?(v=T.clone(),T=C.clone()):Q?T=_.clone():j&&(T=C.clone());continue}let L=ie(v,T,C,_);if(!L||L.angle<u||L.angle>d){p=!0;break}let k=ct(C,y),F=ct(C,m),B=ct(_,y),O=ct(_,m);if(k||F||B||O)h=!0;else for(let $=H+1;$<c[l].lineIndexes.length;$++){let Z=t[c[l].lineIndexes[$]].length;if(Z<r||Z>s)break;let Q=new Bt.Vector3(t[c[l].lineIndexes[$]].start.x,t[c[l].lineIndexes[$]].start.y,t[c[l].lineIndexes[$]].start.z),j=new Bt.Vector3(t[c[l].lineIndexes[$]].end.x,t[c[l].lineIndexes[$]].end.y,t[c[l].lineIndexes[$]].end.z),X=Zt(C,_,Q,j);if(X&&X.isParallel){if(V+Z>s){p=!0;break}V+=Z;let U=ct(C,Q),at=ct(C,j),mt=ct(_,Q),St=ct(_,j);if(U)C=_.clone(),_=j.clone();else if(at)C=_.clone(),_=Q.clone();else if(mt)_=j.clone();else if(St)_=Q.clone();else continue;if(k=ct(C,y),F=ct(C,m),B=ct(_,y),O=ct(_,m),k||F||B||O){h=!0;break}}}break}if(p)break}if(p)break}if(p)break}h&&n.rectangles.push(c[l].uuids)}for(let l=0;l<t.length;l++){let h=t[l].length;if(o.has(t[l].uuid)||h<r||h>s)continue;let g={uuids:[],missingEdge:{start:new Bt.Vector3,end:new Bt.Vector3}},x=new Bt.Vector3(t[l].start.x,t[l].start.y,t[l].start.z),y=new Bt.Vector3(t[l].end.x,t[l].end.y,t[l].end.z),m=!0,p=!0;for(let z=0;z<t.length;z++){if(z==l)continue;let M=new Bt.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),P=new Bt.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),E=ct(M,x),S=ct(P,x),I=ct(M,y),W=ct(P,y);if(E||S?m=!1:(I||W)&&(p=!1),!m&&!p)break}if(!m&&!p)continue;let b=new Bt.Vector3;m||([x,y]=[y,x]),b=new Bt.Vector3().subVectors(y,x).normalize();let w=b.clone().negate();for(let z=0;z<t.length;z++){let M=t[z].length;if(z==l||o.has(z)||M<r||M>s)continue;let P=new Bt.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),E=new Bt.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),S=ie(x,y,P,E);if(!S||S.angle<85)continue;let I=ct(P,y),W=ct(E,y);if(!I&&!W)continue;let v=new Bt.Vector3,T=new Bt.Vector3;I?(v=P.clone(),T=E.clone()):(v=E.clone(),T=P.clone());for(let R=0;R<t.length;R++){let D=t[R].length;if(R==l||R==z||o.has(R)||D<r||D>s)continue;let H=new Bt.Vector3(t[R].start.x,t[R].start.y,t[R].start.z),V=new Bt.Vector3(t[R].end.x,t[R].end.y,t[R].end.z),C=ie(P,E,H,V);if(!C||C.angle<85)continue;let _=ct(H,T),A=ct(V,T);if(!_&&!A)continue;let L=new Bt.Vector3,k=new Bt.Vector3;_?(L=H.clone(),k=V.clone()):(L=V.clone(),k=H.clone());let F=new Bt.Vector3().subVectors(k,L).normalize(),B=Xt(w,F,.1);if(!B||!B.parallel||!B.sameDirection)continue;let O=!0,$=!0;for(let Q=0;Q<t.length;Q++){if(Q==R)continue;let j=new Bt.Vector3(t[Q].start.x,t[Q].start.y,t[Q].start.z),X=new Bt.Vector3(t[Q].end.x,t[Q].end.y,t[Q].end.z),U=ct(j,H),at=ct(X,H),mt=ct(j,V),St=ct(X,V);if(U||at?O=!1:(mt||St)&&($=!1),!O&&!$)break}if(!O&&!$)continue;let Z=h*M;if(!(Z<i||Z>a)){g.uuids=[t[l].uuid,t[z].uuid,t[R].uuid],g.missingEdge.start=k,g.missingEdge.end=x;break}}if(g.uuids.length==3)break}g.uuids.length==3&&(g.uuids.forEach(z=>o.add(z)),n.threeEdgeRect.push(g))}return{colDatas:n,lines:t}};import*as q from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";var Ht=11102230246251565e-32,Kt=134217729,zn=(3+8*Ht)*Ht;function Fe(t,e,n,o,r){let s,i,a,u,d=e[0],f=o[0],c=0,l=0;f>d==f>-d?(s=d,d=e[++c]):(s=f,f=o[++l]);let h=0;if(c<t&&l<n)for(f>d==f>-d?(i=d+s,a=s-(i-d),d=e[++c]):(i=f+s,a=s-(i-f),f=o[++l]),s=i,a!==0&&(r[h++]=a);c<t&&l<n;)f>d==f>-d?(i=s+d,u=i-s,a=s-(i-u)+(d-u),d=e[++c]):(i=s+f,u=i-s,a=s-(i-u)+(f-u),f=o[++l]),s=i,a!==0&&(r[h++]=a);for(;c<t;)i=s+d,u=i-s,a=s-(i-u)+(d-u),d=e[++c],s=i,a!==0&&(r[h++]=a);for(;l<n;)i=s+f,u=i-s,a=s-(i-u)+(f-u),f=o[++l],s=i,a!==0&&(r[h++]=a);return(s!==0||h===0)&&(r[h++]=s),h}function Mn(t,e){let n=e[0];for(let o=1;o<t;o++)n+=e[o];return n}function K(t){return new Float64Array(t)}var Qi=(3+16*Ht)*Ht,Ji=(2+12*Ht)*Ht,tl=(9+64*Ht)*Ht*Ht,nn=K(4),Sr=K(8),Rr=K(12),Dr=K(16),re=K(4);function el(t,e,n,o,r,s,i){let a,u,d,f,c,l,h,g,x,y,m,p,b,w,z,M,P,E,S=t-r,I=n-r,W=e-s,v=o-s;w=S*v,l=Kt*S,h=l-(l-S),g=S-h,l=Kt*v,x=l-(l-v),y=v-x,z=g*y-(w-h*x-g*x-h*y),M=W*I,l=Kt*W,h=l-(l-W),g=W-h,l=Kt*I,x=l-(l-I),y=I-x,P=g*y-(M-h*x-g*x-h*y),m=z-P,c=z-m,nn[0]=z-(m+c)+(c-P),p=w+m,c=p-w,b=w-(p-c)+(m-c),m=b-M,c=b-m,nn[1]=b-(m+c)+(c-M),E=p+m,c=E-p,nn[2]=p-(E-c)+(m-c),nn[3]=E;let T=Mn(4,nn),R=Ji*i;if(T>=R||-T>=R||(c=t-S,a=t-(S+c)+(c-r),c=n-I,d=n-(I+c)+(c-r),c=e-W,u=e-(W+c)+(c-s),c=o-v,f=o-(v+c)+(c-s),a===0&&u===0&&d===0&&f===0)||(R=tl*i+zn*Math.abs(T),T+=S*f+v*a-(W*d+I*u),T>=R||-T>=R))return T;w=a*v,l=Kt*a,h=l-(l-a),g=a-h,l=Kt*v,x=l-(l-v),y=v-x,z=g*y-(w-h*x-g*x-h*y),M=u*I,l=Kt*u,h=l-(l-u),g=u-h,l=Kt*I,x=l-(l-I),y=I-x,P=g*y-(M-h*x-g*x-h*y),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,b=w-(p-c)+(m-c),m=b-M,c=b-m,re[1]=b-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let D=Fe(4,nn,4,re,Sr);w=S*f,l=Kt*S,h=l-(l-S),g=S-h,l=Kt*f,x=l-(l-f),y=f-x,z=g*y-(w-h*x-g*x-h*y),M=W*d,l=Kt*W,h=l-(l-W),g=W-h,l=Kt*d,x=l-(l-d),y=d-x,P=g*y-(M-h*x-g*x-h*y),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,b=w-(p-c)+(m-c),m=b-M,c=b-m,re[1]=b-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let H=Fe(D,Sr,4,re,Rr);w=a*f,l=Kt*a,h=l-(l-a),g=a-h,l=Kt*f,x=l-(l-f),y=f-x,z=g*y-(w-h*x-g*x-h*y),M=u*d,l=Kt*u,h=l-(l-u),g=u-h,l=Kt*d,x=l-(l-d),y=d-x,P=g*y-(M-h*x-g*x-h*y),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,b=w-(p-c)+(m-c),m=b-M,c=b-m,re[1]=b-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let V=Fe(H,Rr,4,re,Dr);return Dr[V-1]}function on(t,e,n,o,r,s){let i=(e-s)*(n-r),a=(t-r)*(o-s),u=i-a,d=Math.abs(i+a);return Math.abs(u)>=Qi*d?u:-el(t,e,n,o,r,s,d)}var Tu=(7+56*Ht)*Ht,Su=(3+28*Ht)*Ht,Ru=(26+288*Ht)*Ht*Ht,Du=K(4),vu=K(4),Vu=K(4),Iu=K(4),Cu=K(4),Hu=K(4),Wu=K(4),_u=K(4),Au=K(4),Bu=K(8),Lu=K(8),ku=K(8),Ou=K(4),Fu=K(8),Nu=K(8),qu=K(16),ju=K(12),$u=K(192),Xu=K(192);var Yu=(10+96*Ht)*Ht,Uu=(4+48*Ht)*Ht,Ku=(44+576*Ht)*Ht*Ht,Qu=K(4),Ju=K(4),tf=K(4),ef=K(4),nf=K(4),of=K(4),rf=K(4),sf=K(4),lf=K(8),af=K(8),cf=K(8),uf=K(8),ff=K(8),df=K(8),hf=K(8),mf=K(8),pf=K(8),gf=K(4),xf=K(4),yf=K(4),bf=K(8),wf=K(16),zf=K(16),Mf=K(16),Ef=K(32),Pf=K(32),Tf=K(48),Sf=K(64),Rf=K(1152),Df=K(1152);var Cf=(16+224*Ht)*Ht,Hf=(5+72*Ht)*Ht,Wf=(71+1408*Ht)*Ht*Ht,_f=K(4),Af=K(4),Bf=K(4),Lf=K(4),kf=K(4),Of=K(4),Ff=K(4),Nf=K(4),qf=K(4),jf=K(4),$f=K(24),Xf=K(24),Zf=K(24),Gf=K(24),Yf=K(24),Uf=K(24),Kf=K(24),Qf=K(24),Jf=K(24),td=K(24),ed=K(1152),nd=K(1152),od=K(1152),rd=K(1152),sd=K(1152),id=K(2304),ld=K(2304),ad=K(3456),cd=K(5760),ud=K(8),fd=K(8),dd=K(8),hd=K(16),md=K(24),pd=K(48),gd=K(48),xd=K(96),yd=K(192),bd=K(384),wd=K(384),zd=K(384),Md=K(768);var Ed=K(96),Pd=K(96),Td=K(96),Sd=K(1152);var Vr=Math.pow(2,-52),qn=new Uint32Array(512),sn=class t{static from(e,n=ll,o=al){let r=e.length,s=new Float64Array(r*2);for(let i=0;i<r;i++){let a=e[i];s[2*i]=n(a),s[2*i+1]=o(a)}return new t(s)}constructor(e){let n=e.length>>1;if(n>0&&typeof e[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=e;let o=Math.max(2*n-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(n)),this._hullPrev=new Uint32Array(n),this._hullNext=new Uint32Array(n),this._hullTri=new Uint32Array(n),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(n),this._dists=new Float64Array(n),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:n,_hullNext:o,_hullTri:r,_hullHash:s}=this,i=e.length>>1,a=1/0,u=1/0,d=-1/0,f=-1/0;for(let S=0;S<i;S++){let I=e[2*S],W=e[2*S+1];I<a&&(a=I),W<u&&(u=W),I>d&&(d=I),W>f&&(f=W),this._ids[S]=S}let c=(a+d)/2,l=(u+f)/2,h=0,g=0,x=0;for(let S=0,I=1/0;S<i;S++){let W=To(c,l,e[2*S],e[2*S+1]);W<I&&(h=S,I=W)}let y=e[2*h],m=e[2*h+1];for(let S=0,I=1/0;S<i;S++){if(S===h)continue;let W=To(y,m,e[2*S],e[2*S+1]);W<I&&W>0&&(g=S,I=W)}let p=e[2*g],b=e[2*g+1],w=1/0;for(let S=0;S<i;S++){if(S===h||S===g)continue;let I=sl(y,m,p,b,e[2*S],e[2*S+1]);I<w&&(x=S,w=I)}let z=e[2*x],M=e[2*x+1];if(w===1/0){for(let W=0;W<i;W++)this._dists[W]=e[2*W]-e[0]||e[2*W+1]-e[1];rn(this._ids,this._dists,0,i-1);let S=new Uint32Array(i),I=0;for(let W=0,v=-1/0;W<i;W++){let T=this._ids[W],R=this._dists[T];R>v&&(S[I++]=T,v=R)}this.hull=S.subarray(0,I),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(on(y,m,p,b,z,M)<0){let S=g,I=p,W=b;g=x,p=z,b=M,x=S,z=I,M=W}let P=il(y,m,p,b,z,M);this._cx=P.x,this._cy=P.y;for(let S=0;S<i;S++)this._dists[S]=To(e[2*S],e[2*S+1],P.x,P.y);rn(this._ids,this._dists,0,i-1),this._hullStart=h;let E=3;o[h]=n[x]=g,o[g]=n[h]=x,o[x]=n[g]=h,r[h]=0,r[g]=1,r[x]=2,s.fill(-1),s[this._hashKey(y,m)]=h,s[this._hashKey(p,b)]=g,s[this._hashKey(z,M)]=x,this.trianglesLen=0,this._addTriangle(h,g,x,-1,-1,-1);for(let S=0,I=0,W=0;S<this._ids.length;S++){let v=this._ids[S],T=e[2*v],R=e[2*v+1];if(S>0&&Math.abs(T-I)<=Vr&&Math.abs(R-W)<=Vr||(I=T,W=R,v===h||v===g||v===x))continue;let D=0;for(let A=0,L=this._hashKey(T,R);A<this._hashSize&&(D=s[(L+A)%this._hashSize],!(D!==-1&&D!==o[D]));A++);D=n[D];let H=D,V;for(;V=o[H],on(T,R,e[2*H],e[2*H+1],e[2*V],e[2*V+1])>=0;)if(H=V,H===D){H=-1;break}if(H===-1)continue;let C=this._addTriangle(H,v,o[H],-1,-1,r[H]);r[v]=this._legalize(C+2),r[H]=C,E++;let _=o[H];for(;V=o[_],on(T,R,e[2*_],e[2*_+1],e[2*V],e[2*V+1])<0;)C=this._addTriangle(_,v,V,r[v],-1,r[_]),r[v]=this._legalize(C+2),o[_]=_,E--,_=V;if(H===D)for(;V=n[H],on(T,R,e[2*V],e[2*V+1],e[2*H],e[2*H+1])<0;)C=this._addTriangle(V,v,H,-1,r[H],r[V]),this._legalize(C+2),r[V]=C,o[H]=H,E--,H=V;this._hullStart=n[v]=H,o[H]=n[_]=v,o[v]=_,s[this._hashKey(T,R)]=v,s[this._hashKey(e[2*H],e[2*H+1])]=H}this.hull=new Uint32Array(E);for(let S=0,I=this._hullStart;S<E;S++)this.hull[S]=I,I=o[I];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,n){return Math.floor(ol(e-this._cx,n-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:n,_halfedges:o,coords:r}=this,s=0,i=0;for(;;){let a=o[e],u=e-e%3;if(i=u+(e+2)%3,a===-1){if(s===0)break;e=qn[--s];continue}let d=a-a%3,f=u+(e+1)%3,c=d+(a+2)%3,l=n[i],h=n[e],g=n[f],x=n[c];if(rl(r[2*l],r[2*l+1],r[2*h],r[2*h+1],r[2*g],r[2*g+1],r[2*x],r[2*x+1])){n[e]=x,n[a]=l;let m=o[c];if(m===-1){let b=this._hullStart;do{if(this._hullTri[b]===c){this._hullTri[b]=e;break}b=this._hullPrev[b]}while(b!==this._hullStart)}this._link(e,m),this._link(a,o[i]),this._link(i,c);let p=d+(a+1)%3;s<qn.length&&(qn[s++]=p)}else{if(s===0)break;e=qn[--s]}}return i}_link(e,n){this._halfedges[e]=n,n!==-1&&(this._halfedges[n]=e)}_addTriangle(e,n,o,r,s,i){let a=this.trianglesLen;return this._triangles[a]=e,this._triangles[a+1]=n,this._triangles[a+2]=o,this._link(a,r),this._link(a+1,s),this._link(a+2,i),this.trianglesLen+=3,a}};function ol(t,e){let n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}function To(t,e,n,o){let r=t-n,s=e-o;return r*r+s*s}function rl(t,e,n,o,r,s,i,a){let u=t-i,d=e-a,f=n-i,c=o-a,l=r-i,h=s-a,g=u*u+d*d,x=f*f+c*c,y=l*l+h*h;return u*(c*y-x*h)-d*(f*y-x*l)+g*(f*h-c*l)<0}function sl(t,e,n,o,r,s){let i=n-t,a=o-e,u=r-t,d=s-e,f=i*i+a*a,c=u*u+d*d,l=.5/(i*d-a*u),h=(d*f-a*c)*l,g=(i*c-u*f)*l;return h*h+g*g}function il(t,e,n,o,r,s){let i=n-t,a=o-e,u=r-t,d=s-e,f=i*i+a*a,c=u*u+d*d,l=.5/(i*d-a*u),h=t+(d*f-a*c)*l,g=e+(i*c-u*f)*l;return{x:h,y:g}}function rn(t,e,n,o){if(o-n<=20)for(let r=n+1;r<=o;r++){let s=t[r],i=e[s],a=r-1;for(;a>=n&&e[t[a]]>i;)t[a+1]=t[a--];t[a+1]=s}else{let r=n+o>>1,s=n+1,i=o;En(t,r,s),e[t[n]]>e[t[o]]&&En(t,n,o),e[t[s]]>e[t[o]]&&En(t,s,o),e[t[n]]>e[t[s]]&&En(t,n,s);let a=t[s],u=e[a];for(;;){do s++;while(e[t[s]]<u);do i--;while(e[t[i]]>u);if(i<s)break;En(t,s,i)}t[n+1]=t[i],t[i]=a,o-s+1>=i-n?(rn(t,e,s,o),rn(t,e,n,i-1)):(rn(t,e,n,i-1),rn(t,e,s,o))}}function En(t,e,n){let o=t[e];t[e]=t[n],t[n]=o}function ll(t){return t[0]}function al(t){return t[1]}var he=class{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(e,n){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(e,n){this._+=`L${this._x1=+e},${this._y1=+n}`}arc(e,n,o){e=+e,n=+n,o=+o;let r=e+o,s=n;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${r},${s}`:(Math.abs(this._x1-r)>1e-6||Math.abs(this._y1-s)>1e-6)&&(this._+="L"+r+","+s),o&&(this._+=`A${o},${o},0,1,1,${e-o},${n}A${o},${o},0,1,1,${this._x1=r},${this._y1=s}`)}rect(e,n,o,r){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}h${+o}v${+r}h${-o}Z`}value(){return this._||null}};var _e=class{constructor(){this._=[]}moveTo(e,n){this._.push([e,n])}closePath(){this._.push(this._[0].slice())}lineTo(e,n){this._.push([e,n])}value(){return this._.length?this._:null}};var Pn=class{constructor(e,[n,o,r,s]=[0,0,960,500]){if(!((r=+r)>=(n=+n))||!((s=+s)>=(o=+o)))throw new 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=n,this.ymax=s,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){let{delaunay:{points:e,hull:n,triangles:o},vectors:r}=this,s,i,a=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let x=0,y=0,m=o.length,p,b;x<m;x+=3,y+=2){let w=o[x]*2,z=o[x+1]*2,M=o[x+2]*2,P=e[w],E=e[w+1],S=e[z],I=e[z+1],W=e[M],v=e[M+1],T=S-P,R=I-E,D=W-P,H=v-E,V=(T*H-R*D)*2;if(Math.abs(V)<1e-9){if(s===void 0){s=i=0;for(let _ of n)s+=e[_*2],i+=e[_*2+1];s/=n.length,i/=n.length}let C=1e9*Math.sign((s-P)*H-(i-E)*D);p=(P+W)/2-C*H,b=(E+v)/2+C*D}else{let C=1/V,_=T*T+R*R,A=D*D+H*H;p=P+(H*_-R*A)*C,b=E+(T*A-D*_)*C}a[y]=p,a[y+1]=b}let u=n[n.length-1],d,f=u*4,c,l=e[2*u],h,g=e[2*u+1];r.fill(0);for(let x=0;x<n.length;++x)u=n[x],d=f,c=l,h=g,f=u*4,l=e[2*u],g=e[2*u+1],r[d+2]=r[f]=h-g,r[d+3]=r[f+1]=l-c}render(e){let n=e==null?e=new he:void 0,{delaunay:{halfedges:o,inedges:r,hull:s},circumcenters:i,vectors:a}=this;if(s.length<=1)return null;for(let f=0,c=o.length;f<c;++f){let l=o[f];if(l<f)continue;let h=Math.floor(f/3)*2,g=Math.floor(l/3)*2,x=i[h],y=i[h+1],m=i[g],p=i[g+1];this._renderSegment(x,y,m,p,e)}let u,d=s[s.length-1];for(let f=0;f<s.length;++f){u=d,d=s[f];let c=Math.floor(r[d]/3)*2,l=i[c],h=i[c+1],g=u*4,x=this._project(l,h,a[g+2],a[g+3]);x&&this._renderSegment(l,h,x[0],x[1],e)}return n&&n.value()}renderBounds(e){let n=e==null?e=new he:void 0;return e.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),n&&n.value()}renderCell(e,n){let o=n==null?n=new he:void 0,r=this._clip(e);if(r===null||!r.length)return;n.moveTo(r[0],r[1]);let s=r.length;for(;r[0]===r[s-2]&&r[1]===r[s-1]&&s>1;)s-=2;for(let i=2;i<s;i+=2)(r[i]!==r[i-2]||r[i+1]!==r[i-1])&&n.lineTo(r[i],r[i+1]);return n.closePath(),o&&o.value()}*cellPolygons(){let{delaunay:{points:e}}=this;for(let n=0,o=e.length/2;n<o;++n){let r=this.cellPolygon(n);r&&(r.index=n,yield r)}}cellPolygon(e){let n=new _e;return this.renderCell(e,n),n.value()}_renderSegment(e,n,o,r,s){let i,a=this._regioncode(e,n),u=this._regioncode(o,r);a===0&&u===0?(s.moveTo(e,n),s.lineTo(o,r)):(i=this._clipSegment(e,n,o,r,a,u))&&(s.moveTo(i[0],i[1]),s.lineTo(i[2],i[3]))}contains(e,n,o){return n=+n,n!==n||(o=+o,o!==o)?!1:this.delaunay._step(e,n,o)===e}*neighbors(e){let n=this._clip(e);if(n)for(let o of this.delaunay.neighbors(e)){let r=this._clip(o);if(r){t:for(let s=0,i=n.length;s<i;s+=2)for(let a=0,u=r.length;a<u;a+=2)if(n[s]===r[a]&&n[s+1]===r[a+1]&&n[(s+2)%i]===r[(a+u-2)%u]&&n[(s+3)%i]===r[(a+u-1)%u]){yield o;break t}}}}_cell(e){let{circumcenters:n,delaunay:{inedges:o,halfedges:r,triangles:s}}=this,i=o[e];if(i===-1)return null;let a=[],u=i;do{let d=Math.floor(u/3);if(a.push(n[d*2],n[d*2+1]),u=u%3===2?u-2:u+1,s[u]!==e)break;u=r[u]}while(u!==i&&u!==-1);return a}_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 n=this._cell(e);if(n===null)return null;let{vectors:o}=this,r=e*4;return this._simplify(o[r]||o[r+1]?this._clipInfinite(e,n,o[r],o[r+1],o[r+2],o[r+3]):this._clipFinite(e,n))}_clipFinite(e,n){let o=n.length,r=null,s,i,a=n[o-2],u=n[o-1],d,f=this._regioncode(a,u),c,l=0;for(let h=0;h<o;h+=2)if(s=a,i=u,a=n[h],u=n[h+1],d=f,f=this._regioncode(a,u),d===0&&f===0)c=l,l=0,r?r.push(a,u):r=[a,u];else{let g,x,y,m,p;if(d===0){if((g=this._clipSegment(s,i,a,u,d,f))===null)continue;[x,y,m,p]=g}else{if((g=this._clipSegment(a,u,s,i,f,d))===null)continue;[m,p,x,y]=g,c=l,l=this._edgecode(x,y),c&&l&&this._edge(e,c,l,r,r.length),r?r.push(x,y):r=[x,y]}c=l,l=this._edgecode(m,p),c&&l&&this._edge(e,c,l,r,r.length),r?r.push(m,p):r=[m,p]}if(r)c=l,l=this._edgecode(r[0],r[1]),c&&l&&this._edge(e,c,l,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,n,o,r,s,i){let a=s<i;for(a&&([e,n,o,r,s,i]=[o,r,e,n,i,s]);;){if(s===0&&i===0)return a?[o,r,e,n]:[e,n,o,r];if(s&i)return null;let u,d,f=s||i;f&8?(u=e+(o-e)*(this.ymax-n)/(r-n),d=this.ymax):f&4?(u=e+(o-e)*(this.ymin-n)/(r-n),d=this.ymin):f&2?(d=n+(r-n)*(this.xmax-e)/(o-e),u=this.xmax):(d=n+(r-n)*(this.xmin-e)/(o-e),u=this.xmin),s?(e=u,n=d,s=this._regioncode(e,n)):(o=u,r=d,i=this._regioncode(o,r))}}_clipInfinite(e,n,o,r,s,i){let a=Array.from(n),u;if((u=this._project(a[0],a[1],o,r))&&a.unshift(u[0],u[1]),(u=this._project(a[a.length-2],a[a.length-1],s,i))&&a.push(u[0],u[1]),a=this._clipFinite(e,a))for(let d=0,f=a.length,c,l=this._edgecode(a[f-2],a[f-1]);d<f;d+=2)c=l,l=this._edgecode(a[d],a[d+1]),c&&l&&(d=this._edge(e,c,l,a,d),f=a.length);else this.contains(e,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(e,n,o,r,s){for(;n!==o;){let i,a;switch(n){case 5:n=4;continue;case 4:n=6,i=this.xmax,a=this.ymin;break;case 6:n=2;continue;case 2:n=10,i=this.xmax,a=this.ymax;break;case 10:n=8;continue;case 8:n=9,i=this.xmin,a=this.ymax;break;case 9:n=1;continue;case 1:n=5,i=this.xmin,a=this.ymin;break}(r[s]!==i||r[s+1]!==a)&&this.contains(e,i,a)&&(r.splice(s,0,i,a),s+=2)}return s}_project(e,n,o,r){let s=1/0,i,a,u;if(r<0){if(n<=this.ymin)return null;(i=(this.ymin-n)/r)<s&&(u=this.ymin,a=e+(s=i)*o)}else if(r>0){if(n>=this.ymax)return null;(i=(this.ymax-n)/r)<s&&(u=this.ymax,a=e+(s=i)*o)}if(o>0){if(e>=this.xmax)return null;(i=(this.xmax-e)/o)<s&&(a=this.xmax,u=n+(s=i)*r)}else if(o<0){if(e<=this.xmin)return null;(i=(this.xmin-e)/o)<s&&(a=this.xmin,u=n+(s=i)*r)}return[a,u]}_edgecode(e,n){return(e===this.xmin?1:e===this.xmax?2:0)|(n===this.ymin?4:n===this.ymax?8:0)}_regioncode(e,n){return(e<this.xmin?1:e>this.xmax?2:0)|(n<this.ymin?4:n>this.ymax?8:0)}_simplify(e){if(e&&e.length>4){for(let n=0;n<e.length;n+=2){let o=(n+2)%e.length,r=(n+4)%e.length;(e[n]===e[o]&&e[o]===e[r]||e[n+1]===e[o+1]&&e[o+1]===e[r+1])&&(e.splice(o,2),n-=2)}e.length||(e=null)}return e}};var cl=2*Math.PI,ln=Math.pow;function ul(t){return t[0]}function fl(t){return t[1]}function dl(t){let{triangles:e,coords:n}=t;for(let o=0;o<e.length;o+=3){let r=2*e[o],s=2*e[o+1],i=2*e[o+2];if((n[i]-n[r])*(n[s+1]-n[r+1])-(n[s]-n[r])*(n[i+1]-n[r+1])>1e-10)return!1}return!0}function hl(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}var Ae=class t{static from(e,n=ul,o=fl,r){return new t("length"in e?ml(e,n,o,r):Float64Array.from(pl(e,n,o,r)))}constructor(e){this._delaunator=new sn(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,n=this.points;if(e.hull&&e.hull.length>2&&dl(e)){this.collinear=Int32Array.from({length:n.length/2},(l,h)=>h).sort((l,h)=>n[2*l]-n[2*h]||n[2*l+1]-n[2*h+1]);let u=this.collinear[0],d=this.collinear[this.collinear.length-1],f=[n[2*u],n[2*u+1],n[2*d],n[2*d+1]],c=1e-8*Math.hypot(f[3]-f[1],f[2]-f[0]);for(let l=0,h=n.length/2;l<h;++l){let g=hl(n[2*l],n[2*l+1],c);n[2*l]=g[0],n[2*l+1]=g[1]}this._delaunator=new sn(n)}else delete this.collinear;let o=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,s=this.triangles=this._delaunator.triangles,i=this.inedges.fill(-1),a=this._hullIndex.fill(-1);for(let u=0,d=o.length;u<d;++u){let f=s[u%3===2?u-2:u+1];(o[u]===-1||i[f]===-1)&&(i[f]=u)}for(let u=0,d=r.length;u<d;++u)a[r[u]]=u;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],i[r[0]]=1,r.length===2&&(i[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(e){return new Pn(this,e)}*neighbors(e){let{inedges:n,hull:o,_hullIndex:r,halfedges:s,triangles:i,collinear:a}=this;if(a){let c=a.indexOf(e);c>0&&(yield a[c-1]),c<a.length-1&&(yield a[c+1]);return}let u=n[e];if(u===-1)return;let d=u,f=-1;do{if(yield f=i[d],d=d%3===2?d-2:d+1,i[d]!==e)return;if(d=s[d],d===-1){let c=o[(r[e]+1)%o.length];c!==f&&(yield c);return}}while(d!==u)}find(e,n,o=0){if(e=+e,e!==e||(n=+n,n!==n))return-1;let r=o,s;for(;(s=this._step(o,e,n))>=0&&s!==o&&s!==r;)o=s;return s}_step(e,n,o){let{inedges:r,hull:s,_hullIndex:i,halfedges:a,triangles:u,points:d}=this;if(r[e]===-1||!d.length)return(e+1)%(d.length>>1);let f=e,c=ln(n-d[e*2],2)+ln(o-d[e*2+1],2),l=r[e],h=l;do{let g=u[h],x=ln(n-d[g*2],2)+ln(o-d[g*2+1],2);if(x<c&&(c=x,f=g),h=h%3===2?h-2:h+1,u[h]!==e)break;if(h=a[h],h===-1){if(h=s[(i[e]+1)%s.length],h!==g&&ln(n-d[h*2],2)+ln(o-d[h*2+1],2)<c)return h;break}}while(h!==l);return f}render(e){let n=e==null?e=new he:void 0,{points:o,halfedges:r,triangles:s}=this;for(let i=0,a=r.length;i<a;++i){let u=r[i];if(u<i)continue;let d=s[i]*2,f=s[u]*2;e.moveTo(o[d],o[d+1]),e.lineTo(o[f],o[f+1])}return this.renderHull(e),n&&n.value()}renderPoints(e,n){n===void 0&&(!e||typeof e.moveTo!="function")&&(n=e,e=null),n=n==null?2:+n;let o=e==null?e=new he:void 0,{points:r}=this;for(let s=0,i=r.length;s<i;s+=2){let a=r[s],u=r[s+1];e.moveTo(a+n,u),e.arc(a,u,n,0,cl)}return o&&o.value()}renderHull(e){let n=e==null?e=new he:void 0,{hull:o,points:r}=this,s=o[0]*2,i=o.length;e.moveTo(r[s],r[s+1]);for(let a=1;a<i;++a){let u=2*o[a];e.lineTo(r[u],r[u+1])}return e.closePath(),n&&n.value()}hullPolygon(){let e=new _e;return this.renderHull(e),e.value()}renderTriangle(e,n){let o=n==null?n=new he:void 0,{points:r,triangles:s}=this,i=s[e*=3]*2,a=s[e+1]*2,u=s[e+2]*2;return n.moveTo(r[i],r[i+1]),n.lineTo(r[a],r[a+1]),n.lineTo(r[u],r[u+1]),n.closePath(),o&&o.value()}*trianglePolygons(){let{triangles:e}=this;for(let n=0,o=e.length/3;n<o;++n)yield this.trianglePolygon(n)}trianglePolygon(e){let n=new _e;return this.renderTriangle(e,n),n.value()}};function ml(t,e,n,o){let r=t.length,s=new Float64Array(r*2);for(let i=0;i<r;++i){let a=t[i];s[i*2]=e.call(o,a,i,t),s[i*2+1]=n.call(o,a,i,t)}return s}function*pl(t,e,n,o){let r=0;for(let s of t)yield e.call(o,s,r,t),yield n.call(o,s,r,t),++r}function So(t,e,n,o){let r,s;n<o?(r=n,s=o):(r=o,s=n);let i=r*e+s;t.set(i,(t.get(i)||0)+1)}function Ir(t,e,n){let o=t.get(e);o===void 0&&(o=[],t.set(e,o)),o.push(n)}function me(t){if(!t||t.length<3)return[];let e=new Set,n=[];for(let x=0;x<t.length;x++){let y=t[x],m=`${y[0]}_${y[1]}`;e.has(m)||(e.add(m),n.push(y))}let o=n.length;if(o<3)return[];let r=new Float64Array(o*2);for(let x=0,y=0;x<o;x++){let m=n[x];r[y++]=m[0],r[y++]=m[1]}let s=new Ae(r),{triangles:i}=s;if(!i.length)return[];let a=new Map;for(let x=0;x<i.length;x+=3){let y=i[x],m=i[x+1],p=i[x+2],b=y*2,w=m*2,z=p*2,M=r[b],P=r[b+1],E=r[w],S=r[w+1],I=r[z],W=r[z+1],v=M-E,T=P-S,R=M-I,D=P-W,H=E-I,V=S-W,C=H*H+V*V,_=R*R+D*D,A=v*v+T*T,L=(E-M)*(W-P)-(I-M)*(S-P);if(L===0)continue;let k=L*L,B=M===0||E===0||I===0?k:4*k;C*_*A<=B&&(So(a,o,y,m),So(a,o,m,p),So(a,o,p,y))}if(!a.size)return[];let u=new Map,d=0,f=-1;for(let[x,y]of a){if(y!==1)continue;let m=Math.floor(x/o),p=x-m*o;f===-1&&(f=m),Ir(u,m,p),Ir(u,p,m),d++}if(d===0)return[];let c=[],l=new Uint8Array(o),h=f,g=-1;do{c.push(n[h]),l[h]=1;let x=u.get(h)||[],y=-1;for(let m=0;m<x.length;m++){let p=x[m];if(p!==g&&!l[p]){y=p;break}}if(y===-1)for(let m=0;m<x.length;m++){let p=x[m];if(p!==g){y=p;break}}if(y===-1)break;g=h,h=y}while(h!==f&&c.length<=d+1);return c.length>0&&c.push(c[0]),c}import*as Nt from"three";import{OBB as Wl}from"three/examples/jsm/math/OBB.js";var Qt=63710088e-1,Hr={centimeters:Qt*100,centimetres:Qt*100,degrees:360/(2*Math.PI),feet:Qt*3.28084,inches:Qt*39.37,kilometers:Qt/1e3,kilometres:Qt/1e3,meters:Qt,metres:Qt,miles:Qt/1609.344,millimeters:Qt*1e3,millimetres:Qt*1e3,nauticalmiles:Qt/1852,radians:1,yards:Qt*1.0936};function Wr(t,e,n={}){let o={type:"Feature"};return(n.id===0||n.id)&&(o.id=n.id),n.bbox&&(o.bbox=n.bbox),o.properties=e||{},o.geometry=t,o}function jn(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Cr(t[0])||!Cr(t[1]))throw new Error("coordinates must contain numbers");return Wr({type:"Point",coordinates:t},e,n)}function $n(t,e,n={}){for(let r of t){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let s=0;s<r[r.length-1].length;s++)if(r[r.length-1][s]!==r[0][s])throw new Error("First and last Position are not equivalent.")}return Wr({type:"Polygon",coordinates:t},e,n)}function gl(t,e="kilometers"){let n=Hr[e];if(!n)throw new Error(e+" units is invalid");return t*n}function xl(t,e="kilometers"){let n=Hr[e];if(!n)throw new Error(e+" units is invalid");return t/n}function Xn(t){return t%(2*Math.PI)*180/Math.PI}function pe(t){return t%360*Math.PI/180}function Zn(t,e="kilometers",n="kilometers"){if(!(t>=0))throw new Error("length must be a positive number");return gl(xl(t,e),n)}function Cr(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function _r(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Te(t,e,n){if(t!==null)for(var o,r,s,i,a,u,d,f=0,c=0,l,h=t.type,g=h==="FeatureCollection",x=h==="Feature",y=g?t.features.length:1,m=0;m<y;m++){d=g?t.features[m].geometry:x?t.geometry:t,l=d?d.type==="GeometryCollection":!1,a=l?d.geometries.length:1;for(var p=0;p<a;p++){var b=0,w=0;if(i=l?d.geometries[p]:d,i!==null){u=i.coordinates;var z=i.type;switch(f=n&&(z==="Polygon"||z==="MultiPolygon")?1:0,z){case null:break;case"Point":if(e(u,c,m,b,w)===!1)return!1;c++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<u.length;o++){if(e(u[o],c,m,b,w)===!1)return!1;c++,z==="MultiPoint"&&b++}z==="LineString"&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<u.length;o++){for(r=0;r<u[o].length-f;r++){if(e(u[o][r],c,m,b,w)===!1)return!1;c++}z==="MultiLineString"&&b++,z==="Polygon"&&w++}z==="Polygon"&&b++;break;case"MultiPolygon":for(o=0;o<u.length;o++){for(w=0,r=0;r<u[o].length;r++){for(s=0;s<u[o][r].length-f;s++){if(e(u[o][r][s],c,m,b,w)===!1)return!1;c++}w++}b++}break;case"GeometryCollection":for(o=0;o<i.geometries.length;o++)if(Te(i.geometries[o],e,n)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ar(t){var e=[];return Te(t,function(n){e.push(n)}),e}function yl(t,e){var n,o,r,s,i,a,u,d,f,c,l=0,h=t.type==="FeatureCollection",g=t.type==="Feature",x=h?t.features.length:1;for(n=0;n<x;n++){for(a=h?t.features[n].geometry:g?t.geometry:t,d=h?t.features[n].properties:g?t.properties:{},f=h?t.features[n].bbox:g?t.bbox:void 0,c=h?t.features[n].id:g?t.id:void 0,u=a?a.type==="GeometryCollection":!1,i=u?a.geometries.length:1,r=0;r<i;r++){if(s=u?a.geometries[r]:a,s===null){if(e(null,l,d,f,c)===!1)return!1;continue}switch(s.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(e(s,l,d,f,c)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<s.geometries.length;o++)if(e(s.geometries[o],l,d,f,c)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}l++}}function Br(t,e,n){var o=n;return yl(t,function(r,s,i,a,u){s===0&&n===void 0?o=r:o=e(o,r,s,i,a,u)}),o}var es=Ei(ts(),1);function ns(t,e={}){e.concavity=e.concavity||1/0;let n=[];if(Te(t,r=>{n.push([r[0],r[1]])}),!n.length)return null;let o=(0,es.default)(n,e.concavity);return o.length>3?$n([o]):null}function Qn(t,e={}){let n=0,o=0,r=0;return Te(t,function(s){n+=s[0],o+=s[1],r++},!0),jn([n/r,o/r],e.properties)}function ce(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if(t.type==="Feature"&&t.geometry!==null&&t.geometry.type==="Point")return[...t.geometry.coordinates];if(t.type==="Point")return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function os(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function ss(t,e,n={}){let o;return n.final?o=rs(ce(e),ce(t)):o=rs(ce(t),ce(e)),o>180?-(360-o):o}function rs(t,e){let n=pe(t[1]),o=pe(e[1]),r=pe(e[0]-t[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);let s=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),i=Math.atan2(r,s);return(Xn(i)+360)%360}function is(t,e,n={}){let o=ce(t),r=ce(e);r[0]+=r[0]-o[0]>180?-360:o[0]-r[0]>180?360:0;let s=Dl(o,r);return Zn(s,"meters",n.units)}function Dl(t,e,n){n=n===void 0?Qt:Number(n);let o=n,r=t[1]*Math.PI/180,s=e[1]*Math.PI/180,i=s-r,a=Math.abs(e[0]-t[0])*Math.PI/180;a>Math.PI&&(a-=2*Math.PI);let u=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),d=Math.abs(u)>1e-11?i/u:Math.cos(r);return Math.sqrt(i*i+d*d*a*a)*o}function ls(t,e,n,o={}){let r=e<0,s=Zn(Math.abs(e),o.units,"meters");r&&(s=-Math.abs(s));let i=ce(t),a=vl(i,s,n);return a[0]+=a[0]-i[0]>180?-360:i[0]-a[0]>180?360:0,jn(a,o.properties)}function vl(t,e,n,o){o=o===void 0?Qt:Number(o);let r=e/o,s=t[0]*Math.PI/180,i=pe(t[1]),a=pe(n),u=r*Math.cos(a),d=i+u;Math.abs(d)>Math.PI/2&&(d=d>0?Math.PI-d:-Math.PI-d);let f=Math.log(Math.tan(d/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=Math.abs(f)>1e-11?u/f:Math.cos(i),l=r*Math.sin(a)/c;return[((s+l)*180/Math.PI+540)%360-180,d*180/Math.PI]}function as(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return cs(t);case"FeatureCollection":return Vl(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return _o(t);default:throw new Error("unknown GeoJSON type")}}function cs(t){let e={type:"Feature"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:e[n]=t[n]}}),e.properties=us(t.properties),t.geometry==null?e.geometry=null:e.geometry=_o(t.geometry),e}function us(t){let e={};return t&&Object.keys(t).forEach(n=>{let o=t[n];typeof o=="object"?o===null?e[n]=null:Array.isArray(o)?e[n]=o.map(r=>r):e[n]=us(o):e[n]=o}),e}function Vl(t){let e={type:"FeatureCollection"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"features":return;default:e[n]=t[n]}}),e.features=t.features.map(n=>cs(n)),e}function _o(t){let e={type:t.type};return t.bbox&&(e.bbox=t.bbox),t.type==="GeometryCollection"?(e.geometries=t.geometries.map(n=>_o(n)),e):(e.coordinates=fs(t.coordinates),e)}function fs(t){let e=t;return typeof e[0]!="object"?e.slice():e.map(n=>fs(n))}function Ao(t,e,n){if(n=n||{},!_r(n))throw new Error("options is invalid");let o=n.pivot,r=n.mutate;if(!t)throw new Error("geojson is required");if(e==null||isNaN(e))throw new Error("angle is required");if(e===0)return t;let s=o??Qn(t);return(r===!1||r===void 0)&&(t=as(t)),Te(t,function(i){let u=ss(s,i)+e,d=is(s,i),f=os(ls(s,d,u));i[0]=f[0],i[1]=f[1]}),t}function Bo(t,e,n={}){if(n.final===!0)return Il(t,e);let o=ce(t),r=ce(e),s=pe(o[0]),i=pe(r[0]),a=pe(o[1]),u=pe(r[1]),d=Math.sin(i-s)*Math.cos(u),f=Math.cos(a)*Math.sin(u)-Math.sin(a)*Math.cos(u)*Math.cos(i-s);return Xn(Math.atan2(d,f))}function Il(t,e){let n=Bo(e,t);return n=(n+180)%360,n}function ds(t,e={}){if(t.bbox!=null&&e.recompute!==!0)return t.bbox;let n=[1/0,1/0,-1/0,-1/0];return Te(t,o=>{n[0]>o[0]&&(n[0]=o[0]),n[1]>o[1]&&(n[1]=o[1]),n[2]<o[0]&&(n[2]=o[0]),n[3]<o[1]&&(n[3]=o[1])}),n}function hs(t,e={}){let n=Number(t[0]),o=Number(t[1]),r=Number(t[2]),s=Number(t[3]);if(t.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");let i=[n,o];return $n([[i,[r,o],[r,s],[n,s],i]],e.properties,{bbox:t,id:e.id})}function ms(t){return hs(ds(t))}function xs(t){return Br(t,(e,n)=>e+Cl(n),0)}function Cl(t){let e=0,n;switch(t.type){case"Polygon":return ps(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=ps(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function ps(t){let e=0;if(t&&t.length>0){e+=Math.abs(gs(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(gs(t[n]))}return e}var Hl=Qt*Qt/2,Lo=Math.PI/180;function gs(t){let e=t.length-1;if(e<=2)return 0;let n=0,o=0;for(;o<e;){let r=t[o],s=t[o+1===e?0:o+1],i=t[o+2>=e?(o+2)%e:o+2],a=r[0]*Lo,u=s[1]*Lo,d=i[0]*Lo;n+=(d-a)*Math.sin(u),o++}return n*Hl}function ys(t){let e=ns(t);if(!e)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");let n=Qn(e),o=Ar(e),r=Number.MAX_SAFE_INTEGER,s=null;for(let i=0;i<o.length-1;i++){let a=Bo(o[i],o[i+1]),u=Ao(e,-1*a,{pivot:n}),d=ms(u),f=xs(d);f<r&&(r=f,s=Ao(d,a,{pivot:n}))}return s}function bs(t,e){let n=e[0]-t[0],o=e[1]-t[1];return Math.sqrt(n*n+o*o)}function _l(t){let e=1/0,n=-1/0,o=1/0,r=-1/0;for(let[s,i]of t)s<e&&(e=s),s>n&&(n=s),i<o&&(o=i),i>r&&(r=i);return[(n+e)*.5,(r+o)*.5]}var to=class t extends Wl{getBoxMesh(){Be.identity(),Be.setFromMatrix3(this.rotation),Be.decompose(Jn,Ne,new Nt.Vector3);let e=this.halfSize.clone().multiplyScalar(2),n=new Nt.Mesh(new Nt.BoxGeometry(e.x,e.y,e.z));return n.position.copy(this.center),n.rotation.setFromQuaternion(Ne),n}getBoxEdge(e=16776960){let n=this.getBoxMesh();Bl.setFromObject(n);let o=new Nt.EdgesGeometry(n.geometry.clone().applyMatrix4(n.matrixWorld));return new Nt.LineSegments(o,new Nt.LineBasicMaterial({color:e,toneMapped:!1}))}toJson(){return Be.identity(),Be.setFromMatrix3(this.rotation),Be.decompose(Jn,Ne,new Nt.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:Ne.toArray()}}static from(e,n,o,r=new t){if(o instanceof Nt.Euler)Ne.setFromEuler(o);else if(o instanceof Nt.Quaternion)Ne.copy(o);else throw new Error("\u4F20\u5165\u7684\u65CB\u8F6C\u4E0D\u662F\u6B27\u62C9\u89D2\u6216\u8005\u56DB\u5143\u6570");return Be.compose(n,Ne,Al),r.center.copy(n),r.halfSize.copy(e.multiplyScalar(.5)),r.rotation.setFromMatrix4(Be),r}static fromByPath2D(e,n,o,r=new t){let s=ys({type:"Polygon",coordinates:[e.map(h=>[h.x,h.y])]});if(!s)throw new Error("2d obb \u83B7\u53D6\u5931\u8D25");let i=s.geometry.coordinates[0],a=bs(i[0],i[1]),u=bs(i[1],i[2]),d=Math.atan2(i[1][1]-i[0][1],i[1][0]-i[0][0]);Jn.set(a,u,o),ws.set(0,0,d);let[f,c]=_l(i);return n.x=f,n.y=c,this.from(Jn,n,ws,r)}},Be=new Nt.Matrix4,Ne=new Nt.Quaternion,ws=new Nt.Euler,Al=new Nt.Vector3(1,1,1),Jn=new Nt.Vector3,Bl=new Nt.Box3;import"three";function Ll(t,e,n=.005,o=.2){if(!t.length||!e.length)return 0;let r=Math.max(n,.03),s=n*n,i=new Map,a=(c,l,h)=>`${Math.floor(c/r)},${Math.floor(l/r)},${Math.floor(h/r)}`;for(let c of e){let l=a(c.x,c.y,c.z);i.has(l)||i.set(l,[]),i.get(l).push(c)}let u=0,d=Math.ceil(n/r)+1,f=[];for(let c=-d;c<=d;c++)for(let l=-d;l<=d;l++)for(let h=-d;h<=d;h++)c*c+l*l+h*h<=d*d&&f.push([c,l,h]);for(let c of t){let l=Math.floor(c.x/r),h=Math.floor(c.y/r),g=Math.floor(c.z/r),x=!1;for(let[y,m,p]of f){let b=`${l+y},${h+m},${g+p}`;if(i.has(b)){for(let w of i.get(b))if(c.distanceToSquared(w)<s){x=!0;break}if(x)break}}if(x&&(u++,u/t.length>o))return u/t.length}return u/t.length}function Ie(t,e,n=.5){let o=0,r=0;for(let s of t)if(e.containsPoint(s)&&(o++,r=o/t.length,r>n))break;return r}function ko(t,e,n,o){if(t.intersectsOBB(e))return!0;{let s=Jt(t,o),i=Jt(e,n);if(s||i)return!0}return!1}function Oo(t,e){let n=new q.Vector3,o=new q.Vector3;t.getSize(n),e.getSize(o);let r=n.x*n.y*n.z,s=o.x*o.y*o.z;return r>s?1:r<s?-1:0}function Jt(t,e){let n=!0;for(let o=0;o<e.length;o++)if(!t.containsPoint(e[o])){n=!1;break}return n}function ue(t){if(t.length===0)return{x:0,y:0,z:0,h:0};let e=0,n=0,o=-1/0,r=1/0;for(let s of t)e+=s.x,n+=s.y,o=Math.max(o,s.z),r=Math.min(r,s.z);return{x:e/t.length,y:n/t.length,z:0,maxz:o,minz:r,h:o-r}}function ze(t,e,n,o){let r=[];for(let i=0;i<t.length;i++)r.push(new q.Vector3(t[i][0],t[i][1],0));if(r.length==0)return null;let s=to.fromByPath2D(r,e,n);return s.center.z=o,s}var kl=(t,e)=>{let n=new q.Group,o=new q.MeshStandardMaterial({color:16737792,side:q.DoubleSide});for(let r=0;r<t.length;r++){let s=[];for(let x=0;x<t[r].path.length;x++)s.push(new q.Vector3(t[r].path[x][0],t[r].path[x][1],0));if(s.length==0)continue;n.add(t[r].obb.getBoxEdge());let i=new q.BufferGeometry;i.setFromPoints(s);let a="green",u=new q.LineBasicMaterial({color:a,depthTest:!1,depthWrite:!1}),d=new q.Line(i,u);d.position.z=t[r].maxz,n.add(d);let f=t[r].obb.center.clone(),c=pr(t[r].type,f),l=t[r].stairBottomPt1.clone(),h=t[r].stairBottomPt2.clone();for(let x=0;x<t[r].stairStepNum;x++){let y=[l,h];y.push(h.clone().addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth)),y.push(l.clone().addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth));let m=Eo(y,t[r].stairStepHeight),p=new q.Mesh(m,o);n.add(p),l=l.addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth),l=l.addScaledVector(new q.Vector3(0,0,1),t[r].stairStepHeight),h=h.addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth),h=h.addScaledVector(new q.Vector3(0,0,1),t[r].stairStepHeight)}if(t[r].rectPt1.x!=0&&t[r].rectPt1.y!=0){let x=[t[r].stairBottomPt1,t[r].stairBottomPt2,t[r].rectPt2,t[r].rectPt1],y=Eo(x,t[r].stairStepHeight),m=new q.Mesh(y,o);n.add(m)}let g=new q.MeshBasicMaterial({color:16776960});for(let x=0;x<t[r].stairBottom1BalconyRailing.length;x++){let y=new q.CylinderGeometry(.03,.03,t[r].balconyRailingHeight,32),m=new q.Mesh(y,g);m.position.set(t[r].stairBottom1BalconyRailing[x].x,t[r].stairBottom1BalconyRailing[x].z+t[r].balconyRailingHeight/2,-t[r].stairBottom1BalconyRailing[x].y),e.add(m)}for(let x=0;x<t[r].stairBottom2BalconyRailing.length;x++){let y=new q.CylinderGeometry(.03,.03,t[r].balconyRailingHeight,32),m=new q.Mesh(y,g);m.position.set(t[r].stairBottom2BalconyRailing[x].x,t[r].stairBottom2BalconyRailing[x].z+t[r].balconyRailingHeight/2,-t[r].stairBottom2BalconyRailing[x].y),e.add(m)}}return n},Ol=(t,e,n=null)=>{if(t.length==0)return[];e||(e=t[0].averagePz);let o=[],r=new Map;for(let i=0;i<t.length;i++){let a=t[i].points.map(p=>[p.x,p.y]),u=t[i].obj_id;u=u.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").replace(/roof/g,"Ceiling");let d=u.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],f=u.indexOf("_")+1,c=u.lastIndexOf("_"),l=u.substring(f,c);if(l.includes("top")&&(f=l.indexOf("top")+4,l=l.substring(f,c)),l.includes("left")&&(f=l.indexOf("left")+5,l=l.substring(f,c)),l.includes("right")&&(f=l.indexOf("right")+6,l=l.substring(f,c)),l.includes("front")&&(f=l.indexOf("front")+6,l=l.substring(f,c)),l==="wall"||l==="stair guardrail")continue;let h=[];for(let p=0;p<t[i].points.length;p++)h.push(new q.Vector3(t[i].points[p].x,t[i].points[p].y,t[i].points[p].z));let g=-99999;if(l==="floor"){let p=new Map;for(let w=0;w<t[i].points.length;w++){let z=t[i].points[w].z;if(z=Math.floor(z*10)/10,p.has(z)){let M=p.get(z);M.num+=1,M.points.push(t[i].points[w]),p.set(z,M)}else p.set(z,{num:1,points:[t[i].points[w]]})}let b=[...p.entries()].reduce((w,z)=>z[1].num>w[1].num?z:w);a=[],a=b[1].points.map(w=>[w.x,w.y]),h=[],h=b[1].points.map(w=>new q.Vector3(w.x,w.y,w.z)),g=b[0]}let x=ue(h),y={points:h,path:me(a),h:x.h,minz:x.minz,maxz:x.maxz,center:{x:x.x,y:x.y,z:x.z},obj_id:t[i].obj_id,type:l,averagePz:e,obb:null,isDel:!1,obj_id:u,positionArr:[t[i].position],isStaircaseBalconyRailing:!1};if(y.obb=ze(y.path,y.center,y.h,(y.maxz+y.minz)/2),y.obb==null)continue;let m=-1;for(let p=0;p<o.length;p++)if(o[p].type==l){m=p;break}if(m!=-1?o[m].array.push(y):o.push({type:l,array:[y]}),l=="floor"&&g!=-99999)if(r.has(g)){let p=r.get(g);p.num+=y.points.length,p.datas.push(y),r.set(g,p)}else r.set(g,{num:y.points.length,datas:[y]})}if(r.size>0){let i=[];for(let[a,u]of r.entries()){let{num:d,datas:f}=u;d>3e3&&i.push(...f)}for(let a=0;a<o.length;a++)if(o[a].type=="floor"){o[a].array=i;break}}for(let i=0;i<o.length;i++){let a=o[i].array,u=new Set,d=[];for(let c=0;c<a.length;c++){if(a[c].obb==null||u.has(c))continue;let l={...a[c],obb:a[c].obb.clone()},h=0,g=0;if(l.type=="pipe"){let y=Ve(l.points);h=y.minZ,g=y.maxZ}let x=!0;h!=0&&g!=0&&Math.abs(g-h)<.3&&(x=!1);for(let y=c+1;y<a.length;y++){if(a[y].obb==null||u.has(y))continue;let m=0,p=0;if(a[y].type=="pipe"){let z=Ve(a[y].points);m=z.minZ,p=z.maxZ}let b=!0;if(m!=0&&p!=0&&Math.abs(p-m)<.3&&(b=!1),l.type=="pipe"&&a[y].type=="pipe"&&x!=b)continue;let w=!1;if(l.type=="pipe"&&!x?w=Ie(a[y].points,l.obb)>.3:(w=l.obb.intersectsOBB(a[y].obb,.01),w||(w=Gl(l.obb,a[y].obb))),w){u.add(y);for(let P=0;P<a[y].points.length;P++)(a[y].points[P].z>e&&a[y].points[P].z-e>.1||l.type=="floor"||l.type=="Staircase")&&l.points.push(a[y].points[P]);let z=l.points.map(P=>[P.x,P.y]);l.type=="floor"&&(z=Kl(z,.1)),l.path=me(z);let M=ue(l.points);l.h=M.h,l.minz=M.minz,l.maxz=M.maxz,l.center={x:M.x,y:M.y,z:M.z},l.obb=ze(l.path,l.center,l.h,(l.maxz+l.minz)/2),l.positionArr.push(...a[y].positionArr),y=c}}l.path.length>a[c].path.length&&(u.add(c),d.push(l))}let f=[];for(let c=0;c<a.length;c++)u.has(c)||f.push(a[c]);f.push(...d),o[i].array=f}for(let i=0;i<o.length;i++){let a=o[i].type;if(a==="people"||a==="floor")continue;let u=o[i].array;for(let d=0;d<u.length;d++){let f=u[d].obb,c=u[d].minz,l=u[d].maxz,h=u[d].averagePz;if(a==="window"||a==="door"||a==="tv"||a==="chair"||a==="cabinet"||a==="table"){let g=new q.Vector3;f.getSize(g);let x=[g.x,g.y,g.z],y=0;for(let m of x)if(m<.2&&(y++,y===2)){u[d].isDel=!0;break}}if(!u[d].isDel)for(let g=i+1;g<o.length;g++){let x=o[g].type;if(x==="people")continue;let y=o[g].array;for(let m=0;m<y.length;m++){if(y[m].isDel)continue;let p=y[m].obb,b=y[m].minz,w=y[m].maxz;if(f.intersectsOBB(p)){let z=Ie(y[m].points,f),M=Ie(u[d].points,p),P=Oo(f,p);if(M>=.5&&P==-1&&a!=="Staircase"&&x!=="Staircase"){u[d].isDel=!0;break}if(a!=="wall"&&a!=="floor"&&a!=="roof"){if(a==="window"){if(x==="balcony railing"&&Jt(f,y[m].points)){y[m].isDel=!0;continue}if(x==="balcony railing"&&Jt(p,u[d].points)){u[d].isDel=!0;break}if(x==="balcony railing"&&ko(f,p,u[d].points,y[m].points)&&(Math.abs(c-b)<.1||Math.abs(b-h)>.3)){y[m].isDel=!0;continue}if(x==="door"&&Jt(f,y[m].points)){y[m].isDel=!0;continue}if(x==="door"&&Jt(p,u[d].points)){y[m].isDel=!0;continue}if(x==="window sill")continue}else if(a==="balcony railing"){if(x==="window"&&Jt(f,y[m].points)){y[m].isDel=!0;continue}if(x==="window"&&Jt(p,u[d].points)){u[d].isDel=!0;break}if(x==="window"&&ko(f,p,u[d].points,y[m].points)&&(Math.abs(c-b)<.1||Math.abs(c-h)>.3)){u[d].isDel=!0;break}if(x==="Staircase"&&Jt(f,y[m].points)){u[d].isStaircaseBalconyRailing=!0;break}if(x==="Staircase"&&Jt(p,u[d].points)){u[d].isStaircaseBalconyRailing=!0;break}if(x==="Staircase"&&f.intersectsOBB(p)){u[d].isStaircaseBalconyRailing=!0;break}}else if(a==="door"){if(x==="window"&&Jt(f,y[m].points)){u[d].isDel=!0;break}if(x==="window"&&Jt(p,u[d].points)){u[d].isDel=!0;break}if(x==="window sill"&&Jt(f,y[m].points)){u[d].isDel=!0;break}if(x==="window sill"&&Jt(p,u[d].points)){u[d].isDel=!0;break}}else if(a==="window sill"){if(x==="window")continue;if(x==="floor"&&Jt(f,y[m].points)){y[m].isDel=!0;continue}if(x==="door"&&Jt(f,y[m].points)){y[m].isDel=!0;continue}if(x==="door"&&Jt(p,u[d].points)){y[m].isDel=!0;continue}}else if(a==="Staircase"){if(x==="balcony railing"&&Jt(f,y[m].points)){y[m].isStaircaseBalconyRailing=!0;continue}if(x==="balcony railing"&&Jt(p,u[d].points)){y[m].isStaircaseBalconyRailing=!0;continue}if(x==="balcony railing"&&f.intersectsOBB(p)){y[m].isStaircaseBalconyRailing=!0;continue}}let E=!1,S=[],I=[],W=u[d].points,v=y[m].points;if(W.length>v.length?(E=!0,S=W,I=v):(S=v,I=W),Ll(I,S,.03,.5)>.5)if(E)y[m].isDel=!0;else{u[d].isDel=!0;break}else if(ko(f,p,u[d].points,y[m].points)){let R=Oo(f,p);if(R===1||R===0){if(x==="switch"||x==="Staircase")continue;W.length>v.length?Ie(I,f)>=.5&&(y[m].isDel=!0):Ie(S,f)>=.5&&(y[m].isDel=!0)}else{if(a==="switch"||a==="Staircase")continue;if(W.length>v.length){if(Ie(S,p)>=.5){u[d].isDel=!0;break}}else if(Ie(I,p)>=.5){u[d].isDel=!0;break}}}}}}if(u[d].isDel)break}}}for(let i=0;i<o.length;i++){let a=o[i].type,u=o[i].array;for(let d=0;d<u.length;d++){let f=u[d].maxz,c=u[d].minz,l=a==="switch"?.1:.3;if(Math.abs(f-e)<l&&a!="floor"){u[d].isDel=!0;continue}if(a==="window"||a==="door"||a==="tv"){let h=Math.abs(f-e),g=Math.abs(c-e);(a==="tv"&&g<1.6||a!=="window"&&h<1.6)&&(u[d].isDel=!0),a==="window"&&h<1&&(u[d].isDel=!0),a==="door"&&g>1&&(u[d].isDel=!0)}if(a==="chair"){let h=new q.Vector3;u[d].obb.getSize(h),(h.x<.1||h.y<.1||h.z<.2)&&(u[d].isDel=!0)}if(a==="balcony railing"&&(Math.abs(f-c)<.4&&(u[d].isDel=!0),(c<e&&Math.abs(c-e)>1||c>e&&Math.abs(c-e)>1)&&(u[d].isDel=!0),f<e&&(u[d].isDel=!0)),a==="people"&&(Math.abs(f-c)<1&&(u[d].isDel=!0),c>e&&c-e>.3&&(u[d].isDel=!0),f<e&&(u[d].isDel=!0)),a==="floor"){let h=new q.Vector3;u[d].obb.getSize(h),(h.x<.1||h.y<.1)&&(u[d].isDel=!0)}a==="stair guardrail"&&u[d].points.length<100&&(u[d].isDel=!0)}}for(let i=0;i<o.length;i++)o[i].array=o[i].array.filter(a=>!a.isDel);if(n!=null)for(let i=0;i<o.length;i++){if(o[i].type=="floor")continue;let u=o[i].array,d=new Set,f=[];for(let c=0;c<u.length;c++){if(d.has(c))continue;let l=u[c].points,h=u[c].obj_id,g=u[c].type,x=u[c].averagePz,y=u[c].positionArr,m=u[c].isStaircaseBalconyRailing;if(l.length<50)continue;let p=n([l],{tolerance:.2,minClusterSize:50,maxClusterSize:1e7,threadCount:1}),b=f.length;if(p.length>0&&p[0].length>1)for(let w of p[0]){if(w.length<50)continue;let z=w.map(S=>l[S]),M=ue(z),P=z.map(S=>[S.x,S.y]),E={points:z,path:me(P),h:M.h,minz:M.minz,maxz:M.maxz,center:{x:M.x,y:M.y,z:M.z},type:g,averagePz:x,obb:null,obj_id:h,positionArr:y,isStaircaseBalconyRailing:m};E.obb=ze(E.path,E.center,E.h,(E.maxz+E.minz)/2),E.obb!=null&&f.push(E)}f.length!=b&&d.add(c)}if(d.size>0){for(let c=0;c<u.length;c++)d.has(c)||f.push(u[c]);o[i].array=f}}let s=[];for(let i=0;i<o.length;i++){let a=o[i].array;for(let u=0;u<a.length;u++)s.push({obbBox:a[u].obb,box:new q.Box3().setFromPoints(a[u].points),category:a[u].type,center:{x:a[u].center.x,y:a[u].center.y,z:(a[u].minz+a[u].maxz)/2},name:a[u].obj_id,obj_id:a[u].obj_id,pcdPoints:a[u].points,positionArr:a[u].positionArr,isStaircaseBalconyRailing:a[u].isStaircaseBalconyRailing})}return s},Fl=t=>{if(t.length==0)return[];let e=[],n=new Map;for(let r=0;r<t.length;r++){let s=t[r].points.map(y=>[y.x,y.y]),i=t[r].obj_id;i=i.replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor");let a=i.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],u=i.indexOf("_")+1,d=i.lastIndexOf("_"),f=i.substring(u,d);if(f!=="floor")continue;let c=[];for(let y=0;y<t[r].points.length;y++)c.push(new q.Vector3(t[r].points[y].x,t[r].points[y].y,t[r].points[y].z));let l=-99999;if(f==="floor"){let y=new Map;for(let p=0;p<t[r].points.length;p++){let b=t[r].points[p].z;if(b=Math.floor(b*10)/10,y.has(b)){let w=y.get(b);w.num+=1,w.points.push(t[r].points[p]),y.set(b,w)}else y.set(b,{num:1,points:[t[r].points[p]]})}let m=[...y.entries()].reduce((p,b)=>b[1].num>p[1].num?b:p);s=[],s=m[1].points.map(p=>[p.x,p.y]),c=[],c=m[1].points.map(p=>new q.Vector3(p.x,p.y,p.z)),l=m[0]}let h=ue(c),g={points:c,path:me(s),h:h.h,minz:h.minz,maxz:h.maxz,center:{x:h.x,y:h.y,z:h.z},obj_id:t[r].obj_id,type:f,obb:null,isDel:!1,obj_id:i,positionArr:[t[r].position]};if(g.obb=ze(g.path,g.center,g.h,(g.maxz+g.minz)/2),g.obb==null)continue;let x=-1;for(let y=0;y<e.length;y++)if(e[y].type==f){x=y;break}if(x!=-1?e[x].array.push(g):e.push({type:f,array:[g]}),f=="floor"&&l!=-99999)if(n.has(l)){let y=n.get(l);y.num+=g.points.length,y.datas.push(g),n.set(l,y)}else n.set(l,{num:g.points.length,datas:[g]})}for(let r=0;r<e.length;r++){let s=e[r].array,i=[],a=[];for(let d=0;d<s.length;d++){if(s[d].obb==null||i.includes(d))continue;let f={...s[d],obb:s[d].obb.clone()};for(let c=d+1;c<s.length;c++){if(s[c].obb==null||i.includes(c))continue;if(f.obb.intersectsOBB(s[c].obb)){i.push(c);for(let x=0;x<s[c].points.length;x++)f.points.push(s[c].points[x]);let h=f.points.map(x=>[x.x,x.y]);f.path=me(h);let g=ue(f.points);f.h=g.h,f.minz=g.minz,f.maxz=g.maxz,f.center={x:g.x,y:g.y,z:g.z},f.obb=ze(f.path,f.center,f.h,(f.maxz+f.minz)/2),f.positionArr.push(...s[c].positionArr),c=d}}f.path.length>s[d].path.length&&(i.push(d),a.push(f))}let u=[];for(let d=0;d<s.length;d++)i.includes(d)||u.push(s[d]);u.push(...a),e[r].array=u}for(let r=0;r<e.length;r++){let s=e[r].type,i=e[r].array;for(let a=0;a<i.length;a++)s==="floor"&&i[a].points.length<500&&(i[a].isDel=!0)}for(let r=0;r<e.length;r++)e[r].array=e[r].array.filter(s=>!s.isDel);let o=[];for(let r=0;r<e.length;r++){let s=e[r].array;for(let i=0;i<s.length;i++)o.push({obbBox:s[i].obb,box:new q.Box3().setFromPoints(s[i].points),category:s[i].type,center:{x:s[i].center.x,y:s[i].center.y,z:(s[i].minz+s[i].maxz)/2},name:s[i].obj_id,obj_id:s[i].obj_id,pcdPoints:s[i].points,positionArr:s[i].positionArr})}return o},Nl=(t,e)=>{if(!t||!t.splitFloorProjectsResults||!t.trajectoryResults)return[];let n=t.splitFloorProjectsResults,o=t.trajectoryResults,r=new Map;for(let l=0;l<o.length;l++){let h=o[l].floor;r.has(h)?r.get(h).push(o[l]):r.set(h,[o[l]])}let s=new Map,i=[];for(let l=0;l<n.length;l++){let h=[],g=n[l];for(let x=0;x<g.length;x++){let y=g[x].points.map(S=>[S.x,S.y]),m=g[x].obj_id;m=m.replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor").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");let p=m.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],b=m.indexOf("_")+1,w=m.lastIndexOf("_"),z=m.substring(b,w);if(z.includes("top")&&(b=z.indexOf("top")+4,z=z.substring(b,w)),z.includes("left")&&(b=z.indexOf("left")+5,z=z.substring(b,w)),z.includes("right")&&(b=z.indexOf("right")+6,z=z.substring(b,w)),z.includes("front")&&(b=z.indexOf("front")+6,z=z.substring(b,w)),z!=="Staircase"&&z!=="balcony railing")continue;let M=[];for(let S=0;S<g[x].points.length;S++)M.push(new q.Vector3(g[x].points[S].x,g[x].points[S].y,g[x].points[S].z));let P=ue(M),E={points:M,path:me(y),h:P.h,minz:P.minz,maxz:P.maxz,center:{x:P.x,y:P.y,z:P.z},obj_id:g[x].obj_id,type:z,averagePz:0,obb:null,isDel:!1,obj_id:m,positionArr:[g[x].position],aabbBox:new q.Box3().setFromPoints(M)};E.obb=ze(E.path,E.center,E.h,(E.maxz+E.minz)/2),E.obb!=null&&(z=="Staircase"?h.push(E):z=="balcony railing"&&i.push(E))}s.set(l+1,h)}let a=[];for(let[l,h]of s){let g={floor:l,findTrajectoryResults:[],otherTrajectoryResults:[],lastTrajectoryResults:[]},x=r.get(l);if(!x){g.otherTrajectoryResults=h,a.push(g);continue}let y=[],m=[],p=[];for(let b=0;b<x.length;b++){let w=[];for(let M=0;M<x[b].points.length;M++){let P=[new q.Vector3(x[b].points[M].x,x[b].points[M].y,x[b].points[M].z)];P.push(P[0].clone().addScaledVector(new q.Vector3(0,0,-1),2));let E=new q.Box3().setFromPoints(P);w.push(E)}let z=[];for(let M=0;M<h.length;M++)for(let P=0;P<w.length;P++)!p.includes(M)&&h[M].aabbBox.intersectsBox(w[P])&&(p.push(M),z.push(h[M]));z.length>0&&m.push(z)}for(let b=0;b<h.length;b++)p.includes(b)||y.push(h[b]);g.findTrajectoryResults=m,g.otherTrajectoryResults=y,a.push(g)}function u(l,h){let g=l,x=[],y=[];for(let p=0;p<l.length;p++){if(l[p].obb==null||x.includes(p))continue;let b={...l[p],obb:l[p].obb.clone()};for(let w=p+1;w<l.length;w++){if(l[w].obb==null||x.includes(w))continue;if(b.obb.intersectsOBB(l[w].obb)||h){x.push(w);for(let E=0;E<l[w].points.length;E++)b.points.push(l[w].points[E]);let M=b.points.map(E=>[E.x,E.y]);b.path=me(M);let P=ue(b.points);b.h=P.h,b.minz=P.minz,b.maxz=P.maxz,b.center={x:P.x,y:P.y,z:P.z},b.obb=ze(b.path,b.center,b.h,(b.maxz+b.minz)/2),b.positionArr.push(...l[w].positionArr),w=p}}b.path.length>l[p].path.length&&(x.push(p),y.push(b))}let m=[];for(let p=0;p<l.length;p++)x.includes(p)||m.push(l[p]);return m.push(...y),l=m,l}for(let l=0;l<a.length;l++){for(let h=0;h<a[l].findTrajectoryResults.length;h++)a[l].findTrajectoryResults[h]=u(a[l].findTrajectoryResults[h],!0);a[l].otherTrajectoryResults=u(a[l].otherTrajectoryResults,!1)}for(let l=0;l<a.length;l++){for(let h=0;h<a[l].findTrajectoryResults.length;h++){for(let g=0;g<a[l].findTrajectoryResults[h].length;g++){let x=zs(a[l].findTrajectoryResults[h][g].points,{binCount:100,minBinPoints:5,sideK:2.2,zK:2.2,minSideRange:.2,minZRange:.2,lowerZScale:.4,upperZScale:1.8}),y=Ms(x.keep,{radius:.1,minClusterSize:50,lowPercent:.45});if(y.keep.length==0){a[l].findTrajectoryResults[h][g].isDel=!0;continue}a[l].findTrajectoryResults[h][g].points=y.keep;let m=a[l].findTrajectoryResults[h][g].points.map(b=>[b.x,b.y]);a[l].findTrajectoryResults[h][g].path=me(m);let p=ue(a[l].findTrajectoryResults[h][g].points);a[l].findTrajectoryResults[h][g].h=p.h,a[l].findTrajectoryResults[h][g].minz=p.minz,a[l].findTrajectoryResults[h][g].maxz=p.maxz,a[l].findTrajectoryResults[h][g].center={x:p.x,y:p.y,z:p.z},a[l].findTrajectoryResults[h][g].obb=ze(a[l].findTrajectoryResults[h][g].path,a[l].findTrajectoryResults[h][g].center,a[l].findTrajectoryResults[h][g].h,(a[l].findTrajectoryResults[h][g].maxz+a[l].findTrajectoryResults[h][g].minz)/2)}a[l].findTrajectoryResults[h]=a[l].findTrajectoryResults[h].filter(g=>!g.isDel)}for(let h=0;h<a[l].otherTrajectoryResults.length;h++){let g=zs(a[l].otherTrajectoryResults[h].points,{binCount:100,minBinPoints:5,sideK:2.2,zK:2.2,minSideRange:.2,minZRange:.2,lowerZScale:.4,upperZScale:1.8}),x=Ms(g.keep,{radius:.1,minClusterSize:50,lowPercent:.45});if(x.keep.length==0){a[l].otherTrajectoryResults[h].isDel=!0;continue}a[l].otherTrajectoryResults[h].points=x.keep;let y=a[l].otherTrajectoryResults[h].points.map(p=>[p.x,p.y]);a[l].otherTrajectoryResults[h].path=me(y);let m=ue(a[l].otherTrajectoryResults[h].points);a[l].otherTrajectoryResults[h].h=m.h,a[l].otherTrajectoryResults[h].minz=m.minz,a[l].otherTrajectoryResults[h].maxz=m.maxz,a[l].otherTrajectoryResults[h].center={x:m.x,y:m.y,z:m.z},a[l].otherTrajectoryResults[h].obb=ze(a[l].otherTrajectoryResults[h].path,a[l].otherTrajectoryResults[h].center,a[l].otherTrajectoryResults[h].h,(a[l].otherTrajectoryResults[h].maxz+a[l].otherTrajectoryResults[h].minz)/2)}a[l].otherTrajectoryResults.filter(h=>!h.isDel)}function d(l){for(let h=0;h<l.length;h++){let g=l[h].obb;for(let x=h+1;x<l.length;x++){let y=l[x].obb;if(!l[x].isDel){if(g.intersectsOBB(y)){let m=Ie(l[x].points,g),p=Ie(l[h].points,y),b=Oo(g,y);if(m>=.5&&(b==1||b==0)&&(l[x].isDel=!0),p>=.5&&b==-1){l[h].isDel=!0;break}}if(l[h].isDel)break}}}return l=l.filter(h=>!h.isDel),l}for(let l=0;l<a.length;l++){let h=[];for(let g=0;g<a[l].findTrajectoryResults.length;g++)h.push(...a[l].findTrajectoryResults[g]);h.push(...a[l].otherTrajectoryResults),a[l].lastTrajectoryResults=d(h)}function f(l){let h=[];if(l.length>0){let g=.3,x=.5,y=.5,m=.2;for(let p=0;p<l.length;p++){let b=l[p].obb.halfSize.clone().multiplyScalar(2),w=l[p].points,z=b.x,M=b.y,P=b.z;if(z>M&&([z,M]=[M,z]),z<x||M<g||P<y)continue;let E=wr(l[p].obb);if(E.length!=8)continue;let S=new q.Line3(E[0],E[1]),I=new q.Line3(E[1],E[2]),W=new q.Line3(E[2],E[3]),v=new q.Line3(E[3],E[0]),T=new q.Line3(E[4],E[5]),R=new q.Line3(E[5],E[6]),D=new q.Line3(E[6],E[7]),H=new q.Line3(E[7],E[4]),V=[],C=[],_=[],A=[],L=[],k=[],F=[],B=[];for(let wt=0;wt<w.length;wt++){let te=S.closestPointToPoint(w[wt],!0,new q.Vector3),ge=I.closestPointToPoint(w[wt],!0,new q.Vector3),Dt=W.closestPointToPoint(w[wt],!0,new q.Vector3),ne=v.closestPointToPoint(w[wt],!0,new q.Vector3),xe=T.closestPointToPoint(w[wt],!0,new q.Vector3),tt=R.closestPointToPoint(w[wt],!0,new q.Vector3),mn=D.closestPointToPoint(w[wt],!0,new q.Vector3),Je=H.closestPointToPoint(w[wt],!0,new q.Vector3);te.distanceTo(w[wt])<m&&V.push(w[wt]),ge.distanceTo(w[wt])<m&&C.push(w[wt]),Dt.distanceTo(w[wt])<m&&_.push(w[wt]),ne.distanceTo(w[wt])<m&&A.push(w[wt]),xe.distanceTo(w[wt])<m&&L.push(w[wt]),tt.distanceTo(w[wt])<m&&k.push(w[wt]),mn.distanceTo(w[wt])<m&&F.push(w[wt]),Je.distanceTo(w[wt])<m&&B.push(w[wt])}let O=E[0].distanceTo(E[1]),$=E[1].distanceTo(E[2]),Z=E[2].distanceTo(E[3]),Q=E[3].distanceTo(E[0]),j=new q.Vector3,X=new q.Vector3,U=new q.Vector3,at=new q.Vector3;Math.abs(O-z)<.01?V.length>_.length?(j=E[0].clone(),X=E[1].clone(),U=new q.Vector3().subVectors(X,j).normalize(),at=new q.Vector3().subVectors(E[2],E[1]).normalize()):(j=E[2].clone(),X=E[3].clone(),U=new q.Vector3().subVectors(X,j).normalize(),at=new q.Vector3().subVectors(E[0],E[3]).normalize()):C.length>A.length?(j=E[1].clone(),X=E[2].clone(),U=new q.Vector3().subVectors(X,j).normalize(),at=new q.Vector3().subVectors(E[3],E[2]).normalize()):(j=E[3].clone(),X=E[0].clone(),U=new q.Vector3().subVectors(X,j).normalize(),at=new q.Vector3().subVectors(E[1],E[0]).normalize());let mt=E[4].distanceTo(E[5]),St=E[5].distanceTo(E[6]),ot=E[6].distanceTo(E[7]),Mt=E[7].distanceTo(E[4]),bt=new q.Vector3,Ct=new q.Vector3,Et=new q.Vector3(j.x,j.y,E[4].z),zt=new q.Vector3(X.x,X.y,E[4].z);(ct(E[4],Et)||ct(E[4],zt))&&(ct(E[5],Et)||ct(E[5],zt))?(bt=E[6].clone(),Ct=E[7].clone()):(ct(E[5],Et)||ct(E[5],zt))&&(ct(E[6],Et)||ct(E[6],zt))?(bt=E[7].clone(),Ct=E[4].clone()):(ct(E[6],Et)||ct(E[6],zt))&&(ct(E[7],Et)||ct(E[7],zt))?(bt=E[4].clone(),Ct=E[5].clone()):(ct(E[7],Et)||ct(E[7],zt))&&(ct(E[4],Et)||ct(E[4],zt))&&(bt=E[5].clone(),Ct=E[6].clone());let Pt=j.distanceTo(X),et=bt.distanceTo(Ct),ht=new q.Vector3().subVectors(new q.Vector3(j.x,j.y,bt.z),j).normalize();if(Math.abs(Pt-et)>.01||Math.abs(Pt-z)>.01){console.log("\u4E0A\u4E0B\u957F\u5EA6\u4E0D\u4E00\u81F4,\u6216\u4E0E\u5BBD\u4E0D\u4E00\u81F4",Pt,et,z);continue}let nt=Math.sqrt(Pt*Pt+et*et),J=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(nt)))),le={stairStepHeight:P/J,stairStepWidth:M/J,staitWidth:z,stairLength:M,stairHeigth:P,stairStepNum:J,stairBottomPt1:j,stairBottomPt2:X,stairTopPt1:bt,stairTopPt2:Ct,vecStepLength:U,vecStepWidth:at,vecStepHeight:ht,path:l[p].path,obb:l[p].obb,maxz:l[p].maxz,points:l[p].points,rectPt1:new q.Vector3(0,0,0),rectPt2:new q.Vector3(0,0,0)};h.push(le)}}return h}let c=[];for(let l=0;l<a.length;l++)c.push(...f(a[l].lastTrajectoryResults));for(let l=0;l<c.length;l++){let h=c[l].stairTopPt1.clone(),g=c[l].stairTopPt2.clone(),x=c[l].stairBottomPt1.clone(),y=c[l].stairBottomPt2.clone(),m=h.clone(),p=g.clone(),b=x.clone(),w=y.clone();m.z=p.z=b.z=w.z=0;let z=At(h,g,!0),M=At(x,y,!0),P=At(z,M),E=new q.Vector3().subVectors(z,P).normalize(),S=new q.Vector3().subVectors(M,P).normalize(),I=z.distanceTo(M),W=!1,v=!1;for(let T=0;T<c.length;T++){if(l==T)continue;let R=c[T].stairTopPt1.clone(),D=c[T].stairTopPt2.clone(),H=c[T].stairBottomPt1.clone(),V=c[T].stairBottomPt2.clone(),C=new q.Vector3().subVectors(R,D).normalize(),_=new q.Vector3().subVectors(H,V).normalize(),A=R.clone(),L=D.clone(),k=H.clone(),F=V.clone();A.z=L.z=k.z=F.z=0;let B=At(R,D,!0),O=At(H,V,!0),$=B.distanceTo(O),Z=Zt(z,M,B,O),Q=!1;if(Z&&Z.isParallel&&R.z<=x.z&&x.z-R.z<.3){Q=!0,v=!0;let j=A.addScaledVector(C.clone().negate(),100),X=L.addScaledVector(C,100),U=k.addScaledVector(_.clone().negate(),100),at=F.addScaledVector(_,100),mt=new q.Line3(j,X),St=new q.Line3(U,at),ot=mt.closestPointToPoint(P,!0,new q.Vector3),Mt=St.closestPointToPoint(P,!0,new q.Vector3),bt=new q.Vector3().subVectors(ot,P),Ct=new q.Vector3().subVectors(Mt,P),Et=bt.length(),zt=Ct.length();Ct=Ct.normalize(),bt=bt.normalize();let Pt=Xt(E,bt,.1),et=Xt(S,bt,.1),ht=Xt(S,Ct,.1),nt=Xt(E,Ct,.1);if(Pt&&Pt.sameDirection&&Et>I/2){let J=Et-I/2;c[l].stairBottomPt1=c[l].stairBottomPt1.addScaledVector(S,J),c[l].stairBottomPt2=c[l].stairBottomPt2.addScaledVector(S,J)}else if(et&&et.sameDirection&&Et>I/2){let J=Et-I/2;c[l].stairBottomPt1=c[l].stairBottomPt1.addScaledVector(S,J),c[l].stairBottomPt2=c[l].stairBottomPt2.addScaledVector(S,J)}if(ht&&ht.sameDirection&&zt>I/2){let J=zt-I/2;c[l].stairTopPt1=c[l].stairTopPt1.addScaledVector(E,J),c[l].stairTopPt2=c[l].stairTopPt2.addScaledVector(E,J)}else if(nt&&nt.sameDirection&&zt>I/2){let J=zt-I/2;c[l].stairTopPt1=c[l].stairTopPt1.addScaledVector(E,J),c[l].stairTopPt2=c[l].stairTopPt2.addScaledVector(E,J)}}else if(Z&&Z.isParallel&&h.z<H.z&&H.z-h.z<.2){Q=!0,W=!0;let j=A.addScaledVector(C.clone().negate(),100),X=L.addScaledVector(C,100),U=k.addScaledVector(_.clone().negate(),100),at=F.addScaledVector(_,100),mt=new q.Line3(j,X),St=new q.Line3(U,at),ot=mt.closestPointToPoint(P,!1,new q.Vector3),Mt=St.closestPointToPoint(P,!1,new q.Vector3),bt=new q.Vector3().subVectors(ot,P),Ct=new q.Vector3().subVectors(Mt,P),Et=bt.length(),zt=Ct.length();Ct=Ct.normalize(),bt=bt.normalize();let Pt=Xt(E,bt,.1),et=Xt(S,bt,.1),ht=Xt(S,Ct,.1),nt=Xt(E,Ct,.1);if(Pt&&Pt.sameDirection&&Et>I/2){let J=Et-I/2;c[l].stairBottomPt1=c[l].stairBottomPt1.addScaledVector(S,J),c[l].stairBottomPt2=c[l].stairBottomPt2.addScaledVector(S,J)}else if(et&&et.sameDirection&&Et>I/2){let J=Et-I/2;c[l].stairBottomPt1=c[l].stairBottomPt1.addScaledVector(S,J),c[l].stairBottomPt2=c[l].stairBottomPt2.addScaledVector(S,J)}if(ht&&ht.sameDirection&&zt>I/2){let J=zt-I/2;c[l].stairTopPt1=c[l].stairTopPt1.addScaledVector(E,J),c[l].stairTopPt2=c[l].stairTopPt2.addScaledVector(E,J)}else if(nt&&nt.sameDirection&&zt>I/2){let J=zt-I/2;c[l].stairTopPt1=c[l].stairTopPt1.addScaledVector(E,J),c[l].stairTopPt2=c[l].stairTopPt2.addScaledVector(E,J)}c[l].stairTopPt1.z=c[l].stairTopPt2.z=H.z}if(Q&&(h=c[l].stairTopPt1.clone(),g=c[l].stairTopPt2.clone(),x=c[l].stairBottomPt1.clone(),y=c[l].stairBottomPt2.clone(),m=h.clone(),p=g.clone(),b=x.clone(),w=y.clone(),m.z=p.z=b.z=w.z=0,z=At(h,g,!0),M=At(x,y,!0),P=At(z,M),E=new q.Vector3().subVectors(z,P).normalize(),S=new q.Vector3().subVectors(M,P).normalize(),I=z.distanceTo(M)),v&&W)break}if(v||W){let T=c[l].stairTopPt1.clone(),R=c[l].stairTopPt2.clone(),D=c[l].stairBottomPt1.clone(),H=c[l].stairBottomPt2.clone(),V=At(T,R,!0),C=At(D,H,!0),_=V.distanceTo(C),A=c[l].stairTopPt1.distanceTo(c[l].stairTopPt2),L=c[l].stairBottomPt1.distanceTo(c[l].stairBottomPt2),k=Math.sqrt(A*A+L*L),F=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(k))));c[l].stairStepNum=F,c[l].stairHeigth=c[l].stairTopPt1.z-c[l].stairBottomPt1.z,c[l].stairStepHeight=c[l].stairHeigth/c[l].stairStepNum,c[l].stairStepWidth=_/c[l].stairStepNum}}for(let l=0;l<c.length;l++){let h=c[l].stairTopPt1,g=c[l].stairTopPt2,x=c[l].stairBottomPt1.clone(),y=c[l].stairBottomPt2.clone(),m=new q.Vector3(h.x,h.y,x.z),p=c[l].vecStepWidth;for(let b=0;b<c.length;b++){if(l==b)continue;let w=c[b].stairTopPt1,z=c[b].stairTopPt2,M=c[b].stairBottomPt1.clone(),P=c[b].stairBottomPt2.clone(),E=new q.Vector3(w.x,w.y,M.z),S=c[b].vecStepWidth;if(Math.abs(h.z-M.z)<.3&&M.z>x.z&&c[l].obb.intersectsOBB(c[b].obb)){let I=ie(m,x,E,M);if(I&&I.angle>75){let W=M.distanceTo(h),v=M.distanceTo(g),T=P.distanceTo(h),R=P.distanceTo(g),D=h.clone(),H=D.clone().addScaledVector(p,c[b].staitWidth),V=new q.Vector3().subVectors(g,h).normalize(),C=h.distanceTo(g),_=D.clone().addScaledVector(V,C),A=H.clone().addScaledVector(V,C),L=D.clone().addScaledVector(V,c[b].stairLength),k=H.clone().addScaledVector(V,c[b].stairLength),F=W;(F>v||F>R)&&(F=v,D=g.clone(),H=D.clone().addScaledVector(p,c[b].staitWidth),V=new q.Vector3().subVectors(h,g).normalize(),C=h.distanceTo(g),_=D.clone().addScaledVector(V,C),A=H.clone().addScaledVector(V,C),L=D.clone().addScaledVector(V,c[b].stairLength),k=H.clone().addScaledVector(V,c[b].stairLength));let B=new q.Vector3().subVectors(L,_).normalize(),O=L.distanceTo(_);L.z=k.z=c[b].maxz,c[b].stairBottomPt1=_,c[b].stairBottomPt2=A,c[b].stairTopPt1=L,c[b].stairTopPt2=k,c[b].rectPt1=D,c[b].rectPt2=H;let $=_.distanceTo(A),Z=L.distanceTo(k),Q=Math.sqrt(O*O+c[b].stairHeigth*c[b].stairHeigth),j=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(Q))));c[b].stairStepNum=j,c[b].stairHeigth=L.z-_.z,c[b].stairStepHeight=c[b].stairHeigth/c[b].stairStepNum,c[b].stairStepWidth=O/c[b].stairStepNum,c[b].vecStepLength=V.clone().negate(),c[b].vecStepWidth=B;break}}}}return t.finalFloorMap&&jl(c,t.finalFloorMap),ql(c,i,e),c},ql=(t,e,n)=>{if(!t||t.length<=0||!e||e.length<=0)return;let o=1.5,r=0;for(let s=0;s<t.length;s++){t[s].stairBottom1BalconyRailing=[],t[s].stairBottom2BalconyRailing=[],t[s].balconyRailingHeight=0;let i=t[s].stairBottomPt1.clone(),a=t[s].stairBottomPt2.clone(),u=t[s].stairBottomPt1.clone(),d=t[s].stairBottomPt2.clone(),f=new q.Vector3().subVectors(a,i).normalize();i=i.addScaledVector(f,.05),a=a.addScaledVector(f.clone().negate(),.05);let c=[],l=[];for(let h=0;h<t[s].stairStepNum;h++){let g=[i,u];g.push(g[1].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),g.push(g[0].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth));let x=g.map(z=>[z.x,z.y]);g.push(new q.Vector3(g[3].x,g[3].y,g[3].z+o)),g.push(new q.Vector3(g[2].x,g[2].y,g[2].z+o)),g.push(new q.Vector3(g[1].x,g[1].y,g[1].z+o)),g.push(new q.Vector3(g[0].x,g[0].y,g[0].z+o));let y=ue(g),m=ze(x,{x:y.x,y:y.y,z:y.z},y.h,(y.maxz+y.minz)/2),p=[],b=!1,w=0;for(let z=0;z<e.length;z++)if(m.intersectsOBB(e[z].obb)){for(let M=0;M<e[z].points.length&&!(m.containsPoint(e[z].points[M])&&(h==0&&p.push(e[z].points[M]),e[z].points[M].z>i.z&&e[z].points[M].z-i.z<1&&(w++,w>10&&h!=0)));M++);if(w>10&&(b=!0),h!=0&&b)break}if(r==0&&(r=ue(p).maxz),b){let z=At(g[1],g[2]);z.z+=t[s].stairStepHeight,c.push(z)}g=[],g=[a,d],g.push(g[1].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),g.push(g[0].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),x=g.map(z=>[z.x,z.y]),g.push(new q.Vector3(g[3].x,g[3].y,g[3].z+o)),g.push(new q.Vector3(g[2].x,g[2].y,g[2].z+o)),g.push(new q.Vector3(g[1].x,g[1].y,g[1].z+o)),g.push(new q.Vector3(g[0].x,g[0].y,g[0].z+o)),y=ue(g),m=ze(x,{x:y.x,y:y.y,z:y.z},y.h,(y.maxz+y.minz)/2),p=[],b=!1;for(let z=0;z<e.length;z++)if(m.intersectsOBB(e[z].obb)){let M=0;for(let P=0;P<e[z].points.length&&!(m.containsPoint(e[z].points[P])&&(h==0&&p.push(e[z].points[P]),e[z].points[P].z>i.z&&e[z].points[P].z-i.z<1&&(M++,M>10&&h!=0)));P++);if(M>10&&(b=!0),h!=0&&b)break}if(r==0&&(r=ue(p).maxz),b){let z=At(g[1],g[2]);z.z+=t[s].stairStepHeight,l.push(z)}i=i.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),i=i.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),a=a.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),a=a.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),u=u.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),u=u.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),d=d.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),d=d.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight)}c.length>t[s].stairStepNum-3&&(t[s].stairBottom1BalconyRailing=c),l.length>t[s].stairStepNum-3&&(t[s].stairBottom2BalconyRailing=l),t[s].balconyRailingHeight=r}};function jl(t,e){if(!t||!e)return;let n=[];for(let o=0;o<t.length;o++){let r=t[o].stairTopPt1.clone(),s=t[o].stairTopPt2.clone(),i=t[o].stairBottomPt1.clone(),a=t[o].stairBottomPt2.clone(),u=r.clone(),d=s.clone(),f=i.clone(),c=a.clone();u.z=d.z=f.z=c.z=0;let l=At(r,s,!0),h=At(i,a,!0),g=At(l,h),x=new q.Vector3().subVectors(l,g).normalize(),y=new q.Vector3().subVectors(h,g).normalize(),m=l.distanceTo(h),p=-1,b=-1;for(let w=0;w<t.length;w++){if(o==w)continue;let z=t[w].stairTopPt1.clone(),M=t[w].stairTopPt2.clone(),P=t[w].stairBottomPt1.clone(),E=t[w].stairBottomPt2.clone(),S=new q.Vector3().subVectors(z,M).normalize(),I=new q.Vector3().subVectors(P,E).normalize(),W=z.clone(),v=M.clone(),T=P.clone(),R=E.clone();W.z=v.z=T.z=R.z=0;let D=At(z,M,!0),H=At(P,E,!0),V=D.distanceTo(H),C=Zt(l,h,D,H);if(C&&C.isParallel&&r.z<=P.z&&P.z-r.z<=.2?p=w:C&&C.isParallel&&z.z<=i.z&&i.z-z.z<=.3&&(b=w),p!=-1&&b!=-1)break}for(let w=0;w<e.length;w++){let z=e[w][1];for(let M=0;M<z.length;M++){let P=`${w}+${M}`;if(n.includes(P))continue;let E=z[M].points;if(o==0&&Math.abs(E[0].z-i.z)<.2){let S=i.clone().addScaledVector(t[o].vecStepWidth.clone().negate(),5),I=a.clone().addScaledVector(t[o].vecStepWidth.clone().negate(),5),W=new q.Line3(S,I),v=new q.Line3(i,a),T=999999,R=0,D=new q.Vector3,H=0;for(let V=0;V<E.length;V++){let C=new q.Vector3(E[V].x,E[V].y,S.z),A=W.closestPointToPoint(C,!1,new q.Vector3).distanceTo(C),L=v.closestPointToPoint(C,!1,new q.Vector3),k=new q.Vector3().subVectors(C,L).normalize(),F=Xt(k,t[o].vecStepWidth.clone().negate(),.1);A<T&&F.sameDirection&&(T=A,R=C.distanceTo(L),D=C.clone(),H=E[V].z)}T!=-999999&&(n.push(P),t[o].stairBottomPt1.z=t[o].stairBottomPt2.z=H)}else if(Math.abs(E[0].z-r.z)<.2){let S=r.clone().addScaledVector(t[o].vecStepWidth,5),I=s.clone().addScaledVector(t[o].vecStepWidth,5),W=new q.Line3(S,I),v=new q.Line3(r,s),T=0,R=999999,D=new q.Vector3,H=0;for(let V=0;V<E.length;V++){let C=new q.Vector3(E[V].x,E[V].y,S.z),_=W.closestPointToPoint(C,!1,new q.Vector3),A=v.closestPointToPoint(C,!1,new q.Vector3),L=new q.Vector3().subVectors(C,A).normalize(),k=_.distanceTo(C),F=Xt(L,t[o].vecStepWidth);k<R&&F.sameDirection&&(R=k,T=C.distanceTo(A),D=C,H=E[V].z)}if(R!=-999999){if(n.push(P),t[o].stairTopPt1.z=t[o].stairTopPt2.z=H,p!=-1){t[p].stairBottomPt1.z=t[p].stairBottomPt2.z=H;let V=[t[o].stairTopPt1.clone(),t[o].stairTopPt2.clone(),t[p].stairBottomPt1.clone(),t[p].stairBottomPt2.clone()],C=We(V);C.length==2&&(t[o].stairTopFloorPts=C,t[o].stairTopFloorPts.push(t[o].stairTopFloorPts[1].clone().addScaledVector(t[o].vecStepWidth,T)),t[o].stairTopFloorPts.push(t[o].stairTopFloorPts[0].clone().addScaledVector(t[o].vecStepWidth,T)))}else t[o].stairTopFloorPts=[t[o].stairTopPt1.clone(),t[o].stairTopPt2.clone()],t[o].stairTopFloorPts.push(t[o].stairTopPt2.clone().addScaledVector(t[o].vecStepWidth,T)),t[o].stairTopFloorPts.push(t[o].stairTopPt1.clone().addScaledVector(t[o].vecStepWidth,T));if(t[o].stairTopFloorPts)for(let V=0;V<t[o].stairTopFloorPts.length;V++)t[o].stairTopFloorPts[V].z-=t[o].stairStepHeight;break}}}}if(p!=-1){let w=t[o].stairTopPt1.clone(),z=t[o].stairTopPt2.clone(),M=t[o].stairBottomPt1.clone(),P=t[o].stairBottomPt2.clone(),E=At(w,z,!0),S=At(M,P,!0),I=E.distanceTo(S),W=t[o].stairTopPt1.distanceTo(t[o].stairTopPt2),v=t[o].stairBottomPt1.distanceTo(t[o].stairBottomPt2),T=Math.sqrt(W*W+v*v),R=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(T))));t[o].stairStepNum=R,t[o].stairHeigth=t[o].stairTopPt1.z-t[o].stairBottomPt1.z,t[o].stairStepHeight=t[o].stairHeigth/t[o].stairStepNum,t[o].stairStepWidth=I/t[o].stairStepNum;let D=t[p].stairTopPt1.clone(),H=t[p].stairTopPt2.clone(),V=t[p].stairBottomPt1.clone(),C=t[p].stairBottomPt2.clone(),_=At(D,H,!0),A=At(V,C,!0),L=_.distanceTo(A),k=t[p].stairTopPt1.distanceTo(t[p].stairTopPt2),F=t[p].stairBottomPt1.distanceTo(t[p].stairBottomPt2),B=Math.sqrt(k*k+F*F),O=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(B))));t[p].stairStepNum=O,t[p].stairHeigth=t[p].stairTopPt1.z-t[p].stairBottomPt1.z,t[p].stairStepHeight=t[p].stairHeigth/t[p].stairStepNum,t[p].stairStepWidth=L/t[p].stairStepNum}}}function zs(t,e={}){let{binCount:n=80,minBinPoints:o=5,sideK:r=3,zK:s=3,minSideRange:i=.2,minZRange:a=.2,maxSearchBins:u=3,lowerZScale:d=1,upperZScale:f=1}=e;if(!t||t.length===0)return[];let c=t.map((_,A)=>({index:A,x:_.x,y:_.y,z:_.z,raw:_})),l=0,h=0;for(let _ of c)l+=_.x,h+=_.y;l/=c.length,h/=c.length;let g=0,x=0,y=0;for(let _ of c){let A=_.x-l,L=_.y-h;g+=A*A,x+=A*L,y+=L*L}g/=c.length,x/=c.length,y/=c.length;let m=g+y,p=Math.sqrt((g-y)*(g-y)+4*x*x),b=(m+p)/2,w,z;Math.abs(x)>1e-8?(w=b-y,z=x):g>=y?(w=1,z=0):(w=0,z=1);let M=Math.sqrt(w*w+z*z)||1;w/=M,z/=M;let P=-z,E=w,S=1/0,I=-1/0,W=c.map(_=>{let A=_.x-l,L=_.y-h,k=A*w+L*z,F=A*P+L*E;return S=Math.min(S,k),I=Math.max(I,k),{..._,t:k,side:F}}),T=(I-S||1)/n,R=new Map;for(let _ of W){let A=Math.floor((_.t-S)/T);A<0&&(A=0),A>=n&&(A=n-1),R.has(A)||R.set(A,[]),R.get(A).push(_)}let D=new Map;for(let[_,A]of R){if(A.length<o)continue;let L=A.map(j=>j.side).sort((j,X)=>j-X),k=A.map(j=>j.z).sort((j,X)=>j-X),F=eo(L),B=eo(k),O=eo(L.map(j=>Math.abs(j-F)).sort((j,X)=>j-X)),$=eo(k.map(j=>Math.abs(j-B)).sort((j,X)=>j-X)),Z=Math.max(i,O*1.4826*r),Q=Math.max(a,$*1.4826*s);D.set(_,{sideMedian:F,zMedian:B,sideRange:Z,zRange:Q})}function H(_){if(D.has(_))return D.get(_);for(let A=1;A<=u;A++){if(D.has(_-A))return D.get(_-A);if(D.has(_+A))return D.get(_+A)}return null}let V=[],C=[];for(let _ of W){let A=Math.floor((_.t-S)/T);A<0&&(A=0),A>=n&&(A=n-1);let L=H(A);if(!L){C.push(_.raw);continue}let k=Math.abs(_.side-L.sideMedian)<=L.sideRange,F=L.zMedian-L.zRange*d,B=L.zMedian+L.zRange*f,O=_.z>=F&&_.z<=B;k&&O?V.push(_.raw):C.push(_.raw)}return{keep:V,removed:C,debug:{meanX:l,meanY:h,dirX:w,dirY:z,sideX:P,sideY:E,minT:S,maxT:I,binSize:T,stats:D}}}function eo(t){if(t.length===0)return 0;let e=Math.floor(t.length/2);return t.length%2===0?(t[e-1]+t[e])/2:t[e]}function $l(t,e){let n=new Map;for(let o=0;o<t.length;o++){let r=t[o],s=Math.floor(r.x/e),i=Math.floor(r.y/e),a=Math.floor(r.z/e),u=`${s},${i},${a}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}function Xl(t,e,n,o,r){let s=t[n],i=Math.floor(s.x/o),a=Math.floor(s.y/o),u=Math.floor(s.z/o),d=[];for(let f=-1;f<=1;f++)for(let c=-1;c<=1;c++)for(let l=-1;l<=1;l++){let h=`${i+f},${a+c},${u+l}`,g=e.get(h);if(g)for(let x of g){if(x===n)continue;let y=t[x],m=s.x-y.x,p=s.y-y.y,b=s.z-y.z;m*m+p*p+b*b<=r&&d.push(x)}}return d}function Ms(t,e={}){let{radius:n=.35,minClusterSize:o=20,lowPercent:r=.35}=e,s=Zl(t,{radius:n}),i=t.map(f=>f.z).sort((f,c)=>f-c),a=i[Math.floor(i.length*r)],u=[],d=[];for(let f of s.clusters){let c=f.map(g=>s.points[g]),l=c.reduce((g,x)=>g+x.z,0)/c.length;c.length<o&&l<=a?d.push(...c.map(g=>g.raw)):u.push(...c.map(g=>g.raw))}return{keep:u,removed:d}}function Zl(t,e={}){let{radius:n=.35}=e,o=t.map((u,d)=>({index:d,x:u.x,y:u.y,z:u.z,raw:u})),r=$l(o,n),s=n*n,i=new Array(o.length).fill(!1),a=[];for(let u=0;u<o.length;u++){if(i[u])continue;let d=[],f=[u];for(i[u]=!0;f.length>0;){let c=f.shift();d.push(c);let l=Xl(o,r,c,n,s);for(let h of l)i[h]||(i[h]=!0,f.push(h))}a.push(d)}return{points:o,clusters:a}}function Gl(t,e,n=1e-6){let o=Yl(e);for(let r of o)if(!Ul(t,r,n))return!1;return!0}function Yl(t){let e=t.center,n=t.halfSize,o=t.rotation.elements,r=new q.Vector3(o[0],o[1],o[2]).multiplyScalar(n.x),s=new q.Vector3(o[3],o[4],o[5]).multiplyScalar(n.y),i=new q.Vector3(o[6],o[7],o[8]).multiplyScalar(n.z),a=[];for(let u of[-1,1])for(let d of[-1,1])for(let f of[-1,1]){let c=e.clone().addScaledVector(r,u).addScaledVector(s,d).addScaledVector(i,f);a.push(c)}return a}function Ul(t,e,n=1e-6){let o=new q.Vector3().subVectors(e,t.center),r=t.rotation.elements,s=t.halfSize,i=new q.Vector3(r[0],r[1],r[2]),a=new q.Vector3(r[3],r[4],r[5]),u=new q.Vector3(r[6],r[7],r[8]),d=o.dot(i),f=o.dot(a),c=o.dot(u);return Math.abs(d)<=s.x+n&&Math.abs(f)<=s.y+n&&Math.abs(c)<=s.z+n}function Kl(t,e){if(!t||t.length===0)return[];let n=new Map;for(let i=0;i<t.length;i++){let a=t[i],u=a[0],d=a[1],f=Math.floor(u/e),c=Math.floor(d/e),l=`${f}_${c}`,h=n.get(l);if(!h){let m=(f+.5)*e,p=(c+.5)*e,b=u-m,w=d-p;h={minX:a,maxX:a,minY:a,maxY:a,center:a,centerDist2:b*b+w*w,cx:m,cy:p},n.set(l,h);continue}u<h.minX[0]&&(h.minX=a),u>h.maxX[0]&&(h.maxX=a),d<h.minY[1]&&(h.minY=a),d>h.maxY[1]&&(h.maxY=a);let g=u-h.cx,x=d-h.cy,y=g*g+x*x;y<h.centerDist2&&(h.center=a,h.centerDist2=y)}let o=new Set,r=[];function s(i){let a=`${i[0]}_${i[1]}`;o.has(a)||(o.add(a),r.push(i))}for(let i of n.values())s(i.minX),s(i.maxX),s(i.minY),s(i.maxY),s(i.center);return r}function Ql(t,e,n,o){return 1+(t[e][0]===0||t[n][0]===0||t[o][0]===0?1:0)}function Jl(t,e,n,o,r,s){let i=Math.hypot(n-r,o-s),a=Math.hypot(t-r,e-s),u=Math.hypot(t-n,e-o),d=Math.abs((n-t)*(s-e)-(r-t)*(o-e))/2;return d===0?1/0:i*a*u/(4*d)}function ta(t){if(!t||t.length<3)return[];let e=new Set,n=[];for(let g of t){let x=`${g[0]}_${g[1]}`;e.has(x)||(e.add(x),n.push(g))}if(n.length<3)return[];let o=new Ae(Float64Array.from(n.flat())),{triangles:r}=o;if(!r.length)return[];let s=new Map,i=(g,x)=>g<x?`${g}_${x}`:`${x}_${g}`;for(let g=0;g<r.length;g+=3){let x=r[g],y=r[g+1],m=r[g+2],[p,b]=n[x],[w,z]=n[y],[M,P]=n[m],E=Jl(p,b,w,z,M,P),S=Ql(n,x,y,m);if(E<=1/S)for(let[I,W]of[[x,y],[y,m],[m,x]]){let v=i(I,W);s.set(v,(s.get(v)||0)+1)}}let a=[];for(let[g,x]of s)x===1&&a.push(g.split("_").map(Number));if(!a.length)return[];let u=new Map;for(let[g,x]of a)(u.get(g)||u.set(g,[]).get(g)).push(x),(u.get(x)||u.set(x,[]).get(x)).push(g);let d=a[0][0],f=[],c=new Set,l=d,h=-1;do{f.push(n[l]),c.add(l);let g=u.get(l)||[],x=g.find(y=>y!==h&&!c.has(y));if(x===void 0&&(x=g.find(y=>y!==h)),x===void 0)break;h=l,l=x}while(l!==d&&f.length<=a.length+1);return f.length>0&&f.push(f[0]),f}import*as Fo from"three";var ea=(t,e,n=null)=>{if(t.length===0)return;let o=[],r=new Fo.Vector3(e[0].x,e[0].y,e[0].z),s=0;for(let f=1;f<e.length;f++)s+=e[f].z,e[f].z>r.z&&r.set(e[f].x,e[f].y,e[f].z);let i=s/(e.length-1)+.3,a=0,u=0;for(let f of t){let c=f[1].points;if(c.length<30)continue;let l=new Map;for(let x=0;x<c.length;x++){let y=c[x].z;if(y=Math.floor(y*10)/10,l.has(y)){let m=l.get(y);m.num+=1,m.points.push(c[x]),l.set(y,m)}else l.set(y,{num:1,points:[c[x]]})}c=[...l.entries()].reduce((x,y)=>y[1].num>x[1].num?y:x)[1].points.map(x=>new Fo.Vector3(x.x,x.y,x.z));let g=[];if(n!=null){let x=n([c],{tolerance:.1,minClusterSize:30,maxClusterSize:1e7,threadCount:1});if(x.length>0)for(let y of x[0]){if(y.length<50)continue;let m=y.map(p=>c[p]);g.push(m)}else g.push(c)}else g.push(c);for(let x=0;x<g.length;x++){let{minZ:y,maxZ:m,averagePz:p}=Ve(g[x]),b=m-y;if(i>m)continue;let w=g[x].map(E=>[E.x,E.y]),z=me(w);if(zr(z)<.5)continue;let P={contour:z,averagePz:p};g[x].length>a&&(a=g[x].length,u=p),o.push(P)}}let d=[];for(let f of o)(f.averagePz>=u||f.averagePz>=i-.5)&&d.push(f);return d};function qe(t,e){let n=t.x-e.x,o=t.y-e.y;return Math.sqrt(n*n+o*o)}function je(t){let e=0,n=0,o=0;for(let r=0;r<4;r++){let s=t[r],i=t[(r+1)%4],a=i.x-s.x,u=i.y-s.y,d=Math.sqrt(a*a+u*u);d>e&&(e=d,n=a/d,o=u/d)}return{longSide:e,dirX:n,dirY:o}}function $e(t,e,n){let r=[];for(let s of t){let i=(s.start.x+s.end.x)/2,a=(s.start.y+s.end.y)/2,u=i-e,d=a-n;u*u+d*d<=9&&r.push(s.start.z,s.end.z)}if(r.length===0){let s=[];for(let i of t)s.push(i.start.z,i.end.z);return s.length?(s.sort((i,a)=>i-a),s[Math.floor(s.length/2)]):-1/0}return r.sort((s,i)=>s-i),r[Math.floor(r.length/2)]}function Ce(t,e,n,o,r,s){let i=r-n,a=s-o,u=i*i+a*a;if(u<1e-12)return{dist:Math.sqrt((t-n)**2+(e-o)**2),t:0};let d=t-n,f=e-o,c=(d*i+f*a)/u,l=n+c*i,h=o+c*a;return{dist:Math.sqrt((t-l)**2+(e-h)**2),t:c}}function No(t,e,n){let o=0;for(let r=0;r<4;r++){let s=n[r],i=n[(r+1)%4],a=(i.x-s.x)*(e-s.y)-(i.y-s.y)*(t-s.x);if(Math.abs(a)<1e-12)continue;let u=a>0?1:-1;if(o===0)o=u;else if(o!==u)return!1}return!0}function Es(t,e,n,o,r,s,i,a){let u=n-t,d=o-e,f=i-r,c=a-s,l=u*c-d*f;if(Math.abs(l)<1e-12)return null;let h=((r-t)*c-(s-e)*f)/l,g=((r-t)*d-(s-e)*u)/l;return h<-1e-12||h>1+1e-12||g<-1e-12||g>1+1e-12?null:Math.max(0,Math.min(1,h))}function Ps(t,e,n,o,r){let s=[];No(t,e,r)&&s.push(0),No(n,o,r)&&s.push(1);for(let u=0;u<4;u++){let d=r[u],f=r[(u+1)%4],c=Es(t,e,n,o,d.x,d.y,f.x,f.y);c!==null&&s.push(c)}if(s.length<2)return 0;s.sort((u,d)=>u-d);let i=Math.sqrt((n-t)**2+(o-e)**2),a=0;for(let u=0;u<s.length-1;u++){let d=s[u],f=s[u+1],c=(d+f)/2,l=t+c*(n-t),h=e+c*(o-e);No(l,h,r)&&(a+=(f-d)*i)}return a}function Ts(t,e,n=1e-6){let o=[],r=t.start.x,s=t.start.y,i=t.end.x,a=t.end.y;for(let f of e){if(f===t)continue;let c=Es(r,s,i,a,f.start.x,f.start.y,f.end.x,f.end.y);c!==null&&c>n&&c<1-n&&o.push(c)}o.sort((f,c)=>f-c);let u=[],d=-1/0;for(let f of o)f-d>n&&(u.push(f),d=f);return u}function Ss(t,e){if(!e.length)return[t];let n=[],o=0;for(let s of e){let i=t.start.x+s*(t.end.x-t.start.x),a=t.start.y+s*(t.end.y-t.start.y),u=t.start.z+s*(t.end.z-t.start.z),d=o===0?{...t.start}:{x:t.start.x+o*(t.end.x-t.start.x),y:t.start.y+o*(t.end.y-t.start.y),z:t.start.z+o*(t.end.z-t.start.z)},f={...t,start:d,end:{x:i,y:a,z:u},length:t.length*(s-o)};f.drawWindow=void 0,f.isWindow=!1,n.push(f),o=s}let r={...t,start:{x:t.start.x+o*(t.end.x-t.start.x),y:t.start.y+o*(t.end.y-t.start.y),z:t.start.z+o*(t.end.z-t.start.z)},end:{...t.end},length:t.length*(1-o)};return r.drawWindow=void 0,r.isWindow=!1,n.push(r),n}function na(t,e,n=.15){let o=0,r=0;for(let i of e)i!==t&&((qe(t.start,i.start)<=n||qe(t.start,i.end)<=n)&&o++,(qe(t.end,i.start)<=n||qe(t.end,i.end)<=n)&&r++);let s=0;return o>=1&&r>=1?s=5:(o>=1||r>=1)&&(s=2),{left:o,right:r,score:s}}function oa(t,e){let n=[],{start:o,end:r}=t;for(let a of e){let{dist:u}=Ce(a.x,a.y,o.x,o.y,r.x,r.y);n.push(u)}let s=n.reduce((a,u)=>a+u,0)/n.length,i=n.reduce((a,u)=>a+(u-s)**2,0)/n.length;return i<.01?3:i<.05?2:i<.1?1:0}function ra(t,e,n=.15){let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=Math.sqrt(o*o+r*r);if(s<1e-12)return 0;let i=-r/s,a=o/s,u=[[],[]];for(let c=0;c<2;c++){let l=c===0?t.start:t.end;for(let h of e){if(h===t)continue;let g=qe(l,h.start),x=qe(l,h.end),y=null;if(g<=n?y=h.end:x<=n&&(y=h.start),!y)continue;let m=h.end.x-h.start.x,p=h.end.y-h.start.y,b=Math.sqrt(m*m+p*p);if(b<1e-12||Math.abs(o*m+r*p)/(s*b)>=.342)continue;let z=(y.x-l.x)*i+(y.y-l.y)*a;u[c].push(z>0?1:-1)}}if(u[0].length===0||u[1].length===0)return 0;let d=[...u[0],...u[1]];return d.every(c=>c===d[0])?2:1}function Rs(t,e,n){let o=na(t,n),r=oa(t,e),s=ra(t,n);return{score:o.score*3+r*2+s*2,details:{conn:o.score,variance:r,sameSide:s}}}function sa(t){let e=t.end.x-t.start.x,n=t.end.y-t.start.y,o=Math.atan2(n,e)*(180/Math.PI);return o<0&&(o+=180),o}function ia(t,e){let n=[];for(let o of t){let r=!1;for(let s of n){let i=Math.abs(o.angle-s[0].angle);if(Math.min(i,180-i)<=e){s.push(o),r=!0;break}}r||n.push([o])}return n}function la(t,e=.05){let n=[];for(let o of t){let r=!1;for(let s of n)if(Math.abs(o.offset-s[0].offset)<=e){s.push(o),r=!0;break}r||n.push([o])}return n}function aa(t,e,n,o,r){let s=[];for(let d of t){let f=d.seg,c=(f.start.x-e.start.x)*n+(f.start.y-e.start.y)*o,l=(f.end.x-e.start.x)*n+(f.end.y-e.start.y)*o;c<=l?s.push({l:c,r:l,idx:d.idx,startPt:f.start,endPt:f.end}):s.push({l,r:c,idx:d.idx,startPt:f.end,endPt:f.start})}s.sort((d,f)=>d.l-f.l);let i=[],a=.2,u=.5;for(let{l:d,r:f,idx:c,startPt:l,endPt:h}of s){if(i.length===0){i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h});continue}let g=i[i.length-1];if(d<=g.r+r){let x=Math.min(g.r,f)-Math.max(g.l,d),y=Math.hypot(g.endPt.x-l.x,g.endPt.y-l.y);x>=u||y<=a?(d<g.l&&(g.l=d,g.startPt=l),f>g.r&&(g.r=f,g.endPt=h),g.srcIdxs.includes(c)||g.srcIdxs.push(c)):i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h})}else i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h})}return i}function ca(t,e,n,o,r,s,i){let a=Math.hypot(n.x-e.x,n.y-e.y),u={...t};return u.start={...e},u.end={...n},u.length=a,u.direction={x:o,y:r,z:0},s!==void 0&&(u.rooftopPz=s),u.buildRosource=i,u.isRebuild=!1,u.doorAndBeamData||(u.doorAndBeamData=[]),u.insetionArr||(u.insetionArr=[]),u}function ua(t,e){let n=!0;for(;n;){n=!1;for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o],i=t[r];if(s.rooftopPz!==void 0&&i.rooftopPz!==void 0&&Math.abs(s.rooftopPz-i.rooftopPz)>.05)continue;let a=Math.abs(s.end.x-i.start.x)<.001&&Math.abs(s.end.y-i.start.y)<.001,u=Math.abs(s.start.x-i.end.x)<.001&&Math.abs(s.start.y-i.end.y)<.001,d=Math.abs(s.end.x-i.end.x)<.001&&Math.abs(s.end.y-i.end.y)<.001,f=Math.abs(s.start.x-i.start.x)<.001&&Math.abs(s.start.y-i.start.y)<.001;if(!(a||u||d||f)||s.direction.x*i.direction.x+s.direction.y*i.direction.y<.98)continue;let l=s.start,h=s.end;a?h=i.end:u?l=i.start:d?h=i.start:f&&(l=i.end);let g=Math.hypot(h.x-l.x,h.y-l.y),x={...s};x.start=l,x.end=h,x.length=g,x.direction={x:(h.x-l.x)/g,y:(h.y-l.y)/g,z:0},s.rooftopPz!==void 0&&i.rooftopPz!==void 0?x.rooftopPz=Math.max(s.rooftopPz,i.rooftopPz):x.rooftopPz=s.rooftopPz!==void 0?s.rooftopPz:i.rooftopPz,x.buildRosource=s.buildRosource||i.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),t[o]=x,e[o]=[...new Set([...e[o],...e[r]])],t.splice(r,1),e.splice(r,1),r--,n=!0}}return{segments:t,sourceMap:e}}function Xe(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((u,d)=>[d])};let o=t.map((u,d)=>({seg:u,angle:sa(u),idx:d}));o.sort((u,d)=>u.angle-d.angle);let r=ia(o,e),s=[],i=[],a=[];for(let u of r){let d=u[0].seg;for(let m of u)m.seg.length>d.length&&(d=m.seg);let f=d.end.x-d.start.x,c=d.end.y-d.start.y,l=Math.sqrt(f*f+c*c);if(l<1e-12)continue;let h=-c/l,g=f/l,x=u.map(m=>{let p=m.seg.start.x-d.start.x,b=m.seg.start.y-d.start.y;return{seg:m.seg,offset:Math.abs(p*h+b*g),idx:m.idx}});x.sort((m,p)=>m.offset-p.offset);let y=la(x);for(let m of y){let p=m[0].seg;for(let T of m)T.seg.length>p.length&&(p=T.seg);let b=p.end.x-p.start.x,w=p.end.y-p.start.y,z=Math.sqrt(b*b+w*w);if(z<1e-12)continue;let M=b/z,P=w/z,E=m.map(T=>T.seg.rooftopPz).filter(T=>T!==void 0),S=E.length>0?Math.max(...E):void 0,I=[...new Set(E.map(T=>T.toFixed(3)))];if(I.length>1){let T=m.map(R=>({idx:R.idx,start:{x:R.seg.start.x,y:R.seg.start.y,z:R.seg.start.z},end:{x:R.seg.end.x,y:R.seg.end.y,z:R.seg.end.z},length:R.seg.length,rooftopPz:R.seg.rooftopPz}));a.push({values:[...I],segments:T})}let W=[...new Set(m.map(T=>String(T.seg.buildRosource)))],v=aa(m,p,M,P,n);for(let{l:T,r:R,srcIdxs:D,startPt:H,endPt:V}of v){if(R-T<.01)continue;let C=ca(p,H,V,M,P,S,p.buildRosource);s.push(C),i.push(D)}}}return{...ua(s,i),debugRPZGroups:a}}function fa(t){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,minEmbedRatioThreshold:.3,noWallSurroundDistance:.3,minEmbedRatio:.05,...t}}function da(t,e,n){return[{x:e,y:n,z:0},{x:t[0].x,y:t[0].y,z:0},{x:t[1].x,y:t[1].y,z:0},{x:t[2].x,y:t[2].y,z:0},{x:t[3].x,y:t[3].y,z:0}]}function ha(t,e,n,o,r,s,i,a,u){if(!["1527725434500","1527725386500","1527726772000","1527725058500"].some(c=>t.includes(c)))return;e.map(c=>{let{start:l,end:h}=c,g=Ce(n,o,l.x,l.y,h.x,h.y),x=r.map(z=>{let M=Ce(z.x,z.y,l.x,l.y,h.x,h.y);return`t=${M.t.toFixed(3)},d=${M.dist.toFixed(3)}`}),y=h.x-l.x,m=h.y-l.y,p=Math.sqrt(y*y+m*m)||1,b=Math.abs(i*(y/p)+a*(m/p)),w=Math.acos(Math.min(b,1))*(180/Math.PI);return{seg:c,lineDist:g.dist,t:g.t,pts:x,angle:w,length:c.length}}).sort((c,l)=>c.lineDist-l.lineDist)}function ma(t,e,n,o,r,s,i){let a=[{margin:s.projectionMargin,maxDist:s.maxDistance,label:"\u4E25\u683C"},{margin:.4,maxDist:.65,label:"\u5BBD\u677E"}],u=[];for(let d of a){if(u.length>0)break;for(let f of t){let c=!1,l=!1,h=!1,g=e*s.minLengthRatio;if(f.length<g){continue}c=!0;let{start:x,end:y}=f,m=!1,p=1/0;for(let v of r){let{dist:T,t:R}=Ce(v.x,v.y,x.x,x.y,y.x,y.y);R>=-d.margin&&R<=1+d.margin&&T<=d.maxDist&&(m=!0,p=Math.min(p,T))}if(!m){`${d.maxDist}${(-d.margin).toFixed(1)}${(1+d.margin).toFixed(1)}`;continue}l=!0;let b=Ce(r[0].x,r[0].y,x.x,x.y,y.x,y.y);if(b.t<0||b.t>1){`${b.t.toFixed(3)}`;continue}let w=Math.sqrt((y.x-x.x)**2+(y.y-x.y)**2);if(w<1e-12)continue;let z=(y.x-x.x)/w,M=(y.y-x.y)/w,P=Math.abs(n*z+o*M),E=Math.acos(Math.min(P,1))*(180/Math.PI);if(E>s.angleThreshold){`${E.toFixed(1)}${s.angleThreshold}`;continue}h=!0;let S=[r[1],r[2],r[3],r[4]],I=Ps(x.x,x.y,y.x,y.y,S),W=e>0?I/e:0;u.push({seg:f,minDist:p,embedRatio:W,ratio:f.length/e,score:0,details:{conn:0,variance:0,sameSide:0}})}}return u}function pa(t,e,n,o){if(t.length<=1)return t.length===1&&(t[0].score=-1),t;for(let r of t){let{score:s,details:i}=Rs(r.seg,e,n);r.score=s,r.details=i}return t.sort((r,s)=>s.embedRatio-r.embedRatio||s.score-r.score||r.minDist-s.minDist),t}function ga(t,e,n,o){let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=Math.sqrt(r*r+s*s),a=r/i,u=s/i,d=e.map(P=>{let E=P.x-t.start.x,S=P.y-t.start.y;return(E*a+S*u)/i}),f=Math.min(...d),c=Math.max(...d),l=(c-f)*i,h=(f+c)/2,g=t.start.x+h*r,x=t.start.y+h*s,y=n.box.min.z,m=n.box.max.z,p=Math.abs(m-y),b=$e(o,t.start.x,t.start.y),w=Math.max(0,y-b),z=f<=0&&c>=1,M=t.start.z+h*(t.end.z-t.start.z);return{p:{x:g,y:x,z:M},width:l,full:z,height:p,groundClearance:w}}function qo(t,e,n){let o=e.map(f=>n[f]),r=[],s=[],i=[],a=[],u,d;for(let f of o){if(f.originalPoints?.length)for(let c of f.originalPoints)r.push(c);if(f.doorAndBeamData?.length)for(let c of f.doorAndBeamData)s.push(c);if(f.insetionArr?.length)for(let c of f.insetionArr)i.push(c);if(f.drawWindow?.length)for(let c of f.drawWindow)a.push(c);f.boxData&&!u&&(u=f.boxData),f.rooftopPz!==void 0&&(d===void 0||f.rooftopPz>d)&&(d=f.rooftopPz)}r.length&&(t.originalPoints=r),s.length&&(t.doorAndBeamData=s),i.length&&(t.insetionArr=i),a.length&&(t.drawWindow=a),u&&(t.boxData=u),d!==void 0&&(t.rooftopPz=d)}function Tn(t,e,n=10,o=.2,r=.2){let s=[];if(!t.drawWindow)return s;let i=t.drawWindow.p,a=t.wallSegment,u=a.end.x-a.start.x,d=a.end.y-a.start.y,f=Math.sqrt(u*u+d*d)||1,c=u/f,l=d/f,h=i.x-a.start.x,g=i.y-a.start.y,x=(h*c+g*l)/f;for(let y of e){if(y===a)continue;let m=y.end.x-y.start.x,p=y.end.y-y.start.y,b=Math.sqrt(m*m+p*p)||1,w=m/b,z=p/b,M=Math.abs(c*w+l*z),E=Math.acos(Math.min(M,1))*(180/Math.PI);if(Math.abs(E-90)>n)continue;let S=[y.start,y.end];for(let I of S){let W=I.x-a.start.x,v=I.y-a.start.y,T=(W*c+v*l)/f,R=a.start.x+T*f*c,D=a.start.y+T*f*l;if(Math.sqrt((I.x-R)**2+(I.y-D)**2)>r)continue;let V=Math.abs((T-x)*f);if(V<=o){s.push({seg:y,distAlongWall:V,angle:E,endPoint:I});break}}}return s}function Sn(t,e){let n=t.start,o=t.end,r=o.x-n.x,s=o.y-n.y,i=Math.sqrt(r*r+s*s)||1,a=((e.x-n.x)*r+(e.y-n.y)*s)/(i*i),u=Math.max(0,Math.min(1,a)),d={x:n.x+u*r,y:n.y+u*s,z:n.z+(o.z-n.z)*u||0};function f(b){if(!b||!b.length)return[[],[]];let w=[],z=[];for(let M of b){let P=((M.x-n.x)*r+(M.y-n.y)*s)/(i*i);P<=u+1e-8&&w.push(M),P>=u-1e-8&&z.push(M)}return(w.length===0||c(w[w.length-1],d)>1e-6)&&w.push({...d}),(z.length===0||c(z[0],d)>1e-6)&&z.unshift({...d}),[w,z]}function c(b,w){return Math.sqrt((b.x-w.x)**2+(b.y-w.y)**2)}let[l,h]=f(t.originalPoints),g=Math.max(u*i,1e-6),x=Math.max((1-u)*i,1e-6),y=t.direction||{x:r/i,y:s/i,z:(o.z-n.z)/i||0},m={...t,start:{...n},end:{...d},length:g,direction:{...y},originalPoints:l.length?l:void 0},p={...t,start:{...d},end:{...o},length:x,direction:{...y},originalPoints:h.length?h:void 0};if(t.drawWindow&&t.drawWindow.length>0){let b=[],w=[];for(let z of t.drawWindow){let M=((z.p.x-n.x)*r+(z.p.y-n.y)*s)/(i*i);M<=u+1e-8&&b.push(z),M>=u-1e-8&&w.push(z)}m.drawWindow=b.length?b:void 0,p.drawWindow=w.length?w:void 0}else m.drawWindow=void 0,p.drawWindow=void 0;if(t.boxData){let b=w=>{if(!w.length)return;let z=1/0,M=1/0,P=1/0,E=-1/0,S=-1/0,I=-1/0;for(let W of w)W.x<z&&(z=W.x),W.y<M&&(M=W.y),W.z!==void 0&&W.z<P&&(P=W.z),W.x>E&&(E=W.x),W.y>S&&(S=W.y),W.z!==void 0&&W.z>I&&(I=W.z);return{isBox3:!0,min:{x:z,y:M,z:P},max:{x:E,y:S,z:I}}};m.boxData=b(l),p.boxData=b(h)}return[m,p]}function Rn(t,e,n,o){let r=fa(n),s=[],{segments:i,sourceMap:a}=o??Xe(e),u=i;for(let d of t){let f=d.coordinatesByArea?.coordinates;if(!f||f.length<4)continue;let c=f.slice(0,4),l=c.reduce((I,W)=>I+W.x,0)/4,h=c.reduce((I,W)=>I+W.y,0)/4,{longSide:g,dirX:x,dirY:y}=je(c);if(g<.01)continue;let m=c.reduce((I,W)=>I+W.z,0)/4,p=$e(e,l,h);if(m<p-.3)continue;let b=da(c,l,h);ha(d.name,u,l,h,b,g,x,y,r);let w=ma(u,g,x,y,b,r,d.name);if(w.length>1&&r.minEmbedRatioThreshold>0){let I=Math.max(...w.map(W=>W.embedRatio));if(I>0){let W=w.length;w=w.filter(v=>v.embedRatio>=I*r.minEmbedRatioThreshold)}}if(w.length>0&&r.minEmbedRatio>0){let I=w.length;w=w.filter(W=>W.embedRatio>=r.minEmbedRatio)}w=pa(w,b,e,d.name);let z=null,M=1/0,P=0,E=0;if(w.length>0){let I=w[0];z=I.seg,M=I.minDist,P=I.ratio,E=I.embedRatio}if(z&&E<=0&&r.noWallSurroundDistance>0){let I=r.noWallSurroundDistance,W=c.map(C=>C.x),v=c.map(C=>C.y),T=Math.min(...W)-I,R=Math.max(...W)+I,D=Math.min(...v)-I,H=Math.max(...v)+I,V=!1;for(let C of u){let _=Math.min(C.start.x,C.end.x),A=Math.max(C.start.x,C.end.x),L=Math.min(C.start.y,C.end.y),k=Math.max(C.start.y,C.end.y);if(!(A<T||_>R)&&!(k<D||L>H)){V=!0;break}}V||(z=null)}let S;if(z&&(S=ga(z,c,d,i),!r.printOnly)){let I=z;I.drawWindow||(I.drawWindow=[]),I.drawWindow.push(S),I.isWindow=!0}if(z){let I={windowName:d.name,windowCategory:d.category,windowCenter:d.center,wallSegment:z,distance:M,wallLengthRatio:P,drawWindow:S};s.push(I)}}for(let d of s){let f=d.wallSegment,c=i.indexOf(f);if(c===-1)continue;let l=a[c];!l||l.length<=1||qo(f,l,e)}return s}function jo(t,e,n){let o={printOnly:!1,skipMerge:!1,...n};for(let y of t)y.drawWindow&&(y.drawWindow=void 0),y.isWindow&&(y.isWindow=void 0);let r=Array.isArray(e)?e.filter(y=>y&&y.category==="window"&&!y.isBayWindowObj):[],s,i;if(o.skipMerge)s=t,i=t.map((y,m)=>[m]);else{let y=Xe(t);s=y.segments,i=y.sourceMap}let a=Rn(r,t,o,{segments:s,sourceMap:i}),u=new Set;for(let y of a){let m=s.indexOf(y.wallSegment);m>=0&&u.add(m)}let d=[],f=new Set;for(let y of u){let m=i[y];if(m){qo(s[y],m,t);for(let p of m)f.add(p)}d.push(s[y])}for(let y=0;y<t.length;y++)f.has(y)||d.push(t[y]);let c=new Set(a.map(y=>y.windowName));for(let y of e)y&&y.category==="window"&&!y.isBayWindowObj&&(c.has(y.name)?delete y.AbnormalWindow:y.AbnormalWindow=!0);let l=new Map;for(let y of e)y&&y.name&&l.set(y.name,y);let h=new Map;for(let y of a){let m=y.wallSegment;h.has(m)||h.set(m,[]),h.get(m).push(y)}let g=new Map,x=d;for(let[y,m]of h){if(!y.drawWindow||!y.drawWindow.length||g.has(y))continue;let p=y.length,b=y.end.x-y.start.x,w=y.end.y-y.start.y,z=[];for(let T of m){if(!T.drawWindow)continue;let R=T.drawWindow.width/2,D=((T.drawWindow.p.x-y.start.x)*b+(T.drawWindow.p.y-y.start.y)*w)/(p*p),H=R/p;z.push({left:D-H,right:D+H,match:T})}if(z.length===0)continue;let M=Ts(y,x),P=1e-6,E=new Set,S=!1;for(let T of z){let R=!1,D=!1,H=null;for(let C of M)C<T.left-P&&((H===null||C>H)&&(H=C),R=!0);let V=null;for(let C of M)C>T.right+P&&((V===null||C<V)&&(V=C),D=!0);H!==null&&(E.add(H),S=!0),V!==null&&(E.add(V),S=!0)}if(!S)continue;let I=!1,W=null,v=null;for(let T of z){let R=T.match;if(!R.drawWindow||R.drawWindow.width<=1)continue;let D=l.get(R.windowName);if(!D||!D.positionArr||!D.positionArr.length)continue;let H=Tn(R,s);if(H.length<=1)continue;let V=D.positionArr[0],C=R.drawWindow.p,_=V.x-C.x,A=V.y-C.y,L=Math.sqrt(_*_+A*A);if(L<.001)continue;let k=_/L,F=A/L,B=H.filter(O=>{let $=(O.seg.start.x+O.seg.end.x)/2,Z=(O.seg.start.y+O.seg.end.y)/2,Q=$-C.x,j=Z-C.y;return Q*k+j*F>0});if(B.length){I=!0,W=B[0].endPoint,v=R;break}}if(I&&W&&v){let[T,R]=Sn(y,W);g.set(y,[T,R]);let D=((v.drawWindow.p.x-y.start.x)*b+(v.drawWindow.p.y-y.start.y)*w)/(p*p),H=((W.x-y.start.x)*b+(W.y-y.start.y)*w)/(p*p);D<=H?v.wallSegment=T:v.wallSegment=R}else{let T=Array.from(E).sort((D,H)=>D-H),R=Ss(y,T);for(let D of z){let H=(D.left+D.right)/2,V=0;for(let C of R){let _=C.length/p;if(H>=V-P&&H<=V+_+P){let A=D.match.drawWindow;A&&(C.drawWindow||(C.drawWindow=[]),C.drawWindow.push(A),C.isWindow=!0),D.match.wallSegment=C;break}V+=_}}g.set(y,R)}}if(g.size>0){let y=[];for(let m of d)g.has(m)?y.push(...g.get(m)):y.push(m);for(let m of y)m.isWindow===void 0&&(m.isWindow=!!(m.drawWindow&&m.drawWindow.length>0));return{segments:y,matches:a}}for(let y of d)y.isWindow=!!(y.drawWindow&&y.drawWindow.length>0);return{segments:d,matches:a}}function Ze(t,e){let n=t.x-e.x,o=t.y-e.y;return Math.sqrt(n*n+o*o)}function no(t){let e=0,n=1/0,o=0,r=0;for(let s=0;s<4;s++){let i=t[s],a=t[(s+1)%4],u=a.x-i.x,d=a.y-i.y,f=Math.sqrt(u*u+d*d);f>e&&(e=f,o=u/f,r=d/f),f<n&&(n=f)}return{longSide:e,shortSide:n===1/0?e:n,dirX:o,dirY:r}}function Ge(t,e,n){let r=[];for(let s of t){let i=(s.start.x+s.end.x)/2,a=(s.start.y+s.end.y)/2,u=i-e,d=a-n;u*u+d*d<=9&&r.push(s.start.z,s.end.z)}if(r.length===0){let s=[];for(let i of t)s.push(i.start.z,i.end.z);return s.length?(s.sort((i,a)=>i-a),s[Math.floor(s.length/2)]):-1/0}return r.sort((s,i)=>s-i),r[Math.floor(r.length/2)]}function jt(t,e,n,o,r,s){let i=r-n,a=s-o,u=i*i+a*a;if(u<1e-12)return{dist:Math.sqrt((t-n)**2+(e-o)**2),t:0};let d=t-n,f=e-o,c=(d*i+f*a)/u,l=n+c*i,h=o+c*a;return{dist:Math.sqrt((t-l)**2+(e-h)**2),t:c}}function $o(t,e,n){let o=0;for(let r=0;r<4;r++){let s=n[r],i=n[(r+1)%4],a=(i.x-s.x)*(e-s.y)-(i.y-s.y)*(t-s.x);if(Math.abs(a)<1e-12)continue;let u=a>0?1:-1;if(o===0)o=u;else if(o!==u)return!1}return!0}function xa(t,e,n,o,r,s,i,a){let u=n-t,d=o-e,f=i-r,c=a-s,l=u*c-d*f;if(Math.abs(l)<1e-12)return null;let h=((r-t)*c-(s-e)*f)/l,g=((r-t)*d-(s-e)*u)/l;return h<-1e-12||h>1+1e-12||g<-1e-12||g>1+1e-12?null:Math.max(0,Math.min(1,h))}function vs(t,e,n,o,r){let s=[];$o(t,e,r)&&s.push(0),$o(n,o,r)&&s.push(1);for(let u=0;u<4;u++){let d=r[u],f=r[(u+1)%4],c=xa(t,e,n,o,d.x,d.y,f.x,f.y);c!==null&&s.push(c)}if(s.length<2)return 0;s.sort((u,d)=>u-d);let i=Math.sqrt((n-t)**2+(o-e)**2),a=0;for(let u=0;u<s.length-1;u++){let d=s[u],f=s[u+1],c=(d+f)/2,l=t+c*(n-t),h=e+c*(o-e);$o(l,h,r)&&(a+=(f-d)*i)}return a}function Vs(t){if(!t||t.length<4)return[];let e=[...t].sort((i,a)=>i.z-a.z),n=e.slice(0,2),o=e.slice(2,4),r=[],s=new Set;for(let i of n){let a=-1,u=1/0;for(let d=0;d<o.length;d++){if(s.has(d))continue;let f=o[d].x-i.x,c=o[d].y-i.y,l=Math.sqrt(f*f+c*c);l<u&&(u=l,a=d)}if(a>=0){s.add(a);let d=o[a];r.push({bottom:i,top:d,midX:(i.x+d.x)/2,midY:(i.y+d.y)/2,height:Math.abs(d.z-i.z)})}}return r}function Ds(t,e,n){return jt(t.midX,t.midY,e.x,e.y,n.x,n.y)}function Is(t,e,n,o=.08){if(!t||t.length<2)return null;let r=Ds(t[0],e,n),s=Ds(t[1],e,n);if(r.dist<=o&&s.dist<=o){let i=r.dist<=s.dist?0:1,a=1-i;return{hingeEdge:t[i],otherEdge:t[a],hingeDist:i===0?r.dist:s.dist,otherDist:a===0?r.dist:s.dist,isClosed:!0,hingeT:i===0?r.t:s.t}}if(r.dist<=o||s.dist<=o){let i=r.dist<=o?0:1,a=1-i;return{hingeEdge:t[i],otherEdge:t[a],hingeDist:i===0?r.dist:s.dist,otherDist:a===0?r.dist:s.dist,isClosed:!1,hingeT:i===0?r.t:s.t}}return null}function Cs(t){if(!t||t.length<2)return 0;let e=t[0].midX-t[1].midX,n=t[0].midY-t[1].midY;return Math.sqrt(e*e+n*n)}function Xo(t){if(!t||!t.start||t.start.x==null||t.start.y==null||t.start.z==null||!t.end||t.end.x==null||t.end.y==null||t.end.z==null)return null;let e=t.start,n=t.end,o=n.x-e.x,r=n.y-e.y,s=Math.sqrt(o*o+r*r)||1,i=0,a=0;return t.centerDir?(i=t.centerDir.x,a=t.centerDir.y):(i=-r/s,a=o/s),{p1:e,p2:n,dirX:o/s,dirY:r/s,length:s,midX:(e.x+n.x)/2,midY:(e.y+n.y)/2,normalX:i,normalY:a}}function Hs(t,e,n,o=.08){let r=Xo(t);if(!r)return null;let s=jt(r.p1.x,r.p1.y,e.x,e.y,n.x,n.y),i=jt(r.p2.x,r.p2.y,e.x,e.y,n.x,n.y);if(s.dist<=o&&i.dist<=o){let a=s.dist<=i.dist;return{hingePoint:a?r.p1:r.p2,otherPoint:a?r.p2:r.p1,hingeDist:a?s.dist:i.dist,otherDist:a?i.dist:s.dist,isClosed:!0,hingeT:a?s.t:i.t}}if(s.dist<=o||i.dist<=o){let a=s.dist<=o;return{hingePoint:a?r.p1:r.p2,otherPoint:a?r.p2:r.p1,hingeDist:a?s.dist:i.dist,otherDist:a?i.dist:s.dist,isClosed:!1,hingeT:a?s.t:i.t}}return null}function oo(t,e=.1){let n=t.originalPoints;if(!n||n.length===0)return{densityProfile:[],binStartT:[],binEndT:[],avgDensity:0,maxDensity:0,minDensity:0,binSize:e};let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=t.length;if(s<=0)return{densityProfile:[],binStartT:[],binEndT:[],avgDensity:0,maxDensity:0,minDensity:0,binSize:e};let i=[];for(let y of n){let m=y.x-t.start.x,p=y.y-t.start.y,b=(m*o+p*r)/(s*s);i.push(Math.max(0,Math.min(1,b)))}let a=Math.max(1,Math.ceil(s/e)),u=s/a,d=new Array(a).fill(0);for(let y of i){let m=Math.min(a-1,Math.floor(y*a));d[m]++}let f=d.map(y=>y/u),c=d.map((y,m)=>m/a),l=d.map((y,m)=>(m+1)/a),h=f.reduce((y,m)=>y+m,0)/a,g=Math.max(...f),x=Math.min(...f);return{densityProfile:f,binStartT:c,binEndT:l,avgDensity:h,maxDensity:g,minDensity:x,binSize:u}}function Ws(t){let{densityProfile:e,avgDensity:n}=t;if(e.length===0||n===0)return 0;let o=e.length,r=e.reduce((i,a)=>i+(a-n)**2,0)/o;return Math.sqrt(r)/n}function _s(t){let e=[];for(let o of t)if(o.originalPoints&&o.originalPoints.length>=50&&o.length>=.5){let r=oo(o,.1);r.avgDensity>0&&e.push(r.avgDensity)}e.sort((o,r)=>o-r);let n=e.length>0?e[Math.floor(e.length/2)]:1;return{sortedDensities:e,medianDensity:n}}function Zo(t,e){let{sortedDensities:n}=e;if(n.length===0)return .5;if(t<=0)return 1;let o=0;for(let r of n)r<t&&o++;return 1-o/n.length}function As(t,e,n=.5,o=.5,r=3){let{densityProfile:s,avgDensity:i}=t;if(s.length===0||i===0)return[];let a=i*n,u=s.length,d=[],f=!1,c=0,l=0,h=0;for(let g=0;g<u;g++){let x=s[g]<a;if(x&&!f)f=!0,c=g,l=s[g],h=1;else if(x&&f)l+=s[g],h++;else if(!x&&f){f=!1;let y=g-1,m=c/u,p=(y+1)/u,b=(p-m)*e;b>=o&&b<=r&&d.push({startT:m,endT:p,startLen:m*e,endLen:p*e,avgDensity:l/h}),l=0,h=0}}if(f){let g=u-1,x=c/u,y=(g+1)/u,m=(y-x)*e;m>=o&&m<=r&&d.push({startT:x,endT:y,startLen:x*e,endLen:y*e,avgDensity:l/h})}return d}function ya(t,e,n){let o=t.originalPoints;if(!o||o.length<5)return{verticalGapRatio:1,isDoorSized:!0};let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=t.length*t.length;if(i<=0)return{verticalGapRatio:0,isDoorSized:!1};let a=[];for(let m of o){let p=m.x-t.start.x,b=m.y-t.start.y,w=(p*r+b*s)/i;w>=e&&w<=n&&m.z!==void 0&&isFinite(m.z)&&a.push(m.z)}if(a.length<5)return{verticalGapRatio:1,isDoorSized:!0};let u=1/0,d=-1/0;for(let m of o)m.z!==void 0&&isFinite(m.z)&&(m.z<u&&(u=m.z),m.z>d&&(d=m.z));let f=d-u;if(f<.5)return{verticalGapRatio:0,isDoorSized:!1};let c=15,l=new Array(c).fill(!1);for(let m of a){let p=Math.min(c-1,Math.max(0,Math.floor((m-u)/f*c)));l[p]=!0}let h=0,g=0;for(let m=0;m<c;m++)l[m]?(h=Math.max(h,g),g=0):g++;h=Math.max(h,g);let x=h/c,y=x>=.35;return{verticalGapRatio:x,isDoorSized:y}}function Bs(t,e,n,o=.5,r=.5,s=3,i=.35){let a=As(e,n,o,r,s),u=[];for(let d of a){let{verticalGapRatio:f,isDoorSized:c}=ya(t,d.startT,d.endT);u.push({...d,verticalGapRatio:f,isRectangular:c})}return u}function Ls(t,e,n){if(!t||!t.start||!t.end)return null;let o=t.start,r=t.end,s=jt(o.x,o.y,e.x,e.y,n.x,n.y),i=jt(r.x,r.y,e.x,e.y,n.x,n.y),a=s.dist<=i.dist,u=a?o:r,d=a?s.dist:i.dist,f=jt(u.x,u.y,e.x,e.y,n.x,n.y);return{hingeT:Math.max(0,Math.min(1,f.t)),hingeDist:d}}function ks(t,e,n,o=2e3){let{hingeT:r}=t,s=.25,i=0,a=null,u=0;for(let d of e){let f=(d.startT+d.endT)/2,c=Math.abs(f-r),l=Math.max(0,1-c/s),h=d.isRectangular?1:.3,g=Math.max(0,1-d.avgDensity/o),x=l*.5+h*.3+g*.2;x>i&&(i=x,a=d,u=l)}return{score:i>.5?i:-1,bestRegion:a,bestOverlap:u,bestOpeningStartT:a?.startT??0,bestOpeningEndT:a?.endT??0}}function ba(t,e,n=.15){let o=0,r=0;for(let i of e)i!==t&&((Ze(t.start,i.start)<=n||Ze(t.start,i.end)<=n)&&o++,(Ze(t.end,i.start)<=n||Ze(t.end,i.end)<=n)&&r++);let s=0;return o>=1&&r>=1?s=5:(o>=1||r>=1)&&(s=2),{left:o,right:r,score:s}}function wa(t,e){let n=[],{start:o,end:r}=t;for(let a of e){let{dist:u}=jt(a.x,a.y,o.x,o.y,r.x,r.y);n.push(u)}let s=n.reduce((a,u)=>a+u,0)/n.length,i=n.reduce((a,u)=>a+(u-s)**2,0)/n.length;return i<.01?3:i<.05?2:i<.1?1:0}function za(t,e,n=.15){let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=Math.sqrt(o*o+r*r);if(s<1e-12)return 0;let i=-r/s,a=o/s,u=[[],[]];for(let c=0;c<2;c++){let l=c===0?t.start:t.end;for(let h of e){if(h===t)continue;let g=Ze(l,h.start),x=Ze(l,h.end),y=null;if(g<=n?y=h.end:x<=n&&(y=h.start),!y)continue;let m=h.end.x-h.start.x,p=h.end.y-h.start.y,b=Math.sqrt(m*m+p*p);if(b<1e-12||Math.abs(o*m+r*p)/(s*b)>=.342)continue;let z=(y.x-l.x)*i+(y.y-l.y)*a;u[c].push(z>0?1:-1)}}if(u[0].length===0||u[1].length===0)return 0;let d=[...u[0],...u[1]];return d.every(c=>c===d[0])?2:1}function Os(t,e,n){let o=ba(t,n),r=wa(t,e),s=za(t,n);return{score:o.score*3+r*2+s*2,details:{conn:o.score,variance:r,sameSide:s}}}function Ma(t){let e=t.end.x-t.start.x,n=t.end.y-t.start.y,o=Math.atan2(n,e)*(180/Math.PI);return o<0&&(o+=180),o}function Ea(t,e){let n=[];for(let o of t){let r=!1;for(let s of n){let i=Math.abs(o.angle-s[0].angle);if(Math.min(i,180-i)<=e){s.push(o),r=!0;break}}r||n.push([o])}return n}function Pa(t,e=.04){let n=[];for(let o of t){let r=!1;for(let s of n)if(Math.abs(o.offset-s[0].offset)<=e){s.push(o),r=!0;break}r||n.push([o])}return n}function Ta(t,e,n,o,r){let s=[];for(let d of t){let f=d.seg,c=(f.start.x-e.start.x)*n+(f.start.y-e.start.y)*o,l=(f.end.x-e.start.x)*n+(f.end.y-e.start.y)*o;c<=l?s.push({l:c,r:l,idx:d.idx,startPt:f.start,endPt:f.end}):s.push({l,r:c,idx:d.idx,startPt:f.end,endPt:f.start})}s.sort((d,f)=>d.l-f.l);let i=[],a=.01,u=.5;for(let{l:d,r:f,idx:c,startPt:l,endPt:h}of s){if(i.length===0){i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h});continue}let g=i[i.length-1];if(d<=g.r+r){let x=Math.min(g.r,f)-Math.max(g.l,d),y=Math.hypot(g.endPt.x-l.x,g.endPt.y-l.y);x>=u||y<=a?(d<g.l&&(g.l=d,g.startPt=l),f>g.r&&(g.r=f,g.endPt=h),g.srcIdxs.includes(c)||g.srcIdxs.push(c)):i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h})}else i.push({l:d,r:f,srcIdxs:[c],startPt:l,endPt:h})}return i}function Sa(t,e,n,o,r,s,i){let a=Math.hypot(n.x-e.x,n.y-e.y),u={...t};return u.start={...e},u.end={...n},u.length=a,u.direction={x:o,y:r,z:0},s!==void 0&&(u.rooftopPz=s),u.buildRosource=i,u.isRebuild=!1,u.doorAndBeamData||(u.doorAndBeamData=[]),u.insetionArr||(u.insetionArr=[]),u}function Ra(t,e){let n=!0;for(;n;){n=!1;for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o],i=t[r];if(s.rooftopPz!==void 0&&i.rooftopPz!==void 0&&Math.abs(s.rooftopPz-i.rooftopPz)>.05)continue;let a=Math.abs(s.end.x-i.start.x)<.001&&Math.abs(s.end.y-i.start.y)<.001,u=Math.abs(s.start.x-i.end.x)<.001&&Math.abs(s.start.y-i.end.y)<.001,d=Math.abs(s.end.x-i.end.x)<.001&&Math.abs(s.end.y-i.end.y)<.001,f=Math.abs(s.start.x-i.start.x)<.001&&Math.abs(s.start.y-i.start.y)<.001;if(!(a||u||d||f)||s.direction.x*i.direction.x+s.direction.y*i.direction.y<.98)continue;let l=s.start,h=s.end;a?h=i.end:u?l=i.start:d?h=i.start:f&&(l=i.end);let g=Math.hypot(h.x-l.x,h.y-l.y),x={...s};x.start=l,x.end=h,x.length=g,x.direction={x:(h.x-l.x)/g,y:(h.y-l.y)/g,z:0},s.rooftopPz!==void 0&&i.rooftopPz!==void 0?x.rooftopPz=Math.max(s.rooftopPz,i.rooftopPz):x.rooftopPz=s.rooftopPz!==void 0?s.rooftopPz:i.rooftopPz,x.buildRosource=s.buildRosource||i.buildRosource,x.isRebuild=!1,x.doorAndBeamData||(x.doorAndBeamData=[]),x.insetionArr||(x.insetionArr=[]),t[o]=x,e[o]=[...new Set([...e[o],...e[r]])],t.splice(r,1),e.splice(r,1),r--,n=!0}}return{segments:t,sourceMap:e}}function Ye(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((u,d)=>[d])};let o=t.map((u,d)=>({seg:u,angle:Ma(u),idx:d}));o.sort((u,d)=>u.angle-d.angle);let r=Ea(o,e),s=[],i=[],a=[];for(let u of r){let d=u[0].seg;for(let m of u)m.seg.length>d.length&&(d=m.seg);let f=d.end.x-d.start.x,c=d.end.y-d.start.y,l=Math.sqrt(f*f+c*c);if(l<1e-12)continue;let h=-c/l,g=f/l,x=u.map(m=>{let p=m.seg.start.x-d.start.x,b=m.seg.start.y-d.start.y;return{seg:m.seg,offset:Math.abs(p*h+b*g),idx:m.idx}});x.sort((m,p)=>m.offset-p.offset);let y=Pa(x);for(let m of y){let p=m[0].seg;for(let T of m)T.seg.length>p.length&&(p=T.seg);let b=p.end.x-p.start.x,w=p.end.y-p.start.y,z=Math.sqrt(b*b+w*w);if(z<1e-12)continue;let M=b/z,P=w/z,E=m.map(T=>T.seg.rooftopPz).filter(T=>T!==void 0),S=E.length>0?Math.max(...E):void 0,I=[...new Set(E.map(T=>T.toFixed(3)))];if(I.length>1){let T=m.map(R=>({idx:R.idx,start:{x:R.seg.start.x,y:R.seg.start.y,z:R.seg.start.z},end:{x:R.seg.end.x,y:R.seg.end.y,z:R.seg.end.z},length:R.seg.length,rooftopPz:R.seg.rooftopPz}));a.push({values:[...I],segments:T})}let W=[...new Set(m.map(T=>String(T.seg.buildRosource)))],v=Ta(m,p,M,P,n);for(let{l:T,r:R,srcIdxs:D,startPt:H,endPt:V}of v){if(R-T<.01)continue;let C=Sa(p,H,V,M,P,S,p.buildRosource);s.push(C),i.push(D)}}}return{...Ra(s,i),debugRPZGroups:a}}function Da(t){return{minLengthRatio:0,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,minEmbedRatioThreshold:.3,noWallSurroundDistance:.3,minEmbedRatio:.05,...t}}function va(t,e,n){return[{x:e,y:n,z:0},{x:t[0].x,y:t[0].y,z:0},{x:t[1].x,y:t[1].y,z:0},{x:t[2].x,y:t[2].y,z:0},{x:t[3].x,y:t[3].y,z:0}]}function Va(t,e,n,o,r,s,i,a,u){if(!["_008","_002","_014","_015","_020"].some(c=>t.includes(c)))return;e.map(c=>{let{start:l,end:h}=c,g=jt(n,o,l.x,l.y,h.x,h.y),x=r.map(z=>{let M=jt(z.x,z.y,l.x,l.y,h.x,h.y);return`t=${M.t.toFixed(3)},d=${M.dist.toFixed(3)}`}),y=h.x-l.x,m=h.y-l.y,p=Math.sqrt(y*y+m*m)||1,b=Math.abs(i*(y/p)+a*(m/p)),w=Math.acos(Math.min(b,1))*(180/Math.PI);return{seg:c,lineDist:g.dist,t:g.t,pts:x,angle:w,length:c.length}}).sort((c,l)=>c.lineDist-l.lineDist)}function Ia(t,e,n,o,r,s,i,a,u){let d=[{margin:s.projectionMargin,maxDist:s.maxDistance,label:"\u4E25\u683C"},{margin:.4,maxDist:.65,label:"\u5BBD\u677E"}],f=[],c=Cs(a)||e;for(let l of d){if(f.length>0)break;for(let h of t){let{start:g,end:x}=h,y=!1,m=1/0;for(let E of r){let{dist:S,t:I}=jt(E.x,E.y,g.x,g.y,x.x,x.y);I>=-l.margin&&I<=1+l.margin&&S<=l.maxDist&&(y=!0,S<m&&(m=S))}if(!y)continue;let p=null;if(u&&(p=Hs(u,g,x,.3)),!p||!p.hingePoint){let E=Is(a,g,x,.1);E&&E.hingeEdge&&(p={...E,hingePoint:E.hingeEdge?{x:E.hingeEdge.midX,y:E.hingeEdge.midY,z:0}:null,otherPoint:E.otherEdge?{x:E.otherEdge.midX,y:E.otherEdge.midY,z:0}:null})}p&&p.hingePoint&&jt(r[0].x,r[0].y,g.x,g.y,x.x,x.y).dist>.3&&(p=null);let b=!1;if(!p||!p.hingePoint){let E=jt(r[0].x,r[0].y,g.x,g.y,x.x,x.y);if(m<.15&&E.dist<.3&&h.originalPoints&&h.originalPoints.length>=50&&h.length>=.5)b=!0;else continue}if(!b&&(p.hingeT<-l.margin||p.hingeT>1+l.margin)){let E=jt(r[0].x,r[0].y,g.x,g.y,x.x,x.y);if(m<.15&&E.dist<.3&&h.originalPoints&&h.originalPoints.length>=50&&h.length>=.5)b=!0,h.__candidatesDebug="hingeT\u8D85\u8303\u56F4-\u5BC6\u5EA6\u515C\u5E95";else continue}let w=b?0:p.isClosed?1:.5,z=[r[1],r[2],r[3],r[4]],M=vs(g.x,g.y,x.x,x.y,z),P=c>0?M/c:0;f.push({seg:h,minDist:m,embedRatio:P,ratio:h.length/c,score:0,details:{conn:0,variance:0,sameSide:0},hingeInfo:p,hingeScore:w})}}return f}function Ca(t,e,n,o){if(t.length<=1)return t.length===1&&(t[0].score=-1),t;for(let r of t){let{score:s,details:i}=Os(r.seg,e,n);r.score=s,r.details=i}return t.sort((r,s)=>{let i=r.hingeScore||0;return(s.hingeScore||0)-i||s.embedRatio-r.embedRatio||s.score-r.score||r.minDist-s.minDist}),t}function Ha(t,e,n,o){let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=Math.sqrt(r*r+s*s),a=r/i,u=s/i,d=e.map(P=>{let E=P.x-t.start.x,S=P.y-t.start.y;return(E*a+S*u)/i}),f=Math.min(...d),c=Math.max(...d),l=(c-f)*i,h=(f+c)/2,g=t.start.x+h*r,x=t.start.y+h*s,y=n.coordinatesByArea.heightData?.minZ?n.coordinatesByArea.heightData.minZ:0,m=n.coordinatesByArea.heightData?.maxZ?n.coordinatesByArea.heightData.maxZ:0,p=Math.abs(m-y),b=Ge(o,t.start.x,t.start.y),w=Math.max(0,y-b),z=f<=0&&c>=1,M=t.start.z+h*(t.end.z-t.start.z);return{p:{x:g,y:x,z:M},width:l,full:z,height:p,groundClearance:w,wallTMin:Math.max(0,Math.min(1,f)),wallTMax:Math.max(0,Math.min(1,c))}}function Go(t,e,n){let o=e.map(f=>n[f]),r=[],s=[],i=[],a=[],u,d;for(let f of o){if(f.originalPoints?.length)for(let c of f.originalPoints)r.push(c);if(f.doorAndBeamData?.length)for(let c of f.doorAndBeamData)s.push(c);if(f.insetionArr?.length)for(let c of f.insetionArr)i.push(c);if(f.DrawDoor?.length)for(let c of f.DrawDoor)a.push(c);f.boxData&&!u&&(u=f.boxData),f.rooftopPz!==void 0&&(d===void 0||f.rooftopPz>d)&&(d=f.rooftopPz)}r.length&&(t.originalPoints=r),s.length&&(t.doorAndBeamData=s),i.length&&(t.insetionArr=i),a.length&&(t.DrawDoor=a),u&&(t.boxData=u),d!==void 0&&(t.rooftopPz=d)}function cn(t,e,n=10,o=.2,r=.2){let s=[];if(!t.DrawDoor)return s;let i=t.DrawDoor.p,a=t.wallSegment,u=a.end.x-a.start.x,d=a.end.y-a.start.y,f=Math.sqrt(u*u+d*d)||1,c=u/f,l=d/f,h=i.x-a.start.x,g=i.y-a.start.y,x=(h*c+g*l)/f;for(let y of e){if(y===a)continue;let m=y.end.x-y.start.x,p=y.end.y-y.start.y,b=Math.sqrt(m*m+p*p)||1,w=m/b,z=p/b,M=Math.abs(c*w+l*z),E=Math.acos(Math.min(M,1))*(180/Math.PI);if(Math.abs(E-90)>n)continue;let S=[y.start,y.end];for(let I of S){let W=I.x-a.start.x,v=I.y-a.start.y,T=(W*c+v*l)/f,R=a.start.x+T*f*c,D=a.start.y+T*f*l;if(Math.sqrt((I.x-R)**2+(I.y-D)**2)>r)continue;let V=Math.abs((T-x)*f);if(V<=o){s.push({seg:y,distAlongWall:V,angle:E,endPoint:I});break}}}return s}function Dn(t,e){let n=t.start,o=t.end,r=o.x-n.x,s=o.y-n.y,i=Math.sqrt(r*r+s*s)||1,a=((e.x-n.x)*r+(e.y-n.y)*s)/(i*i),u=Math.max(0,Math.min(1,a)),d={x:n.x+u*r,y:n.y+u*s,z:n.z+(o.z-n.z)*u||0};function f(b){if(!b||!b.length)return[[],[]];let w=[],z=[];for(let M of b){let P=((M.x-n.x)*r+(M.y-n.y)*s)/(i*i);P<=u+1e-8&&w.push(M),P>=u-1e-8&&z.push(M)}return(w.length===0||c(w[w.length-1],d)>1e-6)&&w.push({...d}),(z.length===0||c(z[0],d)>1e-6)&&z.unshift({...d}),[w,z]}function c(b,w){return Math.sqrt((b.x-w.x)**2+(b.y-w.y)**2)}let[l,h]=f(t.originalPoints),g=Math.max(u*i,1e-6),x=Math.max((1-u)*i,1e-6),y=t.direction||{x:r/i,y:s/i,z:(o.z-n.z)/i||0},m={...t,start:{...n},end:{...d},length:g,direction:{...y},originalPoints:l.length?l:void 0},p={...t,start:{...d},end:{...o},length:x,direction:{...y},originalPoints:h.length?h:void 0};if("isRebuild"in t&&(m.isRebuild=t.isRebuild,p.isRebuild=t.isRebuild),t.DrawDoor&&t.DrawDoor.length>0){let b=[],w=[];for(let z of t.DrawDoor){let M=((z.p.x-n.x)*r+(z.p.y-n.y)*s)/(i*i);M<=u+1e-8&&b.push(z),M>=u-1e-8&&w.push(z)}m.DrawDoor=b.length?b:void 0,p.DrawDoor=w.length?w:void 0}else m.DrawDoor=void 0,p.DrawDoor=void 0;if(t.boxData){let b=w=>{if(!w.length)return;let z=1/0,M=1/0,P=1/0,E=-1/0,S=-1/0,I=-1/0;for(let W of w)W.x<z&&(z=W.x),W.y<M&&(M=W.y),W.z!==void 0&&W.z<P&&(P=W.z),W.x>E&&(E=W.x),W.y>S&&(S=W.y),W.z!==void 0&&W.z>I&&(I=W.z);return{isBox3:!0,min:{x:z,y:M,z:P},max:{x:E,y:S,z:I}}};m.boxData=b(l),p.boxData=b(h)}return[m,p]}function vn(t,e,n,o){let r=Da(n),s=[],{segments:i,sourceMap:a}=o??Ye(e),u=i,d=_s(u);for(let f of t){let c=f.coordinatesByArea?.coordinates;if(!c||c.length<4)continue;let l=c.slice(0,4),h=Xo(f.nline),g=no(l),x,y,m,p,b;if(h?(x=h.midX,y=h.midY,m=h.length,p=h.dirX,b=h.dirY):(x=l.reduce((B,O)=>B+O.x,0)/4,y=l.reduce((B,O)=>B+O.y,0)/4,m=g.longSide,p=g.dirX,b=g.dirY),m<.01)continue;let w=l.reduce((B,O)=>B+O.z,0)/4,z=Ge(e,x,y);if(w<z-.3)continue;let M=Vs(l),P=[...l].sort((B,O)=>B.z-O.z),E=P[0].x-P[1].x,S=P[0].y-P[1].y,I=Math.sqrt(E*E+S*S),W=va(l,x,y);Va(f.name,u,x,y,W,m,p,b,r);let v=Ia(u,I,p,b,W,r,f.name,M,f.nline);if(v.length>0)for(let B=0;B<v.length;B++){let O=v[B],$=O.seg,Z=!!O.hingeInfo?.hingePoint,Q=O.hingeInfo?.isClosed,j=O.hingeInfo?.hingeDist??-1,X=jt(W[0].x,W[0].y,$.start.x,$.start.y,$.end.x,$.end.y)}if(v=Ca(v,W,e,f.name),v.length===0){for(let O of u){let $=O.start.x+(O.end.x-O.start.x)/2-x,Z=O.start.y+(O.end.y-O.start.y)/2-y;if(Math.sqrt($*$+Z*Z)>2)continue;let j=O.end.x-O.start.x,X=O.end.y-O.start.y,U=Math.sqrt(j*j+X*X),at=j/U,mt=X/U,St=Math.abs(at*p+mt*b),ot=Math.acos(Math.min(1,Math.abs(St)))*180/Math.PI,Mt=jt(x,y,O.start.x,O.start.y,O.end.x,O.end.y)}let B=0;for(let O of u)jt(x,y,O.start.x,O.start.y,O.end.x,O.end.y).dist<2&&B++}let T=I;for(let B of v){let O=B.seg;if(O.originalPoints&&O.originalPoints.length>100&&O.length>.5)try{let $=oo(O,.1),Z=Bs(O,$,O.length,.5,.5,3,.35),Q,j=!1;if(f.nline){let mt=Ls(f.nline,O.start,O.end);if(mt)Q=mt.hingeT,j=mt.hingeDist>.05;else{let St=jt(x,y,O.start.x,O.start.y,O.end.x,O.end.y);Q=Math.max(0,Math.min(1,St.t))}}else{let mt=jt(x,y,O.start.x,O.start.y,O.end.x,O.end.y);Q=Math.max(0,Math.min(1,mt.t))}let X=Ws($),U,at=X<=.3;at?U={score:Zo($.avgDensity,d),bestRegion:null,bestOverlap:0,bestOpeningStartT:0,bestOpeningEndT:1}:(U=ks({hingeT:Q,doorWidth:T,isOpenDoor:j},Z,O.length,d.medianDensity),U.score<0&&(U={score:Zo($.avgDensity,d),bestRegion:null,bestOverlap:0,bestOpeningStartT:0,bestOpeningEndT:1})),f.name.includes("door_002")&&(window.__doorLog=!0),B.densityScore=U.score,B.densityOverlap=U.bestOverlap,B.rectangularRegions=Z,B.densityResult=$,B.densityOpeningStartT=U.bestOpeningStartT,B.densityOpeningEndT=U.bestOpeningEndT,B.densityCV=X,B.densityUsedGlobalRank=at}catch{B.densityScore=-1}else B.densityScore=-1}if(f.name.includes("door_002"))for(let B=0;B<v.length;B++){let $=v[B].seg,Z=u.findIndex(j=>Math.abs(j.start.x-$.start.x)<.001&&Math.abs(j.start.y-$.start.y)<.001&&Math.abs(j.end.x-$.end.x)<.001&&Math.abs(j.end.y-$.end.y)<.001),Q=Z>=0?a[Z]||[]:[];for(let j of Q){let X=e[j]}}if(v.sort((B,O)=>{let $=B.densityScore>=0?B.densityScore:-1/0,Z=O.densityScore>=0?O.densityScore:-1/0;if($!==Z)return Z-$;if(Math.abs($-Z)<.3){let X=B.ratio||0,U=O.ratio||0,at=Math.abs(X-1),mt=Math.abs(U-1);if(at!==mt)return at-mt}let Q=B.hingeScore||0,j=O.hingeScore||0;return Q!==j?j-Q:B.minDist-O.minDist}),v.length>0)for(let B=0;B<v.length;B++){let O=v[B],$=O.seg,Z=O.ratio||$.length/T,Q=Math.abs(Z-1)}let R=null,D=1/0,H=0,V=0,C=null,_=-1,A=0,L=0,k=0;if(v.length>0){let B=v[0];R=B.seg,D=B.minDist,H=B.ratio,V=B.embedRatio,C=B.hingeInfo,_=B.densityScore??-1,A=B.densityOverlap??0,L=B.densityOpeningStartT??0,k=B.densityOpeningEndT??0}let F;if(R&&(F=Ha(R,l,f,i),F&&k>L&&(F.wallTMin=Math.max(0,Math.min(1,L)),F.wallTMax=Math.max(0,Math.min(1,k))),!r.printOnly)){let B=R;B.DrawDoor||(B.DrawDoor=[]),B.DrawDoor.push(F),B.isDoor=!0}if(R){let B=v.map(($,Z)=>{let Q=$.seg;return{start:{x:Q.start.x,y:Q.start.y,z:Q.start.z},end:{x:Q.end.x,y:Q.end.y,z:Q.end.z},length:Q.length,densityScore:$.densityScore??-1,hingeScore:$.hingeScore??0,minDist:$.minDist,ratio:$.ratio,isWinner:Z===0}}),O={doorName:f.name,doorCategory:f.category,doorCenter:f.center,wallSegment:R,distance:D,wallLengthRatio:H,DrawDoor:F,densityScore:_,densityOverlap:A,candidates:B,hingePoint:C?.hingePoint,otherPoint:C?.otherPoint,isClosed:C?.isClosed,doorWidth:F?.width,wallTMin:F?.wallTMin,wallTMax:F?.wallTMax};if(s.push(O),(f.name==="1527727501200_window_001"||f.name==="1527727427200_window_001")&&F){let $=R.end.x-R.start.x,Z=R.end.y-R.start.y,Q=Math.sqrt($*$+Z*Z),j=$/Q,X=Z/Q,U=F.p.x-R.start.x,at=F.p.y-R.start.y,mt=(U*j+at*X)/Q,St=0;for(let ot of i){if(ot===R)continue;let Mt=ot.end.x-ot.start.x,bt=ot.end.y-ot.start.y,Ct=Math.sqrt(Mt*Mt+bt*bt)||1,Et=Mt/Ct,zt=bt/Ct,Pt=Math.abs(j*Et+X*zt),et=Math.acos(Math.min(Pt,1))*(180/Math.PI);if(Math.abs(et-90)>10)continue;St++;let ht=[ot.start,ot.end],nt="";for(let J of ht){let le=J.x-R.start.x,wt=J.y-R.start.y,te=(le*j+wt*X)/Q,ge=R.start.x+te*Q*j,Dt=R.start.y+te*Q*X,ne=Math.sqrt((J.x-ge)**2+(J.y-Dt)**2),xe=Math.abs((te-mt)*Q);nt+=`\u7AEF(${J.x.toFixed(2)},${J.y.toFixed(2)})\u22A5=${ne.toFixed(3)}m \u6CBF\u5899=${xe.toFixed(3)}m `}}}if(F&&F.width>1){let $=cn(O,i);$.length>0&&$.forEach((Z,Q)=>{})}}}for(let f of s){let c=f.wallSegment,l=i.indexOf(c);if(l===-1)continue;let h=a[l];!h||h.length<=1||Go(c,h,e)}return s}function ro(t){return[t.wallTMin??0,t.wallTMax??1]}function Wa(t,e){let[n,o]=ro(t),[r,s]=ro(e),i=Math.max(0,Math.min(o,s)-Math.max(n,r)),a=Math.min(o-n,s-r);return a>0?i/a:0}function _a(t,e){if(!t.hingePoint||!e.hingePoint)return null;let n=t.hingePoint.x-e.hingePoint.x,o=t.hingePoint.y-e.hingePoint.y;return Math.sqrt(n*n+o*o)}function Fs(t,e){let n=e.end.x-e.start.x,o=e.end.y-e.start.y,r=n*n+o*o;if(r<1e-10)return 0;let s=((t.x-e.start.x)*n+(t.y-e.start.y)*o)/r;return Math.max(0,Math.min(1,s))}function Ns(t,e={}){let n=e.minTOverlapRatio??.5,o=e.maxHingeDist??.3,r=e.minHingeTOverlapRatio??.2;if(t.length<2)return{matches:t,removed:[]};let s=new Set,i=new Map;for(let f=0;f<t.length;f++){let l=t[f].wallSegment;i.has(l)||i.set(l,[]),i.get(l).push(f)}let a=0;for(let[f,c]of i){a++;let l=c.map(x=>t[x].doorName).join(", "),h=f.start,g=f.end}for(let[,f]of i){if(f.length<2)continue;let c=[...f].sort((l,h)=>{let g=t[l].densityScore??0;return(t[h].densityScore??0)-g});for(let l=0;l<c.length;l++){let h=c[l];if(s.has(h))continue;let g=t[h];for(let x=l+1;x<c.length;x++){let y=c[x];if(s.has(y))continue;let m=t[y],p=!1,b="",w=Wa(g,m),z=[g.hingePoint,g.otherPoint].filter(Boolean),M=[m.hingePoint,m.otherPoint].filter(Boolean),P=null;for(let H of z)for(let V of M){let C=Math.sqrt((H.x-V.x)**2+(H.y-V.y)**2);if(C>.25)continue;let _=Fs(H,g.wallSegment),A=Fs(V,m.wallSegment),L=Math.abs(_-A);(!P||C<P.dist)&&(P={dist:C,tDiff:L})}P&&P.tDiff<=.08&&(p=!0,b=`\u6700\u77ED\u8FB9\u8DDD=${P.dist.toFixed(3)}m t\u5DEE=${P.tDiff.toFixed(3)}`);let[E,S]=ro(g),[I,W]=ro(m),v=_a(g,m);g.doorName.includes("door_002")||g.doorName.includes("door_004")||m.doorName.includes("door_002")||m.doorName.includes("door_004");let T=[g.hingePoint,g.otherPoint].filter(Boolean),R=[m.hingePoint,m.otherPoint].filter(Boolean),D=1/0;for(let H of T)for(let V of R){let C=Math.sqrt((H.x-V.x)**2+(H.y-V.y)**2);C<D&&(D=C)}p&&s.add(y)}}}let u=t.filter((f,c)=>!s.has(c)),d=t.filter((f,c)=>s.has(c)).map(f=>f.doorName);return{matches:u,removed:d}}function Yo(t,e,n){let o={printOnly:!1,skipMerge:!1,...n};for(let m of t)m.DrawDoor&&(m.DrawDoor=void 0),m.isDoor&&(m.isDoor=void 0),m.drawDoorData&&(m.drawDoorData=void 0);let r=Array.isArray(e)?e.filter(m=>m&&m.category==="door"&&!m.isFindBeam):[],s,i;if(o.skipMerge)s=t,i=t.map((m,p)=>[p]);else{let m=Ye(t);s=m.segments,i=m.sourceMap}for(let m=0;m<s.length;m++){let p=i[m];p&&!s[m].originalPoints&&Go(s[m],p,t)}let a=vn(r,t,o,{segments:s,sourceMap:i}),d=Ns(a,{minTOverlapRatio:.5}).matches,f=new Set(d.map(m=>m.doorName));for(let m of s){let p=m;if(p.DrawDoor&&p.DrawDoor.length>0){let b=a.filter(z=>z.wallSegment===m).length;d.filter(z=>z.wallSegment===m).length===0&&(p.DrawDoor=[],p.isDoor=!1)}}let c=new Map;for(let m=0;m<d.length;m++){let p=d[m],b=s.indexOf(p.wallSegment);b>=0&&c.set(b,m)}let l=[],h=new Set,g=new Map;for(let m of e)m&&m.name&&g.set(m.name,m);for(let[m,p]of c){let b=i[m];if(!b)continue;let w=s[m],z=w.DrawDoor,M=w.isDoor,P=w.end.x-w.start.x,E=w.end.y-w.start.y,S=P*P+E*E,I=0,W=1,v=d[p],R=(v?g.get(v.doorName):void 0)?.coordinatesByArea?.coordinates;if(R&&R.length>=4&&S>0){let C=R.slice(0,4).map(_=>{let A=_.x-w.start.x,L=_.y-w.start.y;return(A*P+L*E)/S});I=Math.max(0,Math.min(1,Math.min(...C))),W=Math.max(0,Math.min(1,Math.max(...C)))}let D,H;S>0&&W>I&&(D={x:w.start.x+I*P,y:w.start.y+I*E,z:w.start.z+I*(w.end.z-w.start.z)},H={x:w.start.x+W*P,y:w.start.y+W*E,z:w.start.z+W*(w.end.z-w.start.z)});let V=!1;for(let C of b){let _=t[C];if(!_)continue;let A=_.end.x-_.start.x,L=_.end.y-_.start.y,k=A*A+L*L,F=Math.sqrt(k);if(k<1e-10||!D||!H){h.add(C),l.push(_);continue}let B=((D.x-_.start.x)*A+(D.y-_.start.y)*L)/k,O=((H.x-_.start.x)*A+(H.y-_.start.y)*L)/k,$=Math.max(0,Math.min(1,Math.min(B,O))),Z=Math.max(0,Math.min(1,Math.max(B,O)));if(Z-$<.001)continue;h.add(C);let Q=ot=>({x:_.start.x+ot*A,y:_.start.y+ot*L,z:_.start.z+ot*(_.end.z-_.start.z)}),j=Q($),X=Q(Z),U=_.direction||{x:A/F,y:L/F,z:0},at,mt,St;if(_.originalPoints&&_.originalPoints.length>0){at=[],mt=[],St=[];for(let ot of _.originalPoints){let Mt=((ot.x-_.start.x)*A+(ot.y-_.start.y)*L)/k;Mt<$-1e-8?at.push(ot):Mt>Z+1e-8?St.push(ot):mt.push(ot)}at.length===0&&(at=void 0),mt.length===0&&(mt=void 0),St.length===0&&(St=void 0)}if($>.001){let ot={..._,start:{..._.start},end:{...j},length:$*F,direction:{...U}};ot.DrawDoor=void 0,ot.isDoor=!1,ot.drawDoorData=void 0,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=at,l.push(ot)}{let ot={..._,start:{...j},end:{...X},length:(Z-$)*F,direction:{...U}};if(z&&(ot.DrawDoor=z),M&&(ot.isDoor=!0),ot.__matchIdx=p,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=mt,!V&&z&&z.length>0){let Mt=0;for(let Pt=0;Pt<z.length;Pt++)if(yr(D,H,z[Pt].p)){Mt=Pt;break}V=!0;let bt=Math.sqrt(S),Ct=bt>0?-E/bt:0,Et=bt>0?P/bt:0,zt={pointNum:2,start:D,end:H,n:{x:Ct,y:Et,z:0},height:z[Mt].height,groundClearance:z[Mt].groundClearance};ot.drawDoorData=zt}l.push(ot)}if(Z<.999){let ot={..._,start:{...X},end:{..._.end},length:(1-Z)*F,direction:{...U}};ot.DrawDoor=void 0,ot.isDoor=!1,ot.drawDoorData=void 0,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=St,l.push(ot)}}}for(let m=0;m<t.length;m++)h.has(m)||l.push(t[m]);let x=new Set(d.map(m=>m.doorName));for(let m of e)m&&m.category==="door"&&(x.has(m.name)?delete m.AbnormalDoor:m.AbnormalDoor=!0);let y=new Map;for(let m of d){if(!m.DrawDoor||m.DrawDoor.width<=1)continue;let p=g.get(m.doorName);if(!p||!p.positionArr||!p.positionArr.length)continue;let b=cn(m,s);if(b.length<=1)continue;let w=p.positionArr[0],z=m.DrawDoor.p,M=w.x-z.x,P=w.y-z.y,E=Math.sqrt(M*M+P*P);if(E<.001)continue;let S=M/E,I=P/E,W=b.filter(C=>{let _=(C.seg.start.x+C.seg.end.x)/2,A=(C.seg.start.y+C.seg.end.y)/2,L=_-z.x,k=A-z.y;return L*S+k*I>0});if(!W.length)continue;let v=W[0].endPoint,T=m.wallSegment;if(y.has(T))continue;let[R,D]=Dn(T,v);y.set(T,[R,D]);let H=((z.x-T.start.x)*(T.end.x-T.start.x)+(z.y-T.start.y)*(T.end.y-T.start.y))/(T.length*T.length),V=((v.x-T.start.x)*(T.end.x-T.start.x)+(v.y-T.start.y)*(T.end.y-T.start.y))/(T.length*T.length);H<=V?m.wallSegment=R:m.wallSegment=D}if(y.size>0){let m=[];for(let p of l)y.has(p)?m.push(...y.get(p)):m.push(p);for(let p of m)p.isDoor=!!(p.DrawDoor&&p.DrawDoor.length>0);return{segments:m,matches:d}}for(let m of l)m.isDoor=!!(m.DrawDoor&&m.DrawDoor.length>0);return{segments:l,matches:d}}var Aa={findWalls:Rn,mergeSegments:Xe,computeFloorZ:$e,analyzeQuadrangle:je,detectPerpWalls:Tn,splitSegment:Sn,process:jo},Ba={findWalls:vn,mergeSegments:Ye,computeFloorZ:Ge,analyzeQuadrangle:je,detectPerpWalls:cn,splitSegment:Dn,process:Yo};function un(t){return t==="window"?Aa:Ba}function La(t,e,n,o,r){return un(t).findWalls(e,n,o,r)}function ka(t,e,n,o){return un(t).process(e,n,o)}function Oa(t,e){return un(t).mergeSegments(e)}function Fa(t,e,n){return un(t).detectPerpWalls(e,n)}function Na(t,e,n){return un(t).splitSegment(e,n)}function Ue(t,e){let n=Math.atan2(e,t);return n<0&&(n+=Math.PI),n>=Math.PI&&(n-=Math.PI),n}function He(t,e,n){let o=Math.cos(n),r=Math.sin(n);return{x:t*o-e*r,z:t*r+e*o}}function so(t,e,n,o,r,s){let i=r-n,a=s-o,u=i*i+a*a;if(u<1e-10){let g=t-n,x=e-o;return Math.sqrt(g*g+x*x)}let d=((t-n)*i+(e-o)*a)/u;d=Math.max(0,Math.min(1,d));let f=n+d*i,c=o+d*a,l=t-f,h=e-c;return Math.sqrt(l*l+h*h)}function qs(t){if(t.length<3)return 0;let e=0,n=t.length;for(let o=0;o<n;o++){let r=(o+1)%n;e+=t[o].x*t[r].z,e-=t[r].x*t[o].z}return Math.abs(e)/2}function Uo(t){let e=t.x2-t.x1,n=t.z2-t.z1;return Math.sqrt(e*e+n*n)}function io(t){if(!t.length)return{rotated:[],mainAngle:0};let e=180,n=new Array(e).fill(0),o=Math.PI/e;for(let f of t){let c=f.x2-f.x1,l=f.z2-f.z1,h=Math.sqrt(c*c+l*l);if(h<.01)continue;let g=Ue(c,l),x=Math.floor(g/o);x>=e&&(x=e-1),n[x]+=h}let r=new Array(e).fill(0),s=5;for(let f=0;f<e;f++){let c=0;for(let l=-s;l<=s;l++){let h=f+l;h<0&&(h+=e),h>=e&&(h-=e),c+=n[h]}r[f]=c}let i=0,a=0;for(let f=0;f<e;f++)r[f]>i&&(i=r[f],a=f);let u=(a+.5)*o;return{rotated:t.map(f=>{let c=He(f.x1,f.z1,-u),l=He(f.x2,f.z2,-u);return{...f,x1:c.x,z1:c.z,x2:l.x,z2:l.z}}),mainAngle:u}}var Ko=15*(Math.PI/180);function lo(t,e,n=.15,o=.5){let r=[];for(let f of t){let c=f.x2-f.x1,l=f.z2-f.z1,h=Math.sqrt(c*c+l*l);if(h<.01)continue;let g=Ue(c,l),x;if(e==="X"?x=g<Ko||g>Math.PI-Ko:x=Math.abs(g-Math.PI/2)<Ko,!x)continue;let y,m,p;e==="X"?(y=(f.z1+f.z2)/2,m=Math.min(f.x1,f.x2),p=Math.max(f.x1,f.x2)):(y=(f.x1+f.x2)/2,m=Math.min(f.z1,f.z2),p=Math.max(f.z1,f.z2)),r.push({line:f,offset:y,pStart:m,pEnd:p,length:h})}if(r.length===0)return{groups:[],lineToGroup:new Map};r.sort((f,c)=>f.offset-c.offset);let s=[],i=[r[0]],a=r[0].offset;for(let f=1;f<r.length;f++){let c=r[f];Math.abs(c.offset-a)<n?i.push(c):(s.push(i),i=[c],a=c.offset)}i.length>0&&s.push(i);let u=[],d=new Map;for(let f of s){f.sort((l,h)=>l.pStart-h.pStart);let c=[];for(let l of f){let h=!1;for(let g of c)if(l.pStart<=g.end+o){g.items.push(l),g.end=Math.max(g.end,l.pEnd),h=!0;break}h||c.push({items:[l],end:l.pEnd})}for(let l of c){let h=l.items.map(x=>x.line),g=u.length;u.push(h);for(let x of h)d.set(x.id,g)}}return{groups:u,lineToGroup:d}}function ao(t,e,n=.3){let o=new Map;for(let r of t){let s=null,i=1/0;for(let a of e){let u=so(r.x,r.z,a.x1,a.z1,a.x2,a.z2);u<i&&(i=u,s=a.id)}s!==null&&i<=n&&o.set(r.id,s)}return o}var fn=.15;function qa(t,e){return Math.round(t/fn)+"_"+Math.round(e/fn)}function js(t,e=5){if(t.length<3)return new Set;let n=new Map,o=0,r=0;function s(u,d){let f=qa(u,d),c=n.get(f);if(c)return c;let l=Math.round(u/fn),h=Math.round(d/fn),g=null,x=fn*fn;for(let y=-1;y<=1;y++)for(let m=-1;m<=1;m++){let p=l+y+"_"+(h+m),b=n.get(p);if(!b)continue;let w=b.x-u,z=b.z-d,M=w*w+z*z;M<x&&(x=M,g=b)}return g?(n.set(f,g),g):(c={id:o++,x:u,z:d,edges:[]},n.set(f,c),c)}let i=[];for(let u of t){let d=s(u.x1,u.z1),f=s(u.x2,u.z2);if(d.id===f.id)continue;let c=Math.atan2(f.z-d.z,f.x-d.x),l=Math.atan2(d.z-f.z,d.x-f.x),h={id:r++,wallId:u.id,from:d,to:f,twin:null,angle:c,visited:!1},g={id:r++,wallId:u.id,from:f,to:d,twin:h,angle:l,visited:!1};h.twin=g,d.edges.push(h),f.edges.push(g),i.push(h,g)}if(i.length<6)return new Set;for(let u of n.values())u.edges.sort((d,f)=>d.angle-f.angle);let a=new Set;for(let u of i){if(u.visited)continue;let d=[],f=u,c=i.length+10;for(;!f.visited&&d.length<c;){f.visited=!0,d.push(f);let l=f.to,h=f.twin,g=l.edges.indexOf(h);if(g<0)break;let x=(g+1)%l.edges.length;f=l.edges[x]}if(d.length>=3){let l=d[0];if(d[d.length-1].to.id===l.from.id){let g=[],x=new Set;for(let m of d)x.add(m.wallId),g.length===0&&g.push({x:m.from.x,z:m.from.z}),g.push({x:m.to.x,z:m.to.z});if(qs(g)>=e)for(let m of x)a.add(m)}}}return a}var Ep=12*(Math.PI/180);function $s(t,e=2){let n=new Map;for(let o of t){let r=(o.x1+o.x2)/2,s=(o.z1+o.z2)/2,i=Math.floor(r/e),a=Math.floor(s/e),u=`${i},${a}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}var ja=0;function Xs(){return++ja}function Zs(t,e,n=.15,o=.5){if(!t.length)return[];let r=10*Math.PI/180,s=[];for(let f of t){let c=f.x2-f.x1,l=f.z2-f.z1,h=Math.sqrt(c*c+l*l);if(!(h<.01))if(e==="X"){if(Math.abs(l)>h*Math.sin(r))continue;let g=(f.z1+f.z2)/2,x=Math.min(f.x1,f.x2),y=Math.max(f.x1,f.x2);s.push({line:f,pStart:x,pEnd:y,offset:g,yMin:Math.min(f.y1,f.y2),yMax:Math.max(f.y1,f.y2)})}else{if(Math.abs(c)>h*Math.sin(r))continue;let g=(f.x1+f.x2)/2,x=Math.min(f.z1,f.z2),y=Math.max(f.z1,f.z2);s.push({line:f,pStart:x,pEnd:y,offset:g,yMin:Math.min(f.y1,f.y2),yMax:Math.max(f.y1,f.y2)})}}if(!s.length)return[];s.sort((f,c)=>f.offset-c.offset);let i=[],a=[s[0]],u=s[0].offset;for(let f=1;f<s.length;f++){let c=s[f];Math.abs(c.offset-u)<n?a.push(c):(i.push(a),a=[c],u=c.offset)}i.push(a);let d=[];for(let f of i){f.sort((l,h)=>l.pStart-h.pStart);let c=[];for(let l of f){if(c.length===0){c.push({pStart:l.pStart,pEnd:l.pEnd,offset:l.offset,count:1,yMin:l.yMin,yMax:l.yMax});continue}let h=c[c.length-1];l.pStart<=h.pEnd+o?(h.pEnd=Math.max(h.pEnd,l.pEnd),h.count+=1,h.yMin=Math.min(h.yMin,l.yMin),h.yMax=Math.max(h.yMax,l.yMax),h.offset=(h.offset*(h.count-1)+l.offset)/h.count):c.push({pStart:l.pStart,pEnd:l.pEnd,offset:l.offset,count:1,yMin:l.yMin,yMax:l.yMax})}for(let l of c){let h=l.pEnd-l.pStart;if(h<.01)continue;let g;e==="X"?g={id:Xs(),x1:l.pStart,y1:l.yMin,z1:l.offset,x2:l.pEnd,y2:l.yMax,z2:l.offset,length:h,pointCount:l.count,isMain:!1}:g={id:Xs(),x1:l.offset,y1:l.yMin,z1:l.pStart,x2:l.offset,y2:l.yMax,z2:l.pEnd,length:h,pointCount:l.count,isMain:!1},d.push(g)}}return d}function Gs(t,e=.8,n=3){return t.filter(o=>o.length>=e&&o.pointCount>=n)}function Ys(t,e=1,n=3){return t.filter(o=>o.length>=e&&o.pointCount>=n)}function $a(t,e,n={}){let{distTol:o=.15,gapTol:r=.5,minLen:s=.2,minGroupLen:i=1,minArea:a=3,maxWinDist:u=.3,minLongWall:d=2}=n,f=performance.now(),{rotated:c,mainAngle:l}=io(t),h=performance.now(),g=e.map(D=>{let H=He(D.x,D.z,-l);return{...D,x:H.x,z:H.z}}),{groups:x}=lo(c,"X",o,r),{groups:y}=lo(c,"Z",o,r),m=[...x,...y],p=performance.now(),b=new Map,w=[];for(let D=0;D<m.length;D++){let H=m[D];if(H.length===0){w.push(0);continue}let V=0;for(let C of H)V+=Uo(C),b.set(C.id,D);w.push(V)}let z=performance.now(),M=new Set;for(let D=0;D<m.length;D++)w[D]>=d&&M.add(D);if(M.size>0){let D=[...M];for(;D.length>0;){let H=D.shift(),V=m[H];for(let C=0;C<m.length;C++){if(M.has(C)||w[C]<i)continue;let _=m[C],A=!1;t:for(let L of V)for(let k of _)if(Math.hypot(L.x1-k.x1,L.z1-k.z1)<=co||Math.hypot(L.x1-k.x2,L.z1-k.z2)<=co||Math.hypot(L.x2-k.x1,L.z2-k.z1)<=co||Math.hypot(L.x2-k.x2,L.z2-k.z2)<=co){A=!0;break t}A&&(M.add(C),D.push(C))}}}let P=c.map((D,H)=>{let V=Uo(D),C=b.get(D.id),_=C!==void 0&&M.has(C),A=V>=d;return{id:H,x1:D.x1,y1:D.y1,z1:D.z1,x2:D.x2,y2:D.y2,z2:D.z2,length:V,pointCount:1,isMain:_||A}}),E=P.filter(D=>D.isMain),S=P.filter(D=>!D.isMain),I=performance.now(),W=ao(g,E,u),v=performance.now(),T=D=>D.map(H=>{let V=He(H.x1,H.z1,l),C=He(H.x2,H.z2,l);return{...H,x1:V.x,z1:V.z,x2:C.x,z2:C.z}}),R=performance.now();return console.log(`[\u4E3B\u4F53\u67B6\u6784] \u89D2\u5EA6\u5F52\u4E00\u5316: ${(h-f).toFixed(0)}ms`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u5171\u7EBF\u5206\u7EC4: ${(p-h).toFixed(0)}ms (\u6C34\u5E73${x.length}\u7EC4 \u5782\u76F4${y.length}\u7EC4)`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u7EC4\u5206\u6790+\u4E3B\u4F53\u5224\u5B9A: ${(R-p).toFixed(0)}ms (\u4E3B\u4F53\u7EC4${M.size} / \u603B\u7EC4${m.length})`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u6807\u8BB0\u539F\u59CB\u7EBF\u6BB5: ${(I-R).toFixed(0)}ms (\u4E3B\u4F53${E.length} / \u6742\u7EBF${S.length})`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u7A97\u6237\u6302\u63A5: ${(v-I).toFixed(0)}ms`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u603B\u8BA1: ${(v-f).toFixed(0)}ms`),{mainWalls:T(E),noiseWalls:T(S),windowToWall:W}}var co=.2;function Se(t,e){let n=Math.atan2(e,t);return n<0&&(n+=Math.PI),n>=Math.PI&&(n-=Math.PI),n}function Vn(t){for(;t>Math.PI;)t-=2*Math.PI;for(;t<-Math.PI;)t+=2*Math.PI;return t}function uo(t){return t*Math.PI/180}function In(t,e,n){let o=Math.cos(n),r=Math.sin(n);return{x:t*o-e*r,z:t*r+e*o}}function Re(t){let e=0;for(let n=1;n<t.length;n++){let o=t[n].x-t[n-1].x,r=t[n].z-t[n-1].z;e+=Math.sqrt(o*o+r*r)}return e}function Qo(t){if(t.length<3)return 0;let e=0,n=t.length;for(let o=0;o<n;o++){let r=(o+1)%n;e+=t[o].x*t[r].z,e-=t[r].x*t[o].z}return Math.abs(e)/2}function Me(t,e,n,o){let r=n-t,s=o-e;return Math.sqrt(r*r+s*s)}function Cn(t,e,n,o,r,s){let i=r-n,a=s-o,u=i*i+a*a;if(u<1e-6)return Me(t,e,n,o);let d=((t-n)*i+(e-o)*a)/u;return d=Math.max(0,Math.min(1,d)),Me(t,e,n+d*i,o+d*a)}function Jo(t){if(t.length<4)return t;let e=t.map(n=>({x:n.x,z:n.z}));for(let n=0;n<3;n++){let o=[{...e[0]}];for(let r=1;r<e.length-1;r++)o.push({x:(e[r-1].x+e[r].x+e[r+1].x)/3,z:(e[r-1].z+e[r].z+e[r+1].z)/3});o.push({...e[e.length-1]}),e=o}return e}function Us(t,e){let n=1/0;for(let o of t)for(let r=0;r<e.length-1;r++){let s=Cn(o.x,o.z,e[r].x,e[r].z,e[r+1].x,e[r+1].z);s<n&&(n=s)}return n}function fo(t,e){let n=new Map,o=1/0,r=-1/0,s=1/0,i=-1/0;for(let a of t){let u=Math.floor(a.x/e),d=Math.floor(a.z/e),f=u+","+d;n.set(f,(n.get(f)||0)+1),u<o&&(o=u),u>r&&(r=u),d<s&&(s=d),d>i&&(i=d)}return{cells:n,minX:o,maxX:r,minZ:s,maxZ:i}}function Ks(t,e){let n=new Set,o=1/0,r=-1/0,s=1/0,i=-1/0,a=(u,d)=>{let f=u+","+d;n.add(f),u<o&&(o=u),u>r&&(r=u),d<s&&(s=d),d>i&&(i=d)};for(let u of t){let d=u.x1,f=u.z1,c=u.x2,l=u.z2,h=Math.floor(d/e),g=Math.floor(f/e),x=Math.floor(c/e),y=Math.floor(l/e),m=Math.abs(x-h),p=Math.abs(y-g),b=h<x?1:-1,w=g<y?1:-1,z=m-p,M=Math.max(m,p)*2+5,P=0;for(;P++<M&&(a(h,g),!(h===x&&g===y));){let E=2*z;E>-p&&(z-=p,h+=b),E<m&&(z+=m,g+=w)}}return{active:n,minX:o,maxX:r,minZ:s,maxZ:i}}function Wn(t,e=1){let n=new Set(t);for(let o=0;o<e;o++){let r=new Set(n);for(let i of n){let[a,u]=i.split(",").map(Number);for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++)d===0&&f===0||r.add(a+d+","+(u+f))}let s=new Set(r);for(let i of r){let[a,u]=i.split(",").map(Number),d=!0;for(let f=-1;f<=1;f++){for(let c=-1;c<=1;c++)if(!r.has(a+f+","+(u+c))){d=!1;break}if(!d)break}d||s.delete(i)}n.clear();for(let i of s)n.add(i)}return n}function tr(t){let e=[],n=new Set;for(let o of t){if(n.has(o))continue;let r=new Set,s=[o];for(n.add(o);s.length>0;){let i=s.shift();r.add(i);let[a,u]=i.split(",").map(Number);for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++){if(d===0&&f===0)continue;let c=a+d+","+(u+f);t.has(c)&&!n.has(c)&&(n.add(c),s.push(c))}}r.size>=4&&e.push(r)}return e}function er(t,e){if(t.size<3)return[];let n=new Set,o=(g,x)=>t.has(g+","+x);for(let g of t){let[x,y]=g.split(",").map(Number);(!o(x+1,y)||!o(x-1,y)||!o(x,y+1)||!o(x,y-1))&&n.add(g)}if(n.size<3)return[];let r="",s=1/0,i=1/0;for(let g of n){let[x,y]=g.split(",").map(Number);(y<s||y===s&&x<i)&&(s=y,i=x,r=g)}if(!r)return[];let a=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]],u=[],[d,f]=r.split(",").map(Number),c=0,l=new Set,h=n.size*8;for(let g=0;g<h;g++){let y=d+","+f+"|"+c;if(l.has(y))break;l.add(y),u.push({x:(d+.5)*e,z:(f+.5)*e});let m=(c+3)%8,p=!1;for(let b=0;b<8;b++){let w=(m+b)%8,z=d+a[w][0],M=f+a[w][1];if(n.has(z+","+M)){c=(w+4)%8,d=z,f=M,p=!0;break}}if(!p||d+","+f===r&&u.length>2)break}return u}function Hn(t,e){if(t.length<=2)return[...t];let n=0,o=0,r=t[0],s=t[t.length-1];for(let i=1;i<t.length-1;i++){let a=Cn(t[i].x,t[i].z,r.x,r.z,s.x,s.z);a>n&&(n=a,o=i)}if(n>e){let i=Hn(t.slice(0,o+1),e),a=Hn(t.slice(o),e);return[...i.slice(0,-1),...a]}return[r,s]}var nr={cellSize:.1,densityThreshold:1,minComponentCells:20,simplifyEpsilon:.01,heightMin:.3,heightMax:2.8,closeIterations:5,sparseRadius:.3,sparseMinNeighbors:5,lineDensityMin:0,lineDensityMinLen:1,densityRatio:.12};function dn(t){let e=t.length;if(e<3)return{cx:0,cz:0,r:0,rmsResidual:0};let n=0,o=0,r=0,s=0,i=0,a=0,u=0,d=0,f=0;for(let m of t){let p=m.x,b=m.z;n+=p,o+=b,r+=p*p,s+=b*b,i+=p*b,a+=p*p*p,u+=b*b*b,d+=p*p*b,f+=p*b*b}let c=2*(e*(r+s)-n*n-o*o);if(Math.abs(c)<1e-10)return{cx:0,cz:0,r:0,rmsResidual:0};let l=(e*(a+f)-n*(r+s))/c,h=(e*(d+u)-o*(r+s))/c,g=Math.sqrt(Math.abs((r+s-2*l*n-2*h*o)/e+l*l+h*h)),x=0;for(let m of t){let b=Math.hypot(m.x-l,m.z-h)-g;x+=b*b}let y=Math.sqrt(x/e);return{cx:l,cz:h,r:g,rmsResidual:y}}function Xa(t){let e=t.length;if(e<4)return{eigenRatio:1,isLinear:!1,spread:0,mx:0,mz:0,v1x:1,v1z:0,v2x:0,v2z:1,s1:0,s2:0};let n=0,o=0;for(let w of t)n+=w.x,o+=w.z;n/=e,o/=e;let r=0,s=0,i=0;for(let w of t){let z=w.x-n,M=w.z-o;r+=z*z,s+=M*M,i+=z*M}r/=e,s/=e,i/=e;let a=r+s,u=Math.max(0,(r-s)*(r-s)+4*i*i),d=Math.sqrt(u),f=(a+d)/2,c=(a-d)/2,l=Math.sqrt(f),h=Math.sqrt(c),g=h,x=1,y=0,m=0,p=1;if(Math.abs(i)>1e-12||Math.abs(r-s)>1e-12){let w=i,z=f-r,M=Math.sqrt(w*w+z*z);M>1e-12&&(x=w/M,y=z/M);let P=i,E=c-r,S=Math.sqrt(P*P+E*E);S>1e-12&&(m=P/S,p=E/S)}let b=f>1e-10?c/f:0;return{eigenRatio:b,isLinear:b<.05,spread:g,mx:n,mz:o,v1x:x,v1z:y,v2x:m,v2z:p,s1:l,s2:h}}function Qs(t,e,n){if(t.length<6)return{type:"straight",eigenRatio:.5,spread:0,cloudUsed:t.length,mx:0,mz:0,v1x:1,v1z:0,v2x:0,v2z:1,s1:0,s2:0};let{eigenRatio:o,isLinear:r,spread:s,mx:i,mz:a,v1x:u,v1z:d,v2x:f,v2z:c,s1:l,s2:h}=Xa(t),g=0;for(let w=1;w<t.length;w++){let z=t[w].x-t[w-1].x,M=t[w].z-t[w-1].z;g+=Math.sqrt(z*z+M*M)}let x=Za(t),y=dn(x);if(y.r>.1&&y.r<Math.max(g*5,2)&&y.rmsResidual<.07)return{type:"curved",eigenRatio:o,spread:s,cloudUsed:t.length,mx:i,mz:a,v1x:u,v1z:d,v2x:f,v2z:c,s1:l,s2:h};let p=g>.01?s/g:1;return{type:r&&(s<.05||p<.1)?"straight":"curved",eigenRatio:o,spread:s,cloudUsed:t.length,mx:i,mz:a,v1x:u,v1z:d,v2x:f,v2z:c,s1:l,s2:h}}function Za(t){if(t.length<4)return[...t];let e=[{...t[0]}];for(let n=1;n<t.length-1;n++)e.push({x:(t[n-1].x+t[n].x+t[n+1].x)/3,z:(t[n-1].z+t[n].z+t[n+1].z)/3});return e.push({...t[t.length-1]}),e}function Ga(t,e,n=1.57){if(e<10)return[];let o=[];for(let x=0;x<e;x++){let y=(x+1)%e;o.push(Math.atan2(t[y].z-t[x].z,t[y].x-t[x].x))}let r=[o[0]];for(let x=1;x<e;x++){let y=o[x]-o[x-1];y>Math.PI?y-=2*Math.PI:y<-Math.PI&&(y+=2*Math.PI),r.push(r[x-1]+y)}let s=0;{let x=o[0]-o[e-1];x>Math.PI?x-=2*Math.PI:x<-Math.PI&&(x+=2*Math.PI),s=x}Math.abs(s)<.1;let i=[],a=5;for(let x=0;x<e;x++){let y=0;for(let m=-a;m<=a;m++)y+=r[(x+m+e)%e];i.push(y/(a*2+1))}let u=5,d=[];for(let x=0;x<e;x++){let y=i[(x+u)%e]-i[x];y>Math.PI?y-=2*Math.PI:y<-Math.PI&&(y+=2*Math.PI),d.push(y)}let f=10,c=.003,l=10,h=.05,g=[];for(let x=0;x<e;x++){let y=x,m=x,p=0,b=0,w=x,z=e+10;for(;z-- >0;){let P=d[w],E=Math.abs(P),S=P>0?1:P<0?-1:0;if(E<c){w=(w+1)%e;continue}if(b===0){b=S,p=E,m=w,w=(w+1)%e;continue}if(S!==b){let I=E,W=S,v=(w+1)%e,T=1;for(let R=0;R<l&&T<l*2;R++){let D=d[v],H=Math.abs(D);if(H<c){v=(v+1)%e;continue}(D>0?1:-1)===W?I+=H:(I-=H,I<0&&(W=-W,I=-I)),v=(v+1)%e,T++}if(W===b&&I>h){w=(w+1)%e;continue}break}if(p+=E,m=w,w=(w+1)%e,w===x)break}if((m>y?m-y+1:e-y+m+1)>=f&&p>=n){let P=y,E=(y+u)%e,S=(m-u+e)%e,I=m,W=t[P],v=t[E],T=t[S],R=t[I],D=Math.atan2(v.z-W.z,v.x-W.x),V=Math.atan2(R.z-T.z,R.x-T.x)-D;V>Math.PI?V-=2*Math.PI:V<-Math.PI&&(V+=2*Math.PI);let C=Math.abs(V);if(!g.some(A=>{function L(B,O,$){return B<=O?$>=B&&$<=O:$>=B||$<=O}let k=0,F=0;for(let B=y;F++,L(A.start,A.end,B)&&k++,B!==m;B=(B+1)%e);return F>0&&k/F>.7})){let A=g.findIndex(L=>{function k(O,$,Z){return O<=$?Z>=O&&Z<=$:Z>=O||Z<=$}let F=0,B=0;for(let O=L.start;B++,k(y,m,O)&&F++,O!==L.end;O=(O+1)%e);return B>0&&F/B>.7});A>=0?p>g[A].cumAngle&&(g[A]={start:y,end:m,cumAngle:p,actualAngle:C}):g.push({start:y,end:m,cumAngle:p,actualAngle:C})}}}return g}function Ya(t,e){let s=new Array(e).fill(!1);for(let d=0;d<e;d++){let f=t[d],c=t[(d+15)%e],l=t[(d+30)%e],h=Math.atan2(c.z-f.z,c.x-f.x),g=Math.atan2(l.z-c.z,l.x-c.x),x=Math.abs(g-h);x>Math.PI&&(x=2*Math.PI-x),x>.07&&(s[(d+15)%e]=!0)}let i=new Set,a=[],u=-1;for(let d=0;d<e*2;d++){let f=d%e;if(s[f])u<0&&(u=f);else if(u>=0){let c=(f-1+e)%e,l=0;for(let h=u;l++,h!==c;h=(h+1)%e);if(l>=12){let h=`${u},${c}`;i.has(h)||(i.add(h),a.push({start:u,end:c}))}u=-1}}if(a.length>1){let d=a[0],f=a[a.length-1];f.end>e-3&&d.start<3&&(a[0]={start:f.start,end:d.end},a.pop())}return a}function Ua(t,e){let n=[10,15,20,25,30,40],o=.15,r=.15,s=.5,i=3,a=6,u=new Array(e).fill(0);for(let c of n)if(!(c>=e))for(let l=0;l<e;l+=i){let h=l+c;if(h>=e)break;let g=[];for(let w=l;w<=h;w++)g.push(t[w]);if(g.length<c-1)continue;let{cx:x,cz:y,r:m,rmsResidual:p}=dn(g);if(m<.1||p>o||m<s)continue;let b=0;for(let w=1;w<g.length;w++){let z=g[w-1].x-x,M=g[w-1].z-y,P=g[w].x-x,E=g[w].z-y;b+=Math.abs(Math.atan2(z*E-M*P,z*P+M*E))}if(!(b<r))for(let w=l;w<=h;w++)u[w]++}let d=[],f=-1;for(let c=0;c<e*2;c++){let l=c%e;if(u[l]>=2)f<0&&(f=l);else if(f>=0){let h=(l-1+e)%e,g=0;for(let x=f;g++,x!==h;x=(x+1)%e);g>=a&&d.push({start:f,end:h}),f=-1}}if(d.length>1){let c=d[0],l=d[d.length-1];l.end>e-3&&c.start<3&&(d[0]={start:l.start,end:c.end},d.pop())}return d}function Ka(t,e,n){function o(h,g){return h<=g?g-h+1:n-h+(g+1)}function r(h,g,x){return h<=g?x>=h&&x<=g:x>=h||x<=g}let s=o(t.start,t.end),i=o(e.start,e.end),a=s<=i?t.start:e.start,u=s<=i?t.end:e.end,d=s<=i?e.start:t.start,f=s<=i?e.end:t.end,c=0;for(let h=a;r(d,f,h)&&c++,h!==u;h=(h+1)%n);let l=s+i-c;return l>0?c/l:0}function Qa(t){if(t.length<2)return[];let e=[],n=.15,o=1.22,r=1.92;for(let a=0;a<t.length;a++){let u=t[a];for(let d=a+1;d<t.length;d++){let f=t[d],c=u.bx-u.ax,l=u.bz-u.az,h=f.bx-f.ax,g=f.bz-f.az,x=Math.sqrt(c*c+l*l),y=Math.sqrt(h*h+g*g);if(x<.01||y<.01)continue;let m=Math.abs(Math.atan2(c*g-l*h,c*h+l*g));if(m<o||m>r)continue;let p=[{x:u.ax,z:u.az},{x:u.bx,z:u.bz}],b=[{x:f.ax,z:f.az},{x:f.bx,z:f.bz}];for(let w of p)for(let z of b){let M=w.x-z.x,P=w.z-z.z;Math.sqrt(M*M+P*P)<n&&e.push({x:(w.x+z.x)/2,z:(w.z+z.z)/2})}}}if(e.length<2)return e;let s=[],i=new Array(e.length).fill(!1);for(let a=0;a<e.length;a++){if(i[a])continue;let u=e[a].x,d=e[a].z,f=1;i[a]=!0;for(let c=a+1;c<e.length;c++){if(i[c])continue;let l=e[c].x-u/f,h=e[c].z-d/f;Math.sqrt(l*l+h*h)<.3&&(u+=e[c].x,d+=e[c].z,f++,i[c]=!0)}s.push({x:u/f,z:d/f})}return s}function Js(t,e){if(t.length<6)return[];let n={minCurveAngle:.05,minCurvePoints:5,smoothWindow:3,...e},o=t.length,r=[];for(let T=0;T<o;T++){let R=t[(T-1+o)%o],D=t[T],H=t[(T+1)%o],V=D.x-R.x,C=D.z-R.z,_=H.x-D.x,A=H.z-D.z,L=Math.sqrt(V*V+C*C),k=Math.sqrt(_*_+A*A);if(L<.001||k<.001){r.push(0);continue}r.push(Math.atan2((V*A-C*_)/(L*k),(V*_+C*A)/(L*k)))}let s=[],i=n.smoothWindow;for(let T=0;T<o;T++){let R=0;for(let D=-i;D<=i;D++)R+=r[(T+D+o)%o];s.push(R/(i*2+1))}let a=.008,u=[],d=-1,f=0,c=new Set;for(let T=0;T<o*2;T++){let R=T%o,D=s[R],H=D>=0?1:-1;if(Math.abs(D)>a&&(f===0||f===H))d<0&&(d=R,f=H);else if(d>=0){let V=(R-1+o)%o,C=0,_=0;for(let A=d;C+=Math.abs(s[A]),_++,A!==V;A=(A+1)%o);if(_>=n.minCurvePoints&&C>n.minCurveAngle){let A=`${d},${V}`;c.has(A)||(c.add(A),u.push({start:d,end:V,sign:f}))}d=-1,f=0}}if(u.length>1){let T=u[0],R=u[u.length-1];T.sign===R.sign&&R.end>o-3&&T.start<3&&(u[0]={start:R.start,end:T.end,sign:T.sign},u.pop())}{let T=s.filter(V=>Math.abs(V)>.001).map(V=>Math.abs(V)),R=T.length>0?Math.max(...T):0,D=T.length>0?T.reduce((V,C)=>V+C,0)/T.length:0,H=u.reduce((V,C)=>{let _=0;for(let A=C.start;_++,A!==C.end;A=(A+1)%o);return V+_},0)}let l=Ya(t,o),h=Ua(t,o),g=[...u,...l.map(T=>({start:T.start,end:T.end,sign:1})),...h.map(T=>({start:T.start,end:T.end,sign:1}))],x=u.length,m=g.map((T,R)=>{let D=[];for(let Z=T.start;D.push({...t[Z]}),Z!==T.end;Z=(Z+1)%o);let H=0;for(let Z=1;Z<D.length;Z++)s[(T.start+Z-1)%o]*s[(T.start+Z)%o]<-1e-8&&H++;let{cx:V,cz:C,r:_,rmsResidual:A}=dn(D),L=0,k=0;for(let Z=1;Z<D.length;Z++){let Q=D[Z-1].x-V,j=D[Z-1].z-C,X=D[Z].x-V,U=D[Z].z-C,at=Math.atan2(Q*U-j*X,Q*X+j*U);L+=Math.abs(at),k+=at}let F=Re(D),B=H===0?.12:.08;if(_>.1&&A>B||_>.1&&_>Math.max(F*15,8)||Math.abs(k)<.05)return null;let O=R<x?"turning":"sliding",$=O!=="turning"?Math.abs(k)>.35?"C_curve":"S_curve":H>0?"S_curve":"C_curve";return{seg:{points:D,type:$,radius:_,centerX:V,centerZ:C,arcAngle:L,arcLength:F},start:T.start,end:T.end,source:O}}).filter(T=>T!==null),p=new Set;function b(T,R){return T<=R?R-T+1:o-T+(R+1)}function w(T,R,D,H){for(let V=T;;V=(V+1)%o){let C;if(D<=H?C=V>=D&&V<=H:C=V>=D||V<=H,!C)return!1;if(V===R)break}return!0}for(let T=0;T<m.length;T++)if(!p.has(T))for(let R=T+1;R<m.length;R++){if(p.has(R))continue;if(Ka({start:m[T].start,end:m[T].end},{start:m[R].start,end:m[R].end},o)>.6){let V=(m[T].seg.arcAngle>=m[R].seg.arcAngle?T:R)===T?R:T;if(m[T].seg.arcAngle>=m[R].seg.arcAngle)p.add(R);else{p.add(T);break}}else{let H=b(m[T].start,m[T].end),V=b(m[R].start,m[R].end),C=H<=V?T:R,_=H<=V?R:T;w(m[C].start,m[C].end,m[_].start,m[_].end)&&b(m[C].start,m[C].end)/b(m[_].start,m[_].end)<.7&&p.add(C)}}let z=m.filter((T,R)=>!p.has(R)),M=10,P=10,E=30,S=15,I=[],W=0;if(z.length>0){for(let D of z)D.start=(D.start-S+o)%o,D.end=(D.end+S)%o;let T=[...z].sort((D,H)=>D.start-H.start),R=T[0];for(let D=1;D<T.length;D++){let H=T[D],V=H.start-R.end;V<0&&(R.end>o*.5&&H.start<o*.5?V=H.start+o-R.end:V=0);let C=V===0,_=V<=E&&C;if(!_&&V<=E){let A=Math.sqrt((R.seg.centerX-H.seg.centerX)**2+(R.seg.centerZ-H.seg.centerZ)**2),L=Math.max(R.seg.radius,H.seg.radius),k=Math.min(R.seg.radius,H.seg.radius),F=k>0?L/k:99;_=A<P&&F<M}if(_){let A=Math.min(R.start,H.start),L=Math.max(R.end,H.end),k=[];for(let Z=A;k.push({...t[Z]}),Z!==L;Z=(Z+1)%o);let{cx:F,cz:B,r:O}=dn(k),$=0;for(let Z=1;Z<k.length;Z++){let Q=k[Z-1].x-F,j=k[Z-1].z-B,X=k[Z].x-F,U=k[Z].z-B;$+=Math.abs(Math.atan2(Q*U-j*X,Q*X+j*U))}R={seg:{points:k,type:"C_curve",radius:O,centerX:F,centerZ:B,arcAngle:$,arcLength:Re(k)},start:R.start,end:H.end,source:R.source},W++}else I.push(R),R=H}I.push(R)}{if(I.length>1){let R=I.map((D,H)=>{if(H===0)return 0;let V=D.start-I[H-1].end;return V<0&&(V=D.start+o-I[H-1].end),V})}let T=[];for(let R=0;R<I.length;R++){if(T.length===0){T.push(I[R]);continue}let D=T[T.length-1],H=I[R].start-D.end;if(H<0&&(H=I[R].start+o-D.end),H<=30){let V=[...D.seg.points];for(let k=(D.end+1)%o;V.push({...t[k]}),k!==I[R].end;k=(k+1)%o);let{cx:C,cz:_,r:A}=dn(V),L=0;for(let k=1;k<V.length;k++){let F=V[k-1].x-C,B=V[k-1].z-_,O=V[k].x-C,$=V[k].z-_;L+=Math.abs(Math.atan2(F*$-B*O,F*O+B*$))}T[T.length-1]={seg:{points:V,type:"C_curve",radius:A,centerX:C,centerZ:_,arcAngle:L,arcLength:Re(V)},start:D.start,end:I[R].end,source:D.source}}else T.push(I[R])}I=T}return I.map((T,R)=>{let D=T.seg;return D.candidateId=R,D})}function Ja(t){let e=t.length;if(e<6)return null;let n=Ga(t,e,.35);if(n.length===0)return null;let o=n.filter(l=>l.actualAngle!=null&&l.actualAngle>.17);if(o.length===0)return null;o.sort((l,h)=>{let g=l.end>=l.start?l.end-l.start+1:e-l.start+l.end+1;return(h.end>=h.start?h.end-h.start+1:e-h.start+h.end+1)-g});let r=o[0],s=[];for(let l=r.start;s.push({...t[l]}),l!==r.end;l=(l+1)%e);if(s.length<10)return null;let{cx:i,cz:a,r:u,rmsResidual:d}=dn(s);if(u>.1&&d>.1)return null;let f=r.actualAngle,c=s.reduce((l,h,g)=>g===0?0:l+Math.hypot(h.x-s[g-1].x,h.z-s[g-1].z),0);return u>.3&&f>.17?{points:s,type:"C_curve",radius:u,centerX:i,centerZ:a,arcAngle:f,arcLength:c}:null}function ho(t,e,n){let o={...nr,...n},r=Date.now(),s=t,i=Array.isArray(e)?e:[],a=[];if(i.length>10)try{for(let T of i){let R=T.x1,D=T.z1,H=T.x2,V=T.z2;if(R==null||D==null||H==null||V==null){let C=T.start?.x,_=T.start?.y,A=T.end?.x,L=T.end?.y;if(C==null||_==null||A==null||L==null)continue;a.push({ax:C,az:_,bx:A,bz:L})}else a.push({ax:R,az:D,bx:H,bz:V})}let v=.1*.1;if(a.length>5){let T=[],R=[],D=new Array(a.length).fill(0);for(let V of t){let C=1/0,_=-1;for(let A=0;A<a.length;A++){let L=a[A],k=L.bx-L.ax,F=L.bz-L.az,B=k*k+F*F,O;if(B<1e-8)O=(V.x-L.ax)**2+(V.y-L.az)**2;else{let $=((V.x-L.ax)*k+(V.y-L.az)*F)/B;$=Math.max(0,Math.min(1,$));let Z=L.ax+$*k,Q=L.az+$*F;O=(V.x-Z)**2+(V.y-Q)**2}if(O<C&&(C=O,_=A),C<=v)break}C<=v&&(R.push(V),T.push(_),D[_]++)}let H=R;if(o.lineDensityMin>0&&o.lineDensityMinLen>0){let V=new Set;for(let C=0;C<a.length;C++){let _=a[C],A=Math.hypot(_.bx-_.ax,_.bz-_.az);if(A>=o.lineDensityMinLen)continue;(A>.01?D[C]/A:0)<o.lineDensityMin&&V.add(C)}if(V.size>0){let C=[];for(let _=0;_<R.length;_++)V.has(T[_])||C.push(R[_]);H=C}}s=H}}catch(v){console.warn("[\u70B9\u4E91\u8F6E\u5ED3] \u7EBF\u6BB5\u8FC7\u6EE4\u5931\u8D25:",v)}let u=Qa(a),d=[];for(let v of s){let T=v.z;T<o.heightMin||T>o.heightMax||d.push({x:v.x,z:v.y})}if(d.length<50)return Ke(e,r);if(o.sparseRadius>0){let v=new Map,T=o.cellSize;for(let V of d){let C=`${Math.round(V.x/T)},${Math.round(V.z/T)}`;v.has(C)||v.set(C,[]),v.get(C).push(V)}let R=[],D=Math.ceil(o.sparseRadius/T);for(let V=-D;V<=D;V++)for(let C=-D;C<=D;C++)R.push(`${V},${C}`);let H=[];for(let V of d){let C=Math.round(V.x/T),_=Math.round(V.z/T),A=0;for(let L of R){let[k,F]=L.split(",").map(Number),B=v.get(`${C+k},${_+F}`);if(B&&(A+=B.length),A>=o.sparseMinNeighbors)break}A>=o.sparseMinNeighbors&&H.push(V)}d.length=0;for(let V=0;V<H.length;V++)d.push(H[V])}if(d.length<50)return Ke(e,r);let f=Date.now(),{cells:c}=fo(d,o.cellSize),l=new Set;if(o.densityRatio>0&&c.size>10){let v=Array.from(c.values()).sort((D,H)=>D-H),T=v[Math.floor(v.length/2)],R=Math.max(o.densityThreshold,Math.ceil(T*o.densityRatio));for(let[D,H]of c)H>=R&&l.add(D);if(l.size<o.minComponentCells){l.clear();for(let[D,H]of c)H>=o.densityThreshold&&l.add(D)}}else for(let[v,T]of c)T>=o.densityThreshold&&l.add(v);if(l.size<o.minComponentCells)return Ke(e,r);let h=l;o.closeIterations>0&&(h=Wn(l,o.closeIterations));let g=Date.now(),x=tr(h).filter(v=>v.size>=o.minComponentCells);x.sort((v,T)=>T.size-v.size);let y=20;x.length>y&&(x=x.slice(0,y));let m=Date.now(),p=[];for(let v of x){let T=er(v,o.cellSize);T.length>=4&&p.push(T)}let b=Date.now(),w=p.map(v=>{let T=Hn(v,o.simplifyEpsilon);if(T.length>=7)for(let R=0;R<2;R++){let D=T.length,H=T.map(V=>({x:V.x,z:V.z}));for(let V=0;V<D;V++){let C=T[(V-1+D)%D],_=T[V],A=T[(V+1)%D],L=_.x-C.x,k=_.z-C.z,F=A.x-_.x,B=A.z-_.z,O=Math.sqrt(L*L+k*k),$=Math.sqrt(F*F+B*B);if(O<.001||$<.001)continue;if(Math.abs(Math.atan2(L*B-k*F,L*F+k*B))>1.8){let Q=[-2,-1,0,1,2].map(U=>T[(V+U+D)%D]),j=Q.map(U=>U.x).sort((U,at)=>U-at),X=Q.map(U=>U.z).sort((U,at)=>U-at);H[V]={x:j[2],z:X[2]}}}T=H}if(T=Jo(T),u.length>0&&T.length>=5)for(let R of u){let D=1/0,H=-1;for(let V=0;V<T.length;V++){let C=T[V].x-R.x,_=T[V].z-R.z,A=C*C+_*_;A<D&&(D=A,H=V)}H>=0&&D<.3*.3&&(T[H]={x:R.x,z:R.z})}if(T.length>2){let R=T[0],D=T[T.length-1];(Math.abs(R.x-D.x)>.001||Math.abs(R.z-D.z)>.001)&&T.push({...R})}return T}),z=o.cellSize/2;function M(v){let T=0;for(let R=0;R<v.length;R++){let D=(R+1)%v.length;T+=v[R].x*v[D].z-v[D].x*v[R].z}return T/2}let P=w.map(v=>{if(v.length<3)return v;let T=M(v)>=0;return v.map((R,D)=>{let H=v[(D-1+v.length)%v.length],V=v[(D+1)%v.length],C=V.x-H.x,_=V.z-H.z;if(Math.sqrt(C*C+_*_)<.001)return{...R};let L=T?_:-_,k=T?-C:C,F=Math.sqrt(L*L+k*k);return F<.001?{...R}:{x:R.x+L/F*z,z:R.z+k/F*z}})}),E=Date.now(),S=[];for(let v=0;v<P.length;v++){let T=P[v];T.length<3||S.push({id:-v-1,points:T,length:Re(T),pointCount:T.length,type:"straight",isMain:!1})}let I=Date.now()-r,W=[];for(let v of w){let T=Js(v);for(let D of T)W.push(D);let R=Ja(v);R&&W.push(R)}return{mainWalls:[],noiseWalls:[],contours:S,curvedSegments:W,filteredPoints:s,stats:{totalRawLines:e?.length??t.length,totalWalls:0,mainCount:0,noiseCount:S.length,elapsedMs:I}}}function ti(t,e){let n=e?.cellSize??.05,o=e?.closeIterations??2,r=e?.minComponentCells??10,s=e?.simplifyEpsilon??.02,i=Date.now();if(t.length<3)return Ke(t,i);let a=t.map(S=>({x1:S.x1,z1:S.z1,x2:S.x2,z2:S.z2})),{active:u}=Ks(a,n);if(u.size<r)return Ke(t,i);let d=Date.now(),f=Wn(u,o),c=Date.now(),l=tr(f).filter(S=>S.size>=r);if(l.length===0)return Ke(t,i);let h=l.reduce((S,I)=>S.size>=I.size?S:I),g=Date.now(),x=er(h,n);if(x.length<4)return Ke(t,i);let y=Date.now(),m=Hn(x,s);if(m=Jo(m),m.length>2){let S=m[0],I=m[m.length-1];(Math.abs(S.x-I.x)>.001||Math.abs(S.z-I.z)>.001)&&m.push({...S})}let p=n/2;function b(S){let I=0;for(let W=0;W<S.length;W++){let v=(W+1)%S.length;I+=S[W].x*S[v].z-S[v].x*S[W].z}return I/2}let w=b(m)>=0,z=m.map((S,I)=>{let W=m[(I-1+m.length)%m.length],v=m[(I+1)%m.length],T=v.x-W.x,R=v.z-W.z;if(Math.sqrt(T*T+R*R)<.001)return{...S};let H=w?R:-R,V=w?-T:T,C=Math.sqrt(H*H+V*V);return C<.001?{...S}:{x:S.x+H/C*p,z:S.z+V/C*p}}),M=Date.now(),P=[];z.length>=3&&P.push({id:-1,points:z,length:Re(z),pointCount:z.length,type:"straight",isMain:!0});let E=Date.now()-i;return{mainWalls:[],noiseWalls:[],contours:P,stats:{totalRawLines:t.length,totalWalls:0,mainCount:0,noiseCount:P.length,elapsedMs:E}}}function Ke(t,e){return{mainWalls:[],noiseWalls:[],stats:{totalRawLines:t?.length??0,totalWalls:0,mainCount:0,noiseCount:0,elapsedMs:Date.now()-e}}}function mo(t,e,n){if(!t.length||n<=1)return t;let o=new Map;for(let a of t){let u=Math.floor(a.x/e),d=Math.floor(a.y/e),f=`${u},${d}`;o.has(f)||o.set(f,[]),o.get(f).push(a)}let r=new Map;for(let[a,u]of o){let[d,f]=a.split(","),c=parseInt(d),l=parseInt(f),h=0;for(let g=-2;g<=2;g++)for(let x=-2;x<=2;x++){let y=`${c+g},${l+x}`;h+=o.get(y)?.length??0}r.set(a,h)}let s=[],i=0;for(let a of t){let u=Math.floor(a.x/e),d=Math.floor(a.y/e),f=`${u},${d}`;(r.get(f)??0)>=n?s.push(a):i++}return s}function po(t,e,n){if(!t.length||n<=1||e<=0)return t;let o=new Map;for(let s of t){let i=Math.floor(s.x/e),a=Math.floor(s.y/e),u=Math.floor(s.z/e),d=`${i},${a},${u}`;o.has(d)||o.set(d,[]),o.get(d).push(s)}let r=[];for(let s of o.values())if(s.length>=n){let i=s.reduce((d,f)=>d+f.x,0)/s.length,a=s.reduce((d,f)=>d+f.y,0)/s.length,u=s.reduce((d,f)=>d+f.z,0)/s.length;r.push({x:i,y:a,z:u})}return r}function ei(t,e,n){let o=po(t,e,n),r=t.length-o.length;return o}function ni(t){let e=[];for(let d of t){let f=d.originalPoints??d.points??[];if(!Array.isArray(f)||f.length<2)continue;let c=Math.min(f.length,200);for(let l=1;l<c;l++){let h=Math.hypot(f[l].x-f[l-1].x,f[l].y-f[l-1].y,f[l].z-f[l-1].z);h>.001&&e.push(h)}}let n={voxelSize:.08,minPoints:3,minCentroids:3};if(e.length<10)return n;e.sort((d,f)=>d-f);let o=e[Math.floor(e.length/2)],r=Math.max(.03,Math.min(.25,o*3.5));r=Math.round(r*100)/100;let s=Math.pow(r/o,2),i=Math.max(2,Math.min(5,Math.round(s/4))),a=e.length/Math.max(1,t.length),u=Math.max(2,Math.min(4,Math.round(a/50)));return{voxelSize:r,minPoints:i,minCentroids:u}}function oi(t,e,n,o,r=3){if(!t.length||n<=0||o<=1)return{data:t,lines:e,removedCount:0};let s=[],i=[],a=0;for(let u=0;u<t.length;u++){let d=t[u],f=d.originalPoints??d.points??[];if(!Array.isArray(f)||f.length===0){s.push(d),i.push(e[u]);continue}let c=po(f,n,o);c.length>=r?(d.originalPoints&&(d.originalPoints=c),d.points&&(d.points=c),s.push(d),i.push(e[u])):a++}return{data:s,lines:i,removedCount:a}}function ri(t,e,n,o){let r=[],s=[],i=0;for(let a=0;a<t.length;a++){let u=t[a],d=u.originalPoints??u.points??[],c=(Array.isArray(d)?d.filter(y=>y&&y.x!==void 0&&y.y!==void 0):[]).length;if(c===0){r.push(u),s.push({...e[a],id:r.length-1});continue}let l=u.start??u,h=u.end??u,g=Math.hypot(h.x??0-l.x??0,h.y??0-l.y??0);if(g>=o||g<=.01){r.push(u),s.push({...e[a],id:r.length-1});continue}if(c/g<n){i++;continue}r.push(u),s.push({...e[a],id:r.length-1})}return{data:r,lines:s}}function Qe(t,e,n,o,r,s){let i=r-n,a=s-o,u=i*i+a*a;if(u===0)return Math.hypot(t-n,e-o);let d=((t-n)*i+(e-o)*a)/u;return d=Math.max(0,Math.min(1,d)),Math.hypot(t-(n+d*i),e-(o+d*a))}function or(t,e,n=.2){for(let o of e)if(Qe(o.x,o.z,t.x1,t.z1,t.x2,t.z2)<=n)return!0;return!1}function si(t,e,n=.2){let o=1/0,r={x:0,z:0};for(let i of e){let a=Qe(i.x,i.z,t.x1,t.z1,t.x2,t.z2);a<o&&(o=a,r=i)}return o<=n}function ii(t,e,n,o=!0){function g(b,w,z,M){let P=z.points[0],E=z.points[z.points.length-1];return Math.hypot(b-P.x,w-P.z)<=M||Math.hypot(b-E.x,w-E.z)<=M}function x(b,w,z,M){for(let P=0;P<z.points.length-1;P++)if(Qe(b,w,z.points[P].x,z.points[P].z,z.points[P+1].x,z.points[P+1].z)<=M)return!0;return!1}function y(b,w,z){let M=0,P=b[0],E=b[b.length-1];for(let S of w)if(g(P.x,P.z,S,z)||x(P.x,P.z,S,z)){M++;break}for(let S of w)if(g(E.x,E.z,S,z)||x(E.x,E.z,S,z)){M++;break}return M}function m(b){if(b.length<2)return 0;if(b.length<=30){let P=0;for(let E=0;E<b.length;E++)for(let S=E+1;S<b.length;S++){let I=Math.hypot(b[E].x-b[S].x,b[E].z-b[S].z);I>P&&(P=I)}return P}let w=Math.max(1,Math.floor(b.length/15)),z=[];for(let P=0;P<b.length;P+=w)z.push(b[P]);z[z.length-1]!==b[b.length-1]&&z.push(b[b.length-1]);let M=0;for(let P=0;P<z.length;P++)for(let E=P+1;E<z.length;E++){let S=Math.hypot(z[P].x-z[E].x,z[P].z-z[E].z);S>M&&(M=S)}return M}let p=[];for(let b of t){let w=b.points,z=w.length>=2?m(w):0,M=b.candidateId!==void 0?`#${b.candidateId}`:"#?";if(o&&console.log(`[\u5F27\u6BB5\u5206\u6790] ${M} r=${b.radius.toFixed(3)}m \u5F27\u89D2=${(b.arcAngle*180/Math.PI).toFixed(1)}\xB0 \u5F26\u957F=${z.toFixed(3)}m pts=${w.length}`),b.radius<.2){o&&console.log(` \u2192 \u534A\u5F84<${.2}m \u8FC7\u6EE4`);continue}if(w.length<3){o&&console.log(" \u2192 \u70B9\u6570<3 \u8FC7\u6EE4");continue}let P=z/b.radius,E=z/2,S=0;E<=b.radius?S=b.radius-Math.sqrt(b.radius*b.radius-E*E):S=z;let I=z>.01?S/z:0,W=y(w,e,.8),v=b.arcAngle>1.745&&b.radius<5,T=b.radius>15&&P>.15&&w.length>=10,R=P>.12&&b.radius>1&&b.radius<4&&b.arcAngle>=.35&&w.length>=3;if(o&&console.log(` \u7279\u5F81: \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} \u5F13\u9AD8/\u5F26\u957F=${I.toFixed(4)} \u8FDE\u63A5=${W}/2${v?" \u5927\u5F27\u89D2\u8C41\u514D":""}${T?" \u5927\u534A\u5F84\u7ED3\u6784\u5F27":""}${R?" \u5408\u7406\u77ED\u5F27\u8C41\u514D":""}`),w.length>20&&b.arcAngle>5.2&&b.radius>.2){o&&console.log(` \u2192 \u8FD1\u95ED\u5408\u5706\u8C41\u514D(\u5F27\u89D2=${(b.arcAngle*180/Math.PI).toFixed(1)}\xB0, ${w.length}pts)`),p.push(b);continue}if(P<.15)if(W>=2&&b.arcAngle>=.35)o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} < ${.15}\uFF0C\u4F46\u4E24\u7AEF\u8FDE\u63A5+\u5F27\u89D2>20\xB0\uFF0C\u8C41\u514D`);else{o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} < ${.15}\uFF0C\u8F6E\u5ED3\u6296\u52A8\u5047\u5F27 \u8FC7\u6EE4`);continue}let D=W>=2?.025:.035;if(I<D&&!v&&!R&&!T){o&&console.log(` \u2192 \u5F13\u9AD8/\u5F26\u957F=${I.toFixed(4)} < ${D}(${W>=2?"\u5BBD\u677E":"\u6807\u51C6"})\uFF0C\u6781\u6241\u5F27(\u76F4\u7EBF\u6BB5\u566A\u58F0) \u8FC7\u6EE4`);continue}if(!v&&!R&&!T){if(b.arcAngle<.17){o&&console.log(` \u2192 \u5F27\u89D2<${(.17*180/Math.PI).toFixed(0)}\xB0 \u8FC7\u6EE4`);continue}if(b.arcAngle<.35&&W<2){o&&console.log(` \u2192 \u5F27\u89D2<${(.35*180/Math.PI).toFixed(0)}\xB0 \u4E14\u672A\u4E24\u7AEF\u8FDE\u63A5 \u8FC7\u6EE4`);continue}}if(P>2.01){o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} > 2.01\uFF0C\u5F26\u957F\u8D85\u8FC7\u76F4\u5F84\uFF0C\u5F02\u5E38 \u8FC7\u6EE4`);continue}if(!v&&!T){let H=W>=2?2.5:1.5,V=Math.floor(w.length/2),C=w[V].x-w[0].x,_=w[V].z-w[0].z,A=w[w.length-1].x-w[V].x,L=w[w.length-1].z-w[V].z,k=Math.atan2(_,C),F=Math.atan2(L,A),B=Math.abs(F-k);if(B>Math.PI&&(B=2*Math.PI-B),B>60*Math.PI/180&&B>b.arcAngle*H){o&&console.log(` \u2192 V\u5F62\u62D0\u89D2\u8FC7\u6EE4 \u8F6C\u89D2=${(B*180/Math.PI).toFixed(1)}\xB0 > \u5F27\u89D2\xD7${H.toFixed(1)}=${(b.arcAngle*180/Math.PI*H).toFixed(1)}\xB0`);continue}}if(n&&n.length>5&&!(b.radius>15&&b.arcAngle>.26)){let H=w[0],V=w[w.length-1],C=.3,_=null,A=1/0,L=null,k=1/0;for(let F of n){let B=Qe(H.x,H.z,F.x1,F.z1,F.x2,F.z2),O=Qe(V.x,V.z,F.x1,F.z1,F.x2,F.z2);B<C&&B<A&&(_=F,A=B),O<C&&O<k&&(L=F,k=O)}if(!_||!L)console.log(` [\u7EBF\u6BB5\u8F6C\u89D2\u8C03\u8BD5 #${M}] \u672A\u627E\u5230\u5B8C\u6574\u7EBF\u6BB5: \u8D77\u7AEF=${!!_}(d=${A.toFixed(3)}) \u672B\u7AEF=${!!L}(d=${k.toFixed(3)})`);else if(_===L){console.log(" \u2192 \u7EBF\u6BB5\u8F6C\u89D2\u9A8C\u8BC1: \u5F27\u4E24\u7AEF\u5728\u540C\u4E00\u6761\u7EBF\u6BB5\u4E0A, \u76F4\u7EBF\u566A\u58F0\u5047\u5F27 \u8FC7\u6EE4");continue}else{let F=_.x2-_.x1,B=_.z2-_.z1,O=L.x2-L.x1,$=L.z2-L.z1,Z=Math.sqrt(F*F+B*B),Q=Math.sqrt(O*O+$*$);if(Z>.01&&Q>.01){let j=Math.abs(Math.atan2(F*$-B*O,F*O+B*$)),X=j*180/Math.PI;if(console.log(` [\u7EBF\u6BB5\u8F6C\u89D2\u8C03\u8BD5 #${M}] \u5F27\u4E24\u7AEF\u6BB5\u5939\u89D2=${X.toFixed(1)}\xB0 \u5F27\u89D2=${(b.arcAngle*180/Math.PI).toFixed(1)}\xB0`),j>.35&&j<3.05){let U=j>2.09;if(!U||b.arcAngle<.44){console.log(` \u2192 \u7EBF\u6BB5\u8F6C\u89D2\u9A8C\u8BC1: \u5F27\u4E24\u7AEF\u6BB5\u5939\u89D2=${X.toFixed(1)}\xB0\uFF0C${U?"\u659C\u5899":"\u6298\u5899"}\u78E8\u5706\u5047\u5F27 \u8FC7\u6EE4`);continue}}}}}o&&console.log(" \u2192 \u2713 \u4FDD\u7559"),p.push(b)}return o&&console.log(`[\u56DE\u52A0\u5224\u65AD] ${t.length} \u2192 ${p.length} \u4E2A\u5F27\u6BB5`),p}function li(t,e){for(let n=0;n<t.length;n++){let o=t[n],r=[];for(let i of e)or(i,o.points)&&r.push({id:i.id,len:Math.hypot(i.x2-i.x1,i.z2-i.z1)});r.sort((i,a)=>a.len-i.len);let s=r.map(i=>`#${i.id}(${i.len.toFixed(2)}m)`).join(", ");console.log(`[\u5F27\u6BB5\u539F\u59CB\u7EBF\u6BB5] #${n} r=${o.radius.toFixed(3)}m \u2192 ${r.length} \u6761: ${s}`)}}var sr={gridSize:2,connectDist:.8,angleTol:25,minLength:.8,minPointCount:3,hardCornerThreshold:30,minArea:5,minCurvePoints:6,curveStraightDist:.25,longWallMinLength:5};function ai(t){if(!t.length)return{rotated:[],mainAngle:0};let e=180,n=new Array(e).fill(0),o=Math.PI/e;for(let f of t){let c=f.x2-f.x1,l=f.z2-f.z1,h=Math.sqrt(c*c+l*l);if(h<.01)continue;let g=Se(c,l),x=Math.floor(g/o);x>=e&&(x=e-1),n[x]+=h}let r=new Array(e).fill(0),s=5;for(let f=0;f<e;f++){let c=0;for(let l=-s;l<=s;l++){let h=f+l;h<0&&(h+=e),h>=e&&(h-=e),c+=n[h]}r[f]=c}let i=0,a=0;for(let f=0;f<e;f++)r[f]>i&&(i=r[f],a=f);let u=(a+.5)*o;return{rotated:t.map(f=>{let c=In(f.x1,f.z1,-u),l=In(f.x2,f.z2,-u);return{...f,x1:c.x,z1:c.z,x2:l.x,z2:l.z}}),mainAngle:u}}function ci(t,e){let n=new Map;for(let o of t){let r=(o.x1+o.x2)/2,s=(o.z1+o.z2)/2,i=Math.floor(r/e),a=Math.floor(s/e),u=`${i},${a}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}function ui(t,e,n){if(t.length===0)return[];let o=new Set,r=[];for(let s of t){if(o.has(s.id))continue;let i=[s],a=[],u=new Set([s.id]);o.add(s.id);let d=!0;for(;d;){d=!1;let l=i[i.length-1],h=l.x2,g=l.z2,x=Se(l.x2-l.x1,l.z2-l.z1),y=null,m=e;for(let p of t){if(o.has(p.id))continue;let b=Me(h,g,p.x1,p.z1),w=Me(h,g,p.x2,p.z2),z=w<b,M=Math.min(b,w);if(M>m)continue;let P=z?Se(p.x1-p.x2,p.z1-p.z2):Se(p.x2-p.x1,p.z2-p.z1);Math.abs(Vn(P-x))>n||(y=p,m=M)}if(y){o.add(y.id),u.add(y.id);let p=i[i.length-1],b=Me(p.x2,p.z2,y.x1,y.z1),w=Me(p.x2,p.z2,y.x2,y.z2);b<=w?i.push(y):i.push({id:y.id,x1:y.x2,z1:y.z2,x2:y.x1,z2:y.z1}),d=!0}}for(d=!0;d;){d=!1;let l=a.length>0?a[a.length-1]:i[0],h=a.length>0?l.x2:l.x1,g=a.length>0?l.z2:l.z1,x=a.length>0?Se(l.x2-l.x1,l.z2-l.z1):Se(l.x2-l.x1,l.z2-l.z1),y=null,m=e;for(let p of t){if(o.has(p.id))continue;let b=Me(h,g,p.x1,p.z1),w=Me(h,g,p.x2,p.z2),z=w<b,M=Math.min(b,w);if(M>m)continue;let P=z?Se(p.x1-p.x2,p.z1-p.z2):Se(p.x2-p.x1,p.z2-p.z1);Math.abs(Vn(P-x))>n||(y=p,m=M)}if(y){o.add(y.id),u.add(y.id);let p=Me(h,g,y.x1,y.z1),b=Me(h,g,y.x2,y.z2);p<=b?a.push({id:y.id,x1:y.x2,z1:y.z2,x2:y.x1,z2:y.z1}):a.push({...y}),d=!0}}let f=[];for(let l=a.length-1;l>=0;l--){let h=a[l];l===a.length-1&&f.push({x:h.x1,z:h.z1}),f.push({x:h.x2,z:h.z2})}for(let l=0;l<i.length;l++){let h=i[l];l===0&&f.length===0&&f.push({x:h.x1,z:h.z1}),f.push({x:h.x2,z:h.z2})}let c=[];for(let l of f){if(c.length>0){let h=c[c.length-1];if(Math.abs(l.x-h.x)<.001&&Math.abs(l.z-h.z)<.001)continue}c.push(l)}if(c.length>=2){let l=Re(c);r.push({points:c,length:l,pointCount:i.length+a.length,lineIds:[...u]})}}return r}function fi(t){if(t.length<3)return[];let e=[];for(let n=1;n<t.length-1;n++){let o=t[n].x-t[n-1].x,r=t[n].z-t[n-1].z,s=t[n+1].x-t[n].x,i=t[n+1].z-t[n].z,a=Math.atan2(r,o),u=Math.atan2(i,s),d=Vn(u-a);e.push(d)}return e}function di(t,e=6){if(t.length<3)return"straight";let n=t[0],o=t[t.length-1],r=o.x-n.x,s=o.z-n.z;if(Math.sqrt(r*r+s*s)>.1){let f=0;for(let c of t){let l=Cn(c.x,c.z,n.x,n.z,o.x,o.z);l>f&&(f=l)}if(f<.05)return"straight"}let a=fi(t);if(a.reduce((f,c)=>f+Math.abs(c),0)<.1||t.length<e)return"straight";let d=0;for(let f=0;f<a.length-1;f++)a[f]*a[f+1]<0&&d++;return d>0?"S_curve":"C_curve"}function hi(t,e){if(t.length<3)return[t];let n=uo(e),o=fi(t),r=[],s=0;for(let i=0;i<o.length;i++)Math.abs(o[i])>n&&(r.push(t.slice(s,i+2)),s=i+1);return s<t.length-1&&r.push(t.slice(s)),r}function mi(t,e,n=6){let o=[],r=0;for(let s of t){let i=hi(s.points,e);for(let a of i){if(a.length<2)continue;let u=di(a,n),d=Re(a),f=d/(s.length||1),c=Math.max(1,Math.round(s.pointCount*f));o.push({id:r++,points:a,length:d,pointCount:c,lineIds:s.lineIds,type:u,isMain:!1})}}return o}function pi(t,e){if(t.length<3)return new Set;let n=.15;function o(d,f){return Math.round(d/n)+"_"+Math.round(f/n)}let r=new Map,s=0;function i(d,f){let c=o(d,f),l=r.get(c);if(l)return l;let h=Math.round(d/n),g=Math.round(f/n),x=null,y=n*n;for(let m=-1;m<=1;m++)for(let p=-1;p<=1;p++){let b=h+m+"_"+(g+p),w=r.get(b);if(!w)continue;let z=w.x-d,M=w.z-f,P=z*z+M*M;P<y&&(y=P,x=w)}return x?(r.set(c,x),x):(l={id:s++,x:d,z:f,edges:[]},r.set(c,l),l)}for(let d of t){if(d.points.length<2)continue;let f=d.points[0],c=d.points[d.points.length-1],l=i(f.x,f.z),h=i(c.x,c.z);if(l.id===h.id)continue;let g={to:h,wallId:d.id,visited:!1,twin:null},x={to:l,wallId:d.id,visited:!1,twin:g};g.twin=x,l.edges.push(g),h.edges.push(x)}for(let d of r.values())d.edges.sort((f,c)=>{let l=Math.atan2(f.to.z-d.z,f.to.x-d.x),h=Math.atan2(c.to.z-d.z,c.to.x-d.x);return l-h});let a=new Set,u=new Set;for(let d of r.values())for(let f of d.edges)u.add(f);for(let d of u){if(d.visited)continue;let f=[],c=d,l=u.size+10;for(;!c.visited&&f.length<l;){c.visited=!0,f.push(c);let h=c.to,g=c.twin,x=h.edges.indexOf(g);if(x<0)break;let y=(x+1)%h.edges.length;c=h.edges[y]}if(f.length>=3){let h=f[0];if(f[f.length-1].to.id===h.from?.id){let x=[],y=new Set,m=null;for(let p of r.values())if(p.edges.includes(f[0])){m=p;break}if(!m)continue;x.push({x:m.x,z:m.z});for(let p of f)y.add(p.wallId),x.push({x:p.to.x,z:p.to.z});if(f[f.length-1].to.id===m.id&&Qo(x)>=e)for(let b of y)a.add(b)}}}return a}function hn(t,e){let n={...sr,...e},o=Date.now(),{rotated:r,mainAngle:s}=ai(t),i=Date.now(),a=ci(r,n.gridSize),u=Date.now(),d=uo(n.angleTol),f=[];for(let v of a.values()){let T=v.map(D=>({id:D.id,x1:D.x1,z1:D.z1,x2:D.x2,z2:D.z2})),R=ui(T,n.connectDist,d);f.push(...R)}let c=Date.now(),l=new Set,h=f.filter(v=>{let T=v.length>=n.minLength||v.pointCount>=n.minPointCount;return T&&l.add(v),T}),g=f.filter(v=>!l.has(v)),x=Date.now(),y=mi(h,n.hardCornerThreshold,n.minCurvePoints),m=Date.now(),p=pi(y,n.minArea);y.forEach(v=>{v.isMain=p.has(v.id),v.length>=n.longWallMinLength&&(v.isMain=!0)});let b=Date.now();function w(v,T,R=.1){let D=v[0],H=v[v.length-1],V=T[0],C=T[T.length-1];return Math.hypot(D.x-V.x,D.z-V.z)<R||Math.hypot(D.x-C.x,D.z-C.z)<R||Math.hypot(H.x-V.x,H.z-V.z)<R||Math.hypot(H.x-C.x,H.z-C.z)<R}let z=[],M=[];for(let v of y){if(v.type==="straight"&&v.points.length>=2){let T=!1;for(let R of y){if(R.id===v.id||R.type==="straight"||w(v.points,R.points))continue;if(Us(v.points,R.points)<n.curveStraightDist){T=!0;break}}if(T){z.push({...v,id:-z.length-1});continue}}M.push(v)}let P=Date.now(),E=M,S=[];for(let v=0;v<g.length;v++){let T=g[v];S.push({id:-v-1,points:T.points,length:T.length,pointCount:T.pointCount,lineIds:T.lineIds,type:"straight",isMain:!1})}for(let v of z)S.push(v);let I=v=>v.map(T=>({...T,points:T.points.map(R=>In(R.x,R.z,s))})),W=Date.now()-o;return{mainWalls:I(E),noiseWalls:I(S),stats:{totalRawLines:t.length,totalWalls:y.length,mainCount:E.length,noiseCount:S.length,elapsedMs:W}}}function ir(t,e,n){let o={...nr,...n},r=Date.now(),s=[];for(let h of t){let g=h.z;g<o.heightMin||g>o.heightMax||s.push({x:h.x,z:h.y})}if(s.length<100)return hn(e);let{cells:i}=fo(s,o.cellSize),a=new Set;for(let[h,g]of i)g>=o.densityThreshold&&a.add(h);let u=Wn(a,o.morphIterations),d=[],f={total:0,lowDensity:0};for(let h of e){let g=h.x1,x=h.z1,y=h.x2,m=h.z2;if(Math.sqrt((y-g)**2+(m-x)**2)<.3){d.push(h);continue}let b=0,w=9;for(let z=0;z<w;z++){let M=z/(w-1),P=g+(y-g)*M,E=x+(m-x)*M,S=Math.floor(P/o.cellSize),I=Math.floor(E/o.cellSize);u.has(S+","+I)&&b++}b>=Math.ceil(w*.5)?d.push(h):f.lowDensity++,f.total++}if(d.length<5)return hn(e);let c=hn(d),l=Date.now()-r;return c}function rr(t){return{id:t.id,points:[{x:t.x1,z:t.z1},{x:t.x2,z:t.z2}],length:Math.hypot(t.x2-t.x1,t.z2-t.z1),pointCount:1,type:"straight",isMain:!1}}function lr(t,e,n){let o={outlierEnabled:!0,outlierCellSize:.1,outlierMinNeighbors:3,densityFilterEnabled:!1,...n},r=Date.now(),s=hn(t),i=s.mainWalls,a=s.noiseWalls,u=new Set(i.map(M=>M.id)),d=[];for(let M=0;M<e.length;M++){if(!u.has(M))continue;let P=e[M];if(!(!P||!Array.isArray(P)))for(let E of P)E&&E.x!==void 0&&E.y!==void 0&&E.z!==void 0&&d.push({x:E.x,y:E.y,z:E.z})}let f=d.length,c=d;o.outlierEnabled&&c.length>0&&(c=mo(c,o.outlierCellSize,o.outlierMinNeighbors));let l=[],h=[];if(c.length>=100){let M=o.pcConfig??{},P=ho(c,t,{cellSize:.05,densityThreshold:1,minComponentCells:8,simplifyEpsilon:.008,heightMin:.3,heightMax:2.8,closeIterations:8,densityRatio:.12,...M});l=P.contours??[],h=P.curvedSegments??[]}let g=[];if(h.length>0)for(let M=0;M<h.length;M++){let E=h[M].points;if(E.length<2)continue;let S=1/0,I=-1/0,W=1/0,v=-1/0;for(let D of E)D.x<S&&(S=D.x),D.x>I&&(I=D.x),D.z<W&&(W=D.z),D.z>v&&(v=D.z);let T=[];for(let D of t)si(D,E,.2)&&T.push(D.id);let R=E.map(D=>({x:D.x,y:D.z,z:0}));g.push({id:M,originalPoints:R,rawLineIds:T})}let x;if(o.densityFilterEnabled&&c.length>0&&i.length>0){let M=new Set(s.mainWalls.map(S=>S.id)),P=t.filter(S=>M.has(S.id));x=ir(c,P).mainWalls}let y=new Set;for(let M of s.mainWalls)if(M.lineIds)for(let P of M.lineIds)y.add(P);let m=new Set;for(let M of s.noiseWalls)if(M.lineIds)for(let P of M.lineIds)m.add(P);let p=t.filter(M=>y.has(M.id)).map(rr),b=t.filter(M=>m.has(M.id)).map(rr),w;if(x&&x.length>0){let M=new Set;for(let P of x)if(P.lineIds)for(let E of P.lineIds)M.add(E);w=t.filter(P=>M.has(P.id)).map(rr)}let z=Date.now()-r;return{mainWalls:p,noiseWalls:b,contours:l,curvedSegments:h,lineCurves:g.length>0?g:void 0,filteredPoints:c,secondMainWalls:w,stats:{totalRawLines:t.length,firstMainCount:p.length,firstNoiseCount:b.length,contourCount:l.length,curvedCount:h.length,secondMainCount:x?.length,mainWallPointCount:f,filteredPointCount:c.length,elapsedMs:z}}}function gi(t,e){let n=Array.isArray(t)?t:t?.data??[],o=[],r=[];for(let a=0;a<n.length;a++){let u=n[a],d=u.start??u,f=u.end??u;o.push({id:a,x1:d.x??0,y1:d.z??0,z1:d.y??0,x2:f.x??0,y2:f.z??0,z2:f.y??0});let c=u.originalPoints??u.points??[],l=Array.isArray(c)?c.filter(h=>h&&h.x!==void 0):[];r.push(l)}let s=lr(o,r,e),i=Array.isArray(t)?{data:t}:{...t};return i.lineCurves=s.lineCurves??[],i.lineCurveNum=s.curvedSegments?.length??0,i}export{sr as CONFIG,no as analyzeDoorQuad,je as analyzeQuad,po as applyVoxelFilter,ao as attachWindows,Ue as calcAngle,Xi as checkBeamIsReasonable,Qs as classifyWallByPointCloudPCA,hn as classifyWallShapes,ta as computeContour,Ge as computeDoorLocalFloorZ,$e as computeLocalFloorZ,ni as computeVoxelParams,ri as densityPreFilter,cn as detectDoorPerpendicularWalls,Fa as detectPerpWalls,Tn as detectPerpendicularWalls,kl as drawStaircase,ii as filterFalseArcCurves,Gs as filterWalls,Ys as filterWallsHard,vn as findDoorWalls,js as findMainByLoops,Rn as findWindowWalls,$i as getBeamLine,Ki as getColLine,Ri as getLineCheckResults,un as getMatcherAPI,Fl as getMergeFloorMeaning,Ol as getMergeMeaning,Si as getOneLineCheckResults,vi as getOneLineClusterResults,ea as getSlabData,Nl as getStaircase,or as isRawLineNearArc,li as logArcRawSegments,La as matchWalls,Zs as mergeCollinear,Xe as mergeCollinearSegments,Ye as mergeDoorCollinearSegments,Oa as mergeWallSegments,io as normalizeAngles,jt as pointToDoorSegmentDist,so as pointToSegDist,Qe as pointToSegDist2D,Ce as pointToSegmentDist,jo as processData,Yo as processDoorData,ir as processFilteredByPointCloud,ho as processFromPointCloud,ti as processFromSegments,$a as processPipeline,gi as processSegments,ka as processWallData,mo as removeOutlierPoints,He as rotateXZ,lr as runMainWallPipeline,$s as spatialGrid,Dn as splitDoorWallSegment,Na as splitWallSeg,Sn as splitWallSegment,Bi as updateStEdPoint,ei as voxelFilter,oi as voxelFilterLines};
1
+ var zi=Object.create;var ur=Object.defineProperty;var Mi=Object.getOwnPropertyDescriptor;var Ei=Object.getOwnPropertyNames;var Pi=Object.getPrototypeOf,Ti=Object.prototype.hasOwnProperty;var Be=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Si=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ei(e))!Ti.call(t,r)&&r!==n&&ur(t,r,{get:()=>e[r],enumerable:!(o=Mi(e,r))||o.enumerable});return t};var Ri=(t,e,n)=>(n=t!=null?zi(Pi(t)):{},Si(e||!t||!t.__esModule?ur(n,"default",{value:t,enumerable:!0}):n,t));var Nr=Be((vo,Vo)=>{(function(t,e){typeof vo=="object"&&typeof Vo<"u"?Vo.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self,t.RBush=e())})(vo,function(){"use strict";function t(y,w,z,M,P){e(y,w,z||0,M||y.length-1,P||o)}function e(y,w,z,M,P){for(;M>z;){if(M-z>600){var E=M-z+1,S=w-z+1,I=Math.log(E),W=.5*Math.exp(2*I/3),v=.5*Math.sqrt(I*W*(E-W)/E)*(S-E/2<0?-1:1),T=Math.max(z,Math.floor(w-S*W/E+v)),R=Math.min(M,Math.floor(w+(E-S)*W/E+v));e(y,w,T,R,P)}var D=y[w],H=z,V=M;for(n(y,z,w),P(y[M],D)>0&&n(y,z,M);H<V;){for(n(y,H,V),H++,V--;P(y[H],D)<0;)H++;for(;P(y[V],D)>0;)V--}P(y[z],D)===0?n(y,z,V):(V++,n(y,V,M)),V<=w&&(z=V+1),w<=V&&(M=V-1)}}function n(y,w,z){var M=y[w];y[w]=y[z],y[z]=M}function o(y,w){return y<w?-1:y>w?1:0}var r=function(w){w===void 0&&(w=9),this._maxEntries=Math.max(4,w),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()};r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(w){var z=this.data,M=[];if(!x(w,z))return M;for(var P=this.toBBox,E=[];z;){for(var S=0;S<z.children.length;S++){var I=z.children[S],W=z.leaf?P(I):I;x(w,W)&&(z.leaf?M.push(I):b(w,W)?this._all(I,M):E.push(I))}z=E.pop()}return M},r.prototype.collides=function(w){var z=this.data;if(!x(w,z))return!1;for(var M=[];z;){for(var P=0;P<z.children.length;P++){var E=z.children[P],S=z.leaf?this.toBBox(E):E;if(x(w,S)){if(z.leaf||b(w,S))return!0;M.push(E)}}z=M.pop()}return!1},r.prototype.load=function(w){if(!(w&&w.length))return this;if(w.length<this._minEntries){for(var z=0;z<w.length;z++)this.insert(w[z]);return this}var M=this._build(w.slice(),0,w.length-1,0);if(!this.data.children.length)this.data=M;else if(this.data.height===M.height)this._splitRoot(this.data,M);else{if(this.data.height<M.height){var P=this.data;this.data=M,M=P}this._insert(M,this.data.height-M.height-1,!0)}return this},r.prototype.insert=function(w){return w&&this._insert(w,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(w,z){if(!w)return this;for(var M=this.data,P=this.toBBox(w),E=[],S=[],I,W,v;M||E.length;){if(M||(M=E.pop(),W=E[E.length-1],I=S.pop(),v=!0),M.leaf){var T=s(w,M.children,z);if(T!==-1)return M.children.splice(T,1),E.push(M),this._condense(E),this}!v&&!M.leaf&&b(M,P)?(E.push(M),S.push(I),I=0,W=M,M=M.children[0]):W?(I++,M=W.children[I],v=!1):M=null}return this},r.prototype.toBBox=function(w){return w},r.prototype.compareMinX=function(w,z){return w.minX-z.minX},r.prototype.compareMinY=function(w,z){return w.minY-z.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(w){return this.data=w,this},r.prototype._all=function(w,z){for(var M=[];w;)w.leaf?z.push.apply(z,w.children):M.push.apply(M,w.children),w=M.pop();return z},r.prototype._build=function(w,z,M,P){var E=M-z+1,S=this._maxEntries,I;if(E<=S)return I=m(w.slice(z,M+1)),i(I,this.toBBox),I;P||(P=Math.ceil(Math.log(E)/Math.log(S)),S=Math.ceil(E/Math.pow(S,P-1))),I=m([]),I.leaf=!1,I.height=P;var W=Math.ceil(E/S),v=W*Math.ceil(Math.sqrt(S));p(w,z,M,v,this.compareMinX);for(var T=z;T<=M;T+=v){var R=Math.min(T+v-1,M);p(w,T,R,W,this.compareMinY);for(var D=T;D<=R;D+=W){var H=Math.min(D+W-1,R);I.children.push(this._build(w,D,H,P-1))}}return i(I,this.toBBox),I},r.prototype._chooseSubtree=function(w,z,M,P){for(;P.push(z),!(z.leaf||P.length-1===M);){for(var E=1/0,S=1/0,I=void 0,W=0;W<z.children.length;W++){var v=z.children[W],T=c(v),R=h(w,v)-T;R<S?(S=R,E=T<E?T:E,I=v):R===S&&T<E&&(E=T,I=v)}z=I||z.children[0]}return z},r.prototype._insert=function(w,z,M){var P=M?w:this.toBBox(w),E=[],S=this._chooseSubtree(P,this.data,z,E);for(S.children.push(w),u(S,P);z>=0&&E[z].children.length>this._maxEntries;)this._split(E,z),z--;this._adjustParentBBoxes(P,E,z)},r.prototype._split=function(w,z){var M=w[z],P=M.children.length,E=this._minEntries;this._chooseSplitAxis(M,E,P);var S=this._chooseSplitIndex(M,E,P),I=m(M.children.splice(S,M.children.length-S));I.height=M.height,I.leaf=M.leaf,i(M,this.toBBox),i(I,this.toBBox),z?w[z-1].children.push(I):this._splitRoot(M,I)},r.prototype._splitRoot=function(w,z){this.data=m([w,z]),this.data.height=w.height+1,this.data.leaf=!1,i(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(w,z,M){for(var P,E=1/0,S=1/0,I=z;I<=M-z;I++){var W=l(w,0,I,this.toBBox),v=l(w,I,M,this.toBBox),T=g(W,v),R=c(W)+c(v);T<E?(E=T,P=I,S=R<S?R:S):T===E&&R<S&&(S=R,P=I)}return P||M-z},r.prototype._chooseSplitAxis=function(w,z,M){var P=w.leaf?this.compareMinX:f,E=w.leaf?this.compareMinY:d,S=this._allDistMargin(w,z,M,P),I=this._allDistMargin(w,z,M,E);S<I&&w.children.sort(P)},r.prototype._allDistMargin=function(w,z,M,P){w.children.sort(P);for(var E=this.toBBox,S=l(w,0,z,E),I=l(w,M-z,M,E),W=a(S)+a(I),v=z;v<M-z;v++){var T=w.children[v];u(S,w.leaf?E(T):T),W+=a(S)}for(var R=M-z-1;R>=z;R--){var D=w.children[R];u(I,w.leaf?E(D):D),W+=a(I)}return W},r.prototype._adjustParentBBoxes=function(w,z,M){for(var P=M;P>=0;P--)u(z[P],w)},r.prototype._condense=function(w){for(var z=w.length-1,M=void 0;z>=0;z--)w[z].children.length===0?z>0?(M=w[z-1].children,M.splice(M.indexOf(w[z]),1)):this.clear():i(w[z],this.toBBox)};function s(y,w,z){if(!z)return w.indexOf(y);for(var M=0;M<w.length;M++)if(z(y,w[M]))return M;return-1}function i(y,w){l(y,0,y.children.length,w,y)}function l(y,w,z,M,P){P||(P=m(null)),P.minX=1/0,P.minY=1/0,P.maxX=-1/0,P.maxY=-1/0;for(var E=w;E<z;E++){var S=y.children[E];u(P,y.leaf?M(S):S)}return P}function u(y,w){return y.minX=Math.min(y.minX,w.minX),y.minY=Math.min(y.minY,w.minY),y.maxX=Math.max(y.maxX,w.maxX),y.maxY=Math.max(y.maxY,w.maxY),y}function f(y,w){return y.minX-w.minX}function d(y,w){return y.minY-w.minY}function c(y){return(y.maxX-y.minX)*(y.maxY-y.minY)}function a(y){return y.maxX-y.minX+(y.maxY-y.minY)}function h(y,w){return(Math.max(w.maxX,y.maxX)-Math.min(w.minX,y.minX))*(Math.max(w.maxY,y.maxY)-Math.min(w.minY,y.minY))}function g(y,w){var z=Math.max(y.minX,w.minX),M=Math.max(y.minY,w.minY),P=Math.min(y.maxX,w.maxX),E=Math.min(y.maxY,w.maxY);return Math.max(0,P-z)*Math.max(0,E-M)}function b(y,w){return y.minX<=w.minX&&y.minY<=w.minY&&w.maxX<=y.maxX&&w.maxY<=y.maxY}function x(y,w){return w.minX<=y.maxX&&w.minY<=y.maxY&&w.maxX>=y.minX&&w.maxY>=y.minY}function m(y){return{children:y,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function p(y,w,z,M,P){for(var E=[w,z];E.length;)if(z=E.pop(),w=E.pop(),!(z-w<=M)){var S=w+Math.ceil((z-w)/M/2)*M;t(y,S,w,z,P),E.push(w,S,S,z)}}return r})});var qr=Be((Io,Co)=>{(function(t,e){typeof Io=="object"&&typeof Co<"u"?Co.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self,t.TinyQueue=e())})(Io,function(){"use strict";var t=function(o,r){if(o===void 0&&(o=[]),r===void 0&&(r=e),this.data=o,this.length=this.data.length,this.compare=r,this.length>0)for(var s=(this.length>>1)-1;s>=0;s--)this._down(s)};t.prototype.push=function(o){this.data.push(o),this.length++,this._up(this.length-1)},t.prototype.pop=function(){if(this.length!==0){var o=this.data[0],r=this.data.pop();return this.length--,this.length>0&&(this.data[0]=r,this._down(0)),o}},t.prototype.peek=function(){return this.data[0]},t.prototype._up=function(o){for(var r=this,s=r.data,i=r.compare,l=s[o];o>0;){var u=o-1>>1,f=s[u];if(i(l,f)>=0)break;s[o]=f,o=u}s[o]=l},t.prototype._down=function(o){for(var r=this,s=r.data,i=r.compare,l=this.length>>1,u=s[o];o<l;){var f=(o<<1)+1,d=s[f],c=f+1;if(c<this.length&&i(s[c],d)<0&&(f=c,d=s[c]),i(d,u)>=0)break;s[o]=d,o=f}s[o]=u};function e(n,o){return n<o?-1:n>o?1:0}return t})});var $r=Be((uh,jr)=>{jr.exports=function(e,n,o,r){var s=e[0],i=e[1],l=!1;o===void 0&&(o=0),r===void 0&&(r=n.length);for(var u=(r-o)/2,f=0,d=u-1;f<u;d=f++){var c=n[o+f*2+0],a=n[o+f*2+1],h=n[o+d*2+0],g=n[o+d*2+1],b=a>i!=g>i&&s<(h-c)*(i-a)/(g-a)+c;b&&(l=!l)}return l}});var Zr=Be((fh,Xr)=>{Xr.exports=function(e,n,o,r){var s=e[0],i=e[1],l=!1;o===void 0&&(o=0),r===void 0&&(r=n.length);for(var u=r-o,f=0,d=u-1;f<u;d=f++){var c=n[f+o][0],a=n[f+o][1],h=n[d+o][0],g=n[d+o][1],b=a>i!=g>i&&s<(h-c)*(i-a)/(g-a)+c;b&&(l=!l)}return l}});var Ur=Be((dh,Un)=>{var Gr=$r(),Yr=Zr();Un.exports=function(e,n,o,r){return n.length>0&&Array.isArray(n[0])?Yr(e,n,o,r):Gr(e,n,o,r)};Un.exports.nested=Yr;Un.exports.flat=Gr});var Qr=Be((Kn,Kr)=>{(function(t,e){typeof Kn=="object"&&typeof Kr<"u"?e(Kn):typeof define=="function"&&define.amd?define(["exports"],e):e((t=t||self).predicates={})})(Kn,function(t){"use strict";let n=33306690738754706e-32;function o(h,g,b,x,m){let p,y,w,z,M=g[0],P=x[0],E=0,S=0;P>M==P>-M?(p=M,M=g[++E]):(p=P,P=x[++S]);let I=0;if(E<h&&S<b)for(P>M==P>-M?(w=p-((y=M+p)-M),M=g[++E]):(w=p-((y=P+p)-P),P=x[++S]),p=y,w!==0&&(m[I++]=w);E<h&&S<b;)P>M==P>-M?(w=p-((y=p+M)-(z=y-p))+(M-z),M=g[++E]):(w=p-((y=p+P)-(z=y-p))+(P-z),P=x[++S]),p=y,w!==0&&(m[I++]=w);for(;E<h;)w=p-((y=p+M)-(z=y-p))+(M-z),M=g[++E],p=y,w!==0&&(m[I++]=w);for(;S<b;)w=p-((y=p+P)-(z=y-p))+(P-z),P=x[++S],p=y,w!==0&&(m[I++]=w);return p===0&&I!==0||(m[I++]=p),I}function r(h){return new Float64Array(h)}let s=33306690738754716e-32,i=22204460492503146e-32,l=11093356479670487e-47,u=r(4),f=r(8),d=r(12),c=r(16),a=r(4);t.orient2d=function(h,g,b,x,m,p){let y=(g-p)*(b-m),w=(h-m)*(x-p),z=y-w;if(y===0||w===0||y>0!=w>0)return z;let M=Math.abs(y+w);return Math.abs(z)>=s*M?z:-(function(P,E,S,I,W,v,T){let R,D,H,V,C,_,A,B,k,F,L,O,$,Z,Q,j,X,U,lt=P-W,mt=S-W,St=E-v,ot=I-v;C=(Q=(B=lt-(A=(_=134217729*lt)-(_-lt)))*(F=ot-(k=(_=134217729*ot)-(_-ot)))-((Z=lt*ot)-A*k-B*k-A*F))-(L=Q-(X=(B=St-(A=(_=134217729*St)-(_-St)))*(F=mt-(k=(_=134217729*mt)-(_-mt)))-((j=St*mt)-A*k-B*k-A*F))),u[0]=Q-(L+C)+(C-X),C=($=Z-((O=Z+L)-(C=O-Z))+(L-C))-(L=$-j),u[1]=$-(L+C)+(C-j),C=(U=O+L)-O,u[2]=O-(U-C)+(L-C),u[3]=U;let Mt=(function(Pt,et){let ht=et[0];for(let nt=1;nt<Pt;nt++)ht+=et[nt];return ht})(4,u),bt=i*T;if(Mt>=bt||-Mt>=bt||(R=P-(lt+(C=P-lt))+(C-W),H=S-(mt+(C=S-mt))+(C-W),D=E-(St+(C=E-St))+(C-v),V=I-(ot+(C=I-ot))+(C-v),R===0&&D===0&&H===0&&V===0)||(bt=l*T+n*Math.abs(Mt),(Mt+=lt*V+ot*R-(St*H+mt*D))>=bt||-Mt>=bt))return Mt;C=(Q=(B=R-(A=(_=134217729*R)-(_-R)))*(F=ot-(k=(_=134217729*ot)-(_-ot)))-((Z=R*ot)-A*k-B*k-A*F))-(L=Q-(X=(B=D-(A=(_=134217729*D)-(_-D)))*(F=mt-(k=(_=134217729*mt)-(_-mt)))-((j=D*mt)-A*k-B*k-A*F))),a[0]=Q-(L+C)+(C-X),C=($=Z-((O=Z+L)-(C=O-Z))+(L-C))-(L=$-j),a[1]=$-(L+C)+(C-j),C=(U=O+L)-O,a[2]=O-(U-C)+(L-C),a[3]=U;let Ct=o(4,u,4,a,f);C=(Q=(B=lt-(A=(_=134217729*lt)-(_-lt)))*(F=V-(k=(_=134217729*V)-(_-V)))-((Z=lt*V)-A*k-B*k-A*F))-(L=Q-(X=(B=St-(A=(_=134217729*St)-(_-St)))*(F=H-(k=(_=134217729*H)-(_-H)))-((j=St*H)-A*k-B*k-A*F))),a[0]=Q-(L+C)+(C-X),C=($=Z-((O=Z+L)-(C=O-Z))+(L-C))-(L=$-j),a[1]=$-(L+C)+(C-j),C=(U=O+L)-O,a[2]=O-(U-C)+(L-C),a[3]=U;let Et=o(Ct,f,4,a,d);C=(Q=(B=R-(A=(_=134217729*R)-(_-R)))*(F=V-(k=(_=134217729*V)-(_-V)))-((Z=R*V)-A*k-B*k-A*F))-(L=Q-(X=(B=D-(A=(_=134217729*D)-(_-D)))*(F=H-(k=(_=134217729*H)-(_-H)))-((j=D*H)-A*k-B*k-A*F))),a[0]=Q-(L+C)+(C-X),C=($=Z-((O=Z+L)-(C=O-Z))+(L-C))-(L=$-j),a[1]=$-(L+C)+(C-j),C=(U=O+L)-O,a[2]=O-(U-C)+(L-C),a[3]=U;let zt=o(Et,d,4,a,c);return c[zt-1]})(h,g,b,x,m,p,M)},t.orient2dfast=function(h,g,b,x,m,p){return(g-p)*(b-m)-(h-m)*(x-p)},Object.defineProperty(t,"__esModule",{value:!0})})});var rs=Be((hh,Ao)=>{"use strict";var Jr=Nr(),Jn=qr(),Ta=Ur(),Sa=Qr().orient2d;Jn.default&&(Jn=Jn.default);Ao.exports=os;Ao.exports.default=os;function os(t,e,n){e=Math.max(0,e===void 0?2:e),n=n||0;var o=Ia(t),r=new Jr(16);r.toBBox=function(p){return{minX:p[0],minY:p[1],maxX:p[0],maxY:p[1]}},r.compareMinX=function(p,y){return p[0]-y[0]},r.compareMinY=function(p,y){return p[1]-y[1]},r.load(t);for(var s=[],i=0,l;i<o.length;i++){var u=o[i];r.remove(u),l=ns(u,l),s.push(l)}var f=new Jr(16);for(i=0;i<s.length;i++)f.insert(Ho(s[i]));for(var d=e*e,c=n*n;s.length;){var a=s.shift(),h=a.p,g=a.next.p,b=Wo(h,g);if(!(b<c)){var x=b/d;u=Ra(r,a.prev.p,h,g,a.next.next.p,x,f),u&&Math.min(Wo(u,h),Wo(u,g))<=x&&(s.push(a),s.push(ns(u,a)),r.remove(u),f.remove(a),f.insert(Ho(a)),f.insert(Ho(a.next)))}}a=l;var m=[];do m.push(a.p),a=a.next;while(a!==l);return m.push(a.p),m}function Ra(t,e,n,o,r,s,i){for(var l=new Jn([],Da),u=t.data;u;){for(var f=0;f<u.children.length;f++){var d=u.children[f],c=u.leaf?_o(d,n,o):va(n,o,d);c>s||l.push({node:d,dist:c})}for(;l.length&&!l.peek().node.children;){var a=l.pop(),h=a.node,g=_o(h,e,n),b=_o(h,o,r);if(a.dist<g&&a.dist<b&&es(n,h,i)&&es(o,h,i))return h}u=l.pop(),u&&(u=u.node)}return null}function Da(t,e){return t.dist-e.dist}function va(t,e,n){if(ts(t,n)||ts(e,n))return 0;var o=Qn(t[0],t[1],e[0],e[1],n.minX,n.minY,n.maxX,n.minY);if(o===0)return 0;var r=Qn(t[0],t[1],e[0],e[1],n.minX,n.minY,n.minX,n.maxY);if(r===0)return 0;var s=Qn(t[0],t[1],e[0],e[1],n.maxX,n.minY,n.maxX,n.maxY);if(s===0)return 0;var i=Qn(t[0],t[1],e[0],e[1],n.minX,n.maxY,n.maxX,n.maxY);return i===0?0:Math.min(o,r,s,i)}function ts(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function es(t,e,n){for(var o=Math.min(t[0],e[0]),r=Math.min(t[1],e[1]),s=Math.max(t[0],e[0]),i=Math.max(t[1],e[1]),l=n.search({minX:o,minY:r,maxX:s,maxY:i}),u=0;u<l.length;u++)if(Va(l[u].p,l[u].next.p,t,e))return!1;return!0}function ln(t,e,n){return Sa(t[0],t[1],e[0],e[1],n[0],n[1])}function Va(t,e,n,o){return t!==o&&e!==n&&ln(t,e,n)>0!=ln(t,e,o)>0&&ln(n,o,t)>0!=ln(n,o,e)>0}function Ho(t){var e=t.p,n=t.next.p;return t.minX=Math.min(e[0],n[0]),t.minY=Math.min(e[1],n[1]),t.maxX=Math.max(e[0],n[0]),t.maxY=Math.max(e[1],n[1]),t}function Ia(t){for(var e=t[0],n=t[0],o=t[0],r=t[0],s=0;s<t.length;s++){var i=t[s];i[0]<e[0]&&(e=i),i[0]>o[0]&&(o=i),i[1]<n[1]&&(n=i),i[1]>r[1]&&(r=i)}var l=[e,n,o,r],u=l.slice();for(s=0;s<t.length;s++)Ta(t[s],l)||u.push(t[s]);return Ha(u)}function ns(t,e){var n={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(n.next=e.next,n.prev=e,e.next.prev=n,e.next=n):(n.prev=n,n.next=n),n}function Wo(t,e){var n=t[0]-e[0],o=t[1]-e[1];return n*n+o*o}function _o(t,e,n){var o=e[0],r=e[1],s=n[0]-o,i=n[1]-r;if(s!==0||i!==0){var l=((t[0]-o)*s+(t[1]-r)*i)/(s*s+i*i);l>1?(o=n[0],r=n[1]):l>0&&(o+=s*l,r+=i*l)}return s=t[0]-o,i=t[1]-r,s*s+i*i}function Qn(t,e,n,o,r,s,i,l){var u=n-t,f=o-e,d=i-r,c=l-s,a=t-r,h=e-s,g=u*u+f*f,b=u*d+f*c,x=d*d+c*c,m=u*a+f*h,p=d*a+c*h,y=g*x-b*b,w,z,M,P,E=y,S=y;y===0?(z=0,E=1,P=p,S=x):(z=b*p-x*m,P=g*p-b*m,z<0?(z=0,P=p,S=x):z>E&&(z=E,P=p+b,S=x)),P<0?(P=0,-m<0?z=0:-m>g?z=E:(z=-m,E=g)):P>S&&(P=S,-m+b<0?z=0:-m+b>g?z=E:(z=-m+b,E=g)),w=z===0?0:z/E,M=P===0?0:P/S;var I=(1-w)*t+w*n,W=(1-w)*e+w*o,v=(1-M)*r+M*i,T=(1-M)*s+M*l,R=v-I,D=T-W;return R*R+D*D}function Ca(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}function Ha(t){t.sort(Ca);for(var e=[],n=0;n<t.length;n++){for(;e.length>=2&&ln(e[e.length-2],e[e.length-1],t[n])<=0;)e.pop();e.push(t[n])}for(var o=[],r=t.length-1;r>=0;r--){for(;o.length>=2&&ln(o[o.length-2],o[o.length-1],t[r])<=0;)o.pop();o.push(t[r])}return o.pop(),e.pop(),e.concat(o)}});import*as Oe from"three";import*as ke from"three";var _t=class t{constructor(e=0,n=0,o=0){this.x=e,this.y=n,this.z=o}set(e,n,o){return this.x=e,this.y=n,this.z=o,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}clone(){return new t(this.x,this.y,this.z)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}crossVectors(e,n){let o=e.x,r=e.y,s=e.z,i=n.x,l=n.y,u=n.z;return this.x=r*u-s*l,this.y=s*i-o*u,this.z=o*l-r*i,this}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.lengthSq())}normalize(){let e=this.length();return e>0&&(this.x/=e,this.y/=e,this.z/=e),this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let n=this.x-e.x,o=this.y-e.y,r=this.z-e.z;return n*n+o*o+r*r}toArray(){return[this.x,this.y,this.z]}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}applyAxisAngle(e,n){let o=this.x,r=this.y,s=this.z,i=e.x,l=e.y,u=e.z,f=Math.cos(n),d=Math.sin(n),c=i*o+l*r+u*s;return this.x=i*c*(1-f)+o*f+(-u*r+l*s)*d,this.y=l*c*(1-f)+r*f+(u*o-i*s)*d,this.z=u*c*(1-f)+s*f+(-l*o+i*r)*d,this}},An=class{constructor(e=new _t(1,0,0),n=0){this.normal=e,this.constant=n}set(e,n){return this.normal.copy(e),this.constant=n,this}setFromNormalAndCoplanarPoint(e,n){return this.normal.copy(e),this.constant=-n.dot(this.normal),this}setFromCoplanarPoints(e,n,o){let r=new _t().subVectors(n,e),s=new _t().subVectors(o,e),i=new _t().crossVectors(r,s).normalize();return this.normal.copy(i),this.constant=-e.dot(this.normal),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}projectPoint(e,n=new _t){let o=this.distanceToPoint(e);return n.copy(e),n.x-=this.normal.x*o,n.y-=this.normal.y*o,n.z-=this.normal.z*o,n}},_n=()=>typeof performance<"u"&&performance.now?performance.now():Date.now(),wo=class{constructor(){this.results=null,this.clusterResults=null}initLimits1(e,n){let o,r;return e<.3?o=5:e<.5?o=8:e<.8?o=10:e<1?o=15:e<2?o=30:e<3?o=35:e<4?o=40:e<5?o=45:e<6?o=50:e<7?o=60:e<8.5?o=70:e<10?o=80:e<15?o=100:e<20?o=120:e<25?o=140:e<30?o=160:e<35?o=180:e<40?o=200:e<45?o=230:e<50?o=250:o=350,n<1?r=30:n<2?r=40:n<2.5?r=45:n<3?r=60:n<3.6?r=70:r=80,{horizontalSubdivisions:o,verticalSubdivisions:r}}initLimits2(e,n){let s=Math.round(Math.max(5,Math.min(350,e/.08))),i=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:s,verticalSubdivisions:i}}initLimits3(e,n){let o;e<2?o=.06:e<10?o=.1:o=.15;let r=Math.round(Math.max(5,Math.min(350,e/o))),s=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(e,n){let o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(e)))),r=Math.round(Math.max(30,Math.min(80,20*Math.sqrt(n))));return{horizontalSubdivisions:o,verticalSubdivisions:r}}createSubdividedWallPlane(e,n,o,r=null){let s=[];if(!e||!e.start||!e.end||isNaN(e.rooftopPz))return s;let i=new _t(e.start.x,e.start.y,e.start.z),l=new _t(e.end.x,e.end.y,e.end.z),u=new _t(e.end.x,e.end.y,e.rooftopPz),f=new _t(e.start.x,e.start.y,e.rooftopPz),d=[i,l,u,f];for(let P=0;P<d.length;P++)if(!this.isValidVector3(d[P]))return console.error(`\u5899\u4F53\u57FA\u7840\u70B9${P}\u65E0\u6548:`,d[P]),s;let c=i.distanceTo(l),a=Math.abs(e.rooftopPz-e.start.z);if(c===0||a===0)return s;let h=c/o,g=a/n,b=new _t().subVectors(l,i).normalize(),x=i.x,m=i.y,p=i.z,y=b.x,w=b.y,z=b.z,M=(P,E)=>new _t(x+y*P,m+w*P,p+z*P+E);for(let P=0;P<n;P++){let E=P*g,S=(P+1)*g;for(let I=0;I<o;I++){let W=I*h,v=(I+1)*h;s.push({points:[M(W,E),M(v,E),M(v,S),M(W,S)],userData:{type:"wallSegment",row:P,col:I,width:h,height:g}})}}return s}analyzePointDistribution(e,n,o=.01,r={}){let s=r.projectPlane||null;this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],existSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};let i=_n(),l=[],u=new Map,f=1/0,d=-1/0,c=1/0,a=-1/0;for(let W=0;W<e.length;W++){let v=e[W];if(v.userData&&v.userData.type==="wallSegment"){let T=this.getWorldVerticesNew(v.points);if(T.length<4)continue;let R=new _t().add(T[0]).add(T[1]).add(T[2]).add(T[3]).multiplyScalar(.25);v.userData.center=R,v.vertices=T;let D=v.userData.row,H=v.userData.col,V=`row${D}_col${H}`;l.push(v),u.set(V,v),D<f&&(f=D),D>d&&(d=D),H<c&&(c=H),H>a&&(a=H)}}if(this.results.totalSegments=l.length,l.length===0)return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results;let h=`row${f}_col${c}`,g=u.get(h)||l[0];if(!g||!g.vertices||g.vertices.length<4)return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results;let b=g.vertices[0],x=g.vertices[1],m=g.vertices[3],p=new _t().subVectors(x,b).normalize(),y=new _t().subVectors(m,b).normalize(),w=g.userData.width,z=g.userData.height,M=d-f+1,P=a-c+1,E=new An;E.setFromCoplanarPoints(b,x,m);let S=new _t,I=new _t;for(let W=0;W<n.length;W+=3){let v=new _t(n[W],n[W+1],n[W+2]),T=s?s.projectPoint(v,I):v;if(Math.abs(E.distanceToPoint(T))>o)continue;S.subVectors(T,b);let D=S.dot(p),H=S.dot(y),V=Math.ceil((D-o)/w-1),C=Math.floor((D+o)/w),_=Math.ceil((H-o)/z-1),A=Math.floor((H+o)/z);if(C<0||V>P-1||A<0||_>M-1)continue;let B=Math.max(0,V),k=Math.min(P-1,C),F=Math.max(0,_),L=Math.min(M-1,A);for(let O=F;O<=L;O++){let $=f+O;for(let Z=B;Z<=k;Z++){let Q=c+Z,j=`row${$}_col${Q}`;u.has(j)&&(this.results.pointsInSegments.has(j)||this.results.pointsInSegments.set(j,[W]))}}}for(let W of l){let v=`row${W.userData.row}_col${W.userData.col}`,T=this.results.pointsInSegments.has(v)?this.results.pointsInSegments.get(v).length:0,R=T>=1,D={row:W.userData.row,col:W.userData.col,width:W.userData.width,height:W.userData.height,segmentKey:v,vertices:W.vertices,center:W.userData.center,mesh:W,pointCount:T,hasPointsButNotEnough:T>0&&T<1};R?(this.results.segmentsWithPoints++,this.results.existSegments.push(D)):(this.results.segmentsWithoutPoints++,this.results.missingSegments.push(D))}return this.results.analysisTime=_n()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(e,n,o,r,s,i,l,u,f,d,c){if(Math.abs(o.distanceToPoint(e))>c)return!1;let h=new _t().subVectors(e,n),g=Math.abs(h.dot(s)),b=Math.abs(h.dot(i));if(g>f&&b>d)return!1;let x=new _t().subVectors(e,r),m=x.dot(s),p=x.dot(i),y=m>=-c&&m<=l+c,w=p>=-c&&p<=u+c;return y&&w}getWorldVerticesNew(e){return e}highlightEmptySegments(e,n=null,o=null,r=1){if(!this.results)return console.warn("\u8BF7\u5148\u8FD0\u884C\u5206\u6790\u51FD\u6570"),null;let s=new Map,i=new Map;for(let f of this.results.missingSegments)s.set(f.segmentKey,f),i.has(f.row)||i.set(f.row,new Map),i.get(f.row).set(f.col,{segmentKey:f.segmentKey,isEmpty:!0,visited:!1});for(let f of e)if(f.userData&&f.userData.type==="wallSegment"){let d=`row${f.userData.row}_col${f.userData.col}`,c=s.has(d);i.has(f.userData.row)||i.set(f.userData.row,new Map),i.get(f.userData.row).has(f.userData.col)||i.get(f.userData.row).set(f.userData.col,{segmentKey:d,isEmpty:c,visited:!1})}let l=[],u=[[0,1],[1,0],[0,-1],[-1,0]];for(let[f,d]of s){let c=i.get(d.row)?.get(d.col);if(c&&!c.visited){let a=[],h=[[d.row,d.col]],g=0;for(c.visited=!0;g<h.length;){let b=h[g++],x=b[0],m=b[1],p=`row${x}_col${m}`;s.has(p)&&a.push(s.get(p));for(let y of u){let w=x+y[0],z=m+y[1];if(i.has(w)&&i.get(w).has(z)){let M=i.get(w).get(z);!M.visited&&M.isEmpty&&(M.visited=!0,h.push([w,z]))}}}a.length>=r&&l.push(a)}}return this.clusterResults={clusters:l.sort((f,d)=>d.length-f.length),totalClusters:l.length},this.clusterResults}getClusterInfo(){if(!this.clusterResults)return null;let e=this.clusterResults.clusters.map(n=>n.length);return{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((n,o)=>({clusterIndex:o,size:n.length,segments:n.map(r=>r.segmentKey)})),largestCluster:e.length?Math.max(...e):0,smallestCluster:e.length?Math.min(...e):0}}printAnalysisResults(){if(!this.results){console.warn("\u6CA1\u6709\u53EF\u7528\u7684\u5206\u6790\u7ED3\u679C");return}}isValidVector3(e){return e&&!isNaN(e.x)&&!isNaN(e.y)&&!isNaN(e.z)&&isFinite(e.x)&&isFinite(e.y)&&isFinite(e.z)}},fr=(t,e)=>{let n={},o=[],r=[];if(!t||t.length===0)return n.originalVertices=o,n.allCenterPoints=r,n;if(e=="xyz")for(let s of t){r.push({x:s.center.x,y:s.center.y,z:s.center.z});let i=[];for(let l=0;l<s.vertices.length;l++)i.push({x:s.vertices[l].x,y:s.vertices[l].y,z:s.vertices[l].z});o.push(i)}else if(e=="three")for(let s of t){r.push(new ke.Vector3(s.center.x,s.center.y,s.center.z));let i=[];for(let l=0;l<s.vertices.length;l++)i.push(new ke.Vector3(s.vertices[l].x,s.vertices[l].y,s.vertices[l].z));o.push(i)}else if(e=="array")for(let s of t){r.push(s.center.x),r.push(s.center.y),r.push(s.center.z);let i=[];for(let l=0;l<s.vertices.length;l++)i.push(s.vertices[l].x,s.vertices[l].y,s.vertices[l].z);o.push(i)}return n.originalVertices=o,n.allCenterPoints=r,n},Di=(t,e)=>{let n=new _t().copy(t.start).add(t.end).multiplyScalar(.5),o=new _t().subVectors(new _t(n.x,n.y,n.z+1),n).normalize(),r=new _t(t.direction.x,t.direction.y,0);r.applyAxisAngle(o,Math.PI/2);let s=new _t().copy(n).add(r.clone().multiplyScalar(t.length)),i=new _t().copy(n).sub(r.clone().multiplyScalar(t.length));if(n.z=t.start.z,s.z=t.start.z,i.z=t.start.z,e=="three")return{start:new ke.Vector3(s.x,s.y,s.z),end:new ke.Vector3(i.x,i.y,i.z),center:new ke.Vector3(n.x,n.y,n.z),direction:new ke.Vector3(r.x,r.y,r.z)};if(e=="xyz")return{start:{x:s.x,y:s.y,z:s.z},end:{x:i.x,y:i.y,z:i.z},center:{x:n.x,y:n.y,z:n.z},direction:{x:r.x,y:r.y,z:r.z}};if(e=="array")return{start:[s.x,s.y,s.z],end:[i.x,i.y,i.z],center:[n.x,n.y,n.z],direction:[r.x,r.y,r.z]}},dr=async(t,e=!0,n="three")=>{for(let o=0;o<t.length;o++){let r=t[o];await zo(r,e,n)}},zo=(t,e=!0,n="three")=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&e)return;let o=new An().setFromCoplanarPoints(new _t(t.start.x,t.start.y,t.start.z),new _t(t.end.x,t.end.y,t.end.z),new _t(t.start.x,t.start.y,t.rooftopPz)),r=new _t(t.start.x,t.start.y,t.start.z).distanceTo(new _t(t.end.x,t.end.y,t.end.z)),s=Math.abs(t.rooftopPz-t.start.z),i=new wo,{horizontalSubdivisions:l,verticalSubdivisions:u}=i.initLimits4(r,s),f=i.createSubdividedWallPlane(t,u,l,null);i.analyzePointDistribution(f,t.originalPoints,.01,{projectPlane:o});let d=i.highlightEmptySegments(f,null,null),c=[];if(d&&d.clusters)for(let g of d.clusters){let b=fr(g,n);b&&c.push(b)}let h=Di(t,n).direction;if(t.checkResults=c,t.verticalDirection=h,t.saveExistSegments){let g=[],b=fr(i.results.existSegments,n);b&&g.push(b),t.existSegments=g}};var Vt=class t{constructor(e=0,n=0,o=0){this.x=e,this.y=n,this.z=o}set(e,n,o){return this.x=e,this.y=n,this.z=o,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}clone(){return new t(this.x,this.y,this.z)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}crossVectors(e,n){let o=e.x,r=e.y,s=e.z,i=n.x,l=n.y,u=n.z;return this.x=r*u-s*l,this.y=s*i-o*u,this.z=o*l-r*i,this}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.lengthSq())}normalize(){let e=this.length();return e>0&&(this.x/=e,this.y/=e,this.z/=e),this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let n=this.x-e.x,o=this.y-e.y,r=this.z-e.z;return n*n+o*o+r*r}toArray(){return[this.x,this.y,this.z]}fromArray(e,n=0){return this.x=e[n],this.y=e[n+1],this.z=e[n+2],this}applyAxisAngle(e,n){let o=this.x,r=this.y,s=this.z,i=e.x,l=e.y,u=e.z,f=Math.cos(n),d=Math.sin(n),c=i*o+l*r+u*s;return this.x=i*c*(1-f)+o*f+(-u*r+l*s)*d,this.y=l*c*(1-f)+r*f+(u*o-i*s)*d,this.z=u*c*(1-f)+s*f+(-l*o+i*r)*d,this}},bn=class{constructor(e=new Vt(1,0,0),n=0){this.normal=e,this.constant=n}set(e,n){return this.normal.copy(e),this.constant=n,this}setFromNormalAndCoplanarPoint(e,n){return this.normal.copy(e),this.constant=-n.dot(this.normal),this}setFromCoplanarPoints(e,n,o){let r=new Vt().subVectors(n,e),s=new Vt().subVectors(o,e),i=new Vt().crossVectors(r,s).normalize();return this.normal.copy(i),this.constant=-e.dot(this.normal),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}projectPoint(e,n=new Vt){let o=this.distanceToPoint(e);return n.copy(e),n.x-=this.normal.x*o,n.y-=this.normal.y*o,n.z-=this.normal.z*o,n}},Ln=()=>typeof performance<"u"&&performance.now?performance.now():Date.now(),Bn=class{constructor(){this.results=null,this.clusterResults=null}initLimits1(e,n){let o,r;return e<.3?o=5:e<.5?o=8:e<.8?o=10:e<1?o=15:e<2?o=30:e<3?o=35:e<4?o=40:e<5?o=45:e<6?o=50:e<7?o=60:e<8.5?o=70:e<10?o=80:e<15?o=100:e<20?o=120:e<25?o=140:e<30?o=160:e<35?o=180:e<40?o=200:e<45?o=230:e<50?o=250:o=350,n<1?r=30:n<2?r=40:n<2.5?r=45:n<3?r=60:n<3.6?r=70:r=80,{horizontalSubdivisions:o,verticalSubdivisions:r}}initLimits2(e,n){let s=Math.round(Math.max(5,Math.min(350,e/.08))),i=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:s,verticalSubdivisions:i}}initLimits3(e,n){let o;e<2?o=.06:e<10?o=.1:o=.15;let r=Math.round(Math.max(5,Math.min(350,e/o))),s=Math.round(Math.max(30,Math.min(80,n/.06)));return{horizontalSubdivisions:r,verticalSubdivisions:s}}initLimits4(e,n){let o=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(e)))),r=Math.round(Math.max(30,Math.min(80,20*Math.sqrt(n))));return{horizontalSubdivisions:o,verticalSubdivisions:r}}createSubdividedWallPlane(e,n,o,r=null){let s=[];if(!e||!e.start||!e.end||isNaN(e.rooftopPz))return s;let i=new Vt(e.start.x,e.start.y,e.start.z),l=new Vt(e.end.x,e.end.y,e.end.z),u=new Vt(e.end.x,e.end.y,e.rooftopPz),f=new Vt(e.start.x,e.start.y,e.rooftopPz),d=[i,l,u,f];for(let P=0;P<d.length;P++)if(!this.isValidVector3(d[P]))return console.error(`\u5899\u4F53\u57FA\u7840\u70B9${P}\u65E0\u6548:`,d[P]),s;let c=i.distanceTo(l),a=Math.abs(e.rooftopPz-e.start.z);if(c===0||a===0)return s;let h=c/o,g=a/n,b=new Vt().subVectors(l,i).normalize(),x=i.x,m=i.y,p=i.z,y=b.x,w=b.y,z=b.z,M=(P,E)=>new Vt(x+y*P,m+w*P,p+z*P+E);for(let P=0;P<n;P++){let E=P*g,S=(P+1)*g;for(let I=0;I<o;I++){let W=I*h,v=(I+1)*h;s.push({points:[M(W,E),M(v,E),M(v,S),M(W,S)],userData:{type:"wallSegment",row:P,col:I,width:h,height:g}})}}return s}analyzePointDistribution(e,n,o=.01,r={}){let s=r.projectPlane||null;this.results={totalSegments:0,segmentsWithPoints:0,segmentsWithoutPoints:0,missingSegments:[],existSegments:[],pointsInSegments:new Map,segmentsByPoint:new Map,segmentDetails:new Map,tolerance:o,analysisTime:null};let i=Ln(),l=[],u=new Map,f=1/0,d=-1/0,c=1/0,a=-1/0;for(let W=0;W<e.length;W++){let v=e[W];if(v.userData&&v.userData.type==="wallSegment"){let T=this.getWorldVerticesNew(v.points);if(T.length<4)continue;let R=new Vt().add(T[0]).add(T[1]).add(T[2]).add(T[3]).multiplyScalar(.25);v.userData.center=R,v.vertices=T;let D=v.userData.row,H=v.userData.col,V=`row${D}_col${H}`;l.push(v),u.set(V,v),D<f&&(f=D),D>d&&(d=D),H<c&&(c=H),H>a&&(a=H)}}if(this.results.totalSegments=l.length,l.length===0)return this.results.analysisTime=Ln()-i,this.printAnalysisResults(),this.results;let h=`row${f}_col${c}`,g=u.get(h)||l[0];if(!g||!g.vertices||g.vertices.length<4)return this.results.analysisTime=Ln()-i,this.printAnalysisResults(),this.results;let b=g.vertices[0],x=g.vertices[1],m=g.vertices[3],p=new Vt().subVectors(x,b).normalize(),y=new Vt().subVectors(m,b).normalize(),w=g.userData.width,z=g.userData.height,M=d-f+1,P=a-c+1,E=new bn;E.setFromCoplanarPoints(b,x,m);let S=new Vt,I=new Vt;for(let W=0;W<n.length;W++){let v=n[W],T=s?s.projectPoint(v,I):v;if(Math.abs(E.distanceToPoint(T))>o)continue;S.subVectors(T,b);let D=S.dot(p),H=S.dot(y),V=Math.ceil((D-o)/w-1),C=Math.floor((D+o)/w),_=Math.ceil((H-o)/z-1),A=Math.floor((H+o)/z);if(C<0||V>P-1||A<0||_>M-1)continue;let B=Math.max(0,V),k=Math.min(P-1,C),F=Math.max(0,_),L=Math.min(M-1,A);for(let O=F;O<=L;O++){let $=f+O;for(let Z=B;Z<=k;Z++){let Q=c+Z,j=`row${$}_col${Q}`;u.has(j)&&(this.results.pointsInSegments.has(j)||this.results.pointsInSegments.set(j,[W]))}}}for(let W of l){let v=`row${W.userData.row}_col${W.userData.col}`,T=this.results.pointsInSegments.has(v)?this.results.pointsInSegments.get(v).length:0,R=T>=1,D={row:W.userData.row,col:W.userData.col,width:W.userData.width,height:W.userData.height,segmentKey:v,vertices:W.vertices,center:W.userData.center,mesh:W,pointCount:T,hasPointsButNotEnough:T>0&&T<1};R?(this.results.segmentsWithPoints++,this.results.existSegments.push(D)):(this.results.segmentsWithoutPoints++,this.results.missingSegments.push(D))}return this.results.analysisTime=Ln()-i,this.printAnalysisResults(),this.results}isPointInWallSegmentOptimized(e,n,o,r,s,i,l,u,f,d,c){if(Math.abs(o.distanceToPoint(e))>c)return!1;let h=new Vt().subVectors(e,n),g=Math.abs(h.dot(s)),b=Math.abs(h.dot(i));if(g>f&&b>d)return!1;let x=new Vt().subVectors(e,r),m=x.dot(s),p=x.dot(i),y=m>=-c&&m<=l+c,w=p>=-c&&p<=u+c;return y&&w}getWorldVerticesNew(e){return e}highlightEmptySegments(e,n=null,o=null,r=1){if(!this.results)return console.warn("\u8BF7\u5148\u8FD0\u884C\u5206\u6790\u51FD\u6570"),null;let s=new Map,i=new Map;for(let f of this.results.missingSegments)s.set(f.segmentKey,f),i.has(f.row)||i.set(f.row,new Map),i.get(f.row).set(f.col,{segmentKey:f.segmentKey,isEmpty:!0,visited:!1});for(let f of e)if(f.userData&&f.userData.type==="wallSegment"){let d=`row${f.userData.row}_col${f.userData.col}`,c=s.has(d);i.has(f.userData.row)||i.set(f.userData.row,new Map),i.get(f.userData.row).has(f.userData.col)||i.get(f.userData.row).set(f.userData.col,{segmentKey:d,isEmpty:c,visited:!1})}let l=[],u=[[0,1],[1,0],[0,-1],[-1,0]];for(let[f,d]of s){let c=i.get(d.row)?.get(d.col);if(c&&!c.visited){let a=[],h=[[d.row,d.col]],g=0;for(c.visited=!0;g<h.length;){let b=h[g++],x=b[0],m=b[1],p=`row${x}_col${m}`;s.has(p)&&a.push(s.get(p));for(let y of u){let w=x+y[0],z=m+y[1];if(i.has(w)&&i.get(w).has(z)){let M=i.get(w).get(z);!M.visited&&M.isEmpty&&(M.visited=!0,h.push([w,z]))}}}a.length>=r&&l.push(a)}}return this.clusterResults={clusters:l.sort((f,d)=>d.length-f.length),totalClusters:l.length},this.clusterResults}getClusterInfo(){if(!this.clusterResults)return null;let e=this.clusterResults.clusters.map(n=>n.length);return{totalClusters:this.clusterResults.totalClusters,clusterSizes:this.clusterResults.clusters.map((n,o)=>({clusterIndex:o,size:n.length,segments:n.map(r=>r.segmentKey)})),largestCluster:e.length?Math.max(...e):0,smallestCluster:e.length?Math.min(...e):0}}printAnalysisResults(){if(!this.results){console.warn("\u6CA1\u6709\u53EF\u7528\u7684\u5206\u6790\u7ED3\u679C");return}}isValidVector3(e){return e&&!isNaN(e.x)&&!isNaN(e.y)&&!isNaN(e.z)&&isFinite(e.x)&&isFinite(e.y)&&isFinite(e.z)}},hr=(t,e)=>{let n={},o=[],r=[];if(!t||t.length===0)return n.originalVertices=o,n.allCenterPoints=r,n;if(e=="xyz")for(let s of t){r.push({x:s.center.x,y:s.center.y,z:s.center.z});let i=[];for(let l=0;l<s.vertices.length;l++)i.push({x:s.vertices[l].x,y:s.vertices[l].y,z:s.vertices[l].z});o.push(i)}else if(e=="three")for(let s of t){r.push(new Oe.Vector3(s.center.x,s.center.y,s.center.z));let i=[];for(let l=0;l<s.vertices.length;l++)i.push(new Oe.Vector3(s.vertices[l].x,s.vertices[l].y,s.vertices[l].z));o.push(i)}else if(e=="array")for(let s of t){r.push(s.center.x),r.push(s.center.y),r.push(s.center.z);let i=[];for(let l=0;l<s.vertices.length;l++)i.push(s.vertices[l].x,s.vertices[l].y,s.vertices[l].z);o.push(i)}return n.originalVertices=o,n.allCenterPoints=r,n},vi=(t,e)=>{let n=new Vt().copy(t.start).add(t.end).multiplyScalar(.5),o=new Vt().subVectors(new Vt(n.x,n.y,n.z+1),n).normalize(),r=new Vt(t.direction.x,t.direction.y,0);r.applyAxisAngle(o,Math.PI/2);let s=new Vt().copy(n).add(r.clone().multiplyScalar(t.length)),i=new Vt().copy(n).sub(r.clone().multiplyScalar(t.length));if(n.z=t.start.z,s.z=t.start.z,i.z=t.start.z,e=="three")return{start:new Oe.Vector3(s.x,s.y,s.z),end:new Oe.Vector3(i.x,i.y,i.z),center:new Oe.Vector3(n.x,n.y,n.z),direction:new Oe.Vector3(r.x,r.y,r.z)};if(e=="xyz")return{start:{x:s.x,y:s.y,z:s.z},end:{x:i.x,y:i.y,z:i.z},center:{x:n.x,y:n.y,z:n.z},direction:{x:r.x,y:r.y,z:r.z}};if(e=="array")return{start:[s.x,s.y,s.z],end:[i.x,i.y,i.z],center:[n.x,n.y,n.z],direction:[r.x,r.y,r.z]}},Vi=(t,e=!0,n="three",o="xyz")=>{o=="xyz"?mr(t,e,n):o=="array"&&zo(t,e,n)},Ii=(t,e=!0,n="three",o="xyz")=>{o=="xyz"?Ci(t,e,n):o=="array"&&dr(t,e,n)},Ci=(t,e=!0,n="three")=>{for(let o=0;o<t.length;o++){let r=t[o];mr(r,e,n)}},mr=(t,e=!0,n="three")=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&e)return;let o=new bn().setFromCoplanarPoints(new Vt(t.start.x,t.start.y,t.start.z),new Vt(t.end.x,t.end.y,t.end.z),new Vt(t.start.x,t.start.y,t.rooftopPz)),r=new Vt(t.start.x,t.start.y,t.start.z).distanceTo(new Vt(t.end.x,t.end.y,t.end.z)),s=Math.abs(t.rooftopPz-t.start.z),i=new Bn,{horizontalSubdivisions:l,verticalSubdivisions:u}=i.initLimits4(r,s),f=i.createSubdividedWallPlane(t,u,l,null);i.analyzePointDistribution(f,t.originalPoints,.01,{projectPlane:o});let d=i.highlightEmptySegments(f,null,null),c=[];if(d&&d.clusters)for(let g of d.clusters){let b=hr(g,n);b&&c.push(b)}let h=vi(t,n).direction;if(t.checkResults=c,t.verticalDirection=h,t.saveExistSegments){let g=[],b=hr(i.results.existSegments,n);b&&g.push(b),t.existSegments=g}},Hi=t=>{if((t.isBayWindow||t.isWindow||t.isBalconyRailing)&&limit)return;let e=new bn().setFromCoplanarPoints(new Vt(t.start.x,t.start.y,t.start.z),new Vt(t.end.x,t.end.y,t.end.z),new Vt(t.start.x,t.start.y,t.rooftopPz)),n=new Vt(t.start.x,t.start.y,t.start.z).distanceTo(new Vt(t.end.x,t.end.y,t.end.z)),o=Math.abs(t.rooftopPz-t.start.z),r=new Bn,{horizontalSubdivisions:s,verticalSubdivisions:i}=r.initLimits4(n,o),l=r.createSubdividedWallPlane(t,i,s,null);return r.analyzePointDistribution(l,t.originalPoints,.01,{projectPlane:e}),r.highlightEmptySegments(l,null,null)};import*as N from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";import*as Y from"three";import{CSS2DObject as _c}from"three/examples/jsm/renderers/CSS2DRenderer.js";import"three/examples/jsm/utils/BufferGeometryUtils.js";import Ee from"path";import{fileURLToPath as Ai}from"url";import kn from"path";import{fileURLToPath as Wi}from"url";import{Vector3 as hc}from"three";var _i=Wi(import.meta.url),Mo=kn.dirname(_i),mc=kn.resolve(Mo,"./data/lines.meta.json"),pc=kn.resolve(Mo,"./data/lines.bin"),gc=kn.resolve(Mo,"./data/checks.bin");var Li=Ai(import.meta.url),ve=Ee.dirname(Li),Mc=Ee.resolve(ve,"./data/lines.tmp.bin"),Ec=Ee.resolve(ve,"./data/checks.tmp.bin"),Pc=Ee.resolve(ve,"./data/lines.new_points.tmp.bin"),Tc=Ee.resolve(ve,"./data/lines.new_points.bin"),Sc=Ee.resolve(ve,"./data/lines.meta.json"),Rc=Ee.resolve(ve,"./data/lines.bin"),Dc=Ee.resolve(ve,"./data/checks.bin"),vc=Ee.resolve(ve,"./data/lines.exist_segments.bin"),Vc=Ee.resolve(ve,"./data/lines.exist_segments.tmp.bin");import{Vector3 as Bi}from"three";var On=class{points=[];_tempArr=[0,0,0];constructor(e){}initPoints(e){this.points=e}getPointByIndex(e,n){let o=e*3;return n.x=this.points[o],n.y=this.points[o+1],n.z=this.points[o+2],n}getPointArrByIndex(e){let n=e*3;return[this.points[n],this.points[n+1],this.points[n+2]]}getPoint2ArrByIndex(e){let n=e*3;return[this.points[n],this.points[n+1]]}getIndexsByIndex(e,n){n.length=0,n.push(e*3),n.push(e*3+1),n.push(e*3+2)}pointsToVector3Arr(e){let n=[];for(let o=0;o<e.length/3;o++)n.push(new Bi(e[o*3],e[o*3+1],e[o*3+2]));return n}vector3ArrToPoints(e){let n=[];for(let o=0;o<e.length;o++)n.push(e[o].x,e[o].y,e[o].z);return n}vector3ArrToFloat32Array(e){return new Float32Array(e.flatMap(o=>[o.x,o.y,o.z]))}clsoe(){this.points=[]}};var xr=(t,e,n)=>{let o=new Y.LineBasicMaterial({color:"#0011ff"}),r=[];r.push(t),r.push(e);let s=new Y.BufferGeometry;s.setFromPoints(r),s.rotateX(-Math.PI/2),n.add(new Y.Line(s,o))},Pe=(t,e,n,o,r=1e-8)=>{let s=e.x-t.x,i=e.y-t.y,l=o.x-n.x,u=o.y-n.y,f=s*u-i*l;if(Math.abs(f)<r)return null;let d=((n.x-t.x)*u-(n.y-t.y)*l)/f,c=((n.x-t.x)*i-(n.y-t.y)*s)/f;return d<-r||d>1+r||c<-r||c>1+r?null:{point:new Y.Vector3(t.x+d*s,t.y+d*i,t.z)}},yr=(t,e,n={})=>{let{fontSize:o=36,fontFamily:r="sans-serif",backgroundColor:s="rgba(0,0,0,0)",textColor:i="#ffffff",padding:l=10,maxWidth:u=256}=n,d=document.createElement("canvas").getContext("2d");d.font=`bold ${o}px ${r}`;let a=d.measureText(t).width,h=Math.min(a+l*2,u),g=o+l*2,b=document.createElement("canvas");b.width=h,b.height=g;let x=b.getContext("2d");x.fillStyle=s,x.fillRect(0,0,h,g),x.fillStyle=i,x.font=`bold ${o}px ${r}`,x.textAlign="center",x.textBaseline="middle",a>u-l*2?ki(x,t,h/2,g/2,u,o):x.fillText(t,h/2,g/2);let m=new Y.CanvasTexture(b),p=new Y.SpriteMaterial({map:m,depthTest:!1,transparent:!0}),y=new Y.Sprite(p);y.position.set(e.x,e.y,e.z);let w=.005;return y.scale.set(h*w,g*w,1),y};function ki(t,e,n,o,r,s){let i=e.split(""),l="",u=s*1.2,f=o;for(let d=0;d<i.length;d++){let c=l+i[d];t.measureText(c).width>r&&d>0?(t.fillText(l,n,f),l=i[d],f+=u):l=c}t.fillText(l,n,f)}var Xt=(t,e,n=.01)=>{let o=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(o<1e-10||r<1e-10)return{parallel:!1,sameDirection:null,angle:NaN};let s={x:t.x/o,y:t.y/o,z:t.z/o},i={x:e.x/r,y:e.y/r,z:e.z/r},l=s.x*i.x+s.y*i.y+s.z*i.z;l=Math.max(-1,Math.min(1,l));let u=Math.acos(Math.abs(l)),f=u<=n;return{parallel:f,sameDirection:f?l>0:null,angle:u}};var br=(t,e,n,o)=>{if(e<1e-4||n<1e-4)return{};let r=t,s=[];if(o&&o.length&&(s=o.map(M=>M.clone())),!r||r.length<4)return{};let i=new Y.Vector3().subVectors(r[1],r[0]).normalize(),l=new Y.Vector3().subVectors(r[3],r[0]).normalize(),u=i.clone().cross(l).normalize(),f=1/0,d=-1/0,c=1/0,a=-1/0;for(let M of r){let P=M.dot(i),E=M.dot(l);P<f&&(f=P),P>d&&(d=P),E<c&&(c=E),E>a&&(a=E)}let h=r[0].dot(u),g=i.clone().multiplyScalar(f).add(l.clone().multiplyScalar(c)).add(u.clone().multiplyScalar(h)),b=i.clone().multiplyScalar(d).add(l.clone().multiplyScalar(c)).add(u.clone().multiplyScalar(h)),x=i.clone().multiplyScalar(d).add(l.clone().multiplyScalar(a)).add(u.clone().multiplyScalar(h)),m=i.clone().multiplyScalar(f).add(l.clone().multiplyScalar(a)).add(u.clone().multiplyScalar(h)),p=[g,b,x,m],y=Xt(new Y.Vector3().subVectors(g,b),new Y.Vector3(0,0,1));y&&y.parallel&&(p=[g,m,x,b]);let w=0;if(o.length>0){let M=new Y.Vector3().subVectors(p[1],p[0]).normalize(),P=M.clone().negate(),E=new Y.Vector3().subVectors(p[3],p[0]).normalize(),S=E.clone().negate(),I=p[0].distanceTo(p[1]),W=p[0].distanceTo(p[3]),v=I/e,T=W/n,R=.001;for(let D=0;D<v;D++){let H=p[0],V=0;for(let C=0;C<T;C++){let _=H.clone().addScaledVector(M,e),A=_.clone().addScaledVector(E,n),B=H.clone().addScaledVector(E,n),k=new Y.Vector3().add(H).add(_).add(A).add(B).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=B}if(V>=T/2)break;w+=V,p[0]=p[0].addScaledVector(M,e),p[3]=p[3].addScaledVector(M,e)}I=p[0].distanceTo(p[1]),v=I/e;for(let D=0;D<v;D++){let H=p[1],V=0;for(let C=0;C<T;C++){let _=H.clone().addScaledVector(P,e),A=_.clone().addScaledVector(E,n),B=H.clone().addScaledVector(E,n),k=new Y.Vector3().add(H).add(_).add(A).add(B).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=B}if(V>=T/2)break;w+=V,p[1]=p[1].addScaledVector(P,e),p[2]=p[2].addScaledVector(P,e)}I=p[0].distanceTo(p[1]),v=I/e;for(let D=0;D<T;D++){let H=p[3],V=0;for(let C=0;C<v;C++){let _=H.clone().addScaledVector(M,e),A=_.clone().addScaledVector(S,n),B=H.clone().addScaledVector(S,n),k=new Y.Vector3().add(H).add(_).add(A).add(B).multiplyScalar(.25);for(let F=0;F<s.length;F++)if(s[F].distanceTo(k)<R){V++;break}H=_}if(V>=v/2)break;w+=V,p[2]=p[2].addScaledVector(S,n),p[3]=p[3].addScaledVector(S,n)}}let z=p[0].distanceTo(p[1])*p[0].distanceTo(p[3]);return{facePoints:p,boxArea:z,totalInPlaneNum:w}},Zt=(t,e,n,o,r=Y.MathUtils.degToRad(8))=>{let s=new Y.Vector3,i=new Y.Vector3;s.subVectors(new Y.Vector3(e.x,e.y,0),new Y.Vector3(t.x,t.y,0)).normalize(),i.subVectors(new Y.Vector3(o.x,o.y,0),new Y.Vector3(n.x,n.y,0)).normalize();let l=s.dot(i),u=Math.acos(Math.min(Math.abs(l),1)),f=1-Math.min(u/r,1),d=l>0?"same":"opposite";return{parallelism:f,angle:u,angleDeg:Y.MathUtils.radToDeg(u),isParallel:u<r,direction:d,vectors:{v1:s,v2:i}}},ie=(t,e,n,o)=>{let r=new Y.Vector3().subVectors(e,t),s=new Y.Vector3().subVectors(o,n),i=r.length(),l=s.length();if(i===0||l===0)return{rate:NaN,angle:NaN,isPerpendicular:!1,isParallel:!1};r.normalize(),s.normalize();let u=Math.abs(r.dot(s)),f=Math.min(1,Math.max(0,u)),d=Math.acos(f),c=Y.MathUtils.radToDeg(d),a=1-f,h=1e-6;return{rate:a,percent:`${(a*100).toFixed(2)}%`,angle:c,isPerpendicular:Math.abs(c-90)<.01,isParallel:c<.01}},At=(t,e,n=!1)=>new Y.Vector3((t.x+e.x)/2,(t.y+e.y)/2,n?0:(t.z+e.z)/2),we=(t,e,n,o,r={})=>{let{parallelAngleMax:s=Y.MathUtils.degToRad(10),collinearAngleMax:i=Y.MathUtils.degToRad(7),distanceThreshold:l=2,overlapThreshold:u=.01}=r,f=new Y.Vector3().subVectors(e,t),d=new Y.Vector3().subVectors(o,n),c=f.clone().normalize(),a=d.clone().normalize(),h=Y.MathUtils.clamp(c.dot(a),-1,1),g=Math.acos(Math.abs(h)),b=Y.MathUtils.radToDeg(g);if(g>s)return{type:"not_parallel",angleDeg:b,avgPerpendicularDistance:null,maxPerpendicularDistance:null,gap:null,overlap:null,closestDistance:null};h<0&&a.negate();let x=new Y.Vector3().addVectors(c,a).normalize(),m=new Y.Vector3().addVectors(t,e).multiplyScalar(.5),p=pr(n,m,c),y=pr(o,m,c),w=(p+y)/2,z=Math.max(p,y),M=t.dot(x),P=e.dot(x),E=n.dot(x),S=o.dot(x),I=Math.min(M,P),W=Math.max(M,P),v=Math.min(E,S),T=Math.max(E,S),R=W-I,D=T-v,H=Math.min(R,D),V=Math.min(W,T)-Math.max(I,v),C=V<0?-V:0,_=V>0?V:0,A=H>0?_/H:0,B=Oi(t,e,n,o),k=g<=i&&w<l,F;return k?F=A>.5?"collinear_overlap":"collinear_gap":g<=s&&(F="parallel_offset"),{type:F,angleDeg:b,avgPerpendicularDistance:w,maxPerpendicularDistance:z,gap:C,overlap:_,closestDistance:B}};function pr(t,e,n){let o=new Y.Vector3().subVectors(t,e),r=o.dot(n),s=n.clone().multiplyScalar(r);return new Y.Vector3().subVectors(o,s).length()}function Oi(t,e,n,o){let r=new Y.Vector3().subVectors(e,t),s=new Y.Vector3().subVectors(o,n),i=new Y.Vector3().subVectors(n,t),l=r.dot(r),u=r.dot(s),f=s.dot(s),d=r.dot(i),c=s.dot(i),a=l*f-u*u,h,g;a<1e-10?(h=0,g=f!==0?c/f:0):(h=(u*c-f*d)/a,g=(l*c-u*d)/a),h=Y.MathUtils.clamp(h,0,1),g=f!==0?Y.MathUtils.clamp((u*h+c)/f,0,1):0,h=l!==0?Y.MathUtils.clamp((u*g-d)/l,0,1):0;let b=t.clone().add(r.clone().multiplyScalar(h)),x=n.clone().add(s.clone().multiplyScalar(g));return b.distanceTo(x)}var Ve=t=>{let e=999999,n=-999999,o=0;for(let r=0;r<t.length;r++)t[r].z>n&&(n=t[r].z),t[r].z<e&&(e=t[r].z),o+=t[r].z;return o=o/t.length,{minZ:e,maxZ:n,averagePz:o}},wn=(t,e,n)=>{let o=new Y.Plane,r=new Y.Vector3(t.x,t.y,t.z),s=new Y.Vector3(e.x,e.y,e.z),i=new Y.Vector3(e.x,e.y,e.z+5);o.setFromCoplanarPoints(r,s,i);let l=[],u=[];n.forEach(x=>{let m=new Y.Vector3;o.projectPoint(x,m),u.push(m.clone()),m.z=r.z,l.push(m)});let f=new Y.Vector3,d=new Y.Vector3;o.projectPoint(r,f),o.projectPoint(s,d);let c=new Y.Line3(f,d),a=[],h=[],g=[],b=new Y.Vector3;return l.forEach((x,m)=>{c.closestPointToPoint(x,!0,b).distanceTo(x)<.001?(a.push(n[m]),h.push(u[m])):g.push(x)}),{newOriginalPoints:a,newProjectPoints:g,newOnLinePoints:h}},wr=(t,e,n)=>{function o(r,s,i,l,u,f,d,c,a){let h=new Y.Line3(r,s),g=new Map,b=new Y.Vector3,x=r.clone(),m=s.clone(),p=0;for(;;){let y=new Map,w=0;for(let z=0;z<a.checkResults.length;z++)if(!(a.checkResults[z].allCenterPoints.length/c*100<1))for(let P=0;P<a.checkResults[z].allCenterPoints.length;P++){if(g.has(z)&&g.get(z).removePtsIndex.includes(P))continue;let E=a.checkResults[z].allCenterPoints[P];E=new Y.Vector3(E.x,E.y,E.z);let S=h.closestPointToPoint(E,!0,b),I=E.distanceTo(S);Math.abs(I-u)<.01&&(w++,y.has(z)?y.get(z).removePtsIndex.push(P):y.set(z,{index:z,removePtsIndex:[P]}))}if(p==d){r=x,s=m;break}if(w<f/20*19||w==0){y.clear(),d-p<5&&(r=x,s=m,g.clear());break}else{p++;for(let[z,M]of y)g.has(z)?g.get(z).removePtsIndex.push(...M.removePtsIndex):g.set(z,M);y.clear(),r=r.addScaledVector(i,l),s=s.addScaledVector(i,l),h.set(r,s)}}if(g.size>0&&p!=d)for(let[y,w]of g){let z=[],M=[];for(let P=0;P<a.checkResults[y].allCenterPoints.length;P++)w.removePtsIndex.includes(P)||(z.push(a.checkResults[y].allCenterPoints[P]),M.push(a.checkResults[y].originalVertices[P]));a.checkResults[y].allCenterPoints=z,a.checkResults[y].originalVertices=M}}for(let r=0;r<t.length;r++){let s=t[r];if(s.length<.5)continue;let i=-1,l=-1,u=e.readLineById(s.id);u.checkResults=e.getLineCheckReultsById(s.id),u.originalPoints=e.getOriginalPointsById(s.id),s.originalPoints=u.originalPoints,s.checkResults=u.checkResults,s.checkResults.allCenterPoints=[],u=null;for(let D=0;D<s.checkResults.length;D++)for(let H=0;H<s.checkResults[D].originalVertices.length;H++){let V=qn(s.checkResults[D].originalVertices[H]);s.checkResults.allCenterPoints.push(V)}if(!s.checkResults||s.checkResults.length<=0)continue;if(s.checkResults[0].originalVertices&&s.checkResults[0].originalVertices.length>0){let D=s.checkResults[0].originalVertices[0],[H,V,C,_]=D;H=new Y.Vector3(H.x,H.y,H.z),V=new Y.Vector3(V.x,V.y,V.z),C=new Y.Vector3(C.x,C.y,C.z),_=new Y.Vector3(_.x,_.y,_.z),i=H.distanceTo(V),l=H.distanceTo(_);let A=new Y.Vector3().subVectors(H,V).normalize(),B=Xt(A,new Y.Vector3(0,0,1));B&&B.parallel&&([l,i]=[i,l])}if(i<0||l<0)continue;let f=new Y.Vector3(s.start.x,s.start.y,s.start.z),d=new Y.Vector3(s.end.x,s.end.y,s.end.z),c=f.distanceTo(d),a=s.rooftopPz-s.start.z,h=Math.ceil(c/i),g=Math.ceil(a/l),b=f.clone(),x=d.clone(),m=x.clone().add(new Y.Vector3(0,0,a)),p=b.clone().add(new Y.Vector3(0,0,a)),y=new Y.Vector3().subVectors(x,b).normalize(),w=y.clone().negate(),M=new Y.Vector3().subVectors(m,b).normalize().clone().negate(),P=i/2,E=l/2,S=c*a,I=i*l,W=S/I;o(b,p,y,i,P,g,h,W,s),o(x,m,w,i,P,g,h,W,s),s.start=b,s.end=x;let{newOriginalPoints:v}=wn(b,x,s.originalPoints);s.originalPoints=v,n.stageReplaceCheckResults(s.id,s.checkResults);let R=new On().vector3ArrToFloat32Array(s.originalPoints);n.stageReplacePoints(s.id,R),s.checkResults=null,s.originalPoints=null}n.commit()},Gt=(t,e)=>new Y.Vector3(t.x,t.y,0).distanceTo(new Y.Vector3(e.x,e.y,0)),Eo=(t,e,n=1e-6)=>{let o=new Y.Vector3;return t.closestPointToPoint(e,!0,o),o.distanceTo(e)<n},zr=(t,e,n,o=1e-6)=>{let r=new Y.Line3(new Y.Vector3(t.x,t.y,t.z),new Y.Vector3(e.x,e.y,e.z)),s=new Y.Vector3;return r.closestPointToPoint(new Y.Vector3(n.x,n.y,n.z),!0,s),s.distanceTo(new Y.Vector3(n.x,n.y,n.z))<o},We=t=>{let e=0,n=[];for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o].distanceTo(t[r]);s>e&&(e=s,n=[t[o],t[r]])}return n},ct=(t,e,n=.03)=>Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n&&Math.abs(t.z-e.z)<n;var Mr=()=>{let t=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),e=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0"),n=Math.floor(Math.random()*75+180).toString(16).padStart(2,"0");return`#${t}${e}${n}`};var Po=(t,e=.001)=>{let n=new Map,o=[];for(let r of t){let s=Math.round(r.x/e),i=Math.round(r.y/e),l=Math.round(r.z/e),u=`${s},${i},${l}`;n.has(u)||(n.set(u,!0),o.push(r))}return o},Er=t=>{let e=t.center,n=t.halfSize,r=t.rotation.elements,s=new Y.Vector3(r[0],r[1],r[2]).multiplyScalar(n.x),i=new Y.Vector3(r[3],r[4],r[5]).multiplyScalar(n.y),l=new Y.Vector3(r[6],r[7],r[8]).multiplyScalar(n.z);function u(d,c,a){return e.clone().addScaledVector(s,d).addScaledVector(i,c).addScaledVector(l,a)}return[u(-1,-1,-1),u(1,-1,-1),u(1,1,-1),u(-1,1,-1),u(-1,-1,1),u(1,-1,1),u(1,1,1),u(-1,1,1)]},To=(t,e)=>{let n=t[0],o=t[1],r=t[2],s=t[3],i=new Y.Vector3().subVectors(o,n),l=new Y.Vector3().subVectors(s,n),u=i.length(),f=l.length();i.normalize(),l.normalize();let d=new Y.Vector3(0,0,1),a=new Y.Vector3().add(n).add(o).add(r).add(s).multiplyScalar(.25).clone().addScaledVector(d,e/2),h=new Y.BoxGeometry(u,f,e),g=new Y.Matrix4;return g.makeBasis(i,l,d),g.setPosition(a),h.applyMatrix4(g),h.computeVertexNormals(),h},qn=t=>{if(!t||t.length===0)return null;let e=new Y.Vector3(0,0,0);for(let n of t)Array.isArray(n)?(e.x+=n[0],e.y+=n[1],e.z+=n[2]):(e.x+=n.x,e.y+=n.y,e.z+=n.z);return e.divideScalar(t.length),e},Pr=t=>{if(!t||t.length<3)return 0;let e=Array.isArray(t[0]),n=0;for(let o=0;o<t.length;o++){let r=t[o],s=t[(o+1)%t.length];e?n+=r[0]*s[1]-s[0]*r[1]:n+=r.x*s.y-s.x*r.y}return Math.abs(n)/2},Tr=(t,e,n=1e-8)=>{if(t.length<3||e.length<3)return!1;let o=t;t[0].x||(o=t.map(s=>({x:s[0],y:s[1]})));let r=e;e[0].x||(r=e.map(s=>({x:s[0],y:s[1]})));for(let s=0;s<o.length;s++){let i=o[s],l=o[(s+1)%o.length];for(let u=0;u<r.length;u++){let f=r[u],d=r[(u+1)%r.length];if(Fi(i,l,f,d,n))return!0}}return!!(gr(o[0],r,n)||gr(r[0],o,n))};function Fi(t,e,n,o,r=1e-8){let s=Fn(t,e,n),i=Fn(t,e,o),l=Fn(n,o,t),u=Fn(n,o,e);return!!((s>r&&i<-r||s<-r&&i>r)&&(l>r&&u<-r||l<-r&&u>r)||Math.abs(s)<=r&&Nn(t,e,n,r)||Math.abs(i)<=r&&Nn(t,e,o,r)||Math.abs(l)<=r&&Nn(n,o,t,r)||Math.abs(u)<=r&&Nn(n,o,e,r))}function Fn(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)}function Nn(t,e,n,o=1e-8){return n.x>=Math.min(t.x,e.x)-o&&n.x<=Math.max(t.x,e.x)+o&&n.y>=Math.min(t.y,e.y)-o&&n.y<=Math.max(t.y,e.y)+o}function gr(t,e,n=1e-8){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let i=e[r],l=e[s];if(Ni(t,i,l)<=n)return!0;i.y>t.y!=l.y>t.y&&t.x<(l.x-i.x)*(t.y-i.y)/(l.y-i.y)+i.x&&(o=!o)}return o}function Ni(t,e,n){let o=n.x-e.x,r=n.y-e.y,s=o*o+r*r;if(s===0)return Math.hypot(t.x-e.x,t.y-e.y);let i=((t.x-e.x)*o+(t.y-e.y)*r)/s;i=Math.max(0,Math.min(1,i));let l=e.x+i*o,u=e.y+i*r;return Math.hypot(t.x-l,t.y-u)}import*as Yt from"three";var qi=(t,e)=>{console.log("lines",t);for(let n=0;n<t.length;n++){let o=t[n],r=[];o.originalPoints.forEach(y=>{let w=new Yt.Vector3(y.x,y.y,0),z=!1;for(let M=0;M<r.length;M++)if(ct(w,r[M],.01)){z=!0;break}z||r.push(w)});let s=Math.round(Math.max(5,Math.min(350,20*Math.sqrt(o.length)))),i=1,l=new Yt.Vector3(o.start.x,o.start.y,o.start.z),u=new Yt.Vector3(o.end.x,o.end.y,o.end.z),f=new Yt.Vector3().subVectors(u,l).normalize(),d=f.clone().cross(new Yt.Vector3(0,0,1)).normalize(),c=d.clone().negate(),a=[],h=[],g=o.length/s;console.log(g);for(let y=0;y<s;y++){let w=[];w.push(l.clone().addScaledVector(d,i)),w.push(w[0].clone().addScaledVector(f,g)),w.push(w[1].clone().addScaledVector(c,i*2)),w.push(l.clone().addScaledVector(c,g));let z=[];for(let M=0;M<r.length;M++)a.includes(M)||$i(r[M],w)&&(a.push(M),z.push(r[M]));z.length>0&&h.push(Xi(z)),l=l.addScaledVector(f,g)}let b=new Float32Array(r.length*3);r.forEach((y,w)=>{b[w*3]=y.x,b[w*3+1]=y.y,b[w*3+2]=y.z});let x=new Yt.BufferGeometry;x.setAttribute("position",new Yt.BufferAttribute(b,3)),x.rotateX(-Math.PI/2),e.add(new Yt.Points(x,new Yt.PointsMaterial({color:Mr(),size:.02})));let[m,p]=Ui(h,{plane:"xy",trimRatio:0});xr(m,p,e)}};function Sr(t,e="xy"){if(e==="xy")return{x:t.x,y:t.y};if(e==="xz")return{x:t.x,y:t.z};if(e==="yz")return{x:t.y,y:t.z};throw new Error(`Unsupported plane: ${e}`)}function ji(t,e,n){let o=e.x-t.x,r=e.y-t.y,s=n.x-t.x,i=n.y-t.y;return o*i-r*s}function $i(t,e,n="xy"){if(!e||e.length!==4)throw new Error("rectPoints must contain 4 points");let o=Sr(t,n),r=e.map(l=>Sr(l,n)),s=!1,i=!1;for(let l=0;l<4;l++){let u=r[l],f=r[(l+1)%4],d=ji(u,f,o);if(d>1e-9&&(s=!0),d<-1e-9&&(i=!0),s&&i)return!1}return!0}function Xi(t){if(!t||t.length===0)return null;let e=new Yt.Vector3(0,0,0);for(let n of t)Array.isArray(n)?(e.x+=n[0],e.y+=n[1],e.z+=n[2]):(e.x+=n.x,e.y+=n.y,e.z+=n.z);return e.divideScalar(t.length),e}function Zi(t){return t instanceof Yt.Vector3?t.clone():Array.isArray(t)?new Yt.Vector3(t[0],t[1],t[2]):new Yt.Vector3(t.x,t.y,t.z)}function Gi(t,e="xy"){let n=Zi(t);if(e==="xy")return{x:n.x,y:n.y,up:n.z};if(e==="xz")return{x:n.x,y:n.z,up:n.y};if(e==="yz")return{x:n.y,y:n.z,up:n.x};throw new Error(`Unsupported plane: ${e}`)}function Rr(t,e,n,o="xy"){if(o==="xy")return new Yt.Vector3(t,e,n);if(o==="xz")return new Yt.Vector3(t,n,e);if(o==="yz")return new Yt.Vector3(n,t,e);throw new Error(`Unsupported plane: ${o}`)}function Yi(t,e,n){if(Math.abs(e)<1e-12)return t>=n?{x:1,y:0}:{x:0,y:1};let r=t+n,s=t*n-e*e,i=Math.sqrt(Math.max(0,r*r*.25-s)),l=r*.5+i,u=e,f=l-t,d=Math.hypot(u,f);return d<1e-12?{x:1,y:0}:{x:u/d,y:f/d}}function Ui(t,e={}){let{plane:n="xy",trimRatio:o=0}=e;if(!t||t.length<2)return null;let r=t.map(V=>Gi(V,n)),s=0,i=0,l=0;for(let V of r)s+=V.x,i+=V.y,l+=V.up;s/=r.length,i/=r.length,l/=r.length;let u=0,f=0,d=0;for(let V of r){let C=V.x-s,_=V.y-i;u+=C*C,f+=C*_,d+=_*_}u/=r.length,f/=r.length,d/=r.length;let c=Yi(u,f,d),a={x:-c.y,y:c.x},h=[];for(let V of r){let C=V.x-s,_=V.y-i,A=C*c.x+_*c.y,B=C*a.x+_*a.y;h.push({s:A,t:B,up:V.up})}h.sort((V,C)=>V.s-C.s);let g=h.length,b=Math.floor(g*o),x=Math.ceil(g*(1-o))-1;b=Math.max(0,Math.min(g-1,b)),x=Math.max(0,Math.min(g-1,x));let m=h[b],p=h[x],y=(()=>{let V=h.map(_=>_.t).sort((_,A)=>_-A),C=Math.floor(V.length/2);return V.length%2===0?(V[C-1]+V[C])*.5:V[C]})(),w=(()=>{let V=h.map(_=>_.up).sort((_,A)=>_-A),C=Math.floor(V.length/2);return V.length%2===0?(V[C-1]+V[C])*.5:V[C]})(),z=m.s,M=p.s,P=y,E=y,S=w,I=w,W=s+c.x*z+a.x*P,v=i+c.y*z+a.y*P,T=s+c.x*M+a.x*E,R=i+c.y*M+a.y*E,D=Rr(W,v,S,n),H=Rr(T,R,I,n);return[D,H]}var Ki=async(t,e,n,o,r)=>{if(wr(t,o,r),t.length<=0||e.length<=0)return t;n||(n=[]);for(let m of t){let p=[],y=o.readLineById(m.id);if(y.checkResults=o.getLineCheckReultsById(m.id),m.checkResults=y.checkResults,!(!m.checkResults||m.checkResults.length<=0)){for(let w=0;w<m.checkResults.length;w++){let S=function(R){for(;E[R]!==R;)E[R]=E[E[R]],R=E[R];return R},z=m.checkResults[w];if(!z.originalVertices||z.originalVertices.length==0)continue;let M=[];z.originalVertices.forEach(R=>{let D=[];R.forEach(H=>{D.push(new N.Vector3(H.x,H.y,H.z))}),M.push(D)});let P=M.length,E=Array.from({length:P},(R,D)=>D);for(let R=0;R<P;R++)for(let D=R+1;D<P;D++){let H=M[R],V=M[D];if(H.some(_=>V.some(A=>_.equals(A)))){let _=S(R),A=S(D);_!==A&&(E[_]=A)}}let I=new Map,W=-1,v=-1;for(let R=0;R<P;R++){let D=S(R);I.has(D)||I.set(D,{points:[],area:0,index:-1,gridWidth:-1,gridHeight:-1,centerPts:[],facePoints:[],boxArea:-1,totalInPlaneNum:-1});let H=I.get(D),[V,C,_,A]=M[R],B=new N.Vector3().add(V).add(C).add(_).add(A).multiplyScalar(.25);if(H.points.push(...M[R]),H.area+=V.distanceTo(C)*V.distanceTo(A),H.index=w,H.centerPts.push(B),W==-1||v==-1){let k=new N.Vector3().subVectors(V,C).normalize();v=V.distanceTo(A),W=V.distanceTo(C);let F=Xt(k,new N.Vector3(0,0,1));F&&F.parallel&&([v,W]=[W,v])}H.gridWidth=W,H.gridHeight=v}let T=I.values();for(let R of I.values()){let{facePoints:D,boxArea:H,totalInPlaneNum:V}=br(R.points,R.gridWidth,R.gridHeight,R.centerPts);R.centerPts=null,R.facePoints=D,R.boxArea=H,R.totalInPlaneNum=V}p.push(...T)}m.checkResults=null,m.mergeCheckRegion=p}}let s=[];for(let m=0;m<n.length;m++){let p=n[m];if(p.isFindBeam=!1,p.category=="door"){let y=[];p.coordinatesByArea.coordinates.forEach(E=>{y.push(new N.Vector3(E.x,E.y,E.z))}),y[0].equals(y[y.length-1])&&y.pop();let w=y[0].distanceTo(y[1]),z=y[0].distanceTo(y[3]);z>w&&([w,z]=[z,w],y=[y[0],y[3],y[2],y[1]]);let M=At(y[0],y[3],!0),P=At(y[1],y[2],!0);s.push({doorStartPt:M,doorEndPt:P,boxPoints:y,minZ:p.coordinatesByArea.heightData.minZ,maxZ:p.coordinatesByArea.heightData.maxZ,index:m,isFind:!1,inWall:!1})}}for(let m=0;m<s.length;m++){let p=s[m];for(let y=0;y<t.length;y++){if(t[y].length<.5)continue;let w=[],z=At(t[y].start,t[y].end,!0);w.push(z),w.push(At(z,t[y].start,!0)),w.push(At(z,t[y].end,!0));let M=!1,P=p.boxPoints.length;for(let E=0;E<w.length;E++){let S=w[E].x,I=w[E].y;for(let W=0,v=P-1;W<P;v=W++){let T=p.boxPoints[W].x,R=p.boxPoints[W].y,D=p.boxPoints[v].x,H=p.boxPoints[v].y;R>I!=H>I&&S<(D-T)*(I-R)/(H-R)+T&&(M=!M)}if(M)break}if(M){let E=new N.Vector3(t[y].start.x,t[y].start.y,0),S=new N.Vector3(t[y].end.x,t[y].end.y,0),I=p.doorStartPt.distanceTo(p.doorEndPt),W=E.distanceTo(S),v=Zt(p.doorStartPt,p.doorEndPt,E,S);if(Math.abs(W-I)<.5&&v&&v.angleDeg<15){p.doorStartPt=new N.Vector3(t[y].start.x,t[y].start.y,0),p.doorEndPt=new N.Vector3(t[y].end.x,t[y].end.y,0);break}else if(Math.abs(W-I)>1.3&&v&&v.angleDeg<15){let T=we(p.doorStartPt,p.doorEndPt,E,S,{parallelAngleMax:N.MathUtils.degToRad(15)}),R=p.doorStartPt.distanceTo(E),D=p.doorStartPt.distanceTo(S),H=p.doorEndPt.distanceTo(E),V=p.doorEndPt.distanceTo(S),C=R<.2||D<.2||H<.2||V<.2;if(T&&T.type=="collinear_overlap"&&T.maxPerpendicularDistance<.1&&!C){p.inWall=!0;break}else{let _=new N.Line3(E,S),A=_.closestPointToPoint(p.doorStartPt,!0,new N.Vector3),B=_.closestPointToPoint(p.doorEndPt,!0,new N.Vector3),k=A.distanceTo(p.doorStartPt),F=B.distanceTo(p.doorEndPt);if(k<.1||F<.1){p.inWall=!0;break}}}}else continue}}let i=0,l=[],u=[],f=[],d=[],c=.15;for(let m=0;m<t.length;m++){let p=t[m];if(p.noDetection)continue;let y=o.readLineById(p.id);if(y.originalPoints=o.getOriginalPointsById(p.id),y.checkResults=o.getLineCheckReultsById(p.id),p.originalPoints=y.originalPoints,p.checkResults=y.checkResults,y=null,p.doorAndBeamData=[],p.doorAndBeamIdToCheckResults=[],!p.mergeCheckRegion||p.mergeCheckRegion.length==0)continue;p.completePointAreaPercentage=-1;let w=new N.Box3;w.setFromPoints(p.originalPoints);let z=w.max.z,M=w.min.z,P=new N.Vector3(p.start.x,p.start.y,p.start.z),E=new N.Vector3(p.end.x,p.end.y,p.end.z),S=p.rooftopPz-p.start.z,I=0;for(let v of p.mergeCheckRegion){let T=v.facePoints,R=v.boxArea,D=v.totalInPlaneNum;if(!T||T.length<=0)continue;let H=T[0].distanceTo(T[1]),V=T[0].distanceTo(T[3]),C=v.gridHeight*(V/v.gridHeight/3*2)+v.gridHeight/2,_=new N.Vector3(T[0].x,T[0].y,T[0].z+C),A=new N.Vector3(T[1].x,T[1].y,T[1].z+C),B=new N.Line3(_,A),k=[],F=new N.Vector3;v.points.forEach(j=>{B.closestPointToPoint(j,!0,F).distanceTo(j)<v.gridHeight+.01&&k.push(j)});let L=[],O=[];for(;;){let j=[];for(let X=0;X<k.length;X++)O.includes(X)||j.length==0&&(j.push(k[X]),O.push(X));for(let X=0;X<k.length;X++)if(!O.includes(X)){for(let U=0;U<j.length;U++)if(k[X].distanceTo(j[U])<v.gridWidth+.01){j.push(k[X]),O.push(X),X=-1;break}}if(j.length==0)break;L.push(j)}let $=[];for(let j=0;j<L.length;j++){let X={lineSt:new N.Vector3,lineEd:new N.Vector3,facePoints:[]},U=We(L[j]);Array.isArray(U)&&U.length==2&&(X.lineSt=U[0],X.lineEd=U[1],X.facePoints.push(new N.Vector3(U[0].x,U[0].y,T[0].z)),X.facePoints.push(new N.Vector3(U[1].x,U[1].y,T[0].z)),X.facePoints.push(new N.Vector3(U[1].x,U[1].y,T[2].z)),X.facePoints.push(new N.Vector3(U[0].x,U[0].y,T[2].z)),$.push(X))}I+=v.area;let Z=0;if(D!=0&&(Z=v.gridHeight*v.gridWidth*D),(v.area-Z)/R*100>70&&$.length==1||$.length>1)for(let j=0;j<$.length;j++){let X=$[j],U=X.facePoints[0].distanceTo(X.facePoints[1]),lt=X.facePoints[0].distanceTo(X.facePoints[3]),mt=U/p.length*100,St=p.rooftopPz-X.facePoints[2].z;if(lt<1.5||z<X.facePoints[2].z||St>S/3*2)continue;let ot=!1,Mt=!1,bt=!1,Ct=new N.Vector3(0,0,0),Et=new N.Vector3(0,0,0),zt=!1,Pt=[],et=X.facePoints[2].clone(),ht=X.facePoints[3].clone(),nt=X.facePoints[0].clone(),J=X.facePoints[1].clone(),ae=!1,wt=-1;if(Math.abs(X.facePoints[0].z-p.start.z)<.25){let te=!1;for(let at=0;at<e.length;at++){let It=at+1;if(It>=e.length)continue;let Ot=new N.Vector3(e[at].x,e[at].y,e[at].z),Ft=new N.Vector3(e[It].x,e[It].y,e[It].z);if(Pe(new N.Vector3(Ot.x,Ot.y,0),new N.Vector3(Ft.x,Ft.y,0),new N.Vector3(X.facePoints[0].x,X.facePoints[0].y,0),new N.Vector3(X.facePoints[1].x,X.facePoints[1].y,0),.1)!=null){te=!0;break}}let{newOriginalPoints:ge}=wn(nt,J,p.originalPoints),Dt=[],ne=[];if(ge.forEach(at=>{at.z>=et.z?Dt.push(at):at.z<=nt.z&&ne.push(at)}),Dt.length<20)continue;let xe=p.rooftopPz-et.z,tt=et.clone();tt.z+=xe;let mn=et.distanceTo(ht),Je=new N.Vector3().subVectors(ht,et).normalize(),pn=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(mn)))),gn=mn/pn,de=[],tn=[];for(let at=0;at<pn;at++)de.push(new N.Vector3(et.x,et.y,et.z+xe/5).addScaledVector(Je,gn*at)),de.push(new N.Vector3(tt.x,tt.y,tt.z-xe/5).addScaledVector(Je,gn*at));let xn=de.length;for(let at=0;at<Dt.length;at++)for(let It=0;It<de.length;It++)if(new N.Vector3(Dt[at].x,Dt[at].y,Dt[at].z).distanceTo(de[It])<.05){tn.push(de[It]),de.splice(It,1);break}if(tn.length/xn<.5)continue;if(U>.17&&p.length>.5){let at=Gt(P,nt),It=Gt(P,J),Ot=Gt(E,nt),Ft=Gt(E,J),it=.15,G=10;if(at<it||It<it)if(Dt.length>10){let dt=new N.Vector3(p.start.x,p.start.y,0),ut=new N.Vector3(p.end.x,p.end.y,0),xt=new N.Vector3().subVectors(dt,ut).normalize(),vt=new N.Vector3,pt=1/0,Bt=-1,qt=!1,ft=!1;for(let rt=0;rt<t.length;rt++){if(rt==m)continue;let st=new N.Vector3(t[rt].start.x,t[rt].start.y,0),yt=new N.Vector3(t[rt].end.x,t[rt].end.y,0),gt=Pe(dt,ut,st,yt,.1),Rt=ie(dt,ut,st,yt);if(gt!=null){if(Rt&&Rt.angle>85){let Wt=gt.point.distanceTo(dt),Tt=gt.point.distanceTo(ut);if(Wt<.3){ft=!0,pt=1/0,Bt=-1;break}}continue}if(Rt&&Rt.angle>85){let Tt=new N.Line3(st,yt).closestPointToPoint(dt,!0,vt),kt=Zt(dt,ut,Tt,dt);if(!kt||kt.direction!="same")continue;let Ut=dt.clone().addScaledVector(xt,G),se=ut.clone().addScaledVector(xt.clone().negate(),G),$t=new N.Vector3().subVectors(yt,st).normalize(),ee=st.clone().addScaledVector($t.clone().negate(),.03),he=yt.clone().addScaledVector($t,.03),le=Pe(Ut,se,ee,he);if(le==null)continue;let oe=dt.distanceTo(le.point);oe<pt&&(pt=oe,Bt=rt)}else if(Rt&&Rt.angle<5){let Wt=new N.Vector3(nt.x,nt.y,0),Tt=new N.Vector3(J.x,J.y,0),kt=Gt(Wt,st),Ut=Gt(Wt,yt),se=Gt(Tt,st),$t=Gt(Tt,yt),ee=Zt(dt,ut,st,Wt),he=!1,le=o.readLineById(t[rt].id);if(le.checkResults=o.getLineCheckReultsById(t[rt].id),t[rt].checkResults=le.checkResults,le=null,t[rt].checkResults){for(let oe=0;oe<t[rt].checkResults.length;oe++){let yn=[];for(let be=0;be<t[rt].checkResults[oe].originalVertices.length;be++){let De=qn(t[rt].checkResults[oe].originalVertices[be]);De.z=0,yn.push(De)}let ye=We(yn);if(ye.length==2){let be=Gt(Wt,ye[0]),De=Gt(Wt,ye[1]),yo=Gt(Tt,ye[0]),bo=Gt(Tt,ye[1]);if(be<.2||De<.2||yo<.2||bo<.2){he=!0;break}}}t[rt].checkResults=null}if(ee&&ee.direction=="same"&&!he&&(kt<.1||Ut<.1||se<.1||$t<.1)){qt=!0,pt=1/0,Bt=-1;break}}}if(pt!=1/0&&pt<2&&(p.length-U>.2||p.length-U<.02)&&pt<U*2)t[Bt].length>.25&&U+pt>.5&&(ae=!0,at<it?(ht=ht.addScaledVector(xt,pt),nt=nt.addScaledVector(xt,pt)):(et=et.addScaledVector(xt,pt),J=J.addScaledVector(xt,pt)));else{if(!qt&&!ft&&p.length-U>.1)continue;if(!qt&&!ft&&p.length-U<.1&&p.length<1.8)continue}}else continue;if(Ot<it||Ft<it)if(Dt.length>10){let dt=new N.Vector3(p.start.x,p.start.y,0),ut=new N.Vector3(p.end.x,p.end.y,0),xt=new N.Vector3().subVectors(ut,dt).normalize(),vt=new N.Vector3,pt=1/0,Bt=-1,qt=!1,ft=!1;for(let rt=0;rt<t.length;rt++){if(rt==m)continue;let st=new N.Vector3(t[rt].start.x,t[rt].start.y,0),yt=new N.Vector3(t[rt].end.x,t[rt].end.y,0),gt=Pe(dt,ut,st,yt,.03),Rt=ie(dt,ut,st,yt);if(gt!=null){if(Rt&&Rt.angle>85){let Wt=gt.point.distanceTo(dt);if(gt.point.distanceTo(ut)<.3){ft=!0,pt=1/0,Bt=-1;break}}continue}if(Rt&&Rt.angle>85){let Tt=new N.Line3(st,yt).closestPointToPoint(ut,!0,vt),kt=Zt(ut,dt,Tt,ut);if(!kt||kt.direction!="same")continue;let Ut=dt.clone().addScaledVector(xt.clone().negate(),G),se=ut.clone().addScaledVector(xt,G),$t=new N.Vector3().subVectors(yt,st).normalize(),ee=st.clone().addScaledVector($t.clone().negate(),.03),he=yt.clone().addScaledVector($t,.03),le=Pe(Ut,se,ee,he);if(le==null)continue;let oe=ut.distanceTo(le.point);oe<pt&&(pt=oe,Bt=rt)}else if(Rt&&Rt.angle<5){let Wt=new N.Vector3(nt.x,nt.y,0),Tt=new N.Vector3(J.x,J.y,0),kt=Gt(Wt,st),Ut=Gt(Wt,yt),se=Gt(Tt,st),$t=Gt(Tt,yt),ee=Zt(ut,dt,st,Wt),he=!1,le=o.readLineById(t[rt].id);if(le.checkResults=o.getLineCheckReultsById(t[rt].id),t[rt].checkResults=le.checkResults,le=null,t[rt].checkResults){for(let oe=0;oe<t[rt].checkResults.length;oe++){let yn=[];for(let be=0;be<t[rt].checkResults[oe].originalVertices.length;be++){let De=qn(t[rt].checkResults[oe].originalVertices[be]);De.z=0,yn.push(De)}let ye=We(yn);if(ye.length==2){let be=Gt(Wt,ye[0]),De=Gt(Wt,ye[1]),yo=Gt(Tt,ye[0]),bo=Gt(Tt,ye[1]);if(be<.2||De<.2||yo<.2||bo<.2){he=!0;break}}}t[rt].checkResults=null}if(ee&&ee.direction=="same"&&!he&&(kt<.1||Ut<.1||se<.1||$t<.1)){qt=!0,pt=1/0,Bt=-1;break}}}if(pt!=1/0&&pt<2&&(p.length-U>.2||p.length-U<.02)&&pt<U*2)t[Bt].length>.25&&U+pt>.5&&(ae=!0,Ot<it?(ht=ht.addScaledVector(xt,pt),nt=nt.addScaledVector(xt,pt)):(et=et.addScaledVector(xt,pt),J=J.addScaledVector(xt,pt)));else{if(!qt&&!ft&&p.length-U>.1)continue;if(!qt&&!ft&&p.length-U<.1&&p.length<1.8)continue}}else continue;U=ht.distanceTo(et)}if(mt<85&&U>.3||U>.7&&lt>S-S/2){if(!p.isLine2){if(U<3.5)for(let at=0;at<s.length;at++){let It=new N.Vector3(s[at].doorStartPt.x,s[at].doorStartPt.y,0),Ot=new N.Vector3(s[at].doorEndPt.x,s[at].doorEndPt.y,0),Ft=new N.Vector3(X.facePoints[0].x,X.facePoints[0].y,0),it=new N.Vector3(X.facePoints[1].x,X.facePoints[1].y,0),G=X.facePoints[2].z<s[at].maxZ||Math.abs(X.facePoints[2].z-s[at].maxZ)<.3,dt=Math.abs(X.facePoints[2].z-s[at].maxZ)>.2;if(G){let ut=we(It.clone(),Ot.clone(),Ft.clone(),it.clone(),{distanceThreshold:2});if(ut&&ut.type=="collinear_gap"){let xt=At(It,Ot),vt=new N.Line3(new N.Vector3(p.start.x,p.start.y,0),new N.Vector3(p.end.x,p.end.y,0)),pt=new N.Vector3,Bt=vt.closestPointToPoint(xt,!0,pt);if(xt.distanceTo(Bt)<.15){let ft=Ft.distanceTo(It),rt=it.distanceTo(It);if(ft>.25&&rt>.25){let gt=Ft.distanceTo(Ot),Rt=it.distanceTo(Ot);if(gt>.2&&Rt>.2)continue}Mt=!0,zt=!0,Pt.push(s[at].index),s[at].isFind=!0,wt=at,bt=n[s[at].index].isFindBeam,n[s[at].index].isFindBeam=!0;let st=new N.Vector3().subVectors(Ft,it).normalize(),yt=It.distanceTo(Ot)-ut.overlap;rt<ft&&st.negate(),ft>rt?(et=X.facePoints[2].clone().addScaledVector(st,yt),ht=X.facePoints[3].clone(),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z):(et=X.facePoints[2].clone(),ht=X.facePoints[3].clone().addScaledVector(st,yt),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z)}}else if(ut&&ut.type=="collinear_overlap"&&ut.maxPerpendicularDistance<.35){let xt=Ft.distanceTo(it),vt=Ot.distanceTo(It);if(Math.abs(xt-ut.overlap)<.25||Math.abs(vt-ut.overlap)<.25){if(vt>xt&&Math.abs(vt-ut.overlap)>1){let pt=Ft.distanceTo(It),Bt=Ft.distanceTo(Ot),qt=it.distanceTo(It),ft=it.distanceTo(Ot),rt=pt<Bt?pt:Bt,st=qt<ft?qt:ft,yt=new N.Vector3().subVectors(Ft,it).normalize(),gt=vt-ut.overlap;rt<st?(yt.negate(),et=X.facePoints[2].clone().addScaledVector(yt,gt),ht=X.facePoints[3].clone(),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z):(et=X.facePoints[2].clone(),ht=X.facePoints[3].clone().addScaledVector(yt,gt),nt=ht.clone(),J=et.clone(),nt.z=J.z=X.facePoints[0].z)}U>1.5&&(Mt=!0,zt=!0,Pt.push(s[at].index),s[at].isFind=!0,bt=n[s[at].index].isFindBeam,n[s[at].index].isFindBeam=!0,wt=at)}}}}if(!zt&&U<1.5)for(let at=0;at<s.length;at++){if(s[at].inWall)continue;let It=new N.Vector3(s[at].doorStartPt.x,s[at].doorStartPt.y,0),Ot=new N.Vector3(s[at].doorEndPt.x,s[at].doorEndPt.y,0),Ft=new N.Vector3(ht.x,ht.y,0),it=new N.Vector3(et.x,et.y,0),G=new N.Vector3().subVectors(It,Ot).normalize(),dt=new N.Vector3().subVectors(Ft,it).normalize(),ut=.25,xt=It.clone().addScaledVector(G,ut),vt=Ot.clone().addScaledVector(G.clone().negate(),ut),pt=Ft.clone().addScaledVector(dt,ut),Bt=it.clone().addScaledVector(dt.clone().negate(),ut);if(Zt(xt,vt,pt,Bt).isParallel)continue;let ft=Pe(xt,vt,pt,Bt),rt=!0,st=It.distanceTo(Ft),yt=It.distanceTo(it),gt=Ot.distanceTo(Ft),Rt=Ot.distanceTo(it);if((st<c||yt<c||gt<c||Rt<c||ft)&&rt){let Tt=new N.Line3(Ft,it);if(st<c||gt<c)if(Ct=Ft.clone(),st<c){let kt=Tt.closestPointToPoint(Ot,!1,new N.Vector3);Et=new N.Vector3().subVectors(Ot,kt).normalize()}else{let kt=Tt.closestPointToPoint(It,!1,new N.Vector3);Et=new N.Vector3().subVectors(It,kt).normalize()}else if(yt<c||Rt<c)if(Ct=it.clone(),yt<c){let kt=Tt.closestPointToPoint(Ot,!1,new N.Vector3);Et=new N.Vector3().subVectors(Ot,kt).normalize()}else{let kt=Tt.closestPointToPoint(It,!1,new N.Vector3);Et=new N.Vector3().subVectors(It,kt).normalize()}else if(ft){let kt=ft.point.distanceTo(Ft),Ut=ft.point.distanceTo(it),se=ft.point.distanceTo(xt),$t=ft.point.distanceTo(vt);if(kt<Ut?Ct=Ft.clone():Ct=it.clone(),se<$t){let ee=Tt.closestPointToPoint(vt,!1,new N.Vector3);Et=new N.Vector3().subVectors(vt,ee).normalize()}else{let ee=Tt.closestPointToPoint(xt,!1,new N.Vector3);Et=new N.Vector3().subVectors(xt,ee).normalize()}}bt=n[s[at].index].isFindBeam,n[s[at].index].isFindBeam=!0,Mt=!0,s[at].isFind=!0,wt=at}}}(Mt||te||Math.abs(lt-S)>.1&&lt>S/3&&U>.3)&&(ot=!0)}}if(ot){{let it=new N.Vector3().subVectors(nt,J),G=new N.Vector3().subVectors(J,nt),dt=1/0,ut=1/0,xt=nt.clone(),vt=J.clone(),pt=[],Bt=[],qt=new N.Line3(et,ht),ft=new N.Vector3,rt=999999;if(p.originalPoints.forEach(st=>{if(st.z-nt.z<lt/2+.1&&st.z-nt.z>lt/2-.1&&pt.push(st),st.z>et.z){let yt=qt.closestPointToPoint(st,!0,ft),gt=new N.Vector3().subVectors(yt,et),Rt=new N.Vector3().subVectors(yt,ht),Wt=Xt(it,Rt),Tt=Xt(G,gt);Wt&&Wt.parallel&&!Wt.sameDirection&&Tt&&Tt.parallel&&!Tt.sameDirection&&Bt.push(st)}}),pt.length>0){let{newProjectPoints:st}=wn(nt,J,pt);for(let yt of st)yt.z=nt.z;st.forEach(yt=>{let gt=new N.Vector3(yt.x,yt.y,nt.z),Rt=new N.Vector3().subVectors(gt,J),Wt=new N.Vector3().subVectors(gt,nt),Tt=Xt(it,Wt),kt=Xt(G,Rt);if(Tt&&Tt.parallel&&Tt.sameDirection){let Ut=gt.distanceTo(nt);Ut<dt&&(dt=Ut,xt=gt)}else if(kt&&kt.parallel&&kt.sameDirection){let Ut=gt.distanceTo(J);Ut<ut&&(ut=Ut,vt=gt)}})}if(xt.equals(nt)||(nt=xt,ht=new N.Vector3(nt.x,nt.y,ht.z)),vt.equals(J)||(J=vt,et=new N.Vector3(J.x,J.y,et.z)),Bt.length>10){let{newOnLinePoints:st}=wn(ht,et,Bt);for(let yt=0;yt<st.length;yt++){let Rt=qt.closestPointToPoint(st[yt],!0,ft).distanceTo(st[yt]);Rt>.02&&rt>Rt&&(rt=Rt)}et.z+=rt,ht.z+=rt,lt+=rt}}let te=!1;for(let it=0;it<f.length;it++){let G=we(f[it].start,f[it].end,nt,J);G&&G.type=="collinear_overlap"&&G.maxPerpendicularDistance<.07&&(te=!0)}if(te){wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1));continue}let ge=J.distanceTo(nt);if(ge<.4&&!Mt||ge<.3&&Mt)continue;u.includes(m)||u.push(m);let Dt="",ne=Mt?"singleDoor":"";ne=zt?"pullOutDoor":ne;let xe=nt.z-p.start.z>1e-4?nt.z-p.start.z:0,tt={id:i,beamStart:et,beamEnd:ht,beamHeight:p.rooftopPz-et.z,doorStart:nt,doorEnd:J,doorHeight:lt,nearId:-1,type:Dt,isExtend:ae,isDoor:Mt,isPullOutDoor:zt,pcbDoorIndexs:Pt,beamNearWallVec:new N.Vector3(0,0,0),doorType:ne,doorOpenEndPoint:Ct,doorOpenVector:Et,lineIsOnlyBeam:!1,groundClearance:xe};if(tt.beamHeight<.1)continue;let mn=1/0,Je=!1,pn=new N.Vector3,gn=new N.Vector3,de=-1,tn=-1,xn=-1,en=!1,at=!1;{let it=new N.Line3(nt.clone(),J.clone()),G=-1;for(let dt=0;dt<t.length;dt++){if(t[dt].length<.5||dt==m)continue;let ut=new N.Vector3(t[dt].start.x,t[dt].start.y,t[dt].start.z),xt=new N.Vector3(t[dt].end.x,t[dt].end.y,t[dt].end.z),vt=we(ut,xt,nt,J),pt=Zt(ut,xt,nt,J);if(vt&&vt.maxPerpendicularDistance<.5){if(pt&&pt.isParallel){let gt=new N.Line3(ut,xt),Rt=new N.Vector3(nt.x,nt.y,ut.z),Wt=gt.closestPointToPoint(Rt,!0,new N.Vector3),Tt=ie(Wt,Rt,nt,J);Tt&&Tt.angle>85&&(tt.beamNearWallVec=new N.Vector3().subVectors(Wt,Rt).normalize(),tt.beamStart.z>t[dt].rooftopPz-.03&&U>1?at=!0:at=!1)}let Bt=[],qt=o.readLineById(t[dt].id);qt.originalPoints=o.getOriginalPointsById(t[dt].id),t[dt].originalPoints=qt.originalPoints,qt=null,t[dt].originalPoints.forEach(gt=>{gt.z>nt.z+.2&&gt.z<nt.z+lt/2&&Bt.push(new N.Vector3(gt.x,gt.y,nt.z))}),t[dt].originalPoints=null;let ft=new N.Vector3,rt=[],st=[];for(let gt=0;gt<Bt.length;gt++){let Rt=it.closestPointToPoint(Bt[gt],!0,ft);Rt.distanceTo(Bt[gt])<.15&&(rt.push(Bt[gt]),st.push(Rt.clone()))}for(let gt=0;gt<st.length;gt++)Eo(it,st[gt])&&rt.push(st[gt]);if(rt=st,rt=Po(rt),rt.length<150)continue;let yt=We(rt);if(yt.length==2){let gt=yt[0].distanceTo(yt[1]);if(Math.abs(gt-it.distance())<.3){G=vt.maxPerpendicularDistance;let Rt=new N.Line3(ut,xt),Wt=new N.Vector3(nt.x,nt.y,ut.z),Tt=Rt.closestPointToPoint(Wt,!0,new N.Vector3);if(tt.beamNearWallVec=new N.Vector3().subVectors(Tt,Wt).normalize(),tt.beamStart.z>t[dt].rooftopPz-.03&&U>.8)at=!0,en=!0;else if(te=!0,wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1)),tn!=-1&&xn!=-1){let kt=t[tn].doorAndBeamData[xn];kt.nearId=-1}break}}if(te)break}else vt&&vt.type=="collinear_overlap"&&vt.maxPerpendicularDistance>.3&&vt.maxPerpendicularDistance<.7&&(en=!0)}if(te){if(U<1.5||G<.08)continue;en=!0}}let It=!1;if(de!=-1)for(let it=0;it<d.length&&!(d[it].length==1&&(d[it][0].id==i?(d[it].push({id:de,beamStart:pn,beamEnd:gn}),It=!0):d[it][0].id==de&&(d[it].push({id:i,beamStart:et,beamEnd:ht}),It=!0),It));it++);It||d.push([{id:i,beamStart:et,beamEnd:ht}]);let Ot=tt.doorStart.distanceTo(tt.doorEnd),Ft=Ve(p.originalPoints);if(tt.lineIsOnlyBeam=Ft.minZ>p.start.z&&Ft.minZ-p.start.z>1,Mt&&en){wt!=-1&&(bt||(n[s[wt].index].isFindBeam=!1,s[wt].isFind=!1));continue}if(Mt?Dt="door":Ot>1.5||ae?Dt="beam":Dt=en&&Ot>.8?"beam":"hole",Dt!="beam"&&t[m].isLine2)continue;tt.type=Dt,tt.wallBelowBeam=at;for(let it=0;it<l.length;it++){let G=t[l[it].linesIndex].doorAndBeamData[l[it].doorIndex];if(G.nearId!=-1||tt.type=="beam"&&G.type!="beam"||tt.type!="beam"&&G.type=="beam")continue;let dt=Zt(et.clone(),ht.clone(),G.beamStart.clone(),G.beamEnd.clone());if(dt&&dt.isParallel){let ut=et.distanceTo(ht),xt=G.beamStart.distanceTo(G.beamEnd),vt=new N.Line3(et.clone(),ht.clone());vt.start.z=0,vt.end.z=0;let pt=At(G.beamStart,G.beamEnd,!0);xt>ut&&(vt.start=new N.Vector3(G.beamStart.x,G.beamStart.y,0),vt.end=new N.Vector3(G.beamEnd.x,G.beamEnd.y,0),pt=At(et,ht,!0));let Bt=new N.Vector3,qt=vt.closestPointToPoint(pt,!0,Bt),ft=qt.distanceTo(pt),rt=new N.Vector3().subVectors(pt,qt).normalize(),st=rt.clone().negate(),yt=pt.clone().addScaledVector(st,ft+.1),gt=Pe(vt.start,vt.end,pt,yt),Rt=!Mt&&!G.isDoor&&(ut>xt*2||xt>ut*2);if(ft<.4&&gt!=null&&!Rt){let Wt=!1;for(let $t=0;$t<p.doorAndBeamData.length;$t++)if(p.doorAndBeamData[$t].id==G.id){Wt=!0;break}if(Wt)continue;G.nearId=i,tt.nearId=G.id;let Tt=.8;(G.isDoor||tt.isDoor)&&(G.isDoor=!0,tt.isDoor=!0),G.doorType!=""?tt.doorType=G.doorType:tt.doorType!=""&&(G.doorType=tt.doorType),G.isPullOutDoor?tt.isPullOutDoor=!0:tt.isPullOutDoor&&(G.isPullOutDoor=!0);let kt=Pt.some($t=>G.pcbDoorIndexs.includes($t)),Ut=!1,se=!1;if(tt.type=="beam"&&G.type=="beam"){let $t=o.readLineById(t[l[it].linesIndex].id);$t.originalPoints=o.getOriginalPointsById(t[l[it].linesIndex].id),t[l[it].linesIndex].originalPoints=$t.originalPoints,$t=null;let ee=Ve(t[l[it].linesIndex].originalPoints),he=Ve(p.originalPoints);t[l[it].linesIndex].originalPoints=null,ee.minZ>t[l[it].linesIndex].start.z&&ee.minZ-t[l[it].linesIndex].start.z>1&&he.minZ>p.start.z&&he.minZ-p.start.z>1&&(Ut=ut>xt,se=ut<xt,xt>ut&&(tt.isExtend=!0),ut>xt&&(t[l[it].linesIndex].isExtend=!0))}ut<xt&&!se||Ut?(Ut&&(st=st.negate(),rt=rt.negate()),ut>Tt&&!G.isPullOutDoor?(G.beamStart=et.clone().addScaledVector(st,ft),G.beamEnd=ht.clone().addScaledVector(st,ft),G.doorStart=nt.clone().addScaledVector(st,ft),G.doorEnd=J.clone().addScaledVector(st,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone()):!zt||zt&&G.isPullOutDoor&&kt?(tt.beamStart=G.beamStart.clone().addScaledVector(rt,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(rt,ft),tt.doorStart=G.doorStart.clone().addScaledVector(rt,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(rt,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone()):(G.beamStart=et.clone().addScaledVector(st,ft),G.beamEnd=ht.clone().addScaledVector(st,ft),G.doorStart=nt.clone().addScaledVector(st,ft),G.doorEnd=J.clone().addScaledVector(st,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone())):(ut>xt&&!Ut||se)&&(se&&(st=st.negate(),rt=rt.negate()),xt>Tt&&!zt?(tt.beamStart=G.beamStart.clone().addScaledVector(st,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(st,ft),tt.doorStart=G.doorStart.clone().addScaledVector(st,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(st,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone()):!G.isPullOutDoor||zt&&G.isPullOutDoor&&kt?(G.beamStart=et.clone().addScaledVector(rt,ft),G.beamEnd=ht.clone().addScaledVector(rt,ft),G.doorStart=nt.clone().addScaledVector(rt,ft),G.doorEnd=J.clone().addScaledVector(rt,ft),G.doorHeight=tt.doorHeight,G.beamStart.z=G.beamEnd.z=G.doorStart.z+G.doorHeight,G.doorOpenEndPoint=tt.doorOpenEndPoint.clone(),G.doorOpenVector=tt.doorOpenVector.clone()):(tt.beamStart=G.beamStart.clone().addScaledVector(st,ft),tt.beamEnd=G.beamEnd.clone().addScaledVector(st,ft),tt.doorStart=G.doorStart.clone().addScaledVector(st,ft),tt.doorEnd=G.doorEnd.clone().addScaledVector(st,ft),tt.doorHeight=G.doorHeight,tt.beamStart.z=tt.beamEnd.z=tt.doorStart.z+tt.doorHeight,tt.doorOpenEndPoint=G.doorOpenEndPoint.clone(),tt.doorOpenVector=G.doorOpenVector.clone())),de=tt.nearId,pn=G.beamStart.clone(),gn=G.beamEnd.clone(),Je=!0,tn=l[it].linesIndex,xn=l[it].doorIndex;break}}}if(tt.nearId!=-1&&Dt=="hole"){let it=!1;for(let G=0;G<t.length;G++)if(t[G].doorAndBeamData){for(let dt=0;dt<t[G].doorAndBeamData.length;dt++)if(t[G].doorAndBeamData[dt].nearId==i&&t[G].doorAndBeamData[dt].type=="beam"){t[G].doorAndBeamData[dt].type=Dt,it=!0;break}if(it)break}}if(p.doorAndBeamIdToCheckResults.push([v.index,i]),p.doorAndBeamData.push(tt),l.push({linesIndex:m,doorIndex:p.doorAndBeamData.length-1}),f.push({start:nt,end:J}),i++,zt&&U<2)break}}}let W=p.length*(p.rooftopPz-p.start.z);p.completePointAreaPercentage=I/W*100,p.checkResults=null,p.originalPoints=null,p.mergeCheckRegion=null}if(u.length>1)for(let m=0;m<u.length;m++){let p=[];for(let y=0;y<t[u[m]].doorAndBeamData.length;y++){let w=!1;if(t[u[m]].doorAndBeamData[y].type==="beam"&&(t[u[m]].doorAndBeamData[y].beamNearWallVec.x==0&&t[u[m]].doorAndBeamData[y].beamNearWallVec.y==0&&t[u[m]].doorAndBeamData[y].beamNearWallVec.z==0&&t[u[m]].doorAndBeamData[y].nearId==-1||!t[u[m]].doorAndBeamData[y].wallBelowBeam&&t[u[m]].doorAndBeamData[y].nearId==-1)&&(t[u[m]].doorAndBeamData[y].lineIsOnlyBeam?w=!0:t[u[m]].doorAndBeamData[y].type="hole"),!w){let z=t[u[m]].doorAndBeamData[y].doorStart.clone(),M=t[u[m]].doorAndBeamData[y].doorEnd.clone();z.z=M.z=0;let P=z.distanceTo(M);for(let E=0;E<u.length;E++)if(m!=E)for(let S=0;S<t[u[E]].doorAndBeamData.length;S++){let I=t[u[E]].doorAndBeamData[S].doorStart.clone(),W=t[u[E]].doorAndBeamData[S].doorEnd.clone();I.z=W.z=0;let v=I.distanceTo(W),T=we(z,M,I,W);if(T.type=="collinear_overlap"&&T.maxPerpendicularDistance<.2){let R=new N.Line3(I,W),D=At(z,M),H=R.closestPointToPoint(D,!0,new N.Vector3),V=D.distanceTo(H);if(Math.abs(P-T.overlap)<.1&&V<.04){t[u[E]].doorAndBeamData[S].nearId==t[u[m]].doorAndBeamData[y].id&&(t[u[E]].doorAndBeamData[S].nearId=-1),w=!0;break}}}}if(w){for(let z=0;z<t[u[m]].doorAndBeamIdToCheckResults.length;z++)if(t[u[m]].doorAndBeamIdToCheckResults[1]==t[u[m]].doorAndBeamData[y].id){t[u[m]].doorAndBeamIdToCheckResults.splice(z,1);break}}w||p.push(t[u[m]].doorAndBeamData[y])}p.length!=t[u[m]].doorAndBeamData.length&&(t[u[m]].doorAndBeamData=p)}let a=.65,h=2,g=[],b=[];for(let m=0;m<s.length;m++){if(s[m].isFind||s[m].inWall)continue;let p=new N.Vector3(s[m].doorStartPt.x,s[m].doorStartPt.y,0),y=new N.Vector3(s[m].doorEndPt.x,s[m].doorEndPt.y,0),w=new N.Vector3().subVectors(p,y).normalize();for(let z=0;z<t.length;z++){if(t[z].length<.7||t[z].completePointAreaPercentage>60)continue;let M=new N.Vector3(t[z].start.x,t[z].start.y,0),P=new N.Vector3(t[z].end.x,t[z].end.y,0),E=new N.Vector3().subVectors(M,P).normalize(),S=.3,I=p.clone().addScaledVector(w,S),W=y.clone().addScaledVector(w.clone().negate(),S),v=M.clone().addScaledVector(E,S),T=P.clone().addScaledVector(E.clone().negate(),S),R=Pe(I,W,v,T),D=Zt(I,W,v,T),H=p.distanceTo(M)>y.distanceTo(M)?y:p,V=H.distanceTo(M),C=H.distanceTo(P);if((V<c||C<c)&&D&&!D.isParallel){let A=p.distanceTo(M),B=p.distanceTo(P),k=A<B?M:P,F=!1;for(let L=0;L<t.length;L++){if(L==z||g.includes(L)||t[L].length<.7)continue;let O=new N.Vector3(t[L].start.x,t[L].start.y,0),$=new N.Vector3(t[L].end.x,t[L].end.y,0),Z=new N.Vector3().subVectors(O,$).normalize(),Q=Z.clone().negate(),j=O.clone().addScaledVector(Z,5),X=$.clone().addScaledVector(Q,5),U=ie(M,P,O,$),lt=we(M,P,O,$),mt=Pe(M,P,j,X),St=!0;if(mt!=null&&(St=mt.point.distanceTo(M)<c||mt.point.distanceTo(P)<c),(U&&U.angle>85||lt&&lt.type=="collinear_gap")&&St){let ot=new N.Line3(M,P),Mt=new N.Vector3,bt=ot.closestPointToPoint(O,!0,Mt),Ct=ot.closestPointToPoint($,!0,Mt),Et=bt.distanceTo(O),zt=Ct.distanceTo($),Pt,et;if(Et>zt&&zt>a)Pt=$,et=Ct;else if(Et<zt&&Et>a)Pt=O,et=bt;else continue;if(Et=k.distanceTo(O),zt=k.distanceTo($),Et>h&&zt>h)continue;let ht=Zt(Pt,et,O,$),nt=Zt(Pt,et,I,W);if(nt&&nt.isParallel||!ht||!ht.isParallel)continue;let J=we(p,y,Pt,et);if(J&&J.type=="collinear_overlap"&&J.maxPerpendicularDistance<.2)continue;Pt.z=et.z=t[L].start.z;let ae=!1;for(let Dt=0;Dt<b.length;Dt++){let ne=we(b[Dt].start,b[Dt].end,Pt,et);if(ne&&ne.type=="collinear_overlap"&&ne.maxPerpendicularDistance<.2){ae=!0;break}}if(ae)continue;for(let Dt=0;Dt<t.length;Dt++){if(t[Dt].length<.5)continue;let ne=new N.Vector3(t[Dt].start.x,t[Dt].start.y,t[Dt].start.z),xe=new N.Vector3(t[Dt].end.x,t[Dt].end.y,t[Dt].end.z),tt=we(ne,xe,Pt,et);if(tt&&tt.type=="collinear_overlap"&&tt.maxPerpendicularDistance<.1){ae=!0;break}}if(ae)continue;b.push({start:Pt,end:et}),g.push(L);let wt=t[L].rooftopPz-t[L].start.z,te=t[z].rooftopPz-t[z].start.z,ge=wt<te?wt:te;t[L].doorAndBeamData||(t[L].doorAndBeamData=[]),t[L].doorAndBeamData.push({id:i,beamStart:Pt,beamEnd:et,beamHeight:ge,doorStart:Pt,doorEnd:et,doorHeight:ge,nearId:-1,type:"onlyDoor",isDoor:!0,beamNearWallVec:new N.Vector3(0,0,0),groundClearance:0}),n[s[m].index].isFindBeam=!0,n[s[m].index].isFindOnlyDoor=!0,d.push([{id:i,beamStart:Pt,beamEnd:et}]),i++,F=!0;break}}if(F)break}}}let x=[];for(let m=0;m<t.length;m++)t[m].isLine2||x.push(t[m]),t[m].isLine2&&t[m].doorAndBeamData.length!=0&&x.push(t[m]);return t.length=0,t.push(...x),{lines:t,beamGroup:d,pcdData:n}},Qi=async(t,e)=>{for(let n=0;n<t.length;n++){let o=t[n],r=new N.Vector3(o.start.x,o.start.y,o.start.z),s=new N.Vector3(o.end.x,o.end.y,o.end.z),i=new N.Line3(r.clone(),s.clone()),l=-1;for(let u=0;u<o.doorAndBeamData.length;u++){let f=o.doorAndBeamData[u],d=f.doorHeight;f.isRebuild=!1;let c=!1,a=!1;if(!(f.nearId!=-1||f.type!="beam")){for(let h=0;h<t.length;h++){if(t[h].length<.5||h==n)continue;let g=new N.Vector3(t[h].start.x,t[h].start.y,t[h].start.z),b=new N.Vector3(t[h].end.x,t[h].end.y,t[h].end.z),x=we(g,b,r,s),m=Zt(g,b,r,s);if(x&&x.maxPerpendicularDistance<.5){if(m&&m.isParallel){let E=new N.Line3(g,b),S=new N.Vector3(r.x,r.y,g.z),I=E.closestPointToPoint(S,!0,new N.Vector3),W=ie(I,S,r,s);W&&W.angle>85&&(f.beamNearWallVec=new N.Vector3().subVectors(I,S).normalize())}let p=[],y=e.readLineById(t[h].id);y.originalPoints=e.getOriginalPointsById(t[h].id),t[h].originalPoints=y.originalPoints,y=null,t[h].originalPoints.forEach(E=>{E.z>r.z+.2&&E.z<r.z+d/2&&p.push(new N.Vector3(E.x,E.y,r.z))}),t[h].originalPoints=null;let w=new N.Vector3,z=[],M=[];for(let E=0;E<p.length;E++){let S=i.closestPointToPoint(p[E],!0,w);S.distanceTo(p[E])<.15&&(z.push(p[E]),M.push(S.clone()))}for(let E=0;E<M.length;E++)Eo(i,M[E])&&z.push(M[E]);if(z=M,z=Po(z),z.length<150)continue;let P=We(z);if(P.length==2){let E=P[0].distanceTo(P[1]);if(Math.abs(E-i.distance())<.3){l=x.maxPerpendicularDistance;let S=new N.Line3(g,b),I=new N.Vector3(r.x,r.y,g.z),W=S.closestPointToPoint(I,!0,new N.Vector3);f.beamNearWallVec=new N.Vector3().subVectors(W,I).normalize(),f.beamStart.z>t[h].rooftopPz-.03&&length>1?a=!0:c=!0;break}}if(c)break}else x&&x.type=="collinear_overlap"&&x.maxPerpendicularDistance>.3&&x.maxPerpendicularDistance<.7&&(a=!0)}if(c){if(length<1.8||l<.2)continue;a=!0}a||(f.isRebuild=!0)}}}};import*as Lt from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";var Dr=(t,e={})=>{let n=e.eps??1e-6,o=e.project??(m=>({x:m.x,y:m.z})),r=e.skipSplit??!1,s=e.insideAreaSign??"positive",i=r?t.map((m,p)=>({start:jn(m.start),end:jn(m.end),uuid:m.uuid,sourceIndex:p,sourceSegment:m})):Ji(t,o,n),l=[],u=new Map;function f(m){let p=Math.round(m.x/n),y=Math.round(m.y/n);return`${p},${y}`}function d(m){let p=f(m);if(u.has(p))return u.get(p);let y=l.length;return l.push({id:y,x:m.x,y:m.y}),u.set(p,y),y}let c=[],a=new Map;for(let m of i){let p=o(m.start),y=o(m.end);if(vr(p,y)<n*n)continue;let w=d(p),z=d(y);if(w===z)continue;let M=w<z?`${w}_${z}`:`${z}_${w}`;if(a.has(M))continue;let P=c.length;c.push({id:P,a:w,b:z,uuid:m.uuid,sourceIndex:m.sourceIndex,sourceSegment:m.sourceSegment||m}),a.set(M,P)}let h=[],g=Array.from({length:l.length},()=>[]);function b(m,p,y,w,z){let M=l[m],P=l[p],E=h.length,S=Math.atan2(P.y-M.y,P.x-M.x),I={id:E,from:m,to:p,twin:null,next:null,angle:S,edgeId:y,uuid:w,sourceIndex:z,visited:!1};return h.push(I),g[m].push(E),E}for(let m of c){let p=b(m.a,m.b,m.id,m.uuid,m.sourceIndex),y=b(m.b,m.a,m.id,m.uuid,m.sourceIndex);h[p].twin=y,h[y].twin=p}for(let m of g)m.sort((p,y)=>h[p].angle-h[y].angle);for(let m of h){let p=g[m.to],y=m.twin,w=p.indexOf(y);if(w===-1)continue;let z=(w-1+p.length)%p.length;m.next=p[z]}let x=[];for(let m of h){if(m.visited)continue;let p=[],y=[],w=m.id,z=0,M=h.length+10;for(;;){let v=h[w];if(!v||v.visited)break;if(v.visited=!0,p.push(w),y.push(v.from),w=v.next,z++,z>M){console.warn("\u534A\u8FB9\u904D\u5386\u5F02\u5E38\uFF0C\u53EF\u80FD\u5B58\u5728\u975E\u5E73\u9762\u56FE\u3001\u91CD\u590D\u7EBF\u3001\u60AC\u6302\u7EBF\u6216\u810F\u6570\u636E");break}}if(p.length<3)continue;let P=y.map(v=>l[v]),E=ea(P),S=!1;if(s==="positive"?S=E>n:S=E<-n,!S)continue;let I=p.map(v=>h[v].uuid),W=p.map(v=>h[v].sourceIndex);x.push({uuids:I,area:Math.abs(E),lineIndexes:W})}return x};function Ji(t,e,n=1e-6){let o=[];for(let r=0;r<t.length;r++){let s=t[r],i=e(s.start),l=e(s.end),u=[{t:0,point:jn(s.start)},{t:1,point:jn(s.end)}];for(let d=0;d<t.length;d++){if(r===d)continue;let c=t[d],a=e(c.start),h=e(c.end),g=ta(i,l,a,h,n);g&&g.t>n&&g.t<1-n&&u.push({t:g.t,point:na(s.start,s.end,g.t)})}u.sort((d,c)=>d.t-c.t);let f=[];for(let d of u)(f.length===0||Math.abs(d.t-f[f.length-1].t)>n)&&f.push(d);for(let d=0;d<f.length-1;d++){let c=f[d].point,a=f[d+1].point,h=e(c),g=e(a);vr(h,g)<n*n||o.push({start:c,end:a,uuid:s.uuid,sourceIndex:r,sourceSegment:s})}}return o}function ta(t,e,n,o,r=1e-6){let s={x:e.x-t.x,y:e.y-t.y},i={x:o.x-n.x,y:o.y-n.y},l={x:n.x-t.x,y:n.y-t.y},u=So(s,i);if(Math.abs(u)<r)return null;let f=So(l,i)/u,d=So(l,s)/u;return f>=-r&&f<=1+r&&d>=-r&&d<=1+r?{t:f,u:d,point:{x:t.x+f*s.x,y:t.y+f*s.y}}:null}function So(t,e){return t.x*e.y-t.y*e.x}function vr(t,e){let n=t.x-e.x,o=t.y-e.y;return n*n+o*o}function ea(t){let e=0;for(let n=0;n<t.length;n++){let o=t[n],r=t[(n+1)%t.length];e+=o.x*r.y-r.x*o.y}return e/2}function na(t,e,n){return t&&typeof t.clone=="function"&&typeof t.lerp=="function"?t.clone().lerp(e,n):{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n,z:t.z!==void 0&&e.z!==void 0?t.z+(e.z-t.z)*n:void 0}}function jn(t){return t&&typeof t.clone=="function"?t.clone():{x:t.x,y:t.y,z:t.z}}var oa=(t,e)=>{if(!t||t.length<=0)return;let n={rectangles:[],threeEdgeRect:[]},o=new Set,r=.1,s=1.2,i=.15,l=2,u=80,f=95;if(!t[0].uuid){let a=1e4;for(let h=0;h<t.length;h++)t[h].uuid=a++}let d=[];for(let a=0;a<t.length;a++)d.push({start:t[a].start,end:t[a].end,uuid:t[a].uuid});let c=Dr(d,{eps:.035,returnDetail:!0,project:a=>({x:a.x,y:a.y})});for(let a=0;a<c.length;a++){if(c[a].uuids.length<4||c[a].area<i||c[a].area>l)continue;let h=!1;for(let g=0;g<c[a].lineIndexes.length;g++){let b=t[c[a].lineIndexes[g]].length;if(b<r||b>s)break;let x=new Lt.Vector3(t[c[a].lineIndexes[g]].start.x,t[c[a].lineIndexes[g]].start.y,t[c[a].lineIndexes[g]].start.z),m=new Lt.Vector3(t[c[a].lineIndexes[g]].end.x,t[c[a].lineIndexes[g]].end.y,t[c[a].lineIndexes[g]].end.z),p=!1,y=new Lt.Vector3(0,0,0);for(let w=g+1;w<c[a].lineIndexes.length;w++){let z=t[c[a].lineIndexes[w]].length;if(z<r||z>s)break;let M=new Lt.Vector3(t[c[a].lineIndexes[w]].start.x,t[c[a].lineIndexes[w]].start.y,t[c[a].lineIndexes[w]].start.z),P=new Lt.Vector3(t[c[a].lineIndexes[w]].end.x,t[c[a].lineIndexes[w]].end.y,t[c[a].lineIndexes[w]].end.z),E=Zt(x,m,M,P);if(E&&E.isParallel){if(b+z>s){p=!0;break}b+=z;let I=ct(x,M),W=ct(x,P),v=ct(m,M),T=ct(m,P);I?(x=m.clone(),m=P.clone()):W?(x=m.clone(),m=M.clone()):v?m=P.clone():T&&(m=M.clone());continue}let S=ie(x,m,M,P);if(!S||S.angle<u||S.angle>f){p=!0;break}for(let I=w+1;I<c[a].lineIndexes.length;I++){let W=t[c[a].lineIndexes[I]].length;if(W<r||W>s)break;let v=new Lt.Vector3(t[c[a].lineIndexes[I]].start.x,t[c[a].lineIndexes[I]].start.y,t[c[a].lineIndexes[I]].start.z),T=new Lt.Vector3(t[c[a].lineIndexes[I]].end.x,t[c[a].lineIndexes[I]].end.y,t[c[a].lineIndexes[I]].end.z),R=Zt(M,P,v,T);if(R&&R.isParallel){if(z+W>s){p=!0;break}z+=W;let H=ct(M,v),V=ct(M,T),C=ct(P,v),_=ct(P,T);H?(M=P.clone(),P=T.clone()):V?(M=P.clone(),P=v.clone()):C?P=T.clone():_&&(P=v.clone());continue}let D=ie(M,P,v,T);if(!D||D.angle<u||D.angle>f){p=!0;break}for(let H=I+1;H<c[a].lineIndexes.length;H++){let V=t[c[a].lineIndexes[H]].length;if(V<r||V>s)break;let C=new Lt.Vector3(t[c[a].lineIndexes[H]].start.x,t[c[a].lineIndexes[H]].start.y,t[c[a].lineIndexes[H]].start.z),_=new Lt.Vector3(t[c[a].lineIndexes[H]].end.x,t[c[a].lineIndexes[H]].end.y,t[c[a].lineIndexes[H]].end.z),A=Zt(v,T,C,_);if(A&&A.isParallel){if(W+V>s){p=!0;break}W+=V;let $=ct(v,C),Z=ct(v,_),Q=ct(T,C),j=ct(T,_);$?(v=T.clone(),T=_.clone()):Z?(v=T.clone(),T=C.clone()):Q?T=_.clone():j&&(T=C.clone());continue}let B=ie(v,T,C,_);if(!B||B.angle<u||B.angle>f){p=!0;break}let k=ct(C,x),F=ct(C,m),L=ct(_,x),O=ct(_,m);if(k||F||L||O)h=!0;else for(let $=H+1;$<c[a].lineIndexes.length;$++){let Z=t[c[a].lineIndexes[$]].length;if(Z<r||Z>s)break;let Q=new Lt.Vector3(t[c[a].lineIndexes[$]].start.x,t[c[a].lineIndexes[$]].start.y,t[c[a].lineIndexes[$]].start.z),j=new Lt.Vector3(t[c[a].lineIndexes[$]].end.x,t[c[a].lineIndexes[$]].end.y,t[c[a].lineIndexes[$]].end.z),X=Zt(C,_,Q,j);if(X&&X.isParallel){if(V+Z>s){p=!0;break}V+=Z;let U=ct(C,Q),lt=ct(C,j),mt=ct(_,Q),St=ct(_,j);if(U)C=_.clone(),_=j.clone();else if(lt)C=_.clone(),_=Q.clone();else if(mt)_=j.clone();else if(St)_=Q.clone();else continue;if(k=ct(C,x),F=ct(C,m),L=ct(_,x),O=ct(_,m),k||F||L||O){h=!0;break}}}break}if(p)break}if(p)break}if(p)break}h&&n.rectangles.push(c[a].uuids)}for(let a=0;a<t.length;a++){let h=t[a].length;if(o.has(t[a].uuid)||h<r||h>s)continue;let g={uuids:[],missingEdge:{start:new Lt.Vector3,end:new Lt.Vector3}},b=new Lt.Vector3(t[a].start.x,t[a].start.y,t[a].start.z),x=new Lt.Vector3(t[a].end.x,t[a].end.y,t[a].end.z),m=!0,p=!0;for(let z=0;z<t.length;z++){if(z==a)continue;let M=new Lt.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),P=new Lt.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),E=ct(M,b),S=ct(P,b),I=ct(M,x),W=ct(P,x);if(E||S?m=!1:(I||W)&&(p=!1),!m&&!p)break}if(!m&&!p)continue;let y=new Lt.Vector3;m||([b,x]=[x,b]),y=new Lt.Vector3().subVectors(x,b).normalize();let w=y.clone().negate();for(let z=0;z<t.length;z++){let M=t[z].length;if(z==a||o.has(z)||M<r||M>s)continue;let P=new Lt.Vector3(t[z].start.x,t[z].start.y,t[z].start.z),E=new Lt.Vector3(t[z].end.x,t[z].end.y,t[z].end.z),S=ie(b,x,P,E);if(!S||S.angle<85)continue;let I=ct(P,x),W=ct(E,x);if(!I&&!W)continue;let v=new Lt.Vector3,T=new Lt.Vector3;I?(v=P.clone(),T=E.clone()):(v=E.clone(),T=P.clone());for(let R=0;R<t.length;R++){let D=t[R].length;if(R==a||R==z||o.has(R)||D<r||D>s)continue;let H=new Lt.Vector3(t[R].start.x,t[R].start.y,t[R].start.z),V=new Lt.Vector3(t[R].end.x,t[R].end.y,t[R].end.z),C=ie(P,E,H,V);if(!C||C.angle<85)continue;let _=ct(H,T),A=ct(V,T);if(!_&&!A)continue;let B=new Lt.Vector3,k=new Lt.Vector3;_?(B=H.clone(),k=V.clone()):(B=V.clone(),k=H.clone());let F=new Lt.Vector3().subVectors(k,B).normalize(),L=Xt(w,F,.1);if(!L||!L.parallel||!L.sameDirection)continue;let O=!0,$=!0;for(let Q=0;Q<t.length;Q++){if(Q==R)continue;let j=new Lt.Vector3(t[Q].start.x,t[Q].start.y,t[Q].start.z),X=new Lt.Vector3(t[Q].end.x,t[Q].end.y,t[Q].end.z),U=ct(j,H),lt=ct(X,H),mt=ct(j,V),St=ct(X,V);if(U||lt?O=!1:(mt||St)&&($=!1),!O&&!$)break}if(!O&&!$)continue;let Z=h*M;if(!(Z<i||Z>l)){g.uuids=[t[a].uuid,t[z].uuid,t[R].uuid],g.missingEdge.start=k,g.missingEdge.end=b;break}}if(g.uuids.length==3)break}g.uuids.length==3&&(g.uuids.forEach(z=>o.add(z)),n.threeEdgeRect.push(g))}return n};import*as q from"three";import"three/examples/jsm/utils/BufferGeometryUtils.js";var Ht=11102230246251565e-32,Kt=134217729,zn=(3+8*Ht)*Ht;function Fe(t,e,n,o,r){let s,i,l,u,f=e[0],d=o[0],c=0,a=0;d>f==d>-f?(s=f,f=e[++c]):(s=d,d=o[++a]);let h=0;if(c<t&&a<n)for(d>f==d>-f?(i=f+s,l=s-(i-f),f=e[++c]):(i=d+s,l=s-(i-d),d=o[++a]),s=i,l!==0&&(r[h++]=l);c<t&&a<n;)d>f==d>-f?(i=s+f,u=i-s,l=s-(i-u)+(f-u),f=e[++c]):(i=s+d,u=i-s,l=s-(i-u)+(d-u),d=o[++a]),s=i,l!==0&&(r[h++]=l);for(;c<t;)i=s+f,u=i-s,l=s-(i-u)+(f-u),f=e[++c],s=i,l!==0&&(r[h++]=l);for(;a<n;)i=s+d,u=i-s,l=s-(i-u)+(d-u),d=o[++a],s=i,l!==0&&(r[h++]=l);return(s!==0||h===0)&&(r[h++]=s),h}function Mn(t,e){let n=e[0];for(let o=1;o<t;o++)n+=e[o];return n}function K(t){return new Float64Array(t)}var ra=(3+16*Ht)*Ht,sa=(2+12*Ht)*Ht,ia=(9+64*Ht)*Ht*Ht,nn=K(4),Vr=K(8),Ir=K(12),Cr=K(16),re=K(4);function aa(t,e,n,o,r,s,i){let l,u,f,d,c,a,h,g,b,x,m,p,y,w,z,M,P,E,S=t-r,I=n-r,W=e-s,v=o-s;w=S*v,a=Kt*S,h=a-(a-S),g=S-h,a=Kt*v,b=a-(a-v),x=v-b,z=g*x-(w-h*b-g*b-h*x),M=W*I,a=Kt*W,h=a-(a-W),g=W-h,a=Kt*I,b=a-(a-I),x=I-b,P=g*x-(M-h*b-g*b-h*x),m=z-P,c=z-m,nn[0]=z-(m+c)+(c-P),p=w+m,c=p-w,y=w-(p-c)+(m-c),m=y-M,c=y-m,nn[1]=y-(m+c)+(c-M),E=p+m,c=E-p,nn[2]=p-(E-c)+(m-c),nn[3]=E;let T=Mn(4,nn),R=sa*i;if(T>=R||-T>=R||(c=t-S,l=t-(S+c)+(c-r),c=n-I,f=n-(I+c)+(c-r),c=e-W,u=e-(W+c)+(c-s),c=o-v,d=o-(v+c)+(c-s),l===0&&u===0&&f===0&&d===0)||(R=ia*i+zn*Math.abs(T),T+=S*d+v*l-(W*f+I*u),T>=R||-T>=R))return T;w=l*v,a=Kt*l,h=a-(a-l),g=l-h,a=Kt*v,b=a-(a-v),x=v-b,z=g*x-(w-h*b-g*b-h*x),M=u*I,a=Kt*u,h=a-(a-u),g=u-h,a=Kt*I,b=a-(a-I),x=I-b,P=g*x-(M-h*b-g*b-h*x),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,y=w-(p-c)+(m-c),m=y-M,c=y-m,re[1]=y-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let D=Fe(4,nn,4,re,Vr);w=S*d,a=Kt*S,h=a-(a-S),g=S-h,a=Kt*d,b=a-(a-d),x=d-b,z=g*x-(w-h*b-g*b-h*x),M=W*f,a=Kt*W,h=a-(a-W),g=W-h,a=Kt*f,b=a-(a-f),x=f-b,P=g*x-(M-h*b-g*b-h*x),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,y=w-(p-c)+(m-c),m=y-M,c=y-m,re[1]=y-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let H=Fe(D,Vr,4,re,Ir);w=l*d,a=Kt*l,h=a-(a-l),g=l-h,a=Kt*d,b=a-(a-d),x=d-b,z=g*x-(w-h*b-g*b-h*x),M=u*f,a=Kt*u,h=a-(a-u),g=u-h,a=Kt*f,b=a-(a-f),x=f-b,P=g*x-(M-h*b-g*b-h*x),m=z-P,c=z-m,re[0]=z-(m+c)+(c-P),p=w+m,c=p-w,y=w-(p-c)+(m-c),m=y-M,c=y-m,re[1]=y-(m+c)+(c-M),E=p+m,c=E-p,re[2]=p-(E-c)+(m-c),re[3]=E;let V=Fe(H,Ir,4,re,Cr);return Cr[V-1]}function on(t,e,n,o,r,s){let i=(e-s)*(n-r),l=(t-r)*(o-s),u=i-l,f=Math.abs(i+l);return Math.abs(u)>=ra*f?u:-aa(t,e,n,o,r,s,f)}var Iu=(7+56*Ht)*Ht,Cu=(3+28*Ht)*Ht,Hu=(26+288*Ht)*Ht*Ht,Wu=K(4),_u=K(4),Au=K(4),Lu=K(4),Bu=K(4),ku=K(4),Ou=K(4),Fu=K(4),Nu=K(4),qu=K(8),ju=K(8),$u=K(8),Xu=K(4),Zu=K(8),Gu=K(8),Yu=K(16),Uu=K(12),Ku=K(192),Qu=K(192);var ef=(10+96*Ht)*Ht,nf=(4+48*Ht)*Ht,of=(44+576*Ht)*Ht*Ht,rf=K(4),sf=K(4),af=K(4),lf=K(4),cf=K(4),uf=K(4),ff=K(4),df=K(4),hf=K(8),mf=K(8),pf=K(8),gf=K(8),xf=K(8),yf=K(8),bf=K(8),wf=K(8),zf=K(8),Mf=K(4),Ef=K(4),Pf=K(4),Tf=K(8),Sf=K(16),Rf=K(16),Df=K(16),vf=K(32),Vf=K(32),If=K(48),Cf=K(64),Hf=K(1152),Wf=K(1152);var Bf=(16+224*Ht)*Ht,kf=(5+72*Ht)*Ht,Of=(71+1408*Ht)*Ht*Ht,Ff=K(4),Nf=K(4),qf=K(4),jf=K(4),$f=K(4),Xf=K(4),Zf=K(4),Gf=K(4),Yf=K(4),Uf=K(4),Kf=K(24),Qf=K(24),Jf=K(24),td=K(24),ed=K(24),nd=K(24),od=K(24),rd=K(24),sd=K(24),id=K(24),ad=K(1152),ld=K(1152),cd=K(1152),ud=K(1152),fd=K(1152),dd=K(2304),hd=K(2304),md=K(3456),pd=K(5760),gd=K(8),xd=K(8),yd=K(8),bd=K(16),wd=K(24),zd=K(48),Md=K(48),Ed=K(96),Pd=K(192),Td=K(384),Sd=K(384),Rd=K(384),Dd=K(768);var vd=K(96),Vd=K(96),Id=K(96),Cd=K(1152);var Wr=Math.pow(2,-52),$n=new Uint32Array(512),sn=class t{static from(e,n=ha,o=ma){let r=e.length,s=new Float64Array(r*2);for(let i=0;i<r;i++){let l=e[i];s[2*i]=n(l),s[2*i+1]=o(l)}return new t(s)}constructor(e){let n=e.length>>1;if(n>0&&typeof e[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=e;let o=Math.max(2*n-5,0);this._triangles=new Uint32Array(o*3),this._halfedges=new Int32Array(o*3),this._hashSize=Math.ceil(Math.sqrt(n)),this._hullPrev=new Uint32Array(n),this._hullNext=new Uint32Array(n),this._hullTri=new Uint32Array(n),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(n),this._dists=new Float64Array(n),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:n,_hullNext:o,_hullTri:r,_hullHash:s}=this,i=e.length>>1,l=1/0,u=1/0,f=-1/0,d=-1/0;for(let S=0;S<i;S++){let I=e[2*S],W=e[2*S+1];I<l&&(l=I),W<u&&(u=W),I>f&&(f=I),W>d&&(d=W),this._ids[S]=S}let c=(l+f)/2,a=(u+d)/2,h=0,g=0,b=0;for(let S=0,I=1/0;S<i;S++){let W=Ro(c,a,e[2*S],e[2*S+1]);W<I&&(h=S,I=W)}let x=e[2*h],m=e[2*h+1];for(let S=0,I=1/0;S<i;S++){if(S===h)continue;let W=Ro(x,m,e[2*S],e[2*S+1]);W<I&&W>0&&(g=S,I=W)}let p=e[2*g],y=e[2*g+1],w=1/0;for(let S=0;S<i;S++){if(S===h||S===g)continue;let I=fa(x,m,p,y,e[2*S],e[2*S+1]);I<w&&(b=S,w=I)}let z=e[2*b],M=e[2*b+1];if(w===1/0){for(let W=0;W<i;W++)this._dists[W]=e[2*W]-e[0]||e[2*W+1]-e[1];rn(this._ids,this._dists,0,i-1);let S=new Uint32Array(i),I=0;for(let W=0,v=-1/0;W<i;W++){let T=this._ids[W],R=this._dists[T];R>v&&(S[I++]=T,v=R)}this.hull=S.subarray(0,I),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(on(x,m,p,y,z,M)<0){let S=g,I=p,W=y;g=b,p=z,y=M,b=S,z=I,M=W}let P=da(x,m,p,y,z,M);this._cx=P.x,this._cy=P.y;for(let S=0;S<i;S++)this._dists[S]=Ro(e[2*S],e[2*S+1],P.x,P.y);rn(this._ids,this._dists,0,i-1),this._hullStart=h;let E=3;o[h]=n[b]=g,o[g]=n[h]=b,o[b]=n[g]=h,r[h]=0,r[g]=1,r[b]=2,s.fill(-1),s[this._hashKey(x,m)]=h,s[this._hashKey(p,y)]=g,s[this._hashKey(z,M)]=b,this.trianglesLen=0,this._addTriangle(h,g,b,-1,-1,-1);for(let S=0,I=0,W=0;S<this._ids.length;S++){let v=this._ids[S],T=e[2*v],R=e[2*v+1];if(S>0&&Math.abs(T-I)<=Wr&&Math.abs(R-W)<=Wr||(I=T,W=R,v===h||v===g||v===b))continue;let D=0;for(let A=0,B=this._hashKey(T,R);A<this._hashSize&&(D=s[(B+A)%this._hashSize],!(D!==-1&&D!==o[D]));A++);D=n[D];let H=D,V;for(;V=o[H],on(T,R,e[2*H],e[2*H+1],e[2*V],e[2*V+1])>=0;)if(H=V,H===D){H=-1;break}if(H===-1)continue;let C=this._addTriangle(H,v,o[H],-1,-1,r[H]);r[v]=this._legalize(C+2),r[H]=C,E++;let _=o[H];for(;V=o[_],on(T,R,e[2*_],e[2*_+1],e[2*V],e[2*V+1])<0;)C=this._addTriangle(_,v,V,r[v],-1,r[_]),r[v]=this._legalize(C+2),o[_]=_,E--,_=V;if(H===D)for(;V=n[H],on(T,R,e[2*V],e[2*V+1],e[2*H],e[2*H+1])<0;)C=this._addTriangle(V,v,H,-1,r[H],r[V]),this._legalize(C+2),r[V]=C,o[H]=H,E--,H=V;this._hullStart=n[v]=H,o[H]=n[_]=v,o[v]=_,s[this._hashKey(T,R)]=v,s[this._hashKey(e[2*H],e[2*H+1])]=H}this.hull=new Uint32Array(E);for(let S=0,I=this._hullStart;S<E;S++)this.hull[S]=I,I=o[I];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,n){return Math.floor(ca(e-this._cx,n-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:n,_halfedges:o,coords:r}=this,s=0,i=0;for(;;){let l=o[e],u=e-e%3;if(i=u+(e+2)%3,l===-1){if(s===0)break;e=$n[--s];continue}let f=l-l%3,d=u+(e+1)%3,c=f+(l+2)%3,a=n[i],h=n[e],g=n[d],b=n[c];if(ua(r[2*a],r[2*a+1],r[2*h],r[2*h+1],r[2*g],r[2*g+1],r[2*b],r[2*b+1])){n[e]=b,n[l]=a;let m=o[c];if(m===-1){let y=this._hullStart;do{if(this._hullTri[y]===c){this._hullTri[y]=e;break}y=this._hullPrev[y]}while(y!==this._hullStart)}this._link(e,m),this._link(l,o[i]),this._link(i,c);let p=f+(l+1)%3;s<$n.length&&($n[s++]=p)}else{if(s===0)break;e=$n[--s]}}return i}_link(e,n){this._halfedges[e]=n,n!==-1&&(this._halfedges[n]=e)}_addTriangle(e,n,o,r,s,i){let l=this.trianglesLen;return this._triangles[l]=e,this._triangles[l+1]=n,this._triangles[l+2]=o,this._link(l,r),this._link(l+1,s),this._link(l+2,i),this.trianglesLen+=3,l}};function ca(t,e){let n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}function Ro(t,e,n,o){let r=t-n,s=e-o;return r*r+s*s}function ua(t,e,n,o,r,s,i,l){let u=t-i,f=e-l,d=n-i,c=o-l,a=r-i,h=s-l,g=u*u+f*f,b=d*d+c*c,x=a*a+h*h;return u*(c*x-b*h)-f*(d*x-b*a)+g*(d*h-c*a)<0}function fa(t,e,n,o,r,s){let i=n-t,l=o-e,u=r-t,f=s-e,d=i*i+l*l,c=u*u+f*f,a=.5/(i*f-l*u),h=(f*d-l*c)*a,g=(i*c-u*d)*a;return h*h+g*g}function da(t,e,n,o,r,s){let i=n-t,l=o-e,u=r-t,f=s-e,d=i*i+l*l,c=u*u+f*f,a=.5/(i*f-l*u),h=t+(f*d-l*c)*a,g=e+(i*c-u*d)*a;return{x:h,y:g}}function rn(t,e,n,o){if(o-n<=20)for(let r=n+1;r<=o;r++){let s=t[r],i=e[s],l=r-1;for(;l>=n&&e[t[l]]>i;)t[l+1]=t[l--];t[l+1]=s}else{let r=n+o>>1,s=n+1,i=o;En(t,r,s),e[t[n]]>e[t[o]]&&En(t,n,o),e[t[s]]>e[t[o]]&&En(t,s,o),e[t[n]]>e[t[s]]&&En(t,n,s);let l=t[s],u=e[l];for(;;){do s++;while(e[t[s]]<u);do i--;while(e[t[i]]>u);if(i<s)break;En(t,s,i)}t[n+1]=t[i],t[i]=l,o-s+1>=i-n?(rn(t,e,s,o),rn(t,e,n,i-1)):(rn(t,e,n,i-1),rn(t,e,s,o))}}function En(t,e,n){let o=t[e];t[e]=t[n],t[n]=o}function ha(t){return t[0]}function ma(t){return t[1]}var me=class{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(e,n){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(e,n){this._+=`L${this._x1=+e},${this._y1=+n}`}arc(e,n,o){e=+e,n=+n,o=+o;let r=e+o,s=n;if(o<0)throw new Error("negative radius");this._x1===null?this._+=`M${r},${s}`:(Math.abs(this._x1-r)>1e-6||Math.abs(this._y1-s)>1e-6)&&(this._+="L"+r+","+s),o&&(this._+=`A${o},${o},0,1,1,${e-o},${n}A${o},${o},0,1,1,${this._x1=r},${this._y1=s}`)}rect(e,n,o,r){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}h${+o}v${+r}h${-o}Z`}value(){return this._||null}};var _e=class{constructor(){this._=[]}moveTo(e,n){this._.push([e,n])}closePath(){this._.push(this._[0].slice())}lineTo(e,n){this._.push([e,n])}value(){return this._.length?this._:null}};var Pn=class{constructor(e,[n,o,r,s]=[0,0,960,500]){if(!((r=+r)>=(n=+n))||!((s=+s)>=(o=+o)))throw new 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=n,this.ymax=s,this.ymin=o,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){let{delaunay:{points:e,hull:n,triangles:o},vectors:r}=this,s,i,l=this.circumcenters=this._circumcenters.subarray(0,o.length/3*2);for(let b=0,x=0,m=o.length,p,y;b<m;b+=3,x+=2){let w=o[b]*2,z=o[b+1]*2,M=o[b+2]*2,P=e[w],E=e[w+1],S=e[z],I=e[z+1],W=e[M],v=e[M+1],T=S-P,R=I-E,D=W-P,H=v-E,V=(T*H-R*D)*2;if(Math.abs(V)<1e-9){if(s===void 0){s=i=0;for(let _ of n)s+=e[_*2],i+=e[_*2+1];s/=n.length,i/=n.length}let C=1e9*Math.sign((s-P)*H-(i-E)*D);p=(P+W)/2-C*H,y=(E+v)/2+C*D}else{let C=1/V,_=T*T+R*R,A=D*D+H*H;p=P+(H*_-R*A)*C,y=E+(T*A-D*_)*C}l[x]=p,l[x+1]=y}let u=n[n.length-1],f,d=u*4,c,a=e[2*u],h,g=e[2*u+1];r.fill(0);for(let b=0;b<n.length;++b)u=n[b],f=d,c=a,h=g,d=u*4,a=e[2*u],g=e[2*u+1],r[f+2]=r[d]=h-g,r[f+3]=r[d+1]=a-c}render(e){let n=e==null?e=new me:void 0,{delaunay:{halfedges:o,inedges:r,hull:s},circumcenters:i,vectors:l}=this;if(s.length<=1)return null;for(let d=0,c=o.length;d<c;++d){let a=o[d];if(a<d)continue;let h=Math.floor(d/3)*2,g=Math.floor(a/3)*2,b=i[h],x=i[h+1],m=i[g],p=i[g+1];this._renderSegment(b,x,m,p,e)}let u,f=s[s.length-1];for(let d=0;d<s.length;++d){u=f,f=s[d];let c=Math.floor(r[f]/3)*2,a=i[c],h=i[c+1],g=u*4,b=this._project(a,h,l[g+2],l[g+3]);b&&this._renderSegment(a,h,b[0],b[1],e)}return n&&n.value()}renderBounds(e){let n=e==null?e=new me:void 0;return e.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),n&&n.value()}renderCell(e,n){let o=n==null?n=new me:void 0,r=this._clip(e);if(r===null||!r.length)return;n.moveTo(r[0],r[1]);let s=r.length;for(;r[0]===r[s-2]&&r[1]===r[s-1]&&s>1;)s-=2;for(let i=2;i<s;i+=2)(r[i]!==r[i-2]||r[i+1]!==r[i-1])&&n.lineTo(r[i],r[i+1]);return n.closePath(),o&&o.value()}*cellPolygons(){let{delaunay:{points:e}}=this;for(let n=0,o=e.length/2;n<o;++n){let r=this.cellPolygon(n);r&&(r.index=n,yield r)}}cellPolygon(e){let n=new _e;return this.renderCell(e,n),n.value()}_renderSegment(e,n,o,r,s){let i,l=this._regioncode(e,n),u=this._regioncode(o,r);l===0&&u===0?(s.moveTo(e,n),s.lineTo(o,r)):(i=this._clipSegment(e,n,o,r,l,u))&&(s.moveTo(i[0],i[1]),s.lineTo(i[2],i[3]))}contains(e,n,o){return n=+n,n!==n||(o=+o,o!==o)?!1:this.delaunay._step(e,n,o)===e}*neighbors(e){let n=this._clip(e);if(n)for(let o of this.delaunay.neighbors(e)){let r=this._clip(o);if(r){t:for(let s=0,i=n.length;s<i;s+=2)for(let l=0,u=r.length;l<u;l+=2)if(n[s]===r[l]&&n[s+1]===r[l+1]&&n[(s+2)%i]===r[(l+u-2)%u]&&n[(s+3)%i]===r[(l+u-1)%u]){yield o;break t}}}}_cell(e){let{circumcenters:n,delaunay:{inedges:o,halfedges:r,triangles:s}}=this,i=o[e];if(i===-1)return null;let l=[],u=i;do{let f=Math.floor(u/3);if(l.push(n[f*2],n[f*2+1]),u=u%3===2?u-2:u+1,s[u]!==e)break;u=r[u]}while(u!==i&&u!==-1);return l}_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 n=this._cell(e);if(n===null)return null;let{vectors:o}=this,r=e*4;return this._simplify(o[r]||o[r+1]?this._clipInfinite(e,n,o[r],o[r+1],o[r+2],o[r+3]):this._clipFinite(e,n))}_clipFinite(e,n){let o=n.length,r=null,s,i,l=n[o-2],u=n[o-1],f,d=this._regioncode(l,u),c,a=0;for(let h=0;h<o;h+=2)if(s=l,i=u,l=n[h],u=n[h+1],f=d,d=this._regioncode(l,u),f===0&&d===0)c=a,a=0,r?r.push(l,u):r=[l,u];else{let g,b,x,m,p;if(f===0){if((g=this._clipSegment(s,i,l,u,f,d))===null)continue;[b,x,m,p]=g}else{if((g=this._clipSegment(l,u,s,i,d,f))===null)continue;[m,p,b,x]=g,c=a,a=this._edgecode(b,x),c&&a&&this._edge(e,c,a,r,r.length),r?r.push(b,x):r=[b,x]}c=a,a=this._edgecode(m,p),c&&a&&this._edge(e,c,a,r,r.length),r?r.push(m,p):r=[m,p]}if(r)c=a,a=this._edgecode(r[0],r[1]),c&&a&&this._edge(e,c,a,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,n,o,r,s,i){let l=s<i;for(l&&([e,n,o,r,s,i]=[o,r,e,n,i,s]);;){if(s===0&&i===0)return l?[o,r,e,n]:[e,n,o,r];if(s&i)return null;let u,f,d=s||i;d&8?(u=e+(o-e)*(this.ymax-n)/(r-n),f=this.ymax):d&4?(u=e+(o-e)*(this.ymin-n)/(r-n),f=this.ymin):d&2?(f=n+(r-n)*(this.xmax-e)/(o-e),u=this.xmax):(f=n+(r-n)*(this.xmin-e)/(o-e),u=this.xmin),s?(e=u,n=f,s=this._regioncode(e,n)):(o=u,r=f,i=this._regioncode(o,r))}}_clipInfinite(e,n,o,r,s,i){let l=Array.from(n),u;if((u=this._project(l[0],l[1],o,r))&&l.unshift(u[0],u[1]),(u=this._project(l[l.length-2],l[l.length-1],s,i))&&l.push(u[0],u[1]),l=this._clipFinite(e,l))for(let f=0,d=l.length,c,a=this._edgecode(l[d-2],l[d-1]);f<d;f+=2)c=a,a=this._edgecode(l[f],l[f+1]),c&&a&&(f=this._edge(e,c,a,l,f),d=l.length);else this.contains(e,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(l=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return l}_edge(e,n,o,r,s){for(;n!==o;){let i,l;switch(n){case 5:n=4;continue;case 4:n=6,i=this.xmax,l=this.ymin;break;case 6:n=2;continue;case 2:n=10,i=this.xmax,l=this.ymax;break;case 10:n=8;continue;case 8:n=9,i=this.xmin,l=this.ymax;break;case 9:n=1;continue;case 1:n=5,i=this.xmin,l=this.ymin;break}(r[s]!==i||r[s+1]!==l)&&this.contains(e,i,l)&&(r.splice(s,0,i,l),s+=2)}return s}_project(e,n,o,r){let s=1/0,i,l,u;if(r<0){if(n<=this.ymin)return null;(i=(this.ymin-n)/r)<s&&(u=this.ymin,l=e+(s=i)*o)}else if(r>0){if(n>=this.ymax)return null;(i=(this.ymax-n)/r)<s&&(u=this.ymax,l=e+(s=i)*o)}if(o>0){if(e>=this.xmax)return null;(i=(this.xmax-e)/o)<s&&(l=this.xmax,u=n+(s=i)*r)}else if(o<0){if(e<=this.xmin)return null;(i=(this.xmin-e)/o)<s&&(l=this.xmin,u=n+(s=i)*r)}return[l,u]}_edgecode(e,n){return(e===this.xmin?1:e===this.xmax?2:0)|(n===this.ymin?4:n===this.ymax?8:0)}_regioncode(e,n){return(e<this.xmin?1:e>this.xmax?2:0)|(n<this.ymin?4:n>this.ymax?8:0)}_simplify(e){if(e&&e.length>4){for(let n=0;n<e.length;n+=2){let o=(n+2)%e.length,r=(n+4)%e.length;(e[n]===e[o]&&e[o]===e[r]||e[n+1]===e[o+1]&&e[o+1]===e[r+1])&&(e.splice(o,2),n-=2)}e.length||(e=null)}return e}};var pa=2*Math.PI,an=Math.pow;function ga(t){return t[0]}function xa(t){return t[1]}function ya(t){let{triangles:e,coords:n}=t;for(let o=0;o<e.length;o+=3){let r=2*e[o],s=2*e[o+1],i=2*e[o+2];if((n[i]-n[r])*(n[s+1]-n[r+1])-(n[s]-n[r])*(n[i+1]-n[r+1])>1e-10)return!1}return!0}function ba(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}var Ae=class t{static from(e,n=ga,o=xa,r){return new t("length"in e?wa(e,n,o,r):Float64Array.from(za(e,n,o,r)))}constructor(e){this._delaunator=new sn(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,n=this.points;if(e.hull&&e.hull.length>2&&ya(e)){this.collinear=Int32Array.from({length:n.length/2},(a,h)=>h).sort((a,h)=>n[2*a]-n[2*h]||n[2*a+1]-n[2*h+1]);let u=this.collinear[0],f=this.collinear[this.collinear.length-1],d=[n[2*u],n[2*u+1],n[2*f],n[2*f+1]],c=1e-8*Math.hypot(d[3]-d[1],d[2]-d[0]);for(let a=0,h=n.length/2;a<h;++a){let g=ba(n[2*a],n[2*a+1],c);n[2*a]=g[0],n[2*a+1]=g[1]}this._delaunator=new sn(n)}else delete this.collinear;let o=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,s=this.triangles=this._delaunator.triangles,i=this.inedges.fill(-1),l=this._hullIndex.fill(-1);for(let u=0,f=o.length;u<f;++u){let d=s[u%3===2?u-2:u+1];(o[u]===-1||i[d]===-1)&&(i[d]=u)}for(let u=0,f=r.length;u<f;++u)l[r[u]]=u;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],i[r[0]]=1,r.length===2&&(i[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(e){return new Pn(this,e)}*neighbors(e){let{inedges:n,hull:o,_hullIndex:r,halfedges:s,triangles:i,collinear:l}=this;if(l){let c=l.indexOf(e);c>0&&(yield l[c-1]),c<l.length-1&&(yield l[c+1]);return}let u=n[e];if(u===-1)return;let f=u,d=-1;do{if(yield d=i[f],f=f%3===2?f-2:f+1,i[f]!==e)return;if(f=s[f],f===-1){let c=o[(r[e]+1)%o.length];c!==d&&(yield c);return}}while(f!==u)}find(e,n,o=0){if(e=+e,e!==e||(n=+n,n!==n))return-1;let r=o,s;for(;(s=this._step(o,e,n))>=0&&s!==o&&s!==r;)o=s;return s}_step(e,n,o){let{inedges:r,hull:s,_hullIndex:i,halfedges:l,triangles:u,points:f}=this;if(r[e]===-1||!f.length)return(e+1)%(f.length>>1);let d=e,c=an(n-f[e*2],2)+an(o-f[e*2+1],2),a=r[e],h=a;do{let g=u[h],b=an(n-f[g*2],2)+an(o-f[g*2+1],2);if(b<c&&(c=b,d=g),h=h%3===2?h-2:h+1,u[h]!==e)break;if(h=l[h],h===-1){if(h=s[(i[e]+1)%s.length],h!==g&&an(n-f[h*2],2)+an(o-f[h*2+1],2)<c)return h;break}}while(h!==a);return d}render(e){let n=e==null?e=new me:void 0,{points:o,halfedges:r,triangles:s}=this;for(let i=0,l=r.length;i<l;++i){let u=r[i];if(u<i)continue;let f=s[i]*2,d=s[u]*2;e.moveTo(o[f],o[f+1]),e.lineTo(o[d],o[d+1])}return this.renderHull(e),n&&n.value()}renderPoints(e,n){n===void 0&&(!e||typeof e.moveTo!="function")&&(n=e,e=null),n=n==null?2:+n;let o=e==null?e=new me:void 0,{points:r}=this;for(let s=0,i=r.length;s<i;s+=2){let l=r[s],u=r[s+1];e.moveTo(l+n,u),e.arc(l,u,n,0,pa)}return o&&o.value()}renderHull(e){let n=e==null?e=new me:void 0,{hull:o,points:r}=this,s=o[0]*2,i=o.length;e.moveTo(r[s],r[s+1]);for(let l=1;l<i;++l){let u=2*o[l];e.lineTo(r[u],r[u+1])}return e.closePath(),n&&n.value()}hullPolygon(){let e=new _e;return this.renderHull(e),e.value()}renderTriangle(e,n){let o=n==null?n=new me:void 0,{points:r,triangles:s}=this,i=s[e*=3]*2,l=s[e+1]*2,u=s[e+2]*2;return n.moveTo(r[i],r[i+1]),n.lineTo(r[l],r[l+1]),n.lineTo(r[u],r[u+1]),n.closePath(),o&&o.value()}*trianglePolygons(){let{triangles:e}=this;for(let n=0,o=e.length/3;n<o;++n)yield this.trianglePolygon(n)}trianglePolygon(e){let n=new _e;return this.renderTriangle(e,n),n.value()}};function wa(t,e,n,o){let r=t.length,s=new Float64Array(r*2);for(let i=0;i<r;++i){let l=t[i];s[i*2]=e.call(o,l,i,t),s[i*2+1]=n.call(o,l,i,t)}return s}function*za(t,e,n,o){let r=0;for(let s of t)yield e.call(o,s,r,t),yield n.call(o,s,r,t),++r}function Do(t,e,n,o){let r,s;n<o?(r=n,s=o):(r=o,s=n);let i=r*e+s;t.set(i,(t.get(i)||0)+1)}function _r(t,e,n){let o=t.get(e);o===void 0&&(o=[],t.set(e,o)),o.push(n)}function ce(t){if(!t||t.length<3)return[];let e=new Set,n=[];for(let b=0;b<t.length;b++){let x=t[b],m=`${x[0]}_${x[1]}`;e.has(m)||(e.add(m),n.push(x))}let o=n.length;if(o<3)return[];let r=new Float64Array(o*2);for(let b=0,x=0;b<o;b++){let m=n[b];r[x++]=m[0],r[x++]=m[1]}let s=new Ae(r),{triangles:i}=s;if(!i.length)return[];let l=new Map;for(let b=0;b<i.length;b+=3){let x=i[b],m=i[b+1],p=i[b+2],y=x*2,w=m*2,z=p*2,M=r[y],P=r[y+1],E=r[w],S=r[w+1],I=r[z],W=r[z+1],v=M-E,T=P-S,R=M-I,D=P-W,H=E-I,V=S-W,C=H*H+V*V,_=R*R+D*D,A=v*v+T*T,B=(E-M)*(W-P)-(I-M)*(S-P);if(B===0)continue;let k=B*B,L=M===0||E===0||I===0?k:4*k;C*_*A<=L&&(Do(l,o,x,m),Do(l,o,m,p),Do(l,o,p,x))}if(!l.size)return[];let u=new Map,f=0,d=-1;for(let[b,x]of l){if(x!==1)continue;let m=Math.floor(b/o),p=b-m*o;d===-1&&(d=m),_r(u,m,p),_r(u,p,m),f++}if(f===0)return[];let c=[],a=new Uint8Array(o),h=d,g=-1;do{c.push(n[h]),a[h]=1;let b=u.get(h)||[],x=-1;for(let m=0;m<b.length;m++){let p=b[m];if(p!==g&&!a[p]){x=p;break}}if(x===-1)for(let m=0;m<b.length;m++){let p=b[m];if(p!==g){x=p;break}}if(x===-1)break;g=h,h=x}while(h!==d&&c.length<=f+1);return c.length>0&&c.push(c[0]),c}import*as Nt from"three";import{OBB as Oa}from"three/examples/jsm/math/OBB.js";var Qt=63710088e-1,Lr={centimeters:Qt*100,centimetres:Qt*100,degrees:360/(2*Math.PI),feet:Qt*3.28084,inches:Qt*39.37,kilometers:Qt/1e3,kilometres:Qt/1e3,meters:Qt,metres:Qt,miles:Qt/1609.344,millimeters:Qt*1e3,millimetres:Qt*1e3,nauticalmiles:Qt/1852,radians:1,yards:Qt*1.0936};function Br(t,e,n={}){let o={type:"Feature"};return(n.id===0||n.id)&&(o.id=n.id),n.bbox&&(o.bbox=n.bbox),o.properties=e||{},o.geometry=t,o}function Xn(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Ar(t[0])||!Ar(t[1]))throw new Error("coordinates must contain numbers");return Br({type:"Point",coordinates:t},e,n)}function Zn(t,e,n={}){for(let r of t){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let s=0;s<r[r.length-1].length;s++)if(r[r.length-1][s]!==r[0][s])throw new Error("First and last Position are not equivalent.")}return Br({type:"Polygon",coordinates:t},e,n)}function Ma(t,e="kilometers"){let n=Lr[e];if(!n)throw new Error(e+" units is invalid");return t*n}function Ea(t,e="kilometers"){let n=Lr[e];if(!n)throw new Error(e+" units is invalid");return t/n}function Gn(t){return t%(2*Math.PI)*180/Math.PI}function pe(t){return t%360*Math.PI/180}function Yn(t,e="kilometers",n="kilometers"){if(!(t>=0))throw new Error("length must be a positive number");return Ma(Ea(t,e),n)}function Ar(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function kr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Te(t,e,n){if(t!==null)for(var o,r,s,i,l,u,f,d=0,c=0,a,h=t.type,g=h==="FeatureCollection",b=h==="Feature",x=g?t.features.length:1,m=0;m<x;m++){f=g?t.features[m].geometry:b?t.geometry:t,a=f?f.type==="GeometryCollection":!1,l=a?f.geometries.length:1;for(var p=0;p<l;p++){var y=0,w=0;if(i=a?f.geometries[p]:f,i!==null){u=i.coordinates;var z=i.type;switch(d=n&&(z==="Polygon"||z==="MultiPolygon")?1:0,z){case null:break;case"Point":if(e(u,c,m,y,w)===!1)return!1;c++,y++;break;case"LineString":case"MultiPoint":for(o=0;o<u.length;o++){if(e(u[o],c,m,y,w)===!1)return!1;c++,z==="MultiPoint"&&y++}z==="LineString"&&y++;break;case"Polygon":case"MultiLineString":for(o=0;o<u.length;o++){for(r=0;r<u[o].length-d;r++){if(e(u[o][r],c,m,y,w)===!1)return!1;c++}z==="MultiLineString"&&y++,z==="Polygon"&&w++}z==="Polygon"&&y++;break;case"MultiPolygon":for(o=0;o<u.length;o++){for(w=0,r=0;r<u[o].length;r++){for(s=0;s<u[o][r].length-d;s++){if(e(u[o][r][s],c,m,y,w)===!1)return!1;c++}w++}y++}break;case"GeometryCollection":for(o=0;o<i.geometries.length;o++)if(Te(i.geometries[o],e,n)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Or(t){var e=[];return Te(t,function(n){e.push(n)}),e}function Pa(t,e){var n,o,r,s,i,l,u,f,d,c,a=0,h=t.type==="FeatureCollection",g=t.type==="Feature",b=h?t.features.length:1;for(n=0;n<b;n++){for(l=h?t.features[n].geometry:g?t.geometry:t,f=h?t.features[n].properties:g?t.properties:{},d=h?t.features[n].bbox:g?t.bbox:void 0,c=h?t.features[n].id:g?t.id:void 0,u=l?l.type==="GeometryCollection":!1,i=u?l.geometries.length:1,r=0;r<i;r++){if(s=u?l.geometries[r]:l,s===null){if(e(null,a,f,d,c)===!1)return!1;continue}switch(s.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(e(s,a,f,d,c)===!1)return!1;break}case"GeometryCollection":{for(o=0;o<s.geometries.length;o++)if(e(s.geometries[o],a,f,d,c)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}a++}}function Fr(t,e,n){var o=n;return Pa(t,function(r,s,i,l,u){s===0&&n===void 0?o=r:o=e(o,r,s,i,l,u)}),o}var ss=Ri(rs(),1);function is(t,e={}){e.concavity=e.concavity||1/0;let n=[];if(Te(t,r=>{n.push([r[0],r[1]])}),!n.length)return null;let o=(0,ss.default)(n,e.concavity);return o.length>3?Zn([o]):null}function to(t,e={}){let n=0,o=0,r=0;return Te(t,function(s){n+=s[0],o+=s[1],r++},!0),Xn([n/r,o/r],e.properties)}function ue(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if(t.type==="Feature"&&t.geometry!==null&&t.geometry.type==="Point")return[...t.geometry.coordinates];if(t.type==="Point")return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function as(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function cs(t,e,n={}){let o;return n.final?o=ls(ue(e),ue(t)):o=ls(ue(t),ue(e)),o>180?-(360-o):o}function ls(t,e){let n=pe(t[1]),o=pe(e[1]),r=pe(e[0]-t[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);let s=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),i=Math.atan2(r,s);return(Gn(i)+360)%360}function us(t,e,n={}){let o=ue(t),r=ue(e);r[0]+=r[0]-o[0]>180?-360:o[0]-r[0]>180?360:0;let s=Wa(o,r);return Yn(s,"meters",n.units)}function Wa(t,e,n){n=n===void 0?Qt:Number(n);let o=n,r=t[1]*Math.PI/180,s=e[1]*Math.PI/180,i=s-r,l=Math.abs(e[0]-t[0])*Math.PI/180;l>Math.PI&&(l-=2*Math.PI);let u=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),f=Math.abs(u)>1e-11?i/u:Math.cos(r);return Math.sqrt(i*i+f*f*l*l)*o}function fs(t,e,n,o={}){let r=e<0,s=Yn(Math.abs(e),o.units,"meters");r&&(s=-Math.abs(s));let i=ue(t),l=_a(i,s,n);return l[0]+=l[0]-i[0]>180?-360:i[0]-l[0]>180?360:0,Xn(l,o.properties)}function _a(t,e,n,o){o=o===void 0?Qt:Number(o);let r=e/o,s=t[0]*Math.PI/180,i=pe(t[1]),l=pe(n),u=r*Math.cos(l),f=i+u;Math.abs(f)>Math.PI/2&&(f=f>0?Math.PI-f:-Math.PI-f);let d=Math.log(Math.tan(f/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=Math.abs(d)>1e-11?u/d:Math.cos(i),a=r*Math.sin(l)/c;return[((s+a)*180/Math.PI+540)%360-180,f*180/Math.PI]}function ds(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return hs(t);case"FeatureCollection":return Aa(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Lo(t);default:throw new Error("unknown GeoJSON type")}}function hs(t){let e={type:"Feature"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:e[n]=t[n]}}),e.properties=ms(t.properties),t.geometry==null?e.geometry=null:e.geometry=Lo(t.geometry),e}function ms(t){let e={};return t&&Object.keys(t).forEach(n=>{let o=t[n];typeof o=="object"?o===null?e[n]=null:Array.isArray(o)?e[n]=o.map(r=>r):e[n]=ms(o):e[n]=o}),e}function Aa(t){let e={type:"FeatureCollection"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"features":return;default:e[n]=t[n]}}),e.features=t.features.map(n=>hs(n)),e}function Lo(t){let e={type:t.type};return t.bbox&&(e.bbox=t.bbox),t.type==="GeometryCollection"?(e.geometries=t.geometries.map(n=>Lo(n)),e):(e.coordinates=ps(t.coordinates),e)}function ps(t){let e=t;return typeof e[0]!="object"?e.slice():e.map(n=>ps(n))}function Bo(t,e,n){if(n=n||{},!kr(n))throw new Error("options is invalid");let o=n.pivot,r=n.mutate;if(!t)throw new Error("geojson is required");if(e==null||isNaN(e))throw new Error("angle is required");if(e===0)return t;let s=o??to(t);return(r===!1||r===void 0)&&(t=ds(t)),Te(t,function(i){let u=cs(s,i)+e,f=us(s,i),d=as(fs(s,f,u));i[0]=d[0],i[1]=d[1]}),t}function ko(t,e,n={}){if(n.final===!0)return La(t,e);let o=ue(t),r=ue(e),s=pe(o[0]),i=pe(r[0]),l=pe(o[1]),u=pe(r[1]),f=Math.sin(i-s)*Math.cos(u),d=Math.cos(l)*Math.sin(u)-Math.sin(l)*Math.cos(u)*Math.cos(i-s);return Gn(Math.atan2(f,d))}function La(t,e){let n=ko(e,t);return n=(n+180)%360,n}function gs(t,e={}){if(t.bbox!=null&&e.recompute!==!0)return t.bbox;let n=[1/0,1/0,-1/0,-1/0];return Te(t,o=>{n[0]>o[0]&&(n[0]=o[0]),n[1]>o[1]&&(n[1]=o[1]),n[2]<o[0]&&(n[2]=o[0]),n[3]<o[1]&&(n[3]=o[1])}),n}function xs(t,e={}){let n=Number(t[0]),o=Number(t[1]),r=Number(t[2]),s=Number(t[3]);if(t.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");let i=[n,o];return Zn([[i,[r,o],[r,s],[n,s],i]],e.properties,{bbox:t,id:e.id})}function ys(t){return xs(gs(t))}function zs(t){return Fr(t,(e,n)=>e+Ba(n),0)}function Ba(t){let e=0,n;switch(t.type){case"Polygon":return bs(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=bs(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function bs(t){let e=0;if(t&&t.length>0){e+=Math.abs(ws(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(ws(t[n]))}return e}var ka=Qt*Qt/2,Oo=Math.PI/180;function ws(t){let e=t.length-1;if(e<=2)return 0;let n=0,o=0;for(;o<e;){let r=t[o],s=t[o+1===e?0:o+1],i=t[o+2>=e?(o+2)%e:o+2],l=r[0]*Oo,u=s[1]*Oo,f=i[0]*Oo;n+=(f-l)*Math.sin(u),o++}return n*ka}function Ms(t){let e=is(t);if(!e)throw new Error("Can't calculate smallestSurroundingRectangleByArea for given geometry");let n=to(e),o=Or(e),r=Number.MAX_SAFE_INTEGER,s=null;for(let i=0;i<o.length-1;i++){let l=ko(o[i],o[i+1]),u=Bo(e,-1*l,{pivot:n}),f=ys(u),d=zs(f);d<r&&(r=d,s=Bo(f,l,{pivot:n}))}return s}function Es(t,e){let n=e[0]-t[0],o=e[1]-t[1];return Math.sqrt(n*n+o*o)}function Fa(t){let e=1/0,n=-1/0,o=1/0,r=-1/0;for(let[s,i]of t)s<e&&(e=s),s>n&&(n=s),i<o&&(o=i),i>r&&(r=i);return[(n+e)*.5,(r+o)*.5]}var no=class t extends Oa{getBoxMesh(){Le.identity(),Le.setFromMatrix3(this.rotation),Le.decompose(eo,Ne,new Nt.Vector3);let e=this.halfSize.clone().multiplyScalar(2),n=new Nt.Mesh(new Nt.BoxGeometry(e.x,e.y,e.z));return n.position.copy(this.center),n.rotation.setFromQuaternion(Ne),n}getBoxEdge(e=16776960){let n=this.getBoxMesh();qa.setFromObject(n);let o=new Nt.EdgesGeometry(n.geometry.clone().applyMatrix4(n.matrixWorld));return new Nt.LineSegments(o,new Nt.LineBasicMaterial({color:e,toneMapped:!1}))}toJson(){return Le.identity(),Le.setFromMatrix3(this.rotation),Le.decompose(eo,Ne,new Nt.Vector3),{size:this.halfSize.toArray(),center:this.center.toArray(),quaternion:Ne.toArray()}}static from(e,n,o,r=new t){if(o instanceof Nt.Euler)Ne.setFromEuler(o);else if(o instanceof Nt.Quaternion)Ne.copy(o);else throw new Error("\u4F20\u5165\u7684\u65CB\u8F6C\u4E0D\u662F\u6B27\u62C9\u89D2\u6216\u8005\u56DB\u5143\u6570");return Le.compose(n,Ne,Na),r.center.copy(n),r.halfSize.copy(e.multiplyScalar(.5)),r.rotation.setFromMatrix4(Le),r}static fromByPath2D(e,n,o,r=new t){let s=Ms({type:"Polygon",coordinates:[e.map(h=>[h.x,h.y])]});if(!s)throw new Error("2d obb \u83B7\u53D6\u5931\u8D25");let i=s.geometry.coordinates[0],l=Es(i[0],i[1]),u=Es(i[1],i[2]),f=Math.atan2(i[1][1]-i[0][1],i[1][0]-i[0][0]);eo.set(l,u,o),Ps.set(0,0,f);let[d,c]=Fa(i);return n.x=d,n.y=c,this.from(eo,n,Ps,r)}},Le=new Nt.Matrix4,Ne=new Nt.Quaternion,Ps=new Nt.Euler,Na=new Nt.Vector3(1,1,1),eo=new Nt.Vector3,qa=new Nt.Box3;import"three";function ja(t,e,n=.005,o=.2){if(!t.length||!e.length)return 0;let r=Math.max(n,.03),s=n*n,i=new Map,l=(c,a,h)=>`${Math.floor(c/r)},${Math.floor(a/r)},${Math.floor(h/r)}`;for(let c of e){let a=l(c.x,c.y,c.z);i.has(a)||i.set(a,[]),i.get(a).push(c)}let u=0,f=Math.ceil(n/r)+1,d=[];for(let c=-f;c<=f;c++)for(let a=-f;a<=f;a++)for(let h=-f;h<=f;h++)c*c+a*a+h*h<=f*f&&d.push([c,a,h]);for(let c of t){let a=Math.floor(c.x/r),h=Math.floor(c.y/r),g=Math.floor(c.z/r),b=!1;for(let[x,m,p]of d){let y=`${a+x},${h+m},${g+p}`;if(i.has(y)){for(let w of i.get(y))if(c.distanceToSquared(w)<s){b=!0;break}if(b)break}}if(b&&(u++,u/t.length>o))return u/t.length}return u/t.length}function Ie(t,e,n=.5){let o=0,r=0;for(let s of t)if(e.containsPoint(s)&&(o++,r=o/t.length,r>n))break;return r}function Fo(t,e,n,o){if(t.intersectsOBB(e))return!0;{let s=Jt(t,o),i=Jt(e,n);if(s||i)return!0}return!1}function No(t,e){let n=new q.Vector3,o=new q.Vector3;t.getSize(n),e.getSize(o);let r=n.x*n.y*n.z,s=o.x*o.y*o.z;return r>s?1:r<s?-1:0}function Jt(t,e){let n=!0;for(let o=0;o<e.length;o++)if(!t.containsPoint(e[o])){n=!1;break}return n}function fe(t){if(t.length===0)return{x:0,y:0,z:0,h:0};let e=0,n=0,o=-1/0,r=1/0;for(let s of t)e+=s.x,n+=s.y,o=Math.max(o,s.z),r=Math.min(r,s.z);return{x:e/t.length,y:n/t.length,z:0,maxz:o,minz:r,h:o-r}}function ze(t,e,n,o){let r=[];for(let i=0;i<t.length;i++)r.push(new q.Vector3(t[i][0],t[i][1],0));if(r.length==0)return null;let s=no.fromByPath2D(r,e,n);return s.center.z=o,s}var $a=(t,e)=>{let n=new q.Group,o=new q.MeshStandardMaterial({color:16737792,side:q.DoubleSide});for(let r=0;r<t.length;r++){let s=[];for(let b=0;b<t[r].path.length;b++)s.push(new q.Vector3(t[r].path[b][0],t[r].path[b][1],0));if(s.length==0)continue;n.add(t[r].obb.getBoxEdge());let i=new q.BufferGeometry;i.setFromPoints(s);let l="green",u=new q.LineBasicMaterial({color:l,depthTest:!1,depthWrite:!1}),f=new q.Line(i,u);f.position.z=t[r].maxz,n.add(f);let d=t[r].obb.center.clone(),c=yr(t[r].type,d),a=t[r].stairBottomPt1.clone(),h=t[r].stairBottomPt2.clone();for(let b=0;b<t[r].stairStepNum;b++){let x=[a,h];x.push(h.clone().addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth)),x.push(a.clone().addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth));let m=To(x,t[r].stairStepHeight),p=new q.Mesh(m,o);n.add(p),a=a.addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth),a=a.addScaledVector(new q.Vector3(0,0,1),t[r].stairStepHeight),h=h.addScaledVector(t[r].vecStepWidth,t[r].stairStepWidth),h=h.addScaledVector(new q.Vector3(0,0,1),t[r].stairStepHeight)}if(t[r].rectPt1.x!=0&&t[r].rectPt1.y!=0){let b=[t[r].stairBottomPt1,t[r].stairBottomPt2,t[r].rectPt2,t[r].rectPt1],x=To(b,t[r].stairStepHeight),m=new q.Mesh(x,o);n.add(m)}let g=new q.MeshBasicMaterial({color:16776960});for(let b=0;b<t[r].stairBottom1BalconyRailing.length;b++){let x=new q.CylinderGeometry(.03,.03,t[r].balconyRailingHeight,32),m=new q.Mesh(x,g);m.position.set(t[r].stairBottom1BalconyRailing[b].x,t[r].stairBottom1BalconyRailing[b].z+t[r].balconyRailingHeight/2,-t[r].stairBottom1BalconyRailing[b].y),e.add(m)}for(let b=0;b<t[r].stairBottom2BalconyRailing.length;b++){let x=new q.CylinderGeometry(.03,.03,t[r].balconyRailingHeight,32),m=new q.Mesh(x,g);m.position.set(t[r].stairBottom2BalconyRailing[b].x,t[r].stairBottom2BalconyRailing[b].z+t[r].balconyRailingHeight/2,-t[r].stairBottom2BalconyRailing[b].y),e.add(m)}}return n},Xa=(t,e,n=null)=>{if(t.length==0)return[];e||(e=t[0].averagePz);let o=[],r=new Map;for(let i=0;i<t.length;i++){let l=t[i].points.map(p=>[p.x,p.y]),u=t[i].obj_id;u=u.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").replace(/roof/g,"Ceiling");let f=u.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],d=u.indexOf("_")+1,c=u.lastIndexOf("_"),a=u.substring(d,c);if(a.includes("top")&&(d=a.indexOf("top")+4,a=a.substring(d,c)),a.includes("left")&&(d=a.indexOf("left")+5,a=a.substring(d,c)),a.includes("right")&&(d=a.indexOf("right")+6,a=a.substring(d,c)),a.includes("front")&&(d=a.indexOf("front")+6,a=a.substring(d,c)),a==="wall"||a==="stair guardrail")continue;let h=[];for(let p=0;p<t[i].points.length;p++)h.push(new q.Vector3(t[i].points[p].x,t[i].points[p].y,t[i].points[p].z));let g=-99999;if(a==="floor"){let p=new Map;for(let w=0;w<t[i].points.length;w++){let z=t[i].points[w].z;if(z=Math.floor(z*10)/10,p.has(z)){let M=p.get(z);M.num+=1,M.points.push(t[i].points[w]),p.set(z,M)}else p.set(z,{num:1,points:[t[i].points[w]]})}let y=[...p.entries()].reduce((w,z)=>z[1].num>w[1].num?z:w);l=[],l=y[1].points.map(w=>[w.x,w.y]),h=[],h=y[1].points.map(w=>new q.Vector3(w.x,w.y,w.z)),g=y[0]}let b=fe(h),x={points:h,path:ce(l),h:b.h,minz:b.minz,maxz:b.maxz,center:{x:b.x,y:b.y,z:b.z},obj_id:t[i].obj_id,type:a,averagePz:e,obb:null,isDel:!1,obj_id:u,positionArr:[t[i].position],isStaircaseBalconyRailing:!1};if(x.obb=ze(x.path,x.center,x.h,(x.maxz+x.minz)/2),x.obb==null)continue;let m=-1;for(let p=0;p<o.length;p++)if(o[p].type==a){m=p;break}if(m!=-1?o[m].array.push(x):o.push({type:a,array:[x]}),a=="floor"&&g!=-99999)if(r.has(g)){let p=r.get(g);p.num+=x.points.length,p.datas.push(x),r.set(g,p)}else r.set(g,{num:x.points.length,datas:[x]})}if(r.size>0){let i=[];for(let[l,u]of r.entries()){let{num:f,datas:d}=u;f>3e3&&i.push(...d)}for(let l=0;l<o.length;l++)if(o[l].type=="floor"){o[l].array=i;break}}for(let i=0;i<o.length;i++){let l=o[i].array,u=new Set,f=[];for(let c=0;c<l.length;c++){if(l[c].obb==null||u.has(c))continue;let a={...l[c],obb:l[c].obb.clone()},h=0,g=0;if(a.type=="pipe"){let x=Ve(a.points);h=x.minZ,g=x.maxZ}let b=!0;h!=0&&g!=0&&Math.abs(g-h)<.3&&(b=!1);for(let x=c+1;x<l.length;x++){if(l[x].obb==null||u.has(x))continue;let m=0,p=0;if(l[x].type=="pipe"){let z=Ve(l[x].points);m=z.minZ,p=z.maxZ}let y=!0;if(m!=0&&p!=0&&Math.abs(p-m)<.3&&(y=!1),a.type=="pipe"&&l[x].type=="pipe"&&b!=y)continue;let w=!1;if(a.type=="pipe"&&!b?w=Ie(l[x].points,a.obb)>.3:(w=a.obb.intersectsOBB(l[x].obb,.01),w||(w=tl(a.obb,l[x].obb))),w){u.add(x);for(let P=0;P<l[x].points.length;P++)(l[x].points[P].z>e&&l[x].points[P].z-e>.1||a.type=="floor"||a.type=="Staircase")&&a.points.push(l[x].points[P]);let z=a.points.map(P=>[P.x,P.y]);a.type=="floor"&&(z=ol(z,.1)),a.path=ce(z);let M=fe(a.points);a.h=M.h,a.minz=M.minz,a.maxz=M.maxz,a.center={x:M.x,y:M.y,z:M.z},a.obb=ze(a.path,a.center,a.h,(a.maxz+a.minz)/2),a.positionArr.push(...l[x].positionArr),x=c}}a.path.length>l[c].path.length&&(u.add(c),f.push(a))}let d=[];for(let c=0;c<l.length;c++)u.has(c)||d.push(l[c]);d.push(...f),o[i].array=d}for(let i=0;i<o.length;i++){let l=o[i].type;if(l==="people"||l==="floor")continue;let u=o[i].array;for(let f=0;f<u.length;f++){let d=u[f].obb,c=u[f].minz,a=u[f].maxz,h=u[f].averagePz;if(l==="window"||l==="door"||l==="tv"||l==="chair"||l==="cabinet"||l==="table"){let g=new q.Vector3;d.getSize(g);let b=[g.x,g.y,g.z],x=0;for(let m of b)if(m<.2&&(x++,x===2)){u[f].isDel=!0;break}}if(!u[f].isDel)for(let g=i+1;g<o.length;g++){let b=o[g].type;if(b==="people")continue;let x=o[g].array;for(let m=0;m<x.length;m++){if(x[m].isDel)continue;let p=x[m].obb,y=x[m].minz,w=x[m].maxz;if(d.intersectsOBB(p)){let z=Ie(x[m].points,d),M=Ie(u[f].points,p),P=No(d,p);if(M>=.5&&P==-1&&l!=="Staircase"&&b!=="Staircase"){u[f].isDel=!0;break}if(l!=="wall"&&l!=="floor"&&l!=="roof"){if(l==="window"){if(b==="balcony railing"&&Jt(d,x[m].points)){x[m].isDel=!0;continue}if(b==="balcony railing"&&Jt(p,u[f].points)){u[f].isDel=!0;break}if(b==="balcony railing"&&Fo(d,p,u[f].points,x[m].points)&&(Math.abs(c-y)<.1||Math.abs(y-h)>.3)){x[m].isDel=!0;continue}if(b==="door"&&Jt(d,x[m].points)){x[m].isDel=!0;continue}if(b==="door"&&Jt(p,u[f].points)){x[m].isDel=!0;continue}if(b==="window sill")continue}else if(l==="balcony railing"){if(b==="window"&&Jt(d,x[m].points)){x[m].isDel=!0;continue}if(b==="window"&&Jt(p,u[f].points)){u[f].isDel=!0;break}if(b==="window"&&Fo(d,p,u[f].points,x[m].points)&&(Math.abs(c-y)<.1||Math.abs(c-h)>.3)){u[f].isDel=!0;break}if(b==="Staircase"&&Jt(d,x[m].points)){u[f].isStaircaseBalconyRailing=!0;break}if(b==="Staircase"&&Jt(p,u[f].points)){u[f].isStaircaseBalconyRailing=!0;break}if(b==="Staircase"&&d.intersectsOBB(p)){u[f].isStaircaseBalconyRailing=!0;break}}else if(l==="door"){if(b==="window"&&Jt(d,x[m].points)){u[f].isDel=!0;break}if(b==="window"&&Jt(p,u[f].points)){u[f].isDel=!0;break}if(b==="window sill"&&Jt(d,x[m].points)){u[f].isDel=!0;break}if(b==="window sill"&&Jt(p,u[f].points)){u[f].isDel=!0;break}}else if(l==="window sill"){if(b==="window")continue;if(b==="floor"&&Jt(d,x[m].points)){x[m].isDel=!0;continue}if(b==="door"&&Jt(d,x[m].points)){x[m].isDel=!0;continue}if(b==="door"&&Jt(p,u[f].points)){x[m].isDel=!0;continue}}else if(l==="Staircase"){if(b==="balcony railing"&&Jt(d,x[m].points)){x[m].isStaircaseBalconyRailing=!0;continue}if(b==="balcony railing"&&Jt(p,u[f].points)){x[m].isStaircaseBalconyRailing=!0;continue}if(b==="balcony railing"&&d.intersectsOBB(p)){x[m].isStaircaseBalconyRailing=!0;continue}}let E=!1,S=[],I=[],W=u[f].points,v=x[m].points;if(W.length>v.length?(E=!0,S=W,I=v):(S=v,I=W),ja(I,S,.03,.5)>.5)if(E)x[m].isDel=!0;else{u[f].isDel=!0;break}else if(Fo(d,p,u[f].points,x[m].points)){let R=No(d,p);if(R===1||R===0){if(b==="switch"||b==="Staircase")continue;W.length>v.length?Ie(I,d)>=.5&&(x[m].isDel=!0):Ie(S,d)>=.5&&(x[m].isDel=!0)}else{if(l==="switch"||l==="Staircase")continue;if(W.length>v.length){if(Ie(S,p)>=.5){u[f].isDel=!0;break}}else if(Ie(I,p)>=.5){u[f].isDel=!0;break}}}}}}if(u[f].isDel)break}}}for(let i=0;i<o.length;i++){let l=o[i].type,u=o[i].array;for(let f=0;f<u.length;f++){let d=u[f].maxz,c=u[f].minz,a=l==="switch"?.1:.3;if(Math.abs(d-e)<a&&l!="floor"){u[f].isDel=!0;continue}if(l==="window"||l==="door"||l==="tv"){let h=Math.abs(d-e),g=Math.abs(c-e);(l==="tv"&&g<1.6||l!=="window"&&h<1.6)&&(u[f].isDel=!0),l==="window"&&h<1&&(u[f].isDel=!0),l==="door"&&g>1&&(u[f].isDel=!0)}if(l==="chair"){let h=new q.Vector3;u[f].obb.getSize(h),(h.x<.1||h.y<.1||h.z<.2)&&(u[f].isDel=!0)}if(l==="balcony railing"&&(Math.abs(d-c)<.4&&(u[f].isDel=!0),(c<e&&Math.abs(c-e)>1||c>e&&Math.abs(c-e)>1)&&(u[f].isDel=!0),d<e&&(u[f].isDel=!0)),l==="people"&&(Math.abs(d-c)<1&&(u[f].isDel=!0),c>e&&c-e>.3&&(u[f].isDel=!0),d<e&&(u[f].isDel=!0)),l==="floor"){let h=new q.Vector3;u[f].obb.getSize(h),(h.x<.1||h.y<.1)&&(u[f].isDel=!0)}l==="stair guardrail"&&u[f].points.length<100&&(u[f].isDel=!0)}}for(let i=0;i<o.length;i++)o[i].array=o[i].array.filter(l=>!l.isDel);if(n!=null)for(let i=0;i<o.length;i++){if(o[i].type=="floor")continue;let u=o[i].array,f=new Set,d=[];for(let c=0;c<u.length;c++){if(f.has(c))continue;let a=u[c].points,h=u[c].obj_id,g=u[c].type,b=u[c].averagePz,x=u[c].positionArr,m=u[c].isStaircaseBalconyRailing;if(a.length<50)continue;let p=n([a],{tolerance:.2,minClusterSize:50,maxClusterSize:1e7,threadCount:1}),y=d.length;if(p.length>0&&p[0].length>1)for(let w of p[0]){if(w.length<50)continue;let z=w.map(S=>a[S]),M=fe(z),P=z.map(S=>[S.x,S.y]),E={points:z,path:ce(P),h:M.h,minz:M.minz,maxz:M.maxz,center:{x:M.x,y:M.y,z:M.z},type:g,averagePz:b,obb:null,obj_id:h,positionArr:x,isStaircaseBalconyRailing:m};E.obb=ze(E.path,E.center,E.h,(E.maxz+E.minz)/2),E.obb!=null&&d.push(E)}d.length!=y&&f.add(c)}if(f.size>0){for(let c=0;c<u.length;c++)f.has(c)||d.push(u[c]);o[i].array=d}}let s=[];for(let i=0;i<o.length;i++){let l=o[i].array;for(let u=0;u<l.length;u++)s.push({obbBox:l[u].obb,box:new q.Box3().setFromPoints(l[u].points),category:l[u].type,center:{x:l[u].center.x,y:l[u].center.y,z:(l[u].minz+l[u].maxz)/2},name:l[u].obj_id,obj_id:l[u].obj_id,pcdPoints:l[u].points,positionArr:l[u].positionArr,isStaircaseBalconyRailing:l[u].isStaircaseBalconyRailing})}return s},Za=t=>{if(t.length==0)return[];let e=[],n=new Map;for(let r=0;r<t.length;r++){let s=t[r].points.map(x=>[x.x,x.y]),i=t[r].obj_id;i=i.replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor");let l=i.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],u=i.indexOf("_")+1,f=i.lastIndexOf("_"),d=i.substring(u,f);if(d!=="floor")continue;let c=[];for(let x=0;x<t[r].points.length;x++)c.push(new q.Vector3(t[r].points[x].x,t[r].points[x].y,t[r].points[x].z));let a=-99999;if(d==="floor"){let x=new Map;for(let p=0;p<t[r].points.length;p++){let y=t[r].points[p].z;if(y=Math.floor(y*10)/10,x.has(y)){let w=x.get(y);w.num+=1,w.points.push(t[r].points[p]),x.set(y,w)}else x.set(y,{num:1,points:[t[r].points[p]]})}let m=[...x.entries()].reduce((p,y)=>y[1].num>p[1].num?y:p);s=[],s=m[1].points.map(p=>[p.x,p.y]),c=[],c=m[1].points.map(p=>new q.Vector3(p.x,p.y,p.z)),a=m[0]}let h=fe(c),g={points:c,path:ce(s),h:h.h,minz:h.minz,maxz:h.maxz,center:{x:h.x,y:h.y,z:h.z},obj_id:t[r].obj_id,type:d,obb:null,isDel:!1,obj_id:i,positionArr:[t[r].position]};if(g.obb=ze(g.path,g.center,g.h,(g.maxz+g.minz)/2),g.obb==null)continue;let b=-1;for(let x=0;x<e.length;x++)if(e[x].type==d){b=x;break}if(b!=-1?e[b].array.push(g):e.push({type:d,array:[g]}),d=="floor"&&a!=-99999)if(n.has(a)){let x=n.get(a);x.num+=g.points.length,x.datas.push(g),n.set(a,x)}else n.set(a,{num:g.points.length,datas:[g]})}for(let r=0;r<e.length;r++){let s=e[r].array,i=[],l=[];for(let f=0;f<s.length;f++){if(s[f].obb==null||i.includes(f))continue;let d={...s[f],obb:s[f].obb.clone()};for(let c=f+1;c<s.length;c++){if(s[c].obb==null||i.includes(c))continue;if(d.obb.intersectsOBB(s[c].obb)){i.push(c);for(let b=0;b<s[c].points.length;b++)d.points.push(s[c].points[b]);let h=d.points.map(b=>[b.x,b.y]);d.path=ce(h);let g=fe(d.points);d.h=g.h,d.minz=g.minz,d.maxz=g.maxz,d.center={x:g.x,y:g.y,z:g.z},d.obb=ze(d.path,d.center,d.h,(d.maxz+d.minz)/2),d.positionArr.push(...s[c].positionArr),c=f}}d.path.length>s[f].path.length&&(i.push(f),l.push(d))}let u=[];for(let f=0;f<s.length;f++)i.includes(f)||u.push(s[f]);u.push(...l),e[r].array=u}for(let r=0;r<e.length;r++){let s=e[r].type,i=e[r].array;for(let l=0;l<i.length;l++)s==="floor"&&i[l].points.length<500&&(i[l].isDel=!0)}for(let r=0;r<e.length;r++)e[r].array=e[r].array.filter(s=>!s.isDel);let o=[];for(let r=0;r<e.length;r++){let s=e[r].array;for(let i=0;i<s.length;i++)o.push({obbBox:s[i].obb,box:new q.Box3().setFromPoints(s[i].points),category:s[i].type,center:{x:s[i].center.x,y:s[i].center.y,z:(s[i].minz+s[i].maxz)/2},name:s[i].obj_id,obj_id:s[i].obj_id,pcdPoints:s[i].points,positionArr:s[i].positionArr})}return o},Ga=(t,e)=>{if(!t||!t.splitFloorProjectsResults||!t.trajectoryResults)return[];let n=t.splitFloorProjectsResults,o=t.trajectoryResults,r=new Map;for(let a=0;a<o.length;a++){let h=o[a].floor;r.has(h)?r.get(h).push(o[a]):r.set(h,[o[a]])}let s=new Map,i=[];for(let a=0;a<n.length;a++){let h=[],g=n[a];for(let b=0;b<g.length;b++){let x=g[b].points.map(S=>[S.x,S.y]),m=g[b].obj_id;m=m.replace(/the floor of the house/g,"floor").replace(/the outdoor floor/g,"floor").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");let p=m.split("_").slice(1,3).join("_").split(".")[0].split("_")[0],y=m.indexOf("_")+1,w=m.lastIndexOf("_"),z=m.substring(y,w);if(z.includes("top")&&(y=z.indexOf("top")+4,z=z.substring(y,w)),z.includes("left")&&(y=z.indexOf("left")+5,z=z.substring(y,w)),z.includes("right")&&(y=z.indexOf("right")+6,z=z.substring(y,w)),z.includes("front")&&(y=z.indexOf("front")+6,z=z.substring(y,w)),z!=="Staircase"&&z!=="balcony railing")continue;let M=[];for(let S=0;S<g[b].points.length;S++)M.push(new q.Vector3(g[b].points[S].x,g[b].points[S].y,g[b].points[S].z));let P=fe(M),E={points:M,path:ce(x),h:P.h,minz:P.minz,maxz:P.maxz,center:{x:P.x,y:P.y,z:P.z},obj_id:g[b].obj_id,type:z,averagePz:0,obb:null,isDel:!1,obj_id:m,positionArr:[g[b].position],aabbBox:new q.Box3().setFromPoints(M)};E.obb=ze(E.path,E.center,E.h,(E.maxz+E.minz)/2),E.obb!=null&&(z=="Staircase"?h.push(E):z=="balcony railing"&&i.push(E))}s.set(a+1,h)}let l=[];for(let[a,h]of s){let g={floor:a,findTrajectoryResults:[],otherTrajectoryResults:[],lastTrajectoryResults:[]},b=r.get(a);if(!b){g.otherTrajectoryResults=h,l.push(g);continue}let x=[],m=[],p=[];for(let y=0;y<b.length;y++){let w=[];for(let M=0;M<b[y].points.length;M++){let P=[new q.Vector3(b[y].points[M].x,b[y].points[M].y,b[y].points[M].z)];P.push(P[0].clone().addScaledVector(new q.Vector3(0,0,-1),2));let E=new q.Box3().setFromPoints(P);w.push(E)}let z=[];for(let M=0;M<h.length;M++)for(let P=0;P<w.length;P++)!p.includes(M)&&h[M].aabbBox.intersectsBox(w[P])&&(p.push(M),z.push(h[M]));z.length>0&&m.push(z)}for(let y=0;y<h.length;y++)p.includes(y)||x.push(h[y]);g.findTrajectoryResults=m,g.otherTrajectoryResults=x,l.push(g)}function u(a,h){let g=a,b=[],x=[];for(let p=0;p<a.length;p++){if(a[p].obb==null||b.includes(p))continue;let y={...a[p],obb:a[p].obb.clone()};for(let w=p+1;w<a.length;w++){if(a[w].obb==null||b.includes(w))continue;if(y.obb.intersectsOBB(a[w].obb)||h){b.push(w);for(let E=0;E<a[w].points.length;E++)y.points.push(a[w].points[E]);let M=y.points.map(E=>[E.x,E.y]);y.path=ce(M);let P=fe(y.points);y.h=P.h,y.minz=P.minz,y.maxz=P.maxz,y.center={x:P.x,y:P.y,z:P.z},y.obb=ze(y.path,y.center,y.h,(y.maxz+y.minz)/2),y.positionArr.push(...a[w].positionArr),w=p}}y.path.length>a[p].path.length&&(b.push(p),x.push(y))}let m=[];for(let p=0;p<a.length;p++)b.includes(p)||m.push(a[p]);return m.push(...x),a=m,a}for(let a=0;a<l.length;a++){for(let h=0;h<l[a].findTrajectoryResults.length;h++)l[a].findTrajectoryResults[h]=u(l[a].findTrajectoryResults[h],!0);l[a].otherTrajectoryResults=u(l[a].otherTrajectoryResults,!1)}for(let a=0;a<l.length;a++){for(let h=0;h<l[a].findTrajectoryResults.length;h++){for(let g=0;g<l[a].findTrajectoryResults[h].length;g++){let b=Ts(l[a].findTrajectoryResults[h][g].points,{binCount:100,minBinPoints:5,sideK:2.2,zK:2.2,minSideRange:.2,minZRange:.2,lowerZScale:.4,upperZScale:1.8}),x=Ss(b.keep,{radius:.1,minClusterSize:50,lowPercent:.45});if(x.keep.length==0){l[a].findTrajectoryResults[h][g].isDel=!0;continue}l[a].findTrajectoryResults[h][g].points=x.keep;let m=l[a].findTrajectoryResults[h][g].points.map(y=>[y.x,y.y]);l[a].findTrajectoryResults[h][g].path=ce(m);let p=fe(l[a].findTrajectoryResults[h][g].points);l[a].findTrajectoryResults[h][g].h=p.h,l[a].findTrajectoryResults[h][g].minz=p.minz,l[a].findTrajectoryResults[h][g].maxz=p.maxz,l[a].findTrajectoryResults[h][g].center={x:p.x,y:p.y,z:p.z},l[a].findTrajectoryResults[h][g].obb=ze(l[a].findTrajectoryResults[h][g].path,l[a].findTrajectoryResults[h][g].center,l[a].findTrajectoryResults[h][g].h,(l[a].findTrajectoryResults[h][g].maxz+l[a].findTrajectoryResults[h][g].minz)/2)}l[a].findTrajectoryResults[h]=l[a].findTrajectoryResults[h].filter(g=>!g.isDel)}for(let h=0;h<l[a].otherTrajectoryResults.length;h++){let g=Ts(l[a].otherTrajectoryResults[h].points,{binCount:100,minBinPoints:5,sideK:2.2,zK:2.2,minSideRange:.2,minZRange:.2,lowerZScale:.4,upperZScale:1.8}),b=Ss(g.keep,{radius:.1,minClusterSize:50,lowPercent:.45});if(b.keep.length==0){l[a].otherTrajectoryResults[h].isDel=!0;continue}l[a].otherTrajectoryResults[h].points=b.keep;let x=l[a].otherTrajectoryResults[h].points.map(p=>[p.x,p.y]);l[a].otherTrajectoryResults[h].path=ce(x);let m=fe(l[a].otherTrajectoryResults[h].points);l[a].otherTrajectoryResults[h].h=m.h,l[a].otherTrajectoryResults[h].minz=m.minz,l[a].otherTrajectoryResults[h].maxz=m.maxz,l[a].otherTrajectoryResults[h].center={x:m.x,y:m.y,z:m.z},l[a].otherTrajectoryResults[h].obb=ze(l[a].otherTrajectoryResults[h].path,l[a].otherTrajectoryResults[h].center,l[a].otherTrajectoryResults[h].h,(l[a].otherTrajectoryResults[h].maxz+l[a].otherTrajectoryResults[h].minz)/2)}l[a].otherTrajectoryResults.filter(h=>!h.isDel)}function f(a){for(let h=0;h<a.length;h++){let g=a[h].obb;for(let b=h+1;b<a.length;b++){let x=a[b].obb;if(!a[b].isDel){if(g.intersectsOBB(x)){let m=Ie(a[b].points,g),p=Ie(a[h].points,x),y=No(g,x);if(m>=.5&&(y==1||y==0)&&(a[b].isDel=!0),p>=.5&&y==-1){a[h].isDel=!0;break}}if(a[h].isDel)break}}}return a=a.filter(h=>!h.isDel),a}for(let a=0;a<l.length;a++){let h=[];for(let g=0;g<l[a].findTrajectoryResults.length;g++)h.push(...l[a].findTrajectoryResults[g]);h.push(...l[a].otherTrajectoryResults),l[a].lastTrajectoryResults=f(h)}function d(a){let h=[];if(a.length>0){let g=.3,b=.5,x=.5,m=.2;for(let p=0;p<a.length;p++){let y=a[p].obb.halfSize.clone().multiplyScalar(2),w=a[p].points,z=y.x,M=y.y,P=y.z;if(z>M&&([z,M]=[M,z]),z<b||M<g||P<x)continue;let E=Er(a[p].obb);if(E.length!=8)continue;let S=new q.Line3(E[0],E[1]),I=new q.Line3(E[1],E[2]),W=new q.Line3(E[2],E[3]),v=new q.Line3(E[3],E[0]),T=new q.Line3(E[4],E[5]),R=new q.Line3(E[5],E[6]),D=new q.Line3(E[6],E[7]),H=new q.Line3(E[7],E[4]),V=[],C=[],_=[],A=[],B=[],k=[],F=[],L=[];for(let wt=0;wt<w.length;wt++){let te=S.closestPointToPoint(w[wt],!0,new q.Vector3),ge=I.closestPointToPoint(w[wt],!0,new q.Vector3),Dt=W.closestPointToPoint(w[wt],!0,new q.Vector3),ne=v.closestPointToPoint(w[wt],!0,new q.Vector3),xe=T.closestPointToPoint(w[wt],!0,new q.Vector3),tt=R.closestPointToPoint(w[wt],!0,new q.Vector3),mn=D.closestPointToPoint(w[wt],!0,new q.Vector3),Je=H.closestPointToPoint(w[wt],!0,new q.Vector3);te.distanceTo(w[wt])<m&&V.push(w[wt]),ge.distanceTo(w[wt])<m&&C.push(w[wt]),Dt.distanceTo(w[wt])<m&&_.push(w[wt]),ne.distanceTo(w[wt])<m&&A.push(w[wt]),xe.distanceTo(w[wt])<m&&B.push(w[wt]),tt.distanceTo(w[wt])<m&&k.push(w[wt]),mn.distanceTo(w[wt])<m&&F.push(w[wt]),Je.distanceTo(w[wt])<m&&L.push(w[wt])}let O=E[0].distanceTo(E[1]),$=E[1].distanceTo(E[2]),Z=E[2].distanceTo(E[3]),Q=E[3].distanceTo(E[0]),j=new q.Vector3,X=new q.Vector3,U=new q.Vector3,lt=new q.Vector3;Math.abs(O-z)<.01?V.length>_.length?(j=E[0].clone(),X=E[1].clone(),U=new q.Vector3().subVectors(X,j).normalize(),lt=new q.Vector3().subVectors(E[2],E[1]).normalize()):(j=E[2].clone(),X=E[3].clone(),U=new q.Vector3().subVectors(X,j).normalize(),lt=new q.Vector3().subVectors(E[0],E[3]).normalize()):C.length>A.length?(j=E[1].clone(),X=E[2].clone(),U=new q.Vector3().subVectors(X,j).normalize(),lt=new q.Vector3().subVectors(E[3],E[2]).normalize()):(j=E[3].clone(),X=E[0].clone(),U=new q.Vector3().subVectors(X,j).normalize(),lt=new q.Vector3().subVectors(E[1],E[0]).normalize());let mt=E[4].distanceTo(E[5]),St=E[5].distanceTo(E[6]),ot=E[6].distanceTo(E[7]),Mt=E[7].distanceTo(E[4]),bt=new q.Vector3,Ct=new q.Vector3,Et=new q.Vector3(j.x,j.y,E[4].z),zt=new q.Vector3(X.x,X.y,E[4].z);(ct(E[4],Et)||ct(E[4],zt))&&(ct(E[5],Et)||ct(E[5],zt))?(bt=E[6].clone(),Ct=E[7].clone()):(ct(E[5],Et)||ct(E[5],zt))&&(ct(E[6],Et)||ct(E[6],zt))?(bt=E[7].clone(),Ct=E[4].clone()):(ct(E[6],Et)||ct(E[6],zt))&&(ct(E[7],Et)||ct(E[7],zt))?(bt=E[4].clone(),Ct=E[5].clone()):(ct(E[7],Et)||ct(E[7],zt))&&(ct(E[4],Et)||ct(E[4],zt))&&(bt=E[5].clone(),Ct=E[6].clone());let Pt=j.distanceTo(X),et=bt.distanceTo(Ct),ht=new q.Vector3().subVectors(new q.Vector3(j.x,j.y,bt.z),j).normalize();if(Math.abs(Pt-et)>.01||Math.abs(Pt-z)>.01){console.log("\u4E0A\u4E0B\u957F\u5EA6\u4E0D\u4E00\u81F4,\u6216\u4E0E\u5BBD\u4E0D\u4E00\u81F4",Pt,et,z);continue}let nt=Math.sqrt(Pt*Pt+et*et),J=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(nt)))),ae={stairStepHeight:P/J,stairStepWidth:M/J,staitWidth:z,stairLength:M,stairHeigth:P,stairStepNum:J,stairBottomPt1:j,stairBottomPt2:X,stairTopPt1:bt,stairTopPt2:Ct,vecStepLength:U,vecStepWidth:lt,vecStepHeight:ht,path:a[p].path,obb:a[p].obb,maxz:a[p].maxz,points:a[p].points,rectPt1:new q.Vector3(0,0,0),rectPt2:new q.Vector3(0,0,0)};h.push(ae)}}return h}let c=[];for(let a=0;a<l.length;a++)c.push(...d(l[a].lastTrajectoryResults));for(let a=0;a<c.length;a++){let h=c[a].stairTopPt1.clone(),g=c[a].stairTopPt2.clone(),b=c[a].stairBottomPt1.clone(),x=c[a].stairBottomPt2.clone(),m=h.clone(),p=g.clone(),y=b.clone(),w=x.clone();m.z=p.z=y.z=w.z=0;let z=At(h,g,!0),M=At(b,x,!0),P=At(z,M),E=new q.Vector3().subVectors(z,P).normalize(),S=new q.Vector3().subVectors(M,P).normalize(),I=z.distanceTo(M),W=!1,v=!1;for(let T=0;T<c.length;T++){if(a==T)continue;let R=c[T].stairTopPt1.clone(),D=c[T].stairTopPt2.clone(),H=c[T].stairBottomPt1.clone(),V=c[T].stairBottomPt2.clone(),C=new q.Vector3().subVectors(R,D).normalize(),_=new q.Vector3().subVectors(H,V).normalize(),A=R.clone(),B=D.clone(),k=H.clone(),F=V.clone();A.z=B.z=k.z=F.z=0;let L=At(R,D,!0),O=At(H,V,!0),$=L.distanceTo(O),Z=Zt(z,M,L,O),Q=!1;if(Z&&Z.isParallel&&R.z<=b.z&&b.z-R.z<.3){Q=!0,v=!0;let j=A.addScaledVector(C.clone().negate(),100),X=B.addScaledVector(C,100),U=k.addScaledVector(_.clone().negate(),100),lt=F.addScaledVector(_,100),mt=new q.Line3(j,X),St=new q.Line3(U,lt),ot=mt.closestPointToPoint(P,!0,new q.Vector3),Mt=St.closestPointToPoint(P,!0,new q.Vector3),bt=new q.Vector3().subVectors(ot,P),Ct=new q.Vector3().subVectors(Mt,P),Et=bt.length(),zt=Ct.length();Ct=Ct.normalize(),bt=bt.normalize();let Pt=Xt(E,bt,.1),et=Xt(S,bt,.1),ht=Xt(S,Ct,.1),nt=Xt(E,Ct,.1);if(Pt&&Pt.sameDirection&&Et>I/2){let J=Et-I/2;c[a].stairBottomPt1=c[a].stairBottomPt1.addScaledVector(S,J),c[a].stairBottomPt2=c[a].stairBottomPt2.addScaledVector(S,J)}else if(et&&et.sameDirection&&Et>I/2){let J=Et-I/2;c[a].stairBottomPt1=c[a].stairBottomPt1.addScaledVector(S,J),c[a].stairBottomPt2=c[a].stairBottomPt2.addScaledVector(S,J)}if(ht&&ht.sameDirection&&zt>I/2){let J=zt-I/2;c[a].stairTopPt1=c[a].stairTopPt1.addScaledVector(E,J),c[a].stairTopPt2=c[a].stairTopPt2.addScaledVector(E,J)}else if(nt&&nt.sameDirection&&zt>I/2){let J=zt-I/2;c[a].stairTopPt1=c[a].stairTopPt1.addScaledVector(E,J),c[a].stairTopPt2=c[a].stairTopPt2.addScaledVector(E,J)}}else if(Z&&Z.isParallel&&h.z<H.z&&H.z-h.z<.2){Q=!0,W=!0;let j=A.addScaledVector(C.clone().negate(),100),X=B.addScaledVector(C,100),U=k.addScaledVector(_.clone().negate(),100),lt=F.addScaledVector(_,100),mt=new q.Line3(j,X),St=new q.Line3(U,lt),ot=mt.closestPointToPoint(P,!1,new q.Vector3),Mt=St.closestPointToPoint(P,!1,new q.Vector3),bt=new q.Vector3().subVectors(ot,P),Ct=new q.Vector3().subVectors(Mt,P),Et=bt.length(),zt=Ct.length();Ct=Ct.normalize(),bt=bt.normalize();let Pt=Xt(E,bt,.1),et=Xt(S,bt,.1),ht=Xt(S,Ct,.1),nt=Xt(E,Ct,.1);if(Pt&&Pt.sameDirection&&Et>I/2){let J=Et-I/2;c[a].stairBottomPt1=c[a].stairBottomPt1.addScaledVector(S,J),c[a].stairBottomPt2=c[a].stairBottomPt2.addScaledVector(S,J)}else if(et&&et.sameDirection&&Et>I/2){let J=Et-I/2;c[a].stairBottomPt1=c[a].stairBottomPt1.addScaledVector(S,J),c[a].stairBottomPt2=c[a].stairBottomPt2.addScaledVector(S,J)}if(ht&&ht.sameDirection&&zt>I/2){let J=zt-I/2;c[a].stairTopPt1=c[a].stairTopPt1.addScaledVector(E,J),c[a].stairTopPt2=c[a].stairTopPt2.addScaledVector(E,J)}else if(nt&&nt.sameDirection&&zt>I/2){let J=zt-I/2;c[a].stairTopPt1=c[a].stairTopPt1.addScaledVector(E,J),c[a].stairTopPt2=c[a].stairTopPt2.addScaledVector(E,J)}c[a].stairTopPt1.z=c[a].stairTopPt2.z=H.z}if(Q&&(h=c[a].stairTopPt1.clone(),g=c[a].stairTopPt2.clone(),b=c[a].stairBottomPt1.clone(),x=c[a].stairBottomPt2.clone(),m=h.clone(),p=g.clone(),y=b.clone(),w=x.clone(),m.z=p.z=y.z=w.z=0,z=At(h,g,!0),M=At(b,x,!0),P=At(z,M),E=new q.Vector3().subVectors(z,P).normalize(),S=new q.Vector3().subVectors(M,P).normalize(),I=z.distanceTo(M)),v&&W)break}if(v||W){let T=c[a].stairTopPt1.clone(),R=c[a].stairTopPt2.clone(),D=c[a].stairBottomPt1.clone(),H=c[a].stairBottomPt2.clone(),V=At(T,R,!0),C=At(D,H,!0),_=V.distanceTo(C),A=c[a].stairTopPt1.distanceTo(c[a].stairTopPt2),B=c[a].stairBottomPt1.distanceTo(c[a].stairBottomPt2),k=Math.sqrt(A*A+B*B),F=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(k))));c[a].stairStepNum=F,c[a].stairHeigth=c[a].stairTopPt1.z-c[a].stairBottomPt1.z,c[a].stairStepHeight=c[a].stairHeigth/c[a].stairStepNum,c[a].stairStepWidth=_/c[a].stairStepNum}}for(let a=0;a<c.length;a++){let h=c[a].stairTopPt1,g=c[a].stairTopPt2,b=c[a].stairBottomPt1.clone(),x=c[a].stairBottomPt2.clone(),m=new q.Vector3(h.x,h.y,b.z),p=c[a].vecStepWidth;for(let y=0;y<c.length;y++){if(a==y)continue;let w=c[y].stairTopPt1,z=c[y].stairTopPt2,M=c[y].stairBottomPt1.clone(),P=c[y].stairBottomPt2.clone(),E=new q.Vector3(w.x,w.y,M.z),S=c[y].vecStepWidth;if(Math.abs(h.z-M.z)<.3&&M.z>b.z&&c[a].obb.intersectsOBB(c[y].obb)){let I=ie(m,b,E,M);if(I&&I.angle>75){let W=M.distanceTo(h),v=M.distanceTo(g),T=P.distanceTo(h),R=P.distanceTo(g),D=h.clone(),H=D.clone().addScaledVector(p,c[y].staitWidth),V=new q.Vector3().subVectors(g,h).normalize(),C=h.distanceTo(g),_=D.clone().addScaledVector(V,C),A=H.clone().addScaledVector(V,C),B=D.clone().addScaledVector(V,c[y].stairLength),k=H.clone().addScaledVector(V,c[y].stairLength),F=W;(F>v||F>R)&&(F=v,D=g.clone(),H=D.clone().addScaledVector(p,c[y].staitWidth),V=new q.Vector3().subVectors(h,g).normalize(),C=h.distanceTo(g),_=D.clone().addScaledVector(V,C),A=H.clone().addScaledVector(V,C),B=D.clone().addScaledVector(V,c[y].stairLength),k=H.clone().addScaledVector(V,c[y].stairLength));let L=new q.Vector3().subVectors(B,_).normalize(),O=B.distanceTo(_);B.z=k.z=c[y].maxz,c[y].stairBottomPt1=_,c[y].stairBottomPt2=A,c[y].stairTopPt1=B,c[y].stairTopPt2=k,c[y].rectPt1=D,c[y].rectPt2=H;let $=_.distanceTo(A),Z=B.distanceTo(k),Q=Math.sqrt(O*O+c[y].stairHeigth*c[y].stairHeigth),j=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(Q))));c[y].stairStepNum=j,c[y].stairHeigth=B.z-_.z,c[y].stairStepHeight=c[y].stairHeigth/c[y].stairStepNum,c[y].stairStepWidth=O/c[y].stairStepNum,c[y].vecStepLength=V.clone().negate(),c[y].vecStepWidth=L;break}}}}return t.finalFloorMap&&Ua(c,t.finalFloorMap),Ya(c,i,e),c},Ya=(t,e,n)=>{if(!t||t.length<=0||!e||e.length<=0)return;let o=1.5,r=0;for(let s=0;s<t.length;s++){t[s].stairBottom1BalconyRailing=[],t[s].stairBottom2BalconyRailing=[],t[s].balconyRailingHeight=0;let i=t[s].stairBottomPt1.clone(),l=t[s].stairBottomPt2.clone(),u=t[s].stairBottomPt1.clone(),f=t[s].stairBottomPt2.clone(),d=new q.Vector3().subVectors(l,i).normalize();i=i.addScaledVector(d,.05),l=l.addScaledVector(d.clone().negate(),.05);let c=[],a=[];for(let h=0;h<t[s].stairStepNum;h++){let g=[i,u];g.push(g[1].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),g.push(g[0].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth));let b=g.map(z=>[z.x,z.y]);g.push(new q.Vector3(g[3].x,g[3].y,g[3].z+o)),g.push(new q.Vector3(g[2].x,g[2].y,g[2].z+o)),g.push(new q.Vector3(g[1].x,g[1].y,g[1].z+o)),g.push(new q.Vector3(g[0].x,g[0].y,g[0].z+o));let x=fe(g),m=ze(b,{x:x.x,y:x.y,z:x.z},x.h,(x.maxz+x.minz)/2),p=[],y=!1,w=0;for(let z=0;z<e.length;z++)if(m.intersectsOBB(e[z].obb)){for(let M=0;M<e[z].points.length&&!(m.containsPoint(e[z].points[M])&&(h==0&&p.push(e[z].points[M]),e[z].points[M].z>i.z&&e[z].points[M].z-i.z<1&&(w++,w>10&&h!=0)));M++);if(w>10&&(y=!0),h!=0&&y)break}if(r==0&&(r=fe(p).maxz),y){let z=At(g[1],g[2]);z.z+=t[s].stairStepHeight,c.push(z)}g=[],g=[l,f],g.push(g[1].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),g.push(g[0].clone().addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth)),b=g.map(z=>[z.x,z.y]),g.push(new q.Vector3(g[3].x,g[3].y,g[3].z+o)),g.push(new q.Vector3(g[2].x,g[2].y,g[2].z+o)),g.push(new q.Vector3(g[1].x,g[1].y,g[1].z+o)),g.push(new q.Vector3(g[0].x,g[0].y,g[0].z+o)),x=fe(g),m=ze(b,{x:x.x,y:x.y,z:x.z},x.h,(x.maxz+x.minz)/2),p=[],y=!1;for(let z=0;z<e.length;z++)if(m.intersectsOBB(e[z].obb)){let M=0;for(let P=0;P<e[z].points.length&&!(m.containsPoint(e[z].points[P])&&(h==0&&p.push(e[z].points[P]),e[z].points[P].z>i.z&&e[z].points[P].z-i.z<1&&(M++,M>10&&h!=0)));P++);if(M>10&&(y=!0),h!=0&&y)break}if(r==0&&(r=fe(p).maxz),y){let z=At(g[1],g[2]);z.z+=t[s].stairStepHeight,a.push(z)}i=i.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),i=i.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),l=l.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),l=l.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),u=u.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),u=u.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight),f=f.addScaledVector(t[s].vecStepWidth,t[s].stairStepWidth),f=f.addScaledVector(t[s].vecStepHeight,t[s].stairStepHeight)}c.length>t[s].stairStepNum-3&&(t[s].stairBottom1BalconyRailing=c),a.length>t[s].stairStepNum-3&&(t[s].stairBottom2BalconyRailing=a),t[s].balconyRailingHeight=r}};function Ua(t,e){if(!t||!e)return;let n=[];for(let o=0;o<t.length;o++){let r=t[o].stairTopPt1.clone(),s=t[o].stairTopPt2.clone(),i=t[o].stairBottomPt1.clone(),l=t[o].stairBottomPt2.clone(),u=r.clone(),f=s.clone(),d=i.clone(),c=l.clone();u.z=f.z=d.z=c.z=0;let a=At(r,s,!0),h=At(i,l,!0),g=At(a,h),b=new q.Vector3().subVectors(a,g).normalize(),x=new q.Vector3().subVectors(h,g).normalize(),m=a.distanceTo(h),p=-1,y=-1;for(let w=0;w<t.length;w++){if(o==w)continue;let z=t[w].stairTopPt1.clone(),M=t[w].stairTopPt2.clone(),P=t[w].stairBottomPt1.clone(),E=t[w].stairBottomPt2.clone(),S=new q.Vector3().subVectors(z,M).normalize(),I=new q.Vector3().subVectors(P,E).normalize(),W=z.clone(),v=M.clone(),T=P.clone(),R=E.clone();W.z=v.z=T.z=R.z=0;let D=At(z,M,!0),H=At(P,E,!0),V=D.distanceTo(H),C=Zt(a,h,D,H);if(C&&C.isParallel&&r.z<=P.z&&P.z-r.z<=.2?p=w:C&&C.isParallel&&z.z<=i.z&&i.z-z.z<=.3&&(y=w),p!=-1&&y!=-1)break}for(let w=0;w<e.length;w++){let z=e[w][1];for(let M=0;M<z.length;M++){let P=`${w}+${M}`;if(n.includes(P))continue;let E=z[M].points;if(o==0&&Math.abs(E[0].z-i.z)<.2){let S=i.clone().addScaledVector(t[o].vecStepWidth.clone().negate(),5),I=l.clone().addScaledVector(t[o].vecStepWidth.clone().negate(),5),W=new q.Line3(S,I),v=new q.Line3(i,l),T=999999,R=0,D=new q.Vector3,H=0;for(let V=0;V<E.length;V++){let C=new q.Vector3(E[V].x,E[V].y,S.z),A=W.closestPointToPoint(C,!1,new q.Vector3).distanceTo(C),B=v.closestPointToPoint(C,!1,new q.Vector3),k=new q.Vector3().subVectors(C,B).normalize(),F=Xt(k,t[o].vecStepWidth.clone().negate(),.1);A<T&&F.sameDirection&&(T=A,R=C.distanceTo(B),D=C.clone(),H=E[V].z)}T!=-999999&&(n.push(P),t[o].stairBottomPt1.z=t[o].stairBottomPt2.z=H)}else if(Math.abs(E[0].z-r.z)<.2){let S=r.clone().addScaledVector(t[o].vecStepWidth,5),I=s.clone().addScaledVector(t[o].vecStepWidth,5),W=new q.Line3(S,I),v=new q.Line3(r,s),T=0,R=999999,D=new q.Vector3,H=0;for(let V=0;V<E.length;V++){let C=new q.Vector3(E[V].x,E[V].y,S.z),_=W.closestPointToPoint(C,!1,new q.Vector3),A=v.closestPointToPoint(C,!1,new q.Vector3),B=new q.Vector3().subVectors(C,A).normalize(),k=_.distanceTo(C),F=Xt(B,t[o].vecStepWidth);k<R&&F.sameDirection&&(R=k,T=C.distanceTo(A),D=C,H=E[V].z)}if(R!=-999999){if(n.push(P),t[o].stairTopPt1.z=t[o].stairTopPt2.z=H,p!=-1){t[p].stairBottomPt1.z=t[p].stairBottomPt2.z=H;let V=[t[o].stairTopPt1.clone(),t[o].stairTopPt2.clone(),t[p].stairBottomPt1.clone(),t[p].stairBottomPt2.clone()],C=We(V);C.length==2&&(t[o].stairTopFloorPts=C,t[o].stairTopFloorPts.push(t[o].stairTopFloorPts[1].clone().addScaledVector(t[o].vecStepWidth,T)),t[o].stairTopFloorPts.push(t[o].stairTopFloorPts[0].clone().addScaledVector(t[o].vecStepWidth,T)))}else t[o].stairTopFloorPts=[t[o].stairTopPt1.clone(),t[o].stairTopPt2.clone()],t[o].stairTopFloorPts.push(t[o].stairTopPt2.clone().addScaledVector(t[o].vecStepWidth,T)),t[o].stairTopFloorPts.push(t[o].stairTopPt1.clone().addScaledVector(t[o].vecStepWidth,T));if(t[o].stairTopFloorPts)for(let V=0;V<t[o].stairTopFloorPts.length;V++)t[o].stairTopFloorPts[V].z-=t[o].stairStepHeight;break}}}}if(p!=-1){let w=t[o].stairTopPt1.clone(),z=t[o].stairTopPt2.clone(),M=t[o].stairBottomPt1.clone(),P=t[o].stairBottomPt2.clone(),E=At(w,z,!0),S=At(M,P,!0),I=E.distanceTo(S),W=t[o].stairTopPt1.distanceTo(t[o].stairTopPt2),v=t[o].stairBottomPt1.distanceTo(t[o].stairBottomPt2),T=Math.sqrt(W*W+v*v),R=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(T))));t[o].stairStepNum=R,t[o].stairHeigth=t[o].stairTopPt1.z-t[o].stairBottomPt1.z,t[o].stairStepHeight=t[o].stairHeigth/t[o].stairStepNum,t[o].stairStepWidth=I/t[o].stairStepNum;let D=t[p].stairTopPt1.clone(),H=t[p].stairTopPt2.clone(),V=t[p].stairBottomPt1.clone(),C=t[p].stairBottomPt2.clone(),_=At(D,H,!0),A=At(V,C,!0),B=_.distanceTo(A),k=t[p].stairTopPt1.distanceTo(t[p].stairTopPt2),F=t[p].stairBottomPt1.distanceTo(t[p].stairBottomPt2),L=Math.sqrt(k*k+F*F),O=Math.round(Math.max(5,Math.min(350,10*Math.sqrt(L))));t[p].stairStepNum=O,t[p].stairHeigth=t[p].stairTopPt1.z-t[p].stairBottomPt1.z,t[p].stairStepHeight=t[p].stairHeigth/t[p].stairStepNum,t[p].stairStepWidth=B/t[p].stairStepNum}}}function Ts(t,e={}){let{binCount:n=80,minBinPoints:o=5,sideK:r=3,zK:s=3,minSideRange:i=.2,minZRange:l=.2,maxSearchBins:u=3,lowerZScale:f=1,upperZScale:d=1}=e;if(!t||t.length===0)return[];let c=t.map((_,A)=>({index:A,x:_.x,y:_.y,z:_.z,raw:_})),a=0,h=0;for(let _ of c)a+=_.x,h+=_.y;a/=c.length,h/=c.length;let g=0,b=0,x=0;for(let _ of c){let A=_.x-a,B=_.y-h;g+=A*A,b+=A*B,x+=B*B}g/=c.length,b/=c.length,x/=c.length;let m=g+x,p=Math.sqrt((g-x)*(g-x)+4*b*b),y=(m+p)/2,w,z;Math.abs(b)>1e-8?(w=y-x,z=b):g>=x?(w=1,z=0):(w=0,z=1);let M=Math.sqrt(w*w+z*z)||1;w/=M,z/=M;let P=-z,E=w,S=1/0,I=-1/0,W=c.map(_=>{let A=_.x-a,B=_.y-h,k=A*w+B*z,F=A*P+B*E;return S=Math.min(S,k),I=Math.max(I,k),{..._,t:k,side:F}}),T=(I-S||1)/n,R=new Map;for(let _ of W){let A=Math.floor((_.t-S)/T);A<0&&(A=0),A>=n&&(A=n-1),R.has(A)||R.set(A,[]),R.get(A).push(_)}let D=new Map;for(let[_,A]of R){if(A.length<o)continue;let B=A.map(j=>j.side).sort((j,X)=>j-X),k=A.map(j=>j.z).sort((j,X)=>j-X),F=oo(B),L=oo(k),O=oo(B.map(j=>Math.abs(j-F)).sort((j,X)=>j-X)),$=oo(k.map(j=>Math.abs(j-L)).sort((j,X)=>j-X)),Z=Math.max(i,O*1.4826*r),Q=Math.max(l,$*1.4826*s);D.set(_,{sideMedian:F,zMedian:L,sideRange:Z,zRange:Q})}function H(_){if(D.has(_))return D.get(_);for(let A=1;A<=u;A++){if(D.has(_-A))return D.get(_-A);if(D.has(_+A))return D.get(_+A)}return null}let V=[],C=[];for(let _ of W){let A=Math.floor((_.t-S)/T);A<0&&(A=0),A>=n&&(A=n-1);let B=H(A);if(!B){C.push(_.raw);continue}let k=Math.abs(_.side-B.sideMedian)<=B.sideRange,F=B.zMedian-B.zRange*f,L=B.zMedian+B.zRange*d,O=_.z>=F&&_.z<=L;k&&O?V.push(_.raw):C.push(_.raw)}return{keep:V,removed:C,debug:{meanX:a,meanY:h,dirX:w,dirY:z,sideX:P,sideY:E,minT:S,maxT:I,binSize:T,stats:D}}}function oo(t){if(t.length===0)return 0;let e=Math.floor(t.length/2);return t.length%2===0?(t[e-1]+t[e])/2:t[e]}function Ka(t,e){let n=new Map;for(let o=0;o<t.length;o++){let r=t[o],s=Math.floor(r.x/e),i=Math.floor(r.y/e),l=Math.floor(r.z/e),u=`${s},${i},${l}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}function Qa(t,e,n,o,r){let s=t[n],i=Math.floor(s.x/o),l=Math.floor(s.y/o),u=Math.floor(s.z/o),f=[];for(let d=-1;d<=1;d++)for(let c=-1;c<=1;c++)for(let a=-1;a<=1;a++){let h=`${i+d},${l+c},${u+a}`,g=e.get(h);if(g)for(let b of g){if(b===n)continue;let x=t[b],m=s.x-x.x,p=s.y-x.y,y=s.z-x.z;m*m+p*p+y*y<=r&&f.push(b)}}return f}function Ss(t,e={}){let{radius:n=.35,minClusterSize:o=20,lowPercent:r=.35}=e,s=Ja(t,{radius:n}),i=t.map(d=>d.z).sort((d,c)=>d-c),l=i[Math.floor(i.length*r)],u=[],f=[];for(let d of s.clusters){let c=d.map(g=>s.points[g]),a=c.reduce((g,b)=>g+b.z,0)/c.length;c.length<o&&a<=l?f.push(...c.map(g=>g.raw)):u.push(...c.map(g=>g.raw))}return{keep:u,removed:f}}function Ja(t,e={}){let{radius:n=.35}=e,o=t.map((u,f)=>({index:f,x:u.x,y:u.y,z:u.z,raw:u})),r=Ka(o,n),s=n*n,i=new Array(o.length).fill(!1),l=[];for(let u=0;u<o.length;u++){if(i[u])continue;let f=[],d=[u];for(i[u]=!0;d.length>0;){let c=d.shift();f.push(c);let a=Qa(o,r,c,n,s);for(let h of a)i[h]||(i[h]=!0,d.push(h))}l.push(f)}return{points:o,clusters:l}}function tl(t,e,n=1e-6){let o=el(e);for(let r of o)if(!nl(t,r,n))return!1;return!0}function el(t){let e=t.center,n=t.halfSize,o=t.rotation.elements,r=new q.Vector3(o[0],o[1],o[2]).multiplyScalar(n.x),s=new q.Vector3(o[3],o[4],o[5]).multiplyScalar(n.y),i=new q.Vector3(o[6],o[7],o[8]).multiplyScalar(n.z),l=[];for(let u of[-1,1])for(let f of[-1,1])for(let d of[-1,1]){let c=e.clone().addScaledVector(r,u).addScaledVector(s,f).addScaledVector(i,d);l.push(c)}return l}function nl(t,e,n=1e-6){let o=new q.Vector3().subVectors(e,t.center),r=t.rotation.elements,s=t.halfSize,i=new q.Vector3(r[0],r[1],r[2]),l=new q.Vector3(r[3],r[4],r[5]),u=new q.Vector3(r[6],r[7],r[8]),f=o.dot(i),d=o.dot(l),c=o.dot(u);return Math.abs(f)<=s.x+n&&Math.abs(d)<=s.y+n&&Math.abs(c)<=s.z+n}function ol(t,e){if(!t||t.length===0)return[];let n=new Map;for(let i=0;i<t.length;i++){let l=t[i],u=l[0],f=l[1],d=Math.floor(u/e),c=Math.floor(f/e),a=`${d}_${c}`,h=n.get(a);if(!h){let m=(d+.5)*e,p=(c+.5)*e,y=u-m,w=f-p;h={minX:l,maxX:l,minY:l,maxY:l,center:l,centerDist2:y*y+w*w,cx:m,cy:p},n.set(a,h);continue}u<h.minX[0]&&(h.minX=l),u>h.maxX[0]&&(h.maxX=l),f<h.minY[1]&&(h.minY=l),f>h.maxY[1]&&(h.maxY=l);let g=u-h.cx,b=f-h.cy,x=g*g+b*b;x<h.centerDist2&&(h.center=l,h.centerDist2=x)}let o=new Set,r=[];function s(i){let l=`${i[0]}_${i[1]}`;o.has(l)||(o.add(l),r.push(i))}for(let i of n.values())s(i.minX),s(i.maxX),s(i.minY),s(i.maxY),s(i.center);return r}function rl(t,e,n,o){return 1+(t[e][0]===0||t[n][0]===0||t[o][0]===0?1:0)}function sl(t,e,n,o,r,s){let i=Math.hypot(n-r,o-s),l=Math.hypot(t-r,e-s),u=Math.hypot(t-n,e-o),f=Math.abs((n-t)*(s-e)-(r-t)*(o-e))/2;return f===0?1/0:i*l*u/(4*f)}function il(t){if(!t||t.length<3)return[];let e=new Set,n=[];for(let g of t){let b=`${g[0]}_${g[1]}`;e.has(b)||(e.add(b),n.push(g))}if(n.length<3)return[];let o=new Ae(Float64Array.from(n.flat())),{triangles:r}=o;if(!r.length)return[];let s=new Map,i=(g,b)=>g<b?`${g}_${b}`:`${b}_${g}`;for(let g=0;g<r.length;g+=3){let b=r[g],x=r[g+1],m=r[g+2],[p,y]=n[b],[w,z]=n[x],[M,P]=n[m],E=sl(p,y,w,z,M,P),S=rl(n,b,x,m);if(E<=1/S)for(let[I,W]of[[b,x],[x,m],[m,b]]){let v=i(I,W);s.set(v,(s.get(v)||0)+1)}}let l=[];for(let[g,b]of s)b===1&&l.push(g.split("_").map(Number));if(!l.length)return[];let u=new Map;for(let[g,b]of l)(u.get(g)||u.set(g,[]).get(g)).push(b),(u.get(b)||u.set(b,[]).get(b)).push(g);let f=l[0][0],d=[],c=new Set,a=f,h=-1;do{d.push(n[a]),c.add(a);let g=u.get(a)||[],b=g.find(x=>x!==h&&!c.has(x));if(b===void 0&&(b=g.find(x=>x!==h)),b===void 0)break;h=a,a=b}while(a!==f&&d.length<=l.length+1);return d.length>0&&d.push(d[0]),d}import*as qo from"three";var al=(t,e,n=null)=>{if(t.length===0)return;let o=[],r=new qo.Vector3(e[0].x,e[0].y,e[0].z),s=0;for(let c=1;c<e.length;c++)s+=e[c].z,e[c].z>r.z&&r.set(e[c].x,e[c].y,e[c].z);let i=s/(e.length-1)+.3,l=0,u=0;for(let c of t){let a=c[1].points;if(a.length<30)continue;let h=new Map;for(let x=0;x<a.length;x++){let m=a[x].z;if(m=Math.floor(m*10)/10,h.has(m)){let p=h.get(m);p.num+=1,p.points.push(a[x]),h.set(m,p)}else h.set(m,{num:1,points:[a[x]]})}a=[...h.entries()].reduce((x,m)=>m[1].num>x[1].num?m:x)[1].points.map(x=>new qo.Vector3(x.x,x.y,x.z));let b=[];if(n!=null){let x=n([a],{tolerance:.1,minClusterSize:30,maxClusterSize:1e7,threadCount:1});if(x.length>0)for(let m of x[0]){if(m.length<50)continue;let p=m.map(y=>a[y]);b.push(p)}else b.push(a)}else b.push(a);for(let x=0;x<b.length;x++){let{minZ:m,maxZ:p,averagePz:y}=Ve(b[x]),w=p-m;if(i>p)continue;let z=b[x].map(S=>[S.x,S.y]),M=ce(z);if(Pr(M)<.5)continue;let E={contour:M,averagePz:y,points:b[x]};b[x].length>l&&(l=b[x].length,u=y),o.push(E)}}let f=[];for(let c of o)(c.averagePz>=u||c.averagePz>=i-.5)&&f.push(c);let d=new Set;for(let c=0;c<f.length;c++){if(d.has(c))continue;let a=f[c];for(let h=0;h<f.length;h++){if(c==h||d.has(h))continue;let g=f[h];if(Math.abs(a.averagePz-g.averagePz)>.05)continue;if(Tr(a.contour,g.contour,.001)){a.points.push(...g.points);let x=a.points.map(p=>[p.x,p.y]),m=ce(x);a.contour=m,d.add(h),h=-1;break}}}o=[];for(let c=0;c<f.length;c++)d.has(c)||o.push({contour:f[c].contour,averagePz:f[c].averagePz});return o};function qe(t,e){let n=t.x-e.x,o=t.y-e.y;return Math.sqrt(n*n+o*o)}function je(t){let e=0,n=0,o=0;for(let r=0;r<4;r++){let s=t[r],i=t[(r+1)%4],l=i.x-s.x,u=i.y-s.y,f=Math.sqrt(l*l+u*u);f>e&&(e=f,n=l/f,o=u/f)}return{longSide:e,dirX:n,dirY:o}}function $e(t,e,n){let r=[];for(let s of t){let i=(s.start.x+s.end.x)/2,l=(s.start.y+s.end.y)/2,u=i-e,f=l-n;u*u+f*f<=9&&r.push(s.start.z,s.end.z)}if(r.length===0){let s=[];for(let i of t)s.push(i.start.z,i.end.z);return s.length?(s.sort((i,l)=>i-l),s[Math.floor(s.length/2)]):-1/0}return r.sort((s,i)=>s-i),r[Math.floor(r.length/2)]}function Ce(t,e,n,o,r,s){let i=r-n,l=s-o,u=i*i+l*l;if(u<1e-12)return{dist:Math.sqrt((t-n)**2+(e-o)**2),t:0};let f=t-n,d=e-o,c=(f*i+d*l)/u,a=n+c*i,h=o+c*l;return{dist:Math.sqrt((t-a)**2+(e-h)**2),t:c}}function jo(t,e,n){let o=0;for(let r=0;r<4;r++){let s=n[r],i=n[(r+1)%4],l=(i.x-s.x)*(e-s.y)-(i.y-s.y)*(t-s.x);if(Math.abs(l)<1e-12)continue;let u=l>0?1:-1;if(o===0)o=u;else if(o!==u)return!1}return!0}function Rs(t,e,n,o,r,s,i,l){let u=n-t,f=o-e,d=i-r,c=l-s,a=u*c-f*d;if(Math.abs(a)<1e-12)return null;let h=((r-t)*c-(s-e)*d)/a,g=((r-t)*f-(s-e)*u)/a;return h<-1e-12||h>1+1e-12||g<-1e-12||g>1+1e-12?null:Math.max(0,Math.min(1,h))}function Ds(t,e,n,o,r){let s=[];jo(t,e,r)&&s.push(0),jo(n,o,r)&&s.push(1);for(let u=0;u<4;u++){let f=r[u],d=r[(u+1)%4],c=Rs(t,e,n,o,f.x,f.y,d.x,d.y);c!==null&&s.push(c)}if(s.length<2)return 0;s.sort((u,f)=>u-f);let i=Math.sqrt((n-t)**2+(o-e)**2),l=0;for(let u=0;u<s.length-1;u++){let f=s[u],d=s[u+1],c=(f+d)/2,a=t+c*(n-t),h=e+c*(o-e);jo(a,h,r)&&(l+=(d-f)*i)}return l}function vs(t,e,n=1e-6){let o=[],r=t.start.x,s=t.start.y,i=t.end.x,l=t.end.y;for(let d of e){if(d===t)continue;let c=Rs(r,s,i,l,d.start.x,d.start.y,d.end.x,d.end.y);c!==null&&c>n&&c<1-n&&o.push(c)}o.sort((d,c)=>d-c);let u=[],f=-1/0;for(let d of o)d-f>n&&(u.push(d),f=d);return u}function Vs(t,e){if(!e.length)return[t];let n=[],o=0;for(let s of e){let i=t.start.x+s*(t.end.x-t.start.x),l=t.start.y+s*(t.end.y-t.start.y),u=t.start.z+s*(t.end.z-t.start.z),f=o===0?{...t.start}:{x:t.start.x+o*(t.end.x-t.start.x),y:t.start.y+o*(t.end.y-t.start.y),z:t.start.z+o*(t.end.z-t.start.z)},d={...t,start:f,end:{x:i,y:l,z:u},length:t.length*(s-o)};d.drawWindow=void 0,d.isWindow=!1,n.push(d),o=s}let r={...t,start:{x:t.start.x+o*(t.end.x-t.start.x),y:t.start.y+o*(t.end.y-t.start.y),z:t.start.z+o*(t.end.z-t.start.z)},end:{...t.end},length:t.length*(1-o)};return r.drawWindow=void 0,r.isWindow=!1,n.push(r),n}function ll(t,e,n=.15){let o=0,r=0;for(let i of e)i!==t&&((qe(t.start,i.start)<=n||qe(t.start,i.end)<=n)&&o++,(qe(t.end,i.start)<=n||qe(t.end,i.end)<=n)&&r++);let s=0;return o>=1&&r>=1?s=5:(o>=1||r>=1)&&(s=2),{left:o,right:r,score:s}}function cl(t,e){let n=[],{start:o,end:r}=t;for(let l of e){let{dist:u}=Ce(l.x,l.y,o.x,o.y,r.x,r.y);n.push(u)}let s=n.reduce((l,u)=>l+u,0)/n.length,i=n.reduce((l,u)=>l+(u-s)**2,0)/n.length;return i<.01?3:i<.05?2:i<.1?1:0}function ul(t,e,n=.15){let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=Math.sqrt(o*o+r*r);if(s<1e-12)return 0;let i=-r/s,l=o/s,u=[[],[]];for(let c=0;c<2;c++){let a=c===0?t.start:t.end;for(let h of e){if(h===t)continue;let g=qe(a,h.start),b=qe(a,h.end),x=null;if(g<=n?x=h.end:b<=n&&(x=h.start),!x)continue;let m=h.end.x-h.start.x,p=h.end.y-h.start.y,y=Math.sqrt(m*m+p*p);if(y<1e-12||Math.abs(o*m+r*p)/(s*y)>=.342)continue;let z=(x.x-a.x)*i+(x.y-a.y)*l;u[c].push(z>0?1:-1)}}if(u[0].length===0||u[1].length===0)return 0;let f=[...u[0],...u[1]];return f.every(c=>c===f[0])?2:1}function Is(t,e,n){let o=ll(t,n),r=cl(t,e),s=ul(t,n);return{score:o.score*3+r*2+s*2,details:{conn:o.score,variance:r,sameSide:s}}}function fl(t){let e=t.end.x-t.start.x,n=t.end.y-t.start.y,o=Math.atan2(n,e)*(180/Math.PI);return o<0&&(o+=180),o}function dl(t,e){let n=[];for(let o of t){let r=!1;for(let s of n){let i=Math.abs(o.angle-s[0].angle);if(Math.min(i,180-i)<=e){s.push(o),r=!0;break}}r||n.push([o])}return n}function hl(t,e=.05){let n=[];for(let o of t){let r=!1;for(let s of n)if(Math.abs(o.offset-s[0].offset)<=e){s.push(o),r=!0;break}r||n.push([o])}return n}function ml(t,e,n,o,r){let s=[];for(let f of t){let d=f.seg,c=(d.start.x-e.start.x)*n+(d.start.y-e.start.y)*o,a=(d.end.x-e.start.x)*n+(d.end.y-e.start.y)*o;c<=a?s.push({l:c,r:a,idx:f.idx,startPt:d.start,endPt:d.end}):s.push({l:a,r:c,idx:f.idx,startPt:d.end,endPt:d.start})}s.sort((f,d)=>f.l-d.l);let i=[],l=.2,u=.5;for(let{l:f,r:d,idx:c,startPt:a,endPt:h}of s){if(i.length===0){i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h});continue}let g=i[i.length-1];if(f<=g.r+r){let b=Math.min(g.r,d)-Math.max(g.l,f),x=Math.hypot(g.endPt.x-a.x,g.endPt.y-a.y);b>=u||x<=l?(f<g.l&&(g.l=f,g.startPt=a),d>g.r&&(g.r=d,g.endPt=h),g.srcIdxs.includes(c)||g.srcIdxs.push(c)):i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h})}else i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h})}return i}function pl(t,e,n,o,r,s,i){let l=Math.hypot(n.x-e.x,n.y-e.y),u={...t};return u.start={...e},u.end={...n},u.length=l,u.direction={x:o,y:r,z:0},s!==void 0&&(u.rooftopPz=s),u.buildRosource=i,u.isRebuild=!1,u.doorAndBeamData||(u.doorAndBeamData=[]),u.insetionArr||(u.insetionArr=[]),u}function gl(t,e){let n=!0;for(;n;){n=!1;for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o],i=t[r];if(s.rooftopPz!==void 0&&i.rooftopPz!==void 0&&Math.abs(s.rooftopPz-i.rooftopPz)>.05)continue;let l=Math.abs(s.end.x-i.start.x)<.001&&Math.abs(s.end.y-i.start.y)<.001,u=Math.abs(s.start.x-i.end.x)<.001&&Math.abs(s.start.y-i.end.y)<.001,f=Math.abs(s.end.x-i.end.x)<.001&&Math.abs(s.end.y-i.end.y)<.001,d=Math.abs(s.start.x-i.start.x)<.001&&Math.abs(s.start.y-i.start.y)<.001;if(!(l||u||f||d)||s.direction.x*i.direction.x+s.direction.y*i.direction.y<.98)continue;let a=s.start,h=s.end;l?h=i.end:u?a=i.start:f?h=i.start:d&&(a=i.end);let g=Math.hypot(h.x-a.x,h.y-a.y),b={...s};b.start=a,b.end=h,b.length=g,b.direction={x:(h.x-a.x)/g,y:(h.y-a.y)/g,z:0},s.rooftopPz!==void 0&&i.rooftopPz!==void 0?b.rooftopPz=Math.max(s.rooftopPz,i.rooftopPz):b.rooftopPz=s.rooftopPz!==void 0?s.rooftopPz:i.rooftopPz,b.buildRosource=s.buildRosource||i.buildRosource,b.isRebuild=!1,b.doorAndBeamData||(b.doorAndBeamData=[]),b.insetionArr||(b.insetionArr=[]),t[o]=b,e[o]=[...new Set([...e[o],...e[r]])],t.splice(r,1),e.splice(r,1),r--,n=!0}}return{segments:t,sourceMap:e}}function Xe(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((u,f)=>[f])};let o=t.map((u,f)=>({seg:u,angle:fl(u),idx:f}));o.sort((u,f)=>u.angle-f.angle);let r=dl(o,e),s=[],i=[],l=[];for(let u of r){let f=u[0].seg;for(let m of u)m.seg.length>f.length&&(f=m.seg);let d=f.end.x-f.start.x,c=f.end.y-f.start.y,a=Math.sqrt(d*d+c*c);if(a<1e-12)continue;let h=-c/a,g=d/a,b=u.map(m=>{let p=m.seg.start.x-f.start.x,y=m.seg.start.y-f.start.y;return{seg:m.seg,offset:Math.abs(p*h+y*g),idx:m.idx}});b.sort((m,p)=>m.offset-p.offset);let x=hl(b);for(let m of x){let p=m[0].seg;for(let T of m)T.seg.length>p.length&&(p=T.seg);let y=p.end.x-p.start.x,w=p.end.y-p.start.y,z=Math.sqrt(y*y+w*w);if(z<1e-12)continue;let M=y/z,P=w/z,E=m.map(T=>T.seg.rooftopPz).filter(T=>T!==void 0),S=E.length>0?Math.max(...E):void 0,I=[...new Set(E.map(T=>T.toFixed(3)))];if(I.length>1){let T=m.map(R=>({idx:R.idx,start:{x:R.seg.start.x,y:R.seg.start.y,z:R.seg.start.z},end:{x:R.seg.end.x,y:R.seg.end.y,z:R.seg.end.z},length:R.seg.length,rooftopPz:R.seg.rooftopPz}));l.push({values:[...I],segments:T})}let W=[...new Set(m.map(T=>String(T.seg.buildRosource)))],v=ml(m,p,M,P,n);for(let{l:T,r:R,srcIdxs:D,startPt:H,endPt:V}of v){if(R-T<.01)continue;let C=pl(p,H,V,M,P,S,p.buildRosource);s.push(C),i.push(D)}}}return{...gl(s,i),debugRPZGroups:l}}function xl(t){return{minLengthRatio:.95,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,minEmbedRatioThreshold:.3,noWallSurroundDistance:.3,minEmbedRatio:.05,...t}}function yl(t,e,n){return[{x:e,y:n,z:0},{x:t[0].x,y:t[0].y,z:0},{x:t[1].x,y:t[1].y,z:0},{x:t[2].x,y:t[2].y,z:0},{x:t[3].x,y:t[3].y,z:0}]}function bl(t,e,n,o,r,s,i,l,u){if(!["1527725434500","1527725386500","1527726772000","1527725058500"].some(c=>t.includes(c)))return;e.map(c=>{let{start:a,end:h}=c,g=Ce(n,o,a.x,a.y,h.x,h.y),b=r.map(z=>{let M=Ce(z.x,z.y,a.x,a.y,h.x,h.y);return`t=${M.t.toFixed(3)},d=${M.dist.toFixed(3)}`}),x=h.x-a.x,m=h.y-a.y,p=Math.sqrt(x*x+m*m)||1,y=Math.abs(i*(x/p)+l*(m/p)),w=Math.acos(Math.min(y,1))*(180/Math.PI);return{seg:c,lineDist:g.dist,t:g.t,pts:b,angle:w,length:c.length}}).sort((c,a)=>c.lineDist-a.lineDist)}function wl(t,e,n,o,r,s,i){let l=[{margin:s.projectionMargin,maxDist:s.maxDistance,label:"\u4E25\u683C"},{margin:.4,maxDist:.65,label:"\u5BBD\u677E"}],u=[];for(let f of l){if(u.length>0)break;for(let d of t){let c=!1,a=!1,h=!1,g=e*s.minLengthRatio;if(d.length<g){continue}c=!0;let{start:b,end:x}=d,m=!1,p=1/0;for(let v of r){let{dist:T,t:R}=Ce(v.x,v.y,b.x,b.y,x.x,x.y);R>=-f.margin&&R<=1+f.margin&&T<=f.maxDist&&(m=!0,p=Math.min(p,T))}if(!m){`${f.maxDist}${(-f.margin).toFixed(1)}${(1+f.margin).toFixed(1)}`;continue}a=!0;let y=Ce(r[0].x,r[0].y,b.x,b.y,x.x,x.y);if(y.t<0||y.t>1){`${y.t.toFixed(3)}`;continue}let w=Math.sqrt((x.x-b.x)**2+(x.y-b.y)**2);if(w<1e-12)continue;let z=(x.x-b.x)/w,M=(x.y-b.y)/w,P=Math.abs(n*z+o*M),E=Math.acos(Math.min(P,1))*(180/Math.PI);if(E>s.angleThreshold){`${E.toFixed(1)}${s.angleThreshold}`;continue}h=!0;let S=[r[1],r[2],r[3],r[4]],I=Ds(b.x,b.y,x.x,x.y,S),W=e>0?I/e:0;u.push({seg:d,minDist:p,embedRatio:W,ratio:d.length/e,score:0,details:{conn:0,variance:0,sameSide:0}})}}return u}function zl(t,e,n,o){if(t.length<=1)return t.length===1&&(t[0].score=-1),t;for(let r of t){let{score:s,details:i}=Is(r.seg,e,n);r.score=s,r.details=i}return t.sort((r,s)=>s.embedRatio-r.embedRatio||s.score-r.score||r.minDist-s.minDist),t}function Ml(t,e,n,o){let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=Math.sqrt(r*r+s*s),l=r/i,u=s/i,f=e.map(P=>{let E=P.x-t.start.x,S=P.y-t.start.y;return(E*l+S*u)/i}),d=Math.min(...f),c=Math.max(...f),a=(c-d)*i,h=(d+c)/2,g=t.start.x+h*r,b=t.start.y+h*s,x=n.box.min.z,m=n.box.max.z,p=Math.abs(m-x),y=$e(o,t.start.x,t.start.y),w=Math.max(0,x-y),z=d<=0&&c>=1,M=t.start.z+h*(t.end.z-t.start.z);return{p:{x:g,y:b,z:M},width:a,full:z,height:p,groundClearance:w}}function $o(t,e,n){let o=e.map(d=>n[d]),r=[],s=[],i=[],l=[],u,f;for(let d of o){if(d.originalPoints?.length)for(let c of d.originalPoints)r.push(c);if(d.doorAndBeamData?.length)for(let c of d.doorAndBeamData)s.push(c);if(d.insetionArr?.length)for(let c of d.insetionArr)i.push(c);if(d.drawWindow?.length)for(let c of d.drawWindow)l.push(c);d.boxData&&!u&&(u=d.boxData),d.rooftopPz!==void 0&&(f===void 0||d.rooftopPz>f)&&(f=d.rooftopPz)}r.length&&(t.originalPoints=r),s.length&&(t.doorAndBeamData=s),i.length&&(t.insetionArr=i),l.length&&(t.drawWindow=l),u&&(t.boxData=u),f!==void 0&&(t.rooftopPz=f)}function Tn(t,e,n=10,o=.2,r=.2){let s=[];if(!t.drawWindow)return s;let i=t.drawWindow.p,l=t.wallSegment,u=l.end.x-l.start.x,f=l.end.y-l.start.y,d=Math.sqrt(u*u+f*f)||1,c=u/d,a=f/d,h=i.x-l.start.x,g=i.y-l.start.y,b=(h*c+g*a)/d;for(let x of e){if(x===l)continue;let m=x.end.x-x.start.x,p=x.end.y-x.start.y,y=Math.sqrt(m*m+p*p)||1,w=m/y,z=p/y,M=Math.abs(c*w+a*z),E=Math.acos(Math.min(M,1))*(180/Math.PI);if(Math.abs(E-90)>n)continue;let S=[x.start,x.end];for(let I of S){let W=I.x-l.start.x,v=I.y-l.start.y,T=(W*c+v*a)/d,R=l.start.x+T*d*c,D=l.start.y+T*d*a;if(Math.sqrt((I.x-R)**2+(I.y-D)**2)>r)continue;let V=Math.abs((T-b)*d);if(V<=o){s.push({seg:x,distAlongWall:V,angle:E,endPoint:I});break}}}return s}function Sn(t,e){let n=t.start,o=t.end,r=o.x-n.x,s=o.y-n.y,i=Math.sqrt(r*r+s*s)||1,l=((e.x-n.x)*r+(e.y-n.y)*s)/(i*i),u=Math.max(0,Math.min(1,l)),f={x:n.x+u*r,y:n.y+u*s,z:n.z+(o.z-n.z)*u||0};function d(y){if(!y||!y.length)return[[],[]];let w=[],z=[];for(let M of y){let P=((M.x-n.x)*r+(M.y-n.y)*s)/(i*i);P<=u+1e-8&&w.push(M),P>=u-1e-8&&z.push(M)}return(w.length===0||c(w[w.length-1],f)>1e-6)&&w.push({...f}),(z.length===0||c(z[0],f)>1e-6)&&z.unshift({...f}),[w,z]}function c(y,w){return Math.sqrt((y.x-w.x)**2+(y.y-w.y)**2)}let[a,h]=d(t.originalPoints),g=Math.max(u*i,1e-6),b=Math.max((1-u)*i,1e-6),x=t.direction||{x:r/i,y:s/i,z:(o.z-n.z)/i||0},m={...t,start:{...n},end:{...f},length:g,direction:{...x},originalPoints:a.length?a:void 0},p={...t,start:{...f},end:{...o},length:b,direction:{...x},originalPoints:h.length?h:void 0};if(t.drawWindow&&t.drawWindow.length>0){let y=[],w=[];for(let z of t.drawWindow){let M=((z.p.x-n.x)*r+(z.p.y-n.y)*s)/(i*i);M<=u+1e-8&&y.push(z),M>=u-1e-8&&w.push(z)}m.drawWindow=y.length?y:void 0,p.drawWindow=w.length?w:void 0}else m.drawWindow=void 0,p.drawWindow=void 0;if(t.boxData){let y=w=>{if(!w.length)return;let z=1/0,M=1/0,P=1/0,E=-1/0,S=-1/0,I=-1/0;for(let W of w)W.x<z&&(z=W.x),W.y<M&&(M=W.y),W.z!==void 0&&W.z<P&&(P=W.z),W.x>E&&(E=W.x),W.y>S&&(S=W.y),W.z!==void 0&&W.z>I&&(I=W.z);return{isBox3:!0,min:{x:z,y:M,z:P},max:{x:E,y:S,z:I}}};m.boxData=y(a),p.boxData=y(h)}return[m,p]}function Rn(t,e,n,o){let r=xl(n),s=[],{segments:i,sourceMap:l}=o??Xe(e),u=i;for(let f of t){let d=f.coordinatesByArea?.coordinates;if(!d||d.length<4)continue;let c=d.slice(0,4),a=c.reduce((I,W)=>I+W.x,0)/4,h=c.reduce((I,W)=>I+W.y,0)/4,{longSide:g,dirX:b,dirY:x}=je(c);if(g<.01)continue;let m=c.reduce((I,W)=>I+W.z,0)/4,p=$e(e,a,h);if(m<p-.3)continue;let y=yl(c,a,h);bl(f.name,u,a,h,y,g,b,x,r);let w=wl(u,g,b,x,y,r,f.name);if(w.length>1&&r.minEmbedRatioThreshold>0){let I=Math.max(...w.map(W=>W.embedRatio));if(I>0){let W=w.length;w=w.filter(v=>v.embedRatio>=I*r.minEmbedRatioThreshold)}}if(w.length>0&&r.minEmbedRatio>0){let I=w.length;w=w.filter(W=>W.embedRatio>=r.minEmbedRatio)}w=zl(w,y,e,f.name);let z=null,M=1/0,P=0,E=0;if(w.length>0){let I=w[0];z=I.seg,M=I.minDist,P=I.ratio,E=I.embedRatio}if(z&&E<=0&&r.noWallSurroundDistance>0){let I=r.noWallSurroundDistance,W=c.map(C=>C.x),v=c.map(C=>C.y),T=Math.min(...W)-I,R=Math.max(...W)+I,D=Math.min(...v)-I,H=Math.max(...v)+I,V=!1;for(let C of u){let _=Math.min(C.start.x,C.end.x),A=Math.max(C.start.x,C.end.x),B=Math.min(C.start.y,C.end.y),k=Math.max(C.start.y,C.end.y);if(!(A<T||_>R)&&!(k<D||B>H)){V=!0;break}}V||(z=null)}let S;if(z&&(S=Ml(z,c,f,i),!r.printOnly)){let I=z;I.drawWindow||(I.drawWindow=[]),I.drawWindow.push(S),I.isWindow=!0}if(z){let I={windowName:f.name,windowCategory:f.category,windowCenter:f.center,wallSegment:z,distance:M,wallLengthRatio:P,drawWindow:S};s.push(I)}}for(let f of s){let d=f.wallSegment,c=i.indexOf(d);if(c===-1)continue;let a=l[c];!a||a.length<=1||$o(d,a,e)}return s}function Xo(t,e,n){let o={printOnly:!1,skipMerge:!1,...n};for(let x of t)x.drawWindow&&(x.drawWindow=void 0),x.isWindow&&(x.isWindow=void 0);let r=Array.isArray(e)?e.filter(x=>x&&x.category==="window"&&!x.isBayWindowObj):[],s,i;if(o.skipMerge)s=t,i=t.map((x,m)=>[m]);else{let x=Xe(t);s=x.segments,i=x.sourceMap}let l=Rn(r,t,o,{segments:s,sourceMap:i}),u=new Set;for(let x of l){let m=s.indexOf(x.wallSegment);m>=0&&u.add(m)}let f=[],d=new Set;for(let x of u){let m=i[x];if(m){$o(s[x],m,t);for(let p of m)d.add(p)}f.push(s[x])}for(let x=0;x<t.length;x++)d.has(x)||f.push(t[x]);let c=new Set(l.map(x=>x.windowName));for(let x of e)x&&x.category==="window"&&!x.isBayWindowObj&&(c.has(x.name)?delete x.AbnormalWindow:x.AbnormalWindow=!0);let a=new Map;for(let x of e)x&&x.name&&a.set(x.name,x);let h=new Map;for(let x of l){let m=x.wallSegment;h.has(m)||h.set(m,[]),h.get(m).push(x)}let g=new Map,b=f;for(let[x,m]of h){if(!x.drawWindow||!x.drawWindow.length||g.has(x))continue;let p=x.length,y=x.end.x-x.start.x,w=x.end.y-x.start.y,z=[];for(let T of m){if(!T.drawWindow)continue;let R=T.drawWindow.width/2,D=((T.drawWindow.p.x-x.start.x)*y+(T.drawWindow.p.y-x.start.y)*w)/(p*p),H=R/p;z.push({left:D-H,right:D+H,match:T})}if(z.length===0)continue;let M=vs(x,b),P=1e-6,E=new Set,S=!1;for(let T of z){let R=!1,D=!1,H=null;for(let C of M)C<T.left-P&&((H===null||C>H)&&(H=C),R=!0);let V=null;for(let C of M)C>T.right+P&&((V===null||C<V)&&(V=C),D=!0);H!==null&&(E.add(H),S=!0),V!==null&&(E.add(V),S=!0)}if(!S)continue;let I=!1,W=null,v=null;for(let T of z){let R=T.match;if(!R.drawWindow||R.drawWindow.width<=1)continue;let D=a.get(R.windowName);if(!D||!D.positionArr||!D.positionArr.length)continue;let H=Tn(R,s);if(H.length<=1)continue;let V=D.positionArr[0],C=R.drawWindow.p,_=V.x-C.x,A=V.y-C.y,B=Math.sqrt(_*_+A*A);if(B<.001)continue;let k=_/B,F=A/B,L=H.filter(O=>{let $=(O.seg.start.x+O.seg.end.x)/2,Z=(O.seg.start.y+O.seg.end.y)/2,Q=$-C.x,j=Z-C.y;return Q*k+j*F>0});if(L.length){I=!0,W=L[0].endPoint,v=R;break}}if(I&&W&&v){let[T,R]=Sn(x,W);g.set(x,[T,R]);let D=((v.drawWindow.p.x-x.start.x)*y+(v.drawWindow.p.y-x.start.y)*w)/(p*p),H=((W.x-x.start.x)*y+(W.y-x.start.y)*w)/(p*p);D<=H?v.wallSegment=T:v.wallSegment=R}else{let T=Array.from(E).sort((D,H)=>D-H),R=Vs(x,T);for(let D of z){let H=(D.left+D.right)/2,V=0;for(let C of R){let _=C.length/p;if(H>=V-P&&H<=V+_+P){let A=D.match.drawWindow;A&&(C.drawWindow||(C.drawWindow=[]),C.drawWindow.push(A),C.isWindow=!0),D.match.wallSegment=C;break}V+=_}}g.set(x,R)}}if(g.size>0){let x=[];for(let m of f)g.has(m)?x.push(...g.get(m)):x.push(m);for(let m of x)m.isWindow===void 0&&(m.isWindow=!!(m.drawWindow&&m.drawWindow.length>0));return{segments:x,matches:l}}for(let x of f)x.isWindow=!!(x.drawWindow&&x.drawWindow.length>0);return{segments:f,matches:l}}function Ze(t,e){let n=t.x-e.x,o=t.y-e.y;return Math.sqrt(n*n+o*o)}function ro(t){let e=0,n=1/0,o=0,r=0;for(let s=0;s<4;s++){let i=t[s],l=t[(s+1)%4],u=l.x-i.x,f=l.y-i.y,d=Math.sqrt(u*u+f*f);d>e&&(e=d,o=u/d,r=f/d),d<n&&(n=d)}return{longSide:e,shortSide:n===1/0?e:n,dirX:o,dirY:r}}function Ge(t,e,n){let r=[];for(let s of t){let i=(s.start.x+s.end.x)/2,l=(s.start.y+s.end.y)/2,u=i-e,f=l-n;u*u+f*f<=9&&r.push(s.start.z,s.end.z)}if(r.length===0){let s=[];for(let i of t)s.push(i.start.z,i.end.z);return s.length?(s.sort((i,l)=>i-l),s[Math.floor(s.length/2)]):-1/0}return r.sort((s,i)=>s-i),r[Math.floor(r.length/2)]}function jt(t,e,n,o,r,s){let i=r-n,l=s-o,u=i*i+l*l;if(u<1e-12)return{dist:Math.sqrt((t-n)**2+(e-o)**2),t:0};let f=t-n,d=e-o,c=(f*i+d*l)/u,a=n+c*i,h=o+c*l;return{dist:Math.sqrt((t-a)**2+(e-h)**2),t:c}}function Zo(t,e,n){let o=0;for(let r=0;r<4;r++){let s=n[r],i=n[(r+1)%4],l=(i.x-s.x)*(e-s.y)-(i.y-s.y)*(t-s.x);if(Math.abs(l)<1e-12)continue;let u=l>0?1:-1;if(o===0)o=u;else if(o!==u)return!1}return!0}function El(t,e,n,o,r,s,i,l){let u=n-t,f=o-e,d=i-r,c=l-s,a=u*c-f*d;if(Math.abs(a)<1e-12)return null;let h=((r-t)*c-(s-e)*d)/a,g=((r-t)*f-(s-e)*u)/a;return h<-1e-12||h>1+1e-12||g<-1e-12||g>1+1e-12?null:Math.max(0,Math.min(1,h))}function Hs(t,e,n,o,r){let s=[];Zo(t,e,r)&&s.push(0),Zo(n,o,r)&&s.push(1);for(let u=0;u<4;u++){let f=r[u],d=r[(u+1)%4],c=El(t,e,n,o,f.x,f.y,d.x,d.y);c!==null&&s.push(c)}if(s.length<2)return 0;s.sort((u,f)=>u-f);let i=Math.sqrt((n-t)**2+(o-e)**2),l=0;for(let u=0;u<s.length-1;u++){let f=s[u],d=s[u+1],c=(f+d)/2,a=t+c*(n-t),h=e+c*(o-e);Zo(a,h,r)&&(l+=(d-f)*i)}return l}function Ws(t){if(!t||t.length<4)return[];let e=[...t].sort((i,l)=>i.z-l.z),n=e.slice(0,2),o=e.slice(2,4),r=[],s=new Set;for(let i of n){let l=-1,u=1/0;for(let f=0;f<o.length;f++){if(s.has(f))continue;let d=o[f].x-i.x,c=o[f].y-i.y,a=Math.sqrt(d*d+c*c);a<u&&(u=a,l=f)}if(l>=0){s.add(l);let f=o[l];r.push({bottom:i,top:f,midX:(i.x+f.x)/2,midY:(i.y+f.y)/2,height:Math.abs(f.z-i.z)})}}return r}function Cs(t,e,n){return jt(t.midX,t.midY,e.x,e.y,n.x,n.y)}function _s(t,e,n,o=.08){if(!t||t.length<2)return null;let r=Cs(t[0],e,n),s=Cs(t[1],e,n);if(r.dist<=o&&s.dist<=o){let i=r.dist<=s.dist?0:1,l=1-i;return{hingeEdge:t[i],otherEdge:t[l],hingeDist:i===0?r.dist:s.dist,otherDist:l===0?r.dist:s.dist,isClosed:!0,hingeT:i===0?r.t:s.t}}if(r.dist<=o||s.dist<=o){let i=r.dist<=o?0:1,l=1-i;return{hingeEdge:t[i],otherEdge:t[l],hingeDist:i===0?r.dist:s.dist,otherDist:l===0?r.dist:s.dist,isClosed:!1,hingeT:i===0?r.t:s.t}}return null}function As(t){if(!t||t.length<2)return 0;let e=t[0].midX-t[1].midX,n=t[0].midY-t[1].midY;return Math.sqrt(e*e+n*n)}function Go(t){if(!t||!t.start||t.start.x==null||t.start.y==null||t.start.z==null||!t.end||t.end.x==null||t.end.y==null||t.end.z==null)return null;let e=t.start,n=t.end,o=n.x-e.x,r=n.y-e.y,s=Math.sqrt(o*o+r*r)||1,i=0,l=0;return t.centerDir?(i=t.centerDir.x,l=t.centerDir.y):(i=-r/s,l=o/s),{p1:e,p2:n,dirX:o/s,dirY:r/s,length:s,midX:(e.x+n.x)/2,midY:(e.y+n.y)/2,normalX:i,normalY:l}}function Ls(t,e,n,o=.08){let r=Go(t);if(!r)return null;let s=jt(r.p1.x,r.p1.y,e.x,e.y,n.x,n.y),i=jt(r.p2.x,r.p2.y,e.x,e.y,n.x,n.y);if(s.dist<=o&&i.dist<=o){let l=s.dist<=i.dist;return{hingePoint:l?r.p1:r.p2,otherPoint:l?r.p2:r.p1,hingeDist:l?s.dist:i.dist,otherDist:l?i.dist:s.dist,isClosed:!0,hingeT:l?s.t:i.t}}if(s.dist<=o||i.dist<=o){let l=s.dist<=o;return{hingePoint:l?r.p1:r.p2,otherPoint:l?r.p2:r.p1,hingeDist:l?s.dist:i.dist,otherDist:l?i.dist:s.dist,isClosed:!1,hingeT:l?s.t:i.t}}return null}function so(t,e=.1){let n=t.originalPoints;if(!n||n.length===0)return{densityProfile:[],binStartT:[],binEndT:[],avgDensity:0,maxDensity:0,minDensity:0,binSize:e};let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=t.length;if(s<=0)return{densityProfile:[],binStartT:[],binEndT:[],avgDensity:0,maxDensity:0,minDensity:0,binSize:e};let i=[];for(let x of n){let m=x.x-t.start.x,p=x.y-t.start.y,y=(m*o+p*r)/(s*s);i.push(Math.max(0,Math.min(1,y)))}let l=Math.max(1,Math.ceil(s/e)),u=s/l,f=new Array(l).fill(0);for(let x of i){let m=Math.min(l-1,Math.floor(x*l));f[m]++}let d=f.map(x=>x/u),c=f.map((x,m)=>m/l),a=f.map((x,m)=>(m+1)/l),h=d.reduce((x,m)=>x+m,0)/l,g=Math.max(...d),b=Math.min(...d);return{densityProfile:d,binStartT:c,binEndT:a,avgDensity:h,maxDensity:g,minDensity:b,binSize:u}}function Bs(t){let{densityProfile:e,avgDensity:n}=t;if(e.length===0||n===0)return 0;let o=e.length,r=e.reduce((i,l)=>i+(l-n)**2,0)/o;return Math.sqrt(r)/n}function ks(t){let e=[];for(let o of t)if(o.originalPoints&&o.originalPoints.length>=50&&o.length>=.5){let r=so(o,.1);r.avgDensity>0&&e.push(r.avgDensity)}e.sort((o,r)=>o-r);let n=e.length>0?e[Math.floor(e.length/2)]:1;return{sortedDensities:e,medianDensity:n}}function Yo(t,e){let{sortedDensities:n}=e;if(n.length===0)return .5;if(t<=0)return 1;let o=0;for(let r of n)r<t&&o++;return 1-o/n.length}function Os(t,e,n=.5,o=.5,r=3){let{densityProfile:s,avgDensity:i}=t;if(s.length===0||i===0)return[];let l=i*n,u=s.length,f=[],d=!1,c=0,a=0,h=0;for(let g=0;g<u;g++){let b=s[g]<l;if(b&&!d)d=!0,c=g,a=s[g],h=1;else if(b&&d)a+=s[g],h++;else if(!b&&d){d=!1;let x=g-1,m=c/u,p=(x+1)/u,y=(p-m)*e;y>=o&&y<=r&&f.push({startT:m,endT:p,startLen:m*e,endLen:p*e,avgDensity:a/h}),a=0,h=0}}if(d){let g=u-1,b=c/u,x=(g+1)/u,m=(x-b)*e;m>=o&&m<=r&&f.push({startT:b,endT:x,startLen:b*e,endLen:x*e,avgDensity:a/h})}return f}function Pl(t,e,n){let o=t.originalPoints;if(!o||o.length<5)return{verticalGapRatio:1,isDoorSized:!0};let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=t.length*t.length;if(i<=0)return{verticalGapRatio:0,isDoorSized:!1};let l=[];for(let m of o){let p=m.x-t.start.x,y=m.y-t.start.y,w=(p*r+y*s)/i;w>=e&&w<=n&&m.z!==void 0&&isFinite(m.z)&&l.push(m.z)}if(l.length<5)return{verticalGapRatio:1,isDoorSized:!0};let u=1/0,f=-1/0;for(let m of o)m.z!==void 0&&isFinite(m.z)&&(m.z<u&&(u=m.z),m.z>f&&(f=m.z));let d=f-u;if(d<.5)return{verticalGapRatio:0,isDoorSized:!1};let c=15,a=new Array(c).fill(!1);for(let m of l){let p=Math.min(c-1,Math.max(0,Math.floor((m-u)/d*c)));a[p]=!0}let h=0,g=0;for(let m=0;m<c;m++)a[m]?(h=Math.max(h,g),g=0):g++;h=Math.max(h,g);let b=h/c,x=b>=.35;return{verticalGapRatio:b,isDoorSized:x}}function Fs(t,e,n,o=.5,r=.5,s=3,i=.35){let l=Os(e,n,o,r,s),u=[];for(let f of l){let{verticalGapRatio:d,isDoorSized:c}=Pl(t,f.startT,f.endT);u.push({...f,verticalGapRatio:d,isRectangular:c})}return u}function Ns(t,e,n){if(!t||!t.start||!t.end)return null;let o=t.start,r=t.end,s=jt(o.x,o.y,e.x,e.y,n.x,n.y),i=jt(r.x,r.y,e.x,e.y,n.x,n.y),l=s.dist<=i.dist,u=l?o:r,f=l?s.dist:i.dist,d=jt(u.x,u.y,e.x,e.y,n.x,n.y);return{hingeT:Math.max(0,Math.min(1,d.t)),hingeDist:f}}function qs(t,e,n,o=2e3){let{hingeT:r}=t,s=.25,i=0,l=null,u=0;for(let f of e){let d=(f.startT+f.endT)/2,c=Math.abs(d-r),a=Math.max(0,1-c/s),h=f.isRectangular?1:.3,g=Math.max(0,1-f.avgDensity/o),b=a*.5+h*.3+g*.2;b>i&&(i=b,l=f,u=a)}return{score:i>.5?i:-1,bestRegion:l,bestOverlap:u,bestOpeningStartT:l?.startT??0,bestOpeningEndT:l?.endT??0}}function Tl(t,e,n=.15){let o=0,r=0;for(let i of e)i!==t&&((Ze(t.start,i.start)<=n||Ze(t.start,i.end)<=n)&&o++,(Ze(t.end,i.start)<=n||Ze(t.end,i.end)<=n)&&r++);let s=0;return o>=1&&r>=1?s=5:(o>=1||r>=1)&&(s=2),{left:o,right:r,score:s}}function Sl(t,e){let n=[],{start:o,end:r}=t;for(let l of e){let{dist:u}=jt(l.x,l.y,o.x,o.y,r.x,r.y);n.push(u)}let s=n.reduce((l,u)=>l+u,0)/n.length,i=n.reduce((l,u)=>l+(u-s)**2,0)/n.length;return i<.01?3:i<.05?2:i<.1?1:0}function Rl(t,e,n=.15){let o=t.end.x-t.start.x,r=t.end.y-t.start.y,s=Math.sqrt(o*o+r*r);if(s<1e-12)return 0;let i=-r/s,l=o/s,u=[[],[]];for(let c=0;c<2;c++){let a=c===0?t.start:t.end;for(let h of e){if(h===t)continue;let g=Ze(a,h.start),b=Ze(a,h.end),x=null;if(g<=n?x=h.end:b<=n&&(x=h.start),!x)continue;let m=h.end.x-h.start.x,p=h.end.y-h.start.y,y=Math.sqrt(m*m+p*p);if(y<1e-12||Math.abs(o*m+r*p)/(s*y)>=.342)continue;let z=(x.x-a.x)*i+(x.y-a.y)*l;u[c].push(z>0?1:-1)}}if(u[0].length===0||u[1].length===0)return 0;let f=[...u[0],...u[1]];return f.every(c=>c===f[0])?2:1}function js(t,e,n){let o=Tl(t,n),r=Sl(t,e),s=Rl(t,n);return{score:o.score*3+r*2+s*2,details:{conn:o.score,variance:r,sameSide:s}}}function Dl(t){let e=t.end.x-t.start.x,n=t.end.y-t.start.y,o=Math.atan2(n,e)*(180/Math.PI);return o<0&&(o+=180),o}function vl(t,e){let n=[];for(let o of t){let r=!1;for(let s of n){let i=Math.abs(o.angle-s[0].angle);if(Math.min(i,180-i)<=e){s.push(o),r=!0;break}}r||n.push([o])}return n}function Vl(t,e=.04){let n=[];for(let o of t){let r=!1;for(let s of n)if(Math.abs(o.offset-s[0].offset)<=e){s.push(o),r=!0;break}r||n.push([o])}return n}function Il(t,e,n,o,r){let s=[];for(let f of t){let d=f.seg,c=(d.start.x-e.start.x)*n+(d.start.y-e.start.y)*o,a=(d.end.x-e.start.x)*n+(d.end.y-e.start.y)*o;c<=a?s.push({l:c,r:a,idx:f.idx,startPt:d.start,endPt:d.end}):s.push({l:a,r:c,idx:f.idx,startPt:d.end,endPt:d.start})}s.sort((f,d)=>f.l-d.l);let i=[],l=.01,u=.5;for(let{l:f,r:d,idx:c,startPt:a,endPt:h}of s){if(i.length===0){i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h});continue}let g=i[i.length-1];if(f<=g.r+r){let b=Math.min(g.r,d)-Math.max(g.l,f),x=Math.hypot(g.endPt.x-a.x,g.endPt.y-a.y);b>=u||x<=l?(f<g.l&&(g.l=f,g.startPt=a),d>g.r&&(g.r=d,g.endPt=h),g.srcIdxs.includes(c)||g.srcIdxs.push(c)):i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h})}else i.push({l:f,r:d,srcIdxs:[c],startPt:a,endPt:h})}return i}function Cl(t,e,n,o,r,s,i){let l=Math.hypot(n.x-e.x,n.y-e.y),u={...t};return u.start={...e},u.end={...n},u.length=l,u.direction={x:o,y:r,z:0},s!==void 0&&(u.rooftopPz=s),u.buildRosource=i,u.isRebuild=!1,u.doorAndBeamData||(u.doorAndBeamData=[]),u.insetionArr||(u.insetionArr=[]),u}function Hl(t,e){let n=!0;for(;n;){n=!1;for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){let s=t[o],i=t[r];if(s.rooftopPz!==void 0&&i.rooftopPz!==void 0&&Math.abs(s.rooftopPz-i.rooftopPz)>.05)continue;let l=Math.abs(s.end.x-i.start.x)<.001&&Math.abs(s.end.y-i.start.y)<.001,u=Math.abs(s.start.x-i.end.x)<.001&&Math.abs(s.start.y-i.end.y)<.001,f=Math.abs(s.end.x-i.end.x)<.001&&Math.abs(s.end.y-i.end.y)<.001,d=Math.abs(s.start.x-i.start.x)<.001&&Math.abs(s.start.y-i.start.y)<.001;if(!(l||u||f||d)||s.direction.x*i.direction.x+s.direction.y*i.direction.y<.98)continue;let a=s.start,h=s.end;l?h=i.end:u?a=i.start:f?h=i.start:d&&(a=i.end);let g=Math.hypot(h.x-a.x,h.y-a.y),b={...s};b.start=a,b.end=h,b.length=g,b.direction={x:(h.x-a.x)/g,y:(h.y-a.y)/g,z:0},s.rooftopPz!==void 0&&i.rooftopPz!==void 0?b.rooftopPz=Math.max(s.rooftopPz,i.rooftopPz):b.rooftopPz=s.rooftopPz!==void 0?s.rooftopPz:i.rooftopPz,b.buildRosource=s.buildRosource||i.buildRosource,b.isRebuild=!1,b.doorAndBeamData||(b.doorAndBeamData=[]),b.insetionArr||(b.insetionArr=[]),t[o]=b,e[o]=[...new Set([...e[o],...e[r]])],t.splice(r,1),e.splice(r,1),r--,n=!0}}return{segments:t,sourceMap:e}}function Ye(t,e=5,n=.05){if(t.length<=1)return{segments:t,sourceMap:t.map((u,f)=>[f])};let o=t.map((u,f)=>({seg:u,angle:Dl(u),idx:f}));o.sort((u,f)=>u.angle-f.angle);let r=vl(o,e),s=[],i=[],l=[];for(let u of r){let f=u[0].seg;for(let m of u)m.seg.length>f.length&&(f=m.seg);let d=f.end.x-f.start.x,c=f.end.y-f.start.y,a=Math.sqrt(d*d+c*c);if(a<1e-12)continue;let h=-c/a,g=d/a,b=u.map(m=>{let p=m.seg.start.x-f.start.x,y=m.seg.start.y-f.start.y;return{seg:m.seg,offset:Math.abs(p*h+y*g),idx:m.idx}});b.sort((m,p)=>m.offset-p.offset);let x=Vl(b);for(let m of x){let p=m[0].seg;for(let T of m)T.seg.length>p.length&&(p=T.seg);let y=p.end.x-p.start.x,w=p.end.y-p.start.y,z=Math.sqrt(y*y+w*w);if(z<1e-12)continue;let M=y/z,P=w/z,E=m.map(T=>T.seg.rooftopPz).filter(T=>T!==void 0),S=E.length>0?Math.max(...E):void 0,I=[...new Set(E.map(T=>T.toFixed(3)))];if(I.length>1){let T=m.map(R=>({idx:R.idx,start:{x:R.seg.start.x,y:R.seg.start.y,z:R.seg.start.z},end:{x:R.seg.end.x,y:R.seg.end.y,z:R.seg.end.z},length:R.seg.length,rooftopPz:R.seg.rooftopPz}));l.push({values:[...I],segments:T})}let W=[...new Set(m.map(T=>String(T.seg.buildRosource)))],v=Il(m,p,M,P,n);for(let{l:T,r:R,srcIdxs:D,startPt:H,endPt:V}of v){if(R-T<.01)continue;let C=Cl(p,H,V,M,P,S,p.buildRosource);s.push(C),i.push(D)}}}return{...Hl(s,i),debugRPZGroups:l}}function Wl(t){return{minLengthRatio:0,maxDistance:.5,angleThreshold:45,projectionMargin:.1,printOnly:!0,minEmbedRatioThreshold:.3,noWallSurroundDistance:.3,minEmbedRatio:.05,...t}}function _l(t,e,n){return[{x:e,y:n,z:0},{x:t[0].x,y:t[0].y,z:0},{x:t[1].x,y:t[1].y,z:0},{x:t[2].x,y:t[2].y,z:0},{x:t[3].x,y:t[3].y,z:0}]}function Al(t,e,n,o,r,s,i,l,u){if(!["_008","_002","_014","_015","_020"].some(c=>t.includes(c)))return;e.map(c=>{let{start:a,end:h}=c,g=jt(n,o,a.x,a.y,h.x,h.y),b=r.map(z=>{let M=jt(z.x,z.y,a.x,a.y,h.x,h.y);return`t=${M.t.toFixed(3)},d=${M.dist.toFixed(3)}`}),x=h.x-a.x,m=h.y-a.y,p=Math.sqrt(x*x+m*m)||1,y=Math.abs(i*(x/p)+l*(m/p)),w=Math.acos(Math.min(y,1))*(180/Math.PI);return{seg:c,lineDist:g.dist,t:g.t,pts:b,angle:w,length:c.length}}).sort((c,a)=>c.lineDist-a.lineDist)}function Ll(t,e,n,o,r,s,i,l,u){let f=[{margin:s.projectionMargin,maxDist:s.maxDistance,label:"\u4E25\u683C"},{margin:.4,maxDist:.65,label:"\u5BBD\u677E"}],d=[],c=As(l)||e;for(let a of f){if(d.length>0)break;for(let h of t){let{start:g,end:b}=h,x=!1,m=1/0;for(let E of r){let{dist:S,t:I}=jt(E.x,E.y,g.x,g.y,b.x,b.y);I>=-a.margin&&I<=1+a.margin&&S<=a.maxDist&&(x=!0,S<m&&(m=S))}if(!x)continue;let p=null;if(u&&(p=Ls(u,g,b,.3)),!p||!p.hingePoint){let E=_s(l,g,b,.1);E&&E.hingeEdge&&(p={...E,hingePoint:E.hingeEdge?{x:E.hingeEdge.midX,y:E.hingeEdge.midY,z:0}:null,otherPoint:E.otherEdge?{x:E.otherEdge.midX,y:E.otherEdge.midY,z:0}:null})}p&&p.hingePoint&&jt(r[0].x,r[0].y,g.x,g.y,b.x,b.y).dist>.3&&(p=null);let y=!1;if(!p||!p.hingePoint){let E=jt(r[0].x,r[0].y,g.x,g.y,b.x,b.y);if(m<.15&&E.dist<.3&&h.originalPoints&&h.originalPoints.length>=50&&h.length>=.5)y=!0;else continue}if(!y&&(p.hingeT<-a.margin||p.hingeT>1+a.margin)){let E=jt(r[0].x,r[0].y,g.x,g.y,b.x,b.y);if(m<.15&&E.dist<.3&&h.originalPoints&&h.originalPoints.length>=50&&h.length>=.5)y=!0,h.__candidatesDebug="hingeT\u8D85\u8303\u56F4-\u5BC6\u5EA6\u515C\u5E95";else continue}let w=y?0:p.isClosed?1:.5,z=[r[1],r[2],r[3],r[4]],M=Hs(g.x,g.y,b.x,b.y,z),P=c>0?M/c:0;d.push({seg:h,minDist:m,embedRatio:P,ratio:h.length/c,score:0,details:{conn:0,variance:0,sameSide:0},hingeInfo:p,hingeScore:w})}}return d}function Bl(t,e,n,o){if(t.length<=1)return t.length===1&&(t[0].score=-1),t;for(let r of t){let{score:s,details:i}=js(r.seg,e,n);r.score=s,r.details=i}return t.sort((r,s)=>{let i=r.hingeScore||0;return(s.hingeScore||0)-i||s.embedRatio-r.embedRatio||s.score-r.score||r.minDist-s.minDist}),t}function kl(t,e,n,o){let r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=Math.sqrt(r*r+s*s),l=r/i,u=s/i,f=e.map(P=>{let E=P.x-t.start.x,S=P.y-t.start.y;return(E*l+S*u)/i}),d=Math.min(...f),c=Math.max(...f),a=(c-d)*i,h=(d+c)/2,g=t.start.x+h*r,b=t.start.y+h*s,x=n.coordinatesByArea.heightData?.minZ?n.coordinatesByArea.heightData.minZ:0,m=n.coordinatesByArea.heightData?.maxZ?n.coordinatesByArea.heightData.maxZ:0,p=Math.abs(m-x),y=Ge(o,t.start.x,t.start.y),w=Math.max(0,x-y),z=d<=0&&c>=1,M=t.start.z+h*(t.end.z-t.start.z);return{p:{x:g,y:b,z:M},width:a,full:z,height:p,groundClearance:w,wallTMin:Math.max(0,Math.min(1,d)),wallTMax:Math.max(0,Math.min(1,c))}}function Uo(t,e,n){let o=e.map(d=>n[d]),r=[],s=[],i=[],l=[],u,f;for(let d of o){if(d.originalPoints?.length)for(let c of d.originalPoints)r.push(c);if(d.doorAndBeamData?.length)for(let c of d.doorAndBeamData)s.push(c);if(d.insetionArr?.length)for(let c of d.insetionArr)i.push(c);if(d.DrawDoor?.length)for(let c of d.DrawDoor)l.push(c);d.boxData&&!u&&(u=d.boxData),d.rooftopPz!==void 0&&(f===void 0||d.rooftopPz>f)&&(f=d.rooftopPz)}r.length&&(t.originalPoints=r),s.length&&(t.doorAndBeamData=s),i.length&&(t.insetionArr=i),l.length&&(t.DrawDoor=l),u&&(t.boxData=u),f!==void 0&&(t.rooftopPz=f)}function cn(t,e,n=10,o=.2,r=.2){let s=[];if(!t.DrawDoor)return s;let i=t.DrawDoor.p,l=t.wallSegment,u=l.end.x-l.start.x,f=l.end.y-l.start.y,d=Math.sqrt(u*u+f*f)||1,c=u/d,a=f/d,h=i.x-l.start.x,g=i.y-l.start.y,b=(h*c+g*a)/d;for(let x of e){if(x===l)continue;let m=x.end.x-x.start.x,p=x.end.y-x.start.y,y=Math.sqrt(m*m+p*p)||1,w=m/y,z=p/y,M=Math.abs(c*w+a*z),E=Math.acos(Math.min(M,1))*(180/Math.PI);if(Math.abs(E-90)>n)continue;let S=[x.start,x.end];for(let I of S){let W=I.x-l.start.x,v=I.y-l.start.y,T=(W*c+v*a)/d,R=l.start.x+T*d*c,D=l.start.y+T*d*a;if(Math.sqrt((I.x-R)**2+(I.y-D)**2)>r)continue;let V=Math.abs((T-b)*d);if(V<=o){s.push({seg:x,distAlongWall:V,angle:E,endPoint:I});break}}}return s}function Dn(t,e){let n=t.start,o=t.end,r=o.x-n.x,s=o.y-n.y,i=Math.sqrt(r*r+s*s)||1,l=((e.x-n.x)*r+(e.y-n.y)*s)/(i*i),u=Math.max(0,Math.min(1,l)),f={x:n.x+u*r,y:n.y+u*s,z:n.z+(o.z-n.z)*u||0};function d(y){if(!y||!y.length)return[[],[]];let w=[],z=[];for(let M of y){let P=((M.x-n.x)*r+(M.y-n.y)*s)/(i*i);P<=u+1e-8&&w.push(M),P>=u-1e-8&&z.push(M)}return(w.length===0||c(w[w.length-1],f)>1e-6)&&w.push({...f}),(z.length===0||c(z[0],f)>1e-6)&&z.unshift({...f}),[w,z]}function c(y,w){return Math.sqrt((y.x-w.x)**2+(y.y-w.y)**2)}let[a,h]=d(t.originalPoints),g=Math.max(u*i,1e-6),b=Math.max((1-u)*i,1e-6),x=t.direction||{x:r/i,y:s/i,z:(o.z-n.z)/i||0},m={...t,start:{...n},end:{...f},length:g,direction:{...x},originalPoints:a.length?a:void 0},p={...t,start:{...f},end:{...o},length:b,direction:{...x},originalPoints:h.length?h:void 0};if("isRebuild"in t&&(m.isRebuild=t.isRebuild,p.isRebuild=t.isRebuild),t.DrawDoor&&t.DrawDoor.length>0){let y=[],w=[];for(let z of t.DrawDoor){let M=((z.p.x-n.x)*r+(z.p.y-n.y)*s)/(i*i);M<=u+1e-8&&y.push(z),M>=u-1e-8&&w.push(z)}m.DrawDoor=y.length?y:void 0,p.DrawDoor=w.length?w:void 0}else m.DrawDoor=void 0,p.DrawDoor=void 0;if(t.boxData){let y=w=>{if(!w.length)return;let z=1/0,M=1/0,P=1/0,E=-1/0,S=-1/0,I=-1/0;for(let W of w)W.x<z&&(z=W.x),W.y<M&&(M=W.y),W.z!==void 0&&W.z<P&&(P=W.z),W.x>E&&(E=W.x),W.y>S&&(S=W.y),W.z!==void 0&&W.z>I&&(I=W.z);return{isBox3:!0,min:{x:z,y:M,z:P},max:{x:E,y:S,z:I}}};m.boxData=y(a),p.boxData=y(h)}return[m,p]}function vn(t,e,n,o){let r=Wl(n),s=[],{segments:i,sourceMap:l}=o??Ye(e),u=i,f=ks(u);for(let d of t){let c=d.coordinatesByArea?.coordinates;if(!c||c.length<4)continue;let a=c.slice(0,4),h=Go(d.nline),g=ro(a),b,x,m,p,y;if(h?(b=h.midX,x=h.midY,m=h.length,p=h.dirX,y=h.dirY):(b=a.reduce((L,O)=>L+O.x,0)/4,x=a.reduce((L,O)=>L+O.y,0)/4,m=g.longSide,p=g.dirX,y=g.dirY),m<.01)continue;let w=a.reduce((L,O)=>L+O.z,0)/4,z=Ge(e,b,x);if(w<z-.3)continue;let M=Ws(a),P=[...a].sort((L,O)=>L.z-O.z),E=P[0].x-P[1].x,S=P[0].y-P[1].y,I=Math.sqrt(E*E+S*S),W=_l(a,b,x);Al(d.name,u,b,x,W,m,p,y,r);let v=Ll(u,I,p,y,W,r,d.name,M,d.nline);if(v.length>0)for(let L=0;L<v.length;L++){let O=v[L],$=O.seg,Z=!!O.hingeInfo?.hingePoint,Q=O.hingeInfo?.isClosed,j=O.hingeInfo?.hingeDist??-1,X=jt(W[0].x,W[0].y,$.start.x,$.start.y,$.end.x,$.end.y)}if(v=Bl(v,W,e,d.name),v.length===0){for(let O of u){let $=O.start.x+(O.end.x-O.start.x)/2-b,Z=O.start.y+(O.end.y-O.start.y)/2-x;if(Math.sqrt($*$+Z*Z)>2)continue;let j=O.end.x-O.start.x,X=O.end.y-O.start.y,U=Math.sqrt(j*j+X*X),lt=j/U,mt=X/U,St=Math.abs(lt*p+mt*y),ot=Math.acos(Math.min(1,Math.abs(St)))*180/Math.PI,Mt=jt(b,x,O.start.x,O.start.y,O.end.x,O.end.y)}let L=0;for(let O of u)jt(b,x,O.start.x,O.start.y,O.end.x,O.end.y).dist<2&&L++}let T=I;for(let L of v){let O=L.seg;if(O.originalPoints&&O.originalPoints.length>100&&O.length>.5)try{let $=so(O,.1),Z=Fs(O,$,O.length,.5,.5,3,.35),Q,j=!1;if(d.nline){let mt=Ns(d.nline,O.start,O.end);if(mt)Q=mt.hingeT,j=mt.hingeDist>.05;else{let St=jt(b,x,O.start.x,O.start.y,O.end.x,O.end.y);Q=Math.max(0,Math.min(1,St.t))}}else{let mt=jt(b,x,O.start.x,O.start.y,O.end.x,O.end.y);Q=Math.max(0,Math.min(1,mt.t))}let X=Bs($),U,lt=X<=.3;lt?U={score:Yo($.avgDensity,f),bestRegion:null,bestOverlap:0,bestOpeningStartT:0,bestOpeningEndT:1}:(U=qs({hingeT:Q,doorWidth:T,isOpenDoor:j},Z,O.length,f.medianDensity),U.score<0&&(U={score:Yo($.avgDensity,f),bestRegion:null,bestOverlap:0,bestOpeningStartT:0,bestOpeningEndT:1})),d.name.includes("door_002")&&(window.__doorLog=!0),L.densityScore=U.score,L.densityOverlap=U.bestOverlap,L.rectangularRegions=Z,L.densityResult=$,L.densityOpeningStartT=U.bestOpeningStartT,L.densityOpeningEndT=U.bestOpeningEndT,L.densityCV=X,L.densityUsedGlobalRank=lt}catch{L.densityScore=-1}else L.densityScore=-1}if(d.name.includes("door_002"))for(let L=0;L<v.length;L++){let $=v[L].seg,Z=u.findIndex(j=>Math.abs(j.start.x-$.start.x)<.001&&Math.abs(j.start.y-$.start.y)<.001&&Math.abs(j.end.x-$.end.x)<.001&&Math.abs(j.end.y-$.end.y)<.001),Q=Z>=0?l[Z]||[]:[];for(let j of Q){let X=e[j]}}if(v.sort((L,O)=>{let $=L.densityScore>=0?L.densityScore:-1/0,Z=O.densityScore>=0?O.densityScore:-1/0;if($!==Z)return Z-$;if(Math.abs($-Z)<.3){let X=L.ratio||0,U=O.ratio||0,lt=Math.abs(X-1),mt=Math.abs(U-1);if(lt!==mt)return lt-mt}let Q=L.hingeScore||0,j=O.hingeScore||0;return Q!==j?j-Q:L.minDist-O.minDist}),v.length>0)for(let L=0;L<v.length;L++){let O=v[L],$=O.seg,Z=O.ratio||$.length/T,Q=Math.abs(Z-1)}let R=null,D=1/0,H=0,V=0,C=null,_=-1,A=0,B=0,k=0;if(v.length>0){let L=v[0];R=L.seg,D=L.minDist,H=L.ratio,V=L.embedRatio,C=L.hingeInfo,_=L.densityScore??-1,A=L.densityOverlap??0,B=L.densityOpeningStartT??0,k=L.densityOpeningEndT??0}let F;if(R&&(F=kl(R,a,d,i),F&&k>B&&(F.wallTMin=Math.max(0,Math.min(1,B)),F.wallTMax=Math.max(0,Math.min(1,k))),!r.printOnly)){let L=R;L.DrawDoor||(L.DrawDoor=[]),L.DrawDoor.push(F),L.isDoor=!0}if(R){let L=v.map(($,Z)=>{let Q=$.seg;return{start:{x:Q.start.x,y:Q.start.y,z:Q.start.z},end:{x:Q.end.x,y:Q.end.y,z:Q.end.z},length:Q.length,densityScore:$.densityScore??-1,hingeScore:$.hingeScore??0,minDist:$.minDist,ratio:$.ratio,isWinner:Z===0}}),O={doorName:d.name,doorCategory:d.category,doorCenter:d.center,wallSegment:R,distance:D,wallLengthRatio:H,DrawDoor:F,densityScore:_,densityOverlap:A,candidates:L,hingePoint:C?.hingePoint,otherPoint:C?.otherPoint,isClosed:C?.isClosed,doorWidth:F?.width,wallTMin:F?.wallTMin,wallTMax:F?.wallTMax};if(s.push(O),(d.name==="1527727501200_window_001"||d.name==="1527727427200_window_001")&&F){let $=R.end.x-R.start.x,Z=R.end.y-R.start.y,Q=Math.sqrt($*$+Z*Z),j=$/Q,X=Z/Q,U=F.p.x-R.start.x,lt=F.p.y-R.start.y,mt=(U*j+lt*X)/Q,St=0;for(let ot of i){if(ot===R)continue;let Mt=ot.end.x-ot.start.x,bt=ot.end.y-ot.start.y,Ct=Math.sqrt(Mt*Mt+bt*bt)||1,Et=Mt/Ct,zt=bt/Ct,Pt=Math.abs(j*Et+X*zt),et=Math.acos(Math.min(Pt,1))*(180/Math.PI);if(Math.abs(et-90)>10)continue;St++;let ht=[ot.start,ot.end],nt="";for(let J of ht){let ae=J.x-R.start.x,wt=J.y-R.start.y,te=(ae*j+wt*X)/Q,ge=R.start.x+te*Q*j,Dt=R.start.y+te*Q*X,ne=Math.sqrt((J.x-ge)**2+(J.y-Dt)**2),xe=Math.abs((te-mt)*Q);nt+=`\u7AEF(${J.x.toFixed(2)},${J.y.toFixed(2)})\u22A5=${ne.toFixed(3)}m \u6CBF\u5899=${xe.toFixed(3)}m `}}}if(F&&F.width>1){let $=cn(O,i);$.length>0&&$.forEach((Z,Q)=>{})}}}for(let d of s){let c=d.wallSegment,a=i.indexOf(c);if(a===-1)continue;let h=l[a];!h||h.length<=1||Uo(c,h,e)}return s}function io(t){return[t.wallTMin??0,t.wallTMax??1]}function Ol(t,e){let[n,o]=io(t),[r,s]=io(e),i=Math.max(0,Math.min(o,s)-Math.max(n,r)),l=Math.min(o-n,s-r);return l>0?i/l:0}function Fl(t,e){if(!t.hingePoint||!e.hingePoint)return null;let n=t.hingePoint.x-e.hingePoint.x,o=t.hingePoint.y-e.hingePoint.y;return Math.sqrt(n*n+o*o)}function $s(t,e){let n=e.end.x-e.start.x,o=e.end.y-e.start.y,r=n*n+o*o;if(r<1e-10)return 0;let s=((t.x-e.start.x)*n+(t.y-e.start.y)*o)/r;return Math.max(0,Math.min(1,s))}function Xs(t,e={}){let n=e.minTOverlapRatio??.5,o=e.maxHingeDist??.3,r=e.minHingeTOverlapRatio??.2;if(t.length<2)return{matches:t,removed:[]};let s=new Set,i=new Map;for(let d=0;d<t.length;d++){let a=t[d].wallSegment;i.has(a)||i.set(a,[]),i.get(a).push(d)}let l=0;for(let[d,c]of i){l++;let a=c.map(b=>t[b].doorName).join(", "),h=d.start,g=d.end}for(let[,d]of i){if(d.length<2)continue;let c=[...d].sort((a,h)=>{let g=t[a].densityScore??0;return(t[h].densityScore??0)-g});for(let a=0;a<c.length;a++){let h=c[a];if(s.has(h))continue;let g=t[h];for(let b=a+1;b<c.length;b++){let x=c[b];if(s.has(x))continue;let m=t[x],p=!1,y="",w=Ol(g,m),z=[g.hingePoint,g.otherPoint].filter(Boolean),M=[m.hingePoint,m.otherPoint].filter(Boolean),P=null;for(let H of z)for(let V of M){let C=Math.sqrt((H.x-V.x)**2+(H.y-V.y)**2);if(C>.25)continue;let _=$s(H,g.wallSegment),A=$s(V,m.wallSegment),B=Math.abs(_-A);(!P||C<P.dist)&&(P={dist:C,tDiff:B})}P&&P.tDiff<=.08&&(p=!0,y=`\u6700\u77ED\u8FB9\u8DDD=${P.dist.toFixed(3)}m t\u5DEE=${P.tDiff.toFixed(3)}`);let[E,S]=io(g),[I,W]=io(m),v=Fl(g,m);g.doorName.includes("door_002")||g.doorName.includes("door_004")||m.doorName.includes("door_002")||m.doorName.includes("door_004");let T=[g.hingePoint,g.otherPoint].filter(Boolean),R=[m.hingePoint,m.otherPoint].filter(Boolean),D=1/0;for(let H of T)for(let V of R){let C=Math.sqrt((H.x-V.x)**2+(H.y-V.y)**2);C<D&&(D=C)}p&&s.add(x)}}}let u=t.filter((d,c)=>!s.has(c)),f=t.filter((d,c)=>s.has(c)).map(d=>d.doorName);return{matches:u,removed:f}}function Ko(t,e,n){let o={printOnly:!1,skipMerge:!1,...n};for(let m of t)m.DrawDoor&&(m.DrawDoor=void 0),m.isDoor&&(m.isDoor=void 0),m.drawDoorData&&(m.drawDoorData=void 0);let r=Array.isArray(e)?e.filter(m=>m&&m.category==="door"&&!m.isFindBeam):[],s,i;if(o.skipMerge)s=t,i=t.map((m,p)=>[p]);else{let m=Ye(t);s=m.segments,i=m.sourceMap}for(let m=0;m<s.length;m++){let p=i[m];p&&!s[m].originalPoints&&Uo(s[m],p,t)}let l=vn(r,t,o,{segments:s,sourceMap:i}),f=Xs(l,{minTOverlapRatio:.5}).matches,d=new Set(f.map(m=>m.doorName));for(let m of s){let p=m;if(p.DrawDoor&&p.DrawDoor.length>0){let y=l.filter(z=>z.wallSegment===m).length;f.filter(z=>z.wallSegment===m).length===0&&(p.DrawDoor=[],p.isDoor=!1)}}let c=new Map;for(let m=0;m<f.length;m++){let p=f[m],y=s.indexOf(p.wallSegment);y>=0&&c.set(y,m)}let a=[],h=new Set,g=new Map;for(let m of e)m&&m.name&&g.set(m.name,m);for(let[m,p]of c){let y=i[m];if(!y)continue;let w=s[m],z=w.DrawDoor,M=w.isDoor,P=w.end.x-w.start.x,E=w.end.y-w.start.y,S=P*P+E*E,I=0,W=1,v=f[p],R=(v?g.get(v.doorName):void 0)?.coordinatesByArea?.coordinates;if(R&&R.length>=4&&S>0){let C=R.slice(0,4).map(_=>{let A=_.x-w.start.x,B=_.y-w.start.y;return(A*P+B*E)/S});I=Math.max(0,Math.min(1,Math.min(...C))),W=Math.max(0,Math.min(1,Math.max(...C)))}let D,H;S>0&&W>I&&(D={x:w.start.x+I*P,y:w.start.y+I*E,z:w.start.z+I*(w.end.z-w.start.z)},H={x:w.start.x+W*P,y:w.start.y+W*E,z:w.start.z+W*(w.end.z-w.start.z)});let V=!1;for(let C of y){let _=t[C];if(!_)continue;let A=_.end.x-_.start.x,B=_.end.y-_.start.y,k=A*A+B*B,F=Math.sqrt(k);if(k<1e-10||!D||!H){h.add(C),a.push(_);continue}let L=((D.x-_.start.x)*A+(D.y-_.start.y)*B)/k,O=((H.x-_.start.x)*A+(H.y-_.start.y)*B)/k,$=Math.max(0,Math.min(1,Math.min(L,O))),Z=Math.max(0,Math.min(1,Math.max(L,O)));if(Z-$<.001)continue;h.add(C);let Q=ot=>({x:_.start.x+ot*A,y:_.start.y+ot*B,z:_.start.z+ot*(_.end.z-_.start.z)}),j=Q($),X=Q(Z),U=_.direction||{x:A/F,y:B/F,z:0},lt,mt,St;if(_.originalPoints&&_.originalPoints.length>0){lt=[],mt=[],St=[];for(let ot of _.originalPoints){let Mt=((ot.x-_.start.x)*A+(ot.y-_.start.y)*B)/k;Mt<$-1e-8?lt.push(ot):Mt>Z+1e-8?St.push(ot):mt.push(ot)}lt.length===0&&(lt=void 0),mt.length===0&&(mt=void 0),St.length===0&&(St=void 0)}if($>.001){let ot={..._,start:{..._.start},end:{...j},length:$*F,direction:{...U}};ot.DrawDoor=void 0,ot.isDoor=!1,ot.drawDoorData=void 0,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=lt,a.push(ot)}{let ot={..._,start:{...j},end:{...X},length:(Z-$)*F,direction:{...U}};if(z&&(ot.DrawDoor=z),M&&(ot.isDoor=!0),ot.__matchIdx=p,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=mt,!V&&z&&z.length>0){let Mt=0;for(let Pt=0;Pt<z.length;Pt++)if(zr(D,H,z[Pt].p)){Mt=Pt;break}V=!0;let bt=Math.sqrt(S),Ct=bt>0?-E/bt:0,Et=bt>0?P/bt:0,zt={pointNum:2,start:D,end:H,n:{x:Ct,y:Et,z:0},height:z[Mt].height,groundClearance:z[Mt].groundClearance};ot.drawDoorData=zt}a.push(ot)}if(Z<.999){let ot={..._,start:{...X},end:{..._.end},length:(1-Z)*F,direction:{...U}};ot.DrawDoor=void 0,ot.isDoor=!1,ot.drawDoorData=void 0,ot.length<.01?(ot.isRebuild=!0,ot.originalPoints=[]):ot.originalPoints=St,a.push(ot)}}}for(let m=0;m<t.length;m++)h.has(m)||a.push(t[m]);let b=new Set(f.map(m=>m.doorName));for(let m of e)m&&m.category==="door"&&(b.has(m.name)?delete m.AbnormalDoor:m.AbnormalDoor=!0);let x=new Map;for(let m of f){if(!m.DrawDoor||m.DrawDoor.width<=1)continue;let p=g.get(m.doorName);if(!p||!p.positionArr||!p.positionArr.length)continue;let y=cn(m,s);if(y.length<=1)continue;let w=p.positionArr[0],z=m.DrawDoor.p,M=w.x-z.x,P=w.y-z.y,E=Math.sqrt(M*M+P*P);if(E<.001)continue;let S=M/E,I=P/E,W=y.filter(C=>{let _=(C.seg.start.x+C.seg.end.x)/2,A=(C.seg.start.y+C.seg.end.y)/2,B=_-z.x,k=A-z.y;return B*S+k*I>0});if(!W.length)continue;let v=W[0].endPoint,T=m.wallSegment;if(x.has(T))continue;let[R,D]=Dn(T,v);x.set(T,[R,D]);let H=((z.x-T.start.x)*(T.end.x-T.start.x)+(z.y-T.start.y)*(T.end.y-T.start.y))/(T.length*T.length),V=((v.x-T.start.x)*(T.end.x-T.start.x)+(v.y-T.start.y)*(T.end.y-T.start.y))/(T.length*T.length);H<=V?m.wallSegment=R:m.wallSegment=D}if(x.size>0){let m=[];for(let p of a)x.has(p)?m.push(...x.get(p)):m.push(p);for(let p of m)p.isDoor=!!(p.DrawDoor&&p.DrawDoor.length>0);return{segments:m,matches:f}}for(let m of a)m.isDoor=!!(m.DrawDoor&&m.DrawDoor.length>0);return{segments:a,matches:f}}var Nl={findWalls:Rn,mergeSegments:Xe,computeFloorZ:$e,analyzeQuadrangle:je,detectPerpWalls:Tn,splitSegment:Sn,process:Xo},ql={findWalls:vn,mergeSegments:Ye,computeFloorZ:Ge,analyzeQuadrangle:je,detectPerpWalls:cn,splitSegment:Dn,process:Ko};function un(t){return t==="window"?Nl:ql}function jl(t,e,n,o,r){return un(t).findWalls(e,n,o,r)}function $l(t,e,n,o){return un(t).process(e,n,o)}function Xl(t,e){return un(t).mergeSegments(e)}function Zl(t,e,n){return un(t).detectPerpWalls(e,n)}function Gl(t,e,n){return un(t).splitSegment(e,n)}function Ue(t,e){let n=Math.atan2(e,t);return n<0&&(n+=Math.PI),n>=Math.PI&&(n-=Math.PI),n}function He(t,e,n){let o=Math.cos(n),r=Math.sin(n);return{x:t*o-e*r,z:t*r+e*o}}function ao(t,e,n,o,r,s){let i=r-n,l=s-o,u=i*i+l*l;if(u<1e-10){let g=t-n,b=e-o;return Math.sqrt(g*g+b*b)}let f=((t-n)*i+(e-o)*l)/u;f=Math.max(0,Math.min(1,f));let d=n+f*i,c=o+f*l,a=t-d,h=e-c;return Math.sqrt(a*a+h*h)}function Zs(t){if(t.length<3)return 0;let e=0,n=t.length;for(let o=0;o<n;o++){let r=(o+1)%n;e+=t[o].x*t[r].z,e-=t[r].x*t[o].z}return Math.abs(e)/2}function Qo(t){let e=t.x2-t.x1,n=t.z2-t.z1;return Math.sqrt(e*e+n*n)}function lo(t){if(!t.length)return{rotated:[],mainAngle:0};let e=180,n=new Array(e).fill(0),o=Math.PI/e;for(let d of t){let c=d.x2-d.x1,a=d.z2-d.z1,h=Math.sqrt(c*c+a*a);if(h<.01)continue;let g=Ue(c,a),b=Math.floor(g/o);b>=e&&(b=e-1),n[b]+=h}let r=new Array(e).fill(0),s=5;for(let d=0;d<e;d++){let c=0;for(let a=-s;a<=s;a++){let h=d+a;h<0&&(h+=e),h>=e&&(h-=e),c+=n[h]}r[d]=c}let i=0,l=0;for(let d=0;d<e;d++)r[d]>i&&(i=r[d],l=d);let u=(l+.5)*o;return{rotated:t.map(d=>{let c=He(d.x1,d.z1,-u),a=He(d.x2,d.z2,-u);return{...d,x1:c.x,z1:c.z,x2:a.x,z2:a.z}}),mainAngle:u}}var Jo=15*(Math.PI/180);function co(t,e,n=.15,o=.5){let r=[];for(let d of t){let c=d.x2-d.x1,a=d.z2-d.z1,h=Math.sqrt(c*c+a*a);if(h<.01)continue;let g=Ue(c,a),b;if(e==="X"?b=g<Jo||g>Math.PI-Jo:b=Math.abs(g-Math.PI/2)<Jo,!b)continue;let x,m,p;e==="X"?(x=(d.z1+d.z2)/2,m=Math.min(d.x1,d.x2),p=Math.max(d.x1,d.x2)):(x=(d.x1+d.x2)/2,m=Math.min(d.z1,d.z2),p=Math.max(d.z1,d.z2)),r.push({line:d,offset:x,pStart:m,pEnd:p,length:h})}if(r.length===0)return{groups:[],lineToGroup:new Map};r.sort((d,c)=>d.offset-c.offset);let s=[],i=[r[0]],l=r[0].offset;for(let d=1;d<r.length;d++){let c=r[d];Math.abs(c.offset-l)<n?i.push(c):(s.push(i),i=[c],l=c.offset)}i.length>0&&s.push(i);let u=[],f=new Map;for(let d of s){d.sort((a,h)=>a.pStart-h.pStart);let c=[];for(let a of d){let h=!1;for(let g of c)if(a.pStart<=g.end+o){g.items.push(a),g.end=Math.max(g.end,a.pEnd),h=!0;break}h||c.push({items:[a],end:a.pEnd})}for(let a of c){let h=a.items.map(b=>b.line),g=u.length;u.push(h);for(let b of h)f.set(b.id,g)}}return{groups:u,lineToGroup:f}}function uo(t,e,n=.3){let o=new Map;for(let r of t){let s=null,i=1/0;for(let l of e){let u=ao(r.x,r.z,l.x1,l.z1,l.x2,l.z2);u<i&&(i=u,s=l.id)}s!==null&&i<=n&&o.set(r.id,s)}return o}var fn=.15;function Yl(t,e){return Math.round(t/fn)+"_"+Math.round(e/fn)}function Gs(t,e=5){if(t.length<3)return new Set;let n=new Map,o=0,r=0;function s(u,f){let d=Yl(u,f),c=n.get(d);if(c)return c;let a=Math.round(u/fn),h=Math.round(f/fn),g=null,b=fn*fn;for(let x=-1;x<=1;x++)for(let m=-1;m<=1;m++){let p=a+x+"_"+(h+m),y=n.get(p);if(!y)continue;let w=y.x-u,z=y.z-f,M=w*w+z*z;M<b&&(b=M,g=y)}return g?(n.set(d,g),g):(c={id:o++,x:u,z:f,edges:[]},n.set(d,c),c)}let i=[];for(let u of t){let f=s(u.x1,u.z1),d=s(u.x2,u.z2);if(f.id===d.id)continue;let c=Math.atan2(d.z-f.z,d.x-f.x),a=Math.atan2(f.z-d.z,f.x-d.x),h={id:r++,wallId:u.id,from:f,to:d,twin:null,angle:c,visited:!1},g={id:r++,wallId:u.id,from:d,to:f,twin:h,angle:a,visited:!1};h.twin=g,f.edges.push(h),d.edges.push(g),i.push(h,g)}if(i.length<6)return new Set;for(let u of n.values())u.edges.sort((f,d)=>f.angle-d.angle);let l=new Set;for(let u of i){if(u.visited)continue;let f=[],d=u,c=i.length+10;for(;!d.visited&&f.length<c;){d.visited=!0,f.push(d);let a=d.to,h=d.twin,g=a.edges.indexOf(h);if(g<0)break;let b=(g+1)%a.edges.length;d=a.edges[b]}if(f.length>=3){let a=f[0];if(f[f.length-1].to.id===a.from.id){let g=[],b=new Set;for(let m of f)b.add(m.wallId),g.length===0&&g.push({x:m.from.x,z:m.from.z}),g.push({x:m.to.x,z:m.to.z});if(Zs(g)>=e)for(let m of b)l.add(m)}}}return l}var vp=12*(Math.PI/180);function Ys(t,e=2){let n=new Map;for(let o of t){let r=(o.x1+o.x2)/2,s=(o.z1+o.z2)/2,i=Math.floor(r/e),l=Math.floor(s/e),u=`${i},${l}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}var Ul=0;function Us(){return++Ul}function Ks(t,e,n=.15,o=.5){if(!t.length)return[];let r=10*Math.PI/180,s=[];for(let d of t){let c=d.x2-d.x1,a=d.z2-d.z1,h=Math.sqrt(c*c+a*a);if(!(h<.01))if(e==="X"){if(Math.abs(a)>h*Math.sin(r))continue;let g=(d.z1+d.z2)/2,b=Math.min(d.x1,d.x2),x=Math.max(d.x1,d.x2);s.push({line:d,pStart:b,pEnd:x,offset:g,yMin:Math.min(d.y1,d.y2),yMax:Math.max(d.y1,d.y2)})}else{if(Math.abs(c)>h*Math.sin(r))continue;let g=(d.x1+d.x2)/2,b=Math.min(d.z1,d.z2),x=Math.max(d.z1,d.z2);s.push({line:d,pStart:b,pEnd:x,offset:g,yMin:Math.min(d.y1,d.y2),yMax:Math.max(d.y1,d.y2)})}}if(!s.length)return[];s.sort((d,c)=>d.offset-c.offset);let i=[],l=[s[0]],u=s[0].offset;for(let d=1;d<s.length;d++){let c=s[d];Math.abs(c.offset-u)<n?l.push(c):(i.push(l),l=[c],u=c.offset)}i.push(l);let f=[];for(let d of i){d.sort((a,h)=>a.pStart-h.pStart);let c=[];for(let a of d){if(c.length===0){c.push({pStart:a.pStart,pEnd:a.pEnd,offset:a.offset,count:1,yMin:a.yMin,yMax:a.yMax});continue}let h=c[c.length-1];a.pStart<=h.pEnd+o?(h.pEnd=Math.max(h.pEnd,a.pEnd),h.count+=1,h.yMin=Math.min(h.yMin,a.yMin),h.yMax=Math.max(h.yMax,a.yMax),h.offset=(h.offset*(h.count-1)+a.offset)/h.count):c.push({pStart:a.pStart,pEnd:a.pEnd,offset:a.offset,count:1,yMin:a.yMin,yMax:a.yMax})}for(let a of c){let h=a.pEnd-a.pStart;if(h<.01)continue;let g;e==="X"?g={id:Us(),x1:a.pStart,y1:a.yMin,z1:a.offset,x2:a.pEnd,y2:a.yMax,z2:a.offset,length:h,pointCount:a.count,isMain:!1}:g={id:Us(),x1:a.offset,y1:a.yMin,z1:a.pStart,x2:a.offset,y2:a.yMax,z2:a.pEnd,length:h,pointCount:a.count,isMain:!1},f.push(g)}}return f}function Qs(t,e=.8,n=3){return t.filter(o=>o.length>=e&&o.pointCount>=n)}function Js(t,e=1,n=3){return t.filter(o=>o.length>=e&&o.pointCount>=n)}function Kl(t,e,n={}){let{distTol:o=.15,gapTol:r=.5,minLen:s=.2,minGroupLen:i=1,minArea:l=3,maxWinDist:u=.3,minLongWall:f=2}=n,d=performance.now(),{rotated:c,mainAngle:a}=lo(t),h=performance.now(),g=e.map(D=>{let H=He(D.x,D.z,-a);return{...D,x:H.x,z:H.z}}),{groups:b}=co(c,"X",o,r),{groups:x}=co(c,"Z",o,r),m=[...b,...x],p=performance.now(),y=new Map,w=[];for(let D=0;D<m.length;D++){let H=m[D];if(H.length===0){w.push(0);continue}let V=0;for(let C of H)V+=Qo(C),y.set(C.id,D);w.push(V)}let z=performance.now(),M=new Set;for(let D=0;D<m.length;D++)w[D]>=f&&M.add(D);if(M.size>0){let D=[...M];for(;D.length>0;){let H=D.shift(),V=m[H];for(let C=0;C<m.length;C++){if(M.has(C)||w[C]<i)continue;let _=m[C],A=!1;t:for(let B of V)for(let k of _)if(Math.hypot(B.x1-k.x1,B.z1-k.z1)<=fo||Math.hypot(B.x1-k.x2,B.z1-k.z2)<=fo||Math.hypot(B.x2-k.x1,B.z2-k.z1)<=fo||Math.hypot(B.x2-k.x2,B.z2-k.z2)<=fo){A=!0;break t}A&&(M.add(C),D.push(C))}}}let P=c.map((D,H)=>{let V=Qo(D),C=y.get(D.id),_=C!==void 0&&M.has(C),A=V>=f;return{id:H,x1:D.x1,y1:D.y1,z1:D.z1,x2:D.x2,y2:D.y2,z2:D.z2,length:V,pointCount:1,isMain:_||A}}),E=P.filter(D=>D.isMain),S=P.filter(D=>!D.isMain),I=performance.now(),W=uo(g,E,u),v=performance.now(),T=D=>D.map(H=>{let V=He(H.x1,H.z1,a),C=He(H.x2,H.z2,a);return{...H,x1:V.x,z1:V.z,x2:C.x,z2:C.z}}),R=performance.now();return console.log(`[\u4E3B\u4F53\u67B6\u6784] \u89D2\u5EA6\u5F52\u4E00\u5316: ${(h-d).toFixed(0)}ms`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u5171\u7EBF\u5206\u7EC4: ${(p-h).toFixed(0)}ms (\u6C34\u5E73${b.length}\u7EC4 \u5782\u76F4${x.length}\u7EC4)`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u7EC4\u5206\u6790+\u4E3B\u4F53\u5224\u5B9A: ${(R-p).toFixed(0)}ms (\u4E3B\u4F53\u7EC4${M.size} / \u603B\u7EC4${m.length})`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u6807\u8BB0\u539F\u59CB\u7EBF\u6BB5: ${(I-R).toFixed(0)}ms (\u4E3B\u4F53${E.length} / \u6742\u7EBF${S.length})`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u7A97\u6237\u6302\u63A5: ${(v-I).toFixed(0)}ms`),console.log(`[\u4E3B\u4F53\u67B6\u6784] \u603B\u8BA1: ${(v-d).toFixed(0)}ms`),{mainWalls:T(E),noiseWalls:T(S),windowToWall:W}}var fo=.2;function Se(t,e){let n=Math.atan2(e,t);return n<0&&(n+=Math.PI),n>=Math.PI&&(n-=Math.PI),n}function Vn(t){for(;t>Math.PI;)t-=2*Math.PI;for(;t<-Math.PI;)t+=2*Math.PI;return t}function ho(t){return t*Math.PI/180}function In(t,e,n){let o=Math.cos(n),r=Math.sin(n);return{x:t*o-e*r,z:t*r+e*o}}function Re(t){let e=0;for(let n=1;n<t.length;n++){let o=t[n].x-t[n-1].x,r=t[n].z-t[n-1].z;e+=Math.sqrt(o*o+r*r)}return e}function tr(t){if(t.length<3)return 0;let e=0,n=t.length;for(let o=0;o<n;o++){let r=(o+1)%n;e+=t[o].x*t[r].z,e-=t[r].x*t[o].z}return Math.abs(e)/2}function Me(t,e,n,o){let r=n-t,s=o-e;return Math.sqrt(r*r+s*s)}function Cn(t,e,n,o,r,s){let i=r-n,l=s-o,u=i*i+l*l;if(u<1e-6)return Me(t,e,n,o);let f=((t-n)*i+(e-o)*l)/u;return f=Math.max(0,Math.min(1,f)),Me(t,e,n+f*i,o+f*l)}function er(t){if(t.length<4)return t;let e=t.map(n=>({x:n.x,z:n.z}));for(let n=0;n<3;n++){let o=[{...e[0]}];for(let r=1;r<e.length-1;r++)o.push({x:(e[r-1].x+e[r].x+e[r+1].x)/3,z:(e[r-1].z+e[r].z+e[r+1].z)/3});o.push({...e[e.length-1]}),e=o}return e}function ti(t,e){let n=1/0;for(let o of t)for(let r=0;r<e.length-1;r++){let s=Cn(o.x,o.z,e[r].x,e[r].z,e[r+1].x,e[r+1].z);s<n&&(n=s)}return n}function mo(t,e){let n=new Map,o=1/0,r=-1/0,s=1/0,i=-1/0;for(let l of t){let u=Math.floor(l.x/e),f=Math.floor(l.z/e),d=u+","+f;n.set(d,(n.get(d)||0)+1),u<o&&(o=u),u>r&&(r=u),f<s&&(s=f),f>i&&(i=f)}return{cells:n,minX:o,maxX:r,minZ:s,maxZ:i}}function ei(t,e){let n=new Set,o=1/0,r=-1/0,s=1/0,i=-1/0,l=(u,f)=>{let d=u+","+f;n.add(d),u<o&&(o=u),u>r&&(r=u),f<s&&(s=f),f>i&&(i=f)};for(let u of t){let f=u.x1,d=u.z1,c=u.x2,a=u.z2,h=Math.floor(f/e),g=Math.floor(d/e),b=Math.floor(c/e),x=Math.floor(a/e),m=Math.abs(b-h),p=Math.abs(x-g),y=h<b?1:-1,w=g<x?1:-1,z=m-p,M=Math.max(m,p)*2+5,P=0;for(;P++<M&&(l(h,g),!(h===b&&g===x));){let E=2*z;E>-p&&(z-=p,h+=y),E<m&&(z+=m,g+=w)}}return{active:n,minX:o,maxX:r,minZ:s,maxZ:i}}function Wn(t,e=1){let n=new Set(t);for(let o=0;o<e;o++){let r=new Set(n);for(let i of n){let[l,u]=i.split(",").map(Number);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)f===0&&d===0||r.add(l+f+","+(u+d))}let s=new Set(r);for(let i of r){let[l,u]=i.split(",").map(Number),f=!0;for(let d=-1;d<=1;d++){for(let c=-1;c<=1;c++)if(!r.has(l+d+","+(u+c))){f=!1;break}if(!f)break}f||s.delete(i)}n.clear();for(let i of s)n.add(i)}return n}function nr(t){let e=[],n=new Set;for(let o of t){if(n.has(o))continue;let r=new Set,s=[o];for(n.add(o);s.length>0;){let i=s.shift();r.add(i);let[l,u]=i.split(",").map(Number);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++){if(f===0&&d===0)continue;let c=l+f+","+(u+d);t.has(c)&&!n.has(c)&&(n.add(c),s.push(c))}}r.size>=4&&e.push(r)}return e}function or(t,e){if(t.size<3)return[];let n=new Set,o=(g,b)=>t.has(g+","+b);for(let g of t){let[b,x]=g.split(",").map(Number);(!o(b+1,x)||!o(b-1,x)||!o(b,x+1)||!o(b,x-1))&&n.add(g)}if(n.size<3)return[];let r="",s=1/0,i=1/0;for(let g of n){let[b,x]=g.split(",").map(Number);(x<s||x===s&&b<i)&&(s=x,i=b,r=g)}if(!r)return[];let l=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]],u=[],[f,d]=r.split(",").map(Number),c=0,a=new Set,h=n.size*8;for(let g=0;g<h;g++){let x=f+","+d+"|"+c;if(a.has(x))break;a.add(x),u.push({x:(f+.5)*e,z:(d+.5)*e});let m=(c+3)%8,p=!1;for(let y=0;y<8;y++){let w=(m+y)%8,z=f+l[w][0],M=d+l[w][1];if(n.has(z+","+M)){c=(w+4)%8,f=z,d=M,p=!0;break}}if(!p||f+","+d===r&&u.length>2)break}return u}function Hn(t,e){if(t.length<=2)return[...t];let n=0,o=0,r=t[0],s=t[t.length-1];for(let i=1;i<t.length-1;i++){let l=Cn(t[i].x,t[i].z,r.x,r.z,s.x,s.z);l>n&&(n=l,o=i)}if(n>e){let i=Hn(t.slice(0,o+1),e),l=Hn(t.slice(o),e);return[...i.slice(0,-1),...l]}return[r,s]}var rr={cellSize:.1,densityThreshold:1,minComponentCells:20,simplifyEpsilon:.01,heightMin:.3,heightMax:2.8,closeIterations:5,sparseRadius:.3,sparseMinNeighbors:5,lineDensityMin:0,lineDensityMinLen:1,densityRatio:.12};function dn(t){let e=t.length;if(e<3)return{cx:0,cz:0,r:0,rmsResidual:0};let n=0,o=0,r=0,s=0,i=0,l=0,u=0,f=0,d=0;for(let m of t){let p=m.x,y=m.z;n+=p,o+=y,r+=p*p,s+=y*y,i+=p*y,l+=p*p*p,u+=y*y*y,f+=p*p*y,d+=p*y*y}let c=2*(e*(r+s)-n*n-o*o);if(Math.abs(c)<1e-10)return{cx:0,cz:0,r:0,rmsResidual:0};let a=(e*(l+d)-n*(r+s))/c,h=(e*(f+u)-o*(r+s))/c,g=Math.sqrt(Math.abs((r+s-2*a*n-2*h*o)/e+a*a+h*h)),b=0;for(let m of t){let y=Math.hypot(m.x-a,m.z-h)-g;b+=y*y}let x=Math.sqrt(b/e);return{cx:a,cz:h,r:g,rmsResidual:x}}function Ql(t){let e=t.length;if(e<4)return{eigenRatio:1,isLinear:!1,spread:0,mx:0,mz:0,v1x:1,v1z:0,v2x:0,v2z:1,s1:0,s2:0};let n=0,o=0;for(let w of t)n+=w.x,o+=w.z;n/=e,o/=e;let r=0,s=0,i=0;for(let w of t){let z=w.x-n,M=w.z-o;r+=z*z,s+=M*M,i+=z*M}r/=e,s/=e,i/=e;let l=r+s,u=Math.max(0,(r-s)*(r-s)+4*i*i),f=Math.sqrt(u),d=(l+f)/2,c=(l-f)/2,a=Math.sqrt(d),h=Math.sqrt(c),g=h,b=1,x=0,m=0,p=1;if(Math.abs(i)>1e-12||Math.abs(r-s)>1e-12){let w=i,z=d-r,M=Math.sqrt(w*w+z*z);M>1e-12&&(b=w/M,x=z/M);let P=i,E=c-r,S=Math.sqrt(P*P+E*E);S>1e-12&&(m=P/S,p=E/S)}let y=d>1e-10?c/d:0;return{eigenRatio:y,isLinear:y<.05,spread:g,mx:n,mz:o,v1x:b,v1z:x,v2x:m,v2z:p,s1:a,s2:h}}function ni(t,e,n){if(t.length<6)return{type:"straight",eigenRatio:.5,spread:0,cloudUsed:t.length,mx:0,mz:0,v1x:1,v1z:0,v2x:0,v2z:1,s1:0,s2:0};let{eigenRatio:o,isLinear:r,spread:s,mx:i,mz:l,v1x:u,v1z:f,v2x:d,v2z:c,s1:a,s2:h}=Ql(t),g=0;for(let w=1;w<t.length;w++){let z=t[w].x-t[w-1].x,M=t[w].z-t[w-1].z;g+=Math.sqrt(z*z+M*M)}let b=Jl(t),x=dn(b);if(x.r>.1&&x.r<Math.max(g*5,2)&&x.rmsResidual<.07)return{type:"curved",eigenRatio:o,spread:s,cloudUsed:t.length,mx:i,mz:l,v1x:u,v1z:f,v2x:d,v2z:c,s1:a,s2:h};let p=g>.01?s/g:1;return{type:r&&(s<.05||p<.1)?"straight":"curved",eigenRatio:o,spread:s,cloudUsed:t.length,mx:i,mz:l,v1x:u,v1z:f,v2x:d,v2z:c,s1:a,s2:h}}function Jl(t){if(t.length<4)return[...t];let e=[{...t[0]}];for(let n=1;n<t.length-1;n++)e.push({x:(t[n-1].x+t[n].x+t[n+1].x)/3,z:(t[n-1].z+t[n].z+t[n+1].z)/3});return e.push({...t[t.length-1]}),e}function tc(t,e,n=1.57){if(e<10)return[];let o=[];for(let b=0;b<e;b++){let x=(b+1)%e;o.push(Math.atan2(t[x].z-t[b].z,t[x].x-t[b].x))}let r=[o[0]];for(let b=1;b<e;b++){let x=o[b]-o[b-1];x>Math.PI?x-=2*Math.PI:x<-Math.PI&&(x+=2*Math.PI),r.push(r[b-1]+x)}let s=0;{let b=o[0]-o[e-1];b>Math.PI?b-=2*Math.PI:b<-Math.PI&&(b+=2*Math.PI),s=b}Math.abs(s)<.1;let i=[],l=5;for(let b=0;b<e;b++){let x=0;for(let m=-l;m<=l;m++)x+=r[(b+m+e)%e];i.push(x/(l*2+1))}let u=5,f=[];for(let b=0;b<e;b++){let x=i[(b+u)%e]-i[b];x>Math.PI?x-=2*Math.PI:x<-Math.PI&&(x+=2*Math.PI),f.push(x)}let d=10,c=.003,a=10,h=.05,g=[];for(let b=0;b<e;b++){let x=b,m=b,p=0,y=0,w=b,z=e+10;for(;z-- >0;){let P=f[w],E=Math.abs(P),S=P>0?1:P<0?-1:0;if(E<c){w=(w+1)%e;continue}if(y===0){y=S,p=E,m=w,w=(w+1)%e;continue}if(S!==y){let I=E,W=S,v=(w+1)%e,T=1;for(let R=0;R<a&&T<a*2;R++){let D=f[v],H=Math.abs(D);if(H<c){v=(v+1)%e;continue}(D>0?1:-1)===W?I+=H:(I-=H,I<0&&(W=-W,I=-I)),v=(v+1)%e,T++}if(W===y&&I>h){w=(w+1)%e;continue}break}if(p+=E,m=w,w=(w+1)%e,w===b)break}if((m>x?m-x+1:e-x+m+1)>=d&&p>=n){let P=x,E=(x+u)%e,S=(m-u+e)%e,I=m,W=t[P],v=t[E],T=t[S],R=t[I],D=Math.atan2(v.z-W.z,v.x-W.x),V=Math.atan2(R.z-T.z,R.x-T.x)-D;V>Math.PI?V-=2*Math.PI:V<-Math.PI&&(V+=2*Math.PI);let C=Math.abs(V);if(!g.some(A=>{function B(L,O,$){return L<=O?$>=L&&$<=O:$>=L||$<=O}let k=0,F=0;for(let L=x;F++,B(A.start,A.end,L)&&k++,L!==m;L=(L+1)%e);return F>0&&k/F>.7})){let A=g.findIndex(B=>{function k(O,$,Z){return O<=$?Z>=O&&Z<=$:Z>=O||Z<=$}let F=0,L=0;for(let O=B.start;L++,k(x,m,O)&&F++,O!==B.end;O=(O+1)%e);return L>0&&F/L>.7});A>=0?p>g[A].cumAngle&&(g[A]={start:x,end:m,cumAngle:p,actualAngle:C}):g.push({start:x,end:m,cumAngle:p,actualAngle:C})}}}return g}function ec(t,e){let s=new Array(e).fill(!1);for(let f=0;f<e;f++){let d=t[f],c=t[(f+15)%e],a=t[(f+30)%e],h=Math.atan2(c.z-d.z,c.x-d.x),g=Math.atan2(a.z-c.z,a.x-c.x),b=Math.abs(g-h);b>Math.PI&&(b=2*Math.PI-b),b>.07&&(s[(f+15)%e]=!0)}let i=new Set,l=[],u=-1;for(let f=0;f<e*2;f++){let d=f%e;if(s[d])u<0&&(u=d);else if(u>=0){let c=(d-1+e)%e,a=0;for(let h=u;a++,h!==c;h=(h+1)%e);if(a>=12){let h=`${u},${c}`;i.has(h)||(i.add(h),l.push({start:u,end:c}))}u=-1}}if(l.length>1){let f=l[0],d=l[l.length-1];d.end>e-3&&f.start<3&&(l[0]={start:d.start,end:f.end},l.pop())}return l}function nc(t,e){let n=[10,15,20,25,30,40],o=.15,r=.15,s=.5,i=3,l=6,u=new Array(e).fill(0);for(let c of n)if(!(c>=e))for(let a=0;a<e;a+=i){let h=a+c;if(h>=e)break;let g=[];for(let w=a;w<=h;w++)g.push(t[w]);if(g.length<c-1)continue;let{cx:b,cz:x,r:m,rmsResidual:p}=dn(g);if(m<.1||p>o||m<s)continue;let y=0;for(let w=1;w<g.length;w++){let z=g[w-1].x-b,M=g[w-1].z-x,P=g[w].x-b,E=g[w].z-x;y+=Math.abs(Math.atan2(z*E-M*P,z*P+M*E))}if(!(y<r))for(let w=a;w<=h;w++)u[w]++}let f=[],d=-1;for(let c=0;c<e*2;c++){let a=c%e;if(u[a]>=2)d<0&&(d=a);else if(d>=0){let h=(a-1+e)%e,g=0;for(let b=d;g++,b!==h;b=(b+1)%e);g>=l&&f.push({start:d,end:h}),d=-1}}if(f.length>1){let c=f[0],a=f[f.length-1];a.end>e-3&&c.start<3&&(f[0]={start:a.start,end:c.end},f.pop())}return f}function oc(t,e,n){function o(h,g){return h<=g?g-h+1:n-h+(g+1)}function r(h,g,b){return h<=g?b>=h&&b<=g:b>=h||b<=g}let s=o(t.start,t.end),i=o(e.start,e.end),l=s<=i?t.start:e.start,u=s<=i?t.end:e.end,f=s<=i?e.start:t.start,d=s<=i?e.end:t.end,c=0;for(let h=l;r(f,d,h)&&c++,h!==u;h=(h+1)%n);let a=s+i-c;return a>0?c/a:0}function rc(t){if(t.length<2)return[];let e=[],n=.15,o=1.22,r=1.92;for(let l=0;l<t.length;l++){let u=t[l];for(let f=l+1;f<t.length;f++){let d=t[f],c=u.bx-u.ax,a=u.bz-u.az,h=d.bx-d.ax,g=d.bz-d.az,b=Math.sqrt(c*c+a*a),x=Math.sqrt(h*h+g*g);if(b<.01||x<.01)continue;let m=Math.abs(Math.atan2(c*g-a*h,c*h+a*g));if(m<o||m>r)continue;let p=[{x:u.ax,z:u.az},{x:u.bx,z:u.bz}],y=[{x:d.ax,z:d.az},{x:d.bx,z:d.bz}];for(let w of p)for(let z of y){let M=w.x-z.x,P=w.z-z.z;Math.sqrt(M*M+P*P)<n&&e.push({x:(w.x+z.x)/2,z:(w.z+z.z)/2})}}}if(e.length<2)return e;let s=[],i=new Array(e.length).fill(!1);for(let l=0;l<e.length;l++){if(i[l])continue;let u=e[l].x,f=e[l].z,d=1;i[l]=!0;for(let c=l+1;c<e.length;c++){if(i[c])continue;let a=e[c].x-u/d,h=e[c].z-f/d;Math.sqrt(a*a+h*h)<.3&&(u+=e[c].x,f+=e[c].z,d++,i[c]=!0)}s.push({x:u/d,z:f/d})}return s}function oi(t,e){if(t.length<6)return[];let n={minCurveAngle:.05,minCurvePoints:5,smoothWindow:3,...e},o=t.length,r=[];for(let T=0;T<o;T++){let R=t[(T-1+o)%o],D=t[T],H=t[(T+1)%o],V=D.x-R.x,C=D.z-R.z,_=H.x-D.x,A=H.z-D.z,B=Math.sqrt(V*V+C*C),k=Math.sqrt(_*_+A*A);if(B<.001||k<.001){r.push(0);continue}r.push(Math.atan2((V*A-C*_)/(B*k),(V*_+C*A)/(B*k)))}let s=[],i=n.smoothWindow;for(let T=0;T<o;T++){let R=0;for(let D=-i;D<=i;D++)R+=r[(T+D+o)%o];s.push(R/(i*2+1))}let l=.008,u=[],f=-1,d=0,c=new Set;for(let T=0;T<o*2;T++){let R=T%o,D=s[R],H=D>=0?1:-1;if(Math.abs(D)>l&&(d===0||d===H))f<0&&(f=R,d=H);else if(f>=0){let V=(R-1+o)%o,C=0,_=0;for(let A=f;C+=Math.abs(s[A]),_++,A!==V;A=(A+1)%o);if(_>=n.minCurvePoints&&C>n.minCurveAngle){let A=`${f},${V}`;c.has(A)||(c.add(A),u.push({start:f,end:V,sign:d}))}f=-1,d=0}}if(u.length>1){let T=u[0],R=u[u.length-1];T.sign===R.sign&&R.end>o-3&&T.start<3&&(u[0]={start:R.start,end:T.end,sign:T.sign},u.pop())}{let T=s.filter(V=>Math.abs(V)>.001).map(V=>Math.abs(V)),R=T.length>0?Math.max(...T):0,D=T.length>0?T.reduce((V,C)=>V+C,0)/T.length:0,H=u.reduce((V,C)=>{let _=0;for(let A=C.start;_++,A!==C.end;A=(A+1)%o);return V+_},0)}let a=ec(t,o),h=nc(t,o),g=[...u,...a.map(T=>({start:T.start,end:T.end,sign:1})),...h.map(T=>({start:T.start,end:T.end,sign:1}))],b=u.length,m=g.map((T,R)=>{let D=[];for(let Z=T.start;D.push({...t[Z]}),Z!==T.end;Z=(Z+1)%o);let H=0;for(let Z=1;Z<D.length;Z++)s[(T.start+Z-1)%o]*s[(T.start+Z)%o]<-1e-8&&H++;let{cx:V,cz:C,r:_,rmsResidual:A}=dn(D),B=0,k=0;for(let Z=1;Z<D.length;Z++){let Q=D[Z-1].x-V,j=D[Z-1].z-C,X=D[Z].x-V,U=D[Z].z-C,lt=Math.atan2(Q*U-j*X,Q*X+j*U);B+=Math.abs(lt),k+=lt}let F=Re(D),L=H===0?.12:.08;if(_>.1&&A>L||_>.1&&_>Math.max(F*15,8)||Math.abs(k)<.05)return null;let O=R<b?"turning":"sliding",$=O!=="turning"?Math.abs(k)>.35?"C_curve":"S_curve":H>0?"S_curve":"C_curve";return{seg:{points:D,type:$,radius:_,centerX:V,centerZ:C,arcAngle:B,arcLength:F},start:T.start,end:T.end,source:O}}).filter(T=>T!==null),p=new Set;function y(T,R){return T<=R?R-T+1:o-T+(R+1)}function w(T,R,D,H){for(let V=T;;V=(V+1)%o){let C;if(D<=H?C=V>=D&&V<=H:C=V>=D||V<=H,!C)return!1;if(V===R)break}return!0}for(let T=0;T<m.length;T++)if(!p.has(T))for(let R=T+1;R<m.length;R++){if(p.has(R))continue;if(oc({start:m[T].start,end:m[T].end},{start:m[R].start,end:m[R].end},o)>.6){let V=(m[T].seg.arcAngle>=m[R].seg.arcAngle?T:R)===T?R:T;if(m[T].seg.arcAngle>=m[R].seg.arcAngle)p.add(R);else{p.add(T);break}}else{let H=y(m[T].start,m[T].end),V=y(m[R].start,m[R].end),C=H<=V?T:R,_=H<=V?R:T;w(m[C].start,m[C].end,m[_].start,m[_].end)&&y(m[C].start,m[C].end)/y(m[_].start,m[_].end)<.7&&p.add(C)}}let z=m.filter((T,R)=>!p.has(R)),M=10,P=10,E=30,S=15,I=[],W=0;if(z.length>0){for(let D of z)D.start=(D.start-S+o)%o,D.end=(D.end+S)%o;let T=[...z].sort((D,H)=>D.start-H.start),R=T[0];for(let D=1;D<T.length;D++){let H=T[D],V=H.start-R.end;V<0&&(R.end>o*.5&&H.start<o*.5?V=H.start+o-R.end:V=0);let C=V===0,_=V<=E&&C;if(!_&&V<=E){let A=Math.sqrt((R.seg.centerX-H.seg.centerX)**2+(R.seg.centerZ-H.seg.centerZ)**2),B=Math.max(R.seg.radius,H.seg.radius),k=Math.min(R.seg.radius,H.seg.radius),F=k>0?B/k:99;_=A<P&&F<M}if(_){let A=Math.min(R.start,H.start),B=Math.max(R.end,H.end),k=[];for(let Z=A;k.push({...t[Z]}),Z!==B;Z=(Z+1)%o);let{cx:F,cz:L,r:O}=dn(k),$=0;for(let Z=1;Z<k.length;Z++){let Q=k[Z-1].x-F,j=k[Z-1].z-L,X=k[Z].x-F,U=k[Z].z-L;$+=Math.abs(Math.atan2(Q*U-j*X,Q*X+j*U))}R={seg:{points:k,type:"C_curve",radius:O,centerX:F,centerZ:L,arcAngle:$,arcLength:Re(k)},start:R.start,end:H.end,source:R.source},W++}else I.push(R),R=H}I.push(R)}{if(I.length>1){let R=I.map((D,H)=>{if(H===0)return 0;let V=D.start-I[H-1].end;return V<0&&(V=D.start+o-I[H-1].end),V})}let T=[];for(let R=0;R<I.length;R++){if(T.length===0){T.push(I[R]);continue}let D=T[T.length-1],H=I[R].start-D.end;if(H<0&&(H=I[R].start+o-D.end),H<=30){let V=[...D.seg.points];for(let k=(D.end+1)%o;V.push({...t[k]}),k!==I[R].end;k=(k+1)%o);let{cx:C,cz:_,r:A}=dn(V),B=0;for(let k=1;k<V.length;k++){let F=V[k-1].x-C,L=V[k-1].z-_,O=V[k].x-C,$=V[k].z-_;B+=Math.abs(Math.atan2(F*$-L*O,F*O+L*$))}T[T.length-1]={seg:{points:V,type:"C_curve",radius:A,centerX:C,centerZ:_,arcAngle:B,arcLength:Re(V)},start:D.start,end:I[R].end,source:D.source}}else T.push(I[R])}I=T}return I.map((T,R)=>{let D=T.seg;return D.candidateId=R,D})}function sc(t){let e=t.length;if(e<6)return null;let n=tc(t,e,.35);if(n.length===0)return null;let o=n.filter(a=>a.actualAngle!=null&&a.actualAngle>.17);if(o.length===0)return null;o.sort((a,h)=>{let g=a.end>=a.start?a.end-a.start+1:e-a.start+a.end+1;return(h.end>=h.start?h.end-h.start+1:e-h.start+h.end+1)-g});let r=o[0],s=[];for(let a=r.start;s.push({...t[a]}),a!==r.end;a=(a+1)%e);if(s.length<10)return null;let{cx:i,cz:l,r:u,rmsResidual:f}=dn(s);if(u>.1&&f>.1)return null;let d=r.actualAngle,c=s.reduce((a,h,g)=>g===0?0:a+Math.hypot(h.x-s[g-1].x,h.z-s[g-1].z),0);return u>.3&&d>.17?{points:s,type:"C_curve",radius:u,centerX:i,centerZ:l,arcAngle:d,arcLength:c}:null}function po(t,e,n){let o={...rr,...n},r=Date.now(),s=t,i=Array.isArray(e)?e:[],l=[];if(i.length>10)try{for(let T of i){let R=T.x1,D=T.z1,H=T.x2,V=T.z2;if(R==null||D==null||H==null||V==null){let C=T.start?.x,_=T.start?.y,A=T.end?.x,B=T.end?.y;if(C==null||_==null||A==null||B==null)continue;l.push({ax:C,az:_,bx:A,bz:B})}else l.push({ax:R,az:D,bx:H,bz:V})}let v=.1*.1;if(l.length>5){let T=[],R=[],D=new Array(l.length).fill(0);for(let V of t){let C=1/0,_=-1;for(let A=0;A<l.length;A++){let B=l[A],k=B.bx-B.ax,F=B.bz-B.az,L=k*k+F*F,O;if(L<1e-8)O=(V.x-B.ax)**2+(V.y-B.az)**2;else{let $=((V.x-B.ax)*k+(V.y-B.az)*F)/L;$=Math.max(0,Math.min(1,$));let Z=B.ax+$*k,Q=B.az+$*F;O=(V.x-Z)**2+(V.y-Q)**2}if(O<C&&(C=O,_=A),C<=v)break}C<=v&&(R.push(V),T.push(_),D[_]++)}let H=R;if(o.lineDensityMin>0&&o.lineDensityMinLen>0){let V=new Set;for(let C=0;C<l.length;C++){let _=l[C],A=Math.hypot(_.bx-_.ax,_.bz-_.az);if(A>=o.lineDensityMinLen)continue;(A>.01?D[C]/A:0)<o.lineDensityMin&&V.add(C)}if(V.size>0){let C=[];for(let _=0;_<R.length;_++)V.has(T[_])||C.push(R[_]);H=C}}s=H}}catch(v){console.warn("[\u70B9\u4E91\u8F6E\u5ED3] \u7EBF\u6BB5\u8FC7\u6EE4\u5931\u8D25:",v)}let u=rc(l),f=[];for(let v of s){let T=v.z;T<o.heightMin||T>o.heightMax||f.push({x:v.x,z:v.y})}if(f.length<50)return Ke(e,r);if(o.sparseRadius>0){let v=new Map,T=o.cellSize;for(let V of f){let C=`${Math.round(V.x/T)},${Math.round(V.z/T)}`;v.has(C)||v.set(C,[]),v.get(C).push(V)}let R=[],D=Math.ceil(o.sparseRadius/T);for(let V=-D;V<=D;V++)for(let C=-D;C<=D;C++)R.push(`${V},${C}`);let H=[];for(let V of f){let C=Math.round(V.x/T),_=Math.round(V.z/T),A=0;for(let B of R){let[k,F]=B.split(",").map(Number),L=v.get(`${C+k},${_+F}`);if(L&&(A+=L.length),A>=o.sparseMinNeighbors)break}A>=o.sparseMinNeighbors&&H.push(V)}f.length=0;for(let V=0;V<H.length;V++)f.push(H[V])}if(f.length<50)return Ke(e,r);let d=Date.now(),{cells:c}=mo(f,o.cellSize),a=new Set;if(o.densityRatio>0&&c.size>10){let v=Array.from(c.values()).sort((D,H)=>D-H),T=v[Math.floor(v.length/2)],R=Math.max(o.densityThreshold,Math.ceil(T*o.densityRatio));for(let[D,H]of c)H>=R&&a.add(D);if(a.size<o.minComponentCells){a.clear();for(let[D,H]of c)H>=o.densityThreshold&&a.add(D)}}else for(let[v,T]of c)T>=o.densityThreshold&&a.add(v);if(a.size<o.minComponentCells)return Ke(e,r);let h=a;o.closeIterations>0&&(h=Wn(a,o.closeIterations));let g=Date.now(),b=nr(h).filter(v=>v.size>=o.minComponentCells);b.sort((v,T)=>T.size-v.size);let x=20;b.length>x&&(b=b.slice(0,x));let m=Date.now(),p=[];for(let v of b){let T=or(v,o.cellSize);T.length>=4&&p.push(T)}let y=Date.now(),w=p.map(v=>{let T=Hn(v,o.simplifyEpsilon);if(T.length>=7)for(let R=0;R<2;R++){let D=T.length,H=T.map(V=>({x:V.x,z:V.z}));for(let V=0;V<D;V++){let C=T[(V-1+D)%D],_=T[V],A=T[(V+1)%D],B=_.x-C.x,k=_.z-C.z,F=A.x-_.x,L=A.z-_.z,O=Math.sqrt(B*B+k*k),$=Math.sqrt(F*F+L*L);if(O<.001||$<.001)continue;if(Math.abs(Math.atan2(B*L-k*F,B*F+k*L))>1.8){let Q=[-2,-1,0,1,2].map(U=>T[(V+U+D)%D]),j=Q.map(U=>U.x).sort((U,lt)=>U-lt),X=Q.map(U=>U.z).sort((U,lt)=>U-lt);H[V]={x:j[2],z:X[2]}}}T=H}if(T=er(T),u.length>0&&T.length>=5)for(let R of u){let D=1/0,H=-1;for(let V=0;V<T.length;V++){let C=T[V].x-R.x,_=T[V].z-R.z,A=C*C+_*_;A<D&&(D=A,H=V)}H>=0&&D<.3*.3&&(T[H]={x:R.x,z:R.z})}if(T.length>2){let R=T[0],D=T[T.length-1];(Math.abs(R.x-D.x)>.001||Math.abs(R.z-D.z)>.001)&&T.push({...R})}return T}),z=o.cellSize/2;function M(v){let T=0;for(let R=0;R<v.length;R++){let D=(R+1)%v.length;T+=v[R].x*v[D].z-v[D].x*v[R].z}return T/2}let P=w.map(v=>{if(v.length<3)return v;let T=M(v)>=0;return v.map((R,D)=>{let H=v[(D-1+v.length)%v.length],V=v[(D+1)%v.length],C=V.x-H.x,_=V.z-H.z;if(Math.sqrt(C*C+_*_)<.001)return{...R};let B=T?_:-_,k=T?-C:C,F=Math.sqrt(B*B+k*k);return F<.001?{...R}:{x:R.x+B/F*z,z:R.z+k/F*z}})}),E=Date.now(),S=[];for(let v=0;v<P.length;v++){let T=P[v];T.length<3||S.push({id:-v-1,points:T,length:Re(T),pointCount:T.length,type:"straight",isMain:!1})}let I=Date.now()-r,W=[];for(let v of w){let T=oi(v);for(let D of T)W.push(D);let R=sc(v);R&&W.push(R)}return{mainWalls:[],noiseWalls:[],contours:S,curvedSegments:W,filteredPoints:s,stats:{totalRawLines:e?.length??t.length,totalWalls:0,mainCount:0,noiseCount:S.length,elapsedMs:I}}}function ri(t,e){let n=e?.cellSize??.05,o=e?.closeIterations??2,r=e?.minComponentCells??10,s=e?.simplifyEpsilon??.02,i=Date.now();if(t.length<3)return Ke(t,i);let l=t.map(S=>({x1:S.x1,z1:S.z1,x2:S.x2,z2:S.z2})),{active:u}=ei(l,n);if(u.size<r)return Ke(t,i);let f=Date.now(),d=Wn(u,o),c=Date.now(),a=nr(d).filter(S=>S.size>=r);if(a.length===0)return Ke(t,i);let h=a.reduce((S,I)=>S.size>=I.size?S:I),g=Date.now(),b=or(h,n);if(b.length<4)return Ke(t,i);let x=Date.now(),m=Hn(b,s);if(m=er(m),m.length>2){let S=m[0],I=m[m.length-1];(Math.abs(S.x-I.x)>.001||Math.abs(S.z-I.z)>.001)&&m.push({...S})}let p=n/2;function y(S){let I=0;for(let W=0;W<S.length;W++){let v=(W+1)%S.length;I+=S[W].x*S[v].z-S[v].x*S[W].z}return I/2}let w=y(m)>=0,z=m.map((S,I)=>{let W=m[(I-1+m.length)%m.length],v=m[(I+1)%m.length],T=v.x-W.x,R=v.z-W.z;if(Math.sqrt(T*T+R*R)<.001)return{...S};let H=w?R:-R,V=w?-T:T,C=Math.sqrt(H*H+V*V);return C<.001?{...S}:{x:S.x+H/C*p,z:S.z+V/C*p}}),M=Date.now(),P=[];z.length>=3&&P.push({id:-1,points:z,length:Re(z),pointCount:z.length,type:"straight",isMain:!0});let E=Date.now()-i;return{mainWalls:[],noiseWalls:[],contours:P,stats:{totalRawLines:t.length,totalWalls:0,mainCount:0,noiseCount:P.length,elapsedMs:E}}}function Ke(t,e){return{mainWalls:[],noiseWalls:[],stats:{totalRawLines:t?.length??0,totalWalls:0,mainCount:0,noiseCount:0,elapsedMs:Date.now()-e}}}function go(t,e,n){if(!t.length||n<=1)return t;let o=new Map;for(let l of t){let u=Math.floor(l.x/e),f=Math.floor(l.y/e),d=`${u},${f}`;o.has(d)||o.set(d,[]),o.get(d).push(l)}let r=new Map;for(let[l,u]of o){let[f,d]=l.split(","),c=parseInt(f),a=parseInt(d),h=0;for(let g=-2;g<=2;g++)for(let b=-2;b<=2;b++){let x=`${c+g},${a+b}`;h+=o.get(x)?.length??0}r.set(l,h)}let s=[],i=0;for(let l of t){let u=Math.floor(l.x/e),f=Math.floor(l.y/e),d=`${u},${f}`;(r.get(d)??0)>=n?s.push(l):i++}return s}function xo(t,e,n){if(!t.length||n<=1||e<=0)return t;let o=new Map;for(let s of t){let i=Math.floor(s.x/e),l=Math.floor(s.y/e),u=Math.floor(s.z/e),f=`${i},${l},${u}`;o.has(f)||o.set(f,[]),o.get(f).push(s)}let r=[];for(let s of o.values())if(s.length>=n){let i=s.reduce((f,d)=>f+d.x,0)/s.length,l=s.reduce((f,d)=>f+d.y,0)/s.length,u=s.reduce((f,d)=>f+d.z,0)/s.length;r.push({x:i,y:l,z:u})}return r}function si(t,e,n){let o=xo(t,e,n),r=t.length-o.length;return o}function ii(t){let e=[];for(let f of t){let d=f.originalPoints??f.points??[];if(!Array.isArray(d)||d.length<2)continue;let c=Math.min(d.length,200);for(let a=1;a<c;a++){let h=Math.hypot(d[a].x-d[a-1].x,d[a].y-d[a-1].y,d[a].z-d[a-1].z);h>.001&&e.push(h)}}let n={voxelSize:.08,minPoints:3,minCentroids:3};if(e.length<10)return n;e.sort((f,d)=>f-d);let o=e[Math.floor(e.length/2)],r=Math.max(.03,Math.min(.25,o*3.5));r=Math.round(r*100)/100;let s=Math.pow(r/o,2),i=Math.max(2,Math.min(5,Math.round(s/4))),l=e.length/Math.max(1,t.length),u=Math.max(2,Math.min(4,Math.round(l/50)));return{voxelSize:r,minPoints:i,minCentroids:u}}function ai(t,e,n,o,r=3){if(!t.length||n<=0||o<=1)return{data:t,lines:e,removedCount:0};let s=[],i=[],l=0;for(let u=0;u<t.length;u++){let f=t[u],d=f.originalPoints??f.points??[];if(!Array.isArray(d)||d.length===0){s.push(f),i.push(e[u]);continue}let c=xo(d,n,o);c.length>=r?(f.originalPoints&&(f.originalPoints=c),f.points&&(f.points=c),s.push(f),i.push(e[u])):l++}return{data:s,lines:i,removedCount:l}}function li(t,e,n,o){let r=[],s=[],i=0;for(let l=0;l<t.length;l++){let u=t[l],f=u.originalPoints??u.points??[],c=(Array.isArray(f)?f.filter(x=>x&&x.x!==void 0&&x.y!==void 0):[]).length;if(c===0){r.push(u),s.push({...e[l],id:r.length-1});continue}let a=u.start??u,h=u.end??u,g=Math.hypot(h.x??0-a.x??0,h.y??0-a.y??0);if(g>=o||g<=.01){r.push(u),s.push({...e[l],id:r.length-1});continue}if(c/g<n){i++;continue}r.push(u),s.push({...e[l],id:r.length-1})}return{data:r,lines:s}}function Qe(t,e,n,o,r,s){let i=r-n,l=s-o,u=i*i+l*l;if(u===0)return Math.hypot(t-n,e-o);let f=((t-n)*i+(e-o)*l)/u;return f=Math.max(0,Math.min(1,f)),Math.hypot(t-(n+f*i),e-(o+f*l))}function sr(t,e,n=.2){for(let o of e)if(Qe(o.x,o.z,t.x1,t.z1,t.x2,t.z2)<=n)return!0;return!1}function ci(t,e,n=.2){let o=1/0,r={x:0,z:0};for(let i of e){let l=Qe(i.x,i.z,t.x1,t.z1,t.x2,t.z2);l<o&&(o=l,r=i)}return o<=n}function ui(t,e,n,o=!0){function g(y,w,z,M){let P=z.points[0],E=z.points[z.points.length-1];return Math.hypot(y-P.x,w-P.z)<=M||Math.hypot(y-E.x,w-E.z)<=M}function b(y,w,z,M){for(let P=0;P<z.points.length-1;P++)if(Qe(y,w,z.points[P].x,z.points[P].z,z.points[P+1].x,z.points[P+1].z)<=M)return!0;return!1}function x(y,w,z){let M=0,P=y[0],E=y[y.length-1];for(let S of w)if(g(P.x,P.z,S,z)||b(P.x,P.z,S,z)){M++;break}for(let S of w)if(g(E.x,E.z,S,z)||b(E.x,E.z,S,z)){M++;break}return M}function m(y){if(y.length<2)return 0;if(y.length<=30){let P=0;for(let E=0;E<y.length;E++)for(let S=E+1;S<y.length;S++){let I=Math.hypot(y[E].x-y[S].x,y[E].z-y[S].z);I>P&&(P=I)}return P}let w=Math.max(1,Math.floor(y.length/15)),z=[];for(let P=0;P<y.length;P+=w)z.push(y[P]);z[z.length-1]!==y[y.length-1]&&z.push(y[y.length-1]);let M=0;for(let P=0;P<z.length;P++)for(let E=P+1;E<z.length;E++){let S=Math.hypot(z[P].x-z[E].x,z[P].z-z[E].z);S>M&&(M=S)}return M}let p=[];for(let y of t){let w=y.points,z=w.length>=2?m(w):0,M=y.candidateId!==void 0?`#${y.candidateId}`:"#?";if(o&&console.log(`[\u5F27\u6BB5\u5206\u6790] ${M} r=${y.radius.toFixed(3)}m \u5F27\u89D2=${(y.arcAngle*180/Math.PI).toFixed(1)}\xB0 \u5F26\u957F=${z.toFixed(3)}m pts=${w.length}`),y.radius<.2){o&&console.log(` \u2192 \u534A\u5F84<${.2}m \u8FC7\u6EE4`);continue}if(w.length<3){o&&console.log(" \u2192 \u70B9\u6570<3 \u8FC7\u6EE4");continue}let P=z/y.radius,E=z/2,S=0;E<=y.radius?S=y.radius-Math.sqrt(y.radius*y.radius-E*E):S=z;let I=z>.01?S/z:0,W=x(w,e,.8),v=y.arcAngle>1.745&&y.radius<5,T=y.radius>15&&P>.15&&w.length>=10,R=P>.12&&y.radius>1&&y.radius<4&&y.arcAngle>=.35&&w.length>=3;if(o&&console.log(` \u7279\u5F81: \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} \u5F13\u9AD8/\u5F26\u957F=${I.toFixed(4)} \u8FDE\u63A5=${W}/2${v?" \u5927\u5F27\u89D2\u8C41\u514D":""}${T?" \u5927\u534A\u5F84\u7ED3\u6784\u5F27":""}${R?" \u5408\u7406\u77ED\u5F27\u8C41\u514D":""}`),w.length>20&&y.arcAngle>5.2&&y.radius>.2){o&&console.log(` \u2192 \u8FD1\u95ED\u5408\u5706\u8C41\u514D(\u5F27\u89D2=${(y.arcAngle*180/Math.PI).toFixed(1)}\xB0, ${w.length}pts)`),p.push(y);continue}if(P<.15)if(W>=2&&y.arcAngle>=.35)o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} < ${.15}\uFF0C\u4F46\u4E24\u7AEF\u8FDE\u63A5+\u5F27\u89D2>20\xB0\uFF0C\u8C41\u514D`);else{o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} < ${.15}\uFF0C\u8F6E\u5ED3\u6296\u52A8\u5047\u5F27 \u8FC7\u6EE4`);continue}let D=W>=2?.025:.035;if(I<D&&!v&&!R&&!T){o&&console.log(` \u2192 \u5F13\u9AD8/\u5F26\u957F=${I.toFixed(4)} < ${D}(${W>=2?"\u5BBD\u677E":"\u6807\u51C6"})\uFF0C\u6781\u6241\u5F27(\u76F4\u7EBF\u6BB5\u566A\u58F0) \u8FC7\u6EE4`);continue}if(!v&&!R&&!T){if(y.arcAngle<.17){o&&console.log(` \u2192 \u5F27\u89D2<${(.17*180/Math.PI).toFixed(0)}\xB0 \u8FC7\u6EE4`);continue}if(y.arcAngle<.35&&W<2){o&&console.log(` \u2192 \u5F27\u89D2<${(.35*180/Math.PI).toFixed(0)}\xB0 \u4E14\u672A\u4E24\u7AEF\u8FDE\u63A5 \u8FC7\u6EE4`);continue}}if(P>2.01){o&&console.log(` \u2192 \u5F26\u957F/\u534A\u5F84=${P.toFixed(3)} > 2.01\uFF0C\u5F26\u957F\u8D85\u8FC7\u76F4\u5F84\uFF0C\u5F02\u5E38 \u8FC7\u6EE4`);continue}if(!v&&!T){let H=W>=2?2.5:1.5,V=Math.floor(w.length/2),C=w[V].x-w[0].x,_=w[V].z-w[0].z,A=w[w.length-1].x-w[V].x,B=w[w.length-1].z-w[V].z,k=Math.atan2(_,C),F=Math.atan2(B,A),L=Math.abs(F-k);if(L>Math.PI&&(L=2*Math.PI-L),L>60*Math.PI/180&&L>y.arcAngle*H){o&&console.log(` \u2192 V\u5F62\u62D0\u89D2\u8FC7\u6EE4 \u8F6C\u89D2=${(L*180/Math.PI).toFixed(1)}\xB0 > \u5F27\u89D2\xD7${H.toFixed(1)}=${(y.arcAngle*180/Math.PI*H).toFixed(1)}\xB0`);continue}}if(n&&n.length>5&&!(y.radius>15&&y.arcAngle>.26)){let H=w[0],V=w[w.length-1],C=.3,_=null,A=1/0,B=null,k=1/0;for(let F of n){let L=Qe(H.x,H.z,F.x1,F.z1,F.x2,F.z2),O=Qe(V.x,V.z,F.x1,F.z1,F.x2,F.z2);L<C&&L<A&&(_=F,A=L),O<C&&O<k&&(B=F,k=O)}if(!_||!B)console.log(` [\u7EBF\u6BB5\u8F6C\u89D2\u8C03\u8BD5 #${M}] \u672A\u627E\u5230\u5B8C\u6574\u7EBF\u6BB5: \u8D77\u7AEF=${!!_}(d=${A.toFixed(3)}) \u672B\u7AEF=${!!B}(d=${k.toFixed(3)})`);else if(_===B){console.log(" \u2192 \u7EBF\u6BB5\u8F6C\u89D2\u9A8C\u8BC1: \u5F27\u4E24\u7AEF\u5728\u540C\u4E00\u6761\u7EBF\u6BB5\u4E0A, \u76F4\u7EBF\u566A\u58F0\u5047\u5F27 \u8FC7\u6EE4");continue}else{let F=_.x2-_.x1,L=_.z2-_.z1,O=B.x2-B.x1,$=B.z2-B.z1,Z=Math.sqrt(F*F+L*L),Q=Math.sqrt(O*O+$*$);if(Z>.01&&Q>.01){let j=Math.abs(Math.atan2(F*$-L*O,F*O+L*$)),X=j*180/Math.PI;if(console.log(` [\u7EBF\u6BB5\u8F6C\u89D2\u8C03\u8BD5 #${M}] \u5F27\u4E24\u7AEF\u6BB5\u5939\u89D2=${X.toFixed(1)}\xB0 \u5F27\u89D2=${(y.arcAngle*180/Math.PI).toFixed(1)}\xB0`),j>.35&&j<3.05){let U=j>2.09;if(!U||y.arcAngle<.44){console.log(` \u2192 \u7EBF\u6BB5\u8F6C\u89D2\u9A8C\u8BC1: \u5F27\u4E24\u7AEF\u6BB5\u5939\u89D2=${X.toFixed(1)}\xB0\uFF0C${U?"\u659C\u5899":"\u6298\u5899"}\u78E8\u5706\u5047\u5F27 \u8FC7\u6EE4`);continue}}}}}o&&console.log(" \u2192 \u2713 \u4FDD\u7559"),p.push(y)}return o&&console.log(`[\u56DE\u52A0\u5224\u65AD] ${t.length} \u2192 ${p.length} \u4E2A\u5F27\u6BB5`),p}function fi(t,e){for(let n=0;n<t.length;n++){let o=t[n],r=[];for(let i of e)sr(i,o.points)&&r.push({id:i.id,len:Math.hypot(i.x2-i.x1,i.z2-i.z1)});r.sort((i,l)=>l.len-i.len);let s=r.map(i=>`#${i.id}(${i.len.toFixed(2)}m)`).join(", ");console.log(`[\u5F27\u6BB5\u539F\u59CB\u7EBF\u6BB5] #${n} r=${o.radius.toFixed(3)}m \u2192 ${r.length} \u6761: ${s}`)}}var ar={gridSize:2,connectDist:.8,angleTol:25,minLength:.8,minPointCount:3,hardCornerThreshold:30,minArea:5,minCurvePoints:6,curveStraightDist:.25,longWallMinLength:5};function di(t){if(!t.length)return{rotated:[],mainAngle:0};let e=180,n=new Array(e).fill(0),o=Math.PI/e;for(let d of t){let c=d.x2-d.x1,a=d.z2-d.z1,h=Math.sqrt(c*c+a*a);if(h<.01)continue;let g=Se(c,a),b=Math.floor(g/o);b>=e&&(b=e-1),n[b]+=h}let r=new Array(e).fill(0),s=5;for(let d=0;d<e;d++){let c=0;for(let a=-s;a<=s;a++){let h=d+a;h<0&&(h+=e),h>=e&&(h-=e),c+=n[h]}r[d]=c}let i=0,l=0;for(let d=0;d<e;d++)r[d]>i&&(i=r[d],l=d);let u=(l+.5)*o;return{rotated:t.map(d=>{let c=In(d.x1,d.z1,-u),a=In(d.x2,d.z2,-u);return{...d,x1:c.x,z1:c.z,x2:a.x,z2:a.z}}),mainAngle:u}}function hi(t,e){let n=new Map;for(let o of t){let r=(o.x1+o.x2)/2,s=(o.z1+o.z2)/2,i=Math.floor(r/e),l=Math.floor(s/e),u=`${i},${l}`;n.has(u)||n.set(u,[]),n.get(u).push(o)}return n}function mi(t,e,n){if(t.length===0)return[];let o=new Set,r=[];for(let s of t){if(o.has(s.id))continue;let i=[s],l=[],u=new Set([s.id]);o.add(s.id);let f=!0;for(;f;){f=!1;let a=i[i.length-1],h=a.x2,g=a.z2,b=Se(a.x2-a.x1,a.z2-a.z1),x=null,m=e;for(let p of t){if(o.has(p.id))continue;let y=Me(h,g,p.x1,p.z1),w=Me(h,g,p.x2,p.z2),z=w<y,M=Math.min(y,w);if(M>m)continue;let P=z?Se(p.x1-p.x2,p.z1-p.z2):Se(p.x2-p.x1,p.z2-p.z1);Math.abs(Vn(P-b))>n||(x=p,m=M)}if(x){o.add(x.id),u.add(x.id);let p=i[i.length-1],y=Me(p.x2,p.z2,x.x1,x.z1),w=Me(p.x2,p.z2,x.x2,x.z2);y<=w?i.push(x):i.push({id:x.id,x1:x.x2,z1:x.z2,x2:x.x1,z2:x.z1}),f=!0}}for(f=!0;f;){f=!1;let a=l.length>0?l[l.length-1]:i[0],h=l.length>0?a.x2:a.x1,g=l.length>0?a.z2:a.z1,b=l.length>0?Se(a.x2-a.x1,a.z2-a.z1):Se(a.x2-a.x1,a.z2-a.z1),x=null,m=e;for(let p of t){if(o.has(p.id))continue;let y=Me(h,g,p.x1,p.z1),w=Me(h,g,p.x2,p.z2),z=w<y,M=Math.min(y,w);if(M>m)continue;let P=z?Se(p.x1-p.x2,p.z1-p.z2):Se(p.x2-p.x1,p.z2-p.z1);Math.abs(Vn(P-b))>n||(x=p,m=M)}if(x){o.add(x.id),u.add(x.id);let p=Me(h,g,x.x1,x.z1),y=Me(h,g,x.x2,x.z2);p<=y?l.push({id:x.id,x1:x.x2,z1:x.z2,x2:x.x1,z2:x.z1}):l.push({...x}),f=!0}}let d=[];for(let a=l.length-1;a>=0;a--){let h=l[a];a===l.length-1&&d.push({x:h.x1,z:h.z1}),d.push({x:h.x2,z:h.z2})}for(let a=0;a<i.length;a++){let h=i[a];a===0&&d.length===0&&d.push({x:h.x1,z:h.z1}),d.push({x:h.x2,z:h.z2})}let c=[];for(let a of d){if(c.length>0){let h=c[c.length-1];if(Math.abs(a.x-h.x)<.001&&Math.abs(a.z-h.z)<.001)continue}c.push(a)}if(c.length>=2){let a=Re(c);r.push({points:c,length:a,pointCount:i.length+l.length,lineIds:[...u]})}}return r}function pi(t){if(t.length<3)return[];let e=[];for(let n=1;n<t.length-1;n++){let o=t[n].x-t[n-1].x,r=t[n].z-t[n-1].z,s=t[n+1].x-t[n].x,i=t[n+1].z-t[n].z,l=Math.atan2(r,o),u=Math.atan2(i,s),f=Vn(u-l);e.push(f)}return e}function gi(t,e=6){if(t.length<3)return"straight";let n=t[0],o=t[t.length-1],r=o.x-n.x,s=o.z-n.z;if(Math.sqrt(r*r+s*s)>.1){let d=0;for(let c of t){let a=Cn(c.x,c.z,n.x,n.z,o.x,o.z);a>d&&(d=a)}if(d<.05)return"straight"}let l=pi(t);if(l.reduce((d,c)=>d+Math.abs(c),0)<.1||t.length<e)return"straight";let f=0;for(let d=0;d<l.length-1;d++)l[d]*l[d+1]<0&&f++;return f>0?"S_curve":"C_curve"}function xi(t,e){if(t.length<3)return[t];let n=ho(e),o=pi(t),r=[],s=0;for(let i=0;i<o.length;i++)Math.abs(o[i])>n&&(r.push(t.slice(s,i+2)),s=i+1);return s<t.length-1&&r.push(t.slice(s)),r}function yi(t,e,n=6){let o=[],r=0;for(let s of t){let i=xi(s.points,e);for(let l of i){if(l.length<2)continue;let u=gi(l,n),f=Re(l),d=f/(s.length||1),c=Math.max(1,Math.round(s.pointCount*d));o.push({id:r++,points:l,length:f,pointCount:c,lineIds:s.lineIds,type:u,isMain:!1})}}return o}function bi(t,e){if(t.length<3)return new Set;let n=.15;function o(f,d){return Math.round(f/n)+"_"+Math.round(d/n)}let r=new Map,s=0;function i(f,d){let c=o(f,d),a=r.get(c);if(a)return a;let h=Math.round(f/n),g=Math.round(d/n),b=null,x=n*n;for(let m=-1;m<=1;m++)for(let p=-1;p<=1;p++){let y=h+m+"_"+(g+p),w=r.get(y);if(!w)continue;let z=w.x-f,M=w.z-d,P=z*z+M*M;P<x&&(x=P,b=w)}return b?(r.set(c,b),b):(a={id:s++,x:f,z:d,edges:[]},r.set(c,a),a)}for(let f of t){if(f.points.length<2)continue;let d=f.points[0],c=f.points[f.points.length-1],a=i(d.x,d.z),h=i(c.x,c.z);if(a.id===h.id)continue;let g={to:h,wallId:f.id,visited:!1,twin:null},b={to:a,wallId:f.id,visited:!1,twin:g};g.twin=b,a.edges.push(g),h.edges.push(b)}for(let f of r.values())f.edges.sort((d,c)=>{let a=Math.atan2(d.to.z-f.z,d.to.x-f.x),h=Math.atan2(c.to.z-f.z,c.to.x-f.x);return a-h});let l=new Set,u=new Set;for(let f of r.values())for(let d of f.edges)u.add(d);for(let f of u){if(f.visited)continue;let d=[],c=f,a=u.size+10;for(;!c.visited&&d.length<a;){c.visited=!0,d.push(c);let h=c.to,g=c.twin,b=h.edges.indexOf(g);if(b<0)break;let x=(b+1)%h.edges.length;c=h.edges[x]}if(d.length>=3){let h=d[0];if(d[d.length-1].to.id===h.from?.id){let b=[],x=new Set,m=null;for(let p of r.values())if(p.edges.includes(d[0])){m=p;break}if(!m)continue;b.push({x:m.x,z:m.z});for(let p of d)x.add(p.wallId),b.push({x:p.to.x,z:p.to.z});if(d[d.length-1].to.id===m.id&&tr(b)>=e)for(let y of x)l.add(y)}}}return l}function hn(t,e){let n={...ar,...e},o=Date.now(),{rotated:r,mainAngle:s}=di(t),i=Date.now(),l=hi(r,n.gridSize),u=Date.now(),f=ho(n.angleTol),d=[];for(let v of l.values()){let T=v.map(D=>({id:D.id,x1:D.x1,z1:D.z1,x2:D.x2,z2:D.z2})),R=mi(T,n.connectDist,f);d.push(...R)}let c=Date.now(),a=new Set,h=d.filter(v=>{let T=v.length>=n.minLength||v.pointCount>=n.minPointCount;return T&&a.add(v),T}),g=d.filter(v=>!a.has(v)),b=Date.now(),x=yi(h,n.hardCornerThreshold,n.minCurvePoints),m=Date.now(),p=bi(x,n.minArea);x.forEach(v=>{v.isMain=p.has(v.id),v.length>=n.longWallMinLength&&(v.isMain=!0)});let y=Date.now();function w(v,T,R=.1){let D=v[0],H=v[v.length-1],V=T[0],C=T[T.length-1];return Math.hypot(D.x-V.x,D.z-V.z)<R||Math.hypot(D.x-C.x,D.z-C.z)<R||Math.hypot(H.x-V.x,H.z-V.z)<R||Math.hypot(H.x-C.x,H.z-C.z)<R}let z=[],M=[];for(let v of x){if(v.type==="straight"&&v.points.length>=2){let T=!1;for(let R of x){if(R.id===v.id||R.type==="straight"||w(v.points,R.points))continue;if(ti(v.points,R.points)<n.curveStraightDist){T=!0;break}}if(T){z.push({...v,id:-z.length-1});continue}}M.push(v)}let P=Date.now(),E=M,S=[];for(let v=0;v<g.length;v++){let T=g[v];S.push({id:-v-1,points:T.points,length:T.length,pointCount:T.pointCount,lineIds:T.lineIds,type:"straight",isMain:!1})}for(let v of z)S.push(v);let I=v=>v.map(T=>({...T,points:T.points.map(R=>In(R.x,R.z,s))})),W=Date.now()-o;return{mainWalls:I(E),noiseWalls:I(S),stats:{totalRawLines:t.length,totalWalls:x.length,mainCount:E.length,noiseCount:S.length,elapsedMs:W}}}function lr(t,e,n){let o={...rr,...n},r=Date.now(),s=[];for(let h of t){let g=h.z;g<o.heightMin||g>o.heightMax||s.push({x:h.x,z:h.y})}if(s.length<100)return hn(e);let{cells:i}=mo(s,o.cellSize),l=new Set;for(let[h,g]of i)g>=o.densityThreshold&&l.add(h);let u=Wn(l,o.morphIterations),f=[],d={total:0,lowDensity:0};for(let h of e){let g=h.x1,b=h.z1,x=h.x2,m=h.z2;if(Math.sqrt((x-g)**2+(m-b)**2)<.3){f.push(h);continue}let y=0,w=9;for(let z=0;z<w;z++){let M=z/(w-1),P=g+(x-g)*M,E=b+(m-b)*M,S=Math.floor(P/o.cellSize),I=Math.floor(E/o.cellSize);u.has(S+","+I)&&y++}y>=Math.ceil(w*.5)?f.push(h):d.lowDensity++,d.total++}if(f.length<5)return hn(e);let c=hn(f),a=Date.now()-r;return c}function ir(t){return{id:t.id,points:[{x:t.x1,z:t.z1},{x:t.x2,z:t.z2}],length:Math.hypot(t.x2-t.x1,t.z2-t.z1),pointCount:1,type:"straight",isMain:!1}}function cr(t,e,n){let o={outlierEnabled:!0,outlierCellSize:.1,outlierMinNeighbors:3,densityFilterEnabled:!1,...n},r=Date.now(),s=hn(t),i=s.mainWalls,l=s.noiseWalls,u=new Set(i.map(M=>M.id)),f=[];for(let M=0;M<e.length;M++){if(!u.has(M))continue;let P=e[M];if(!(!P||!Array.isArray(P)))for(let E of P)E&&E.x!==void 0&&E.y!==void 0&&E.z!==void 0&&f.push({x:E.x,y:E.y,z:E.z})}let d=f.length,c=f;o.outlierEnabled&&c.length>0&&(c=go(c,o.outlierCellSize,o.outlierMinNeighbors));let a=[],h=[];if(c.length>=100){let M=o.pcConfig??{},P=po(c,t,{cellSize:.05,densityThreshold:1,minComponentCells:8,simplifyEpsilon:.008,heightMin:.3,heightMax:2.8,closeIterations:8,densityRatio:.12,...M});a=P.contours??[],h=P.curvedSegments??[]}let g=[];if(h.length>0)for(let M=0;M<h.length;M++){let E=h[M].points;if(E.length<2)continue;let S=1/0,I=-1/0,W=1/0,v=-1/0;for(let D of E)D.x<S&&(S=D.x),D.x>I&&(I=D.x),D.z<W&&(W=D.z),D.z>v&&(v=D.z);let T=[];for(let D of t)ci(D,E,.2)&&T.push(D.id);let R=E.map(D=>({x:D.x,y:D.z,z:0}));g.push({id:M,originalPoints:R,rawLineIds:T})}let b;if(o.densityFilterEnabled&&c.length>0&&i.length>0){let M=new Set(s.mainWalls.map(S=>S.id)),P=t.filter(S=>M.has(S.id));b=lr(c,P).mainWalls}let x=new Set;for(let M of s.mainWalls)if(M.lineIds)for(let P of M.lineIds)x.add(P);let m=new Set;for(let M of s.noiseWalls)if(M.lineIds)for(let P of M.lineIds)m.add(P);let p=t.filter(M=>x.has(M.id)).map(ir),y=t.filter(M=>m.has(M.id)).map(ir),w;if(b&&b.length>0){let M=new Set;for(let P of b)if(P.lineIds)for(let E of P.lineIds)M.add(E);w=t.filter(P=>M.has(P.id)).map(ir)}let z=Date.now()-r;return{mainWalls:p,noiseWalls:y,contours:a,curvedSegments:h,lineCurves:g.length>0?g:void 0,filteredPoints:c,secondMainWalls:w,stats:{totalRawLines:t.length,firstMainCount:p.length,firstNoiseCount:y.length,contourCount:a.length,curvedCount:h.length,secondMainCount:b?.length,mainWallPointCount:d,filteredPointCount:c.length,elapsedMs:z}}}function wi(t,e){let n=Array.isArray(t)?t:t?.data??[],o=[],r=[];for(let l=0;l<n.length;l++){let u=n[l],f=u.start??u,d=u.end??u;o.push({id:l,x1:f.x??0,y1:f.z??0,z1:f.y??0,x2:d.x??0,y2:d.z??0,z2:d.y??0});let c=u.originalPoints??u.points??[],a=Array.isArray(c)?c.filter(h=>h&&h.x!==void 0):[];r.push(a)}let s=cr(o,r,e),i=Array.isArray(t)?{data:t}:{...t};return i.lineCurves=s.lineCurves??[],i.lineCurveNum=s.curvedSegments?.length??0,i}export{ar as CONFIG,ro as analyzeDoorQuad,je as analyzeQuad,xo as applyVoxelFilter,uo as attachWindows,Ue as calcAngle,Qi as checkBeamIsReasonable,ni as classifyWallByPointCloudPCA,hn as classifyWallShapes,il as computeContour,Ge as computeDoorLocalFloorZ,$e as computeLocalFloorZ,ii as computeVoxelParams,li as densityPreFilter,cn as detectDoorPerpendicularWalls,Zl as detectPerpWalls,Tn as detectPerpendicularWalls,$a as drawStaircase,ui as filterFalseArcCurves,Qs as filterWalls,Js as filterWallsHard,vn as findDoorWalls,Gs as findMainByLoops,Rn as findWindowWalls,Ki as getBeamLine,oa as getColLine,Ii as getLineCheckResults,un as getMatcherAPI,Za as getMergeFloorMeaning,Xa as getMergeMeaning,Vi as getOneLineCheckResults,Hi as getOneLineClusterResults,al as getSlabData,Ga as getStaircase,sr as isRawLineNearArc,fi as logArcRawSegments,jl as matchWalls,Ks as mergeCollinear,Xe as mergeCollinearSegments,Ye as mergeDoorCollinearSegments,Xl as mergeWallSegments,lo as normalizeAngles,jt as pointToDoorSegmentDist,ao as pointToSegDist,Qe as pointToSegDist2D,Ce as pointToSegmentDist,Xo as processData,Ko as processDoorData,lr as processFilteredByPointCloud,po as processFromPointCloud,ri as processFromSegments,Kl as processPipeline,wi as processSegments,$l as processWallData,go as removeOutlierPoints,He as rotateXZ,cr as runMainWallPipeline,Ys as spatialGrid,Dn as splitDoorWallSegment,Gl as splitWallSeg,Sn as splitWallSegment,qi as updateStEdPoint,si as voxelFilter,ai as voxelFilterLines};