/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{pt2px as e}from"../../../core/screenUtils.js";import{Seconds as t}from"../../../core/time.js";import{isFlowPathBuffer as n,valuesPerFlowVertex as i}from"../../3d/support/flow/loadUtils.js";function o(e,t){let n=!0;return n=n&&e.collisions===t.collisions,n=n&&e.density===t.density,n=n&&e.interpolate===t.interpolate,n=n&&e.lineCollisionWidth===t.lineCollisionWidth,n=n&&e.lineSpacing===t.lineSpacing,n=n&&e.maxTurnAngle===t.maxTurnAngle,n=n&&e.minSpeedThreshold===t.minSpeedThreshold,n=n&&e.segmentLength===t.segmentLength,n=n&&e.smoothing===t.smoothing,n=n&&e.velocityScale===t.velocityScale,n=n&&e.verticesPerLine===t.verticesPerLine,n=n&&e.onlyForwardTracing===t.onlyForwardTracing,n=n&&e.continuous===t.continuous,n=n&&e.maxNumberOfStreamlines===t.maxNumberOfStreamlines,n=n&&s(e.perturb,t.perturb),n}function s(e,t){return!e&&!t||!(e&&!t||!e&&t)&&(e?.rotation===t?.rotation&&e?.scale===t?.scale)}function r(t){const n=u(m(t)),i=n,o=!0,s=Math.max(n/2,5),r=Math.round(e(t.maxPathLength)/s)+1,a=10,{density:l}=t,c=e(t.smoothing),x="flow-from"===t.flowRepresentation?1:-1,h=.001,p=1,g=!0,d=!1,{continuous:f,perturb:y}=t;return{smoothing:c,interpolate:g,velocityScale:x,verticesPerLine:r,minSpeedThreshold:h,segmentLength:s,maxTurnAngle:p,collisions:o,lineCollisionWidth:i,lineSpacing:a,density:l,onlyForwardTracing:d,continuous:f,perturb:y,wrapAround:!1,maxNumberOfStreamlines:1/0}}function a(e,o,s,r){if(0===e.length)return[];const a=[],m=s.time-o.time,u=n(e),c=u?i(e[0].hasMagnitude):1,x=u?({vertices:e},n)=>{const i=e,o=n*c;return{x:i[o],y:i[o+1],time:t(i[o+2]),speed:0}}:({vertices:e},t)=>e[t];for(const n of e){const{stage:e,vertices:i}=n;if(2===e)continue;const u=i.length/c,h=x(n,0),p=h.time,g=(m*r-p)%(x(n,u-1).time-p)+p;let d=h.x,f=h.y,y=h.time;for(let o=1;o<u&&y<g;o++){const e=x(n,o),i=Math.min(e.time,g)-y,s=e.time-y;d+=(e.x-d)*(i/s),f+=(e.y-f)*(i/s),y=t(y+i)}a.push(l(d,f,o,s))}return a}function l(e,t,n,i){return e/=n.size[0],t=1-(t/=n.size[1]),e*=n.extent.xmax-n.extent.xmin,t*=n.extent.ymax-n.extent.ymin,e+=n.extent.xmin,t+=n.extent.ymin,e-=i.extent.xmin,t-=i.extent.ymin,e/=i.extent.xmax-i.extent.xmin,t=1-(t/=i.extent.ymax-i.extent.ymin),{x:e*=i.size[0],y:t*=i.size[1]}}function m(t){if(!t.hasVisualVariables("size"))return{kind:"constant",value:[e(t.trailWidth)]};const n=t.getVisualVariablesForType("size")[0],i=[],o=[];let s;if(n.stops){for(const t of n.stops)i.push(t.value),o.push(e(t.size));s=n.stops.length}else i.push(n.minDataValue,n.maxDataValue),o.push(e(n.minSize),e(n.maxSize)),s=2;return{kind:"ramp",stops:i,values:o,count:s}}function u(e){return"constant"===e.kind?e.value[0]:e.values[e.values.length-1]}export{s as _perturbEqual,l as changeQuery,r as getFlowSimulationSettings,u as getMax,a as getPositions,m as getSize,o as simulationSettingsEqual};
