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