cesium
Version:
CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.
27 lines (25 loc) • 15.9 kB
JavaScript
/**
* @license
* Cesium - https://github.com/CesiumGS/cesium
* Version 1.142.0
*
* Copyright 2011-2022 Cesium Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Columbus View (Pat. Pend.)
*
* Portions licensed separately.
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
*/
import{b as U}from"./chunk-XEBZTQHW.js";import{a as ft}from"./chunk-ZQTDDQLY.js";import{a as i,b}from"./chunk-U4VWQPTS.js";import{a as y}from"./chunk-GZABERXA.js";import{a as w,b as $}from"./chunk-WM6AKY6B.js";import{f as g}from"./chunk-6K4BWAPV.js";var tt={};tt.computeDiscriminant=function(t,r,e){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");return r*r-4*t*e};function mt(t,r,e){let n=t+r;return y.sign(t)!==y.sign(r)&&Math.abs(n/Math.max(Math.abs(t),Math.abs(r)))<e?0:n}tt.computeRealRoots=function(t,r,e){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");let n;if(t===0)return r===0?[]:[-e/r];if(r===0){if(e===0)return[0,0];let u=Math.abs(e),f=Math.abs(t);if(u<f&&u/f<y.EPSILON14)return[0,0];if(u>f&&f/u<y.EPSILON14)return[];if(n=-e/t,n<0)return[];let h=Math.sqrt(n);return[-h,h]}else if(e===0)return n=-r/t,n<0?[n,0]:[0,n];let o=r*r,s=4*t*e,c=mt(o,-s,y.EPSILON14);if(c<0)return[];let a=-.5*mt(r,y.sign(r)*Math.sqrt(c),y.EPSILON14);return r>0?[a/t,e/a]:[e/a,a/t]};var z=tt;var et={};et.computeDiscriminant=function(t,r,e,n){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");if(typeof n!="number")throw new w("d is a required number.");let o=t*t,s=r*r,c=e*e,a=n*n;return 18*t*r*e*n+s*c-27*o*a-4*(t*c*e+s*r*n)};function nt(t,r,e,n){let o=t,s=r/3,c=e/3,a=n,u=o*c,f=s*a,h=s*s,d=c*c,p=o*c-h,q=o*a-s*c,m=s*a-d,l=4*p*m-q*q,E,x;if(l<0){let F,G,_;h*f>=u*d?(F=o,G=p,_=-2*s*p+o*q):(F=a,G=m,_=-a*q+2*c*m);let ut=-(_<0?-1:1)*Math.abs(F)*Math.sqrt(-l);x=-_+ut;let J=x/2,Y=J<0?-Math.pow(-J,1/3):Math.pow(J,1/3),K=x===ut?-Y:-G/Y;return E=G<=0?Y+K:-_/(Y*Y+K*K+G),h*f>=u*d?[(E-s)/o]:[-a/(E+c)]}let v=p,W=-2*s*p+o*q,L=m,B=-a*q+2*c*m,I=Math.sqrt(l),C=Math.sqrt(3)/2,P=Math.abs(Math.atan2(o*I,-W)/3);E=2*Math.sqrt(-v);let R=Math.cos(P);x=E*R;let S=E*(-R/2-C*Math.sin(P)),M=x+S>2*s?x-s:S-s,N=o,D=M/N;P=Math.abs(Math.atan2(a*I,-B)/3),E=2*Math.sqrt(-L),R=Math.cos(P),x=E*R,S=E*(-R/2-C*Math.sin(P));let k=-a,Z=x+S<2*c?x+c:S+c,A=k/Z,Rt=N*Z,at=-M*Z-N*k,bt=M*k,V=(c*at-s*bt)/(-s*at+c*Rt);return D<=V?D<=A?V<=A?[D,V,A]:[D,A,V]:[A,D,V]:D<=A?[V,D,A]:V<=A?[V,A,D]:[A,V,D]}et.computeRealRoots=function(t,r,e,n){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");if(typeof n!="number")throw new w("d is a required number.");let o,s;if(t===0)return z.computeRealRoots(r,e,n);if(r===0){if(e===0){if(n===0)return[0,0,0];s=-n/t;let c=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3);return[c,c,c]}else if(n===0)return o=z.computeRealRoots(t,0,e),o.Length===0?[0]:[o[0],0,o[1]];return nt(t,0,e,n)}else{if(e===0)return n===0?(s=-r/t,s<0?[s,0,0]:[0,0,s]):nt(t,r,0,n);if(n===0)return o=z.computeRealRoots(t,r,e),o.length===0?[0]:o[1]<=0?[o[0],o[1],0]:o[0]>=0?[0,o[0],o[1]]:[o[0],0,o[1]]}return nt(t,r,e,n)};var H=et;var rt={};rt.computeDiscriminant=function(t,r,e,n,o){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");if(typeof n!="number")throw new w("d is a required number.");if(typeof o!="number")throw new w("e is a required number.");let s=t*t,c=s*t,a=r*r,u=a*r,f=e*e,h=f*e,d=n*n,p=d*n,q=o*o,m=q*o;return a*f*d-4*u*p-4*t*h*d+18*t*r*e*p-27*s*d*d+256*c*m+o*(18*u*e*n-4*a*h+16*t*f*f-80*t*r*f*n-6*t*a*d+144*s*e*d)+q*(144*t*a*e-27*a*a-128*s*f-192*s*r*n)};function T(t,r,e,n){let o=t*t,s=r-3*o/8,c=e-r*t/2+o*t/8,a=n-e*t/4+r*o/16-3*o*o/256,u=H.computeRealRoots(1,2*s,s*s-4*a,-c*c);if(u.length>0){let f=-t/4,h=u[u.length-1];if(Math.abs(h)<y.EPSILON14){let d=z.computeRealRoots(1,s,a);if(d.length===2){let p=d[0],q=d[1],m;if(p>=0&&q>=0){let l=Math.sqrt(p),E=Math.sqrt(q);return[f-E,f-l,f+l,f+E]}else{if(p>=0&&q<0)return m=Math.sqrt(p),[f-m,f+m];if(p<0&&q>=0)return m=Math.sqrt(q),[f-m,f+m]}}return[]}else if(h>0){let d=Math.sqrt(h),p=(s+h-c/d)/2,q=(s+h+c/d)/2,m=z.computeRealRoots(1,d,p),l=z.computeRealRoots(1,-d,q);return m.length!==0?(m[0]+=f,m[1]+=f,l.length!==0?(l[0]+=f,l[1]+=f,m[1]<=l[0]?[m[0],m[1],l[0],l[1]]:l[1]<=m[0]?[l[0],l[1],m[0],m[1]]:m[0]>=l[0]&&m[1]<=l[1]?[l[0],m[0],m[1],l[1]]:l[0]>=m[0]&&l[1]<=m[1]?[m[0],l[0],l[1],m[1]]:m[0]>l[0]&&m[0]<l[1]?[l[0],m[0],l[1],m[1]]:[m[0],l[0],m[1],l[1]]):m):l.length!==0?(l[0]+=f,l[1]+=f,l):[]}}return[]}function j(t,r,e,n){let o=e*e,s=r*r,c=t*t,a=-2*r,u=e*t+s-4*n,f=c*n-e*r*t+o,h=H.computeRealRoots(1,a,u,f);if(h.length>0){let d=h[0],p=r-d,q=p*p,m=t/2,l=p/2,E=q-4*n,x=q+4*Math.abs(n),v=c-4*d,W=c+4*Math.abs(d),L,B;if(d<0||E*W<v*x){let N=Math.sqrt(v);L=N/2,B=N===0?0:(t*l-e)/N}else{let N=Math.sqrt(E);L=N===0?0:(t*l-e)/N,B=N/2}let I,C;m===0&&L===0?(I=0,C=0):y.sign(m)===y.sign(L)?(I=m+L,C=d/I):(C=m-L,I=d/C);let P,R;l===0&&B===0?(P=0,R=0):y.sign(l)===y.sign(B)?(P=l+B,R=n/P):(R=l-B,P=n/R);let S=z.computeRealRoots(1,I,P),M=z.computeRealRoots(1,C,R);if(S.length!==0)return M.length!==0?S[1]<=M[0]?[S[0],S[1],M[0],M[1]]:M[1]<=S[0]?[M[0],M[1],S[0],S[1]]:S[0]>=M[0]&&S[1]<=M[1]?[M[0],S[0],S[1],M[1]]:M[0]>=S[0]&&M[1]<=S[1]?[S[0],M[0],M[1],S[1]]:S[0]>M[0]&&S[0]<M[1]?[M[0],S[0],M[1],S[1]]:[S[0],M[0],S[1],M[1]]:S;if(M.length!==0)return M}return[]}rt.computeRealRoots=function(t,r,e,n,o){if(typeof t!="number")throw new w("a is a required number.");if(typeof r!="number")throw new w("b is a required number.");if(typeof e!="number")throw new w("c is a required number.");if(typeof n!="number")throw new w("d is a required number.");if(typeof o!="number")throw new w("e is a required number.");if(Math.abs(t)<y.EPSILON15)return H.computeRealRoots(r,e,n,o);let s=r/t,c=e/t,a=n/t,u=o/t,f=s<0?1:0;switch(f+=c<0?f+1:f,f+=a<0?f+1:f,f+=u<0?f+1:f,f){case 0:return T(s,c,a,u);case 1:return j(s,c,a,u);case 2:return j(s,c,a,u);case 3:return T(s,c,a,u);case 4:return T(s,c,a,u);case 5:return j(s,c,a,u);case 6:return T(s,c,a,u);case 7:return T(s,c,a,u);case 8:return j(s,c,a,u);case 9:return T(s,c,a,u);case 10:return T(s,c,a,u);case 11:return j(s,c,a,u);case 12:return T(s,c,a,u);case 13:return T(s,c,a,u);case 14:return T(s,c,a,u);case 15:return T(s,c,a,u);default:return}};var dt=rt;var ot=class t{constructor(r,e){e=i.clone(e??i.ZERO),i.equals(e,i.ZERO)||i.normalize(e,e),this.origin=i.clone(r??i.ZERO),this.direction=e}static clone(r,e){if(g(r))return g(e)?(e.origin=i.clone(r.origin),e.direction=i.clone(r.direction),e):new t(r.origin,r.direction)}static getPoint(r,e,n){return $.typeOf.object("ray",r),$.typeOf.number("t",e),g(n)||(n=new i),n=i.multiplyByScalar(r.direction,e,n),i.add(r.origin,n,n)}},it=ot;var O={};O.rayPlane=function(t,r,e){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("plane is required.");g(e)||(e=new i);let n=t.origin,o=t.direction,s=r.normal,c=i.dot(s,o);if(Math.abs(c)<y.EPSILON15)return;let a=(-r.distance-i.dot(s,n))/c;if(!(a<0))return e=i.multiplyByScalar(o,a,e),i.add(n,e,e)};var Ot=new i,Pt=new i,Mt=new i,ht=new i,lt=new i;O.rayTriangleParametric=function(t,r,e,n,o){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("p0 is required.");if(!g(e))throw new w("p1 is required.");if(!g(n))throw new w("p2 is required.");o=o??!1;let s=t.origin,c=t.direction,a=i.subtract(e,r,Ot),u=i.subtract(n,r,Pt),f=i.cross(c,u,Mt),h=i.dot(a,f),d,p,q,m,l;if(o){if(h<y.EPSILON6||(d=i.subtract(s,r,ht),q=i.dot(d,f),q<0||q>h)||(p=i.cross(d,a,lt),m=i.dot(c,p),m<0||q+m>h))return;l=i.dot(u,p)/h}else{if(Math.abs(h)<y.EPSILON6)return;let E=1/h;if(d=i.subtract(s,r,ht),q=i.dot(d,f)*E,q<0||q>1||(p=i.cross(d,a,lt),m=i.dot(c,p)*E,m<0||q+m>1))return;l=i.dot(u,p)*E}return l};O.rayTriangle=function(t,r,e,n,o,s){let c=O.rayTriangleParametric(t,r,e,n,o);if(!(!g(c)||c<0))return g(s)||(s=new i),i.multiplyByScalar(t.direction,c,s),i.add(t.origin,s,s)};var Et=new it;O.lineSegmentTriangle=function(t,r,e,n,o,s,c){if(!g(t))throw new w("v0 is required.");if(!g(r))throw new w("v1 is required.");if(!g(e))throw new w("p0 is required.");if(!g(n))throw new w("p1 is required.");if(!g(o))throw new w("p2 is required.");let a=Et;i.clone(t,a.origin),i.subtract(r,t,a.direction),i.normalize(a.direction,a.direction);let u=O.rayTriangleParametric(a,e,n,o,s);if(!(!g(u)||u<0||u>i.distance(t,r)))return g(c)||(c=new i),i.multiplyByScalar(a.direction,u,c),i.add(a.origin,c,c)};function Ct(t,r,e,n){let o=r*r-4*t*e;if(o<0)return;if(o>0){let c=1/(2*t),a=Math.sqrt(o),u=(-r+a)*c,f=(-r-a)*c;return u<f?(n.root0=u,n.root1=f):(n.root0=f,n.root1=u),n}let s=-r/(2*t);if(s!==0)return n.root0=n.root1=s,n}var Nt={root0:0,root1:0};function yt(t,r,e){g(e)||(e=new U);let n=t.origin,o=t.direction,s=r.center,c=r.radius*r.radius,a=i.subtract(n,s,Mt),u=i.dot(o,o),f=2*i.dot(o,a),h=i.magnitudeSquared(a)-c,d=Ct(u,f,h,Nt);if(g(d))return e.start=d.root0,e.stop=d.root1,e}O.raySphere=function(t,r,e){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("sphere is required.");if(e=yt(t,r,e),!(!g(e)||e.stop<0))return e.start=Math.max(e.start,0),e};var Lt=new it;O.lineSegmentSphere=function(t,r,e,n){if(!g(t))throw new w("p0 is required.");if(!g(r))throw new w("p1 is required.");if(!g(e))throw new w("sphere is required.");let o=Lt;i.clone(t,o.origin);let s=i.subtract(r,t,o.direction),c=i.magnitude(s);if(i.normalize(s,s),n=yt(o,e,n),!(!g(n)||n.stop<0||n.start>c))return n.start=Math.max(n.start,0),n.stop=Math.min(n.stop,c),n};var It=new i,xt=new i;O.rayEllipsoid=function(t,r){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("ellipsoid is required.");let e=r.oneOverRadii,n=i.multiplyComponents(e,t.origin,It),o=i.multiplyComponents(e,t.direction,xt),s=i.magnitudeSquared(n),c=i.dot(n,o),a,u,f,h,d;if(s>1){if(c>=0)return;let p=c*c;if(a=s-1,u=i.magnitudeSquared(o),f=u*a,p<f)return;if(p>f){h=c*c-f,d=-c+Math.sqrt(h);let m=d/u,l=a/d;return m<l?new U(m,l):{start:l,stop:m}}let q=Math.sqrt(a/u);return new U(q,q)}else if(s<1)return a=s-1,u=i.magnitudeSquared(o),f=u*a,h=c*c-f,d=-c+Math.sqrt(h),new U(0,d/u);if(c<0)return u=i.magnitudeSquared(o),new U(0,-c/u)};var Bt=new U,Dt=new U,zt=new U;O.rayAxisAlignedBoundingBox=function(t,r,e){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("box is required.");g(e)||(e=new U);let n=st(t.origin.x,t.direction.x,r.minimum.x,r.maximum.x,Bt),o=st(t.origin.y,t.direction.y,r.minimum.y,r.maximum.y,Dt),s=st(t.origin.z,t.direction.z,r.minimum.z,r.maximum.z,zt);if(e.start=n.start>o.start?n.start:o.start,e.stop=n.stop<o.stop?n.stop:o.stop,!(n.start>o.stop||o.start>n.stop)&&!(e.start>s.stop||s.start>e.stop))return s.start>e.start&&(e.start=s.start),s.stop<e.stop&&(e.stop=s.stop),e};function st(t,r,e,n,o){if(o.start=(e-t)/r,o.stop=(n-t)/r,o.stop<o.start){let s=o.stop;o.stop=o.start,o.start=s}return o}function Q(t,r,e){let n=t+r;return y.sign(t)!==y.sign(r)&&Math.abs(n/Math.max(Math.abs(t),Math.abs(r)))<e?0:n}O.quadraticVectorExpression=function(t,r,e,n,o){let s=n*n,c=o*o,a=(t[b.COLUMN1ROW1]-t[b.COLUMN2ROW2])*c,u=o*(n*Q(t[b.COLUMN1ROW0],t[b.COLUMN0ROW1],y.EPSILON15)+r.y),f=t[b.COLUMN0ROW0]*s+t[b.COLUMN2ROW2]*c+n*r.x+e,h=c*Q(t[b.COLUMN2ROW1],t[b.COLUMN1ROW2],y.EPSILON15),d=o*(n*Q(t[b.COLUMN2ROW0],t[b.COLUMN0ROW2])+r.z),p,q=[];if(d===0&&h===0){if(p=z.computeRealRoots(a,u,f),p.length===0)return q;let P=p[0],R=Math.sqrt(Math.max(1-P*P,0));if(q.push(new i(n,o*P,o*-R)),q.push(new i(n,o*P,o*R)),p.length===2){let S=p[1],M=Math.sqrt(Math.max(1-S*S,0));q.push(new i(n,o*S,o*-M)),q.push(new i(n,o*S,o*M))}return q}let m=d*d,l=h*h,E=a*a,x=d*h,v=E+l,W=2*(u*a+x),L=2*f*a+u*u-l+m,B=2*(f*u-x),I=f*f-m;if(v===0&&W===0&&L===0&&B===0)return q;p=dt.computeRealRoots(v,W,L,B,I);let C=p.length;if(C===0)return q;for(let P=0;P<C;++P){let R=p[P],S=R*R,M=Math.max(1-S,0),N=Math.sqrt(M),D;y.sign(a)===y.sign(f)?D=Q(a*S+f,u*R,y.EPSILON12):y.sign(f)===y.sign(u*R)?D=Q(a*S,u*R+f,y.EPSILON12):D=Q(a*S+u*R,f,y.EPSILON12);let k=Q(h*R,d,y.EPSILON15),Z=D*k;Z<0?q.push(new i(n,o*R,o*N)):Z>0?q.push(new i(n,o*R,o*-N)):N!==0?(q.push(new i(n,o*R,o*-N)),q.push(new i(n,o*R,o*N)),++P):q.push(new i(n,o*R,o*N))}return q};var ct=new i,wt=new i,qt=new i,X=new i,Tt=new i,vt=new b,Wt=new b,At=new b,Ut=new b,Vt=new b,gt=new b,pt=new b,St=new i,Qt=new i,Zt=new ft;O.grazingAltitudeLocation=function(t,r){if(!g(t))throw new w("ray is required.");if(!g(r))throw new w("ellipsoid is required.");let e=t.origin,n=t.direction;if(!i.equals(e,i.ZERO)){let I=r.geodeticSurfaceNormal(e,ct);if(i.dot(n,I)>=0)return e}let o=g(this.rayEllipsoid(t,r)),s=r.transformPositionToScaledSpace(n,ct),c=i.normalize(s,s),a=i.mostOrthogonalAxis(s,X),u=i.normalize(i.cross(a,c,wt),wt),f=i.normalize(i.cross(c,u,qt),qt),h=vt;h[0]=c.x,h[1]=c.y,h[2]=c.z,h[3]=u.x,h[4]=u.y,h[5]=u.z,h[6]=f.x,h[7]=f.y,h[8]=f.z;let d=b.transpose(h,Wt),p=b.fromScale(r.radii,At),q=b.fromScale(r.oneOverRadii,Ut),m=Vt;m[0]=0,m[1]=-n.z,m[2]=n.y,m[3]=n.z,m[4]=0,m[5]=-n.x,m[6]=-n.y,m[7]=n.x,m[8]=0;let l=b.multiply(b.multiply(d,q,gt),m,gt),E=b.multiply(b.multiply(l,p,pt),h,pt),x=b.multiplyByVector(l,e,Tt),v=O.quadraticVectorExpression(E,i.negate(x,ct),0,0,1),W,L,B=v.length;if(B>0){let I=i.clone(i.ZERO,Qt),C=Number.NEGATIVE_INFINITY;for(let R=0;R<B;++R){W=b.multiplyByVector(p,b.multiplyByVector(h,v[R],St),St);let S=i.normalize(i.subtract(W,e,X),X),M=i.dot(S,n);M>C&&(C=M,I=i.clone(W,I))}let P=r.cartesianToCartographic(I,Zt);return C=y.clamp(C,0,1),L=i.magnitude(i.subtract(I,e,X))*Math.sqrt(1-C*C),L=o?-L:L,P.height=L,r.cartographicToCartesian(P,new i)}};var kt=new i;O.lineSegmentPlane=function(t,r,e,n){if(!g(t))throw new w("endPoint0 is required.");if(!g(r))throw new w("endPoint1 is required.");if(!g(e))throw new w("plane is required.");g(n)||(n=new i);let o=i.subtract(r,t,kt),s=e.normal,c=i.dot(s,o);if(Math.abs(c)<y.EPSILON6)return;let a=i.dot(s,t),u=-(e.distance+a)/c;if(!(u<0||u>1))return i.multiplyByScalar(o,u,n),i.add(t,n,n),n};O.trianglePlaneIntersection=function(t,r,e,n){if(!g(t)||!g(r)||!g(e)||!g(n))throw new w("p0, p1, p2, and plane are required.");let o=n.normal,s=n.distance,c=i.dot(o,t)+s<0,a=i.dot(o,r)+s<0,u=i.dot(o,e)+s<0,f=0;f+=c?1:0,f+=a?1:0,f+=u?1:0;let h,d;if((f===1||f===2)&&(h=new i,d=new i),f===1){if(c)return O.lineSegmentPlane(t,r,n,h),O.lineSegmentPlane(t,e,n,d),{positions:[t,r,e,h,d],indices:[0,3,4,1,2,4,1,4,3]};if(a)return O.lineSegmentPlane(r,e,n,h),O.lineSegmentPlane(r,t,n,d),{positions:[t,r,e,h,d],indices:[1,3,4,2,0,4,2,4,3]};if(u)return O.lineSegmentPlane(e,t,n,h),O.lineSegmentPlane(e,r,n,d),{positions:[t,r,e,h,d],indices:[2,3,4,0,1,4,0,4,3]}}else if(f===2)if(c)if(a){if(!u)return O.lineSegmentPlane(t,e,n,h),O.lineSegmentPlane(r,e,n,d),{positions:[t,r,e,h,d],indices:[0,1,4,0,4,3,2,3,4]}}else return O.lineSegmentPlane(e,r,n,h),O.lineSegmentPlane(t,r,n,d),{positions:[t,r,e,h,d],indices:[2,0,4,2,4,3,1,3,4]};else return O.lineSegmentPlane(r,t,n,h),O.lineSegmentPlane(e,t,n,d),{positions:[t,r,e,h,d],indices:[1,2,4,1,4,3,0,3,4]}};var gn=O;export{it as a,gn as b};