1 |
- define(["exports","./Cartesian3-7e9cc2ff","./Matrix2-e3fb4559","./defaultValue-81eec7ed","./Check-741c5f3c","./Transforms-98ffa11d","./Math-5f585871","./Matrix4-d34187af"],(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,M=i*s-l,h=i*o-r*s,f=r*o-C,m=4*M*f-h*h;let d,g;if(m<0){let t,e,n;l*u>=c*C?(t=i,e=M,n=-2*r*M+i*h):(t=o,e=f,n=-o*h+2*s*f);const a=-(n<0?-1:1)*Math.abs(t)*Math.sqrt(-m);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 d=e<=0?w+R:-n/(w*w+R*R+e),l*u>=c*C?[(d-r)/i]:[-o/(d+s)]}const p=M,w=-2*r*M+i*h,R=f,S=-o*h+2*s*f,x=Math.sqrt(m),O=Math.sqrt(3)/2;let y=Math.abs(Math.atan2(i*x,-w)/3);d=2*Math.sqrt(-p);let P=Math.cos(y);g=d*P;let N=d*(-P/2-O*Math.sin(y));const b=g+N>2*r?g-r:N-r,q=i,L=b/q;y=Math.abs(Math.atan2(o*x,-S)/3),d=2*Math.sqrt(-R),P=Math.cos(y),g=d*P,N=d*(-P/2-O*Math.sin(y));const I=-o,E=g+N<2*s?g+s:N+s,z=I/E,T=-b*E-q*I,v=(s*T-r*(b*I))/(-r*T+s*(q*E));return L<=v?L<=z?v<=z?[L,v,z]:[L,z,v]:[z,L,v]:L<=z?[v,L,z]:v<=z?[v,z,L]:[z,v,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 M={};function h(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 f(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,M=o/2,h=u-4*a,f=u+4*Math.abs(a),m=i-4*r,d=i+4*Math.abs(r);let g,p,w,R,S,x;if(r<0||h*d<m*f){const e=Math.sqrt(m);g=e/2,p=0===e?0:(t*M-n)/e}else{const e=Math.sqrt(h);g=0===e?0:(t*M-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===M&&0===p?(S=0,x=0):s.CesiumMath.sign(M)===s.CesiumMath.sign(p)?(S=M+p,x=a/S):(x=M-p,S=a/x);const O=c.computeRealRoots(1,w,S),y=c.computeRealRoots(1,R,x);if(0!==O.length)return 0!==y.length?O[1]<=y[0]?[O[0],O[1],y[0],y[1]]:y[1]<=O[0]?[y[0],y[1],O[0],O[1]]:O[0]>=y[0]&&O[1]<=y[1]?[y[0],O[0],O[1],y[1]]:y[0]>=O[0]&&y[1]<=O[1]?[O[0],y[0],y[1],O[1]]:O[0]>y[0]&&O[0]<y[1]?[y[0],O[0],y[1],O[1]]:[O[0],y[0],O[1],y[1]]:O;if(0!==y.length)return y}return[]}function m(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}M.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,M=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)*(M*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)+M*(144*t*s*n-27*s*s-128*r*c-192*r*e*a)},M.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 h(r,o,c,u);case 1:case 2:case 5:case 8:case 11:return f(r,o,c,u);default:return}},m.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 m(t.origin,t.direction)},m.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 d={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;d.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),M=e.Cartesian3.cross(u,C,w),h=e.Cartesian3.dot(l,M);let f,m,d,x,O;if(o){if(h<s.CesiumMath.EPSILON6)return;if(f=e.Cartesian3.subtract(c,n,R),d=e.Cartesian3.dot(f,M),d<0||d>h)return;if(m=e.Cartesian3.cross(f,l,S),x=e.Cartesian3.dot(u,m),x<0||d+x>h)return;O=e.Cartesian3.dot(C,m)/h}else{if(Math.abs(h)<s.CesiumMath.EPSILON6)return;const t=1/h;if(f=e.Cartesian3.subtract(c,n,R),d=e.Cartesian3.dot(f,M)*t,d<0||d>1)return;if(m=e.Cartesian3.cross(f,l,S),x=e.Cartesian3.dot(u,m)*t,x<0||d+x>1)return;O=e.Cartesian3.dot(C,m)*t}return O},d.rayTriangle=function(t,n,i,r,s,o){const c=d.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 x=new m;d.lineSegmentTriangle=function(t,n,i,r,s,o,c){const u=x;e.Cartesian3.clone(t,u.origin),e.Cartesian3.subtract(n,t,u.direction),e.Cartesian3.normalize(u.direction,u.direction);const l=d.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 O={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,O);if(a.defined(C))return i.start=C.root0,i.stop=C.root1,i}d.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 m;d.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 N=new e.Cartesian3,b=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}d.rayEllipsoid=function(t,n){const a=n.oneOverRadii,i=e.Cartesian3.multiplyComponents(a,t.origin,N),s=e.Cartesian3.multiplyComponents(a,t.direction,b),o=e.Cartesian3.magnitudeSquared(i),c=e.Cartesian3.dot(i,s);let u,l,C,M,h;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){M=c*c-C,h=-c+Math.sqrt(M);const t=h/l,e=u/h;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,M=c*c-C,h=-c+Math.sqrt(M),new r.Interval(0,h/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,T=new e.Cartesian3,v=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;d.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),h=e.Cartesian3.mostOrthogonalAxis(l,z),f=e.Cartesian3.normalize(e.Cartesian3.cross(h,C,I),I),m=e.Cartesian3.normalize(e.Cartesian3.cross(C,f,E),E),d=v;d[0]=C.x,d[1]=C.y,d[2]=C.z,d[3]=f.x,d[4]=f.y,d[5]=f.z,d[6]=m.x,d[7]=m.y,d[8]=m.z;const g=o.Matrix3.transpose(d,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),x=o.Matrix3.multiply(o.Matrix3.multiply(S,p,A),d,A),O=o.Matrix3.multiplyByVector(S,i,T),y=function(t,n,a,i,r){const u=i*i,l=r*r,C=(t[o.Matrix3.COLUMN1ROW1]-t[o.Matrix3.COLUMN2ROW2])*l,h=r*(i*q(t[o.Matrix3.COLUMN1ROW0],t[o.Matrix3.COLUMN0ROW1],s.CesiumMath.EPSILON15)+n.y),f=t[o.Matrix3.COLUMN0ROW0]*u+t[o.Matrix3.COLUMN2ROW2]*l+i*n.x+a,m=l*q(t[o.Matrix3.COLUMN2ROW1],t[o.Matrix3.COLUMN1ROW2],s.CesiumMath.EPSILON15),d=r*(i*q(t[o.Matrix3.COLUMN2ROW0],t[o.Matrix3.COLUMN0ROW2])+n.z);let g;const p=[];if(0===d&&0===m){if(g=c.computeRealRoots(C,h,f),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=d*d,R=m*m,S=d*m,x=C*C+R,O=2*(h*C+S),y=2*f*C+h*h-R+w,P=2*(f*h-S),N=f*f-w;if(0===x&&0===O&&0===y&&0===P)return p;g=M.computeRealRoots(x,O,y,P,N);const b=g.length;if(0===b)return p;for(let t=0;t<b;++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(f)?q(C*a+f,h*n,s.CesiumMath.EPSILON12):s.CesiumMath.sign(f)===s.CesiumMath.sign(h*n)?q(C*a,h*n+f,s.CesiumMath.EPSILON12):q(C*a+h*n,f,s.CesiumMath.EPSILON12);const l=u*q(m*n,d,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}(x,e.Cartesian3.negate(O,L),0,0,1);let P,N;const b=y.length;if(b>0){let t=e.Cartesian3.clone(e.Cartesian3.ZERO,k),a=Number.NEGATIVE_INFINITY;for(let n=0;n<b;++n){P=o.Matrix3.multiplyByVector(p,o.Matrix3.multiplyByVector(d,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),N=e.Cartesian3.magnitude(e.Cartesian3.subtract(t,i,z))*Math.sqrt(1-a*a),N=u?-N:N,c.height=N,n.cartographicToCartesian(c,new e.Cartesian3)}};const G=new e.Cartesian3;d.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)},d.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,M=0;if(M+=o?1:0,M+=c?1:0,M+=u?1:0,1!==M&&2!==M||(l=new e.Cartesian3,C=new e.Cartesian3),1===M){if(o)return d.lineSegmentPlane(t,n,i,l),d.lineSegmentPlane(t,a,i,C),{positions:[t,n,a,l,C],indices:[0,3,4,1,2,4,1,4,3]};if(c)return d.lineSegmentPlane(n,a,i,l),d.lineSegmentPlane(n,t,i,C),{positions:[t,n,a,l,C],indices:[1,3,4,2,0,4,2,4,3]};if(u)return d.lineSegmentPlane(a,t,i,l),d.lineSegmentPlane(a,n,i,C),{positions:[t,n,a,l,C],indices:[2,3,4,0,1,4,0,4,3]}}else if(2===M){if(!o)return d.lineSegmentPlane(n,t,i,l),d.lineSegmentPlane(a,t,i,C),{positions:[t,n,a,l,C],indices:[1,2,4,1,4,3,0,3,4]};if(!c)return d.lineSegmentPlane(a,n,i,l),d.lineSegmentPlane(t,n,i,C),{positions:[t,n,a,l,C],indices:[2,0,4,2,4,3,1,3,4]};if(!u)return d.lineSegmentPlane(t,a,i,l),d.lineSegmentPlane(n,a,i,C),{positions:[t,n,a,l,C],indices:[0,1,4,0,4,3,2,3,4]}}},t.IntersectionTests=d,t.Ray=m}));
|