define(["exports","./Matrix2-9aa31791","./when-4bbc8319","./RuntimeError-346a3079","./Transforms-d13cc04e","./ComponentDatatype-93750d1a"],(function(a,t,e,r,n,i){"use strict";var s={};function o(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 u={};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,m=s*u-h,f=s*C-o*u,d=o*C-M,v=4*m*d-f*f;if(v<0){var g,p,w;h*l>=c*M?(g=s,p=m,w=-2*o*m+s*f):(g=C,p=d,w=-C*f+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=m,P=-2*o*m+s*f,b=d,N=-C*f+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,D=-T*V-U*B,A=(u*D-o*(T*B))/(-o*D+u*(U*V));return W<=A?W<=Z?A<=Z?[W,A,Z]:[W,Z,A]:[Z,W,A]:W<=Z?[A,W,Z]:A<=Z?[A,Z,W]:[Z,A,W]}u.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)},u.computeRealRoots=function(a,t,e,r){var n,i;if(0===a)return s.computeRealRoots(t,e,r);if(0===t){if(0===e){if(0===r)return[0,0,0];var o=(i=-r/a)<0?-Math.pow(-i,1/3):Math.pow(i,1/3);return[o,o,o]}return 0===r?0===(n=s.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=s.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 c={};function l(a,t,e,r){var n=a*a,o=t-3*n/8,C=e-t*a/2+n*a/8,c=r-e*a/4+t*n/16-3*n*n/256,l=u.computeRealRoots(1,2*o,o*o-4*c,-C*C);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-(f=Math.sqrt(d)),h+f];if(d<0&&v>=0)return[h-(f=Math.sqrt(v)),h+f]}return[]}if(M>0){var w=Math.sqrt(M),R=(o+M-C/w)/2,S=(o+M+C/w)/2,O=s.computeRealRoots(1,w,R),x=s.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,m,f,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,w,p),(l=t.Cartesian3.dot(m,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,w,p),(l=t.Cartesian3.dot(m,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 w=new M;m.lineSegmentTriangle=function(a,r,n,i,s,o,u){var C=w;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 R={root0:0,root1:0};function S(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,v),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 x=new t.Cartesian3,y=new t.Cartesian3;function P(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 m=M*M;if(r=h-1,m<(s=(i=t.Cartesian3.magnitudeSquared(l))*r))return;if(m>s){o=M*M-s;var f=(u=-M+Math.sqrt(o))/i,d=r/u;return f=0)return n}var C=e.defined(this.rayEllipsoid(a,r)),l=r.transformPositionToScaledSpace(o,b),h=t.Cartesian3.normalize(l,l),M=t.Cartesian3.mostOrthogonalAxis(l,L),m=t.Cartesian3.normalize(t.Cartesian3.cross(M,h,N),N),f=t.Cartesian3.normalize(t.Cartesian3.cross(h,m,q),q),d=E;d[0]=h.x,d[1]=h.y,d[2]=h.z,d[3]=m.x,d[4]=m.y,d[5]=m.z,d[6]=f.x,d[7]=f.y,d[8]=f.z;var v=t.Matrix3.transpose(d,z),g=t.Matrix3.fromScale(r.radii,T),p=t.Matrix3.fromScale(r.oneOverRadii,U),w=W;w[0]=0,w[1]=-o.z,w[2]=o.y,w[3]=o.z,w[4]=0,w[5]=-o.x,w[6]=-o.y,w[7]=o.x,w[8]=0;var R,S,O=t.Matrix3.multiply(t.Matrix3.multiply(v,p,B),w,B),x=t.Matrix3.multiply(t.Matrix3.multiply(O,g,V),d,V),y=t.Matrix3.multiplyByVector(O,n,I),F=function(a,e,r,n,o){var u,C=n*n,l=o*o,h=(a[t.Matrix3.COLUMN1ROW1]-a[t.Matrix3.COLUMN2ROW2])*l,M=o*(n*P(a[t.Matrix3.COLUMN1ROW0],a[t.Matrix3.COLUMN0ROW1],i.CesiumMath.EPSILON15)+e.y),m=a[t.Matrix3.COLUMN0ROW0]*C+a[t.Matrix3.COLUMN2ROW2]*l+n*e.x+r,f=l*P(a[t.Matrix3.COLUMN2ROW1],a[t.Matrix3.COLUMN1ROW2],i.CesiumMath.EPSILON15),d=o*(n*P(a[t.Matrix3.COLUMN2ROW0],a[t.Matrix3.COLUMN0ROW2])+e.z),v=[];if(0===d&&0===f){if(0===(u=s.computeRealRoots(h,M,m)).length)return v;var g=u[0],p=Math.sqrt(Math.max(1-g*g,0));if(v.push(new t.Cartesian3(n,o*g,o*-p)),v.push(new t.Cartesian3(n,o*g,o*p)),2===u.length){var w=u[1],R=Math.sqrt(Math.max(1-w*w,0));v.push(new t.Cartesian3(n,o*w,o*-R)),v.push(new t.Cartesian3(n,o*w,o*R))}return v}var S=d*d,O=f*f,x=d*f,y=h*h+O,b=2*(M*h+x),N=2*m*h+M*M-O+S,q=2*(m*M-x),L=m*m-S;if(0===y&&0===b&&0===N&&0===q)return v;var I=(u=c.computeRealRoots(y,b,N,q,L)).length;if(0===I)return v;for(var E=0;E0?v.push(new t.Cartesian3(n,o*z,o*-W)):0!==W?(v.push(new t.Cartesian3(n,o*z,o*-W)),v.push(new t.Cartesian3(n,o*z,o*W)),++E):v.push(new t.Cartesian3(n,o*z,o*W))}return v}(x,t.Cartesian3.negate(y,b),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_&&(_=H,Y=t.Cartesian3.clone(R,Y))}var J=r.cartesianToCartographic(Y,A);return _=i.CesiumMath.clamp(_,0,1),S=t.Cartesian3.magnitude(t.Cartesian3.subtract(Y,n,L))*Math.sqrt(1-_*_),S=C?-S:S,J.height=S,r.cartographicToCartesian(J,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=M}));