/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{getEndpoint as e,isEllipticArc7 as t,isEllipticArc4 as i,isCircularArc as r,isBezierCurve as o,isCoordinate as s}from"../../../../geometry/support/curves/curveUtils.js";import{createConnectingSegment as n}from"../EditGeometry.js";class a{constructor(e,t,i){this._editGeometry=e,this._vertex=t,this._pos=i}apply(){const e=null==this._originalPosition;e&&(this._originalPosition=this._vertex.leftSegment?.toCurveOrCoordinate()??this._vertex.pos),this._apply(e?"apply":"redo")}undo(){const t=this._vertex.leftSegment;t&&this._originalPosition&&this._replaceEdge(t,this._vertex,this._originalPosition),this._vertex.pos=this._editGeometry.coordinateHelper.arrayToVector(e(this._originalPosition)),this._editGeometry.notifyChanges({operation:"undo",updatedVertices:[this._vertex]})}accumulate(e){return e instanceof a&&e._vertex===this._vertex&&(this._pos=e._pos,this._apply("apply"),!0)}_apply(n){this._vertex.pos=this._editGeometry.coordinateHelper.arrayToVector(e(this._pos));const a=this._pos,c=this._vertex.leftSegment;switch(c?.type){case void 0:break;case"line":s(a)||this._replaceEdge(c,this._vertex,a);break;case"bezier":o(a)?(c.curveDefinition.controlPoint1=a.b[1],c.curveDefinition.controlPoint2=a.b[2]):this._replaceEdge(c,this._vertex,a);break;case"circular-arc":r(a)?c.curveDefinition.interiorPoint=a.c[1]:this._replaceEdge(c,this._vertex,a);break;case"elliptic-arc-4":i(a)?(c.curveDefinition.centerPoint=a.a[1],c.curveDefinition.sweep=a.a[2],c.curveDefinition.orientation=a.a[3]):this._replaceEdge(c,this._vertex,a);break;case"elliptic-arc-7":t(a)?(c.curveDefinition.centerPoint=a.a[1],c.curveDefinition.sweep=a.a[2],c.curveDefinition.orientation=a.a[3],c.curveDefinition.rotation=a.a[4],c.curveDefinition.semiMajorAxisLength=a.a[5],c.curveDefinition.minorMajorAxisRatio=a.a[6]):this._replaceEdge(c,this._vertex,a)}this._editGeometry.parts.forEach(e=>e.unnormalizeVertexPositions()),this._editGeometry.notifyChanges({operation:n,updatedVertices:[this._vertex]})}_replaceEdge(e,t,i){const r=this._vertex.part,o=e?r.segments.indexOf(e):-1;if(o>-1&&e.leftVertex){const s=n(r,e.leftVertex,t,i);this._vertex.part.segments.splice(o,1,s)}}}export{a as SetVertexPosition};
