Node n1Old = selectedSegment.getFirstNode();
Node n1New = new Node(Main.getProjection().eastNorth2latlon(newN1en));
wnew.addNode(insertionPoint, n1New);
wnew.removeNode(n1Old);
wayWasModified = true;
cmds.add(new AddCommand(n1New));
changedNodes.add(n1New);
} else {
//introduce new node
Node n1New = new Node(Main.getProjection().eastNorth2latlon(newN1en));
wnew.addNode(insertionPoint, n1New);
wayWasModified = true;
insertionPoint ++;
cmds.add(new AddCommand(n1New));
changedNodes.add(n1New);
}
//find if the new points overlap existing segments (in case of 90 degree angles)
Node nextNode = getNextNode(selectedSegment.lowerIndex + 1);
nodeOverlapsSegment = nextNode != null && Geometry.segmentsParallel(initialN2en, nextNode.getEastNorth(), initialN2en, newN2en);
segmentAngleZero = nextNode != null && Math.abs(Geometry.getCornerAngle(nextNode.getEastNorth(), initialN2en, newN2en)) < 1e-5;
hasOtherWays = hasNodeOtherWays(selectedSegment.getSecondNode(), selectedSegment.way);
if (nodeOverlapsSegment && !alwaysCreateNodes && !hasOtherWays) {
//move existing node
Node n2Old = selectedSegment.getSecondNode();
cmds.add(new MoveCommand(n2Old, Main.getProjection().eastNorth2latlon(newN2en)));
changedNodes.add(n2Old);
} else if (ignoreSharedNodes && segmentAngleZero && !alwaysCreateNodes && hasOtherWays) {
// replace shared node with new one
Node n2Old = selectedSegment.getSecondNode();
Node n2New = new Node(Main.getProjection().eastNorth2latlon(newN2en));
wnew.addNode(insertionPoint, n2New);
wnew.removeNode(n2Old);
wayWasModified = true;
cmds.add(new AddCommand(n2New));
changedNodes.add(n2New);
} else {
//introduce new node
Node n2New = new Node(Main.getProjection().eastNorth2latlon(newN2en));
wnew.addNode(insertionPoint, n2New);
wayWasModified = true;
insertionPoint ++;
cmds.add(new AddCommand(n2New));
changedNodes.add(n2New);
}
//the way was a single segment, close the way
if (wayWasSingleSegment) {