UNPKG

@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
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{floatEqualAbsolute as t}from"../../core/mathUtils.js";import{subtract as n,length as r,scaleAndAdd as s,sub as e,dot as o,squaredLength as c,lerp as i,set as u,distance as a,squaredDistance 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{a as h,e as d,b as A,i as l,h as E,y as N,d as y,c as P,j as b,H 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{fromPositionAndNormal as Y,create 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:r,type:e},i,u){const a=[],f=n(et,r,t),m=n(ot,t,i),L=c(f),h=2*o(f,m),d=h*h-4*L*(c(m)-u*u);if(0===d){const n=-h/(2*L);(e===rt.PLANE||n>=0)&&a.push(s(p(),t,f,n))}else if(d>0){const n=Math.sqrt(d),r=(-h+n)/(2*L);(e===rt.PLANE||r>=0)&&a.push(s(p(),t,f,r));const o=(-h-n)/(2*L);(e===rt.PLANE||o>=0)&&a.push(s(p(),t,f,o))}return a}function k(t,r){const s=t.start,c=t.end,i=n(et,c,s),u=l(it,-i[1],i[0],0),a=r.start,f=r.end,p=h(ut,f,a),m=d(p,u),L=l(at,s[0],s[1],0),E=h(ft,L,a),N=d(E,u),y=R();if(Math.abs(m)<y)return Math.abs(N),[];const P=A(pt,a,p,N/m);if(r.type===F.RAY){const t=h(mt,P,a);if(d(t,p)<-y)return[]}if(t.type===rt.HALF_PLANE){const t=e(ot,P,s);if(o(t,i)<-y)return[]}return[I(P)]}function w(t,n){return T(X(ht,n[2],t),n)}function C(t,n){const r=0;return S(X(ht,r,t),X(dt,r,n)).map((([t,n])=>m(t,n)))}function z(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,e,o,c=M()){const i=n(et,t,e),u=r(i);return s(c,e,i,0===u?1:o/u),c[2]=t[2],c}function G(t,n,r){return a(t,n)-r}function J(t,{start:n,end:r,type:s},e=M()){const o=h(ct,t,n),c=h(it,r,n),i=d(o,c)/d(c,c);return A(e,n,c,s===F.RAY?Math.max(i,0):i)}function K({start:t,end:n,type:r},s){const e=h(ct,s,t),o=h(it,n,t);if(r===F.RAY&&d(o,e)<-R())return b(t,s);const c=E(ut,o,e);return j(c)/j(o)}const O=(()=>{const t=M(),n=M(),r=M();return({start:s,end:e},{center:o,radius:c,normal:i,slicePlane:a})=>{const f=Y(o,i,Lt);if($(x(f,s),0)&&$(x(f,e),0)){q(i,t,n);const f=(s,e)=>(y(r,e,o),u(s,d(r,t),d(r,n)),s),p=_({start:f(et,s),end:f(ot,e),type:F.LINE},L,c),m=[];for(const[r,s]of p){const e=P(M(),o);A(e,e,t,r),A(e,e,n,s),a&&!nt(a,e)||m.push(e)}return m}const p=M();return v(f,s,e,p)?!$(b(p,o),c)||a&&!nt(a,p)?[]:[p]:[]}})();function Q({start:t,end:r,type:s},e,i){const u=[],a=y(ct,r,t),f=n(ot,t,e),p=c(a),m=2*o(a,f),L=m*m-4*p*(c(f)-i*i);if(0===L){const n=-m/(2*p);(s===F.LINE||n>=0)&&u.push(A(M(),t,a,n))}else if(L>0){const n=Math.sqrt(L),r=(-m+n)/(2*p);(s===F.LINE||r>=0)&&u.push(A(M(),t,a,r));const e=(-m-n)/(2*p);(s===F.LINE||e>=0)&&u.push(A(M(),t,a,e))}return u}function S(t,n){const r=t.start,s=t.end,e=n.start,o=n.end,c=h(ct,s,r),i=h(it,o,e),u=h(ut,e,r),a=E(at,c,i);if(!$(d(u,a),0))return[];const f=N(a);if($(f,0))return[];const p=E(ft,u,i),m=d(p,a)/f,L=A(pt,r,c,m);if(t.type===F.RAY){const t=h(mt,L,r);if(d(c,t)<-R())return[]}if(n.type===F.RAY){const t=h(mt,L,e);if(d(i,t)<-R())return[]}return[I(L)]}function T({start:t,end:n,type:r},s){const e=h(ct,s,t),o=h(it,n,t),c=E(ut,o,e),i=N(c)/N(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 $(f(r,t),n*n)?[I(r)]:[]}function W(t,n,r,s){const[e,o]=t,[c,u]=r,a=c-e,f=u-o,p=a*a+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),d=Math.sqrt(n*n-h*h),A=d*f/L,l=d*a/L,[E,N]=i(et,t,r,h/L);return $(A,l)?[m(E,N)]:[m(E+A,N-l),m(E-A,N+l)]}function X(t,n,{start:r,end:s,type:e}){return l(t.start,r[0],r[1],n),l(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=g(),ht={start:M(),end:M(),type:F.LINE},dt={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,C 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,z as projectPointToVerticalPlane,Z as vectorsHaveCloseZ};