@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.62 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{normalize as e,length as t,dot as s,scale as r,distance as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";class a{constructor(e,t){if(this.h1=e,this.h2=t,!(e<t))throw new Error(`Invalid elevated sphere: ${e}..${t}`)}}class n extends a{constructor(t,s,r){if(super(s,r),this.baseSphere=t,s<=0)throw new Error(`Invalid elevated sphere: ${s}..${r}`);this.axis=e(i(),t.center)}clone(){return new n(this.baseSphere,this.h1,this.h2)}calculateSurfaceDistanceFromPoint(e){const a=t(this.baseSphere.center),{h2:n}=this,c=this.baseSphere.radius;if(a<=c){const s=t(e);return Math.max(0,s-(n+c))}const{axis:o,h1:u}=this,p=c*u/a,l=c*n/a,S=a**2-c**2,d=S/c,m=d*u/a,f=d*n/a,x=s(o,e);if(x<=m-p)return this._distanceSphere(e,u,p);if(x>=f)return this._distanceSphere(e,n,l);const b=Math.sqrt(S),M=c*b/a,v=r(i(),o,x),w=h(v,e),_=M*x/d;if(_<=w)return 0;const q=b*n/a,$=b*x/d;return $<=b*u/a?this._distanceSphere(e,u,p):$>=q?this._distanceSphere(e,n,l):(w-_)*x/$}_distanceSphere(e,t,s){const a=r(i(),this.axis,t),n=h(a,e);return n<s?0:n-s}}class c extends a{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:i,h2:a}=this;return r<=i?Math.max(0,Math.sqrt(h+(r-i)**2)-s):r>=a?Math.max(0,Math.sqrt(h+(r-a)**2)-s):Math.max(0,Math.sqrt(h)-s)}}export{a as SphereCone,n as SphereConeGlobal,c as SphereCylinderLocal};