OrientedBoundingBox-0a826a8b.js 9.1 KB

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