private PlaPointInt border_point(PlaPointInt p_point,PlaDirection p_dir){
  int result_x;
  int result_y;
  if (p_dir == PlaDirection.RIGHT) {
    result_x=Math.min(oct_rx,oct_urx - p_point.v_y);
    result_x=Math.min(result_x,oct_lrx + p_point.v_y);
    result_y=p_point.v_y;
  }
 else   if (p_dir == PlaDirection.LEFT) {
    result_x=Math.max(oct_lx,oct_ulx + p_point.v_y);
    result_x=Math.max(result_x,oct_llx - p_point.v_y);
    result_y=p_point.v_y;
  }
 else   if (p_dir == PlaDirection.UP) {
    result_x=p_point.v_x;
    result_y=Math.min(oct_uy,p_point.v_x - oct_ulx);
    result_y=Math.min(result_y,oct_urx - p_point.v_x);
  }
 else   if (p_dir == PlaDirection.DOWN) {
    result_x=p_point.v_x;
    result_y=Math.max(oct_ly,oct_llx - p_point.v_x);
    result_y=Math.max(result_y,p_point.v_x - oct_lrx);
  }
 else   if (p_dir == PlaDirection.RIGHT45) {
    result_x=(int)(Math.ceil(0.5 * (p_point.v_x - p_point.v_y + oct_urx)));
    result_x=Math.min(result_x,oct_rx);
    result_x=Math.min(result_x,p_point.v_x - p_point.v_x + oct_uy);
    result_y=p_point.v_y - p_point.v_x + result_x;
  }
 else   if (p_dir == PlaDirection.UP45) {
    result_x=(int)(Math.floor(0.5 * (p_point.v_x + p_point.v_y + oct_ulx)));
    result_x=Math.max(result_x,oct_lx);
    result_x=Math.max(result_x,p_point.v_x + p_point.v_y - oct_uy);
    result_y=p_point.v_y + p_point.v_x - result_x;
  }
 else   if (p_dir == PlaDirection.LEFT45) {
    result_x=(int)(Math.floor(0.5 * (p_point.v_x - p_point.v_y + oct_llx)));
    result_x=Math.max(result_x,oct_lx);
    result_x=Math.max(result_x,p_point.v_x - p_point.v_y + oct_ly);
    result_y=p_point.v_y - p_point.v_x + result_x;
  }
 else   if (p_dir == PlaDirection.DOWN45) {
    result_x=(int)(Math.ceil(0.5 * (p_point.v_x + p_point.v_y + oct_lrx)));
    result_x=Math.min(result_x,oct_rx);
    result_x=Math.min(result_x,p_point.v_x + p_point.v_y - oct_ly);
    result_y=p_point.v_y + p_point.v_x - result_x;
  }
 else {
    throw new IllegalArgumentException("IntOctagon.border_point: unexpected 45 degree direction");
  }
  return new PlaPointInt(result_x,result_y);
}

private PlaPointInt border_point ( PlaPointInt p_point , PlaDirection p_dir ) { int result_x ; int result_y ; if ( p_dir == PlaDirection . RIGHT ) { result_x = Math . min ( oct_rx , oct_urx - p_point . v_y ) ; result_x = Math . min ( result_x , oct_lrx + p_point . v_y ) ; result_y = p_point . v_y ; } else if ( p_dir == PlaDirection . LEFT ) { result_x = Math . max ( oct_lx , oct_ulx + p_point . v_y ) ; result_x = Math . max ( result_x , oct_llx - p_point . v_y ) ; result_y = p_point . v_y ; } else if ( p_dir == PlaDirection . UP ) { result_x = p_point . v_x ; result_y = Math . min ( oct_uy , p_point . v_x - oct_ulx ) ; result_y = Math . min ( result_y , oct_urx - p_point . v_x ) ; } else if ( p_dir == PlaDirection . DOWN ) { result_x = p_point . v_x ; result_y = Math . max ( oct_ly , oct_llx - p_point . v_x ) ; result_y = Math . max ( result_y , p_point . v_x - oct_lrx ) ; } else if ( p_dir == PlaDirection . RIGHT45 ) { result_x = ( int ) ( Math . ceil ( 0.5 * ( p_point . v_x - p_point . v_y + oct_urx ) ) ) ; result_x = Math . min ( result_x , oct_rx ) ; result_x = Math . min ( result_x , p_point . v_x - p_point . v_x + oct_uy ) ; result_y = p_point . v_y - p_point . v_x + result_x ; } else if ( p_dir == PlaDirection . UP45 ) { result_x = ( int ) ( Math . floor ( 0.5 * ( p_point . v_x + p_point . v_y + oct_ulx ) ) ) ; result_x = Math . max ( result_x , oct_lx ) ; result_x = Math . max ( result_x , p_point . v_x + p_point . v_y - oct_uy ) ; result_y = p_point . v_y + p_point . v_x - result_x ; } else if ( p_dir == PlaDirection . LEFT45 ) { result_x = ( int ) ( Math . floor ( 0.5 * ( p_point . v_x - p_point . v_y + oct_llx ) ) ) ; result_x = Math . max ( result_x , oct_lx ) ; result_x = Math . max ( result_x , p_point . v_x - p_point . v_y + oct_ly ) ; result_y = p_point . v_y - p_point . v_x + result_x ; } else if ( p_dir == PlaDirection . DOWN45 ) { result_x = ( int ) ( Math . ceil ( 0.5 * ( p_point . v_x + p_point . v_y + oct_lrx ) ) ) ; result_x = Math . min ( result_x , oct_rx ) ; result_x = Math . min ( result_x , p_point . v_x + p_point . v_y - oct_ly ) ; result_y = p_point . v_y + p_point . v_x - result_x ; } else { throw new IllegalArgumentException ( "IntOctagon.border_point: unexpected 45 degree direction" ) ; } return new PlaPointInt ( result_x , result_y ) ; }
calculates the border point of this octagon from p_point into the 45 degree direction p_dir . if this border point is not an intpoint the nearest outside intpoint of the octagon is returned .
