UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 4.58 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import has from"../../../../core/has.js";import t from"../../../../core/Logger.js";import{throwIfAborted as n}from"../../../../core/promiseUtils.js";import{serializeFlowPaths as e}from"./flowPathsIO.js";import{createFlowFieldFromData as r,traceFlowPaths as o}from"../../../support/flow/dataUtils.js";const l=()=>t.getLogger("esri.views.2d.engine.flow.dataUtils"),s=10;async function i(t,e,i,a,u){const p=performance.now(),w=c(r(e,i),e),V=performance.now(),d=o(e,w,i.width,i.height,a),x=performance.now(),M=f(d),g=performance.now(),D="Streamlines"===t?m(M,s,d):h(M,d),b=performance.now();return has("esri-2d-profiler")&&(l().info("I.1","_createFlowFieldFromData (ms)",Math.round(V-p)),l().info("I.2","_getStreamlines (ms)",Math.round(x-V)),l().info("I.3","createAnimatedLinesData (ms)",Math.round(g-x)),l().info("I.4","create{Streamlines|Particles}Mesh (ms)",Math.round(b-g)),l().info("I.5","createFlowMesh (ms)",Math.round(b-p)),l().info("I.6","Mesh size (bytes)",D.vertexData.buffer.byteLength+D.indexData.buffer.byteLength)),await Promise.resolve(),n(u),D}function c(t,n){const{perturb:e}=n;if(e){const{rotation:n}=e;null!=n&&(t=a(t,n));const{scale:r}=e;null!=r&&(t=u(t,r))}return t}function a(t,n){const e=Math.cos(n),r=Math.sin(n);return(n,o)=>{const[l,s]=t(n,o);return[e*l+r*s,-r*l+e*s]}}function u(t,n){return(e,r)=>{const[o,l]=t(e,r);return[o*n,l*n]}}function f(t){const n=t.reduce((t,n)=>t+n.vertices.length,0),e=new Float32Array(4*n),r=new Array(t.length);let o=0,l=0;for(const{vertices:s}of t){const t=o;for(const n of s)e[4*o]=n.x,e[4*o+1]=n.y,e[4*o+2]=n.time,e[4*o+3]=n.speed,o++;r[l++]={startVertex:t,numberOfVertices:s.length,firstTime:s[0].time,lastTime:s[s.length-1].time}}return{lineVertices:e,lineDescriptors:r}}function m(t,n,r){const o=9,{lineVertices:l,lineDescriptors:s}=t;let i=0,c=0;for(const e of s){i+=2*e.numberOfVertices;c+=6*(e.numberOfVertices-1)}const a=new Float32Array(i*o),u=new Uint32Array(c);let f=0,m=0;function h(){u[m++]=f-2,u[m++]=f,u[m++]=f-1,u[m++]=f,u[m++]=f+1,u[m++]=f-1}function p(t,n,e,r,l,s,i,c){const u=f*o;let m=0;a[u+m++]=t,a[u+m++]=n,a[u+m++]=1,a[u+m++]=e,a[u+m++]=s,a[u+m++]=i,a[u+m++]=r/2,a[u+m++]=l/2,a[u+m++]=c,f++,a[u+m++]=t,a[u+m++]=n,a[u+m++]=-1,a[u+m++]=e,a[u+m++]=s,a[u+m++]=i,a[u+m++]=-r/2,a[u+m++]=-l/2,a[u+m++]=c,f++}for(const e of s){const{firstTime:t,lastTime:r}=e;let o=null,s=null,i=null,c=null,a=null,u=null;for(let f=0;f<e.numberOfVertices;f++){const m=l[4*(e.startVertex+f)],w=l[4*(e.startVertex+f)+1],V=l[4*(e.startVertex+f)+2],d=l[4*(e.startVertex+f)+3];let x=null,M=null,g=null,D=null;if(f>0){x=m-o,M=w-s;const e=Math.sqrt(x*x+M*M);if(x/=e,M/=e,f>1){let t=x+a,e=M+u;const r=Math.sqrt(t*t+e*e);t/=r,e/=r;const o=Math.min(1/(t*x+e*M),n);t*=o,e*=o,g=-e,D=t}else g=-M,D=x;null!==g&&null!==D&&(p(o,s,i,g,D,t,r,d),h())}o=m,s=w,i=V,a=x,u=M,c=d}p(o,s,i,-u,a,t,r,c)}const w=e(r);return{vertexData:a,indexData:u,pathData:w}}function h(t,n){const r=16,o=1,l=2,{lineVertices:s,lineDescriptors:i}=t;let c=0,a=0;for(const e of i){const t=e.numberOfVertices-1;c+=4*t*2,a+=6*t*2}const u=new Float32Array(c*r),f=new Uint32Array(a);let m,h,p,w,V,d,x,M,g,D,b,y,v,A,F=0,I=0;function O(){f[I++]=F-8,f[I++]=F-7,f[I++]=F-6,f[I++]=F-7,f[I++]=F-5,f[I++]=F-6,f[I++]=F-4,f[I++]=F-3,f[I++]=F-2,f[I++]=F-3,f[I++]=F-1,f[I++]=F-2}function T(t,n,e,s,i,c,a,f,m,h,p,w,V,d){const x=F*r;let M=0;for(const r of[o,l])for(const o of[1,2,3,4])u[x+M++]=t,u[x+M++]=n,u[x+M++]=e,u[x+M++]=s,u[x+M++]=a,u[x+M++]=f,u[x+M++]=m,u[x+M++]=h,u[x+M++]=r,u[x+M++]=o,u[x+M++]=V,u[x+M++]=d,u[x+M++]=i/2,u[x+M++]=c/2,u[x+M++]=p/2,u[x+M++]=w/2,F++}function j(t,n){let e=g+b,r=D+y;const o=Math.sqrt(e*e+r*r);e/=o,r/=o;const l=g*e+D*r;e/=l,r/=l;let s=b+v,i=y+A;const c=Math.sqrt(s*s+i*i);s/=c,i/=c;const a=b*s+y*i;s/=a,i/=a,T(m,h,p,w,-r,e,V,d,x,M,-i,s,t,n),O()}function q(t,n,e,r,o,l){if(g=b,D=y,b=v,y=A,null==g&&null==D&&(g=b,D=y),null!=V&&null!=d){v=t-V,A=n-d;const e=Math.sqrt(v*v+A*A);v/=e,A/=e}null!=g&&null!=D&&j(o,l),m=V,h=d,p=x,w=M,V=t,d=n,x=e,M=r}function L(t,n){g=b,D=y,b=v,y=A,null==g&&null==D&&(g=b,D=y),null!=g&&null!=D&&j(t,n)}for(const e of i){m=null,h=null,p=null,w=null,V=null,d=null,x=null,M=null,g=null,D=null,b=null,y=null,v=null,A=null;const{firstTime:t,lastTime:n}=e;for(let r=0;r<e.numberOfVertices;r++){q(s[4*(e.startVertex+r)],s[4*(e.startVertex+r)+1],s[4*(e.startVertex+r)+2],s[4*(e.startVertex+r)+3],t,n)}L(t,n)}const U=e(n);return{vertexData:u,indexData:f,pathData:U}}export{f as createAnimatedLinesData,i as createFlowMesh,h as createParticlesMesh,m as createStreamlinesMesh};