private static double calcEdgeOffset(int i,int n,int w,boolean away_from){
  double i_d=(double)i;
  double n_d=(double)n;
  double w_d=(double)w;
  double offset=w_d * (2.0 * i_d + 1.0 - n_d) / 2.0 / n_d;
  double direction=away_from ? 1.0 : -1.0;
  return direction * offset;
}

private static double calcEdgeOffset ( int i , int n , int w , boolean away_from ) { double i_d = ( double ) i ; double n_d = ( double ) n ; double w_d = ( double ) w ; double offset = w_d * ( 2.0 * i_d + 1.0 - n_d ) / 2.0 / n_d ; double direction = away_from ? 1.0 : - 1.0 ; return direction * offset ; }
calculates the offset in pixels of a given edge - this could use a little tweaking still .
