/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{getPathLength as t,getLength as n}from"../../geometry/support/coordsUtils.js";import{getPolygonExtent as e}from"../../geometry/support/extentUtils.js";function o(t,e=!1){let o=[];if(e){for(const n of t)if(n.geometry){const t=n.geometry;o.push.apply(o,t.points)}}else o=t.map(t=>t.geometry);const s=[],i=[];let l=1/0,r=-1/0,a=0,c=0,f=0,u=0;for(const m of o){if(!m)continue;e?(s[0]=m[0],s[1]=m[1]):(s[0]=m.x,s[1]=m.y);let t=1/0,p=-1/0;for(const a of o){if(a===m)continue;if(!a)continue;e?(i[0]=a[0],i[1]=a[1]):(i[0]=a.x,i[1]=a.y);const o=n(s,i);o>0&&(o<t&&(t=o),o<l&&(l=o),o>p&&(p=o),o>r&&(r=o))}t!==1/0&&(++f,a+=t),p!==-1/0&&(++u,c+=p)}return{minDistance:l!==1/0?l:null,maxDistance:r!==-1/0?r:null,avgMinDistance:f?a/f:null,avgMaxDistance:u?c/u:null}}function s(n){let e=0,o=0,s=1/0,i=-1/0;for(const l of n){const n=l.geometry;if(n){let l=0;for(const e of n.paths){const n=t(e);n>0&&(l+=n)}l>0&&(++e,o+=l,l<s&&(s=l),l>i&&(i=l))}}return{minLength:s!==1/0?s:null,maxLength:i!==-1/0?i:null,avgLength:e?o/e:null}}function i(t){let n=0,o=0,s=1/0,i=-1/0;for(const l of t){const t=l.geometry;if(t){const l=e(t);if(l){const t=Math.abs(l.xmax-l.xmin),e=Math.abs(l.ymax-l.ymin),r=Math.sqrt(t*e);r>0&&(++n,o+=r,r<s&&(s=r),r>i&&(i=r))}}}return{minSize:s!==1/0?s:null,maxSize:i!==-1/0?i:null,avgSize:n?o/n:null}}function l(t){const{features:n}=t;let e=null;switch(t.geometryType){case"point":e=o(n);break;case"multipoint":e=o(n,!0);break;case"polyline":e=s(n);break;case"polygon":e=i(n)}return Promise.resolve(e)}export{l as default};
