import{cl as xt,t as Y,k as Mt,a as ft,s as yt,h as z,l as kt,b7 as ut,ap as At,cA as bt,dj as It}from"./index.a33cbbbf.js";import{r as at,g as tt}from"./pixelUtils.e4fffbea.js";const W=new Map;W.set("meter-per-second",1),W.set("kilometer-per-hour",.277778),W.set("knots",.514444),W.set("feet-per-second",.3048),W.set("mile-per-hour",.44704);const ot=180/Math.PI,it=5,et=new xt({esriMetersPerSecond:"meter-per-second",esriKilometersPerHour:"kilometer-per-hour",esriKnots:"knots",esriFeetPerSecond:"feet-per-second",esriMilesPerHour:"mile-per-hour"});function st(t,n){return W.get(t)/W.get(n)||1}function dt(t){return(450-t)%360}function mt(t,n="geographic"){const[o,c]=t,i=Math.sqrt(o*o+c*c);let a=Math.atan2(c,o)*ot;return a=(360+a)%360,n==="geographic"&&(a=dt(a)),[i,a]}function pt(t,n="geographic"){let o=t[1];n==="geographic"&&(o=dt(o)),o%=360;const c=t[0];return[c*Math.cos(o/ot),c*Math.sin(o/ot)]}function Ct(t,n,o,c="geographic"){if(!at(t)||Y(o))return t;const i=n==="vector-magdir"?t.clone():Mt(lt(t,n)),a=i.pixels[1];for(let d=0;d0){const[X,G]=T(y,b,n,l),[Q,L]=T(k,I,n,l);F.push(X),F.push(G),F.push(H),F.push(Z),F.push(Q),F.push(L)}else{const[X,G]=T(y,w,n,l),[Q,L]=T(x,f,n,l),[O,nt]=T(M,P,n,l);_.push(H),_.push(Z),_.push(O),_.push(nt),_.push(Q),_.push(L),_.push(X),_.push(G)}b+=a,I+=a,w+=a,f+=a,P+=a}const[N,S]=T(e+A,r+d,n,l),D=(c/2+s)*g,[V,q]=T(e+D,r+d,n,l),[j,J]=T(e+A,r-h,n,l),[B,E]=T(e+D,r-h,n,l);return{pennants:F,barbs:_,shaft:[N,S,V,q,j,J,B,E]}}function T(t,n,o,c=1){const i=Math.sqrt(t*t+n*n)/c,a=(2*Math.PI+Math.atan2(n,t))%(2*Math.PI);return[i,(2*Math.PI+a-o)%(2*Math.PI)]}const $=[0,1,3,6,10,16,21,27,33,40,47,55,63],Dt=[0,.5,1,1.5,2],Ft=[0,.25,.5,1,1.5,2,2.5,3,3.5,4];function K(t,n,o,c){const i=st(c||"knots",o);let a;for(a=1;af>0).length:m*u,y=new Float32Array(I*l),w=new Uint32Array(e*I),x=n.invertDirection?gt(0,0,0,!1):vt;for(let f=0;f=it){const I=(h[A]+360)%360/180*Math.PI,{pennants:y,barbs:w,shaft:x}=rt[Math.min(Math.floor(k/5),29)];if(y.length+w.length===0)continue;let f=e.length/l;const p=(g+.5)/c,b=(u+.5)/i;for(let M=0;M=(v-M)*(U-P)*(1-i)){I[b]=1;const[F,_]=mt([A[b]/p,k[b]/p]);A[b]=F,k[b]=_}else I[b]=0,A[b]=0,k[b]=0}const w=new tt({width:m,height:u,pixels:[A,k],mask:I});return w.updateStatistics(),w}const R=yt.getLogger("esri.views.2d.engine.flow.dataUtils"),qt=10;async function Xt(t,n,o,c){const i=performance.now(),a=Lt(n,o),d=performance.now(),h=Tt(n,a,o.width,o.height),l=performance.now(),e=Bt(h,!0),r=performance.now(),s=t==="Streamlines"?jt(e,qt):Rt(e),m=performance.now();return z("esri-2d-profiler")&&(R.info("I.1","_createFlowFieldFromData (ms)",Math.round(d-i)),R.info("I.2","_getStreamlines (ms)",Math.round(l-d)),R.info("I.3","createAnimatedLinesData (ms)",Math.round(r-l)),R.info("I.4","create{Streamlines|Particles}Mesh (ms)",Math.round(m-r)),R.info("I.5","createFlowMesh (ms)",Math.round(m-i)),R.info("I.6","Mesh size (bytes)",s.vertexData.buffer.byteLength+s.indexData.buffer.byteLength)),await Promise.resolve(),kt(c),s}function Lt(t,n){const o=Nt(n.data,n.width,n.height,t.smoothing);return t.interpolate?(c,i)=>{const a=Math.floor(c),d=Math.floor(i);if(a<0||a>=n.width)return[0,0];if(d<0||d>=n.height)return[0,0];const h=c-a,l=i-d,e=a,r=d,s=a{const a=Math.round(c),d=Math.round(i);return a<0||a>=n.width||d<0||d>=n.height?[0,0]:[o[2*(d*n.width+a)+0],o[2*(d*n.width+a)+1]]}}function Ot(t,n,o,c,i,a,d,h,l){const e=[];let r=o,s=c,m=0,[u,g]=n(r,s);u*=t.velocityScale,g*=t.velocityScale;const A=Math.sqrt(u*u+g*g);let k,I;e.push({x:r,y:s,t:m,speed:A});for(let y=0;yt.maxTurnAngle)return e;if(t.collisions){const M=Math.round(r*l),P=Math.round(s*l);if(M<0||M>d-1||P<0||P>h-1)return e;const v=a[P*d+M];if(v!==-1&&v!==i)return e;a[P*d+M]=i}e.push({x:r,y:s,t:m,speed:f}),k=p,I=b}return e}function Tt(t,n,o,c){const i=[],a=new ut,d=1/Math.max(t.lineCollisionWidth,1),h=Math.round(o*d),l=Math.round(c*d),e=new Int32Array(h*l);for(let s=0;ss.sort-m.sort);for(const{x:s,y:m}of r)if(a.getFloat()=n)continue;const g=a[u+i];s+=g*t[2*(e*n+(r+u))+0],m+=g*t[2*(e*n+(r+u))+1]}h[2*(e*n+r)+0]=s,h[2*(e*n+r)+1]=m}const l=new Float32Array(t.length);for(let e=0;e=o)continue;const g=a[u+i];s+=g*h[2*((r+u)*n+e)+0],m+=g*h[2*((r+u)*n+e)+1]}l[2*(r*n+e)+0]=s,l[2*(r*n+e)+1]=m}return l}function Bt(t,n){const o=new ut,c=t.reduce((l,e)=>l+e.length,0),i=new Float32Array(4*c),a=new Array(t.length);let d=0,h=0;for(const l of t){const e=d;for(const r of l)i[4*d+0]=r.x,i[4*d+1]=r.y,i[4*d+2]=r.t,i[4*d+3]=r.speed,d++;a[h++]={startVertex:e,numberOfVertices:l.length,totalTime:l[l.length-1].t,timeSeed:n?o.getFloat():0}}return{lineVertices:i,lineDescriptors:a}}function jt(t,n){const{lineVertices:c,lineDescriptors:i}=t;let a=0,d=0;for(const u of i)a+=2*u.numberOfVertices,d+=6*(u.numberOfVertices-1);const h=new Float32Array(a*9),l=new Uint32Array(d);let e=0,r=0;function s(){l[r++]=e-2,l[r++]=e,l[r++]=e-1,l[r++]=e,l[r++]=e+1,l[r++]=e-1}function m(u,g,A,k,I,y,w,x){const f=e*9;let p=0;h[f+p++]=u,h[f+p++]=g,h[f+p++]=1,h[f+p++]=A,h[f+p++]=y,h[f+p++]=w,h[f+p++]=k/2,h[f+p++]=I/2,h[f+p++]=x,e++,h[f+p++]=u,h[f+p++]=g,h[f+p++]=-1,h[f+p++]=A,h[f+p++]=y,h[f+p++]=w,h[f+p++]=-k/2,h[f+p++]=-I/2,h[f+p++]=x,e++}for(const u of i){const{totalTime:g,timeSeed:A}=u;let k=null,I=null,y=null,w=null,x=null,f=null;for(let p=0;p0){U=b-k,F=M-I;const S=Math.sqrt(U*U+F*F);if(U/=S,F/=S,p>1){let D=U+x,V=F+f;const q=Math.sqrt(D*D+V*V);D/=q,V/=q;const j=Math.min(1/(D*U+V*F),n);D*=j,V*=j,_=-V,N=D}else _=-F,N=U;_!==null&&N!==null&&(m(k,I,y,_,N,g,A,v),s())}k=b,I=M,y=P,x=U,f=F,w=v}m(k,I,y,-f,x,g,A,w)}return{vertexData:h,indexData:l}}function Rt(t){const{lineVertices:i,lineDescriptors:a}=t;let d=0,h=0;for(const S of a){const D=S.numberOfVertices-1;d+=4*D*2,h+=6*D*2}const l=new Float32Array(d*16),e=new Uint32Array(h);let r,s,m,u,g,A,k,I,y,w,x,f,p,b,M=0,P=0;function v(){e[P++]=M-8,e[P++]=M-7,e[P++]=M-6,e[P++]=M-7,e[P++]=M-5,e[P++]=M-6,e[P++]=M-4,e[P++]=M-3,e[P++]=M-2,e[P++]=M-3,e[P++]=M-1,e[P++]=M-2}function U(S,D,V,q,j,J,B,E,C,H,Z,X,G,Q){const L=M*16;let O=0;for(const nt of[1,2])for(const wt of[1,2,3,4])l[L+O++]=S,l[L+O++]=D,l[L+O++]=V,l[L+O++]=q,l[L+O++]=B,l[L+O++]=E,l[L+O++]=C,l[L+O++]=H,l[L+O++]=nt,l[L+O++]=wt,l[L+O++]=G,l[L+O++]=Q,l[L+O++]=j/2,l[L+O++]=J/2,l[L+O++]=Z/2,l[L+O++]=X/2,M++}function F(S,D){let V=y+x,q=w+f;const j=Math.sqrt(V*V+q*q);V/=j,q/=j;const J=y*V+w*q;V/=J,q/=J;let B=x+p,E=f+b;const C=Math.sqrt(B*B+E*E);B/=C,E/=C;const H=x*B+f*E;B/=H,E/=H,U(r,s,m,u,-q,V,g,A,k,I,-E,B,S,D),v()}function _(S,D,V,q,j,J){if(y=x,w=f,x=p,f=b,y==null&&w==null&&(y=x,w=f),g!=null&&A!=null){p=S-g,b=D-A;const B=Math.sqrt(p*p+b*b);p/=B,b/=B}y!=null&&w!=null&&F(j,J),r=g,s=A,m=k,u=I,g=S,A=D,k=V,I=q}function N(S,D){y=x,w=f,x=p,f=b,y==null&&w==null&&(y=x,w=f),y!=null&&w!=null&&F(S,D)}for(const S of a){r=null,s=null,m=null,u=null,g=null,A=null,k=null,I=null,y=null,w=null,x=null,f=null,p=null,b=null;const{totalTime:D,timeSeed:V}=S;for(let q=0;q=o||(y.data[2*(f*o+w+p)+0]=x.data[2*(f*x.width+p)+0],y.data[2*(f*o+w+p)+1]=x.data[2*(f*x.width+p)+1],y.mask[f*o+w+p]=x.mask[f*x.width+p]);w+=x.width}return z("esri-2d-profiler")&&R.info("I.10","loadImagery, general exit (ms)",Math.round(performance.now()-d)),y}async function ht(t,n,o,c,i,a){const d={requestProjectedLocalDirections:!0,signal:a};if(ft(i)&&(d.timeExtent=i),t.type==="imagery"){await t.load({signal:a});const e=t.rasterInfo.dataType,r=await t.fetchImage(n,o,c,d);return!r||Y(r.pixelData)||Y(r.pixelData.pixelBlock)?{data:new Float32Array(o*c*2),mask:new Uint8Array(o*c),width:o,height:c}:ct(e,r.pixelData.pixelBlock)}await t.load({signal:a});const h=t.rasterInfo.dataType,l=await t.fetchPixels(n,o,c,d);return!l||Y(l.pixelBlock)?{data:new Float32Array(o*c*2),mask:new Uint8Array(o*c),width:o,height:c}:ct(h,l.pixelBlock)}export{_t as D,Wt as F,Gt as a,mt as b,et as c,lt as d,Xt as f,Ht as g,zt as j,st as l,Ct as m,Kt as x};