// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/arcade/functions/centroid",["require","exports","../../geometry/Point","../../kernel"],function(u,m,n,t){function q(a,b,e){var c={x:0,y:0};b&&(c.z=0);e&&(c.m=0);for(var k=0,d=a[0],f=0;f<a.length;f++){var g=a[f],h;a:if(g.length!==d.length)h=!1;else{for(h=0;h<g.length;h++)if(g[h]!==d[h]){h=!1;break a}h=!0}if(!1===h){h=r(d,g,b);var l=g,m=b,n=e,p={x:(d[0]+l[0])/2,y:(d[1]+l[1])/2};m&&(p.z=(d[2]+l[2])/2);m&&n?p.m=(d[3]+l[3])/2:n&&(p.m=(d[2]+l[2])/2);d=p;d.x*=h;d.y*=h;c.x+=d.x;c.y+=d.y;b&&(d.z*=
h,c.z+=d.z);e&&(d.m*=h,c.m+=d.m);k+=h;d=g}}0<k?(c.x/=k,c.y/=k,b&&(c.z/=k),e&&(c.m/=k)):(c.x=a[0][0],c.y=a[0][1],b&&(c.z=a[0][2]),e&&b?c.m=a[0][3]:e&&(c.m=a[0][2]));return c}function r(a,b,e){var c=b[0]-a[0];a=b[1]-a[1];return e?(b=b[2]-b[2],Math.sqrt(c*c+a*a+b*b)):Math.sqrt(c*c+a*a)}Object.defineProperty(m,"__esModule",{value:!0});t.version.indexOf("4.");m.centroidPolyline=function(a){for(var b={x:0,y:0,spatialReference:a.spatialReference.toJson()},e={x:0,y:0,spatialReference:a.spatialReference.toJson()},
c=0,k=0,d=0;d<a.paths.length;d++)if(0!==a.paths[d].length){var f;f=a.paths[d];var g=!0===a.hasZ;if(1>=f.length)f=0;else{for(var h=0,l=1;l<f.length;l++)h+=r(f[l-1],f[l],g);f=h}0===f?(g=q(a.paths[d],!0===a.hasZ,!0===a.hasM),b.x+=g.x,b.y+=g.y,!0===a.hasZ&&(b.z+=g.z),!0===a.hasM&&(b.m+=g.m),++c):(g=q(a.paths[d],!0===a.hasZ,!0===a.hasM),e.x+=g.x*f,e.y+=g.y*f,!0===a.hasZ&&(e.z+=g.z*f),!0===a.hasM&&(e.m+=g.m*f),k+=f)}return 0<k?(e.x/=k,e.y/=k,!0===a.hasZ&&(e.z/=k),!0===a.hasM&&(e.m/=k),new n(e)):0<c?(b.x/=
c,b.y/=c,!0===a.hasZ&&(e.z/=c),!0===a.hasM&&(b.m/=c),new n(b)):null};m.centroidMultiPoint=function(a){if(0===a.points.length)return null;for(var b=0,e=0,c=0,k=0,d=0;d<a.points.length;d++){var f=a.getPoint(d);!0===f.hasZ&&(c+=f.z);!0===f.hasM&&(k+=f.m);b+=f.x;e+=f.y;k+=f.m}b={x:b/a.points.length,y:e/a.points.length,spatialReference:null};b.spatialReference=a.spatialReference.toJson();!0===a.hasZ&&(b.z=c/a.points.length);!0===a.hasM&&(b.m=k/a.points.length);return new n(b)}});