define(["exports","./Cartographic-3309dd0d","./when-b60132fc","./Check-7b2a090c","./buildModuleUrl-4e1b81e7","./Math-119be1a3","./PrimitiveType-a54dc62f"],(function(a,t,e,r,n,i,s){"use strict";var o={};function u(a,t,e){var r=a+t;return i.CesiumMath.sign(a)!==i.CesiumMath.sign(t)&&Math.abs(r/Math.max(Math.abs(a),Math.abs(t)))s&&s/n0?[c/a,e/c]:[e/c,c/a]};var C={};function c(a,t,e,r){var n,i,s=a,o=t/3,u=e/3,C=r,c=s*u,l=o*C,h=o*o,M=u*u,f=s*u-h,m=s*C-o*u,d=o*C-M,v=4*f*d-m*m;if(v<0){var g,p,w;h*l>=c*M?(g=s,p=f,w=-2*o*f+s*m):(g=C,p=d,w=-C*m+2*u*d);var R=-(w<0?-1:1)*Math.abs(g)*Math.sqrt(-v),S=(i=-w+R)/2,O=S<0?-Math.pow(-S,1/3):Math.pow(S,1/3),x=i===R?-O:-p/O;return n=p<=0?O+x:-w/(O*O+x*x+p),h*l>=c*M?[(n-o)/s]:[-C/(n+u)]}var y=f,P=-2*o*f+s*m,b=d,N=-C*m+2*u*d,q=Math.sqrt(v),L=Math.sqrt(3)/2,I=Math.abs(Math.atan2(s*q,-P)/3);n=2*Math.sqrt(-y);var E=Math.cos(I);i=n*E;var z=n*(-E/2-L*Math.sin(I)),T=i+z>2*o?i-o:z-o,U=s,W=T/U;I=Math.abs(Math.atan2(C*q,-N)/3);var B=-C,V=(i=(n=2*Math.sqrt(-b))*(E=Math.cos(I)))+(z=n*(-E/2-L*Math.sin(I)))<2*u?i+u:z+u,Z=B/V,A=-T*V-U*B,D=(u*A-o*(T*B))/(-o*A+u*(U*V));return W<=D?W<=Z?D<=Z?[W,D,Z]:[W,Z,D]:[Z,W,D]:W<=Z?[D,W,Z]:D<=Z?[D,Z,W]:[Z,D,W]}C.computeDiscriminant=function(a,t,e,r){var n=t*t,i=e*e;return 18*a*t*e*r+n*i-27*(a*a)*(r*r)-4*(a*i*e+n*t*r)},C.computeRealRoots=function(a,t,e,r){var n,i;if(0===a)return o.computeRealRoots(t,e,r);if(0===t){if(0===e){if(0===r)return[0,0,0];var s=(i=-r/a)<0?-Math.pow(-i,1/3):Math.pow(i,1/3);return[s,s,s]}return 0===r?0===(n=o.computeRealRoots(a,0,e)).Length?[0]:[n[0],0,n[1]]:c(a,0,e,r)}return 0===e?0===r?(i=-t/a)<0?[i,0,0]:[0,0,i]:c(a,t,0,r):0===r?0===(n=o.computeRealRoots(a,t,e)).length?[0]:n[1]<=0?[n[0],n[1],0]:n[0]>=0?[0,n[0],n[1]]:[n[0],0,n[1]]:c(a,t,e,r)};var l={};function h(a,t,e,r){var n=a*a,s=t-3*n/8,u=e-t*a/2+n*a/8,c=r-e*a/4+t*n/16-3*n*n/256,l=C.computeRealRoots(1,2*s,s*s-4*c,-u*u);if(l.length>0){var h=-a/4,M=l[l.length-1];if(Math.abs(M)=0&&v>=0){var g=Math.sqrt(d),p=Math.sqrt(v);return[h-p,h-g,h+g,h+p]}if(d>=0&&v<0)return[h-(m=Math.sqrt(d)),h+m];if(d<0&&v>=0)return[h-(m=Math.sqrt(v)),h+m]}return[]}if(M>0){var w=Math.sqrt(M),R=(s+M-u/w)/2,S=(s+M+u/w)/2,O=o.computeRealRoots(1,w,R),x=o.computeRealRoots(1,-w,S);return 0!==O.length?(O[0]+=h,O[1]+=h,0!==x.length?(x[0]+=h,x[1]+=h,O[1]<=x[0]?[O[0],O[1],x[0],x[1]]:x[1]<=O[0]?[x[0],x[1],O[0],O[1]]:O[0]>=x[0]&&O[1]<=x[1]?[x[0],O[0],O[1],x[1]]:x[0]>=O[0]&&x[1]<=O[1]?[O[0],x[0],x[1],O[1]]:O[0]>x[0]&&O[0]0){var h,M,f,m,d,v,g=l[0],p=t-g,w=p*p,R=a/2,S=p/2,O=w-4*r,x=w+4*Math.abs(r),y=n-4*g,P=n+4*Math.abs(g);if(g<0||O*P=L[0]&&q[1]<=L[1]?[L[0],q[0],q[1],L[1]]:L[0]>=q[0]&&L[1]<=q[1]?[q[0],L[0],L[1],q[1]]:q[0]>L[0]&&q[0]O)return;if(C=t.Cartesian3.cross(u,m,w),(l=t.Cartesian3.dot(f,C))<0||c+l>O)return;h=t.Cartesian3.dot(R,C)/O}else{if(Math.abs(O)1)return;if(C=t.Cartesian3.cross(u,m,w),(l=t.Cartesian3.dot(f,C)*x)<0||c+l>1)return;h=t.Cartesian3.dot(R,C)*x}return h},m.rayTriangle=function(a,r,n,i,s,o){var u=m.rayTriangleParametric(a,r,n,i,s);if(e.defined(u)&&!(u<0))return e.defined(o)||(o=new t.Cartesian3),t.Cartesian3.multiplyByScalar(a.direction,u,o),t.Cartesian3.add(a.origin,o,o)};var R=new f;m.lineSegmentTriangle=function(a,r,n,i,s,o,u){var C=R;t.Cartesian3.clone(a,C.origin),t.Cartesian3.subtract(r,a,C.direction),t.Cartesian3.normalize(C.direction,C.direction);var c=m.rayTriangleParametric(C,n,i,s,o);if(!(!e.defined(c)||c<0||c>t.Cartesian3.distance(a,r)))return e.defined(u)||(u=new t.Cartesian3),t.Cartesian3.multiplyByScalar(C.direction,c,u),t.Cartesian3.add(C.origin,u,u)};var S={root0:0,root1:0};function O(a,r,i){e.defined(i)||(i=new n.Interval);var s=a.origin,o=a.direction,u=r.center,C=r.radius*r.radius,c=t.Cartesian3.subtract(s,u,g),l=function(a,t,e,r){var n=t*t-4*a*e;if(!(n<0)){if(n>0){var i=1/(2*a),s=Math.sqrt(n),o=(-t+s)*i,u=(-t-s)*i;return ou))return i.start=Math.max(i.start,0),i.stop=Math.min(i.stop,u),i};var y=new t.Cartesian3,P=new t.Cartesian3;function b(a,t,e){var r=a+t;return i.CesiumMath.sign(a)!==i.CesiumMath.sign(t)&&Math.abs(r/Math.max(Math.abs(a),Math.abs(t)))1){if(M>=0)return;var f=M*M;if(r=h-1,f<(s=(i=t.Cartesian3.magnitudeSquared(l))*r))return;if(f>s){o=M*M-s;var m=(u=-M+Math.sqrt(o))/i,d=r/u;return m=0)return n}var c=e.defined(this.rayEllipsoid(a,r)),h=r.transformPositionToScaledSpace(u,N),M=t.Cartesian3.normalize(h,h),f=t.Cartesian3.mostOrthogonalAxis(h,I),m=t.Cartesian3.normalize(t.Cartesian3.cross(f,M,q),q),d=t.Cartesian3.normalize(t.Cartesian3.cross(M,m,L),L),v=z;v[0]=M.x,v[1]=M.y,v[2]=M.z,v[3]=m.x,v[4]=m.y,v[5]=m.z,v[6]=d.x,v[7]=d.y,v[8]=d.z;var g=s.Matrix3.transpose(v,T),p=s.Matrix3.fromScale(r.radii,U),w=s.Matrix3.fromScale(r.oneOverRadii,W),R=B;R[0]=0,R[1]=-u.z,R[2]=u.y,R[3]=u.z,R[4]=0,R[5]=-u.x,R[6]=-u.y,R[7]=u.x,R[8]=0;var S,O,x=s.Matrix3.multiply(s.Matrix3.multiply(g,w,V),R,V),y=s.Matrix3.multiply(s.Matrix3.multiply(x,p,Z),v,Z),P=s.Matrix3.multiplyByVector(x,n,E),F=function(a,e,r,n,u){var C,c=n*n,h=u*u,M=(a[s.Matrix3.COLUMN1ROW1]-a[s.Matrix3.COLUMN2ROW2])*h,f=u*(n*b(a[s.Matrix3.COLUMN1ROW0],a[s.Matrix3.COLUMN0ROW1],i.CesiumMath.EPSILON15)+e.y),m=a[s.Matrix3.COLUMN0ROW0]*c+a[s.Matrix3.COLUMN2ROW2]*h+n*e.x+r,d=h*b(a[s.Matrix3.COLUMN2ROW1],a[s.Matrix3.COLUMN1ROW2],i.CesiumMath.EPSILON15),v=u*(n*b(a[s.Matrix3.COLUMN2ROW0],a[s.Matrix3.COLUMN0ROW2])+e.z),g=[];if(0===v&&0===d){if(0===(C=o.computeRealRoots(M,f,m)).length)return g;var p=C[0],w=Math.sqrt(Math.max(1-p*p,0));if(g.push(new t.Cartesian3(n,u*p,u*-w)),g.push(new t.Cartesian3(n,u*p,u*w)),2===C.length){var R=C[1],S=Math.sqrt(Math.max(1-R*R,0));g.push(new t.Cartesian3(n,u*R,u*-S)),g.push(new t.Cartesian3(n,u*R,u*S))}return g}var O=v*v,x=d*d,y=v*d,P=M*M+x,N=2*(f*M+y),q=2*m*M+f*f-x+O,L=2*(m*f-y),I=m*m-O;if(0===P&&0===N&&0===q&&0===L)return g;var E=(C=l.computeRealRoots(P,N,q,L,I)).length;if(0===E)return g;for(var z=0;z0?g.push(new t.Cartesian3(n,u*T,u*-B)):0!==B?(g.push(new t.Cartesian3(n,u*T,u*-B)),g.push(new t.Cartesian3(n,u*T,u*B)),++z):g.push(new t.Cartesian3(n,u*T,u*B))}return g}(y,t.Cartesian3.negate(P,N),0,0,1),G=F.length;if(G>0){for(var Y=t.Cartesian3.clone(t.Cartesian3.ZERO,D),_=Number.NEGATIVE_INFINITY,j=0;j_&&(_=J,Y=t.Cartesian3.clone(S,Y))}var K=r.cartesianToCartographic(Y,k);return _=i.CesiumMath.clamp(_,0,1),O=t.Cartesian3.magnitude(t.Cartesian3.subtract(Y,n,I))*Math.sqrt(1-_*_),O=c?-O:O,K.height=O,r.cartographicToCartesian(K,new t.Cartesian3)}};var F=new t.Cartesian3;m.lineSegmentPlane=function(a,r,n,s){e.defined(s)||(s=new t.Cartesian3);var o=t.Cartesian3.subtract(r,a,F),u=n.normal,C=t.Cartesian3.dot(u,o);if(!(Math.abs(C)1))return t.Cartesian3.multiplyByScalar(o,l,s),t.Cartesian3.add(a,s,s),s}},m.trianglePlaneIntersection=function(a,e,r,n){var i,s,o=n.normal,u=n.distance,C=t.Cartesian3.dot(o,a)+u<0,c=t.Cartesian3.dot(o,e)+u<0,l=t.Cartesian3.dot(o,r)+u<0,h=0;if(h+=C?1:0,h+=c?1:0,1!==(h+=l?1:0)&&2!==h||(i=new t.Cartesian3,s=new t.Cartesian3),1===h){if(C)return m.lineSegmentPlane(a,e,n,i),m.lineSegmentPlane(a,r,n,s),{positions:[a,e,r,i,s],indices:[0,3,4,1,2,4,1,4,3]};if(c)return m.lineSegmentPlane(e,r,n,i),m.lineSegmentPlane(e,a,n,s),{positions:[a,e,r,i,s],indices:[1,3,4,2,0,4,2,4,3]};if(l)return m.lineSegmentPlane(r,a,n,i),m.lineSegmentPlane(r,e,n,s),{positions:[a,e,r,i,s],indices:[2,3,4,0,1,4,0,4,3]}}else if(2===h){if(!C)return m.lineSegmentPlane(e,a,n,i),m.lineSegmentPlane(r,a,n,s),{positions:[a,e,r,i,s],indices:[1,2,4,1,4,3,0,3,4]};if(!c)return m.lineSegmentPlane(r,e,n,i),m.lineSegmentPlane(a,e,n,s),{positions:[a,e,r,i,s],indices:[2,0,4,2,4,3,1,3,4]};if(!l)return m.lineSegmentPlane(a,r,n,i),m.lineSegmentPlane(e,r,n,s),{positions:[a,e,r,i,s],indices:[0,1,4,0,4,3,2,3,4]}}},a.IntersectionTests=m,a.Ray=f}));