private void calcoffset(int index,boolean doExtend,Point2D result){
  double bx=data[index - 3];
  double by=data[index - 2];
  double px=result.getX() - bx;
  double py=result.getY() - by;
  double dx=data[index] - bx;
  double dy=data[index + 1] - by;
  double l=data[index + 2] - data[index - 1];
  double rx=(px * dx + py * dy) / l;
  double ry=(px * -dy + py * dx) / l;
  if (!doExtend) {
    if (rx < 0)     rx=0;
 else     if (rx > l)     rx=l;
  }
  rx+=data[index - 1];
  result.setLocation(rx,ry);
}

private void calcoffset ( int index , boolean doExtend , Point2D result ) { double bx = data [ index - 3 ] ; double by = data [ index - 2 ] ; double px = result . getX ( ) - bx ; double py = result . getY ( ) - by ; double dx = data [ index ] - bx ; double dy = data [ index + 1 ] - by ; double l = data [ index + 2 ] - data [ index - 1 ] ; double rx = ( px * dx + py * dy ) / l ; double ry = ( px * - dy + py * dx ) / l ; if ( ! doExtend ) { if ( rx < 0 ) rx = 0 ; else if ( rx > l ) rx = l ; } rx += data [ index - 1 ] ; result . setLocation ( rx , ry ) ; }
return the location of the point passed in result as mapped to the line indicated by index . if doextend is true , extend the x value without pinning to the ends of the line . this assumes that index is valid and references a line that has non - zero length .
