/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{equals as t}from"../../core/arrayUtils.js";import{curvesAreSameType as n}from"./curves/curveUtils.js";function e(t){if(!t)return null;if(Array.isArray(t))return t;const n=t.hasZ,e=t.hasM;if("point"===t.type)return e&&n?[t.x,t.y,t.z,t.m]:n?[t.x,t.y,t.z]:e?[t.x,t.y,t.m]:[t.x,t.y];if("polygon"===t.type)return t.rings.slice();if("polyline"===t.type)return t.paths.slice();if("multipoint"===t.type)return t.points.map(t=>[t]);if("extent"===t.type){const n=t.clone().normalize();if(!n)return null;let e=!1,r=!1;return n.forEach(t=>{t.hasZ&&(e=!0),t.hasM&&(r=!0)}),n.map(t=>{const n=[[t.xmin,t.ymin],[t.xmin,t.ymax],[t.xmax,t.ymax],[t.xmax,t.ymin],[t.xmin,t.ymin]];if(e&&t.hasZ){const e=.5*(t.zmax-t.zmin);for(let t=0;t<n.length;t++)n[t].push(e)}if(r&&t.hasM){const e=.5*(t.mmax-t.mmin);for(let t=0;t<n.length;t++)n[t].push(e)}return n})}return null}function r(t,n){const e=n[0]-t[0],r=n[1]-t[1];if(t.length>2&&n.length>2){const i=t[2]-n[2];return Math.sqrt(e*e+r*r+i*i)}return Math.sqrt(e*e+r*r)}function i(t,n,e){const r=t[0]+e*(n[0]-t[0]),i=t[1]+e*(n[1]-t[1]);return t.length>2&&n.length>2?[r,i,t[2]+e*(n[2]-t[2])]:[r,i]}function o(t,n,e,r){return s(t,n,e[r],e[r+1])}function s(t,n,e,r){const[i,o]=n,[s,u]=e,[l,f]=r,c=l-s,h=f-u,g=c*c+h*h,p=(i-s)*c+(o-u)*h,a=Math.min(1,Math.max(0,p/g));return t[0]=s+c*a,t[1]=u+h*a,t}function u(t,n,e){let r,i,o,s,u=!1,f=1/0;for(e.reset();e.nextPath();)if(e.nextPoint())for(r=e.x,i=e.y;e.nextPoint();)o=e.x,s=e.y,i>n!=s>n&&t<(o-r)*(n-i)/(s-i)+r&&(u=!u),f=Math.min(f,l(t,n,r,i,o,s)),r=o,i=s;return 0===f?0:(u?1:-1)*Math.sqrt(f)}function l(t,n,e,r,i,o){let s=e,u=r,l=i-s,f=o-u;if(0!==l||0!==f){const e=((t-s)*l+(n-u)*f)/(l*l+f*f);e>1?(s=i,u=o):e>0&&(s+=l*e,u+=f*e)}return l=t-s,f=n-u,l*l+f*f}function f(t,n){return i(t,n,.5)}function c(t){const n=t.length;let e=0;for(let i=0;i<n-1;++i)e+=r(t[i],t[i+1]);return e}function h(t,n){if(n<=0)return t[0];const e=t.length;let o=0;for(let s=0;s<e-1;++s){const e=r(t[s],t[s+1]);if(n-o<e){const r=(n-o)/e;return i(t[s],t[s+1],r)}o+=e}return t[e-1]}function g(t,n=0,e=1){let r=0;const i=t.length;let o=t[0];for(let s=1;s<i;s++){const i=t[s];r+=(i[n]-o[n])*(i[e]+o[e]),o=i}if(p(t)){const i=t[0];r+=(i[n]-o[n])*(i[e]+o[e])}return r>=0}function p(n){const e=n.length;return e>0&&!t(n[0],n[e-1])}function a(t){"rings"in t&&(y(t),m(t))}function y(t){if("rings"in t)for(const n of t.rings)p(n)&&n.push(n[0].slice())}function m(t){if(!("rings"in t))return!1;if(0===t.rings.length||g(t.rings[0]))return!1;for(const n of t.rings)n.reverse();return!0}function x(t,n){return t===n||t.type===n.type&&("point"===t.type||"mesh"===t.type||"extent"===t.type||("multipoint"===t.type&&"multipoint"===n.type?t.points.length===n.points.length:"polyline"===t.type&&"polyline"===n.type?t.curvePaths?.length===n.curvePaths?.length&&t.paths.length===n.paths.length&&(t.curvePaths?.length?v(t.curvePaths,n.curvePaths,!0):v(t.paths,n.paths,!1)):"polygon"===t.type&&"polygon"===n.type&&(t.curveRings?.length===n.curveRings?.length&&t.rings.length===n.rings.length&&(t.curveRings?.length?v(t.curveRings,n.curveRings,!0):v(t.rings,n.rings,!1)))))}function v(t,e,r){if(void 0===t&&void 0===e)return!0;if(void 0===t||void 0===e)return!1;for(let i=0;i<t.length;i++){if(t[i].length!==e[i].length)return!1;if(r)for(let r=0;r<t[i].length;r++)if(!n(t[i][r],e[i][r]))return!1}return!0}export{y as closeRings,a as closeRingsAndFixWinding,u as distanceFromPointToPolygon,l as distanceToSegmentSquared,e as geometryToCoordinates,r as getLength,f as getMidpoint,c as getPathLength,h as getPointOnPath,x as hasCompatibleTopology,g as isClockwise,o as projectPointOnLine,s as projectPointOnLineSeg};
