/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../core/unitUtils","../core/accessorSupport/decorators/property","../core/arrayUtils","../core/has","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/subclass","./Point","./Polygon","./projectionEllipsoid","./support/geodesicUtils","./support/webMercatorUtils","./support/WKIDUnitConversion"],(function(e,r,t,o,s,i,c,n,a,p,l,u,d,h){"use strict";var g;let f=g=function(r){function o(...e){var t;return(t=r.call(this,...e)||this).center=null,t.geodesic=!1,t.numberOfPoints=60,t.radius=1e3,t.radiusUnit="meters",t}e._inheritsLoose(o,r);var s=o.prototype;return s.normalizeCtorArgs=function(e,t){let o;if(e&&e.center)o=e;else{if(e&&e.rings)return r.prototype.normalizeCtorArgs.call(this,e,t);o={center:e}}return{...r.prototype.normalizeCtorArgs.call(this),...o,...t}},s.initialize=function(){const e=this.center,r=this.numberOfPoints;if(this.hasZ=e&&e.hasZ,0!==this.rings.length||!e)return;const o=t.convertUnit(this.radius,this.radiusUnit,"meters"),s=e.spatialReference;let i,c="geographic";if(s.isWebMercator?c="webMercator":(null!=h[s.wkid]||s.wkt&&0===s.wkt.indexOf("PROJCS"))&&(c="projected"),this.geodesic){let t;switch(c){case"webMercator":t=d.webMercatorToGeographic(e);break;case"projected":console.error("Creating a geodesic circle requires the center to be specified in web mercator or geographic coordinate system");break;case"geographic":t=e}i=this._createGeodesicCircle(t,o,r),"webMercator"===c&&(i=d.geographicToWebMercator(i))}else{let s;"webMercator"===c||"projected"===c?s=o/this._convert2Meters(1,e.spatialReference):"geographic"===c&&(s=t.lengthToDegrees(o,"meters",l.getReferenceEllipsoid(e.spatialReference).radius)),i=this._createPlanarCircle(e,s,r)}this.spatialReference=i.spatialReference,this.addRing(i.rings[0])},s.clone=function(){const{center:e,numberOfPoints:r,radius:t,radiusUnit:o,geodesic:s}=this;return new g({center:e.clone(),numberOfPoints:r,radius:t,radiusUnit:o,geodesic:s})},s._createGeodesicCircle=function(e,r,t){let o=0;const s=[];for(;o<360;){const i=[0,0],c=[e.x,e.y];u.directGeodeticSolver(i,c,o,r),this.hasZ&&i.push(e.z),s.push(i),o+=360/t}return s.push(s[0]),new p(s)},s._createPlanarCircle=function(e,r,t){const o=[],s=2*Math.PI/t;for(let i=0;i<t;++i){const t=s*i,c=[e.x+Math.cos(-t)*r,e.y+Math.sin(-t)*r];this.hasZ&&c.push(e.z),o.push(c)}return o.push(o[0]),new p({spatialReference:e.spatialReference,rings:[o]})},s._convert2Meters=function(e,r){let t;if(null!=h[r.wkid])t=h.values[h[r.wkid]];else{const e=r.wkt,o=e.lastIndexOf(",")+1,s=e.lastIndexOf("]]");t=parseFloat(e.substring(o,s))}return e*t},o}(p);r.__decorate([o.property({type:a})],f.prototype,"center",void 0),r.__decorate([o.property()],f.prototype,"geodesic",void 0),r.__decorate([o.property()],f.prototype,"numberOfPoints",void 0),r.__decorate([o.property()],f.prototype,"radius",void 0),r.__decorate([o.property()],f.prototype,"radiusUnit",void 0),f=g=r.__decorate([n.subclass("esri.geometry.Circle")],f);return f}));
