UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 13 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{isSome as t,equals as e}from"../../../core/arrayUtils.js";import{asinClamped as s}from"../../../core/mathUtils.js";import{dot as r,subtract as n,squaredDistance as i,exactEquals as o,set as c}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{create as u}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{q as a,c as h,i as f,d as l,G as d,b as p,s as m,a as g,k as _,e as L,h as k,n as x}from"../../../chunks/vec32.js";import{create as y,UNIT_Z as P,fromValues as z,clone as M}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as T,g as q}from"../../../chunks/vec42.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{toRadians as j}from"../../../geometry/support/geodesicConstants.js";import{directGeodeticSolver as v,inverseGeodeticSolver as A,InverseGeodeticSolverResult as D}from"../../../geometry/support/geodesicUtils.js";import{create as b,fromPoints as E,fromPositionAndNormal as R,intersectLine as N,signedDistance as U,projectPoint as Z,getNormal as I,distance as G}from"../../../geometry/support/plane.js";import{e as S,h as C,j as O,p as F,a as H}from"../../../chunks/sphere.js";import{tangentFrame as V}from"../../3d/support/mathUtils.js";import{clone as Y,asVec2 as B,createWritable as J,create as K,fromValues as Q,fromVec3 as W}from"./normalizedPoint.js";import{VerticalPlaneType as X,projectPointToVerticalPlane as $,isClose as tt,projectPointToVerticalCylinder as et,projectPointToLineLike as st,intersectLineLikes as rt,intersectVerticalPlaneAndLineLike as nt,intersectLineLikeAndVerticalCylinder as it,intersectLineLikeAndCircle as ot,intersectVerticalPlanes as ct,intersectVerticalPlaneAndVerticalCylinder as ut,intersectVerticalCylinders as at,intersectVerticalPlaneAndPoint as ht,vectorsHaveCloseZ as ft,isPointInsidePlane as lt,pointsInsidePlane as dt}from"../../support/geometry3dUtils.js";import{LineType as pt}from"../../support/geometry2dUtils.js";class mt{intersect(t){return Ht(this,t)}closestPoints(t){return[this.closestTo(t)]}}class gt extends mt{constructor(t){super(),this.point=t}equals(t){return this===t||Le(t)&&a(this.point,t.point)}closestTo(){return Y(this.point)}}class _t extends mt{constructor(t,e,s){super(),this.start=t,this.end=e,this.lineLike={start:t,end:e,type:s}}equals(t){return this===t||ke(t)&&this.lineLike.type===t.lineLike.type&&a(this.start,t.start)&&a(this.end,t.end)}closestTo(t){const e=J();return st(t,this.lineLike,e),e}}class Lt extends _t{constructor(t,e){super(t,e,pt.LINE)}}class kt extends _t{constructor(t,e){super(t,e,pt.RAY)}}class xt extends mt{constructor(t){super(),this.constraints=t}equals(t){return this===t||_e(t)&&e(this.constraints,t.constraints,((t,e)=>t.equals(e)))}closestTo(t){let e,s=1/0;for(const r of this.constraints){const n=r.closestTo(t),i=m(t,n);i<s&&(s=i,e=n)}return Y(e??t)}closestPoints(t){return this.constraints.flatMap((e=>e===this?[]:e.closestPoints(t)))}}class yt extends mt{constructor(t,e){super(),this.center=t,this.radius=e}equals(t){return this===t||Pe(t)&&this.center[0]===t.center[0]&&this.center[1]===t.center[1]&&this.radius===t.radius}closestTo(t){const e=J();return et(t,this.center,this.radius,e),e}}class Pt extends mt{constructor(t,e){super(),this.center=t,this.radius=e}equals(t){return this===t||ze(t)&&a(this.center,t.center)&&this.radius===t.radius}closestTo(t){const e=J();return et(t,this.center,this.radius,e),e[2]=this.center[2],e}asCircle(){return new zt(Y(this.center),this.radius,Q(0,0,1))}}class zt extends mt{constructor(t,e,s,r=void 0){super(),this.center=t,this.radius=e,this.normal=s,this.slicePlane=r}equals(t){return this===t||Me(t)&&a(this.center,t.center)&&a(this.normal,t.normal)&&this.radius===t.radius}closestTo(t){const{center:e,radius:s}=this;Z(this.getPlane(Tt),t,Mt);const r=g(Mt,Mt,e),n=_(r);if(tt(n,0))return Y(t);const i=s/Math.sqrt(n),o=J();p(o,e,r,i);const{slicePlane:c}=this;if(c&&!lt(c,o)){const e=Jt(c,this);return e?.closestTo(t)??Y(t)}return o}getPlane(t=b()){return R(this.center,this.normal,t)}}const Mt=y(),Tt=b();class qt extends mt{constructor(t){super(),this.z=t}equals(t){return this===t||xe(t)&&this.z===t.z}closestTo(t){return Q(t[0],t[1],this.z)}getPlane(t=b()){return f(wt,0,0,this.z),R(wt,P,t)}}const wt=y();class jt extends mt{constructor(t,e,s){super(),this.start=t,this.end=e,this.planeLike={start:B(t),end:B(e),type:s}}equals(t){return this===t||ye(t)&&this.planeLike.type===t.planeLike.type&&a(this.start,t.start)&&a(this.end,t.end)}closestTo(t){const e=J();return $(t,this.planeLike,e),e}closestEndTo(t){const{start:e,end:s}=this.planeLike;return Math.sign(r(n(vt,s,e),n(At,B(t),e)))>0?this.end:this.start}getPlane(t=b()){const e=h(Dt,this.end);return e[2]+=1,E(this.start,this.end,e,t)}getSlicePlane(t=b()){const{start:e,end:s,type:r}=this.planeLike;if(r===X.PLANE)return;const n=f(Dt,e[0],e[1],0),i=f(bt,s[0],s[1],0),o=l(bt,i,n);return R(n,o,t),t}}const vt=u(),At=u(),Dt=y(),bt=y();class Et extends jt{constructor(t,e){super(t,e,X.HALF_PLANE)}}class Rt extends jt{constructor(t,e){super(t,e,X.PLANE)}}class Nt extends mt{constructor(t,e){super(),this.sphere=C(t,e)}equals(t){return this===t||Te(t)&&O(this.sphere,t.sphere)}closestTo(t){const e=J();return F(this.sphere,t,e),e}get center(){return H(this.sphere)}get radius(){return this.sphere[3]}}class Ut extends mt{constructor(t,e,s){super(),this.start=t,this.end=e,this.getZ=s,this.planeLike={start:B(t),end:B(e),type:X.PLANE}}equals(t){return this===t||qe(t)&&a(this.start,t.start)&&a(this.end,t.end)&&this.getZ===t.getZ}closestTo(t){return Ft(this,t)}addIfOnTheGround(t,e){for(const s of e){const e=this.getZ(s[0],s[1])??0;tt(s[2],e)&&(s[2]=e,t.push(s))}}}class Zt extends mt{constructor(t,e,s){super(),this._x=t,this._y=e,this._z=s}equals(t){return this===t||je(t)&&this._x===t._x&&this._y===t._y&&this._z===t._z}closestTo([t,e,s]){return K(this._x??t,this._y??e,this._z??s)}}class It extends mt{constructor(t,e,s,r,n){super(),this._origin=t,this._spatialReference=e,this._distanceMeters=s,this._z=r,this._directionDegrees=n}equals(t){return this===t||we(t)&&o(this._origin,t._origin)&&this._spatialReference===t._spatialReference&&this._distanceMeters===t._distanceMeters&&this._z===t._z&&this._directionDegrees===t._directionDegrees}closestTo([t,e,s]){return c(Gt,t,e),o(Gt,this._origin)||this._applyDirectionAndDistance(Gt),K(Gt[0],Gt[1],this._z??s)}_applyDirectionAndDistance(t){if(null!=this._directionDegrees&&null!=this._distanceMeters)v(t,this._origin,this._directionDegrees,this._distanceMeters,this._spatialReference);else if(null!=this._directionDegrees)Ct(t,this._origin,this._directionDegrees,t,this._spatialReference);else if(null!=this._distanceMeters){const{azimuth:e}=A(St,this._origin,t,this._spatialReference);v(t,this._origin,e??0,this._distanceMeters,this._spatialReference)}}}const Gt=[0,0],St=new D;function Ct(t,e,s,r,n){let{azimuth:i,distance:o}=A(Ot,e,r,n);i??=0;let c=o*Math.cos((i-s)*j);c=Math.max(0,c),v(t,e,s,c,n)}const Ot=new D;function Ft(t,e){const s=J();return $(e,t.planeLike,s),s[2]=t.getZ(s[0],s[1])??ve,s}function Ht(t,e){if(_e(t)){const s=[];for(const r of t.constraints){const t=r.intersect(e);t&&s.push(t)}return ge(s)}if(_e(e))return Ht(e,t);if(qe(t))return le(t,e);if(qe(e))return le(e,t);if(Le(t)){const{point:s}=t;if(Le(e))return a(s,e.point)?t:void 0;const r=e.closestTo(s);return d(r,s)?t:void 0}if(ke(t)){if(Le(e))return Ht(e,t);if(ke(e))return pe(rt(t.lineLike,e.lineLike));if(xe(e))return Vt(t,e);if(ye(e))return pe(nt(e.planeLike,t.lineLike));if(Pe(e))return pe(it(t.lineLike,e.center,e.radius));if(Me(e))return pe(ot(t.lineLike,e));if(ze(e))return Yt(t,e);if(Te(e))return Bt(t,e)}else if(xe(t)){if(Le(e)||ke(e))return Ht(e,t);if(xe(e))return Kt(t,e);if(ye(e))return Qt(t,e);if(Pe(e))return Wt(t,e);if(Me(e))return $t(t,e);if(ze(e))return Xt(t,e);if(Te(e))return te(t,e)}else if(ye(t)){if(Le(e)||ke(e)||xe(e))return Ht(e,t);if(ye(e))return de(ct(t.planeLike,e.planeLike));if(Pe(e))return de(ut(t.planeLike,e.center,e.radius));if(Me(e))return se(t,e);if(ze(e))return ee(t,e);if(Te(e))return re(t,e)}else if(Pe(t)){if(Le(e)||ke(e)||xe(e)||ye(e))return Ht(e,t);if(Pe(e))return de(at(B(t.center),t.radius,B(e.center),e.radius));if(Me(e))return ne();if(ze(e))return ie(t,e);if(Te(e))return oe()}else if(Me(t)){if(Le(e)||ke(e)||xe(e)||ye(e)||Pe(e))return Ht(e,t);if(Me(e))return ce();if(ze(e))return ce(e.asCircle());if(Te(e))return ue()}else if(ze(t)){if(Le(e)||ke(e)||xe(e)||ye(e)||Pe(e)||Me(e))return Ht(e,t);if(ze(e))return ae(e,t);if(Te(e))return he()}else if(Te(t)){if(Le(e)||ke(e)||xe(e)||ye(e)||Pe(e)||ze(e))return Ht(e,t);if(Te(e))return fe()}}const Vt=(()=>{const t=b();return(e,s)=>{const{start:r,end:n}=e;if(ft(r,n)&&tt(r[2],s.z))return e;const i=J();return N(s.getPlane(t),r,n,i)?new gt(i):void 0}})();function Yt({lineLike:t},{center:e,radius:s}){const r=e[2];return pe(it(t,e,s).filter((t=>tt(t[2],r))))}function Bt({lineLike:t},{sphere:e}){return pe(S(e,t.start,t.end))}const Jt=(()=>{const t=w(),e=y(),r=y();return(n,i,o)=>{const{normal:c,center:u,radius:a}=i;V(c,e,r);const h=I(n),f=a*L(h,e),l=a*L(h,r);T(t,u[0],u[1],u[2],1);const d=q(n,t),m=Math.hypot(f,l),g=tt(m,0);if(tt(G(n,u),0)){if(g)return i;if(tt(a,0))return!o||lt(o,u)?new gt(Y(u)):void 0;k(e,h,c),x(e,e);const t=new Array,s=M(u);p(s,s,e,a),o&&!lt(o,s)||t.push(s);const r=M(u);return p(r,r,e,-a),o&&!lt(o,r)||t.push(r),pe(t)}if(g)return;const _=-d/m;if(Math.abs(_)>1||tt(_,1))return;const P=Math.atan(f/l),z=s(_)-P,w=Math.PI-z,j=new Array,v=y();p(v,u,e,a*Math.cos(z)),p(v,v,r,a*Math.sin(z)),j.push(v);const A=y();return p(A,u,e,a*Math.cos(w)),p(A,A,r,a*Math.sin(w)),j.push(A),pe(o?dt(o,j):j)}})();function Kt(t,e){return tt(t.z,e.z)?t:void 0}function Qt({z:t},{planeLike:e}){const[s,r]=e.start,[n,i]=e.end,o=Q(s,r,t),c=Q(n,i,t);return e.type===X.PLANE?new Lt(o,c):new kt(o,c)}function Wt(t,e){const[s,r]=e.center;return new Pt(Q(s,r,t.z),e.radius)}function Xt(t,e){return tt(e.center[2],t.z)?e:void 0}const $t=(()=>{const t=b();return(e,s)=>Jt(e.getPlane(t),s,s.slicePlane)})();function te(t,{center:e,radius:s}){const r=Math.abs(e[2]-t.z);if(r>s&&!tt(r,s))return;const n=Q(e[0],e[1],t.z),i=Math.sqrt(s**2-r**2);return tt(i,0)?void 0:new Pt(n,i)}const ee=(()=>{const t=b();return(e,{center:s,radius:r})=>{const n=ut(e.planeLike,s,r),i=s[2];e.getSlicePlane(t);const o=new Array;for(const[c,u]of n){const e=[c,u,i];lt(t,e)&&o.push(e)}return pe(o)}})(),se=(()=>{const t=b(),e=b();return(s,r)=>Jt(s.getPlane(t),r,s.getSlicePlane(e))})(),re=(()=>{const t=b();return(e,{center:s,radius:r})=>{const n=e.getPlane(t),i=U(n,s),o=Math.abs(i);if(o>r&&!tt(o,r))return;const c=Math.sqrt(r**2-i**2);if(tt(c,0)){const t=J();return Z(n,s,t),new gt(t)}const u=J(),a=M(I(n));return p(u,s,a,i),new zt(u,c,a,e.getSlicePlane())}})();function ne(t,e){}function ie(t,e){const s=i(B(t.center),B(e.center));if(tt(s,0)&&tt(t.radius,e.radius))return e;return me(at(B(t.center),t.radius,B(e.center),e.radius),e.center[2])}function oe(t,e){}function ce(t,e){}function ue(t,e){}function ae(t,e){if(!ft(t.center,e.center))return;const s=i(B(t.center),B(e.center));if(tt(s,0)&&tt(t.radius,e.radius))return t;return me(at(B(t.center),t.radius,B(e.center),e.radius),t.center[2])}function he(t,e){}function fe(t,e){}function le(t,e){const{planeLike:s,getZ:r}=t,n=new Array;if(Le(e))t.addIfOnTheGround(n,ht(s,e.point));else if(ke(e))t.addIfOnTheGround(n,nt(s,e.lineLike));else if(Pe(e))for(const[i,o]of ut(s,e.center,e.radius)){const t=r(i,o);null!=t&&n.push(z(i,o,t))}else if(ye(e)||qe(e))for(const[i,o]of ct(s,e.planeLike)){const t=r(i,o)??ve;n.push(z(i,o,t))}return pe(n)}function de(t){return ge(t.map((([t,e])=>{const s=Q(t,e,0),r=Q(t,e,1);return new Lt(s,r)})))}function pe(t){return ge(t.map((t=>t?new gt(W(t)):void 0)))}function me(t,e){return pe(t.map((([t,s])=>[t,s,e])))}function ge(e){if(0!==e.length)return 1===e.length?e[0]??void 0:new xt(e.filter(t))}function _e(t){return t instanceof xt}function Le(t){return t instanceof gt}function ke(t){return t instanceof _t}function xe(t){return t instanceof qt}function ye(t){return t instanceof jt}function Pe(t){return t instanceof yt}function ze(t){return t instanceof Pt}function Me(t){return t instanceof zt}function Te(t){return t instanceof Nt}function qe(t){return t instanceof Ut}function we(t){return t instanceof It}function je(t){return t instanceof Zt}const ve=0;export{zt as CircleConstraint,mt as Constraint,Zt as CoordinateConstraint,Ut as DrapedLineConstraint,It as GeodesicConstraint,Pt as HorizontalCircleConstraint,qt as HorizontalPlaneConstraint,Lt as LineConstraint,_t as LineLikeConstraint,gt as PointConstraint,kt as RayConstraint,xt as SetConstraint,Nt as SphereConstraint,yt as VerticalCylinderConstraint,Et as VerticalHalfPlaneConstraint,Rt as VerticalPlaneConstraint,jt as VerticalPlaneLikeConstraint,ge as constraintOrSet,Le as isPoint};