text: // COPYRIGHT © 2021 Esri
  //
  // All rights reserved under the copyright laws of the United States
  // and applicable international laws, treaties, and conventions.
  //
  // This material is licensed for use under the Esri Master License
  // Agreement (MLA), and is bound by the terms of that agreement.
  // You may redistribute and use this code without modification,
  // provided you adhere to the terms of the MLA and include this
  // copyright notice.
  //
  // See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
  //
  // For additional information, contact:
  // Environmental Systems Research Institute, Inc.
  // Attn: Contracts and Legal Services Department
  // 380 New York Street
  // Redlands, California, USA 92373
  // USA
  //
  // email: contracts@esri.com
  //
  // See http://js.arcgis.com/3.37/esri/copyright.txt for details.
  
  define(["require","exports","../core/tsSupport/declareExtendsHelper","../core/tsSupport/decorateHelper","../core/lang","../core/accessorSupport/decorators","./Extent","./Geometry","./Point","./SpatialReference","./support/centroid","./support/contains","./support/coordsUtils","./support/intersects","./support/webMercatorUtils","./support/zmUtils"],(function(e,t,r,n,i,s,a,o,p,l,c,h,u,f,y,m){function g(e){return function(t,r){return null==t?r:null==r?t:e(t,r)}}var v=g(Math.min),d=g(Math.max);function x(e){return!Array.isArray(e[0])}var R=function(e){function t(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=e.call(this)||this;return n.rings=[],n.type="polygon",n}return r(t,e),o=t,t.createEllipse=function(e){for(var t=e.center.x,r=e.center.y,n=e.center.z,i=e.center.m,s=e.center.hasZ,a=e.center.hasM,p=e.longAxis,l=e.shortAxis,c=e.numberOfPoints,h=e.view,u=[],f=2*Math.PI/c,y=s?3:2,m=0;m<c;m++){var g=Math.cos(m*f),v=Math.sin(m*f),d=h.toMap(p*g+t,l*v+r),x=[d.x,d.y];s&&(x[2]=n),a&&(x[y]=i),u.push(x)}u.push(u[0]);var R={rings:[u],spatialReference:h.spatialReference};return new o(R)},t.createCircle=function(e){return o.createEllipse({center:e.center,longAxis:e.r,shortAxis:e.r,numberOfPoints:e.numberOfPoints,view:e.view})},t.fromExtent=function(e){var t=e.clone().normalize(),r=e.spatialReference,n=!1,i=!1;t.map((function(e){e.hasZ&&(n=!0),e.hasM&&(i=!0)}));var s={rings:t.map((function(e){var t=[[e.xmin,e.ymin],[e.xmin,e.ymax],[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin]];if(n&&e.hasZ)for(var r=e.zmin+.5*(e.zmax-e.zmin),s=0;s<t.length;s++)t[s].push(r);if(i&&e.hasM){var a=e.mmin+.5*(e.mmax-e.mmin);for(s=0;s<t.length;s++)t[s].push(a)}return t})),spatialReference:r};return n&&(s.hasZ=!0),i&&(s.hasM=!0),new o(s)},t.prototype.normalizeCtorArgs=function(e,t){var r,n,i,s=null;return e&&!Array.isArray(e)?(s=e.rings?e.rings:null,t||(e.spatialReference?t=e.spatialReference:e.rings||(t=e)),r=e.hasZ,n=e.hasM):s=e,s=s||[],t=t||l.WGS84,s.length&&s[0]&&null!=s[0][0]&&"number"==typeof s[0][0]&&(s=[s]),(i=s[0]&&s[0][0])&&(void 0===r&&void 0===n?(r=i.length>2,n=!1):void 0===r?r=!n&&i.length>3:void 0===n&&(n=!r&&i.length>3)),{rings:s,spatialReference:t,hasZ:r,hasM:n}},Object.defineProperty(t.prototype,"centroid",{get:function(){var e=c.polygonCentroid(this);if(!e||isNaN(e[0])||isNaN(e[1])||this.hasZ&&isNaN(e[2]))return null;var t=new p;return t.x=e[0],t.y=e[1],t.spatialReference=this.spatialReference,this.hasZ&&(t.z=e[2]),t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"extent",{get:function(){var e=this.hasZ,t=this.hasM,r=this.spatialReference,n=this.rings,i=e?3:2;if(!n.length||!n[0].length)return null;for(var s=n[0][0],o=s[0],p=s[1],l=n[0][0],c=l[0],h=l[1],u=void 0,f=void 0,y=void 0,m=void 0,g=[],x=0;x<n.length;x++){for(var R=n[x],w=R[0],M=w[0],P=w[1],b=R[0],A=b[0],O=b[1],Z=void 0,z=void 0,S=void 0,C=void 0,I=0;I<R.length;I++){var N=R[I],_=N[0],j=N[1];if(o=v(o,_),p=v(p,j),c=d(c,_),h=d(h,j),M=v(M,_),P=v(P,j),A=d(A,_),O=d(O,j),e&&N.length>2){var E=N[2];u=v(u,E),f=d(f,E),Z=v(Z,E),z=d(z,E)}if(t&&N.length>i){var J=N[i];y=v(u,J),m=d(f,J),S=v(Z,J),C=d(z,J)}}g.push(new a({xmin:M,ymin:P,zmin:Z,mmin:S,xmax:A,ymax:O,zmax:z,mmax:C,spatialReference:r}))}var U=new a;return U.xmin=o,U.ymin=p,U.xmax=c,U.ymax=h,U.spatialReference=r,e&&(U.zmin=u,U.zmax=f),t&&(U.mmin=y,U.mmax=m),U.cache._partwise=g.length>1?g:null,U},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSelfIntersecting",{get:function(){return f.isSelfIntersecting(this.rings)},enumerable:!0,configurable:!0}),t.prototype.writePaths=function(e,t,r,n){t.rings=i.clone(this.rings)},t.prototype.addRing=function(e){if(e){this.clearCache();var t=this.rings,r=t.length;if(x(e)){for(var n=[],i=0,s=e.length;i<s;i++)n[i]=e[i].toArray();t[r]=n}else t[r]=e.concat();return this}},t.prototype.clone=function(){var e=new o;return e.spatialReference=this.spatialReference,e.rings=i.clone(this.rings),e.hasZ=this.hasZ,e.hasM=this.hasM,e},t.prototype.contains=function(e){return!!e&&(y.canProject(e,this.spatialReference)&&(e=y.project(e,this.spatialReference)),h.polygonContainsPoint(this,e))},t.prototype.isClockwise=function(e){var t,r=this;return t=x(e)?e.map((function(e){return r.hasZ?r.hasM?[e.x,e.y,e.z,e.m]:[e.x,e.y,e.z]:[e.x,e.y]})):e,u.isClockwise(t,this.hasM,this.hasZ)},t.prototype.getPoint=function(e,t){if(!this._validateInputs(e,t))return null;var r=this.rings[e][t],n=this.hasZ,i=this.hasM;return n&&!i?new p(r[0],r[1],r[2],void 0,this.spatialReference):i&&!n?new p(r[0],r[1],void 0,r[2],this.spatialReference):n&&i?new p(r[0],r[1],r[2],r[3],this.spatialReference):new p(r[0],r[1],this.spatialReference)},t.prototype.insertPoint=function(e,t,r){return this._validateInputs(e,t,!0)?(this.clearCache(),m.updateSupportFromPoint(this,r),Array.isArray(r)||(r=r.toArray()),this.rings[e].splice(t,0,r),this):this},t.prototype.removePoint=function(e,t){return this._validateInputs(e,t)?(this.clearCache(),new p(this.rings[e].splice(t,1)[0],this.spatialReference)):null},t.prototype.removeRing=function(e){if(!this._validateInputs(e,null))return null;this.clearCache();var t=this.rings.splice(e,1)[0],r=this.spatialReference;return t.map((function(e){return new p(e,r)}))},t.prototype.setPoint=function(e,t,r){return this._validateInputs(e,t)?(this.clearCache(),m.updateSupportFromPoint(this,r),Array.isArray(r)||(r=r.toArray()),this.rings[e][t]=r,this):this},t.prototype._validateInputs=function(e,t,r){if(void 0===r&&(r=!1),null==e||e<0||e>=this.rings.length)return!1;if(null!=t){var n=this.rings[e];if(r&&(t<0||t>n.length))return!1;if(!r&&(t<0||t>=n.length))return!1}return!0},t.prototype.toJSON=function(e){return this.write(null,e)},n([s.property({dependsOn:["hasM","hasZ","rings"]})],t.prototype,"cache",void 0),n([s.property({readOnly:!0,dependsOn:["cache"]})],t.prototype,"centroid",null),n([s.property({dependsOn:["cache"],readOnly:!0})],t.prototype,"extent",null),n([s.property({dependsOn:["cache"],readOnly:!0})],t.prototype,"isSelfIntersecting",null),n([s.property({type:[[[Number]]],json:{write:{isRequired:!0}}})],t.prototype,"rings",void 0),n([s.writer("rings")],t.prototype,"writePaths",null),t=o=n([s.subclass("esri.geometry.Polygon")],t);var o}(s.declared(o));return R.prototype.toJSON.isDefaultToJSON=!0,R}));