@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.09 kB
JavaScript
import{isNone as e,isSome as t}from"../../../../core/maybe.js";import{Vertex as i,Edge as s}from"../EditGeometry.js";class d{constructor(e,t,i){this._editGeometry=e,this._component=t,this._pos=i,this._addedVertex=null,this._originalEdge=null,this._left=null,this._right=null}apply(){let d="redo";e(this._addedVertex)&&(d="apply",this._addedVertex=new i(this._component));const h=this._component.getLastVertex();if(e(h))this._component.vertices.push(this._addedVertex),this._addedVertex.pos=this._pos,this._addedVertex.index=0;else{let i=null;h.rightEdge&&(this._originalEdge=h.rightEdge,i=this._originalEdge.rightVertex,this._component.edges.splice(this._component.edges.indexOf(this._originalEdge),1)),this._component.vertices.push(this._addedVertex),this._addedVertex.pos=this._pos,e(this._left)&&(this._left=new s(this._component,h,this._addedVertex)),this._component.edges.push(this._left),h.rightEdge=this._left,t(this._originalEdge)&&t(i)&&(e(this._right)&&(this._right=new s(this._component,this._addedVertex,i)),this._component.edges.push(this._right),i.leftEdge=this._right),this._component.updateVertexIndex(this._addedVertex,h.index+1)}this._editGeometry.notifyChanges({operation:d,addedVertices:[this._addedVertex]})}undo(){e(this._addedVertex)||(this._component.vertices.splice(this._component.vertices.indexOf(this._addedVertex),1),t(this._left)&&(this._component.edges.splice(this._component.edges.indexOf(this._left),1),this._left.leftVertex.rightEdge=null),t(this._right)&&(this._component.edges.splice(this._component.edges.indexOf(this._right),1),this._right.rightVertex.leftEdge=null),t(this._originalEdge)&&(this._component.edges.push(this._originalEdge),this._originalEdge.leftVertex.rightEdge=this._originalEdge,this._originalEdge.rightVertex.leftEdge=this._originalEdge),t(this._left)?this._component.updateVertexIndex(this._left.leftVertex,this._left.leftVertex.index):this._component.updateVertexIndex(this._addedVertex,0),this._editGeometry.notifyChanges({operation:"undo",removedVertices:[this._addedVertex]}))}accumulate(){return!1}}export{d as AppendVertex};