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