/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{n as e,b as t,g as s,j as r,B as h}from"../../../../chunks/vec32.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";class i{constructor(e,t){if(this.h1=e,this.h2=t,!(e<t))throw new Error(`Invalid elevated sphere: ${e}..${t}`)}}class n extends i{constructor(t,s,r){if(super(s,r),this.baseSphere=t,s<=0)throw new Error(`Invalid elevated sphere: ${s}..${r}`);this.axis=e(a(),t.center)}clone(){return new n(this.baseSphere,this.h1,this.h2)}calculateSurfaceDistanceFromPoint(e){const i=t(this.baseSphere.center),{h2:n}=this,c=this.baseSphere.radius;if(i<=c){const s=t(e);return Math.max(0,s-(n+c))}const{axis:o,h1:u}=this,p=c*u/i,l=c*n/i,S=i**2-c**2,d=S/c,f=d*u/i,m=d*n/i,x=s(o,e);if(x<=f-p)return this._distanceSphere(e,u,p);if(x>=m)return this._distanceSphere(e,n,l);const b=Math.sqrt(S),M=c*b/i,v=r(a(),o,x),w=h(v,e),_=M*x/d;if(_<=w)return 0;const q=b*n/i,$=b*x/d;return $<=b*u/i?this._distanceSphere(e,u,p):$>=q?this._distanceSphere(e,n,l):(w-_)*x/$}_distanceSphere(e,t,s){const i=r(a(),this.axis,t),n=h(i,e);return n<s?0:n-s}}class c extends i{constructor(e,t,s){super(t,s),this.baseSphere=e}clone(){return new c(this.baseSphere,this.h1,this.h2)}calculateSurfaceDistanceFromPoint(e){const{center:t,radius:s}=this.baseSphere,r=e[2],h=(e[0]-t[0])**2+(e[1]-t[1])**2,{h1:a,h2:i}=this;return r<=a?Math.max(0,Math.sqrt(h+(r-a)**2)-s):r>=i?Math.max(0,Math.sqrt(h+(r-i)**2)-s):Math.max(0,Math.sqrt(h)-s)}}export{i as SphereCone,n as SphereConeGlobal,c as SphereCylinderLocal};
