/*
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/ObjectStack","../../chunks/vec3","../../chunks/vec3f64","./lineSegment","./vectorStacks"],(function(t,e,c,n,r,s){"use strict";function o(t){return t?{p0:n.clone(t.p0),p1:n.clone(t.p1),p2:n.clone(t.p2)}:{p0:n.create(),p1:n.create(),p2:n.create()}}function u(t,e,c){const n=v.get();return n.p0=t,n.p1=e,n.p2=c,n}function a(t,e=o()){return p(t.p0,t.p1,t.p2,e)}function p(t,e,n,r=o()){return c.copy(r.p0,t),c.copy(r.p1,e),c.copy(r.p2,n),r}function i(t,e){const n=t.p0,o=t.p1,u=t.p2,a=c.subtract(s.sv3d.get(),o,n),p=c.subtract(s.sv3d.get(),u,o),i=c.subtract(s.sv3d.get(),n,u),d=c.subtract(s.sv3d.get(),e,n),f=c.subtract(s.sv3d.get(),e,o),l=c.subtract(s.sv3d.get(),e,u),g=c.cross(a,a,i),v=c.dot(c.cross(s.sv3d.get(),a,g),d),m=c.dot(c.cross(s.sv3d.get(),p,g),f),S=c.dot(c.cross(s.sv3d.get(),i,g),l);if(v>0&&m>0&&S>0){const t=c.dot(g,d);return t*t/c.dot(g,g)}const k=r.distance2(r.fromValues(n,a,b.get()),e),y=r.distance2(r.fromValues(o,p,b.get()),e),h=r.distance2(r.fromValues(u,i,b.get()),e);return Math.min(k,y,h)}function d(t,e,n){const r=1e-5,{direction:s,origin:o}=e,{p0:u,p1:a,p2:p}=t,i=a[0]-u[0],d=a[1]-u[1],f=a[2]-u[2],l=p[0]-u[0],g=p[1]-u[1],b=p[2]-u[2],v=s[1]*b-g*s[2],m=s[2]*l-b*s[0],S=s[0]*g-l*s[1],k=i*v+d*m+f*S;if(k>-r&&k<r)return!1;const y=1/k,h=o[0]-u[0],j=o[1]-u[1],M=o[2]-u[2],O=y*(h*v+j*m+M*S);if(O<0||O>1)return!1;const V=j*f-d*M,w=M*i-f*h,P=h*d-i*j,_=y*(s[0]*V+s[1]*w+s[2]*P);if(_<0||O+_>1)return!1;if(n){const t=y*(l*V+g*w+b*P);c.scale(n,s,t),c.add(n,o,n)}return!0}function f(t,e,c){const n=e[0]-t[0],r=e[1]-t[1],s=c[0]-t[0],o=c[1]-t[1];return.5*Math.abs(n*o-r*s)}function l(t){return f(t.p0,t.p1,t.p2)}function g(t,e,n){return c.subtract(m,e,t),c.subtract(S,n,t),c.length(c.cross(m,m,S))/2}const b=new e.ObjectStack(r.create),v=new e.ObjectStack((()=>({p0:null,p1:null,p2:null}))),m=n.create(),S=n.create();t.area2d=l,t.areaPoints2d=f,t.areaPoints3d=g,t.copy=a,t.create=o,t.distance2=i,t.fromValues=p,t.intersectRay=d,t.wrap=u,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
