2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
define(["exports","./Cartesian3-e0307675","./Cartesian2-bd414876","./defaultValue-81eec7ed","./Check-741c5f3c","./BoundingSphere-9a3b5656","./Math-e73894ab","./Matrix4-4c545f70"],(function(t,e,n,a,i,r,s,o){"use strict";const c={};function u(t,e,n){const a=t+e;return s.CesiumMath.sign(t)!==s.CesiumMath.sign(e)&&Math.abs(a/Math.max(Math.abs(t),Math.abs(e)))<n?0:a}c.computeDiscriminant=function(t,e,n){return e*e-4*t*n},c.computeRealRoots=function(t,e,n){let a;if(0===t)return 0===e?[]:[-n/e];if(0===e){if(0===n)return[0,0];const e=Math.abs(n),i=Math.abs(t);if(e<i&&e/i<s.CesiumMath.EPSILON14)return[0,0];if(e>i&&i/e<s.CesiumMath.EPSILON14)return[];if(a=-n/t,a<0)return[];const r=Math.sqrt(a);return[-r,r]}if(0===n)return a=-e/t,a<0?[a,0]:[0,a];const i=u(e*e,-(4*t*n),s.CesiumMath.EPSILON14);if(i<0)return[];const r=-.5*u(e,s.CesiumMath.sign(e)*Math.sqrt(i),s.CesiumMath.EPSILON14);return e>0?[r/t,n/r]:[n/r,r/t]};const l={};function C(t,e,n,a){const i=t,r=e/3,s=n/3,o=a,c=i*s,u=r*o,l=r*r,C=s*s,h=i*s-l,M=i*o-r*s,d=r*o-C,f=4*h*d-M*M;let m,g;if(f<0){let t,e,n;l*u>=c*C?(t=i,e=h,n=-2*r*h+i*M):(t=o,e=d,n=-o*M+2*s*d);const a=-(n<0?-1:1)*Math.abs(t)*Math.sqrt(-f);g=-n+a;const p=g/2,w=p<0?-Math.pow(-p,1/3):Math.pow(p,1/3),R=g===a?-w:-e/w;return m=e<=0?w+R:-n/(w*w+R*R+e),l*u>=c*C?[(m-r)/i]:[-o/(m+s)]}const p=h,w=-2*r*h+i*M,R=d,S=-o*M+2*s*d,O=Math.sqrt(f),x=Math.sqrt(3)/2;let y=Math.abs(Math.atan2(i*O,-w)/3);m=2*Math.sqrt(-p);let P=Math.cos(y);g=m*P;let b=m*(-P/2-x*Math.sin(y));const N=g+b>2*r?g-r:b-r,q=i,L=N/q;y=Math.abs(Math.atan2(o*O,-S)/3),m=2*Math.sqrt(-R),P=Math.cos(y),g=m*P,b=m*(-P/2-x*Math.sin(y));const I=-o,E=g+b<2*s?g+s:b+s,z=I/E,v=-N*E-q*I,T=(s*v-r*(N*I))/(-r*v+s*(q*E));return L<=T?L<=z?T<=z?[L,T,z]:[L,z,T]:[z,L,T]:L<=z?[T,L,z]:T<=z?[T,z,L]:[z,T,L]}l.computeDiscriminant=function(t,e,n,a){const i=e*e,r=n*n;return 18*t*e*n*a+i*r-27*(t*t)*(a*a)-4*(t*r*n+i*e*a)},l.computeRealRoots=function(t,e,n,a){let i,r;if(0===t)return c.computeRealRoots(e,n,a);if(0===e){if(0===n){if(0===a)return[0,0,0];r=-a/t;const e=r<0?-Math.pow(-r,1/3):Math.pow(r,1/3);return[e,e,e]}return 0===a?(i=c.computeRealRoots(t,0,n),0===i.Length?[0]:[i[0],0,i[1]]):C(t,0,n,a)}return 0===n?0===a?(r=-e/t,r<0?[r,0,0]:[0,0,r]):C(t,e,0,a):0===a?(i=c.computeRealRoots(t,e,n),0===i.length?[0]:i[1]<=0?[i[0],i[1],0]:i[0]>=0?[0,i[0],i[1]]:[i[0],0,i[1]]):C(t,e,n,a)};const h={};function M(t,e,n,a){const i=t*t,r=e-3*i/8,o=n-e*t/2+i*t/8,u=a-n*t/4+e*i/16-3*i*i/256,C=l.computeRealRoots(1,2*r,r*r-4*u,-o*o);if(C.length>0){const e=-t/4,n=C[C.length-1];if(Math.abs(n)<s.CesiumMath.EPSILON14){const t=c.computeRealRoots(1,r,u);if(2===t.length){const n=t[0],a=t[1];let i;if(n>=0&&a>=0){const t=Math.sqrt(n),i=Math.sqrt(a);return[e-i,e-t,e+t,e+i]}if(n>=0&&a<0)return i=Math.sqrt(n),[e-i,e+i];if(n<0&&a>=0)return i=Math.sqrt(a),[e-i,e+i]}return[]}if(n>0){const t=Math.sqrt(n),a=(r+n-o/t)/2,i=(r+n+o/t)/2,s=c.computeRealRoots(1,t,a),u=c.computeRealRoots(1,-t,i);return 0!==s.length?(s[0]+=e,s[1]+=e,0!==u.length?(u[0]+=e,u[1]+=e,s[1]<=u[0]?[s[0],s[1],u[0],u[1]]:u[1]<=s[0]?[u[0],u[1],s[0],s[1]]:s[0]>=u[0]&&s[1]<=u[1]?[u[0],s[0],s[1],u[1]]:u[0]>=s[0]&&u[1]<=s[1]?[s[0],u[0],u[1],s[1]]:s[0]>u[0]&&s[0]<u[1]?[u[0],s[0],u[1],s[1]]:[s[0],u[0],s[1],u[1]]):s):0!==u.length?(u[0]+=e,u[1]+=e,u):[]}}return[]}function d(t,e,n,a){const i=t*t,r=-2*e,o=n*t+e*e-4*a,u=i*a-n*e*t+n*n,C=l.computeRealRoots(1,r,o,u);if(C.length>0){const r=C[0],o=e-r,u=o*o,l=t/2,h=o/2,M=u-4*a,d=u+4*Math.abs(a),f=i-4*r,m=i+4*Math.abs(r);let g,p,w,R,S,O;if(r<0||M*m<f*d){const e=Math.sqrt(f);g=e/2,p=0===e?0:(t*h-n)/e}else{const e=Math.sqrt(M);g=0===e?0:(t*h-n)/e,p=e/2}0===l&&0===g?(w=0,R=0):s.CesiumMath.sign(l)===s.CesiumMath.sign(g)?(w=l+g,R=r/w):(R=l-g,w=r/R),0===h&&0===p?(S=0,O=0):s.CesiumMath.sign(h)===s.CesiumMath.sign(p)?(S=h+p,O=a/S):(O=h-p,S=a/O);const x=c.computeRealRoots(1,w,S),y=c.computeRealRoots(1,R,O);if(0!==x.length)return 0!==y.length?x[1]<=y[0]?[x[0],x[1],y[0],y[1]]:y[1]<=x[0]?[y[0],y[1],x[0],x[1]]:x[0]>=y[0]&&x[1]<=y[1]?[y[0],x[0],x[1],y[1]]:y[0]>=x[0]&&y[1]<=x[1]?[x[0],y[0],y[1],x[1]]:x[0]>y[0]&&x[0]<y[1]?[y[0],x[0],y[1],x[1]]:[x[0],y[0],x[1],y[1]]:x;if(0!==y.length)return y}return[]}function f(t,n){n=e.Cartesian3.clone(a.defaultValue(n,e.Cartesian3.ZERO)),e.Cartesian3.equals(n,e.Cartesian3.ZERO)||e.Cartesian3.normalize(n,n),this.origin=e.Cartesian3.clone(a.defaultValue(t,e.Cartesian3.ZERO)),this.direction=n}h.computeDiscriminant=function(t,e,n,a,i){const r=t*t,s=e*e,o=s*e,c=n*n,u=c*n,l=a*a,C=l*a,h=i*i;return s*c*l-4*o*C-4*t*u*l+18*t*e*n*C-27*r*l*l+256*(r*t)*(h*i)+i*(18*o*n*a-4*s*u+16*t*c*c-80*t*e*c*a-6*t*s*l+144*r*n*l)+h*(144*t*s*n-27*s*s-128*r*c-192*r*e*a)},h.computeRealRoots=function(t,e,n,a,i){if(Math.abs(t)<s.CesiumMath.EPSILON15)return l.computeRealRoots(e,n,a,i);const r=e/t,o=n/t,c=a/t,u=i/t;let C=r<0?1:0;switch(C+=o<0?C+1:C,C+=c<0?C+1:C,C+=u<0?C+1:C,C){case 0:case 3:case 4:case 6:case 7:case 9:case 10:case 12:case 13:case 14:case 15:return M(r,o,c,u);case 1:case 2:case 5:case 8:case 11:return d(r,o,c,u);default:return}},f.clone=function(t,n){if(a.defined(t))return a.defined(n)?(n.origin=e.Cartesian3.clone(t.origin),n.direction=e.Cartesian3.clone(t.direction),n):new f(t.origin,t.direction)},f.getPoint=function(t,n,i){return a.defined(i)||(i=new e.Cartesian3),i=e.Cartesian3.multiplyByScalar(t.direction,n,i),e.Cartesian3.add(t.origin,i,i)};const m={rayPlane:function(t,n,i){a.defined(i)||(i=new e.Cartesian3);const r=t.origin,o=t.direction,c=n.normal,u=e.Cartesian3.dot(c,o);if(Math.abs(u)<s.CesiumMath.EPSILON15)return;const l=(-n.distance-e.Cartesian3.dot(c,r))/u;return l<0?void 0:(i=e.Cartesian3.multiplyByScalar(o,l,i),e.Cartesian3.add(r,i,i))}},g=new e.Cartesian3,p=new e.Cartesian3,w=new e.Cartesian3,R=new e.Cartesian3,S=new e.Cartesian3;m.rayTriangleParametric=function(t,n,i,r,o){o=a.defaultValue(o,!1);const c=t.origin,u=t.direction,l=e.Cartesian3.subtract(i,n,g),C=e.Cartesian3.subtract(r,n,p),h=e.Cartesian3.cross(u,C,w),M=e.Cartesian3.dot(l,h);let d,f,m,O,x;if(o){if(M<s.CesiumMath.EPSILON6)return;if(d=e.Cartesian3.subtract(c,n,R),m=e.Cartesian3.dot(d,h),m<0||m>M)return;if(f=e.Cartesian3.cross(d,l,S),O=e.Cartesian3.dot(u,f),O<0||m+O>M)return;x=e.Cartesian3.dot(C,f)/M}else{if(Math.abs(M)<s.CesiumMath.EPSILON6)return;const t=1/M;if(d=e.Cartesian3.subtract(c,n,R),m=e.Cartesian3.dot(d,h)*t,m<0||m>1)return;if(f=e.Cartesian3.cross(d,l,S),O=e.Cartesian3.dot(u,f)*t,O<0||m+O>1)return;x=e.Cartesian3.dot(C,f)*t}return x},m.rayTriangle=function(t,n,i,r,s,o){const c=m.rayTriangleParametric(t,n,i,r,s);if(a.defined(c)&&!(c<0))return a.defined(o)||(o=new e.Cartesian3),e.Cartesian3.multiplyByScalar(t.direction,c,o),e.Cartesian3.add(t.origin,o,o)};const O=new f;m.lineSegmentTriangle=function(t,n,i,r,s,o,c){const u=O;e.Cartesian3.clone(t,u.origin),e.Cartesian3.subtract(n,t,u.direction),e.Cartesian3.normalize(u.direction,u.direction);const l=m.rayTriangleParametric(u,i,r,s,o);if(!(!a.defined(l)||l<0||l>e.Cartesian3.distance(t,n)))return a.defined(c)||(c=new e.Cartesian3),e.Cartesian3.multiplyByScalar(u.direction,l,c),e.Cartesian3.add(u.origin,c,c)};const x={root0:0,root1:0};function y(t,n,i){a.defined(i)||(i=new r.Interval);const s=t.origin,o=t.direction,c=n.center,u=n.radius*n.radius,l=e.Cartesian3.subtract(s,c,w),C=function(t,e,n,a){const i=e*e-4*t*n;if(i<0)return;if(i>0){const n=1/(2*t),r=Math.sqrt(i),s=(-e+r)*n,o=(-e-r)*n;return s<o?(a.root0=s,a.root1=o):(a.root0=o,a.root1=s),a}const r=-e/(2*t);return 0!==r?(a.root0=a.root1=r,a):void 0}(e.Cartesian3.dot(o,o),2*e.Cartesian3.dot(o,l),e.Cartesian3.magnitudeSquared(l)-u,x);if(a.defined(C))return i.start=C.root0,i.stop=C.root1,i}m.raySphere=function(t,e,n){if(n=y(t,e,n),a.defined(n)&&!(n.stop<0))return n.start=Math.max(n.start,0),n};const P=new f;m.lineSegmentSphere=function(t,n,i,r){const s=P;e.Cartesian3.clone(t,s.origin);const o=e.Cartesian3.subtract(n,t,s.direction),c=e.Cartesian3.magnitude(o);if(e.Cartesian3.normalize(o,o),r=y(s,i,r),!(!a.defined(r)||r.stop<0||r.start>c))return r.start=Math.max(r.start,0),r.stop=Math.min(r.stop,c),r};const b=new e.Cartesian3,N=new e.Cartesian3;function q(t,e,n){const a=t+e;return s.CesiumMath.sign(t)!==s.CesiumMath.sign(e)&&Math.abs(a/Math.max(Math.abs(t),Math.abs(e)))<n?0:a}m.rayEllipsoid=function(t,n){const a=n.oneOverRadii,i=e.Cartesian3.multiplyComponents(a,t.origin,b),s=e.Cartesian3.multiplyComponents(a,t.direction,N),o=e.Cartesian3.magnitudeSquared(i),c=e.Cartesian3.dot(i,s);let u,l,C,h,M;if(o>1){if(c>=0)return;const t=c*c;if(u=o-1,l=e.Cartesian3.magnitudeSquared(s),C=l*u,t<C)return;if(t>C){h=c*c-C,M=-c+Math.sqrt(h);const t=M/l,e=u/M;return t<e?new r.Interval(t,e):{start:e,stop:t}}const n=Math.sqrt(u/l);return new r.Interval(n,n)}return o<1?(u=o-1,l=e.Cartesian3.magnitudeSquared(s),C=l*u,h=c*c-C,M=-c+Math.sqrt(h),new r.Interval(0,M/l)):c<0?(l=e.Cartesian3.magnitudeSquared(s),new r.Interval(0,-c/l)):void 0};const L=new e.Cartesian3,I=new e.Cartesian3,E=new e.Cartesian3,z=new e.Cartesian3,v=new e.Cartesian3,T=new o.Matrix3,U=new o.Matrix3,W=new o.Matrix3,B=new o.Matrix3,V=new o.Matrix3,Z=new o.Matrix3,A=new o.Matrix3,D=new e.Cartesian3,k=new e.Cartesian3,F=new n.Cartographic;m.grazingAltitudeLocation=function(t,n){const i=t.origin,r=t.direction;if(!e.Cartesian3.equals(i,e.Cartesian3.ZERO)){const t=n.geodeticSurfaceNormal(i,L);if(e.Cartesian3.dot(r,t)>=0)return i}const u=a.defined(this.rayEllipsoid(t,n)),l=n.transformPositionToScaledSpace(r,L),C=e.Cartesian3.normalize(l,l),M=e.Cartesian3.mostOrthogonalAxis(l,z),d=e.Cartesian3.normalize(e.Cartesian3.cross(M,C,I),I),f=e.Cartesian3.normalize(e.Cartesian3.cross(C,d,E),E),m=T;m[0]=C.x,m[1]=C.y,m[2]=C.z,m[3]=d.x,m[4]=d.y,m[5]=d.z,m[6]=f.x,m[7]=f.y,m[8]=f.z;const g=o.Matrix3.transpose(m,U),p=o.Matrix3.fromScale(n.radii,W),w=o.Matrix3.fromScale(n.oneOverRadii,B),R=V;R[0]=0,R[1]=-r.z,R[2]=r.y,R[3]=r.z,R[4]=0,R[5]=-r.x,R[6]=-r.y,R[7]=r.x,R[8]=0;const S=o.Matrix3.multiply(o.Matrix3.multiply(g,w,Z),R,Z),O=o.Matrix3.multiply(o.Matrix3.multiply(S,p,A),m,A),x=o.Matrix3.multiplyByVector(S,i,v),y=function(t,n,a,i,r){const u=i*i,l=r*r,C=(t[o.Matrix3.COLUMN1ROW1]-t[o.Matrix3.COLUMN2ROW2])*l,M=r*(i*q(t[o.Matrix3.COLUMN1ROW0],t[o.Matrix3.COLUMN0ROW1],s.CesiumMath.EPSILON15)+n.y),d=t[o.Matrix3.COLUMN0ROW0]*u+t[o.Matrix3.COLUMN2ROW2]*l+i*n.x+a,f=l*q(t[o.Matrix3.COLUMN2ROW1],t[o.Matrix3.COLUMN1ROW2],s.CesiumMath.EPSILON15),m=r*(i*q(t[o.Matrix3.COLUMN2ROW0],t[o.Matrix3.COLUMN0ROW2])+n.z);let g;const p=[];if(0===m&&0===f){if(g=c.computeRealRoots(C,M,d),0===g.length)return p;const t=g[0],n=Math.sqrt(Math.max(1-t*t,0));if(p.push(new e.Cartesian3(i,r*t,r*-n)),p.push(new e.Cartesian3(i,r*t,r*n)),2===g.length){const t=g[1],n=Math.sqrt(Math.max(1-t*t,0));p.push(new e.Cartesian3(i,r*t,r*-n)),p.push(new e.Cartesian3(i,r*t,r*n))}return p}const w=m*m,R=f*f,S=m*f,O=C*C+R,x=2*(M*C+S),y=2*d*C+M*M-R+w,P=2*(d*M-S),b=d*d-w;if(0===O&&0===x&&0===y&&0===P)return p;g=h.computeRealRoots(O,x,y,P,b);const N=g.length;if(0===N)return p;for(let t=0;t<N;++t){const n=g[t],a=n*n,o=Math.max(1-a,0),c=Math.sqrt(o);let u;u=s.CesiumMath.sign(C)===s.CesiumMath.sign(d)?q(C*a+d,M*n,s.CesiumMath.EPSILON12):s.CesiumMath.sign(d)===s.CesiumMath.sign(M*n)?q(C*a,M*n+d,s.CesiumMath.EPSILON12):q(C*a+M*n,d,s.CesiumMath.EPSILON12);const l=u*q(f*n,m,s.CesiumMath.EPSILON15);l<0?p.push(new e.Cartesian3(i,r*n,r*c)):l>0?p.push(new e.Cartesian3(i,r*n,r*-c)):0!==c?(p.push(new e.Cartesian3(i,r*n,r*-c)),p.push(new e.Cartesian3(i,r*n,r*c)),++t):p.push(new e.Cartesian3(i,r*n,r*c))}return p}(O,e.Cartesian3.negate(x,L),0,0,1);let P,b;const N=y.length;if(N>0){let t=e.Cartesian3.clone(e.Cartesian3.ZERO,k),a=Number.NEGATIVE_INFINITY;for(let n=0;n<N;++n){P=o.Matrix3.multiplyByVector(p,o.Matrix3.multiplyByVector(m,y[n],D),D);const s=e.Cartesian3.normalize(e.Cartesian3.subtract(P,i,z),z),c=e.Cartesian3.dot(s,r);c>a&&(a=c,t=e.Cartesian3.clone(P,t))}const c=n.cartesianToCartographic(t,F);return a=s.CesiumMath.clamp(a,0,1),b=e.Cartesian3.magnitude(e.Cartesian3.subtract(t,i,z))*Math.sqrt(1-a*a),b=u?-b:b,c.height=b,n.cartographicToCartesian(c,new e.Cartesian3)}};const G=new e.Cartesian3;m.lineSegmentPlane=function(t,n,i,r){a.defined(r)||(r=new e.Cartesian3);const o=e.Cartesian3.subtract(n,t,G),c=i.normal,u=e.Cartesian3.dot(c,o);if(Math.abs(u)<s.CesiumMath.EPSILON6)return;const l=e.Cartesian3.dot(c,t),C=-(i.distance+l)/u;return C<0||C>1?void 0:(e.Cartesian3.multiplyByScalar(o,C,r),e.Cartesian3.add(t,r,r),r)},m.trianglePlaneIntersection=function(t,n,a,i){const r=i.normal,s=i.distance,o=e.Cartesian3.dot(r,t)+s<0,c=e.Cartesian3.dot(r,n)+s<0,u=e.Cartesian3.dot(r,a)+s<0;let l,C,h=0;if(h+=o?1:0,h+=c?1:0,h+=u?1:0,1!==h&&2!==h||(l=new e.Cartesian3,C=new e.Cartesian3),1===h){if(o)return m.lineSegmentPlane(t,n,i,l),m.lineSegmentPlane(t,a,i,C),{positions:[t,n,a,l,C],indices:[0,3,4,1,2,4,1,4,3]};if(c)return m.lineSegmentPlane(n,a,i,l),m.lineSegmentPlane(n,t,i,C),{positions:[t,n,a,l,C],indices:[1,3,4,2,0,4,2,4,3]};if(u)return m.lineSegmentPlane(a,t,i,l),m.lineSegmentPlane(a,n,i,C),{positions:[t,n,a,l,C],indices:[2,3,4,0,1,4,0,4,3]}}else if(2===h){if(!o)return m.lineSegmentPlane(n,t,i,l),m.lineSegmentPlane(a,t,i,C),{positions:[t,n,a,l,C],indices:[1,2,4,1,4,3,0,3,4]};if(!c)return m.lineSegmentPlane(a,n,i,l),m.lineSegmentPlane(t,n,i,C),{positions:[t,n,a,l,C],indices:[2,0,4,2,4,3,1,3,4]};if(!u)return m.lineSegmentPlane(t,a,i,l),m.lineSegmentPlane(n,a,i,C),{positions:[t,n,a,l,C],indices:[0,1,4,0,4,3,2,3,4]}}},t.IntersectionTests=m,t.Ray=f}));
|