IntersectionTests-a42760d9.js 14 KB

1
  1. define(["exports","./Cartographic-67e73ef9","./when-92c6cf3c","./Check-52a7d806","./buildModuleUrl-3d15f25c","./Math-92c3b5f7","./PrimitiveType-cdfe443e"],(function(e,t,r,n,i,a,o){"use strict";var u={};function s(e,t,r){var n=e+t;return a.e.sign(e)!==a.e.sign(t)&&Math.abs(n/Math.max(Math.abs(e),Math.abs(t)))<r?0:n}u.computeDiscriminant=function(e,t,r){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");return t*t-4*e*r},u.computeRealRoots=function(e,t,r){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");var i;if(0===e)return 0===t?[]:[-r/t];if(0===t){if(0===r)return[0,0];var o=Math.abs(r),u=Math.abs(e);if(o<u&&o/u<a.e.EPSILON14)return[0,0];if(o>u&&u/o<a.e.EPSILON14)return[];if((i=-r/e)<0)return[];var f=Math.sqrt(i);return[-f,f]}if(0===r)return(i=-t/e)<0?[i,0]:[0,i];var c=s(t*t,-(4*e*r),a.e.EPSILON14);if(c<0)return[];var w=-.5*s(t,a.e.sign(t)*Math.sqrt(c),a.e.EPSILON14);return t>0?[w/e,r/w]:[r/w,w/e]};var f={};function c(e,t,r,n){var i,a,o=e,u=t/3,s=r/3,f=n,c=o*s,w=u*f,h=u*u,l=s*s,p=o*s-h,d=o*f-u*s,m=u*f-l,b=4*p*m-d*d;if(b<0){var g,v,q;h*w>=c*l?(g=o,v=p,q=-2*u*p+o*d):(g=f,v=m,q=-f*d+2*s*m);var M=-(q<0?-1:1)*Math.abs(g)*Math.sqrt(-b),y=(a=-q+M)/2,R=y<0?-Math.pow(-y,1/3):Math.pow(y,1/3),S=a===M?-R:-v/R;return i=v<=0?R+S:-q/(R*R+S*S+v),h*w>=c*l?[(i-u)/o]:[-f/(i+s)]}var O=p,P=-2*u*p+o*d,N=m,L=-f*d+2*s*m,E=Math.sqrt(b),I=Math.sqrt(3)/2,C=Math.abs(Math.atan2(o*E,-P)/3);i=2*Math.sqrt(-O);var x=Math.cos(C);a=i*x;var z=i*(-x/2-I*Math.sin(C)),T=a+z>2*u?a-u:z-u,U=o,W=T/U;C=Math.abs(Math.atan2(f*E,-L)/3);var B=-f,Z=(a=(i=2*Math.sqrt(-N))*(x=Math.cos(C)))+(z=i*(-x/2-I*Math.sin(C)))<2*s?a+s:z+s,V=B/Z,A=-T*Z-U*B,D=(s*A-u*(T*B))/(-u*A+s*(U*Z));return W<=D?W<=V?D<=V?[W,D,V]:[W,V,D]:[V,W,D]:W<=V?[D,W,V]:D<=V?[D,V,W]:[V,D,W]}f.computeDiscriminant=function(e,t,r,i){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");if("number"!=typeof i)throw new n.t("d is a required number.");var a=t*t,o=r*r;return 18*e*t*r*i+a*o-27*(e*e)*(i*i)-4*(e*o*r+a*t*i)},f.computeRealRoots=function(e,t,r,i){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");if("number"!=typeof i)throw new n.t("d is a required number.");var a,o;if(0===e)return u.computeRealRoots(t,r,i);if(0===t){if(0===r){if(0===i)return[0,0,0];var s=(o=-i/e)<0?-Math.pow(-o,1/3):Math.pow(o,1/3);return[s,s,s]}return 0===i?0===(a=u.computeRealRoots(e,0,r)).Length?[0]:[a[0],0,a[1]]:c(e,0,r,i)}return 0===r?0===i?(o=-t/e)<0?[o,0,0]:[0,0,o]:c(e,t,0,i):0===i?0===(a=u.computeRealRoots(e,t,r)).length?[0]:a[1]<=0?[a[0],a[1],0]:a[0]>=0?[0,a[0],a[1]]:[a[0],0,a[1]]:c(e,t,r,i)};var w={};function h(e,t,r,n){var i=e*e,o=t-3*i/8,s=r-t*e/2+i*e/8,c=n-r*e/4+t*i/16-3*i*i/256,w=f.computeRealRoots(1,2*o,o*o-4*c,-s*s);if(w.length>0){var h=-e/4,l=w[w.length-1];if(Math.abs(l)<a.e.EPSILON14){var p=u.computeRealRoots(1,o,c);if(2===p.length){var d,m=p[0],b=p[1];if(m>=0&&b>=0){var g=Math.sqrt(m),v=Math.sqrt(b);return[h-v,h-g,h+g,h+v]}if(m>=0&&b<0)return[h-(d=Math.sqrt(m)),h+d];if(m<0&&b>=0)return[h-(d=Math.sqrt(b)),h+d]}return[]}if(l>0){var q=Math.sqrt(l),M=(o+l-s/q)/2,y=(o+l+s/q)/2,R=u.computeRealRoots(1,q,M),S=u.computeRealRoots(1,-q,y);return 0!==R.length?(R[0]+=h,R[1]+=h,0!==S.length?(S[0]+=h,S[1]+=h,R[1]<=S[0]?[R[0],R[1],S[0],S[1]]:S[1]<=R[0]?[S[0],S[1],R[0],R[1]]:R[0]>=S[0]&&R[1]<=S[1]?[S[0],R[0],R[1],S[1]]:S[0]>=R[0]&&S[1]<=R[1]?[R[0],S[0],S[1],R[1]]:R[0]>S[0]&&R[0]<S[1]?[S[0],R[0],S[1],R[1]]:[R[0],S[0],R[1],S[1]]):R):0!==S.length?(S[0]+=h,S[1]+=h,S):[]}}return[]}function l(e,t,r,n){var i=e*e,o=-2*t,s=r*e+t*t-4*n,c=i*n-r*t*e+r*r,w=f.computeRealRoots(1,o,s,c);if(w.length>0){var h,l,p,d,m,b,g=w[0],v=t-g,q=v*v,M=e/2,y=v/2,R=q-4*n,S=q+4*Math.abs(n),O=i-4*g,P=i+4*Math.abs(g);if(g<0||R*P<O*S){var N=Math.sqrt(O);h=N/2,l=0===N?0:(e*y-r)/N}else{var L=Math.sqrt(R);h=0===L?0:(e*y-r)/L,l=L/2}0===M&&0===h?(p=0,d=0):a.e.sign(M)===a.e.sign(h)?d=g/(p=M+h):p=g/(d=M-h),0===y&&0===l?(m=0,b=0):a.e.sign(y)===a.e.sign(l)?b=n/(m=y+l):m=n/(b=y-l);var E=u.computeRealRoots(1,p,m),I=u.computeRealRoots(1,d,b);if(0!==E.length)return 0!==I.length?E[1]<=I[0]?[E[0],E[1],I[0],I[1]]:I[1]<=E[0]?[I[0],I[1],E[0],E[1]]:E[0]>=I[0]&&E[1]<=I[1]?[I[0],E[0],E[1],I[1]]:I[0]>=E[0]&&I[1]<=E[1]?[E[0],I[0],I[1],E[1]]:E[0]>I[0]&&E[0]<I[1]?[I[0],E[0],I[1],E[1]]:[E[0],I[0],E[1],I[1]]:E;if(0!==I.length)return I}return[]}function p(e,n){n=t.t.clone(r.u(n,t.t.ZERO)),t.t.equals(n,t.t.ZERO)||t.t.normalize(n,n),this.origin=t.t.clone(r.u(e,t.t.ZERO)),this.direction=n}w.computeDiscriminant=function(e,t,r,i,a){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");if("number"!=typeof i)throw new n.t("d is a required number.");if("number"!=typeof a)throw new n.t("e is a required number.");var o=e*e,u=t*t,s=u*t,f=r*r,c=f*r,w=i*i,h=w*i,l=a*a;return u*f*w-4*s*h-4*e*c*w+18*e*t*r*h-27*o*w*w+256*(o*e)*(l*a)+a*(18*s*r*i-4*u*c+16*e*f*f-80*e*t*f*i-6*e*u*w+144*o*r*w)+l*(144*e*u*r-27*u*u-128*o*f-192*o*t*i)},w.computeRealRoots=function(e,t,r,i,o){if("number"!=typeof e)throw new n.t("a is a required number.");if("number"!=typeof t)throw new n.t("b is a required number.");if("number"!=typeof r)throw new n.t("c is a required number.");if("number"!=typeof i)throw new n.t("d is a required number.");if("number"!=typeof o)throw new n.t("e is a required number.");if(Math.abs(e)<a.e.EPSILON15)return f.computeRealRoots(t,r,i,o);var u=t/e,s=r/e,c=i/e,w=o/e,p=u<0?1:0;switch(p+=s<0?p+1:p,p+=c<0?p+1:p,p+=w<0?p+1:p){case 0:case 3:case 4:case 6:case 7:case 9:case 10:case 12:case 13:case 14:case 15:return h(u,s,c,w);case 1:case 2:case 5:case 8:case 11:return l(u,s,c,w);default:return}},p.clone=function(e,n){if(r.e(e))return r.e(n)?(n.origin=t.t.clone(e.origin),n.direction=t.t.clone(e.direction),n):new p(e.origin,e.direction)},p.getPoint=function(e,i,a){return n.o.typeOf.object("ray",e),n.o.typeOf.number("t",i),r.e(a)||(a=new t.t),a=t.t.multiplyByScalar(e.direction,i,a),t.t.add(e.origin,a,a)};var d={rayPlane:function(e,i,o){if(!r.e(e))throw new n.t("ray is required.");if(!r.e(i))throw new n.t("plane is required.");r.e(o)||(o=new t.t);var u=e.origin,s=e.direction,f=i.normal,c=t.t.dot(f,s);if(!(Math.abs(c)<a.e.EPSILON15)){var w=(-i.distance-t.t.dot(f,u))/c;if(!(w<0))return o=t.t.multiplyByScalar(s,w,o),t.t.add(u,o,o)}}},m=new t.t,b=new t.t,g=new t.t,v=new t.t,q=new t.t;d.rayTriangleParametric=function(e,i,o,u,s){if(!r.e(e))throw new n.t("ray is required.");if(!r.e(i))throw new n.t("p0 is required.");if(!r.e(o))throw new n.t("p1 is required.");if(!r.e(u))throw new n.t("p2 is required.");s=r.u(s,!1);var f,c,w,h,l,p=e.origin,d=e.direction,M=t.t.subtract(o,i,m),y=t.t.subtract(u,i,b),R=t.t.cross(d,y,g),S=t.t.dot(M,R);if(s){if(S<a.e.EPSILON6||(f=t.t.subtract(p,i,v),(w=t.t.dot(f,R))<0||w>S)||(c=t.t.cross(f,M,q),(h=t.t.dot(d,c))<0||w+h>S))return;l=t.t.dot(y,c)/S}else{if(Math.abs(S)<a.e.EPSILON6)return;var O=1/S;if(f=t.t.subtract(p,i,v),(w=t.t.dot(f,R)*O)<0||w>1||(c=t.t.cross(f,M,q),(h=t.t.dot(d,c)*O)<0||w+h>1))return;l=t.t.dot(y,c)*O}return l},d.rayTriangle=function(e,n,i,a,o,u){var s=d.rayTriangleParametric(e,n,i,a,o);if(r.e(s)&&!(s<0))return r.e(u)||(u=new t.t),t.t.multiplyByScalar(e.direction,s,u),t.t.add(e.origin,u,u)};var M=new p;d.lineSegmentTriangle=function(e,i,a,o,u,s,f){if(!r.e(e))throw new n.t("v0 is required.");if(!r.e(i))throw new n.t("v1 is required.");if(!r.e(a))throw new n.t("p0 is required.");if(!r.e(o))throw new n.t("p1 is required.");if(!r.e(u))throw new n.t("p2 is required.");var c=M;t.t.clone(e,c.origin),t.t.subtract(i,e,c.direction),t.t.normalize(c.direction,c.direction);var w=d.rayTriangleParametric(c,a,o,u,s);if(!(!r.e(w)||w<0||w>t.t.distance(e,i)))return r.e(f)||(f=new t.t),t.t.multiplyByScalar(c.direction,w,f),t.t.add(c.origin,f,f)};var y={root0:0,root1:0};function R(e,n,a){r.e(a)||(a=new i.o);var o=e.origin,u=e.direction,s=n.center,f=n.radius*n.radius,c=t.t.subtract(o,s,g),w=function(e,t,r,n){var i=t*t-4*e*r;if(!(i<0)){if(i>0){var a=1/(2*e),o=Math.sqrt(i),u=(-t+o)*a,s=(-t-o)*a;return u<s?(n.root0=u,n.root1=s):(n.root0=s,n.root1=u),n}var f=-t/(2*e);if(0!==f)return n.root0=n.root1=f,n}}(t.t.dot(u,u),2*t.t.dot(u,c),t.t.magnitudeSquared(c)-f,y);if(r.e(w))return a.start=w.root0,a.stop=w.root1,a}d.raySphere=function(e,t,i){if(!r.e(e))throw new n.t("ray is required.");if(!r.e(t))throw new n.t("sphere is required.");if(i=R(e,t,i),r.e(i)&&!(i.stop<0))return i.start=Math.max(i.start,0),i};var S=new p;d.lineSegmentSphere=function(e,i,a,o){if(!r.e(e))throw new n.t("p0 is required.");if(!r.e(i))throw new n.t("p1 is required.");if(!r.e(a))throw new n.t("sphere is required.");var u=S;t.t.clone(e,u.origin);var s=t.t.subtract(i,e,u.direction),f=t.t.magnitude(s);if(t.t.normalize(s,s),o=R(u,a,o),!(!r.e(o)||o.stop<0||o.start>f))return o.start=Math.max(o.start,0),o.stop=Math.min(o.stop,f),o};var O=new t.t,P=new t.t;function N(e,t,r){var n=e+t;return a.e.sign(e)!==a.e.sign(t)&&Math.abs(n/Math.max(Math.abs(e),Math.abs(t)))<r?0:n}function L(e,r,n,i,s){var f,c=i*i,h=s*s,l=(e[o.p.COLUMN1ROW1]-e[o.p.COLUMN2ROW2])*h,p=s*(i*N(e[o.p.COLUMN1ROW0],e[o.p.COLUMN0ROW1],a.e.EPSILON15)+r.y),d=e[o.p.COLUMN0ROW0]*c+e[o.p.COLUMN2ROW2]*h+i*r.x+n,m=h*N(e[o.p.COLUMN2ROW1],e[o.p.COLUMN1ROW2],a.e.EPSILON15),b=s*(i*N(e[o.p.COLUMN2ROW0],e[o.p.COLUMN0ROW2])+r.z),g=[];if(0===b&&0===m){if(0===(f=u.computeRealRoots(l,p,d)).length)return g;var v=f[0],q=Math.sqrt(Math.max(1-v*v,0));if(g.push(new t.t(i,s*v,s*-q)),g.push(new t.t(i,s*v,s*q)),2===f.length){var M=f[1],y=Math.sqrt(Math.max(1-M*M,0));g.push(new t.t(i,s*M,s*-y)),g.push(new t.t(i,s*M,s*y))}return g}var R=b*b,S=m*m,O=b*m,P=l*l+S,L=2*(p*l+O),E=2*d*l+p*p-S+R,I=2*(d*p-O),C=d*d-R;if(0===P&&0===L&&0===E&&0===I)return g;var x=(f=w.computeRealRoots(P,L,E,I,C)).length;if(0===x)return g;for(var z=0;z<x;++z){var T=f[z],U=T*T,W=Math.max(1-U,0),B=Math.sqrt(W),Z=(a.e.sign(l)===a.e.sign(d)?N(l*U+d,p*T,a.e.EPSILON12):a.e.sign(d)===a.e.sign(p*T)?N(l*U,p*T+d,a.e.EPSILON12):N(l*U+p*T,d,a.e.EPSILON12))*N(m*T,b,a.e.EPSILON15);Z<0?g.push(new t.t(i,s*T,s*B)):Z>0?g.push(new t.t(i,s*T,s*-B)):0!==B?(g.push(new t.t(i,s*T,s*-B)),g.push(new t.t(i,s*T,s*B)),++z):g.push(new t.t(i,s*T,s*B))}return g}d.rayEllipsoid=function(e,a){if(!r.e(e))throw new n.t("ray is required.");if(!r.e(a))throw new n.t("ellipsoid is required.");var o,u,s,f,c,w=a.oneOverRadii,h=t.t.multiplyComponents(w,e.origin,O),l=t.t.multiplyComponents(w,e.direction,P),p=t.t.magnitudeSquared(h),d=t.t.dot(h,l);if(p>1){if(d>=0)return;var m=d*d;if(o=p-1,m<(s=(u=t.t.magnitudeSquared(l))*o))return;if(m>s){f=d*d-s;var b=(c=-d+Math.sqrt(f))/u,g=o/c;return b<g?new i.o(b,g):{start:g,stop:b}}var v=Math.sqrt(o/u);return new i.o(v,v)}return p<1?(o=p-1,f=d*d-(s=(u=t.t.magnitudeSquared(l))*o),c=-d+Math.sqrt(f),new i.o(0,c/u)):d<0?(u=t.t.magnitudeSquared(l),new i.o(0,-d/u)):void 0};var E=new t.t,I=new t.t,C=new t.t,x=new t.t,z=new t.t,T=new o.p,U=new o.p,W=new o.p,B=new o.p,Z=new o.p,V=new o.p,A=new o.p,D=new t.t,j=new t.t,k=new t.t$1;d.grazingAltitudeLocation=function(e,i){if(!r.e(e))throw new n.t("ray is required.");if(!r.e(i))throw new n.t("ellipsoid is required.");var u=e.origin,s=e.direction;if(!t.t.equals(u,t.t.ZERO)){var f=i.geodeticSurfaceNormal(u,E);if(t.t.dot(s,f)>=0)return u}var c=r.e(this.rayEllipsoid(e,i)),w=i.transformPositionToScaledSpace(s,E),h=t.t.normalize(w,w),l=t.t.mostOrthogonalAxis(w,x),p=t.t.normalize(t.t.cross(l,h,I),I),d=t.t.normalize(t.t.cross(h,p,C),C),m=T;m[0]=h.x,m[1]=h.y,m[2]=h.z,m[3]=p.x,m[4]=p.y,m[5]=p.z,m[6]=d.x,m[7]=d.y,m[8]=d.z;var b=o.p.transpose(m,U),g=o.p.fromScale(i.radii,W),v=o.p.fromScale(i.oneOverRadii,B),q=Z;q[0]=0,q[1]=-s.z,q[2]=s.y,q[3]=s.z,q[4]=0,q[5]=-s.x,q[6]=-s.y,q[7]=s.x,q[8]=0;var M,y,R=o.p.multiply(o.p.multiply(b,v,V),q,V),S=o.p.multiply(o.p.multiply(R,g,A),m,A),O=o.p.multiplyByVector(R,u,z),P=L(S,t.t.negate(O,E),0,0,1),N=P.length;if(N>0){for(var F=t.t.clone(t.t.ZERO,j),G=Number.NEGATIVE_INFINITY,Y=0;Y<N;++Y){M=o.p.multiplyByVector(g,o.p.multiplyByVector(m,P[Y],D),D);var $=t.t.normalize(t.t.subtract(M,u,x),x),_=t.t.dot($,s);_>G&&(G=_,F=t.t.clone(M,F))}var H=i.cartesianToCartographic(F,k);return G=a.e.clamp(G,0,1),y=t.t.magnitude(t.t.subtract(F,u,x))*Math.sqrt(1-G*G),y=c?-y:y,H.height=y,i.cartographicToCartesian(H,new t.t)}};var F=new t.t;d.lineSegmentPlane=function(e,i,o,u){if(!r.e(e))throw new n.t("endPoint0 is required.");if(!r.e(i))throw new n.t("endPoint1 is required.");if(!r.e(o))throw new n.t("plane is required.");r.e(u)||(u=new t.t);var s=t.t.subtract(i,e,F),f=o.normal,c=t.t.dot(f,s);if(!(Math.abs(c)<a.e.EPSILON6)){var w=t.t.dot(f,e),h=-(o.distance+w)/c;if(!(h<0||h>1))return t.t.multiplyByScalar(s,h,u),t.t.add(e,u,u),u}},d.trianglePlaneIntersection=function(e,i,a,o){if(!(r.e(e)&&r.e(i)&&r.e(a)&&r.e(o)))throw new n.t("p0, p1, p2, and plane are required.");var u,s,f=o.normal,c=o.distance,w=t.t.dot(f,e)+c<0,h=t.t.dot(f,i)+c<0,l=t.t.dot(f,a)+c<0,p=0;if(p+=w?1:0,p+=h?1:0,(1===(p+=l?1:0)||2===p)&&(u=new t.t,s=new t.t),1===p){if(w)return d.lineSegmentPlane(e,i,o,u),d.lineSegmentPlane(e,a,o,s),{positions:[e,i,a,u,s],indices:[0,3,4,1,2,4,1,4,3]};if(h)return d.lineSegmentPlane(i,a,o,u),d.lineSegmentPlane(i,e,o,s),{positions:[e,i,a,u,s],indices:[1,3,4,2,0,4,2,4,3]};if(l)return d.lineSegmentPlane(a,e,o,u),d.lineSegmentPlane(a,i,o,s),{positions:[e,i,a,u,s],indices:[2,3,4,0,1,4,0,4,3]}}else if(2===p){if(!w)return d.lineSegmentPlane(i,e,o,u),d.lineSegmentPlane(a,e,o,s),{positions:[e,i,a,u,s],indices:[1,2,4,1,4,3,0,3,4]};if(!h)return d.lineSegmentPlane(a,i,o,u),d.lineSegmentPlane(e,i,o,s),{positions:[e,i,a,u,s],indices:[2,0,4,2,4,3,1,3,4]};if(!l)return d.lineSegmentPlane(e,a,o,u),d.lineSegmentPlane(i,a,o,s),{positions:[e,i,a,u,s],indices:[0,1,4,0,4,3,2,3,4]}}},e.f=p,e.g=d}));