p.prepend(new TrainPath(new IntLine[]{newStartSegment})); p.append(new TrainPath(new IntLine[]{newEndSegment}));
if (newStartSegment.getDirection() == CompassPoints.invert(oldStartSegment.getDirection())) { p.removeFirst(); p.addFirst(new IntLine(newStart.x, newStart.y, oldStartSegment.x2, oldStartSegment.y2)); } else { p.addFirst(newStartSegment); } if (newEndSegment.getDirection() == CompassPoints.invert(oldEndSegment.getDirection())) { p.removeLast(); p.addLast(new IntLine(oldEndSegment.x1, oldEndSegment.y1, newEnd.x, newEnd.y)); } else { p.addLast(newEndSegment); }
    private void fixUpPathEnds(TrainPath p, Point newStart, Point newEnd) {	Point oldStart = new Point();	Point oldEnd = new Point();	p.getHead(oldStart);	p.getTail(oldEnd);	IntLine newStartSegment = new IntLine(newStart, oldStart);	IntLine newEndSegment = new IntLine(oldEnd, newEnd);	p.prepend(new TrainPath(new IntLine[]{newStartSegment}));	p.append(new TrainPath(new IntLine[]{newEndSegment}));    }