OrientedBoundingBox-a6c2fb0f.js 13 KB

1
  1. define(["exports","./buildModuleUrl-8cce5713","./Cartesian4-b0ddc4ba","./Check-7b2a090c","./when-b60132fc","./PolygonPipeline-f2f37e26","./Math-31e539c2","./Plane-5716a082"],(function(a,t,e,n,r,i,s,o){"use strict";var C=[];function d(a,n){this.center=e.Cartesian3.clone(r.defaultValue(a,e.Cartesian3.ZERO)),this.halfAxes=t.Matrix3.clone(r.defaultValue(n,t.Matrix3.ZERO)),this.areaDirty=1}C[0]={num:0,des:"inside"},C[1]={num:4,data:[0,4,7,3],des:"left"},C[2]={num:4,data:[1,2,6,5],des:"right"},C[3]={num:0},C[4]={num:4,data:[0,1,5,4],des:"bottom"},C[5]={num:6,data:[0,1,5,4,7,3],des:"bottom, left"},C[6]={num:6,data:[0,1,2,6,5,4],des:"bottom, right"},C[7]={num:0},C[8]={num:4,data:[2,3,7,6],des:"top"},C[9]={num:6,data:[4,7,6,2,3,0],des:"top, left"},C[10]={num:6,data:[2,3,7,6,5,1],des:"top, right"},C[11]={num:0},C[12]={num:0},C[13]={num:0},C[14]={num:0},C[15]={num:0},C[16]={num:4,data:[0,3,2,1],des:"front"},C[17]={num:6,data:[0,4,7,3,2,1],des:"front, left"},C[18]={num:6,data:[0,3,2,6,5,1],des:"front, right"},C[19]={num:0},C[20]={num:6,data:[0,3,2,1,5,4],des:"front, bottom"},C[21]={num:6,data:[2,1,5,4,7,3],des:"front, bottom, left"},C[22]={num:6,data:[0,3,2,6,5,4],des:"front, bottom, right"},C[23]={num:0},C[24]={num:6,data:[0,3,7,6,2,1],des:"front, top"},C[25]={num:6,data:[0,4,7,6,2,1],des:"front, top, left"},C[26]={num:6,data:[0,3,7,6,5,1],des:"front, top, right"},C[27]={num:0},C[28]={num:0},C[29]={num:0},C[30]={num:0},C[31]={num:0},C[32]={num:4,data:[4,5,6,7],des:"back"},C[33]={num:6,data:[4,5,6,7,3,0],des:"back, left"},C[34]={num:6,data:[1,2,6,7,4,5],des:"back, right"},C[35]={num:0},C[36]={num:6,data:[0,1,5,6,7,4],des:"back, bottom"},C[37]={num:6,data:[0,1,5,6,7,3],des:"back, bottom, left"},C[38]={num:6,data:[0,1,2,6,7,4],des:"back, bottom, right"},C[39]={num:0},C[40]={num:6,data:[2,3,7,4,5,6],des:"back, top"},C[41]={num:6,data:[0,4,5,6,2,3],des:"back, top, left"},C[42]={num:6,data:[1,2,3,7,4,5],des:"back, top, right"},d.packedLength=e.Cartesian3.packedLength+t.Matrix3.packedLength,d.pack=function(a,n,i){return i=r.defaultValue(i,0),e.Cartesian3.pack(a.center,n,i),t.Matrix3.pack(a.halfAxes,n,i+e.Cartesian3.packedLength),n},d.unpack=function(a,n,i){return n=r.defaultValue(n,0),r.defined(i)||(i=new d),e.Cartesian3.unpack(a,n,i.center),t.Matrix3.unpack(a,n+e.Cartesian3.packedLength,i.halfAxes),i};var u=new e.Cartesian3,c=new e.Cartesian3,h=new e.Cartesian3,l=new e.Cartesian3,m=new e.Cartesian3,x=new e.Cartesian3,p=new t.Matrix3,M={unitary:new t.Matrix3,diagonal:new t.Matrix3},f=new e.Cartesian3,g=new e.Cartesian3,w=new e.Cartesian3;d.fromPoints=function(a,n){if(r.defined(n)||(n=new d),!r.defined(a)||0===a.length)return n.halfAxes=t.Matrix3.ZERO,n.center=e.Cartesian3.ZERO,n;var i,s=a.length,o=e.Cartesian3.clone(a[0],u);for(i=1;i<s;i++)e.Cartesian3.add(o,a[i],o);var C=1/s;e.Cartesian3.multiplyByScalar(o,C,o);var f,g=0,w=0,b=0,y=0,v=0,P=0;for(i=0;i<s;i++)g+=(f=e.Cartesian3.subtract(a[i],o,c)).x*f.x,w+=f.x*f.y,b+=f.x*f.z,y+=f.y*f.y,v+=f.y*f.z,P+=f.z*f.z;g*=C,w*=C,b*=C,y*=C,v*=C,P*=C;var O=p;O[0]=g,O[1]=w,O[2]=b,O[3]=w,O[4]=y,O[5]=v,O[6]=b,O[7]=v,O[8]=P;var z=t.Matrix3.computeEigenDecomposition(O,M),A=t.Matrix3.clone(z.unitary,n.halfAxes),N=t.Matrix3.getColumn(A,0,l),R=t.Matrix3.getColumn(A,1,m),I=t.Matrix3.getColumn(A,2,x),T=-Number.MAX_VALUE,E=-Number.MAX_VALUE,D=-Number.MAX_VALUE,B=Number.MAX_VALUE,L=Number.MAX_VALUE,k=Number.MAX_VALUE;for(i=0;i<s;i++)f=a[i],T=Math.max(e.Cartesian3.dot(N,f),T),E=Math.max(e.Cartesian3.dot(R,f),E),D=Math.max(e.Cartesian3.dot(I,f),D),B=Math.min(e.Cartesian3.dot(N,f),B),L=Math.min(e.Cartesian3.dot(R,f),L),k=Math.min(e.Cartesian3.dot(I,f),k);N=e.Cartesian3.multiplyByScalar(N,.5*(B+T),N),R=e.Cartesian3.multiplyByScalar(R,.5*(L+E),R),I=e.Cartesian3.multiplyByScalar(I,.5*(k+D),I);var U=e.Cartesian3.add(N,R,n.center);e.Cartesian3.add(U,I,U);var V=h;return V.x=T-B,V.y=E-L,V.z=D-k,e.Cartesian3.multiplyByScalar(V,.5,V),t.Matrix3.multiplyByScale(n.halfAxes,V,n.halfAxes),n};var b=new e.Cartesian3,y=new e.Cartesian3;function v(a,n,i,s,o,C,u,c,h,l,m){r.defined(m)||(m=new d);var x=m.halfAxes;t.Matrix3.setColumn(x,0,n,x),t.Matrix3.setColumn(x,1,i,x),t.Matrix3.setColumn(x,2,s,x);var p=b;p.x=(o+C)/2,p.y=(u+c)/2,p.z=(h+l)/2;var M=y;M.x=(C-o)/2,M.y=(c-u)/2,M.z=(l-h)/2;var f=m.center;return p=t.Matrix3.multiplyByVector(x,p,p),e.Cartesian3.add(a,p,f),t.Matrix3.multiplyByScale(x,M,x),m}var P=new e.Cartographic,O=new e.Cartesian3,z=new e.Cartographic,A=new e.Cartographic,N=new e.Cartographic,R=new e.Cartographic,I=new e.Cartographic,T=new e.Cartesian3,E=new e.Cartesian3,D=new e.Cartesian3,B=new e.Cartesian3,L=new e.Cartesian3,k=new t.Cartesian2,U=new t.Cartesian2,V=new t.Cartesian2,S=new t.Cartesian2,_=new t.Cartesian2,X=new e.Cartesian3,W=new e.Cartesian3,q=new e.Cartesian3,j=new e.Cartesian3,Z=new t.Cartesian2,F=new e.Cartesian3,G=new e.Cartesian3,Y=new e.Cartesian3,H=new o.Plane(e.Cartesian3.UNIT_X,0);d.fromRectangle=function(a,n,C,d,u){var c,h,l,m,x,p,M;if(n=r.defaultValue(n,0),C=r.defaultValue(C,0),d=r.defaultValue(d,t.Ellipsoid.WGS84),a.width<=s.Math3D.PI){var f=t.Rectangle.center(a,P),g=d.cartographicToCartesian(f,O),w=new i.EllipsoidTangentPlane(g,d);M=w.plane;var b=f.longitude,y=a.south<0&&a.north>0?0:f.latitude,J=e.Cartographic.fromRadians(b,a.north,C,z),K=e.Cartographic.fromRadians(a.west,a.north,C,A),Q=e.Cartographic.fromRadians(a.west,y,C,N),$=e.Cartographic.fromRadians(a.west,a.south,C,R),aa=e.Cartographic.fromRadians(b,a.south,C,I),ta=d.cartographicToCartesian(J,T),ea=d.cartographicToCartesian(K,E),na=d.cartographicToCartesian(Q,D),ra=d.cartographicToCartesian($,B),ia=d.cartographicToCartesian(aa,L),sa=w.projectPointToNearestOnPlane(ta,k),oa=w.projectPointToNearestOnPlane(ea,U),Ca=w.projectPointToNearestOnPlane(na,V),da=w.projectPointToNearestOnPlane(ra,S),ua=w.projectPointToNearestOnPlane(ia,_);return h=-(c=Math.min(oa.x,Ca.x,da.x)),m=Math.max(oa.y,sa.y),l=Math.min(da.y,ua.y),K.height=$.height=n,ea=d.cartographicToCartesian(K,E),ra=d.cartographicToCartesian($,B),x=Math.min(o.Plane.getPointDistance(M,ea),o.Plane.getPointDistance(M,ra)),p=C,v(w.origin,w.xAxis,w.yAxis,w.zAxis,c,h,l,m,x,p,u)}var ca=a.south>0,ha=a.north<0,la=ca?a.south:ha?a.north:0,ma=t.Rectangle.center(a,P).longitude,xa=e.Cartesian3.fromRadians(ma,la,C,d,X);xa.z=0;var pa=Math.abs(xa.x)<s.Math3D.EPSILON10&&Math.abs(xa.y)<s.Math3D.EPSILON10?e.Cartesian3.UNIT_X:e.Cartesian3.normalize(xa,W),Ma=e.Cartesian3.UNIT_Z,fa=e.Cartesian3.cross(pa,Ma,q);M=o.Plane.fromPointNormal(xa,pa,H);var ga=e.Cartesian3.fromRadians(ma+s.Math3D.PI_OVER_TWO,la,C,d,j);c=-(h=e.Cartesian3.dot(o.Plane.projectPointOntoPlane(M,ga,Z),fa)),m=e.Cartesian3.fromRadians(0,a.north,ha?n:C,d,F).z,l=e.Cartesian3.fromRadians(0,a.south,ca?n:C,d,G).z;var wa=e.Cartesian3.fromRadians(a.east,la,C,d,Y);return v(xa,fa,Ma,pa,c,h,l,m,x=o.Plane.getPointDistance(M,wa),p=0,u)},d.clone=function(a,n){if(r.defined(a))return r.defined(n)?(e.Cartesian3.clone(a.center,n.center),t.Matrix3.clone(a.halfAxes,n.halfAxes),n.areaDirty=1,n):new d(a.center,a.halfAxes)},d.intersectPlane=function(a,n){var r=a.center,i=n.normal,s=a.halfAxes,o=i.x,C=i.y,d=i.z,u=Math.abs(o*s[t.Matrix3.COLUMN0ROW0]+C*s[t.Matrix3.COLUMN0ROW1]+d*s[t.Matrix3.COLUMN0ROW2])+Math.abs(o*s[t.Matrix3.COLUMN1ROW0]+C*s[t.Matrix3.COLUMN1ROW1]+d*s[t.Matrix3.COLUMN1ROW2])+Math.abs(o*s[t.Matrix3.COLUMN2ROW0]+C*s[t.Matrix3.COLUMN2ROW1]+d*s[t.Matrix3.COLUMN2ROW2]),c=e.Cartesian3.dot(i,r)+n.distance;return c<=-u?t.Intersect.OUTSIDE:c>=u?t.Intersect.INSIDE:t.Intersect.INTERSECTING};var J=new e.Cartesian3,K=new e.Cartesian3,Q=new e.Cartesian3,$=new e.Cartesian3,aa=new e.Cartesian3;d.distanceSquaredTo=function(a,n){var r=e.Cartesian3.subtract(n,a.center,b),i=a.halfAxes,s=t.Matrix3.getColumn(i,0,J),o=t.Matrix3.getColumn(i,1,K),C=t.Matrix3.getColumn(i,2,Q),d=e.Cartesian3.magnitude(s),u=e.Cartesian3.magnitude(o),c=e.Cartesian3.magnitude(C);e.Cartesian3.normalize(s,s),e.Cartesian3.normalize(o,o),e.Cartesian3.normalize(C,C);var h=$;h.x=e.Cartesian3.dot(r,s),h.y=e.Cartesian3.dot(r,o),h.z=e.Cartesian3.dot(r,C);var l,m=0;return h.x<-d?m+=(l=h.x+d)*l:h.x>d&&(m+=(l=h.x-d)*l),h.y<-u?m+=(l=h.y+u)*l:h.y>u&&(m+=(l=h.y-u)*l),h.z<-c?m+=(l=h.z+c)*l:h.z>c&&(m+=(l=h.z-c)*l),m};var ta=new e.Cartesian3,ea=new e.Cartesian3;d.computePlaneDistances=function(a,n,i,s){r.defined(s)||(s=new t.Interval);var o=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY,d=a.center,u=a.halfAxes,c=t.Matrix3.getColumn(u,0,J),h=t.Matrix3.getColumn(u,1,K),l=t.Matrix3.getColumn(u,2,Q),m=e.Cartesian3.add(c,h,ta);e.Cartesian3.add(m,l,m),e.Cartesian3.add(m,d,m);var x=e.Cartesian3.subtract(m,n,ea),p=e.Cartesian3.dot(i,x);return o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.add(d,c,m),e.Cartesian3.add(m,h,m),e.Cartesian3.subtract(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.add(d,c,m),e.Cartesian3.subtract(m,h,m),e.Cartesian3.add(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.add(d,c,m),e.Cartesian3.subtract(m,h,m),e.Cartesian3.subtract(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.subtract(d,c,m),e.Cartesian3.add(m,h,m),e.Cartesian3.add(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.subtract(d,c,m),e.Cartesian3.add(m,h,m),e.Cartesian3.subtract(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.subtract(d,c,m),e.Cartesian3.subtract(m,h,m),e.Cartesian3.add(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),e.Cartesian3.subtract(d,c,m),e.Cartesian3.subtract(m,h,m),e.Cartesian3.subtract(m,l,m),e.Cartesian3.subtract(m,n,x),p=e.Cartesian3.dot(i,x),o=Math.min(p,o),C=Math.max(p,C),s.start=o,s.stop=C,s};var na=new t.BoundingSphere;d.isOccluded=function(a,e){var n=t.BoundingSphere.fromOrientedBoundingBox(a,na);return!e.isBoundingSphereVisible(n)},d.prototype.intersectPlane=function(a){return d.intersectPlane(this,a)},d.prototype.distanceSquaredTo=function(a){return d.distanceSquaredTo(this,a)},d.prototype.computePlaneDistances=function(a,t,e){return d.computePlaneDistances(this,a,t,e)},d.prototype.isOccluded=function(a){return d.isOccluded(this,a)},d.equals=function(a,n){return a===n||r.defined(a)&&r.defined(n)&&e.Cartesian3.equals(a.center,n.center)&&t.Matrix3.equals(a.halfAxes,n.halfAxes)},d.prototype.clone=function(a){return d.clone(this,a)},d.prototype.equals=function(a){return d.equals(this,a)};var ra=new e.Cartesian4;d.prototype._updateBBox=function(){if(1==this.areaDirty){var a=t.Matrix3.getColumn(this.halfAxes,0,J),n=e.Cartesian3.clone(e.Cartesian3.negate(a,f)),r=t.Matrix3.getColumn(this.halfAxes,1,K),i=e.Cartesian3.clone(e.Cartesian3.negate(r,f)),s=t.Matrix3.getColumn(this.halfAxes,2,Q),o=e.Cartesian3.clone(e.Cartesian3.negate(s,f));this.bbox=[],e.Cartesian3.add(this.center,r,f),e.Cartesian3.add(f,o,g),e.Cartesian3.add(g,n,w),this.bbox[0]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(g,a,w),this.bbox[1]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(f,s,g),e.Cartesian3.add(g,a,w),this.bbox[2]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(g,n,w),this.bbox[3]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(this.center,i,f),e.Cartesian3.add(f,o,g),e.Cartesian3.add(g,n,w),this.bbox[4]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(g,a,w),this.bbox[5]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(f,s,g),e.Cartesian3.add(g,a,w),this.bbox[6]=new e.Cartesian3(w.x,w.y,w.z),e.Cartesian3.add(g,n,w),this.bbox[7]=new e.Cartesian3(w.x,w.y,w.z);var C=e.Cartesian3.magnitude(a),d=e.Cartesian3.magnitude(r),u=e.Cartesian3.magnitude(s),c=new e.Cartesian3(-C,-d,-u),h=new e.Cartesian3(C,d,u);if(C*d*u==0)return void(this.areaDirty=-1);e.Cartesian3.normalize(a,a),e.Cartesian3.normalize(r,r),e.Cartesian3.normalize(s,s),this.u=e.Cartesian3.clone(a),this.v=e.Cartesian3.clone(r),this.w=e.Cartesian3.clone(s),this.posMin=c,this.posMaX=h,this.areaDirty=0}};var ia=[];ia.push(new t.Cartesian2),ia.push(new t.Cartesian2),ia.push(new t.Cartesian2),ia.push(new t.Cartesian2),ia.push(new t.Cartesian2),ia.push(new t.Cartesian2);var sa=new e.Cartographic,oa=new e.Cartesian3;d.prototype.calculateBoxArea=function(a,n,o,d,u,c,h,l){this._updateBBox();var m=a,x=e.Cartesian3.subtract(m,this.center,aa);if(-1==this.areaDirty){var p=u/d*(A=-1!=c?c:.5*e.Cartesian3.distance(this.posMaX,this.posMin))/o;return s.Math3D.PI*p*p}var M=e.Cartesian3.fromElements(e.Cartesian3.dot(x,this.u),e.Cartesian3.dot(x,this.v),e.Cartesian3.dot(x,this.w),ta),f=(M.x<this.posMin.x?1:0)+((M.x>this.posMaX.x?1:0)<<1)+((M.z<this.posMin.z?1:0)<<2)+((M.z>this.posMaX.z?1:0)<<3)+((M.y>this.posMaX.y?1:0)<<4)+((M.y<this.posMin.y?1:0)<<5);if(f>42)return console.log("area calculation is wrong"),-100;var g=C[f];if(0==g.num){p=u/d*(A=-1!=c?c:.5*e.Cartesian3.distance(this.posMaX,this.posMin))/o;return s.Math3D.PI*p*p}if(0==g.num)return console.log("area calculation is wrong"),-100;for(var w,b=[],y=h,v=0;v<g.num;v++){var P,O=ia[v],z=this.bbox[g.data[v]];w=!1;var A,N=s.Math3D.PI;if(3===n)(P=t.Matrix4.multiplyByVector(y,e.Cartesian4.fromElements(z.x,z.y,z.z,1),ra)).z<0&&(w=!0,-1==A&&(N=s.Math3D.PI_OVER_FOUR,o=e.Cartesian3.magnitude(x)));else{var R=l,I=R.ellipsoid.cartesianToCartographic(z,sa);r.defined(I)?(R.project(I,oa),(P=t.Matrix4.multiplyByVector(y,e.Cartesian4.fromElements(oa.z,oa.x,oa.y,1),ra)).z<0&&(w=!0)):w=!0}if(1==w)return N*(p=u/d*(A=-1!=c?c:.5*e.Cartesian3.distance(this.posMaX,this.posMin))/o)*p;O.x=P.x/P.w,O.y=u-P.y/P.w,b.push(O)}return Math.abs(i.PolygonPipeline.computeArea2D(b))},a.OrientedBoundingBox=d}));