OrientedBoundingBox-3db45505.js 11 KB

1
  1. define(["exports","./Transforms-98ffa11d","./Matrix2-e3fb4559","./Cartesian3-7e9cc2ff","./Check-741c5f3c","./defaultValue-81eec7ed","./EllipsoidTangentPlane-fa1337e1","./Math-5f585871","./Matrix4-d34187af","./Plane-4f75b3df"],(function(a,t,e,n,r,i,s,o,c,C){"use strict";function u(a,t){this.center=n.Cartesian3.clone(i.defaultValue(a,n.Cartesian3.ZERO)),this.halfAxes=c.Matrix3.clone(i.defaultValue(t,c.Matrix3.ZERO))}u.packedLength=n.Cartesian3.packedLength+c.Matrix3.packedLength,u.pack=function(a,t,e){return e=i.defaultValue(e,0),n.Cartesian3.pack(a.center,t,e),c.Matrix3.pack(a.halfAxes,t,e+n.Cartesian3.packedLength),t},u.unpack=function(a,t,e){return t=i.defaultValue(t,0),i.defined(e)||(e=new u),n.Cartesian3.unpack(a,t,e.center),c.Matrix3.unpack(a,t+n.Cartesian3.packedLength,e.halfAxes),e};const l=new n.Cartesian3,d=new n.Cartesian3,h=new n.Cartesian3,f=new n.Cartesian3,x=new n.Cartesian3,m=new n.Cartesian3,M=new c.Matrix3,p={unitary:new c.Matrix3,diagonal:new c.Matrix3};u.fromPoints=function(a,t){if(i.defined(t)||(t=new u),!i.defined(a)||0===a.length)return t.halfAxes=c.Matrix3.ZERO,t.center=n.Cartesian3.ZERO,t;let e;const r=a.length,s=n.Cartesian3.clone(a[0],l);for(e=1;e<r;e++)n.Cartesian3.add(s,a[e],s);const o=1/r;n.Cartesian3.multiplyByScalar(s,o,s);let C,w=0,g=0,y=0,b=0,N=0,T=0;for(e=0;e<r;e++)C=n.Cartesian3.subtract(a[e],s,d),w+=C.x*C.x,g+=C.x*C.y,y+=C.x*C.z,b+=C.y*C.y,N+=C.y*C.z,T+=C.z*C.z;w*=o,g*=o,y*=o,b*=o,N*=o,T*=o;const O=M;O[0]=w,O[1]=g,O[2]=y,O[3]=g,O[4]=b,O[5]=N,O[6]=y,O[7]=N,O[8]=T;const A=c.Matrix3.computeEigenDecomposition(O,p),P=c.Matrix3.clone(A.unitary,t.halfAxes);let I=c.Matrix3.getColumn(P,0,f),R=c.Matrix3.getColumn(P,1,x),E=c.Matrix3.getColumn(P,2,m),S=-Number.MAX_VALUE,U=-Number.MAX_VALUE,L=-Number.MAX_VALUE,z=Number.MAX_VALUE,B=Number.MAX_VALUE,V=Number.MAX_VALUE;for(e=0;e<r;e++)C=a[e],S=Math.max(n.Cartesian3.dot(I,C),S),U=Math.max(n.Cartesian3.dot(R,C),U),L=Math.max(n.Cartesian3.dot(E,C),L),z=Math.min(n.Cartesian3.dot(I,C),z),B=Math.min(n.Cartesian3.dot(R,C),B),V=Math.min(n.Cartesian3.dot(E,C),V);I=n.Cartesian3.multiplyByScalar(I,.5*(z+S),I),R=n.Cartesian3.multiplyByScalar(R,.5*(B+U),R),E=n.Cartesian3.multiplyByScalar(E,.5*(V+L),E);const _=n.Cartesian3.add(I,R,t.center);n.Cartesian3.add(_,E,_);const k=h;return k.x=S-z,k.y=U-B,k.z=L-V,n.Cartesian3.multiplyByScalar(k,.5,k),c.Matrix3.multiplyByScale(t.halfAxes,k,t.halfAxes),t};const w=new n.Cartesian3,g=new n.Cartesian3;function y(a,t,e,r,s,o,C,l,d,h,f){i.defined(f)||(f=new u);const x=f.halfAxes;c.Matrix3.setColumn(x,0,t,x),c.Matrix3.setColumn(x,1,e,x),c.Matrix3.setColumn(x,2,r,x);let m=w;m.x=(s+o)/2,m.y=(C+l)/2,m.z=(d+h)/2;const M=g;M.x=(o-s)/2,M.y=(l-C)/2,M.z=(h-d)/2;const p=f.center;return m=c.Matrix3.multiplyByVector(x,m,m),n.Cartesian3.add(a,m,p),c.Matrix3.multiplyByScale(x,M,x),f}const b=new e.Cartographic,N=new n.Cartesian3,T=new e.Cartographic,O=new e.Cartographic,A=new e.Cartographic,P=new e.Cartographic,I=new e.Cartographic,R=new n.Cartesian3,E=new n.Cartesian3,S=new n.Cartesian3,U=new n.Cartesian3,L=new n.Cartesian3,z=new e.Cartesian2,B=new e.Cartesian2,V=new e.Cartesian2,_=new e.Cartesian2,k=new e.Cartesian2,W=new n.Cartesian3,X=new n.Cartesian3,q=new n.Cartesian3,D=new n.Cartesian3,j=new e.Cartesian2,Z=new n.Cartesian3,v=new n.Cartesian3,Y=new n.Cartesian3,G=new C.Plane(n.Cartesian3.UNIT_X,0);u.fromRectangle=function(a,t,r,c,u){let l,d,h,f,x,m,M;if(t=i.defaultValue(t,0),r=i.defaultValue(r,0),c=i.defaultValue(c,e.Ellipsoid.WGS84),a.width<=o.CesiumMath.PI){const n=e.Rectangle.center(a,b),i=c.cartographicToCartesian(n,N),o=new s.EllipsoidTangentPlane(i,c);M=o.plane;const p=n.longitude,w=a.south<0&&a.north>0?0:n.latitude,g=e.Cartographic.fromRadians(p,a.north,r,T),W=e.Cartographic.fromRadians(a.west,a.north,r,O),X=e.Cartographic.fromRadians(a.west,w,r,A),q=e.Cartographic.fromRadians(a.west,a.south,r,P),D=e.Cartographic.fromRadians(p,a.south,r,I),j=c.cartographicToCartesian(g,R);let Z=c.cartographicToCartesian(W,E);const v=c.cartographicToCartesian(X,S);let Y=c.cartographicToCartesian(q,U);const G=c.cartographicToCartesian(D,L),F=o.projectPointToNearestOnPlane(j,z),H=o.projectPointToNearestOnPlane(Z,B),J=o.projectPointToNearestOnPlane(v,V),K=o.projectPointToNearestOnPlane(Y,_),Q=o.projectPointToNearestOnPlane(G,k);return l=Math.min(H.x,J.x,K.x),d=-l,f=Math.max(H.y,F.y),h=Math.min(K.y,Q.y),W.height=q.height=t,Z=c.cartographicToCartesian(W,E),Y=c.cartographicToCartesian(q,U),x=Math.min(C.Plane.getPointDistance(M,Z),C.Plane.getPointDistance(M,Y)),m=r,y(o.origin,o.xAxis,o.yAxis,o.zAxis,l,d,h,f,x,m,u)}const p=a.south>0,w=a.north<0,g=p?a.south:w?a.north:0,F=e.Rectangle.center(a,b).longitude,H=n.Cartesian3.fromRadians(F,g,r,c,W);H.z=0;const J=Math.abs(H.x)<o.CesiumMath.EPSILON10&&Math.abs(H.y)<o.CesiumMath.EPSILON10?n.Cartesian3.UNIT_X:n.Cartesian3.normalize(H,X),K=n.Cartesian3.UNIT_Z,Q=n.Cartesian3.cross(J,K,q);M=C.Plane.fromPointNormal(H,J,G);const $=n.Cartesian3.fromRadians(F+o.CesiumMath.PI_OVER_TWO,g,r,c,D);d=n.Cartesian3.dot(C.Plane.projectPointOntoPlane(M,$,j),Q),l=-d,f=n.Cartesian3.fromRadians(0,a.north,w?t:r,c,Z).z,h=n.Cartesian3.fromRadians(0,a.south,p?t:r,c,v).z;const aa=n.Cartesian3.fromRadians(a.east,g,r,c,Y);return x=C.Plane.getPointDistance(M,aa),m=0,y(H,Q,K,J,l,d,h,f,x,m,u)},u.fromTransformation=function(a,t){return i.defined(t)||(t=new u),t.center=c.Matrix4.getTranslation(a,t.center),t.halfAxes=c.Matrix4.getMatrix3(a,t.halfAxes),t.halfAxes=c.Matrix3.multiplyByScalar(t.halfAxes,.5,t.halfAxes),t},u.clone=function(a,t){if(i.defined(a))return i.defined(t)?(n.Cartesian3.clone(a.center,t.center),c.Matrix3.clone(a.halfAxes,t.halfAxes),t):new u(a.center,a.halfAxes)},u.intersectPlane=function(a,e){const r=a.center,i=e.normal,s=a.halfAxes,o=i.x,C=i.y,u=i.z,l=Math.abs(o*s[c.Matrix3.COLUMN0ROW0]+C*s[c.Matrix3.COLUMN0ROW1]+u*s[c.Matrix3.COLUMN0ROW2])+Math.abs(o*s[c.Matrix3.COLUMN1ROW0]+C*s[c.Matrix3.COLUMN1ROW1]+u*s[c.Matrix3.COLUMN1ROW2])+Math.abs(o*s[c.Matrix3.COLUMN2ROW0]+C*s[c.Matrix3.COLUMN2ROW1]+u*s[c.Matrix3.COLUMN2ROW2]),d=n.Cartesian3.dot(i,r)+e.distance;return d<=-l?t.Intersect.OUTSIDE:d>=l?t.Intersect.INSIDE:t.Intersect.INTERSECTING};const F=new n.Cartesian3,H=new n.Cartesian3,J=new n.Cartesian3,K=new n.Cartesian3,Q=new n.Cartesian3,$=new n.Cartesian3;u.distanceSquaredTo=function(a,t){const e=n.Cartesian3.subtract(t,a.center,w),r=a.halfAxes;let i=c.Matrix3.getColumn(r,0,F),s=c.Matrix3.getColumn(r,1,H),C=c.Matrix3.getColumn(r,2,J);const u=n.Cartesian3.magnitude(i),l=n.Cartesian3.magnitude(s),d=n.Cartesian3.magnitude(C);let h=!0,f=!0,x=!0;u>0?n.Cartesian3.divideByScalar(i,u,i):h=!1,l>0?n.Cartesian3.divideByScalar(s,l,s):f=!1,d>0?n.Cartesian3.divideByScalar(C,d,C):x=!1;const m=!h+!f+!x;let M,p,g;if(1===m){let a=i;M=s,p=C,f?x||(a=C,p=i):(a=s,M=i),g=n.Cartesian3.cross(M,p,Q),a===i?i=g:a===s?s=g:a===C&&(C=g)}else if(2===m){M=i,f?M=s:x&&(M=C);let a=n.Cartesian3.UNIT_Y;a.equalsEpsilon(M,o.CesiumMath.EPSILON3)&&(a=n.Cartesian3.UNIT_X),p=n.Cartesian3.cross(M,a,K),n.Cartesian3.normalize(p,p),g=n.Cartesian3.cross(M,p,Q),n.Cartesian3.normalize(g,g),M===i?(s=p,C=g):M===s?(C=p,i=g):M===C&&(i=p,s=g)}else 3===m&&(i=n.Cartesian3.UNIT_X,s=n.Cartesian3.UNIT_Y,C=n.Cartesian3.UNIT_Z);const y=$;y.x=n.Cartesian3.dot(e,i),y.y=n.Cartesian3.dot(e,s),y.z=n.Cartesian3.dot(e,C);let b,N=0;return y.x<-u?(b=y.x+u,N+=b*b):y.x>u&&(b=y.x-u,N+=b*b),y.y<-l?(b=y.y+l,N+=b*b):y.y>l&&(b=y.y-l,N+=b*b),y.z<-d?(b=y.z+d,N+=b*b):y.z>d&&(b=y.z-d,N+=b*b),N};const aa=new n.Cartesian3,ta=new n.Cartesian3;u.computePlaneDistances=function(a,e,r,s){i.defined(s)||(s=new t.Interval);let o=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;const u=a.center,l=a.halfAxes,d=c.Matrix3.getColumn(l,0,F),h=c.Matrix3.getColumn(l,1,H),f=c.Matrix3.getColumn(l,2,J),x=n.Cartesian3.add(d,h,aa);n.Cartesian3.add(x,f,x),n.Cartesian3.add(x,u,x);const m=n.Cartesian3.subtract(x,e,ta);let M=n.Cartesian3.dot(r,m);return o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.add(u,d,x),n.Cartesian3.add(x,h,x),n.Cartesian3.subtract(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.add(u,d,x),n.Cartesian3.subtract(x,h,x),n.Cartesian3.add(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.add(u,d,x),n.Cartesian3.subtract(x,h,x),n.Cartesian3.subtract(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.subtract(u,d,x),n.Cartesian3.add(x,h,x),n.Cartesian3.add(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.subtract(u,d,x),n.Cartesian3.add(x,h,x),n.Cartesian3.subtract(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.subtract(u,d,x),n.Cartesian3.subtract(x,h,x),n.Cartesian3.add(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),n.Cartesian3.subtract(u,d,x),n.Cartesian3.subtract(x,h,x),n.Cartesian3.subtract(x,f,x),n.Cartesian3.subtract(x,e,m),M=n.Cartesian3.dot(r,m),o=Math.min(M,o),C=Math.max(M,C),s.start=o,s.stop=C,s};const ea=new n.Cartesian3,na=new n.Cartesian3,ra=new n.Cartesian3;u.computeCorners=function(a,t){i.defined(t)||(t=[new n.Cartesian3,new n.Cartesian3,new n.Cartesian3,new n.Cartesian3,new n.Cartesian3,new n.Cartesian3,new n.Cartesian3,new n.Cartesian3]);const e=a.center,r=a.halfAxes,s=c.Matrix3.getColumn(r,0,ea),o=c.Matrix3.getColumn(r,1,na),C=c.Matrix3.getColumn(r,2,ra);return n.Cartesian3.clone(e,t[0]),n.Cartesian3.subtract(t[0],s,t[0]),n.Cartesian3.subtract(t[0],o,t[0]),n.Cartesian3.subtract(t[0],C,t[0]),n.Cartesian3.clone(e,t[1]),n.Cartesian3.subtract(t[1],s,t[1]),n.Cartesian3.subtract(t[1],o,t[1]),n.Cartesian3.add(t[1],C,t[1]),n.Cartesian3.clone(e,t[2]),n.Cartesian3.subtract(t[2],s,t[2]),n.Cartesian3.add(t[2],o,t[2]),n.Cartesian3.subtract(t[2],C,t[2]),n.Cartesian3.clone(e,t[3]),n.Cartesian3.subtract(t[3],s,t[3]),n.Cartesian3.add(t[3],o,t[3]),n.Cartesian3.add(t[3],C,t[3]),n.Cartesian3.clone(e,t[4]),n.Cartesian3.add(t[4],s,t[4]),n.Cartesian3.subtract(t[4],o,t[4]),n.Cartesian3.subtract(t[4],C,t[4]),n.Cartesian3.clone(e,t[5]),n.Cartesian3.add(t[5],s,t[5]),n.Cartesian3.subtract(t[5],o,t[5]),n.Cartesian3.add(t[5],C,t[5]),n.Cartesian3.clone(e,t[6]),n.Cartesian3.add(t[6],s,t[6]),n.Cartesian3.add(t[6],o,t[6]),n.Cartesian3.subtract(t[6],C,t[6]),n.Cartesian3.clone(e,t[7]),n.Cartesian3.add(t[7],s,t[7]),n.Cartesian3.add(t[7],o,t[7]),n.Cartesian3.add(t[7],C,t[7]),t};const ia=new c.Matrix3;u.computeTransformation=function(a,t){i.defined(t)||(t=new c.Matrix4);const e=a.center,n=c.Matrix3.multiplyByUniformScale(a.halfAxes,2,ia);return c.Matrix4.fromRotationTranslation(n,e,t)};const sa=new t.BoundingSphere;u.isOccluded=function(a,e){const n=t.BoundingSphere.fromOrientedBoundingBox(a,sa);return!e.isBoundingSphereVisible(n)},u.prototype.intersectPlane=function(a){return u.intersectPlane(this,a)},u.prototype.distanceSquaredTo=function(a){return u.distanceSquaredTo(this,a)},u.prototype.computePlaneDistances=function(a,t,e){return u.computePlaneDistances(this,a,t,e)},u.prototype.computeCorners=function(a){return u.computeCorners(this,a)},u.prototype.computeTransformation=function(a){return u.computeTransformation(this,a)},u.prototype.isOccluded=function(a){return u.isOccluded(this,a)},u.equals=function(a,t){return a===t||i.defined(a)&&i.defined(t)&&n.Cartesian3.equals(a.center,t.center)&&c.Matrix3.equals(a.halfAxes,t.halfAxes)},u.prototype.clone=function(a){return u.clone(this,a)},u.prototype.equals=function(a){return u.equals(this,a)},a.OrientedBoundingBox=u}));