/*
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/mathUtils","../../core/maybe","../../chunks/vec3","../../chunks/vec3f64","../../chunks/sphere","./vector","./vectorStacks","../../views/3d/support/mathUtils"],(function(t,n,e,r,c,o,i,u,s){"use strict";function a(t=G){return[t[0],t[1],t[2],t[3]]}function f(t=G[0],n=G[1],e=G[2],r=G[3]){return I(t,n,e,r,u.sv4d.get())}function d(t,n){return I(n[0],n[1],n[2],n[3],t)}function I(t,n,e,r,c=a()){return c[0]=t,c[1]=n,c[2]=e,c[3]=r,c}function l(t,n,e){return r.copy(e,t),e[3]=n,e}function g(t,n,e){const r=n[0]*n[0]+n[1]*n[1]+n[2]*n[2],c=Math.abs(r-1)>1e-5&&r>1e-12?1/Math.sqrt(r):1;return e[0]=n[0]*c,e[1]=n[1]*c,e[2]=n[2]*c,e[3]=-(e[0]*t[0]+e[1]*t[1]+e[2]*t[2]),e}function N(t,n,e,r=a()){const c=e[0]-n[0],o=e[1]-n[1],i=e[2]-n[2],u=t[0]-n[0],s=t[1]-n[1],f=t[2]-n[2],d=o*f-i*s,I=i*u-c*f,l=c*s-o*u,g=d*d+I*I+l*l,N=Math.abs(g-1)>1e-5&&g>1e-12?1/Math.sqrt(g):1;return r[0]=d*N,r[1]=I*N,r[2]=l*N,r[3]=-(r[0]*t[0]+r[1]*t[1]+r[2]*t[2]),r}function m(t,n){return M(t,n,0,1,2)}function M(t,n,e,c,o){if(t.count<3)return!1;t.getVec(e,v);let i=c,u=!1;for(;i<t.count-1&&!u;)t.getVec(i,P),i++,u=!r.exactEquals(v,P);if(!u)return!1;for(i=Math.max(i,o),u=!1;i<t.count&&!u;)t.getVec(i,h),i++,r.subtract(A,v,P),r.normalize(A,A),r.subtract(E,P,h),r.normalize(E,E),u=!r.exactEquals(v,h)&&!r.exactEquals(P,h)&&Math.abs(r.dot(A,E))<p;return u?(N(v,P,h,n),!0):(0!==e||1!==c||2!==o)&&M(t,n,0,1,2)}const p=.99619469809,v=c.create(),P=c.create(),h=c.create(),A=c.create(),E=c.create();function y(t,n,e){return n!==t&&d(t,n),t[3]=-r.dot(R(t),e),t}function F(t,n){return n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n[3]=-t[3],n}function b(t,n,e,c){return r.cross(h,n,t),g(e,h,c)}function S(t,n,e,c){return D(t,n,r.subtract(u.sv3d.get(),e,n),J,c)}function L(t,n,r){return!!e.isSome(n)&&D(t,n.origin,n.direction,K,r)}function _(t,n,e){return D(t,n.origin,n.vector,H.NONE,e)}function T(t,n,e){return D(t,n.origin,n.vector,H.CLAMP,e)}function O(t,n){return B(t,o.getCenter(n))-n[3]>=0}function j(t,n){return B(t,o.getCenter(n))+n[3]<0}function C(t,n){return B(t,n)>=0}function V(t,n){return B(t,n)<0}function q(t,n){const e=n[0],r=n[1],c=n[2],o=n[3],i=n[4],u=n[5];return t[0]*(t[0]>0?e:o)+t[1]*(t[1]>0?r:i)+t[2]*(t[2]>0?c:u)+t[3]>=0}function x(t,n){const e=r.dot(R(t),n.ray.direction),c=-B(t,n.ray.origin);if(c<0&&e>=0)return!1;if(e>-1e-6&&e<1e-6)return c>0;if((c<0||e<0)&&!(c<0&&e<0))return!0;const o=c/e;return e>0?o<n.c1&&(n.c1=o):o>n.c0&&(n.c0=o),n.c0<=n.c1}function X(t,n){const e=r.dot(R(t),n.ray.direction),c=-B(t,n.ray.origin);if(e>-1e-6&&e<1e-6)return c>0;const o=c/e;return e>0?o<n.c1&&(n.c1=o):o>n.c0&&(n.c0=o),n.c0<=n.c1}function k(t,n,e){const c=r.scale(u.sv3d.get(),R(t),-t[3]),o=w(t,r.subtract(u.sv3d.get(),n,c),u.sv3d.get());return r.add(e,o,c),e}function U(t,n,e,c){const o=R(t),a=u.sv3d.get(),f=u.sv3d.get();s.tangentFrame(o,a,f);const d=r.subtract(u.sv3d.get(),e,n),I=i.projectPointSignedLength(a,d),l=i.projectPointSignedLength(f,d),g=i.projectPointSignedLength(o,d);return r.set(c,I,l,g)}function w(t,n,e){const c=r.scale(u.sv3d.get(),R(t),r.dot(R(t),n));return r.subtract(e,n,c),e}function z(t,n){return Math.abs(B(t,n))}function B(t,n){return r.dot(R(t),n)+t[3]}function D(t,e,c,o,i){const u=r.dot(R(t),c);if(0===u)return!1;let s=-(r.dot(R(t),e)+t[3])/u;return o&H.CLAMP&&(s=n.clamp(s,0,1)),!(!(o&H.INFINITE_MIN)&&s<0||!(o&H.INFINITE_MAX)&&s>1)&&(r.add(i,e,r.scale(i,c,s)),!0)}function R(t){return t}const G=[0,0,1,0];var H;!function(t){t[t.NONE=0]="NONE",t[t.CLAMP=1]="CLAMP",t[t.INFINITE_MIN=4]="INFINITE_MIN",t[t.INFINITE_MAX=8]="INFINITE_MAX"}(H||(H={}));const J=H.INFINITE_MIN|H.INFINITE_MAX,K=H.INFINITE_MAX;t.UP=G,t.clip=x,t.clipInfinite=X,t.copy=d,t.create=a,t.distance=z,t.fromManyPoints=m,t.fromManyPointsSampleAt=M,t.fromNormalAndOffset=l,t.fromPoints=N,t.fromPositionAndNormal=g,t.fromValues=I,t.fromVectorsAndPoint=b,t.intersectLine=S,t.intersectLineSegment=_,t.intersectLineSegmentClamp=T,t.intersectRay=L,t.isAABBFullyInside=q,t.isPointInside=C,t.isPointOutside=V,t.isSphereFullyInside=O,t.isSphereFullyOutside=j,t.negate=F,t.normal=R,t.projectPoint=k,t.projectPointLocal=U,t.projectVector=w,t.setOffsetFromPoint=y,t.signedDistance=B,t.wrap=f,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
