/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{floatEqualAbsolute as t}from"../../core/mathUtils.js";import{subtract as n,scaleAndAdd as r,add as e,length as s,dot as o,squaredLength as c,scale as u,distance as i,copy as f}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as a,clone as p}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";function m(t,n){return t[0]*n[1]-t[1]*n[0]}function h(t,n,r){const e=(n[0]-t[0])*(r[1]-t[1])-(n[1]-t[1])*(r[0]-t[0]);return Math.abs(e)/i(n,r)}function l(t,n,r){const e=o(r,n)/c(r);return u(t,r,e)}function y(t,r,s,o,c=s){return n(q,o,s),n(k,r,c),l(w,k,q),e(t,c,w)}function b(t,e,s,u){n(q,u,s),n(k,e,s);const i=o(q,k)/c(q);return i>0?r(t,s,q,i):f(t,s)}function d(t,e,o,c){n(q,e,o);const u=c/s(q);return r(t,o,q,u)}function j(n,r){return y(k,r,n.start,n.end),t(k[0],r[0])&&t(k[1],r[1])?[p(r)]:[]}function x(n,r,e){return d(k,e,n,r),t(k[0],e[0])&&t(k[1],e[1])?[p(e)]:[]}function M(t,e){const s=t.start,o=t.end,c=e.start,u=e.end,i=n(q,o,s),f=n(U,u,c),a=m(i,f);if(Math.abs(a)<=v)return[];const p=n(k,s,c),h=m(f,p)/a,l=m(i,p)/a;if(h>=0){if(l>=0||1===e.type)return[r(w,s,i,h)]}else if(1===t.type&&(l>=0||1===e.type))return[r(w,s,i,h)];return[]}function g(t,e,s){const u=[],i=n(q,t.end,t.start),f=n(U,t.start,e),a=c(i),p=2*o(i,f),m=p*p-4*a*(c(f)-s*s);if(0===m){const n=-p/(2*a);(1===t.type||n>=0)&&u.push(r(w,t.start,i,n))}else if(m>0){const n=Math.sqrt(m),e=(-p+n)/(2*a);(1===t.type||e>=0)&&u.push(r(w,t.start,i,e));const s=(-p-n)/(2*a);(1===t.type||s>=0)&&u.push(r(k,t.start,i,s))}return u}const v=1e-6,q=a(),U=a(),k=a(),w=a();export{m as cross,x as intersectCircleAndPoint,j as intersectLineAndPoint,M as intersectLineAndRay,g as intersectLineLikeAndCircle,h as pointToLineDistance,l as projectPoint,d as projectPointToCircle,y as projectPointToLine,b as projectPointToRay};
