/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{expandPointInPlace as t}from"../aaBoundingRect.js";import{closestPointOnLine as n}from"./lineUtils.js";import{angularRange as i,interpolateSegment as a,angularRangeClamp as r,distance2 as s,angularRangeWrap as o}from"./mathUtils.js";class c{constructor(t,n,i,a,r,s){this.cx=t,this.cy=n,this.radius=i,this.thetaStart=a,this.thetaEnd=r,this.isInvalid=s}get startPoint(){const{cx:t,cy:n,radius:i,thetaStart:a}=this;return[t+i*Math.cos(a),n+i*Math.sin(a)]}get endPoint(){const{cx:t,cy:n,radius:i,thetaEnd:a}=this;return[t+i*Math.cos(a),n+i*Math.sin(a)]}}function e(t,n){const{cx:i,cy:a,radius:r}=t;return[i+r*Math.cos(n),a+r*Math.sin(n)]}function h(t,n){if(t.isInvalid)return a([0,0],t.startPoint,t.endPoint,n);const{thetaStart:i,thetaEnd:r}=t;return e(t,i*(1-n)+r*n)}function u(t,a){if(t.isInvalid)return n(t.startPoint,t.endPoint,a);const{cx:o,cy:c,thetaStart:h,thetaEnd:u}=t,[d,f]=a,l=r(i(h,u),Math.atan2(f-c,d-o)),M=e(t,l);return{t:(l-h)/(u-h),curvePoint:M,distance:Math.sqrt(s(a,M))}}function d(n,a){if(a.isInvalid)return t(n,a.startPoint),t(n,a.endPoint),n;const{cx:r,cy:s,radius:c,thetaStart:h,thetaEnd:u}=a;t(n,e(a,h)),t(n,e(a,u));const d=i(h,u),f=Math.PI/2;let l=0;for(const i of[[r+c,s],[r,s+c],[r-c,s],[r,s-c]])l=o(d,l),l>d.min&&l<d.max&&t(n,i),l+=f;return n}function f(t){if(t.isInvalid)return 2*t.radius;const{radius:n,thetaStart:i,thetaEnd:a}=t;return n*Math.abs(a-i)}export{c as DerivedCircle,d as circularCurveExtent,f as circularCurveLength,u as closestPointOnCircle,h as interpolateCircle};
