define(["exports"],(function(e){"use strict";class t{constructor(e){this.segments=e||[]}prepareSegment(e,n,i,r){let s=this.segments[this.segments.length-1];return e>t.MAX_VERTEX_ARRAY_LENGTH&&console.log(`Max vertices per segment is ${t.MAX_VERTEX_ARRAY_LENGTH}: bucket requested ${e}`),(!s||s.vertexLength+e>t.MAX_VERTEX_ARRAY_LENGTH||s.sortKey!==r)&&(s={vertexOffset:n.length,primitiveOffset:i.length,vertexLength:0,primitiveLength:0},void 0!==r&&(s.sortKey=r),this.segments.push(s)),s}get(){return this.segments}destroy(){for(const e of this.segments)e.vao&&e.vao.destroy()}static simpleSegment(e,n,i,r){return new t([{vertexOffset:e,primitiveOffset:n,vertexLength:i,primitiveLength:r,sortKey:0}])}}t.MAX_VERTEX_ARRAY_LENGTH=Math.pow(2,16)-1;class n{constructor(e){this.style=e.style,this.type=e.type,this.tileSize=e.tileSize}serialize(e){}destroy(){}}function i(e,t,n,i,s){r(e,t,n||0,i||e.length-1,s||h)}function r(e,t,n,i,h){for(;i>n;){if(i-n>600){var o=i-n+1,a=t-n+1,l=Math.log(o),d=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*d*(o-d)/o)*(a-o/2<0?-1:1);r(e,t,Math.max(n,Math.floor(t-a*d/o+u)),Math.min(i,Math.floor(t+(o-a)*d/o+u)),h)}var c=e[t],g=n,f=i;for(s(e,n,t),h(e[i],c)>0&&s(e,n,i);g0;)f--}0===h(e[n],c)?s(e,n,f):s(e,++f,i),f<=t&&(n=f+1),t<=f&&(i=f-1)}}function s(e,t,n){var i=e[t];e[t]=e[n],e[n]=i}function h(e,t){return et?1:0}function o(e){let t=0;for(let n,i,r=0,s=e.length,h=s-1;r0?i0?(t.t-n.t)*i+(t.t-e.t)*r:0},p.transEval=function(e,t,n){d(p.transLeq(e,t)&&p.transLeq(t,n));var i=t.t-e.t,r=n.t-t.t;return i+r>0?i0?(t.s-n.s)*i+(t.s-e.s)*r:0},p.vertCCW=function(e,t,n){return e.s*(t.t-n.t)+t.s*(n.t-e.t)+n.s*(e.t-t.t)>=0},p.interpolate=function(e,t,n,i){return(e=e<0?0:e)<=(n=n<0?0:n)?0==n?(t+i)/2:t+e/(e+n)*(i-t):i+n/(e+n)*(t-i)},p.intersect=function(e,t,n,i,r){var s,h,o;p.vertLeq(e,t)||(o=e,e=t,t=o),p.vertLeq(n,i)||(o=n,n=i,i=o),p.vertLeq(e,n)||(o=e,e=n,n=o,o=t,t=i,i=o),p.vertLeq(n,t)?p.vertLeq(t,i)?((s=p.edgeEval(e,n,t))+(h=p.edgeEval(n,t,i))<0&&(s=-s,h=-h),r.s=p.interpolate(s,n.s,h,t.s)):((s=p.edgeSign(e,n,t))+(h=-p.edgeSign(e,i,t))<0&&(s=-s,h=-h),r.s=p.interpolate(s,n.s,h,i.s)):r.s=(n.s+t.s)/2,p.transLeq(e,t)||(o=e,e=t,t=o),p.transLeq(n,i)||(o=n,n=i,i=o),p.transLeq(e,n)||(o=e,e=n,n=o,o=t,t=i,i=o),p.transLeq(n,t)?p.transLeq(t,i)?((s=p.transEval(e,n,t))+(h=p.transEval(n,t,i))<0&&(s=-s,h=-h),r.t=p.interpolate(s,n.t,h,t.t)):((s=p.transSign(e,n,t))+(h=-p.transSign(e,i,t))<0&&(s=-s,h=-h),r.t=p.interpolate(s,n.t,h,i.t)):r.t=(n.t+t.t)/2},m.prototype={min:function(){return this.head.next},max:function(){return this.head.prev},insert:function(e){return this.insertBefore(this.head,e)},search:function(e){var t=this.head;do{t=t.next}while(null!==t.key&&!this.leq(this.frame,e,t.key));return t},insertBefore:function(e,t){do{e=e.prev}while(null!==e.key&&!this.leq(this.frame,e.key,t));var n=new x;return n.key=t,n.next=e.next,e.next.prev=n,n.prev=e,e.next=n,n},delete:function(e){e.next.prev=e.prev,e.prev.next=e.next}},O.prototype={floatDown_:function(e){var t,n,i,r=this.nodes,s=this.handles;for(t=r[e].handle;;){if((i=e<<1)this.size||this.leq(s[t].key,s[n].key)){r[e].handle=t,s[t].node=e;break}r[e].handle=n,s[n].node=e,e=i}},floatUp_:function(e){var t,n,i,r=this.nodes,s=this.handles;for(t=r[e].handle;;){if(n=r[i=e>>1].handle,0==i||this.leq(s[n].key,s[t].key)){r[e].handle=t,s[t].node=e;break}r[e].handle=n,s[n].node=e,e=i}},init:function(){for(var e=this.size;e>=1;--e)this.floatDown_(e);this.initialized=!0},min:function(){return this.handles[this.nodes[1].handle].key},isEmpty:function(){this.size},insert:function(e){var t,n;if(2*(t=++this.size)>this.max){var i;this.max*=2,i=this.nodes.length,this.nodes.length=this.max+1;for(var r=i;r0&&(e[1].handle=e[this.size].handle,t[e[1].handle].node=1,t[n].key=null,t[n].node=this.freeList,this.freeList=n,--this.size,this.size>0&&this.floatDown_(1)),i},delete:function(e){var t,n=this.nodes,i=this.handles;d(e>=1&&e<=this.max&&null!==i[e].key),n[t=i[e].node].handle=n[this.size].handle,i[n[t].handle].node=t,--this.size,t<=this.size&&(t<=1||this.leq(i[n[t>>1].handle].key,i[n[t].handle].key)?this.floatDown_(t):this.floatUp_(t)),i[e].key=null,i[e].node=this.freeList,this.freeList=e}};var E={};function S(){this.mesh=null,this.normal=[0,0,0],this.sUnit=[0,0,0],this.tUnit=[0,0,0],this.bmin=[0,0],this.bmax=[0,0],this.windingRule=l.WINDING_ODD,this.dict=null,this.pq=null,this.event=null,this.vertexIndexCounter=0,this.vertices=[],this.vertexIndices=[],this.vertexCount=0,this.elements=[],this.elementCount=0}E.regionBelow=function(e){return e.nodeUp.prev.key},E.regionAbove=function(e){return e.nodeUp.next.key},E.debugEvent=function(e){},E.addWinding=function(e,t){e.winding+=t.winding,e.Sym.winding+=t.Sym.winding},E.edgeLeq=function(e,t,n){var i=e.event,r=t.eUp,s=n.eUp;return r.Dst===i?s.Dst===i?p.vertLeq(r.Org,s.Org)?p.edgeSign(s.Dst,r.Org,s.Org)<=0:p.edgeSign(r.Dst,s.Org,r.Org)>=0:p.edgeSign(s.Dst,i,s.Org)<=0:s.Dst===i?p.edgeSign(r.Dst,i,r.Org)>=0:p.edgeEval(r.Dst,i,r.Org)>=p.edgeEval(s.Dst,i,s.Org)},E.deleteRegion=function(e,t){t.fixUpperEdge&&d(0===t.eUp.winding),t.eUp.activeRegion=null,e.dict.delete(t.nodeUp)},E.fixUpperEdge=function(e,t,n){d(t.fixUpperEdge),e.mesh.delete(t.eUp),t.fixUpperEdge=!1,t.eUp=n,n.activeRegion=t},E.topLeftRegion=function(e,t){var n,i=t.eUp.Org;do{t=E.regionAbove(t)}while(t.eUp.Org===i);if(t.fixUpperEdge){if(null===(n=e.mesh.connect(E.regionBelow(t).eUp.Sym,t.eUp.Lnext)))return null;E.fixUpperEdge(e,t,n),t=E.regionAbove(t)}return t},E.topRightRegion=function(e){var t=e.eUp.Dst;do{e=E.regionAbove(e)}while(e.eUp.Dst===t);return e},E.addRegionBelow=function(e,t,n){var i=new L;return i.eUp=n,i.nodeUp=e.dict.insertBefore(t.nodeUp,i),i.fixUpperEdge=!1,i.sentinel=!1,i.dirty=!1,n.activeRegion=i,i},E.isWindingInside=function(e,t){switch(e.windingRule){case l.WINDING_ODD:return 0!=(1&t);case l.WINDING_NONZERO:return 0!=t;case l.WINDING_POSITIVE:return t>0;case l.WINDING_NEGATIVE:return t<0;case l.WINDING_ABS_GEQ_TWO:return t>=2||t<=-2}return d(!1),!1},E.computeWinding=function(e,t){t.windingNumber=E.regionAbove(t).windingNumber+t.eUp.winding,t.inside=E.isWindingInside(e,t.windingNumber)},E.finishRegion=function(e,t){var n=t.eUp,i=n.Lface;i.inside=t.inside,i.anEdge=n,E.deleteRegion(e,t)},E.finishLeftRegions=function(e,t,n){for(var i,r=null,s=t,h=t.eUp;s!==n;){if(s.fixUpperEdge=!1,(i=(r=E.regionBelow(s)).eUp).Org!=h.Org){if(!r.fixUpperEdge){E.finishRegion(e,s);break}i=e.mesh.connect(h.Lprev,i.Sym),E.fixUpperEdge(e,r,i)}h.Onext!==i&&(e.mesh.splice(i.Oprev,i),e.mesh.splice(h,i)),E.finishRegion(e,s),h=r.eUp,s=r}return h},E.addRightEdges=function(e,t,n,i,r,s){var h,o,a,l,u=!0;a=n;do{d(p.vertLeq(a.Org,a.Dst)),E.addRegionBelow(e,t,a.Sym),a=a.Onext}while(a!==i);for(null===r&&(r=E.regionBelow(t).eUp.Rprev),o=t,l=r;(a=(h=E.regionBelow(o)).eUp.Sym).Org===l.Org;)a.Onext!==l&&(e.mesh.splice(a.Oprev,a),e.mesh.splice(l.Oprev,a)),h.windingNumber=o.windingNumber-a.winding,h.inside=E.isWindingInside(e,h.windingNumber),o.dirty=!0,!u&&E.checkForRightSplice(e,o)&&(E.addWinding(a,l),E.deleteRegion(e,o),e.mesh.delete(l)),u=!1,o=h,l=a;o.dirty=!0,d(o.windingNumber-a.winding===h.windingNumber),s&&E.walkDirtyRegions(e,o)},E.spliceMergeVertices=function(e,t,n){e.mesh.splice(t,n)},E.vertexWeights=function(e,t,n){var i=p.vertL1dist(t,e),r=p.vertL1dist(n,e),s=.5*r/(i+r),h=.5*i/(i+r);e.coords[0]+=s*t.coords[0]+h*n.coords[0],e.coords[1]+=s*t.coords[1]+h*n.coords[1],e.coords[2]+=s*t.coords[2]+h*n.coords[2]},E.getIntersectData=function(e,t,n,i,r,s){t.coords[0]=t.coords[1]=t.coords[2]=0,t.idx=-1,E.vertexWeights(t,n,i),E.vertexWeights(t,r,s)},E.checkForRightSplice=function(e,t){var n=E.regionBelow(t),i=t.eUp,r=n.eUp;if(p.vertLeq(i.Org,r.Org)){if(p.edgeSign(r.Dst,i.Org,r.Org)>0)return!1;p.vertEq(i.Org,r.Org)?i.Org!==r.Org&&(e.pq.delete(i.Org.pqHandle),E.spliceMergeVertices(e,r.Oprev,i)):(e.mesh.splitEdge(r.Sym),e.mesh.splice(i,r.Oprev),t.dirty=n.dirty=!0)}else{if(p.edgeSign(i.Dst,r.Org,i.Org)<0)return!1;E.regionAbove(t).dirty=t.dirty=!0,e.mesh.splitEdge(i.Sym),e.mesh.splice(r.Oprev,i)}return!0},E.checkForLeftSplice=function(e,t){var n,i=E.regionBelow(t),r=t.eUp,s=i.eUp;if(d(!p.vertEq(r.Dst,s.Dst)),p.vertLeq(r.Dst,s.Dst)){if(p.edgeSign(r.Dst,s.Dst,r.Org)<0)return!1;E.regionAbove(t).dirty=t.dirty=!0,n=e.mesh.splitEdge(r),e.mesh.splice(s.Sym,n),n.Lface.inside=t.inside}else{if(p.edgeSign(s.Dst,r.Dst,s.Org)>0)return!1;t.dirty=i.dirty=!0,n=e.mesh.splitEdge(s),e.mesh.splice(r.Lnext,s.Sym),n.Rface.inside=t.inside}return!0},E.checkForIntersect=function(e,t){var n,i,r=E.regionBelow(t),s=t.eUp,h=r.eUp,o=s.Org,a=h.Org,l=s.Dst,c=h.Dst,g=new u;if(d(!p.vertEq(c,l)),d(p.edgeSign(l,e.event,o)<=0),d(p.edgeSign(c,e.event,a)>=0),d(o!==e.event&&a!==e.event),d(!t.fixUpperEdge&&!r.fixUpperEdge),o===a)return!1;if(Math.min(o.t,l.t)>Math.max(a.t,c.t))return!1;if(p.vertLeq(o,a)){if(p.edgeSign(c,o,a)>0)return!1}else if(p.edgeSign(l,a,o)<0)return!1;return E.debugEvent(e),p.intersect(l,o,c,a,g),d(Math.min(o.t,l.t)<=g.t),d(g.t<=Math.max(a.t,c.t)),d(Math.min(c.s,l.s)<=g.s),d(g.s<=Math.max(a.s,o.s)),p.vertLeq(g,e.event)&&(g.s=e.event.s,g.t=e.event.t),n=p.vertLeq(o,a)?o:a,p.vertLeq(n,g)&&(g.s=n.s,g.t=n.t),p.vertEq(g,o)||p.vertEq(g,a)?(E.checkForRightSplice(e,t),!1):!p.vertEq(l,e.event)&&p.edgeSign(l,e.event,g)>=0||!p.vertEq(c,e.event)&&p.edgeSign(c,e.event,g)<=0?c===e.event?(e.mesh.splitEdge(s.Sym),e.mesh.splice(h.Sym,s),t=E.topLeftRegion(e,t),s=E.regionBelow(t).eUp,E.finishLeftRegions(e,E.regionBelow(t),r),E.addRightEdges(e,t,s.Oprev,s,s,!0),!0):l===e.event?(e.mesh.splitEdge(h.Sym),e.mesh.splice(s.Lnext,h.Oprev),r=t,t=E.topRightRegion(t),i=E.regionBelow(t).eUp.Rprev,r.eUp=h.Oprev,h=E.finishLeftRegions(e,r,null),E.addRightEdges(e,t,h.Onext,s.Rprev,i,!0),!0):(p.edgeSign(l,e.event,g)>=0&&(E.regionAbove(t).dirty=t.dirty=!0,e.mesh.splitEdge(s.Sym),s.Org.s=e.event.s,s.Org.t=e.event.t),p.edgeSign(c,e.event,g)<=0&&(t.dirty=r.dirty=!0,e.mesh.splitEdge(h.Sym),h.Org.s=e.event.s,h.Org.t=e.event.t),!1):(e.mesh.splitEdge(s.Sym),e.mesh.splitEdge(h.Sym),e.mesh.splice(h.Oprev,s),s.Org.s=g.s,s.Org.t=g.t,s.Org.pqHandle=e.pq.insert(s.Org),E.getIntersectData(e,s.Org,o,l,a,c),E.regionAbove(t).dirty=t.dirty=r.dirty=!0,!1)},E.walkDirtyRegions=function(e,t){for(var n,i,r=E.regionBelow(t);;){for(;r.dirty;)t=r,r=E.regionBelow(r);if(!t.dirty&&(r=t,null==(t=E.regionAbove(t))||!t.dirty))return;if(t.dirty=!1,n=t.eUp,i=r.eUp,n.Dst!==i.Dst&&E.checkForLeftSplice(e,t)&&(r.fixUpperEdge?(E.deleteRegion(e,r),e.mesh.delete(i),i=(r=E.regionBelow(t)).eUp):t.fixUpperEdge&&(E.deleteRegion(e,t),e.mesh.delete(n),n=(t=E.regionAbove(r)).eUp)),n.Org!==i.Org)if(n.Dst===i.Dst||t.fixUpperEdge||r.fixUpperEdge||n.Dst!==e.event&&i.Dst!==e.event)E.checkForRightSplice(e,t);else if(E.checkForIntersect(e,t))return;n.Org===i.Org&&n.Dst===i.Dst&&(E.addWinding(i,n),E.deleteRegion(e,t),e.mesh.delete(n),t=E.regionAbove(r))}},E.connectRightVertex=function(e,t,n){var i,r=n.Onext,s=E.regionBelow(t),h=t.eUp,o=s.eUp,a=!1;h.Dst!==o.Dst&&E.checkForIntersect(e,t),p.vertEq(h.Org,e.event)&&(e.mesh.splice(r.Oprev,h),t=E.topLeftRegion(e,t),r=E.regionBelow(t).eUp,E.finishLeftRegions(e,E.regionBelow(t),s),a=!0),p.vertEq(o.Org,e.event)&&(e.mesh.splice(n,o.Oprev),n=E.finishLeftRegions(e,s,null),a=!0),a?E.addRightEdges(e,t,n.Onext,r,r,!0):(i=p.vertLeq(o.Org,h.Org)?o.Oprev:h,i=e.mesh.connect(n.Lprev,i),E.addRightEdges(e,t,i,i.Onext,i.Onext,!1),i.Sym.activeRegion.fixUpperEdge=!0,E.walkDirtyRegions(e,t))},E.connectLeftDegenerate=function(e,t,n){var i,r,s,h,o;return i=t.eUp,p.vertEq(i.Org,n)?(d(!1),void E.spliceMergeVertices(e,i,n.anEdge)):p.vertEq(i.Dst,n)?(d(!1),t=E.topRightRegion(t),r=h=(s=(o=E.regionBelow(t)).eUp.Sym).Onext,o.fixUpperEdge&&(d(r!==s),E.deleteRegion(e,o),e.mesh.delete(s),s=r.Oprev),e.mesh.splice(n.anEdge,s),p.edgeGoesLeft(r)||(r=null),void E.addRightEdges(e,t,s.Onext,h,r,!0)):(e.mesh.splitEdge(i.Sym),t.fixUpperEdge&&(e.mesh.delete(i.Onext),t.fixUpperEdge=!1),e.mesh.splice(n.anEdge,i),void E.sweepEvent(e,n))},E.connectLeftVertex=function(e,t){var n,i,r,s,h,o,a=new L;if(a.eUp=t.anEdge.Sym,n=e.dict.search(a).key,i=E.regionBelow(n))if(s=n.eUp,h=i.eUp,0!==p.edgeSign(s.Dst,t,s.Org))if(r=p.vertLeq(h.Dst,s.Dst)?n:i,n.inside||r.fixUpperEdge){if(r===n)o=e.mesh.connect(t.anEdge.Sym,s.Lnext);else o=e.mesh.connect(h.Dnext,t.anEdge).Sym;r.fixUpperEdge?E.fixUpperEdge(e,r,o):E.computeWinding(e,E.addRegionBelow(e,n,o)),E.sweepEvent(e,t)}else E.addRightEdges(e,n,t.anEdge,t.anEdge,null,!0);else E.connectLeftDegenerate(e,n,t)},E.sweepEvent=function(e,t){e.event=t,E.debugEvent(e);for(var n=t.anEdge;null===n.activeRegion;)if((n=n.Onext)==t.anEdge)return void E.connectLeftVertex(e,t);var i=E.topLeftRegion(e,n.activeRegion);d(null!==i);var r=E.regionBelow(i),s=r.eUp,h=E.finishLeftRegions(e,r,null);h.Onext===s?E.connectRightVertex(e,i,h):E.addRightEdges(e,i,h.Onext,s,s,!0)},E.addSentinel=function(e,t,n,i){var r=new L,s=e.mesh.makeEdge();s.Org.s=n,s.Org.t=i,s.Dst.s=t,s.Dst.t=i,e.event=s.Dst,r.eUp=s,r.windingNumber=0,r.inside=!1,r.fixUpperEdge=!1,r.sentinel=!0,r.dirty=!1,r.nodeUp=e.dict.insert(r)},E.initEdgeDict=function(e){e.dict=new m(e,E.edgeLeq);var t=e.bmax[0]-e.bmin[0],n=e.bmax[1]-e.bmin[1],i=e.bmin[0]-t,r=e.bmax[0]+t,s=e.bmin[1]-n,h=e.bmax[1]+n;E.addSentinel(e,i,r,s),E.addSentinel(e,i,r,h)},E.doneEdgeDict=function(e){for(var t,n=0;null!==(t=e.dict.min().key);)t.sentinel||(d(t.fixUpperEdge),d(1==++n)),d(0==t.windingNumber),E.deleteRegion(e,t)},E.removeDegenerateEdges=function(e){var t,n,i,r=e.mesh.eHead;for(t=r.next;t!==r;t=n)n=t.next,i=t.Lnext,p.vertEq(t.Org,t.Dst)&&t.Lnext.Lnext!==t&&(E.spliceMergeVertices(e,i,t),e.mesh.delete(t),i=(t=i).Lnext),i.Lnext===t&&(i!==t&&(i!==n&&i!==n.Sym||(n=n.next),e.mesh.delete(i)),t!==n&&t!==n.Sym||(n=n.next),e.mesh.delete(t))},E.initPriorityQ=function(e){var t,n,i,r=0;for(n=(i=e.mesh.vHead).next;n!==i;n=n.next)r++;for(r+=8,t=e.pq=new O(r,p.vertLeq),n=(i=e.mesh.vHead).next;n!==i;n=n.next)n.pqHandle=t.insert(n);return n===i&&(t.init(),!0)},E.donePriorityQ=function(e){e.pq=null},E.removeDegenerateFaces=function(e,t){var n,i,r;for(n=t.fHead.next;n!==t.fHead;n=i)i=n.next,r=n.anEdge,d(r.Lnext!==r),r.Lnext.Lnext===r&&(E.addWinding(r.Onext,r),e.mesh.delete(r));return!0},E.computeInterior=function(e){var t,n;if(E.removeDegenerateEdges(e),!E.initPriorityQ(e))return!1;for(E.initEdgeDict(e);null!==(t=e.pq.extractMin());){for(;null!==(n=e.pq.min())&&p.vertEq(n,t);)n=e.pq.extractMin(),E.spliceMergeVertices(e,t.anEdge,n.anEdge);E.sweepEvent(e,t)}return e.event=e.dict.min().key.eUp.Org,E.debugEvent(e),E.doneEdgeDict(e),E.donePriorityQ(e),!!E.removeDegenerateFaces(e,e.mesh)&&(e.mesh.check(),!0)},S.prototype={dot_:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},normalize_:function(e){var t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];d(t>0),t=Math.sqrt(t),e[0]/=t,e[1]/=t,e[2]/=t},longAxis_:function(e){var t=0;return Math.abs(e[1])>Math.abs(e[0])&&(t=1),Math.abs(e[2])>Math.abs(e[t])&&(t=2),t},computeNormal_:function(e){var t,n,i,r,s,h,o,a=[0,0,0],l=[0,0,0],d=[0,0,0],u=[0,0,0],c=[0,0,0],g=[null,null,null],f=[null,null,null],p=this.mesh.vHead;for(t=p.next,o=0;o<3;++o)r=t.coords[o],l[o]=r,f[o]=t,a[o]=r,g[o]=t;for(t=p.next;t!==p;t=t.next)for(o=0;o<3;++o)(r=t.coords[o])a[o]&&(a[o]=r,g[o]=t);if(o=0,a[1]-l[1]>a[0]-l[0]&&(o=1),a[2]-l[2]>a[o]-l[o]&&(o=2),l[o]>=a[o])return e[0]=0,e[1]=0,void(e[2]=1);for(h=0,n=f[o],i=g[o],d[0]=n.coords[0]-i.coords[0],d[1]=n.coords[1]-i.coords[1],d[2]=n.coords[2]-i.coords[2],t=p.next;t!==p;t=t.next)u[0]=t.coords[0]-i.coords[0],u[1]=t.coords[1]-i.coords[1],u[2]=t.coords[2]-i.coords[2],c[0]=d[1]*u[2]-d[2]*u[1],c[1]=d[2]*u[0]-d[0]*u[2],c[2]=d[0]*u[1]-d[1]*u[0],(s=c[0]*c[0]+c[1]*c[1]+c[2]*c[2])>h&&(h=s,e[0]=c[0],e[1]=c[1],e[2]=c[2]);h<=0&&(e[0]=e[1]=e[2]=0,e[this.longAxis_(d)]=1)},checkOrientation_:function(){var e,t,n,i,r=this.mesh.fHead,s=this.mesh.vHead;for(e=0,t=r.next;t!==r;t=t.next)if(!((i=t.anEdge).winding<=0))do{e+=(i.Org.s-i.Dst.s)*(i.Org.t+i.Dst.t),i=i.Lnext}while(i!==t.anEdge);if(e<0){for(n=s.next;n!==s;n=n.next)n.t=-n.t;this.tUnit[0]=-this.tUnit[0],this.tUnit[1]=-this.tUnit[1],this.tUnit[2]=-this.tUnit[2]}},projectPolygon_:function(){var e,t,n,i,r,s=this.mesh.vHead,h=[0,0,0],o=!1;for(h[0]=this.normal[0],h[1]=this.normal[1],h[2]=this.normal[2],0===h[0]&&0===h[1]&&0===h[2]&&(this.computeNormal_(h),o=!0),t=this.sUnit,n=this.tUnit,t[i=this.longAxis_(h)]=0,t[(i+1)%3]=1,t[(i+2)%3]=0,n[i]=0,n[(i+1)%3]=0,n[(i+2)%3]=h[i]>0?1:-1,e=s.next;e!==s;e=e.next)e.s=this.dot_(e.coords,t),e.t=this.dot_(e.coords,n);for(o&&this.checkOrientation_(),r=!0,e=s.next;e!==s;e=e.next)r?(this.bmin[0]=this.bmax[0]=e.s,this.bmin[1]=this.bmax[1]=e.t,r=!1):(e.sthis.bmax[0]&&(this.bmax[0]=e.s),e.tthis.bmax[1]&&(this.bmax[1]=e.t))},addWinding_:function(e,t){e.winding+=t.winding,e.Sym.winding+=t.Sym.winding},tessellateMonoRegion_:function(e,t){var n,i;for(n=t.anEdge,d(n.Lnext!==n&&n.Lnext.Lnext!==n);p.vertLeq(n.Dst,n.Org);n=n.Lprev);for(;p.vertLeq(n.Org,n.Dst);n=n.Lnext);for(i=n.Lprev;n.Lnext!==i;)if(p.vertLeq(n.Dst,i.Org)){for(;i.Lnext!==n&&(p.edgeGoesLeft(i.Lnext)||p.edgeSign(i.Org,i.Dst,i.Lnext.Dst)<=0);){i=e.connect(i.Lnext,i).Sym}i=i.Lprev}else{for(;i.Lnext!=n&&(p.edgeGoesRight(n.Lprev)||p.edgeSign(n.Dst,n.Org,n.Lprev.Org)>=0);){n=e.connect(n,n.Lprev).Sym}n=n.Lnext}for(d(i.Lnext!==n);i.Lnext.Lnext!==n;){i=e.connect(i.Lnext,i).Sym}return!0},tessellateInterior_:function(e){var t,n;for(t=e.fHead.next;t!==e.fHead;t=n)if(n=t.next,t.inside&&!this.tessellateMonoRegion_(e,t))return!1;return!0},discardExterior_:function(e){var t,n;for(t=e.fHead.next;t!==e.fHead;t=n)n=t.next,t.inside||e.zapFace(t)},setWindingNumber_:function(e,t,n){var i,r;for(i=e.eHead.next;i!==e.eHead;i=r)r=i.next,i.Rface.inside!==i.Lface.inside?i.winding=i.Lface.inside?t:-t:n?e.delete(i):i.winding=0},getNeighbourFace_:function(e){return e.Rface&&e.Rface.inside?e.Rface.n:-1},outputPolymesh_:function(e,t,n,i){var r,s,h,o,a,u=0,c=0;for(n>3&&e.mergeConvexFaces(n),r=e.vHead.next;r!==e.vHead;r=r.next)r.n=-1;for(s=e.fHead.next;s!=e.fHead;s=s.next)if(s.n=-1,s.inside){h=s.anEdge,o=0;do{-1===(r=h.Org).n&&(r.n=c,c++),o++,h=h.Lnext}while(h!==s.anEdge);d(o<=n),s.n=u,++u}for(this.elementCount=u,t==l.CONNECTED_POLYGONS&&(u*=2),this.elements=[],this.elements.length=u*n,this.vertexCount=c,this.vertices=[],this.vertices.length=c*i,this.vertexIndices=[],this.vertexIndices.length=c,r=e.vHead.next;r!==e.vHead;r=r.next)if(-1!=r.n){var g=r.n*i;this.vertices[g+0]=r.coords[0],this.vertices[g+1]=r.coords[1],i>2&&(this.vertices[g+2]=r.coords[2]),this.vertexIndices[r.n]=r.idx}var f=0;for(s=e.fHead.next;s!==e.fHead;s=s.next)if(s.inside){h=s.anEdge,o=0;do{r=h.Org,this.elements[f++]=r.n,o++,h=h.Lnext}while(h!==s.anEdge);for(a=o;a2&&(this.vertices[o++]=i.Org.coords[2]),this.vertexIndices[a++]=i.Org.idx,h++,i=i.Lnext}while(i!==r);this.elements[l++]=s,this.elements[l++]=h,s+=h}},addContour:function(e,t){var n,i;for(null===this.mesh&&(this.mesh=new f),e<2&&(e=2),e>3&&(e=3),n=null,i=0;i2?t[i+2]:0,n.Org.idx=this.vertexIndexCounter++,n.winding=1,n.Sym.winding=-1},tesselate:function(e,t,n,i,r){if(this.vertices=[],this.elements=[],this.vertexIndices=[],this.vertexIndexCounter=0,r&&(this.normal[0]=r[0],this.normal[1]=r[1],this.normal[2]=r[2]),this.windingRule=e,i<2&&(i=2),i>3&&(i=3),!this.mesh)return!1;this.projectPolygon_(),E.computeInterior(this);var s=this.mesh;return t==l.BOUNDARY_CONTOURS?this.setWindingNumber_(s,1,!0):this.tessellateInterior_(s),s.check(),t==l.BOUNDARY_CONTOURS?this.outputContours_(s,i):this.outputPolymesh_(s,t,n,i),!0}};const _={Int8:"BYTE",Uint8:"UNSIGNED_BYTE",Int16:"SHORT",Uint16:"UNSIGNED_SHORT",Int32:"INT",Uint32:"UNSIGNED_INT",Float32:"FLOAT"};class w{constructor(e,t,n){this.arrayBuffer=e.arrayBuffer,this.length=e.length,this.attributes=t.members,this.itemSize=t.bytesPerElement,this.type=n,this.arrayType=t}static fromStructArray(e,t){return new w(e.serialize(),e.constructor.serialize(),t)}updateData(e,t){this.bind(e),e.bufferSubData(e.ARRAY_BUFFER,0,t.arrayBuffer)}bind(e){const t=e[this.type];this.buffer?e.bindBuffer(t,this.buffer):(this.gl=e,this.buffer=e.createBuffer(),e.bindBuffer(t,this.buffer),e.bufferData(t,this.arrayBuffer,e.STATIC_DRAW),this.arrayBuffer=null)}enableAttributes(e,t){for(let n=0;n{o.indexOf(e.type)<0&&o.push(e.type);const t=A(e.type),n=s=U(s,Math.max(i,t)),r=e.components||1;return h=Math.max(h,t),s+=t*r,{name:e.name,type:e.type,components:r,offset:n}})),l=U(s,Math.max(h,i));class d extends class{constructor(e,t){this._structArray=e,this._pos1=t*this.size,this._pos2=this._pos1/2,this._pos4=this._pos1/4,this._pos8=this._pos1/8}}{}d.prototype.alignment=i,d.prototype.size=l;for(const e of a)for(let t=0;tthis.capacity){this.capacity=Math.max(e,Math.floor(5*this.capacity),128),this.arrayBuffer=new ArrayBuffer(this.capacity*this.bytesPerElement);const t=this.uint8;this._refreshViews(),t&&this.uint8.set(t)}}_refreshViews(){for(const e of this._usedTypes)this[k(e)]=new b[e](this.arrayBuffer)}toArray(e,t){const n=[];for(let i=e;i>6,i,r)}function P(e,t,n,i,r,s){var h=n,o=i,a=r-h,l=s-o;if(0!==a||0!==l){var d=((e-h)*a+(t-o)*l)/(a*a+l*l);d>1?(h=r,o=s):d>0&&(h+=a*d,o+=l*d)}return(a=e-h)*a+(l=t-o)*l}function Y(e,t,n,i,r){for(var s,h=i,o=t+1;oh&&(s=o,h=a)}h>i&&(s-t>1&&Y(e,t,s,i,r),r.push(e[2*s]),r.push(e[2*s+1]),n-s>1&&Y(e,s,n,i,r))}function $(e,t){var n=e.length/2-1,i=[e[0],e[1]];return Y(e,0,n,t,i),i.push(e[2*n],e[2*n+1]),i}function X(e,t){this.x=e,this.y=t}X.prototype={clone:function(){return new X(this.x,this.y)},add:function(e){return this.clone()._add(e)},sub:function(e){return this.clone()._sub(e)},mult:function(e){return this.clone()._mult(e)},div:function(e){return this.clone()._div(e)},rotate:function(e){return this.clone()._rotate(e)},matMult:function(e){return this.clone()._matMult(e)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(e){return this.x===e.x&&this.y===e.y},dist:function(e){return Math.sqrt(this.distSqr(e))},distSqr:function(e){var t=e.x-this.x,n=e.y-this.y;return t*t+n*n},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith:function(e){return this.angleWithSep(e.x,e.y)},angleWithSep:function(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult:function(e){var t=e[0]*this.x+e[1]*this.y,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,this},_add:function(e){return this.x+=e.x,this.y+=e.y,this},_sub:function(e){return this.x-=e.x,this.y-=e.y,this},_mult:function(e){return this.x*=e,this.y*=e,this},_div:function(e){return this.x/=e,this.y/=e,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var e=this.y;return this.y=this.x,this.x=-e,this},_rotate:function(e){var t=Math.cos(e),n=Math.sin(e),i=t*this.x-n*this.y,r=n*this.x+t*this.y;return this.x=i,this.y=r,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},X.convert=function(e){return e instanceof X?e:Array.isArray(e)?new X(e[0],e[1]):e},e.FillBucket=class extends n{constructor(e){super(e),this.overscaling=e.overscaling,this.layoutVertexArray=new M,this.layoutVertexArray2=new M,this.indexArray=new C,this.indexArray2=new T,this.segments=new t,this.segments2=new t}isEmpty(){return 0===this.layoutVertexArray.length}destroy(){this.segments.destroy(),this.segments2.destroy()}addFeature(e){for(const n of function(e,t){const n=e.length;if(n<=0)return[];const r=[];let s=[];for(let t=0;t1)for(let e=0;e=2&&e[h-1].equals(e[h-2]);)h--;let o=0;for(;oo){const e=c.dist(g);if(e>2*a){const t=c.sub(c.sub(g)._mult(a/e)._round());this.distance+=t.dist(g),this.addCurrentVertex(t,this.distance,p.mult(1),0,0,!1,l),g=t}}const S=g&&f;let _=S?n:f?d:u;if(S&&"round"===_&&(Lr&&(_="bevel"),"bevel"===_&&(L>2&&(_="flipbevel"),L100)i=x.clone().mult(-1);else{const e=p.x*x.y-p.y*x.x>0?-1:1,t=L*p.add(x).mag()/p.sub(x).mag();i._perp()._mult(t*e)}this.addCurrentVertex(c,this.distance,i,0,0,!1,l),this.addCurrentVertex(c,this.distance,i.mult(-1),0,0,!1,l)}else if("bevel"===_||"fakeround"===_){const e=p.x*x.y-p.y*x.x>0,t=-Math.sqrt(L*L-1);if(e?(y=0,m=t):(m=0,y=t),v||this.addCurrentVertex(c,this.distance,p,m,y,!1,l),"fakeround"===_){const t=Math.floor(8*(.5-(O-.5)));let n;for(let i=0;i=0;i--)n=p.mult((i+1)/(t+1))._add(x)._unit(),this.addPieSliceVertex(c,this.distance,n,e,l)}f&&this.addCurrentVertex(c,this.distance,x,-m,-y,!1,l)}else"butt"===_?(v||this.addCurrentVertex(c,this.distance,p,0,0,!1,l),f&&this.addCurrentVertex(c,this.distance,x,0,0,!1,l)):"square"===_?(v||(this.addCurrentVertex(c,this.distance,p,1,1,!1,l),this.e1=this.e2=-1),f&&this.addCurrentVertex(c,this.distance,x,-1,-1,!1,l)):"round"===_&&(v||(this.addCurrentVertex(c,this.distance,p,0,0,!1,l),this.addCurrentVertex(c,this.distance,p,1,1,!0,l),this.e1=this.e2=-1),f&&(this.addCurrentVertex(c,this.distance,x,-1,-1,!0,l),this.addCurrentVertex(c,this.distance,x,0,0,!1,l)));if(E&&t2*a){const t=c.add(f.sub(c)._mult(a/e)._round());this.distance+=t.dist(c),this.addCurrentVertex(t,this.distance,x.mult(1),0,0,!1,l),c=t}}v=!1}}addCurrentVertex(e,t,n,i,r,s,h){const o=s?1:0;let a;a=n.clone(),i&&a._sub(n.perp()._mult(i)),G(this.layoutVertexArray,e,a,o,0,i,t),this.e3=h.vertexLength++,this.e1>=0&&this.e2>=0&&(this.indexArray.emplaceBack(this.e1,this.e2,this.e3),h.primitiveLength++),this.e1=this.e2,this.e2=this.e3,a=n.mult(-1),r&&a._sub(n.perp()._mult(r)),G(this.layoutVertexArray,e,a,o,1,-r,t),this.e3=h.vertexLength++,this.e1>=0&&this.e2>=0&&(this.indexArray.emplaceBack(this.e1,this.e2,this.e3),h.primitiveLength++),this.e1=this.e2,this.e2=this.e3,t>W/2&&(this.distance=0,this.addCurrentVertex(e,this.distance,n,i,r,s,h))}addPieSliceVertex(e,t,n,i,r){const s=i?1:0;n=n.mult(i?-1:1),G(this.layoutVertexArray,e,n,0,s,0,t),this.e3=r.vertexLength++,this.e1>=0&&this.e2>=0&&(this.indexArray.emplaceBack(this.e1,this.e2,this.e3),r.primitiveLength++),i?this.e2=this.e3:this.e1=this.e3}serialize(e){return{type:this.type,style:this.style,tileSize:this.tileSize,layoutVertexArray:this.layoutVertexArray.serialize(e),indexArray:this.indexArray.serialize(e),segments:this.segments}}static createBuffer(e){e.layoutVertexBuffer=new w(e.layoutVertexArray,F.serialize(),w.BufferType.VERTEX),e.indexBuffer=new w(e.indexArray,z.serialize(),w.BufferType.ELEMENT)}},e.Point=X,e.simplify=function(e,t,n){if(e.length<=4)return e;var i=void 0!==t?t*t:1;return e=n?e:function(e,t){for(var n,i,r,s,h=e[0],o=e[1],a=[e[0],e[1]],l=e.length/2,d=1;dt&&(a.push(n),a.push(i),h=n,o=i);return h!==n&&o!==i&&(a.push(n),a.push(i)),a}(e,i),e=$(e,i)}}));