src/index.js
function calculateDiff() {
    // we need to take 2 pointers
    // and travel progressively between them ...
    var newFirst = [
      [].concat(array1Extract[0]),
      [].concat(array1Extract[1])
    ];
    var newSecond = [
      [].concat(array2Extract[0]),
      [].concat(array2Extract[1])
    ];
    var array1Length = array1Extract[0] ? array1Extract[0].length : 0;
    var array2Length = array2Extract[0] ? array2Extract[0].length : 0;

    var pos1 = 0;
    var pos2 = 0;
    var previous2 = 0;
    while (pos1 < array1Length) {
      var diff = newFirst[0][pos1] - array2Extract[0][pos2];
      if (Math.abs(diff) < widthBottom) { // there is some overlap
        var overlap;
        if (options.trapezoid) {
          overlap = getOverlapTrapezoid(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        } else {
          overlap = getOverlap(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        }
        newFirst[1][pos1] -= overlap;
        newSecond[1][pos2] -= overlap;
        if (pos2 < (array2Length - 1)) {
          pos2++;
        } else {
          pos1++;
          pos2 = previous2;
        }
      } else {
        if (diff > 0 && pos2 < (array2Length - 1)) {
          pos2++;
          previous2 = pos2;
        } else {
          pos1++;
          pos2 = previous2;
        }
      }
    }
    return newSecond;
  }
function calculateDiff() {
    // we need to take 2 pointers
    // and travel progressively between them ...
    var newFirst = [
      [].concat(array1Extract[0]),
      [].concat(array1Extract[1])
    ];
    var newSecond = [
      [].concat(array2Extract[0]),
      [].concat(array2Extract[1])
    ];
    var array1Length = array1Extract[0] ? array1Extract[0].length : 0;
    var array2Length = array2Extract[0] ? array2Extract[0].length : 0;

    var pos1 = 0;
    var pos2 = 0;
    var previous2 = 0;
    while (pos1 < array1Length) {
      var diff = newFirst[0][pos1] - array2Extract[0][pos2];
      if (Math.abs(diff) < widthBottom) { // there is some overlap
        var overlap;
        if (options.trapezoid) {
          overlap = getOverlapTrapezoid(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        } else {
          overlap = getOverlap(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        }
        newFirst[1][pos1] -= overlap;
        newSecond[1][pos2] -= overlap;
        if (pos2 < (array2Length - 1)) {
          pos2++;
        } else {
          pos1++;
          pos2 = previous2;
        }
      } else {
        if (diff > 0 && pos2 < (array2Length - 1)) {
          pos2++;
          previous2 = pos2;
        } else {
          pos1++;
          pos2 = previous2;
        }
      }
    }
    return newSecond;
  }
function calculateDiff ( ) { // we need to take 2 pointers // and travel progressively between them ... var newFirst = [ [ ] . concat ( array1Extract [ 0 ] ) , [ ] . concat ( array1Extract [ 1 ] ) ] ; var newSecond = [ [ ] . concat ( array2Extract [ 0 ] ) , [ ] . concat ( array2Extract [ 1 ] ) ] ; var array1Length = array1Extract [ 0 ] ? array1Extract [ 0 ] . length : 0 ; var array2Length = array2Extract [ 0 ] ? array2Extract [ 0 ] . length : 0 ; var pos1 = 0 ; var pos2 = 0 ; var previous2 = 0 ; while ( pos1 < array1Length ) { var diff = newFirst [ 0 ] [ pos1 ] - array2Extract [ 0 ] [ pos2 ] ; if ( Math . abs ( diff ) < widthBottom ) { // there is some overlap var overlap ; if ( options . trapezoid ) { overlap = getOverlapTrapezoid ( newFirst [ 0 ] [ pos1 ] , newFirst [ 1 ] [ pos1 ] , newSecond [ 0 ] [ pos2 ] , newSecond [ 1 ] [ pos2 ] , widthTop , widthBottom ) ; } else { overlap = getOverlap ( newFirst [ 0 ] [ pos1 ] , newFirst [ 1 ] [ pos1 ] , newSecond [ 0 ] [ pos2 ] , newSecond [ 1 ] [ pos2 ] , widthTop , widthBottom ) ; } newFirst [ 1 ] [ pos1 ] -= overlap ; newSecond [ 1 ] [ pos2 ] -= overlap ; if ( pos2 < ( array2Length - 1 ) ) { pos2 ++ ; } else { pos1 ++ ; pos2 = previous2 ; } } else { if ( diff > 0 && pos2 < ( array2Length - 1 ) ) { pos2 ++ ; previous2 = pos2 ; } else { pos1 ++ ; pos2 = previous2 ; } } } return newSecond ; }
this method calculates the total diff. The sum of positive value will yield to overlap
this method calculates the total diff . The sum of positive value will yield to overlap