/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{segmentLength as e}from"../../arcade/functions/measures.js";import{fromArray as t,fromValues as r,create as n}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{normalize as o,scaleAndAdd as s}from"../../core/libs/gl-matrix-2/math/vec3.js";import{interpolateM as i}from"./coordUtils.js";import a from"../../geometry/Point.js";import{getPaths as c,getEndpoint as f,isCoordinate as l}from"../../geometry/support/curves/curveUtils.js";import{interpolate2D as u}from"../../geometry/support/curves/interpolateCurve.js";import{splitCurveAtPoint as p}from"../../geometry/support/curves/splitCurveAtPoint.js";function m(e,t,r){let n=t[0]-e[0],o=t[1]-e[1];const s=Math.hypot(n,o);return n/=s,o/=s,n*=r,o*=r,[e[0]+n,e[1]+o]}function h(e,t,i,a){const c=r(t[0]-e[0],t[1]-e[1],t[2]*a-e[2]*a);return o(c,c),s(n(),e,c,i)}function v(t,r){let n=0,o=null;const s=t.hasM,p=t.hasZ?3:2,h=c(t);for(const c of h){if(0===r){const e=f(c[0]);o=new a({x:e[0],y:e[1],...s?{m:e[p]}:{},spatialReference:t.spatialReference,hasM:s});break}for(let h=0;h<c.length-1;h++){const v=e(f(c[h]),c[h+1],!1,1),y=n+v;if(y===r){const e=f(c[h+1]);o=new a({x:e[0],y:e[1],...s?{m:e[p]}:{},spatialReference:t.spatialReference,hasM:s});break}if(y>r){const e=f(c[h]),y=l(c[h+1])?m(e,f(c[h+1]),r-n):u(e,c[h+1],(r-n)/v);o=new a({x:y[0],y:y[1],...s?{m:i(e[p],f(c[h+1])[p],v,r-n)??void 0}:{},spatialReference:t.spatialReference,hasM:s});break}n+=v}if(null!==o)break}return o}function y(r,n,o){let s=0;const p=r.hasM,m=c(r);for(const c of m){if(0===n){const e=f(c[0]);return new a({x:e[0],y:e[1],z:e[2],...p?{m:e[3]}:{},hasZ:!0,hasM:p,spatialReference:r.spatialReference})}for(let m=0;m<c.length-1;m++){const v=e(f(c[m]),c[m+1],!0,o),y=s+v;if(y===n){const e=f(c[m+1]);return new a({x:e[0],y:e[1],z:e[2],...p?{m:e[3]}:{},hasZ:!0,hasM:p,spatialReference:r.spatialReference})}if(y>n){let e=null;const y=f(c[m]);return l(c[m+1])?e=h(t(y),t(f(c[m+1])),n-s,o):(e=u(y,c[m+1],(n-s)/v),e[2]=i(y[2],f(c[m+1])[2],v,n-s)),new a({x:e[0],y:e[1],z:e[2],...p?{m:i(y[3],f(c[m+1])[3],v,n-s)??void 0}:{},hasZ:!0,hasM:p,spatialReference:r.spatialReference})}s+=v}}return null}function R(e,t,r){return Math.hypot(e[0]-t[0],e[1]-t[1],void 0!==e[2]&&void 0!==t[2]?e[2]*r-t[2]*r:0)}function M(e,t,r,n,o=.001){if(l(t)){return[[e,r],[r,t]]}const[s,i]=p(e,t,r,o);if(n&&null!=r[2]){const e=r[2];f(s)[2]=e}return[[e,s],[f(s),i]]}export{m as distanceAlongLineSegment,h as distanceAlongLineSegmentWithZ,v as pointAlongLine,y as pointAlongLineWithZ,R as segmentLength3d,M as splitSegmentAtPoint};
