/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/maybe"],(function(t,n){"use strict";function e(t,n){return t?n?4:3:n?3:2}function r(t,r,u,l,N){if(n.isNone(r)||!r.lengths.length)return null;const s="upperLeft"===(null==N?void 0:N.originPosition)?-1:1;t.lengths.length&&(t.lengths.length=0),t.coords.length&&(t.coords.length=0);const i=t.coords,c=[],f=u?[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY]:[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY],{lengths:T,coords:g}=r,h=e(u,l);let E=0;for(const n of T){const t=o(f,g,E,n,u,l,s);t&&c.push(t),E+=n*h}if(c.sort(((t,n)=>{let e=s*t[2]-s*n[2];return 0===e&&u&&(e=t[4]-n[4]),e})),c.length){let t=6*c[0][2];i[0]=c[0][0]/t,i[1]=c[0][1]/t,u&&(t=6*c[0][4],i[2]=0!==t?c[0][3]/t:0),(i[0]<f[0]||i[0]>f[1]||i[1]<f[2]||i[1]>f[3]||u&&(i[2]<f[4]||i[2]>f[5]))&&(i.length=0)}if(!i.length){const t=r.lengths[0]?I(g,0,T[0],u,l):null;if(!t)return null;i[0]=t[0],i[1]=t[1],u&&t.length>2&&(i[2]=t[2])}return t}function o(t,n,r,o,I,u,l=1){const N=e(I,u);let s=r,i=r+N,c=0,f=0,T=0,g=0,h=0;for(let e=0,m=o-1;e<m;e++,s+=N,i+=N){const e=n[s],r=n[s+1],o=n[s+2],u=n[i],l=n[i+1],N=n[i+2];let E=e*l-u*r;g+=E,c+=(e+u)*E,f+=(r+l)*E,I&&(E=e*N-u*o,T+=(o+N)*E,h+=E),e<t[0]&&(t[0]=e),e>t[1]&&(t[1]=e),r<t[2]&&(t[2]=r),r>t[3]&&(t[3]=r),I&&(o<t[4]&&(t[4]=o),o>t[5]&&(t[5]=o))}if(g*l>0&&(g*=-1),h*l>0&&(h*=-1),!g)return null;const E=[c,f,.5*g];return I&&(E[3]=T,E[4]=.5*h),E}function I(t,n,r,o,I){const i=e(o,I);let c=n,f=n+i,T=0,g=0,h=0,E=0;for(let e=0,m=r-1;e<m;e++,c+=i,f+=i){const n=t[c],e=t[c+1],r=t[c+2],I=t[f],i=t[f+1],m=t[f+2],b=o?l(n,e,r,I,i,m):u(n,e,I,i);if(b)if(T+=b,o){const t=s(n,e,r,I,i,m);g+=b*t[0],h+=b*t[1],E+=b*t[2]}else{const t=N(n,e,I,i);g+=b*t[0],h+=b*t[1]}}return T>0?o?[g/T,h/T,E/T]:[g/T,h/T]:r>0?o?[t[n],t[n+1],t[n+2]]:[t[n],t[n+1]]:null}function u(t,n,e,r){const o=e-t,I=r-n;return Math.sqrt(o*o+I*I)}function l(t,n,e,r,o,I){const u=r-t,l=o-n,N=I-e;return Math.sqrt(u*u+l*l+N*N)}function N(t,n,e,r){return[t+.5*(e-t),n+.5*(r-n)]}function s(t,n,e,r,o,I){return[t+.5*(r-t),n+.5*(o-n),e+.5*(I-e)]}t.getCentroidOptimizedGeometry=r,t.lineCentroid=I,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
