/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{convertUnit as r,isProjectedWKT as t,getMetersPerUnit as s,lengthToDegrees as i}from"../core/units.js";import{property as o,subclass as c}from"../core/accessorSupport/decorators.js";import{ensureType as n}from"../core/accessorSupport/ensureType.js";import{getReferenceEllipsoid as a}from"./ellipsoidUtils.js";import{directGeodeticSolver as p}from"./geodesicUtils.js";import l from"./Point.js";import u from"./Polygon.js";import h from"./SpatialReference.js";import{webMercatorToGeographic as d,geographicToWebMercator as m}from"./support/webMercatorUtils.js";import f from"./support/WKIDUnitConversion.js";var g;let b=g=class extends u{constructor(e){super(e),this.geodesic=!1,this.numberOfPoints=60,this.radius=1e3,this.radiusUnit="meters"}initialize(){const e=this.center,o=this.numberOfPoints;if(this.hasZ=e?.hasZ??!1,0!==this.rings.length||!e)return;const c=r(this.radius,this.radiusUnit,"meters"),n=e.spatialReference;let p,l="geographic";if(n.isWebMercator?l="webMercator":(null!=(n.wkid&&f[n.wkid])||(n.wkt2||n.wkt)&&t(n.wkt2||n.wkt))&&(l="projected"),this.geodesic){let r;switch(l){case"webMercator":r=d(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":r=e}p=this._createGeodesicCircle(r,c,o),"webMercator"===l&&(p=m(p))}else{let r;"webMercator"===l||"projected"===l?r=c/s(e.spatialReference):"geographic"===l&&(r=i(c,"meters",a(e.spatialReference).radius)),p=this._createPlanarCircle(e,r,o)}this.spatialReference=p.spatialReference,this.addRing(p.rings[0])}get center(){return this._get("center")}set center(e){this._set("center",n(l,e))}clone(){const{center:e,numberOfPoints:r,radius:t,radiusUnit:s,geodesic:i}=this;return new g({center:e?.clone(),numberOfPoints:r,radius:t,radiusUnit:s,geodesic:i})}_createGeodesicCircle(e,r,t){const s=[],i=[e.x,e.y];for(let o=0;o<360;o+=360/t){const t=this.hasZ?[0,0,e.z??0]:[0,0];p(t,i,o,r,h.WGS84),s.push(t)}return s.push(s[0]),new u({rings:[s]})}_createPlanarCircle(e,r,t){const s=[],i=2*Math.PI/t;for(let o=0;o<t;++o){const t=i*o,c=[e.x+Math.cos(-t)*r,e.y+Math.sin(-t)*r];this.hasZ&&c.push(e.z??0),s.push(c)}return s.push(s[0]),new u({spatialReference:e.spatialReference,rings:[s]})}};e([o({type:l,useTypeForAutocast:!1,value:null})],b.prototype,"center",null),e([o()],b.prototype,"geodesic",void 0),e([o()],b.prototype,"numberOfPoints",void 0),e([o()],b.prototype,"radius",void 0),e([o()],b.prototype,"radiusUnit",void 0),b=g=e([c("esri.geometry.Circle")],b);export{b as default};
