/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{P as e}from"../../chunks/Envelope.js";import{O as t}from"../../chunks/OperatorProximity.js";import{fromGeometry as n,fromPoint as r,toPoint as o,getSpatialReference as i}from"../../geometry/operators/support/apiConverter.js";function s(e,t,n){const r=(t.x-e.x)*(n.y-e.y)-(n.x-e.x)*(t.y-e.y);return r>0?"left":r<0?"right":"straddle"}function a(e,t,n){if(e.getPointCount()<=0)return"left";const r=e.querySegmentIteratorAtVertex(n),o=r.hasPreviousSegment()?r.previousSegment():r.nextSegment();return s(o.getStartXY(),o.getEndXY(),t)}const c=new t;function d(t,s){const d=n(t),m=r(s).getXY(),p=c.getNearestVertex(d,m);if(p.isEmpty())return null;switch(t.type){case"point":return{coordinate:t,distance:p.m_distance,sideOfLine:0===p.m_distance?"straddle":"left"};case"multipoint":{const n=new e;return d.getPointByVal(p.m_vertexIndex,n),{coordinate:o(n,i(t)),distance:p.m_distance,sideOfLine:0===p.m_distance?"straddle":"left"}}case"polyline":case"polygon":{const n=new e;return d.getPointByVal(p.m_vertexIndex,n),{coordinate:o(n,i(t)),distance:p.m_distance,sideOfLine:a(d,m,p.m_vertexIndex)}}default:throw new Error(`Unsupported geometry type: ${t.type}`)}}export{d as executeNearestVertex};
