qa-prevention-gwj-vue/static/map/cesium91/CesiumUnminified/Workers/point-766425d1.js

2 lines
42 KiB
JavaScript

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);g<f;){for(s(e,g,f),g++,f--;h(e[g],c)<0;)g++;for(;h(e[f],c)>0;)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 e<t?-1:e>t?1:0}function o(e){let t=0;for(let n,i,r=0,s=e.length,h=s-1;r<s;h=r++)n=e[r],i=e[h],t+=(i.x-n.x)*(n.y+i.y);return t}function a(e,t){return t.area-e.area}var l={WINDING_ODD:0,WINDING_NONZERO:1,WINDING_POSITIVE:2,WINDING_NEGATIVE:3,WINDING_ABS_GEQ_TWO:4,POLYGONS:0,CONNECTED_POLYGONS:1,BOUNDARY_CONTOURS:2,tesselate:function(e){for(var t=e.debug||!1,n=new S,i=0;i<e.contours.length;i++)n.addContour(e.vertexSize||2,e.contours[i]);return n.tesselate(e.windingRule||l.WINDING_ODD,e.elementType||l.POLYGONS,e.polySize||3,e.vertexSize||2,e.normal||[0,0,1]),{vertices:n.vertices,vertexIndices:n.vertexIndices,vertexCount:n.vertexCount,elements:n.elements,elementCount:n.elementCount,mesh:t?n.mesh:void 0}}},d=function(e){if(!e)throw"Assertion Failed!"};function u(){this.next=null,this.prev=null,this.anEdge=null,this.coords=[0,0,0],this.s=0,this.t=0,this.pqHandle=0,this.n=0,this.idx=0}function c(){this.next=null,this.prev=null,this.anEdge=null,this.trail=null,this.n=0,this.marked=!1,this.inside=!1}function g(e){this.next=null,this.Sym=null,this.Onext=null,this.Lnext=null,this.Org=null,this.Lface=null,this.activeRegion=null,this.winding=0,this.side=e}function f(){var e=new u,t=new c,n=new g(0),i=new g(1);e.next=e.prev=e,e.anEdge=null,t.next=t.prev=t,t.anEdge=null,t.trail=null,t.marked=!1,t.inside=!1,n.next=n,n.Sym=i,n.Onext=null,n.Lnext=null,n.Org=null,n.Lface=null,n.winding=0,n.activeRegion=null,i.next=i,i.Sym=n,i.Onext=null,i.Lnext=null,i.Org=null,i.Lface=null,i.winding=0,i.activeRegion=null,this.vHead=e,this.fHead=t,this.eHead=n,this.eHeadSym=i}g.prototype={get Rface(){return this.Sym.Lface},set Rface(e){this.Sym.Lface=e},get Dst(){return this.Sym.Org},set Dst(e){this.Sym.Org=e},get Oprev(){return this.Sym.Lnext},set Oprev(e){this.Sym.Lnext=e},get Lprev(){return this.Onext.Sym},set Lprev(e){this.Onext.Sym=e},get Dprev(){return this.Lnext.Sym},set Dprev(e){this.Lnext.Sym=e},get Rprev(){return this.Sym.Onext},set Rprev(e){this.Sym.Onext=e},get Dnext(){return this.Sym.Onext.Sym},set Dnext(e){this.Sym.Onext.Sym=e},get Rnext(){return this.Sym.Lnext.Sym},set Rnext(e){this.Sym.Lnext.Sym=e}},f.prototype={makeEdge_:function(e){var t=new g(0),n=new g(1);e.Sym.side<e.side&&(e=e.Sym);var i=e.Sym.next;return n.next=i,i.Sym.next=t,t.next=e,e.Sym.next=n,t.Sym=n,t.Onext=t,t.Lnext=n,t.Org=null,t.Lface=null,t.winding=0,t.activeRegion=null,n.Sym=t,n.Onext=n,n.Lnext=t,n.Org=null,n.Lface=null,n.winding=0,n.activeRegion=null,t},splice_:function(e,t){var n=e.Onext,i=t.Onext;n.Sym.Lnext=t,i.Sym.Lnext=e,e.Onext=i,t.Onext=n},makeVertex_:function(e,t,n){var i=e;d(null!==i);var r=n.prev;i.prev=r,r.next=i,i.next=n,n.prev=i,i.anEdge=t;var s=t;do{s.Org=i,s=s.Onext}while(s!==t)},makeFace_:function(e,t,n){var i=e;d(null!==i);var r=n.prev;i.prev=r,r.next=i,i.next=n,n.prev=i,i.anEdge=t,i.trail=null,i.marked=!1,i.inside=n.inside;var s=t;do{s.Lface=i,s=s.Lnext}while(s!==t)},killEdge_:function(e){e.Sym.side<e.side&&(e=e.Sym);var t=e.next,n=e.Sym.next;t.Sym.next=n,n.Sym.next=t},killVertex_:function(e,t){var n=e.anEdge,i=n;do{i.Org=t,i=i.Onext}while(i!==n);var r=e.prev,s=e.next;s.prev=r,r.next=s},killFace_:function(e,t){var n=e.anEdge,i=n;do{i.Lface=t,i=i.Lnext}while(i!==n);var r=e.prev,s=e.next;s.prev=r,r.next=s},makeEdge:function(){var e=new u,t=new u,n=new c,i=this.makeEdge_(this.eHead);return this.makeVertex_(e,i,this.vHead),this.makeVertex_(t,i.Sym,this.vHead),this.makeFace_(n,i,this.fHead),i},splice:function(e,t){var n=!1,i=!1;if(e!==t){if(t.Org!==e.Org&&(i=!0,this.killVertex_(t.Org,e.Org)),t.Lface!==e.Lface&&(n=!0,this.killFace_(t.Lface,e.Lface)),this.splice_(t,e),!i){var r=new u;this.makeVertex_(r,t,e.Org),e.Org.anEdge=e}if(!n){var s=new c;this.makeFace_(s,t,e.Lface),e.Lface.anEdge=e}}},delete:function(e){var t=e.Sym,n=!1;if(e.Lface!==e.Rface&&(n=!0,this.killFace_(e.Lface,e.Rface)),e.Onext===e)this.killVertex_(e.Org,null);else if(e.Rface.anEdge=e.Oprev,e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev),!n){var i=new c;this.makeFace_(i,e,e.Lface)}t.Onext===t?(this.killVertex_(t.Org,null),this.killFace_(t.Lface,null)):(e.Lface.anEdge=t.Oprev,t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),this.killEdge_(e)},addEdgeVertex:function(e){var t=this.makeEdge_(e),n=t.Sym;this.splice_(t,e.Lnext),t.Org=e.Dst;var i=new u;return this.makeVertex_(i,n,t.Org),t.Lface=n.Lface=e.Lface,t},splitEdge:function(e,t){var n=this.addEdgeVertex(e).Sym;return this.splice_(e.Sym,e.Sym.Oprev),this.splice_(e.Sym,n),e.Dst=n.Org,n.Dst.anEdge=n.Sym,n.Rface=e.Rface,n.winding=e.winding,n.Sym.winding=e.Sym.winding,n},connect:function(e,t){var n=!1,i=this.makeEdge_(e),r=i.Sym;if(t.Lface!==e.Lface&&(n=!0,this.killFace_(t.Lface,e.Lface)),this.splice_(i,e.Lnext),this.splice_(r,t),i.Org=e.Dst,r.Org=t.Org,i.Lface=r.Lface=e.Lface,e.Lface.anEdge=r,!n){var s=new c;this.makeFace_(s,i,e.Lface)}return i},zapFace:function(e){var t,n,i,r,s,h=e.anEdge;n=h.Lnext;do{n=(t=n).Lnext,t.Lface=null,null===t.Rface&&(t.Onext===t?this.killVertex_(t.Org,null):(t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),(i=t.Sym).Onext===i?this.killVertex_(i.Org,null):(i.Org.anEdge=i.Onext,this.splice_(i,i.Oprev)),this.killEdge_(t))}while(t!=h);r=e.prev,(s=e.next).prev=r,r.next=s},countFaceVerts_:function(e){var t=e.anEdge,n=0;do{n++,t=t.Lnext}while(t!==e.anEdge);return n},mergeConvexFaces:function(e){var t,n,i,r,s;for(t=this.fHead.next;t!==this.fHead;t=t.next)if(t.inside)for(s=(n=t.anEdge).Org;i=n.Lnext,(r=n.Sym)&&r.Lface&&r.Lface.inside&&this.countFaceVerts_(t)+this.countFaceVerts_(r.Lface)-2<=e&&p.vertCCW(n.Lprev.Org,n.Org,r.Lnext.Lnext.Org)&&p.vertCCW(r.Lprev.Org,r.Org,n.Lnext.Lnext.Org)&&(i=r.Lnext,this.delete(r),n=null,r=null),!n||n.Lnext.Org!==s;)n=i;return!0},check:function(){var e,t,n,i,r,s,h=this.fHead,o=this.vHead,a=this.eHead;for(t=h,t=h;(e=t.next)!==h;t=e){d(e.prev===t),r=e.anEdge;do{d(r.Sym!==r),d(r.Sym.Sym===r),d(r.Lnext.Onext.Sym===r),d(r.Onext.Sym.Lnext===r),d(r.Lface===e),r=r.Lnext}while(r!==e.anEdge)}for(d(e.prev===t&&null===e.anEdge),i=o,i=o;(n=i.next)!==o;i=n){d(n.prev===i),r=n.anEdge;do{d(r.Sym!==r),d(r.Sym.Sym===r),d(r.Lnext.Onext.Sym===r),d(r.Onext.Sym.Lnext===r),d(r.Org===n),r=r.Onext}while(r!==n.anEdge)}for(d(n.prev===i&&null===n.anEdge),s=a,s=a;(r=s.next)!==a;s=r)d(r.Sym.next===s.Sym),d(r.Sym!==r),d(r.Sym.Sym===r),d(null!==r.Org),d(null!==r.Dst),d(r.Lnext.Onext.Sym===r),d(r.Onext.Sym.Lnext===r);d(r.Sym.next===s.Sym&&r.Sym===this.eHeadSym&&r.Sym.Sym===r&&null===r.Org&&null===r.Dst&&null===r.Lface&&null===r.Rface)}};var p={};function x(){this.key=null,this.next=null,this.prev=null}function m(e,t){this.head=new x,this.head.next=this.head,this.head.prev=this.head,this.frame=e,this.leq=t}function y(){this.handle=null}function v(){this.key=null,this.node=null}function O(e,t){this.size=0,this.max=e,this.nodes=[],this.nodes.length=e+1;for(var n=0;n<this.nodes.length;n++)this.nodes[n]=new y;this.handles=[],this.handles.length=e+1;for(n=0;n<this.handles.length;n++)this.handles[n]=new v;this.initialized=!1,this.freeList=0,this.leq=t,this.nodes[1].handle=1,this.handles[1].key=null}function L(){this.eUp=null,this.nodeUp=null,this.windingNumber=0,this.inside=!1,this.sentinel=!1,this.dirty=!1,this.fixUpperEdge=!1}p.vertEq=function(e,t){return e.s===t.s&&e.t===t.t},p.vertLeq=function(e,t){return e.s<t.s||e.s===t.s&&e.t<=t.t},p.transLeq=function(e,t){return e.t<t.t||e.t===t.t&&e.s<=t.s},p.edgeGoesLeft=function(e){return p.vertLeq(e.Dst,e.Org)},p.edgeGoesRight=function(e){return p.vertLeq(e.Org,e.Dst)},p.vertL1dist=function(e,t){return Math.abs(e.s-t.s)+Math.abs(e.t-t.t)},p.edgeEval=function(e,t,n){d(p.vertLeq(e,t)&&p.vertLeq(t,n));var i=t.s-e.s,r=n.s-t.s;return i+r>0?i<r?t.t-e.t+(e.t-n.t)*(i/(i+r)):t.t-n.t+(n.t-e.t)*(r/(i+r)):0},p.edgeSign=function(e,t,n){d(p.vertLeq(e,t)&&p.vertLeq(t,n));var i=t.s-e.s,r=n.s-t.s;return i+r>0?(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?i<r?t.s-e.s+(e.s-n.s)*(i/(i+r)):t.s-n.s+(n.s-e.s)*(r/(i+r)):0},p.transSign=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?(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[r[i+1].handle].key,s[r[i].handle].key)&&++i,d(i<=this.max),n=r[i].handle,i>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;r<this.nodes.length;r++)this.nodes[r]=new y;i=this.handles.length,this.handles.length=this.max+1;for(r=i;r<this.handles.length;r++)this.handles[r]=new v}return 0===this.freeList?n=t:(n=this.freeList,this.freeList=this.handles[n].node),this.nodes[t].handle=n,this.handles[n].node=t,this.handles[n].key=e,this.initialized&&this.floatUp_(t),n},extractMin:function(){var e=this.nodes,t=this.handles,n=e[1].handle,i=t[n].key;return this.size>0&&(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])<l[o]&&(l[o]=r,f[o]=t),r>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.s<this.bmin[0]&&(this.bmin[0]=e.s),e.s>this.bmax[0]&&(this.bmax[0]=e.s),e.t<this.bmin[1]&&(this.bmin[1]=e.t),e.t>this.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;a<n;++a)this.elements[f++]=-1;if(t==l.CONNECTED_POLYGONS){h=s.anEdge;do{this.elements[f++]=this.getNeighbourFace_(h),h=h.Lnext}while(h!==s.anEdge);for(a=o;a<n;++a)this.elements[f++]=-1}}},outputContours_:function(e,t){var n,i,r,s=0,h=0;for(this.vertexCount=0,this.elementCount=0,n=e.fHead.next;n!==e.fHead;n=n.next)if(n.inside){r=i=n.anEdge;do{this.vertexCount++,i=i.Lnext}while(i!==r);this.elementCount++}this.elements=[],this.elements.length=2*this.elementCount,this.vertices=[],this.vertices.length=this.vertexCount*t,this.vertexIndices=[],this.vertexIndices.length=this.vertexCount;var o=0,a=0,l=0;for(s=0,n=e.fHead.next;n!==e.fHead;n=n.next)if(n.inside){h=0,r=i=n.anEdge;do{this.vertices[o++]=i.Org.coords[0],this.vertices[o++]=i.Org.coords[1],t>2&&(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;i<t.length;i+=e)null==n?(n=this.mesh.makeEdge(),this.mesh.splice(n,n.Sym)):(this.mesh.splitEdge(n),n=n.Lnext),n.Org.coords[0]=t[i+0],n.Org.coords[1]=t[i+1],n.Org.coords[2]=e>2?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<this.attributes.length;n++){const i=t[this.attributes[n].name];void 0!==i&&e.enableVertexAttribArray(i)}}setVertexAttribPointers(e,t,n){for(let i=0;i<this.attributes.length;i++){const r=this.attributes[i],s=t[r.name];void 0!==s&&e.vertexAttribPointer(s,r.components,e[_[r.type]],!1,this.arrayType.bytesPerElement,r.offset+(this.arrayType.bytesPerElement*n||0))}}destroy(){this.buffer&&this.gl.deleteBuffer(this.buffer)}}w.BufferType={VERTEX:"ARRAY_BUFFER",ELEMENT:"ELEMENT_ARRAY_BUFFER"};const b={Int8:Int8Array,Uint8:Uint8Array,Uint8Clamped:Uint8ClampedArray,Int16:Int16Array,Uint16:Uint16Array,Int32:Int32Array,Uint32:Uint32Array,Float32:Float32Array,Float64:Float64Array};const R={};function D(e,t,n,i){const r=JSON.stringify(e);if(R[r])return R[r];i=void 0===e.alignment?1:e.alignment;let s=0,h=0;const o=["Uint8"],a=e.members.map((e=>{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;t<e.components;t++){const n=e.name+(1===e.components?"":t);Object.defineProperty(d.prototype,n,{get:N(e,t),set:q(e,t)})}class u extends class{constructor(e,t){this.isTransferred=!1,void 0!==e?(this.arrayBuffer=e.arrayBuffer,this.length=e.length,this.capacity=this.arrayBuffer.byteLength/this.bytesPerElement,this._refreshViews()):(this.capacity=-1,this.resize(0))}static serialize(){return{members:this.prototype.members,alignment:this.prototype.StructType.prototype.alignment,bytesPerElement:this.prototype.bytesPerElement}}serialize(e){return this._trim(),e&&(this.isTransferred=!0,e.push(this.arrayBuffer)),{length:this.length,arrayBuffer:this.arrayBuffer}}get(e){return new this.StructType(this,e)}_trim(){this.length!==this.capacity&&(this.capacity=this.length,this.arrayBuffer=this.arrayBuffer.slice(0,this.length*this.bytesPerElement),this._refreshViews())}resize(e){if(this.length=e,e>this.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<t;i++){const e=this.get(i);n.push(e)}return n}}{}return u.prototype.members=a,u.prototype.StructType=d,u.prototype.bytesPerElement=l,u.prototype.emplaceBack=function(e,t){const n=[],i=[];let r="var i = this.length;\nthis.resize(this.length + 1);\n";for(const s of e){const e=A(s.type);n.indexOf(e)<0&&(n.push(e),r+=`var o${e.toFixed(0)} = i * ${(t/e).toFixed(0)};\n`);for(let t=0;t<s.components;t++){const n=`v${i.length}`,h=`o${e.toFixed(0)} + ${(s.offset/e+t).toFixed(0)}`;r+=`this.${k(s.type)}[${h}] = ${n};\n`,i.push(n)}}return r+="return i;",new Function(i.toString(),r)}(a,l),u.prototype._usedTypes=o,R[r]=u,u}function U(e,t){return Math.ceil(e/t)*t}function A(e){return b[e].BYTES_PER_ELEMENT}function k(e){return e.toLowerCase()}function V(e,t){const n=`${`this._pos${A(e.type).toFixed(0)}`} + ${(e.offset/A(e.type)+t).toFixed(0)}`;return`this._structArray.${k(e.type)}[${n}]`}function N(e,t){return new Function(`return ${V(e,t)};`)}function q(e,t){return new Function("x",`${V(e,t)} = x;`)}function B(e){return D({members:[{type:"Uint16",name:"vertices",components:e||3}]})}function I(e){return D({members:e,alignment:4})}const M=I([{name:"a_pos",components:2,type:"Float32"}]),C=B(3),T=B(2);const F=I([{name:"a_pos",components:2,type:"Float32"},{name:"a_data",components:4,type:"Uint8"},{name:"a_txy",components:2,type:"Int16"}]),z=B(3),H=Math.cos(Math.PI/180*37.5),W=Math.pow(2,14)/.5;function G(e,t,n,i,r,s,h){e.emplaceBack(t.x,t.y,Math.round(63*n.x)+128,Math.round(63*n.y)+128,1+(0===s?0:s<0?-1:1)|(.5*h&63)<<2,.5*h>>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;o<n;o++){var a=P(e[2*o],e[2*o+1],e[2*t],e[2*t+1],e[2*n],e[2*n+1]);a>h&&(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;t<n;t++){const n=o(e[t]);0!==n&&(e[t].area=Math.abs(n),s.push(e[t]))}if(s&&r.push(s),t>1)for(let e=0;e<r.length;e++)r[e].length<=t||(i(r[e],t,1,r[e].length-1,a),r[e]=r[e].slice(0,t));return r}(e,1500)){let e=0,i=[];const r=[];for(const e of n){const t=[];if(0===e.length)continue;e!==n[0]&&r.push(t.length/2);const s=this.segments2.prepareSegment(e.length,this.layoutVertexArray2,this.indexArray2),h=s.vertexLength;this.layoutVertexArray2.emplaceBack(e[0].x,e[0].y),this.indexArray2.emplaceBack(h+e.length-1,h),t.push(e[0].x),t.push(e[0].y);for(let n=1;n<e.length;n++)this.layoutVertexArray2.emplaceBack(e[n].x,e[n].y),this.indexArray2.emplaceBack(h+n-1,h+n),t.push(e[n].x),t.push(e[n].y);s.vertexLength+=e.length,s.primitiveLength+=e.length,i.push(t)}var t=l.tesselate({contours:i,windingRule:l.WINDING_ODD,elementType:l.POLYGONS,polySize:3,vertexSize:2});e=t.vertices.length/2;const s=this.segments.prepareSegment(e,this.layoutVertexArray,this.indexArray),h=s.vertexLength;for(let e=0;e<t.vertices.length;e+=2)this.layoutVertexArray.emplaceBack(t.vertices[e],t.vertices[e+1]);const o=t.elements;for(let e=0;e<o.length;e+=3)this.indexArray.emplaceBack(h+o[e],h+o[e+1],h+o[e+2]);s.vertexLength+=e,s.primitiveLength+=o.length/3}}serialize(e){return{type:this.type,style:this.style,tileSize:this.tileSize,layoutVertexArray:this.layoutVertexArray.serialize(e),layoutVertexArray2:this.layoutVertexArray2.serialize(e),indexArray:this.indexArray.serialize(e),indexArray2:this.indexArray2.serialize(e),segments:this.segments,segments2:this.segments2}}static createBuffer(e){e.layoutVertexBuffer=new w(e.layoutVertexArray,M.serialize(),w.BufferType.VERTEX),e.layoutVertexBuffer2=new w(e.layoutVertexArray2,M.serialize(),w.BufferType.VERTEX),e.indexBuffer=new w(e.indexArray,C.serialize(),w.BufferType.ELEMENT),e.indexBuffer2=new w(e.indexArray2,T.serialize(),w.BufferType.ELEMENT)}},e.LineBucket=class extends n{constructor(e){super(e),this.overscaling=this.tileSize/512,this.layoutVertexArray=new F,this.indexArray=new z,this.segments=new t}upload(e){this.uploaded=!0}destroy(){this.segments.destroy()}addFeature(e){const t=this.style.lineCap?this.style.lineCap:"butt";for(const n of e)this.addLine(n,e,"round",t,0,0)}addLine(e,t,n,i,r,s){let h=e.length;for(;h>=2&&e[h-1].equals(e[h-2]);)h--;let o=0;for(;o<h-1&&e[o].equals(e[o+1]);)o++;if(h<2)return;"bevel"===n&&(r=1.05);const a=8192/(512*this.overscaling)*15;e[o];const l=this.segments.prepareSegment(10*h,this.layoutVertexArray,this.indexArray);this.distance=0;const d=i,u=i;let c,g,f,p,x,m,y,v=!0;this.e1=this.e2=this.e3=-1;for(let t=o;t<h;t++){if(f=e[t+1],f&&e[t].equals(f))continue;x&&(p=x),c&&(g=c),c=e[t],x=f?f.sub(c)._unit()._perp():p,p=p||x;let i=p.add(x);0===i.x&&0===i.y||i._unit();const O=i.x*x.x+i.y*x.y,L=0!==O?1/O:1/0,E=O<H&&g&&f;if(E&&t>o){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"===_&&(L<s?_="miter":L<=2&&(_="fakeround")),"miter"===_&&L>r&&(_="bevel"),"bevel"===_&&(L>2&&(_="flipbevel"),L<r&&(_="miter")),g&&(this.distance+=c.dist(g)),"miter"===_)i._mult(L),this.addCurrentVertex(c,this.distance,i,0,0,!1,l);else if("flipbevel"===_){if(L>100)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<t;i++)n=x.mult((i+1)/(t+1))._add(p)._unit(),this.addPieSliceVertex(c,this.distance,n,e,l);this.addPieSliceVertex(c,this.distance,i,e,l);for(let i=t-1;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&&t<h-1){const e=c.dist(f);if(e>2*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;d<l;d++)n=e[2*d],i=e[2*d+1],r=void 0,s=void 0,(r=n-h)*r+(s=i-o)*s>t&&(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)}}));