code: function filterRedundantWaypoints(waypoints, segmentStartIndex) {
  
      var segmentOffset = 0;
  
      var filteredWaypoints = waypoints.filter(function(r, idx) {
        if (pointsOnLine(waypoints[idx - 1], waypoints[idx + 1], r)) {
  
          // remove point and increment offset
          segmentOffset = idx <= segmentStartIndex ? segmentOffset - 1 : segmentOffset;
          return false;
        }
  
        // dont remove point
        return true;
      });
  
      return {
        waypoints: filteredWaypoints,
        segmentOffset: segmentOffset
      };
    }
docs: Filter waypoints for redundant ones (i.e. on the same axis).
  Returns the filtered waypoints and the offset related to the segment move.
  
  @param {Array<Point>} waypoints
  @param {Integer} segmentStartIndex of moved segment start
  
  @return {Object} { filteredWaypoints, segmentOffset }