/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{G as t,d as e}from"./Geometry.js";import{P as n,K as r}from"./Point2D.js";function a(e,r){if(!e.isEmpty()){switch(e.getGeometryType()){case t.enumPolygon:return o(e);case t.enumPolyline:return l(e);case t.enumLine:case t.enumBezier:case t.enumEllipticArc:return i(e);case t.enumMultiPoint:return g(e);case t.enumEnvelope:return e.getCenterXY();case t.enumPoint:return e.getXY();default:return n.construct(Number.NaN,Number.NaN)}}return n.construct(Number.NaN,Number.NaN)}function u(t,e){return o(t,e)}function o(t,e=-1){const a=new r(0),u=new r(0),o=t.getImpl();let l;const i=o.hasNonLinearSegments();let g;const m=o.getXY(0);if(-1===e){if(g=o.calculateArea2D(),0===g)return d(t);i&&(l=o.querySegmentIterator());for(let t=0,e=o.getPathCount();t<e;t++)s(m,o,t,a,u),i&&c(m,l,a,u)}else{if(g=o.calculateRingArea2D(e),0===g)return d(t,e);i&&(l=o.querySegmentIterator(),l.resetToPath(e)),s(m,o,e,a,u),i&&c(m,l,a,u)}const f=new n,h=new n;return f.setCoords(a.getResult(),u.getResult()),h.assign(f.mul(1/g).add(m)),h}function s(t,e,a,u,o){const s=e.getPathStart(a),c=e.getPathEnd(a);if(c-s<3)return;const l=e.getAttributeStreamRef(0),i=l.readPoint2D(2*s),g=l.readPoint2D(2*(s+1));g.subThis(i);const d=new r(0),m=e.hasNonLinearSegments(),f=1/3,h=new n;for(let n=s+2;n<c;n++){l.queryPoint2D(2*n,h),h.subThis(i);const t=.5*h.crossProduct(g);m&&d.add(t);const e=f*t;u.add((g.x+h.x)*e),o.add((g.y+h.y)*e),g.setCoordsPoint2D(h)}const P=m?d.getResult():e.calculateRingArea2D(a),y=i.sub(t).mul(P);u.add(y.x),o.add(y.y)}function c(t,n,r,a){let u;for(n.nextPath()||e("centroid");null!==(u=n.nextCurve());){const e=u.calculateWeightedAreaCentroid2D(t);r.add(e.x),a.add(e.y)}}function l(t){return m(t.getImpl())}function i(t){const e=t.calculateLength2D();if(0===e)return t.getStartXY();return t.calculateWeightedCentroid2D().mul(1/e)}function g(t){const e=new r(0),a=new r(0),u=t.getImpl(),o=u.getAttributeStreamRef(0),s=u.getPointCount(),c=new n;for(let n=0;n<s;n++)o.queryPoint2D(2*n,c),e.add(c.x),a.add(c.y);const l=new n;return l.setCoords(e.getResult(),a.getResult()),l.divThis(s)}function d(t,e=-1){return m(t.getImpl(),e)}function m(t,e=-1){const a=-1===e?t.calculateLength2D():t.calculatePathLength2D(e);if(0===a)return f(t,e);const u=new r(0),o=new r(0),s=t.querySegmentIterator();for(-1!==e&&s.resetToPath(e);s.nextPath();){const n=s.getPathIndex(),r=t.getXY(t.getPathStart(n));for(;s.hasNextSegment();){const t=s.nextSegment(),e=t.calculateLength2D();if(0===e)continue;const n=t.calculateWeightedCentroid2D().sub(r.mul(e));u.add(n.x),o.add(n.y)}const a=r.mul(t.calculatePathLength2D(n));if(u.add(a.x),o.add(a.y),-1!==e)break}const c=new n;return c.setCoords(u.getResult(),o.getResult()),c.mul(1/a)}function f(t,e=-1){if(-1!==e)return t.getXY(t.getPathStart(e));const a=new r(0),u=new r(0);for(let n=0;n<t.getPathCount();++n){const e=t.getXY(t.getPathStart(n));a.add(e.x),u.add(e.y)}return n.construct(a.getResult(),u.getResult()).mul(1/t.getPathCount())}export{u as a,a as c};
