/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/maybe","../../core/quantityUtils","../../core/unitUtils","../../chunks/vec3","../../chunks/vec3f64","../../geometry/projection","../../geometry/support/spatialReferenceUtils","./measurementUtils"],(function(e,t,n,i,r,c,a,o,l){"use strict";function u(e){return f(e,"direct")}function s(e){return f(e,"horizontal")}function f(e,r){const{hasZ:c,spatialReference:a}=e,o=l.computeEuclideanMeasurementSR(a);let u=0;const s=i.lengthUnitFromSpatialReference(o);if(t.isNone(s))return null;const f="direct"===r?m:S;for(const n of e.paths){if(n.length<2)continue;const e=n.length-1;for(let i=0;i<e;++i){const e=n[i];x[0]=e[0],x[1]=e[1],x[2]=c?e[2]:0;const r=n[i+1];Z[0]=r[0],Z[1]=r[1],Z[2]=c?r[2]:0;const o=f(x,Z,a);if(t.isNone(o))return null;u+=o.value}}return n.createLength(u,s)}function h(e,t){const{spatialReference:n}=e;return o.equals(n,t.spatialReference)?(x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,Z[0]=t.x,Z[1]=t.y,Z[2]=t.hasZ?t.z:0,z(x,Z,n)):null}function d(e,t){const{spatialReference:n}=e;return o.equals(n,t.spatialReference)?(x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,Z[0]=t.x,Z[1]=t.y,Z[2]=t.hasZ?t.z:0,m(x,Z,n)):null}function g(e,t){const{spatialReference:n}=e;return o.equals(n,t.spatialReference)?(x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,Z[0]=t.x,Z[1]=t.y,Z[2]=t.hasZ?t.z:0,S(x,Z,n)):null}function p(e,t){const{spatialReference:n}=e;return o.equals(n,t.spatialReference)?(x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,Z[0]=t.x,Z[1]=t.y,Z[2]=t.hasZ?t.z:0,y(x,Z,n)):null}function v(e){return x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,L(x,e.spatialReference)}function z(e,i,r){const c=D(e,i,r);return t.isSome(c)?{direct:n.createLength(c.direct,c.unit),horizontal:n.createLength(c.horizontal,c.unit),vertical:n.createLength(c.vertical,c.unit)}:null}function m(e,i,r){const c=D(e,i,r,"direct");return t.isSome(c)?n.createLength(c.direct,c.unit):null}function S(e,i,r){const c=D(e,i,r,"horizontal");return t.isSome(c)?n.createLength(c.horizontal,c.unit):null}function R(e,i,r){const c=D(e,i,r,"vertical");return t.isSome(c)?n.createLength(Math.abs(c.verticalSigned),c.unit):null}function y(e,i,r){const c=D(e,i,r,"vertical");return t.isSome(c)?n.createLength(c.verticalSigned,c.unit):null}function L(e,r){const c=i.verticalLengthUnitFromSpatialReference(r);return t.isSome(c)?n.createLength(e[2],c):null}function D(e,n,c,o){const u=l.computeEuclideanMeasurementSR(c),s=i.lengthUnitFromSpatialReference(u);if(t.isNone(s))return null;const f=n[2]-e[2];if("vertical"===o)return{verticalSigned:f,unit:s};if(!a.projectVectorToVector(e,c,U,u)||!a.projectVectorToVector(n,c,M,u))return null;if("direct"===o){return{direct:r.distance(M,U),unit:s}}if(r.set(P,e[0],e[1],n[2]),!a.projectVectorToVector(P,c,P,u))return null;const h=r.distance(P,M);if("horizontal"===o)return{horizontal:h,unit:s};return{direct:r.distance(M,U),horizontal:h,vertical:Math.abs(f),unit:s}}const x=c.create(),Z=c.create(),U=c.create(),M=c.create(),P=c.create();e.elevation=L,e.elevationOfPoint=v,e.euclideanDirectDistance=m,e.euclideanDirectDistanceBetweenPoints=d,e.euclideanDistance=z,e.euclideanDistanceBetweenPoints=h,e.euclideanHorizontalDistance=S,e.euclideanHorizontalDistanceBetweenPoints=g,e.euclideanHorizontalLength=s,e.euclideanLength=u,e.verticalDistance=R,e.verticalSignedDistance=y,e.verticalSignedDistanceBetweenPoints=p,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
