UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{clamp as t}from"../../core/mathUtils.js";import{ObjectStack as r}from"../../core/ObjectStack.js";import{c as n,d as o,f as e,h as i,g as c,k as s,s as u}from"../../chunks/vec32.js";import{clone as a,create as g}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as f}from"./vectorStacks.js";function v(t){return t?{origin:a(t.origin),vector:a(t.vector)}:{origin:g(),vector:g()}}function m(t,r){const n=S.get();return n.origin=t,n.vector=r,n}function p(t,r=v()){return h(t.origin,t.vector,r)}function h(t,r,o=v()){return n(o.origin,t),n(o.vector,r),o}function b(t,r,e=v()){return n(e.origin,t),o(e.vector,r,t),e}function M(r,n){const c=o(f.get(),n,r.origin),s=e(r.vector,c),u=e(r.vector,r.vector),a=t(s/u,0,1),g=o(f.get(),i(f.get(),r.vector,a),c);return e(g,g)}function j(t,r,n){return A(t,r,0,1,n)}function l(t,r,n){return c(n,t.origin,i(n,t.vector,r))}function A(r,n,u,a,g){const{vector:v,origin:m}=r,p=o(f.get(),n,m),h=e(v,p)/s(v);return i(g,v,t(h,u,a)),c(g,g,r.origin)}function d(t,r){if(k(t,m(r.origin,r.direction),!1,x)){const{tA:r,pB:n,distance2:o}=x;if(r>=0&&r<=1)return o;if(r<0)return u(t.origin,n);if(r>1)return u(c(f.get(),t.origin,t.vector),n)}return null}function B(t,r,o){return!!k(t,r,!0,x)&&(n(o,x.pA),!0)}function k(r,n,o,e){const i=1e-6,s=r.origin,a=c(f.get(),s,r.vector),g=n.origin,v=c(f.get(),g,n.vector),m=f.get(),p=f.get();if(m[0]=s[0]-g[0],m[1]=s[1]-g[1],m[2]=s[2]-g[2],p[0]=v[0]-g[0],p[1]=v[1]-g[1],p[2]=v[2]-g[2],Math.abs(p[0])<i&&Math.abs(p[1])<i&&Math.abs(p[2])<i)return!1;const h=f.get();if(h[0]=a[0]-s[0],h[1]=a[1]-s[1],h[2]=a[2]-s[2],Math.abs(h[0])<i&&Math.abs(h[1])<i&&Math.abs(h[2])<i)return!1;const b=m[0]*p[0]+m[1]*p[1]+m[2]*p[2],M=p[0]*h[0]+p[1]*h[1]+p[2]*h[2],j=m[0]*h[0]+m[1]*h[1]+m[2]*h[2],l=p[0]*p[0]+p[1]*p[1]+p[2]*p[2],A=(h[0]*h[0]+h[1]*h[1]+h[2]*h[2])*l-M*M;if(Math.abs(A)<i)return!1;let d=(b*M-j*l)/A,B=(b+M*d)/l;o&&(d=t(d,0,1),B=t(B,0,1));const k=f.get(),x=f.get();return k[0]=s[0]+d*h[0],k[1]=s[1]+d*h[1],k[2]=s[2]+d*h[2],x[0]=g[0]+B*p[0],x[1]=g[1]+B*p[1],x[2]=g[2]+B*p[2],e.tA=d,e.tB=B,e.pA=k,e.pB=x,e.distance2=u(k,x),!0}const x={tA:0,tB:0,pA:g(),pB:g(),distance2:0},S=new r((()=>v()));export{B as closestLineSegmentPoint,d as closestRayDistance2,p as copy,v as create,M as distance2,b as fromPoints,h as fromValues,l as pointAt,j as projectPoint,A as projectPointClamp,m as wrap};