/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import e from"../../core/Error.js";import t from"../../core/Logger.js";import{isNone as n,isSome as o}from"../../core/maybe.js";import{isPoint as r,isPolygon as s,isPolyline as c,isMultipoint as l}from"../../geometry/support/jsonUtils.js";import{OptimizedFeature as u}from"./OptimizedFeature.js";import i from"./OptimizedFeatureSet.js";import f from"./OptimizedGeometry.js";function h(e,t){return e?t?4:3:t?3:2}const a=t.getLogger("esri.layers.graphics.featureConversionUtils"),g={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0},d=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s},m=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+2]},y=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+3]},p=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+2],e[n+3]=t[o+3]};function I(e,t,n,o){if(e){if(n)return t&&o?p:m;if(t&&o)return y}else if(t&&o)return m;return d}function b({scale:e,translate:t},n){return Math.round((n-t[0])/e[0])}function M({scale:e,translate:t},n){return Math.round((t[1]-n)/e[1])}function w({scale:e,translate:t},n){return n*e[0]+t[0]}function N({scale:e,translate:t},n){return t[1]-n*e[1]}function G(e,t,n){return e?t?n?k(e):P(e):n?Z(e):T(e):null}function T(e){const t=e.coords;return{x:t[0],y:t[1]}}function F(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e}function P(e){const t=e.coords;return{x:t[0],y:t[1],z:t[2]}}function x(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.z,e}function Z(e){const t=e.coords;return{x:t[0],y:t[1],m:t[2]}}function j(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.m,e}function k(e){const t=e.coords;return{x:t[0],y:t[1],z:t[2],m:t[3]}}function E(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.z,e.coords[3]=t.m,e}function z(e,t,n,r){let s=T;n&&r?s=k:n?s=P:r&&(s=Z);for(const c of t){const{geometry:t,attributes:n}=c,r=o(t)?s(t):null;e.push({attributes:n,geometry:r})}return e}function v(e,t){return e&&t?E:e?x:t?j:F}function S(e,t,n,o,r){const s=v(n,o);for(const c of t){const{geometry:t,attributes:n}=c;let o;t&&(o=s(new f,t)),e.push(new u(o,n,null,n[r]))}return e}function V(e,t,n=v(null!=t.z,null!=t.m)){return n(e,t)}function Y(e,t,n,o){for(const r of t){const{geometry:t,attributes:s}=r;let c;t&&(c=_(t,n,o)),e.push({attributes:s,geometry:c})}return e}function _(e,t,o){if(n(e))return null;const r=h(t,o),s=[];for(let n=0;n=i&&(e.lengths.push(t),P=F)}return e.coords.length=P,e.coords.length?e:null}function fe(e,t,n,o,r,s,c=n,l=o){if(e.lengths.length&&(e.lengths.length=0),e.coords.length&&(e.coords.length=0),!t||!t.coords.length)return null;const u=g[r],{coords:i,lengths:f}=t,a=h(n,o),d=h(n&&c,o&&l),m=I(n,o,c,l);if(!f.length)return m(e.coords,i,0,0,i[0],i[1]),e.lengths.length&&(e.lengths.length=0),e.coords.length=a,e;let y=0;const p=s*s;for(const h of f){if(h=u?e.lengths.push(r):e.coords.length=t*d,y+=h*a}return e.coords.length?e:null}function he(e,t,n,o){const r=e[t],s=e[t+1],c=e[n],l=e[n+1],u=e[o],i=e[o+1];let f=c,h=l,a=u-f,g=i-h;if(0!==a||0!==g){const e=((r-f)*a+(s-h)*g)/(a*a+g*g);e>1?(f=u,h=i):e>0&&(f+=a*e,h+=g*e)}return a=r-f,g=s-h,a*a+g*g}function ae(e,t,n,o,r,s,c){let l,u=o,i=0;for(let f=s+n;fu&&(i=f,u=l);u>o&&(i-s>n&&ae(e,t,n,o,r,s,i),r(e,t,e.length,i,t[i],t[i+1]),c-i>n&&ae(e,t,n,o,r,i,c))}function ge(e,t,o,r){if(n(t)||!t.coords||!t.coords.length)return null;const s=h(o,r);let c=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;if(t&&t.coords){const e=t.coords;for(let t=0;t0&&(i=Math.max(i,e)),o<0?u=Math.min(u,t):o>0&&(f=Math.max(f,t))}}return e[0]=l,e[1]=u,e[2]=i,e[3]=f,e}function me(e,t,n,o,r){const{coords:s,lengths:c}=t,l=n?o?p:m:o?m:d,u=h(n,o);if(!s.length)return e!==t&&(e.lengths.length=0,e.coords.length=0),e;if(!c.length)return l(e.coords,s,0,0,w(r,s[0]),N(r,s[1])),e!==t&&(e.lengths.length=0,e.coords.length=u),e;const[i,f]=r.scale;let a=0;for(let h=0;h=0&&s>=0||l<=0&&s<=0:r>=0&&n>=0||r<=0&&n<=0;h&&g?(o+=t,r+=n):(o=t,r=n,a+=i),u(e.coords,c,a,f,o,r),f+=i,l=s}a+=i;const g=(a-m)/i;g>=s&&(e.lengths[d]=g,m=a,d++)}return e.coords.length>m&&(e.coords.length=m),e.lengths.length>d&&(e.lengths.length=d),e.coords.length&&e.lengths.length?e:null}function Ie(e,t,n,o){let r=0,s=e[o*t],c=e[o*(t+1)];for(let l=1;l