import GeometryType from"./GeometryType.js";import SimpleGeometry from"./SimpleGeometry.js";import{createOrUpdate,forEachCorner,intersects}from"../extent.js";import{deflateCoordinate}from"./flat/deflate.js";import{rotate,translate}from"./flat/transform.js";class Circle extends SimpleGeometry{constructor(t,e,s){super(),void 0!==s&&void 0===e?this.setFlatCoordinates(s,t):this.setCenterAndRadius(t,e||0,s)}clone(){const t=new Circle(this.flatCoordinates.slice(),void 0,this.layout);return t.applyProperties(this),t}closestPointXY(t,e,s,r){var i=this.flatCoordinates,t=t-i[0],e=e-i[1],a=t*t+e*e;if(a<r){if(0==a)for(let t=0;t<this.stride;++t)s[t]=i[t];else{var o=this.getRadius()/Math.sqrt(a);s[0]=i[0]+o*t,s[1]=i[1]+o*e;for(let t=2;t<this.stride;++t)s[t]=i[t]}return s.length=this.stride,a}return r}containsXY(t,e){var s=this.flatCoordinates,t=t-s[0],e=e-s[1];return t*t+e*e<=this.getRadiusSquared_()}getCenter(){return this.flatCoordinates.slice(0,this.stride)}computeExtent(t){var e=this.flatCoordinates,s=e[this.stride]-e[0];return createOrUpdate(e[0]-s,e[1]-s,e[0]+s,e[1]+s,t)}getRadius(){return Math.sqrt(this.getRadiusSquared_())}getRadiusSquared_(){var t=this.flatCoordinates[this.stride]-this.flatCoordinates[0],e=this.flatCoordinates[this.stride+1]-this.flatCoordinates[1];return t*t+e*e}getType(){return GeometryType.CIRCLE}intersectsExtent(t){var e=this.getExtent();return!!intersects(t,e)&&(e=this.getCenter(),t[0]<=e[0]&&t[2]>=e[0]||(t[1]<=e[1]&&t[3]>=e[1]||forEachCorner(t,this.intersectsCoordinate.bind(this))))}setCenter(e){var s=this.stride,t=this.flatCoordinates[s]-this.flatCoordinates[0];const r=e.slice();r[s]=r[0]+t;for(let t=1;t<s;++t)r[s+t]=e[t];this.setFlatCoordinates(this.layout,r),this.changed()}setCenterAndRadius(t,e,s){this.setLayout(s,t,0),this.flatCoordinates||(this.flatCoordinates=[]);const r=this.flatCoordinates;let i=deflateCoordinate(r,0,t,this.stride);r[i++]=r[0]+e;for(let t=1,e=this.stride;t<e;++t)r[i++]=r[t];r.length=i,this.changed()}getCoordinates(){return null}setCoordinates(t,e){}setRadius(t){this.flatCoordinates[this.stride]=this.flatCoordinates[0]+t,this.changed()}rotate(t,e){var s=this.getCenter(),r=this.getStride();this.setCenter(rotate(s,0,s.length,r,t,e,s)),this.changed()}translate(t,e){var s=this.getCenter(),r=this.getStride();this.setCenter(translate(s,0,s.length,r,t,e,s)),this.changed()}}Circle.prototype.transform;export default Circle;