UNPKG

@arcgis/core

Version:

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

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