private void nextPoint(double x,double y,boolean connect){
  if (x == px && y == py) {
    return;
  }
  if (w == 0) {
    if (data == null) {
      data=new double[6];
    }
    if (connect) {
      w=3;
    }
  }
  if (w != 0 && !connect && !pconnect) {
    data[w - 3]=px=x;
    data[w - 2]=py=y;
    return;
  }
  if (w == data.length) {
    double[] t=new double[w * 2];
    System.arraycopy(data,0,t,0,w);
    data=t;
  }
  if (connect) {
    double dx=x - px;
    double dy=y - py;
    a+=sqrt(dx * dx + dy * dy);
  }
  data[w++]=x;
  data[w++]=y;
  data[w++]=a;
  px=x;
  py=y;
  pconnect=connect;
}

private void nextPoint ( double x , double y , boolean connect ) { if ( x == px && y == py ) { return ; } if ( w == 0 ) { if ( data == null ) { data = new double [ 6 ] ; } if ( connect ) { w = 3 ; } } if ( w != 0 && ! connect && ! pconnect ) { data [ w - 3 ] = px = x ; data [ w - 2 ] = py = y ; return ; } if ( w == data . length ) { double [ ] t = new double [ w * 2 ] ; System . arraycopy ( data , 0 , t , 0 , w ) ; data = t ; } if ( connect ) { double dx = x - px ; double dy = y - py ; a += sqrt ( dx * dx + dy * dy ) ; } data [ w ++ ] = x ; data [ w ++ ] = y ; data [ w ++ ] = a ; px = x ; py = y ; pconnect = connect ; }
add a new point , and increment advance if connect is true . this automatically rejects duplicate points and multiple disconnected points .
