/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{clamp as t,Float as u,length as n,distance as r,Vec3 as i,and as y,greaterThan as s,lessThan as l,cond as c,not as e,Mat3 as a,abs as o,step as p,dot as x,normalize as m,equal as b,min as d}from"../../graph/glsl.js";import{epsilonHitTest as w}from"./constants.js";import{cross2 as f}from"./utils.js";function v(t,u){return x(t,m(u))}function j(i,y,s){const l=s.subtract(y),c=v(i.subtract(y),l),e=t(c.divide(n(l)),new u(0),new u(1));return r(i,y.add(e.multiply(s.subtract(y))))}function g(t){const n=o(t);return p(n.x.add(n.y).add(n.z),new u(1.05))}function h(t,n,r,y){const s=new a(r.x.multiply(y.y).subtract(y.x.multiply(r.y)),y.x.multiply(n.y).subtract(n.x.multiply(y.y)),n.x.multiply(r.y).subtract(r.x.multiply(n.y)),r.y.subtract(y.y),y.y.subtract(n.y),n.y.subtract(r.y),y.x.subtract(r.x),n.x.subtract(y.x),r.x.subtract(n.x)),l=n.x.multiply(r.y.subtract(y.y)),c=r.x.multiply(y.y.subtract(n.y)),e=y.x.multiply(n.y.subtract(r.y)),o=l.add(c).add(e);return new u(1).divide(o).multiply(s.multiply(new i(1,t)))}function M(t,n,r,i){return b(g(h(t,n,r,i)),new u(1))}function P(t,n,r,i){const a=r.subtract(n),o=i.subtract(n),p=f(a,o),x=y(l(p,new u(w)),s(p,new u(-w)));return c([y(e(x),M(t.xy,n,r,i)),new u(-1)],[!0,()=>{const u=j(t,n,r),y=j(t,r,i),s=j(t,i,n);return d(d(u,y),s)}])}function q(t){return t.distance.add(1)}function z(t,u,n){const{viewMat3:r,tileMat3:y}=t.view,s=r.multiply(y),l=s.multiply(new i(u.pos,1)),c=s.multiply(new i(n.nextPos1,1)),e=s.multiply(new i(n.nextPos2,1));return P(t.hittestRequest.position,l.xy,c.xy,e.xy)}function R(t,u,n){return r(t,n).subtract(u)}export{j as distPointSegment,P as distPointTriangle,q as failHittest,z as hittestFill,R as hittestMarker,g as inTriangle,v as projectScalar,h as xyToBarycentric};
