/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{createLength as n}from"../../core/quantity.js";import{verticalLengthUnitFromSpatialReference as t,lengthUnitFromSpatialReference as e}from"../../core/units.js";import{distance as r,set as l}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as i}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectVectorToVector as u}from"../../geometry/projection/projectVectorToVector.js";import{equals as o}from"../../geometry/support/spatialReferenceUtils.js";import{computeEuclideanMeasurementSR as c}from"./measurementUtils.js";function s(n){return f(n,0)}function a(n){return f(n,1)}function f(t,r){const{hasZ:l,spatialReference:i}=t,u=c(i);let o=0;const s=e(u);if(null==s)return null;const a=0===r?Z:g;for(const n of t.paths){if(n.length<2)continue;const t=n.length-1;for(let e=0;e<t;++e){const t=n[e];b[0]=t[0],b[1]=t[1],b[2]=l?t[2]:0;const r=n[e+1];S[0]=r[0],S[1]=r[1],S[2]=l?r[2]:0;const u=a(b,S,i);if(null==u)return null;o+=u.value}}return n(o,s)}function p(n,t){const{spatialReference:e}=n;return o(e,t.spatialReference)?(b[0]=n.x,b[1]=n.y,b[2]=n.hasZ?n.z:0,S[0]=t.x,S[1]=t.y,S[2]=t.hasZ?t.z:0,R(b,S,e)):null}function h(n,t){const{spatialReference:e}=n;return o(e,t.spatialReference)?(b[0]=n.x,b[1]=n.y,b[2]=n.hasZ?n.z:0,S[0]=t.x,S[1]=t.y,S[2]=t.hasZ?t.z:0,Z(b,S,e)):null}function m(n,t){const{spatialReference:e}=n;return o(e,t.spatialReference)?(b[0]=n.x,b[1]=n.y,b[2]=n.hasZ?n.z:0,S[0]=t.x,S[1]=t.y,S[2]=t.hasZ?t.z:0,g(b,S,e)):null}function z(n,t){const{spatialReference:e}=n;return o(e,t.spatialReference)?(b[0]=n.x,b[1]=n.y,b[2]=n.hasZ?n.z:0,S[0]=t.x,S[1]=t.y,S[2]=t.hasZ?t.z:0,v(b,S,e)):null}function x(n){return null!=n?y(n.hasZ?n.z:0,n.spatialReference):null}function y(e,r){const l=t(r);return null!=l?n(e??0,l):null}function R(t,e,r){const l=d(t,e,r);return null!=l?{direct:n(l.direct,l.unit),horizontal:n(l.horizontal,l.unit),vertical:n(l.vertical,l.unit)}:null}function Z(t,e,r){const l=d(t,e,r,0);return null!=l?n(l.direct,l.unit):null}function g(t,e,r){const l=d(t,e,r,1);return null!=l?n(l.horizontal,l.unit):null}function j(t,e,r){const l=d(t,e,r,2);return null!=l?n(Math.abs(l.verticalSigned),l.unit):null}function v(t,e,r){const l=d(t,e,r,2);return null!=l?n(l.verticalSigned,l.unit):null}function d(n,t,i,o){const s=c(i),a=e(s);if(null==a)return null;const f=t[2]-n[2];if(2===o)return{verticalSigned:f,unit:a};if(!u(n,i,M,s)||!u(t,i,U,s))return null;if(0===o){return{direct:r(U,M),unit:a}}if(l(V,n[0],n[1],t[2]),!u(V,i,V,s))return null;const p=r(V,U);if(1===o)return{horizontal:p,unit:a};return{direct:r(U,M),horizontal:p,vertical:Math.abs(f),unit:a}}const b=i(),S=i(),M=i(),U=i(),V=i();export{x as elevationFromPoint,y as elevationFromZ,Z as euclideanDirectDistance,h as euclideanDirectDistanceBetweenPoints,R as euclideanDistance,p as euclideanDistanceBetweenPoints,g as euclideanHorizontalDistance,m as euclideanHorizontalDistanceBetweenPoints,a as euclideanHorizontalLength,s as euclideanLength,j as verticalDistance,v as verticalSignedDistance,z as verticalSignedDistanceBetweenPoints};
