/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{rad2deg as t}from"../../core/mathUtils.js";import n from"../../geometry/Point.js";function e(t,n,e){return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2+(void 0!==t[2]&&void 0!==n[2]?(t[2]*e-n[2]*e)**2:0))}function r(t,n,e){return(t[0]-n[0])**2+(t[1]-n[1])**2+(void 0!==t[2]&&void 0!==n[2]?(t[2]*e-n[2]*e)**2:0)}const o=[];for(const w of[[9002,56146130,6131,6132,8050,8051,8228],[9003,5702,6358,6359,6360,8052,8053],[9095,5754]]){const t=w[0];for(let n=1;n<w.length;n++)o[w[n]]=t}const s=[];function i(t){return t.vcsWkid&&void 0!==o[t.vcsWkid]?s[o[t.vcsWkid]]:t.latestVcsWkid&&void 0!==o[t.latestVcsWkid]?s[o[t.latestVcsWkid]]:1}function c(t,n,e){const r={x:0,y:0};n&&(r.z=0),e&&(r.m=0);let o=0,s=t[0];for(let i=0;i<t.length;i++){const c=t[i];if(!1===l(c,s)){const t=f(s,c,n),i=u(s,c,n,e);i.x*=t,i.y*=t,r.x+=i.x,r.y+=i.y,n&&(i.z*=t,r.z+=i.z),e&&(i.m*=t,r.m+=i.m),o+=t,s=c}}return o>0?(r.x/=o,r.y/=o,n&&(r.z/=o),e&&(r.m/=o)):(r.x=t[0][0],r.y=t[0][1],n&&(r.z=t[0][2]),e&&n?r.m=t[0][3]:e&&(r.m=t[0][2])),r}function u(t,n,e,r){const o={x:(t[0]+n[0])/2,y:(t[1]+n[1])/2};return e&&(o.z=(t[2]+n[2])/2),e&&r?o.m=(t[3]+n[3])/2:r&&(o.m=(t[2]+n[2])/2),o}function a(t,n){if(t.length<=1)return 0;let e=0;for(let r=1;r<t.length;r++)e+=f(t[r-1],t[r],n);return e}function f(t,n,e){const r=n[0]-t[0],o=n[1]-t[1];if(e){const t=n[2]-n[2];return Math.sqrt(r*r+o*o+t*t)}return Math.sqrt(r*r+o*o)}function h(t,n,e){const r=n[0]-t[0],o=n[1]-t[1];if(e){const t=n[2]-n[2];return r*r+o*o+t*t}return r*r+o*o}function l(t,n){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}function x(t){const e={x:0,y:0,spatialReference:t.spatialReference.toJSON()},r={x:0,y:0,spatialReference:t.spatialReference.toJSON()};let o=0,s=0;for(let n=0;n<t.paths.length;n++){if(0===t.paths[n].length)continue;const i=a(t.paths[n],!0===t.hasZ);if(0===i){const r=c(t.paths[n],!0===t.hasZ,!0===t.hasM);e.x+=r.x,e.y+=r.y,!0===t.hasZ&&(e.z+=r.z),!0===t.hasM&&(e.m+=r.m),++o}else{const e=c(t.paths[n],!0===t.hasZ,!0===t.hasM);r.x+=e.x*i,r.y+=e.y*i,!0===t.hasZ&&(r.z+=e.z*i),!0===t.hasM&&(r.m+=e.m*i),s+=i}}return s>0?(r.x/=s,r.y/=s,!0===t.hasZ&&(r.z/=s),!0===t.hasM&&(r.m/=s),new n(r)):o>0?(e.x/=o,e.y/=o,!0===t.hasZ&&(r.z/=o),!0===t.hasM&&(e.m/=o),new n(e)):null}function y(t){if(0===t.points.length)return null;let e=0,r=0,o=0,s=0;for(let n=0;n<t.points.length;n++){const i=t.getPoint(n);!0===i.hasZ&&(o+=i.z),!0===i.hasM&&(s+=i.m),e+=i.x,r+=i.y,s+=i.m}const i={x:e/t.points.length,y:r/t.points.length,spatialReference:null};return i.spatialReference=t.spatialReference.toJSON(),!0===t.hasZ&&(i.z=o/t.points.length),!0===t.hasM&&(i.m=s/t.points.length),new n(i)}function m(t,n){return t.x*n.x+t.y*n.y}function M(t,n){return t.x*n.y-n.x*t.y}function p(t,n,e=0){for(;t<e;)t+=n;const r=e+n;for(;t>=r;)t-=n;return t}function g(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}function z(t,n){return p(g(t,n),2*Math.PI)*(180/Math.PI)}function d(t,n){return p(Math.PI/2-g(t,n),2*Math.PI)*(180/Math.PI)}function v(t,n,e){const r={x:t.x-n.x,y:t.y-n.y},o={x:e.x-n.x,y:e.y-n.y};return Math.atan2(M(r,o),m(r,o))}function P(n,e,r){return t(p(v(n,e,r),2*Math.PI))}function Z(n,e,r){return t(p(-1*v(n,e,r),2*Math.PI))}function I(t,n,e){return Math.max(n,Math.min(e,t))}function R(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]}function k(t){return t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function W(t,n,e){const r=[e[0]-n[0],e[1]-n[1],e[2]-n[2]],o=I(R(r,[t[0]-n[0],t[1]-n[1],t[2]-n[2]])/k(r),0,1);return[n[0]+(e[0]-n[0])*o,n[1]+(e[1]-n[1])*o,n[2]+(e[2]-n[2])*o]}function q(t,n,e){let r=0;const o=e[0]-n[0],s=e[1]-n[1],i=o*o+s*s;if(0===i)r=.5;else{r=((t[0]-n[0])*o+(t[1]-n[1])*s)/i,r<0?r=0:r>1&&(r=1)}return r<=.5?[n[0]+(e[0]-n[0])*r,n[1]+(e[1]-n[1])*r]:[e[0]-(e[0]-n[0])*(1-r),e[1]-(e[1]-n[1])*(1-r)]}s[9002]=.3048,s[9003]=.3048006096012192,s[9095]=.3048007491;export{z as angle2D,P as angleBetween2D,v as angleBetweenRad,g as angleRad,d as bearing2D,Z as bearingBetween2D,y as centroidMultiPoint,x as centroidPolyline,q as closestPointOnLineSegment,W as closestPointOnLineSegmentWithZ,i as getMetersPerVerticalUnitForSR,f as segmentLength,e as segmentLength3d,r as segmentLength3dSqr,h as segmentLengthSqr};
