UNPKG

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) 11 kB
/** * @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{a as A}from"./chunk-6LZUEMFX.js";import{j as W}from"./chunk-AZCCS55A.js";import{b as Z}from"./chunk-V74K6IQF.js";import{a as v,c as N}from"./chunk-ZQTDDQLY.js";import{a as t,b as U}from"./chunk-U4VWQPTS.js";import{a as ot}from"./chunk-GZABERXA.js";import{a as ct,b as h}from"./chunk-WM6AKY6B.js";import{f as x}from"./chunk-6K4BWAPV.js";var X=class{constructor(e){this._ellipsoid=e??N.default,this._semimajorAxis=this._ellipsoid.maximumRadius,this._oneOverSemimajorAxis=1/this._semimajorAxis}get ellipsoid(){return this._ellipsoid}project(e,n){let c=this._semimajorAxis,o=e.longitude*c,a=e.latitude*c,i=e.height;return x(n)?(n.x=o,n.y=a,n.z=i,n):new t(o,a,i)}unproject(e,n){if(!x(e))throw new ct("cartesian is required");let c=this._oneOverSemimajorAxis,o=e.x*c,a=e.y*c,i=e.z;return x(n)?(n.longitude=o,n.latitude=a,n.height=i,n):new v(o,a,i)}},F=X;function ft(m,e){this.start=m??0,this.stop=e??0}var at=ft;var k=class m{constructor(e,n){this.center=t.clone(e??t.ZERO),this.radius=n??0}static fromPoints(e,n){if(x(n)||(n=new m),!x(e)||e.length===0)return n.center=t.clone(t.ZERO,n.center),n.radius=0,n;let c=t.clone(e[0],$),o=t.clone(c,Y),a=t.clone(c,G),i=t.clone(c,I),d=t.clone(c,J),s=t.clone(c,K),f=t.clone(c,Q),S=e.length,y;for(y=1;y<S;y++){t.clone(e[y],c);let R=c.x,M=c.y,p=c.z;R<o.x&&t.clone(c,o),R>d.x&&t.clone(c,d),M<a.y&&t.clone(c,a),M>s.y&&t.clone(c,s),p<i.z&&t.clone(c,i),p>f.z&&t.clone(c,f)}let u=t.magnitudeSquared(t.subtract(d,o,j)),r=t.magnitudeSquared(t.subtract(s,a,j)),B=t.magnitudeSquared(t.subtract(f,i,j)),C=o,q=d,g=u;r>g&&(g=r,C=a,q=s),B>g&&(g=B,C=i,q=f);let z=L;z.x=(C.x+q.x)*.5,z.y=(C.y+q.y)*.5,z.z=(C.z+q.z)*.5;let w=t.magnitudeSquared(t.subtract(q,z,j)),l=Math.sqrt(w),b=H;b.x=o.x,b.y=a.y,b.z=i.z;let P=_;P.x=d.x,P.y=s.y,P.z=f.z;let D=t.midpoint(b,P,tt),E=0;for(y=0;y<S;y++){t.clone(e[y],c);let R=t.magnitude(t.subtract(c,D,j));R>E&&(E=R);let M=t.magnitudeSquared(t.subtract(c,z,j));if(M>w){let p=Math.sqrt(M);l=(l+p)*.5,w=l*l;let O=p-l;z.x=(l*z.x+O*c.x)/p,z.y=(l*z.y+O*c.y)/p,z.z=(l*z.z+O*c.z)/p}}return l<E?(t.clone(z,n.center),n.radius=l):(t.clone(D,n.center),n.radius=E),n}static fromRectangle2D(e,n,c){return m.fromRectangleWithHeights2D(e,n,0,0,c)}static fromRectangleWithHeights2D(e,n,c,o,a){if(x(a)||(a=new m),!x(e))return a.center=t.clone(t.ZERO,a.center),a.radius=0,a;rt._ellipsoid=N.default,n=n??rt,W.southwest(e,nt),nt.height=c,W.northeast(e,et),et.height=o;let i=n.project(nt,ut),d=n.project(et,xt),s=d.x-i.x,f=d.y-i.y,S=d.z-i.z;a.radius=Math.sqrt(s*s+f*f+S*S)*.5;let y=a.center;return y.x=i.x+s*.5,y.y=i.y+f*.5,y.z=i.z+S*.5,a}static fromRectangle3D(e,n,c,o){if(n=n??N.default,c=c??0,x(o)||(o=new m),!x(e))return o.center=t.clone(t.ZERO,o.center),o.radius=0,o;let a=W.subsample(e,n,c,yt);return m.fromPoints(a,o)}static fromVertices(e,n,c,o){if(x(o)||(o=new m),!x(e)||e.length===0)return o.center=t.clone(t.ZERO,o.center),o.radius=0,o;n=n??t.ZERO,c=c??3,h.typeOf.number.greaterThanOrEquals("stride",c,3);let a=$;a.x=e[0]+n.x,a.y=e[1]+n.y,a.z=e[2]+n.z;let i=t.clone(a,Y),d=t.clone(a,G),s=t.clone(a,I),f=t.clone(a,J),S=t.clone(a,K),y=t.clone(a,Q),u=e.length,r;for(r=0;r<u;r+=c){let p=e[r]+n.x,O=e[r+1]+n.y,T=e[r+2]+n.z;a.x=p,a.y=O,a.z=T,p<i.x&&t.clone(a,i),p>f.x&&t.clone(a,f),O<d.y&&t.clone(a,d),O>S.y&&t.clone(a,S),T<s.z&&t.clone(a,s),T>y.z&&t.clone(a,y)}let B=t.magnitudeSquared(t.subtract(f,i,j)),C=t.magnitudeSquared(t.subtract(S,d,j)),q=t.magnitudeSquared(t.subtract(y,s,j)),g=i,z=f,w=B;C>w&&(w=C,g=d,z=S),q>w&&(w=q,g=s,z=y);let l=L;l.x=(g.x+z.x)*.5,l.y=(g.y+z.y)*.5,l.z=(g.z+z.z)*.5;let b=t.magnitudeSquared(t.subtract(z,l,j)),P=Math.sqrt(b),D=H;D.x=i.x,D.y=d.y,D.z=s.z;let E=_;E.x=f.x,E.y=S.y,E.z=y.z;let R=t.midpoint(D,E,tt),M=0;for(r=0;r<u;r+=c){a.x=e[r]+n.x,a.y=e[r+1]+n.y,a.z=e[r+2]+n.z;let p=t.magnitude(t.subtract(a,R,j));p>M&&(M=p);let O=t.magnitudeSquared(t.subtract(a,l,j));if(O>b){let T=Math.sqrt(O);P=(P+T)*.5,b=P*P;let V=T-P;l.x=(P*l.x+V*a.x)/T,l.y=(P*l.y+V*a.y)/T,l.z=(P*l.z+V*a.z)/T}}return P<M?(t.clone(l,o.center),o.radius=P):(t.clone(R,o.center),o.radius=M),o}static fromEncodedCartesianVertices(e,n,c){if(x(c)||(c=new m),!x(e)||!x(n)||e.length!==n.length||e.length===0)return c.center=t.clone(t.ZERO,c.center),c.radius=0,c;let o=$;o.x=e[0]+n[0],o.y=e[1]+n[1],o.z=e[2]+n[2];let a=t.clone(o,Y),i=t.clone(o,G),d=t.clone(o,I),s=t.clone(o,J),f=t.clone(o,K),S=t.clone(o,Q),y=e.length,u;for(u=0;u<y;u+=3){let M=e[u]+n[u],p=e[u+1]+n[u+1],O=e[u+2]+n[u+2];o.x=M,o.y=p,o.z=O,M<a.x&&t.clone(o,a),M>s.x&&t.clone(o,s),p<i.y&&t.clone(o,i),p>f.y&&t.clone(o,f),O<d.z&&t.clone(o,d),O>S.z&&t.clone(o,S)}let r=t.magnitudeSquared(t.subtract(s,a,j)),B=t.magnitudeSquared(t.subtract(f,i,j)),C=t.magnitudeSquared(t.subtract(S,d,j)),q=a,g=s,z=r;B>z&&(z=B,q=i,g=f),C>z&&(z=C,q=d,g=S);let w=L;w.x=(q.x+g.x)*.5,w.y=(q.y+g.y)*.5,w.z=(q.z+g.z)*.5;let l=t.magnitudeSquared(t.subtract(g,w,j)),b=Math.sqrt(l),P=H;P.x=a.x,P.y=i.y,P.z=d.z;let D=_;D.x=s.x,D.y=f.y,D.z=S.z;let E=t.midpoint(P,D,tt),R=0;for(u=0;u<y;u+=3){o.x=e[u]+n[u],o.y=e[u+1]+n[u+1],o.z=e[u+2]+n[u+2];let M=t.magnitude(t.subtract(o,E,j));M>R&&(R=M);let p=t.magnitudeSquared(t.subtract(o,w,j));if(p>l){let O=Math.sqrt(p);b=(b+O)*.5,l=b*b;let T=O-b;w.x=(b*w.x+T*o.x)/O,w.y=(b*w.y+T*o.y)/O,w.z=(b*w.z+T*o.z)/O}}return b<R?(t.clone(w,c.center),c.radius=b):(t.clone(E,c.center),c.radius=R),c}static fromCornerPoints(e,n,c){h.typeOf.object("corner",e),h.typeOf.object("oppositeCorner",n),x(c)||(c=new m);let o=t.midpoint(e,n,c.center);return c.radius=t.distance(o,n),c}static fromEllipsoid(e,n){return h.typeOf.object("ellipsoid",e),x(n)||(n=new m),t.clone(t.ZERO,n.center),n.radius=e.maximumRadius,n}static fromBoundingSpheres(e,n){if(x(n)||(n=new m),!x(e)||e.length===0)return n.center=t.clone(t.ZERO,n.center),n.radius=0,n;let c=e.length;if(c===1)return m.clone(e[0],n);if(c===2)return m.union(e[0],e[1],n);let o=[],a;for(a=0;a<c;a++)o.push(e[a].center);n=m.fromPoints(o,n);let i=n.center,d=n.radius;for(a=0;a<c;a++){let s=e[a];d=Math.max(d,t.distance(i,s.center)+s.radius)}return n.radius=d,n}static fromOrientedBoundingBox(e,n){h.defined("orientedBoundingBox",e),x(n)||(n=new m);let c=e.halfAxes,o=U.getColumn(c,0,lt),a=U.getColumn(c,1,zt),i=U.getColumn(c,2,ht);return t.add(o,a,o),t.add(o,i,o),n.center=t.clone(e.center,n.center),n.radius=t.magnitude(o),n}static fromTransformation(e,n){h.typeOf.object("transformation",e),x(n)||(n=new m);let c=Z.getTranslation(e,St),o=Z.getScale(e,wt),a=.5*t.magnitude(o);return n.center=t.clone(c,n.center),n.radius=a,n}static clone(e,n){if(x(e))return x(n)?(n.center=t.clone(e.center,n.center),n.radius=e.radius,n):new m(e.center,e.radius)}static pack(e,n,c){h.typeOf.object("value",e),h.defined("array",n),c=c??0;let o=e.center;return n[c++]=o.x,n[c++]=o.y,n[c++]=o.z,n[c]=e.radius,n}static unpack(e,n,c){h.defined("array",e),n=n??0,x(c)||(c=new m);let o=c.center;return o.x=e[n++],o.y=e[n++],o.z=e[n++],c.radius=e[n],c}static union(e,n,c){h.typeOf.object("left",e),h.typeOf.object("right",n),x(c)||(c=new m);let o=e.center,a=e.radius,i=n.center,d=n.radius,s=t.subtract(i,o,pt),f=t.magnitude(s);if(a>=f+d)return e.clone(c),c;if(d>=f+a)return n.clone(c),c;let S=(a+f+d)*.5,y=t.multiplyByScalar(s,(-a+S)/f,Pt);return t.add(y,o,y),t.clone(y,c.center),c.radius=S,c}static expand(e,n,c){h.typeOf.object("sphere",e),h.typeOf.object("point",n),c=m.clone(e,c);let o=t.magnitude(t.subtract(n,c.center,Ot));return o>c.radius&&(c.radius=o),c}static intersectPlane(e,n){h.typeOf.object("sphere",e),h.typeOf.object("plane",n);let c=e.center,o=e.radius,a=n.normal,i=t.dot(a,c)+n.distance;return i<-o?A.OUTSIDE:i<o?A.INTERSECTING:A.INSIDE}static transform(e,n,c){return h.typeOf.object("sphere",e),h.typeOf.object("transform",n),x(c)||(c=new m),c.center=Z.multiplyByPoint(n,e.center,c.center),c.radius=Z.getMaximumScale(n)*e.radius,c}static distanceSquaredTo(e,n){h.typeOf.object("sphere",e),h.typeOf.object("cartesian",n);let c=t.subtract(e.center,n,gt),o=t.magnitude(c)-e.radius;return o<=0?0:o*o}static transformWithoutScale(e,n,c){return h.typeOf.object("sphere",e),h.typeOf.object("transform",n),x(c)||(c=new m),c.center=Z.multiplyByPoint(n,e.center,c.center),c.radius=e.radius,c}static computePlaneDistances(e,n,c,o){h.typeOf.object("sphere",e),h.typeOf.object("position",n),h.typeOf.object("direction",c),x(o)||(o=new at);let a=t.subtract(e.center,n,bt),i=t.dot(c,a);return o.start=i-e.radius,o.stop=i+e.radius,o}static projectTo2D(e,n,c){h.typeOf.object("sphere",e),dt._ellipsoid=N.default,n=n??dt;let o=n.ellipsoid,a=e.center,i=e.radius,d;t.equals(a,t.ZERO)?d=t.clone(t.UNIT_X,it):d=o.geodeticSurfaceNormal(a,it);let s=t.cross(t.UNIT_Z,d,jt);t.normalize(s,s);let f=t.cross(d,s,qt);t.normalize(f,f),t.multiplyByScalar(d,i,d),t.multiplyByScalar(f,i,f),t.multiplyByScalar(s,i,s);let S=t.negate(f,Ct),y=t.negate(s,Mt),u=st,r=u[0];t.add(d,f,r),t.add(r,s,r),r=u[1],t.add(d,f,r),t.add(r,y,r),r=u[2],t.add(d,S,r),t.add(r,y,r),r=u[3],t.add(d,S,r),t.add(r,s,r),t.negate(d,d),r=u[4],t.add(d,f,r),t.add(r,s,r),r=u[5],t.add(d,f,r),t.add(r,y,r),r=u[6],t.add(d,S,r),t.add(r,y,r),r=u[7],t.add(d,S,r),t.add(r,s,r);let B=u.length;for(let z=0;z<B;++z){let w=u[z];t.add(a,w,w);let l=o.cartesianToCartographic(w,Rt);n.project(l,w)}c=m.fromPoints(u,c),a=c.center;let C=a.x,q=a.y,g=a.z;return a.x=g,a.y=C,a.z=q,c}static isOccluded(e,n){return h.typeOf.object("sphere",e),h.typeOf.object("occluder",n),!n.isBoundingSphereVisible(e)}static equals(e,n){return e===n||x(e)&&x(n)&&t.equals(e.center,n.center)&&e.radius===n.radius}intersectPlane(e){return m.intersectPlane(this,e)}distanceSquaredTo(e){return m.distanceSquaredTo(this,e)}computePlaneDistances(e,n,c){return m.computePlaneDistances(this,e,n,c)}isOccluded(e){return m.isOccluded(this,e)}equals(e){return m.equals(this,e)}clone(e){return m.clone(this,e)}volume(){let e=this.radius;return mt*e*e*e}};k.packedLength=4;var Y=new t,G=new t,I=new t,J=new t,K=new t,Q=new t,$=new t,j=new t,L=new t,H=new t,_=new t,tt=new t,mt=4/3*ot.PI,rt=new F,ut=new t,xt=new t,nt=new v,et=new v,yt=[],lt=new t,zt=new t,ht=new t,St=new t,wt=new t,pt=new t,Pt=new t,Ot=new t,gt=new t,bt=new t,it=new t,jt=new t,qt=new t,Mt=new t,Ct=new t,Rt=new v,st=new Array(8);for(let m=0;m<8;++m)st[m]=new t;var dt=new F,Qt=k;export{F as a,at as b,Qt as c};