@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.18 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{floatEqualAbsolute as t}from"../../core/mathUtils.js";import{subtract as n,squaredLength as r,dot as s,scaleAndAdd as e,sub as o,length as c,distance as i,squaredDistance as u,lerp as a,set as f}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as p,fromValues as m,ZEROS as L}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{i as h,a as A,f as d,b as l,j as E,e as N,H as y,c as P,d as b,z as j}from"../../chunks/vec32.js";import{create as M,clone as I}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getEpsilon as R}from"../../core/libs/gl-matrix-2/math/common.js";import{create as Y,fromPositionAndNormal as g,distance as x,intersectLine as v,isPointInside as H}from"../../geometry/support/plane.js";import{tangentFrame as q}from"../3d/support/mathUtils.js";import{LineType as F,intersectLineLikeAndCircle as _}from"./geometry2dUtils.js";function U({start:t,end:o,type:c},i,u){const a=[],f=n(et,o,t),m=n(ot,t,i),L=r(f),h=2*s(f,m),A=h*h-4*L*(r(m)-u*u);if(0===A){const n=-h/(2*L);(c===rt.PLANE||n>=0)&&a.push(e(p(),t,f,n))}else if(A>0){const n=Math.sqrt(A),r=(-h+n)/(2*L);(c===rt.PLANE||r>=0)&&a.push(e(p(),t,f,r));const s=(-h-n)/(2*L);(c===rt.PLANE||s>=0)&&a.push(e(p(),t,f,s))}return a}function k(t,r){const e=t.start,c=t.end,i=n(et,c,e),u=h(it,-i[1],i[0],0),a=r.start,f=r.end,p=A(ut,f,a),m=d(p,u),L=h(at,e[0],e[1],0),E=A(ft,L,a),N=d(E,u),y=R();if(Math.abs(m)<y)return Math.abs(N),[];const P=l(pt,a,p,N/m);if(r.type===F.RAY){const t=A(mt,P,a);if(d(t,p)<-y)return[]}if(t.type===rt.HALF_PLANE){const t=o(ot,P,e);if(s(t,i)<-y)return[]}return[I(P)]}function w(t,n){return T(X(ht,n[2],t),n)}function z(t,n){const r=0;return S(X(ht,r,t),X(At,r,n)).map((([t,n])=>m(t,n)))}function C(t,n,r){return J(t,X(ht,t[2],n),r)}function B(t,n){return K(X(ht,t[2],n),t)}function D(t,r,s,o=M()){const i=n(et,t,r),u=c(i);return e(o,r,i,0===u?1:s/u),o[2]=t[2],o}function G(t,n,r){return i(t,n)-r}function J(t,{start:n,end:r,type:s},e=M()){const o=A(ct,t,n),c=A(it,r,n),i=d(o,c)/d(c,c);return l(e,n,c,s===F.RAY?Math.max(i,0):i)}function K({start:t,end:n,type:r},s){const e=A(ct,s,t),o=A(it,n,t);if(r===F.RAY&&d(o,e)<-R())return E(t,s);const c=N(ut,o,e);return y(c)/y(o)}const O=(()=>{const t=M(),n=M(),r=M();return({start:s,end:e},{center:o,radius:c,normal:i,slicePlane:u})=>{const a=g(o,i,Lt);if($(x(a,s),0)&&$(x(a,e),0)){q(i,t,n);const a=(s,e)=>(b(r,e,o),f(s,d(r,t),d(r,n)),s),p=_({start:a(et,s),end:a(ot,e),type:F.LINE},L,c),m=[];for(const[r,s]of p){const e=P(M(),o);l(e,e,t,r),l(e,e,n,s),u&&!nt(u,e)||m.push(e)}return m}const p=M();return v(a,s,e,p)?!$(E(p,o),c)||u&&!nt(u,p)?[]:[p]:[]}})();function Q({start:t,end:e,type:o},c,i){const u=[],a=b(ct,e,t),f=n(ot,t,c),p=r(a),m=2*s(a,f),L=m*m-4*p*(r(f)-i*i);if(0===L){const n=-m/(2*p);(o===F.LINE||n>=0)&&u.push(l(M(),t,a,n))}else if(L>0){const n=Math.sqrt(L),r=(-m+n)/(2*p);(o===F.LINE||r>=0)&&u.push(l(M(),t,a,r));const s=(-m-n)/(2*p);(o===F.LINE||s>=0)&&u.push(l(M(),t,a,s))}return u}function S(t,n){const r=t.start,s=t.end,e=n.start,o=n.end,c=A(ct,s,r),i=A(it,o,e),u=A(ut,e,r),a=N(at,c,i);if(!$(d(u,a),0))return[];const f=j(a);if($(f,0))return[];const p=N(ft,u,i),m=d(p,a)/f,L=l(pt,r,c,m);if(t.type===F.RAY){const t=A(mt,L,r);if(d(c,t)<-R())return[]}if(n.type===F.RAY){const t=A(mt,L,e);if(d(i,t)<-R())return[]}return[I(L)]}function T({start:t,end:n,type:r},s){const e=A(ct,s,t),o=A(it,n,t),c=N(ut,o,e),i=j(c)/j(o),u=R();if(i<u)switch(r){case F.LINE:return[I(s)];case F.RAY:return d(o,e)<-u?[]:[I(s)]}return[]}function V(t,n,r){return $(u(r,t),n*n)?[I(r)]:[]}function W(t,n,r,s){const[e,o]=t,[c,i]=r,u=c-e,f=i-o,p=u*u+f*f,L=Math.sqrt(p);if(L>n+s)return[];if(L<Math.abs(n-s))return[];if($(L,0)&&$(n,s))return[];const h=(n*n-s*s+p)/(2*L),A=Math.sqrt(n*n-h*h),d=A*f/L,l=A*u/L,[E,N]=a(et,t,r,h/L);return $(d,l)?[m(E,N)]:[m(E+d,N-l),m(E-d,N+l)]}function X(t,n,{start:r,end:s,type:e}){return h(t.start,r[0],r[1],n),h(t.end,s[0],s[1],n),t.type=st[e],t}function Z(t,n){return $(t[2],n[2])}function $(n,r){return t(Math.abs(n-r),0,R())}function tt(t,n){return n.filter((n=>nt(t,n)))}function nt(t,n){return H(t,n)}var rt;!function(t){t[t.PLANE=0]="PLANE",t[t.HALF_PLANE=1]="HALF_PLANE"}(rt||(rt={}));const st={[rt.PLANE]:F.LINE,[rt.HALF_PLANE]:F.RAY},et=p(),ot=p(),ct=M(),it=M(),ut=M(),at=M(),ft=M(),pt=M(),mt=M(),Lt=Y(),ht={start:M(),end:M(),type:F.LINE},At={start:M(),end:M(),type:F.LINE};export{F as LineType,rt as VerticalPlaneType,T as intersectLineAndPoint,O as intersectLineLikeAndCircle,Q as intersectLineLikeAndVerticalCylinder,S as intersectLineLikes,V as intersectVerticalCylinderAndPoint,W as intersectVerticalCylinders,k as intersectVerticalPlaneAndLineLike,w as intersectVerticalPlaneAndPoint,U as intersectVerticalPlaneAndVerticalCylinder,z as intersectVerticalPlanes,$ as isClose,nt as isPointInsidePlane,K as pointToLineLikeDistance,G as pointToVerticalCylinderDistance,B as pointToVerticalPlaneDistance,tt as pointsInsidePlane,J as projectPointToLineLike,D as projectPointToVerticalCylinder,C as projectPointToVerticalPlane,Z as vectorsHaveCloseZ};