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