/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import"../../../core/has.js";import{JSONMap as e}from"../../../core/jsonMap.js";import{isIntegerPixelType as t}from"../formats/pixelRangeUtils.js";import a from"../../support/PixelBlock.js";const n=new e({0:"difference",1:"relative-difference",2:"categorical",3:"euclidean-distance",4:"angle-difference",5:"band-with-most-change"},{useNumericKeys:!0}),s=new e({0:"all",1:"changed",2:"unchanged"},{useNumericKeys:!0});function i(e,n,s,i){const[f,h]=e,p=t(s)&&!t(f.pixelType)&&!t(h.pixelType),m=[f.mask,h.mask].filter(e=>e),u=a.combineBandMasks(m),g=e.map(e=>e.pixels[0]),{width:k,height:x}=f,b=a.createEmptyBand(s,k*x);switch(n){case"difference":case"relative-difference":o({bands:g,mask:u,outBand:b,isRoundingNeeded:p,isRelative:"relative-difference"===n});break;case"categorical":c({bands:g,mask:u,outBand:b,...i});break;case"euclidean-distance":l({pixels:e.map(e=>e.pixels),mask:u,outBand:b});break;case"angle-difference":r({pixels:e.map(e=>e.pixels),mask:u,outBand:b});break;case"band-with-most-change":d({pixels:e.map(e=>e.pixels),mask:u,outBand:b})}const B=new a({width:k,height:x,pixels:[b],pixelType:s,mask:u});return B.updateStatistics(),B}function o(e){const{bands:[t,a],mask:n,isRelative:s,isRoundingNeeded:i,outBand:o}=e,c=t.length;for(let l=0;l<c;l++)if(!n||n[l]){let e=t[l]-a[l];if(s){const n=Math.max(Math.abs(t[l])-Math.abs(a[l]));e=n>0?e/n:0}o[l]=i?Math.round(e):e}}function c(e){const{bands:[t,a],categoryIndexLookups:[n,s],classNames:[i,o],mask:c,keepMethod:l,outBand:r}=e,d=t.length,f=i.length,h=o.length,p=f*h,m=p+1,u=p+2;for(let g=0;g<d;g++)if(!c||c[g]){const e=t[g],c=a[g],d=n[e],f=s[c],k=i[d],x=o[f];r[g]=null==d||null==f?p:"changed"===l&&k===x?m:"unchanged"===l&&k!==x?u:d*h+f}}function l(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let c=0;c<i;c++)if(!n||n[c]){let e=0;for(let n=0;n<o;n++){const s=t[n][c]-a[n][c];e+=s*s}s[c]=Math.sqrt(e)}}function r(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let c=0;c<i;c++)if(!n||n[c]){let e=0,n=0,i=0;for(let s=0;s<o;s++){const o=t[s][c],l=a[s][c];e+=o*l,n+=o*o,i+=l*l}const l=Math.sqrt(n*i);s[c]=l?Math.acos(e/l):1.5707963267948966}}function d(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let c=0;c<i;c++)if(!n||n[c]){let e=0,n=0;for(let s=0;s<o;s++){const i=Math.abs(t[s][c]-a[s][c]);i>e&&(e=i,n=s)}s[c]=n}}export{n as changeMethodMap,i as computeChange,s as keepMethodMap};
