/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../core/arrayUtils","../../../../../core/mathUtils","../../../../../core/maybe","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/support/aaBoundingBox","../../lib/basicInterfaces","../../lib/screenSizePerspectiveUtils","../../lib/Util","../../lib/VertexAttribute","../renderers/utils"],(function(e,t,n,i,r,o,s,c,a,l,u,f){"use strict";const m=s.create();function p(e,t,n,i,r,o,s){if(!f.isInstanceHidden(t))if(e.boundingInfo){l.assert(e.primitiveType===c.PrimitiveType.Triangle);const t=n.tolerance;b(e.boundingInfo,i,r,t,o,s)}else{const t=e.indices.get(u.VertexAttribute.POSITION),n=e.vertexAttributes.get(u.VertexAttribute.POSITION);x(i,r,0,t.length/3,t,n,void 0,o,s)}}const d=o.create();function b(e,t,n,r,o,c){if(i.isNone(e))return;const a=I(t,n,d);if(s.setMin(m,e.getBBMin()),s.setMax(m,e.getBBMax()),i.isSome(o)&&o.applyToAabb(m),T(m,t,a,r)){const{primitiveIndices:i,indices:s,position:a}=e,l=i?i.length:s.length/3;if(l>B){const i=e.getChildren();if(void 0!==i){for(let e=0;e<8;++e)void 0!==i[e]&&b(i[e],t,n,r,o,c);return}}x(t,n,0,l,s,a,i,o,c)}}const h=o.create();function x(e,t,n,r,o,s,c,a,l){if(c)return g(e,t,n,r,o,s,c,a,l);const u=s.data,f=s.stride||s.size,m=e[0],p=e[1],d=e[2],b=t[0]-m,x=t[1]-p,M=t[2]-d;for(let g=n,v=3*n;g<r;++g){let e=f*o[v++],t=u[e++],n=u[e++],r=u[e];e=f*o[v++];let s=u[e++],c=u[e++],I=u[e];e=f*o[v++];let T=u[e++],A=u[e++],S=u[e];i.isSome(a)&&([t,n,r]=a.applyToVertex(t,n,r,g),[s,c,I]=a.applyToVertex(s,c,I,g),[T,A,S]=a.applyToVertex(T,A,S,g));const V=s-t,N=c-n,O=I-r,P=T-t,L=A-n,B=S-r,E=x*B-L*M,D=M*P-B*b,U=b*L-P*x,z=V*E+N*D+O*U;if(Math.abs(z)<=Number.EPSILON)continue;const W=m-t,R=p-n,_=d-r,k=W*E+R*D+_*U;if(z>0){if(k<0||k>z)continue}else if(k>0||k<z)continue;const G=R*O-N*_,H=_*V-O*W,j=W*N-V*R,C=b*G+x*H+M*j;if(z>0){if(C<0||k+C>z)continue}else if(C>0||k+C<z)continue;const X=(P*G+L*H+B*j)/z;if(X>=0){l(X,y(V,N,O,P,L,B,h),g,!1)}}}function g(e,t,n,r,o,s,c,a,l){const u=s.data,f=s.stride||s.size,m=e[0],p=e[1],d=e[2],b=t[0]-m,x=t[1]-p,g=t[2]-d;for(let M=n;M<r;++M){const e=c[M];let t=3*e,n=f*o[t++],r=u[n++],s=u[n++],v=u[n];n=f*o[t++];let I=u[n++],T=u[n++],A=u[n];n=f*o[t];let S=u[n++],V=u[n++],N=u[n];i.isSome(a)&&([r,s,v]=a.applyToVertex(r,s,v,M),[I,T,A]=a.applyToVertex(I,T,A,M),[S,V,N]=a.applyToVertex(S,V,N,M));const O=I-r,P=T-s,L=A-v,B=S-r,E=V-s,D=N-v,U=x*D-E*g,z=g*B-D*b,W=b*E-B*x,R=O*U+P*z+L*W;if(Math.abs(R)<=Number.EPSILON)continue;const _=m-r,k=p-s,G=d-v,H=_*U+k*z+G*W;if(R>0){if(H<0||H>R)continue}else if(H>0||H<R)continue;const j=k*L-P*G,C=G*O-L*_,X=_*P-O*k,Y=b*j+x*C+g*X;if(R>0){if(Y<0||H+Y>R)continue}else if(Y>0||H+Y<R)continue;const Z=(B*j+E*C+D*X)/R;if(Z>=0){l(Z,y(O,P,L,B,E,D,h),e,!1)}}}const M=o.create(),v=o.create();function y(e,t,n,i,o,s,c){return r.set(M,e,t,n),r.set(v,i,o,s),r.cross(c,M,v),r.normalize(c,c),c}function I(e,t,n){return r.set(n,1/(t[0]-e[0]),1/(t[1]-e[1]),1/(t[2]-e[2]))}function T(e,t,n,i){return A(e,t,n,i,1/0)}function A(e,t,n,i,r){const o=(e[0]-i-t[0])*n[0],s=(e[3]+i-t[0])*n[0];let c=Math.min(o,s),a=Math.max(o,s);const l=(e[1]-i-t[1])*n[1],u=(e[4]+i-t[1])*n[1];if(a=Math.min(a,Math.max(l,u)),a<0)return!1;if(c=Math.max(c,Math.min(l,u)),c>a)return!1;const f=(e[2]-i-t[2])*n[2],m=(e[5]+i-t[2])*n[2];return a=Math.min(a,Math.max(f,m)),!(a<0)&&(c=Math.max(c,Math.min(f,m)),!(c>a)&&c<r)}function S(e,t,r,o,s){let c=(r.screenLength||0)*e.pixelRatio;i.isSome(s)&&(c=a.scale(c,o,t,s));const l=c*Math.tan(.5*e.fovY)/(.5*e.fullHeight);return n.clamp(l*t,r.minWorldLength||0,null!=r.maxWorldLength?r.maxWorldLength:1/0)}function V(e,t){const n=t?V(t):{};for(const i in e){let t=e[i];t&&t.forEach&&(t=P(t)),null==t&&i in n||(n[i]=t)}return n}function N(e,n){let i=!1;for(const r in n){const o=n[r];void 0!==o&&(Array.isArray(o)?null===e[r]?(e[r]=o.slice(),i=!0):t.update(e[r],o)&&(i=!0):e[r]!==o&&(i=!0,e[r]=o))}return i}function O(e,t,i,r,o,s){if(!t.options.selectionMode)return;const c=e.vertexAttributes.get(u.VertexAttribute.POSITION).data,a=e.vertexAttributes.get(u.VertexAttribute.SIZE),l=a&&a.data[0],f=r[0],m=r[1],p=((l+o)/2+4)*e.screenToWorldRatio;let d=Number.MAX_VALUE,b=0;for(let u=0;u<c.length-5;u+=3){const e=c[u],t=c[u+1],i=f-e,r=m-t,o=c[u+3]-e,s=c[u+4]-t,a=o*i+s*r,l=o*o+s*s,p=n.clamp(a/l,0,1),h=o*p-i,x=s*p-r,g=h*h+x*x;g<d&&(d=g,b=u/3)}d<p*p&&s(i.dist,i.normal,b,!1)}function P(e){const t=[];return e.forEach((e=>t.push(e))),t}const L={multiply:1,ignore:2,replace:3,tint:4},B=1e3;e.colorMixModes=L,e.computeInvDir=I,e.computeNormal=y,e.copyParameters=V,e.intersectAabbInvDir=T,e.intersectAabbInvDirBefore=A,e.intersectDrapedRenderLineGeometry=O,e.intersectTriangleGeometry=p,e.intersectTriangles=x,e.updateParameters=N,e.verticalOffsetAtDistance=S,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
