public void addAndSimplify(double x,double y){
  final int len=data.size();
  if (len >= 4) {
    final double l1x=data.get(len - 4);
    final double l1y=data.get(len - 3);
    final double l2x=data.get(len - 2);
    final double l2y=data.get(len - 1);
    final double ldx=l2x - l1x;
    final double ldy=l2y - l1y;
    final double cdx=x - l2x;
    final double cdy=y - l2y;
    if ((ldx == 0) && (cdx == 0)) {
      data.remove(len - 2,2);
    }
 else     if ((ldy == 0) && (cdy == 0)) {
      data.remove(len - 2,2);
    }
 else     if (ldy > 0 && cdy > 0) {
      if (Math.abs((ldx / ldy) - (cdx / cdy)) < THRESHOLD) {
        data.remove(len - 2,2);
      }
    }
  }
  add(x,y);
}

public void addAndSimplify ( double x , double y ) { final int len = data . size ( ) ; if ( len >= 4 ) { final double l1x = data . get ( len - 4 ) ; final double l1y = data . get ( len - 3 ) ; final double l2x = data . get ( len - 2 ) ; final double l2y = data . get ( len - 1 ) ; final double ldx = l2x - l1x ; final double ldy = l2y - l1y ; final double cdx = x - l2x ; final double cdy = y - l2y ; if ( ( ldx == 0 ) && ( cdx == 0 ) ) { data . remove ( len - 2 , 2 ) ; } else if ( ( ldy == 0 ) && ( cdy == 0 ) ) { data . remove ( len - 2 , 2 ) ; } else if ( ldy > 0 && cdy > 0 ) { if ( Math . abs ( ( ldx / ldy ) - ( cdx / cdy ) ) < THRESHOLD ) { data . remove ( len - 2 , 2 ) ; } } } add ( x , y ) ; }
add a coordinate pair , performing curve simplification if possible .
