public PlaPointInt[] nearest_border_projections(PlaPointInt p_point,int p_max_result_points){
  if (p_max_result_points <= 0) {
    return new PlaPointInt[0];
  }
  p_max_result_points=Math.min(p_max_result_points,2);
  PlaPointInt[] result=new PlaPointInt[p_max_result_points];
  int lower_x_diff=p_point.v_x - box_ll.v_x;
  int upper_x_diff=box_ur.v_x - p_point.v_x;
  int lower_y_diff=p_point.v_y - box_ll.v_y;
  int upper_y_diff=box_ur.v_y - p_point.v_y;
  int min_diff;
  int second_min_diff;
  int nearest_projection_x=p_point.v_x;
  int nearest_projection_y=p_point.v_y;
  int second_nearest_projection_x=p_point.v_x;
  int second_nearest_projection_y=p_point.v_y;
  if (lower_x_diff <= upper_x_diff) {
    min_diff=lower_x_diff;
    second_min_diff=upper_x_diff;
    nearest_projection_x=box_ll.v_x;
    second_nearest_projection_x=box_ur.v_x;
  }
 else {
    min_diff=upper_x_diff;
    second_min_diff=lower_x_diff;
    nearest_projection_x=box_ur.v_x;
    second_nearest_projection_x=box_ll.v_x;
  }
  if (lower_y_diff < min_diff) {
    second_min_diff=min_diff;
    min_diff=lower_y_diff;
    second_nearest_projection_x=nearest_projection_x;
    second_nearest_projection_y=nearest_projection_y;
    nearest_projection_x=p_point.v_x;
    nearest_projection_y=box_ll.v_y;
  }
 else   if (lower_y_diff < second_min_diff) {
    second_min_diff=lower_y_diff;
    second_nearest_projection_x=p_point.v_x;
    second_nearest_projection_y=box_ll.v_y;
  }
  if (upper_y_diff < min_diff) {
    second_min_diff=min_diff;
    min_diff=upper_y_diff;
    second_nearest_projection_x=nearest_projection_x;
    second_nearest_projection_y=nearest_projection_y;
    nearest_projection_x=p_point.v_x;
    nearest_projection_y=box_ur.v_y;
  }
 else   if (upper_y_diff < second_min_diff) {
    second_min_diff=upper_y_diff;
    second_nearest_projection_x=p_point.v_x;
    second_nearest_projection_y=box_ur.v_y;
  }
  result[0]=new PlaPointInt(nearest_projection_x,nearest_projection_y);
  if (result.length > 1) {
    result[1]=new PlaPointInt(second_nearest_projection_x,second_nearest_projection_y);
  }
  return result;
}

public PlaPointInt [ ] nearest_border_projections ( PlaPointInt p_point , int p_max_result_points ) { if ( p_max_result_points <= 0 ) { return new PlaPointInt [ 0 ] ; } p_max_result_points = Math . min ( p_max_result_points , 2 ) ; PlaPointInt [ ] result = new PlaPointInt [ p_max_result_points ] ; int lower_x_diff = p_point . v_x - box_ll . v_x ; int upper_x_diff = box_ur . v_x - p_point . v_x ; int lower_y_diff = p_point . v_y - box_ll . v_y ; int upper_y_diff = box_ur . v_y - p_point . v_y ; int min_diff ; int second_min_diff ; int nearest_projection_x = p_point . v_x ; int nearest_projection_y = p_point . v_y ; int second_nearest_projection_x = p_point . v_x ; int second_nearest_projection_y = p_point . v_y ; if ( lower_x_diff <= upper_x_diff ) { min_diff = lower_x_diff ; second_min_diff = upper_x_diff ; nearest_projection_x = box_ll . v_x ; second_nearest_projection_x = box_ur . v_x ; } else { min_diff = upper_x_diff ; second_min_diff = lower_x_diff ; nearest_projection_x = box_ur . v_x ; second_nearest_projection_x = box_ll . v_x ; } if ( lower_y_diff < min_diff ) { second_min_diff = min_diff ; min_diff = lower_y_diff ; second_nearest_projection_x = nearest_projection_x ; second_nearest_projection_y = nearest_projection_y ; nearest_projection_x = p_point . v_x ; nearest_projection_y = box_ll . v_y ; } else if ( lower_y_diff < second_min_diff ) { second_min_diff = lower_y_diff ; second_nearest_projection_x = p_point . v_x ; second_nearest_projection_y = box_ll . v_y ; } if ( upper_y_diff < min_diff ) { second_min_diff = min_diff ; min_diff = upper_y_diff ; second_nearest_projection_x = nearest_projection_x ; second_nearest_projection_y = nearest_projection_y ; nearest_projection_x = p_point . v_x ; nearest_projection_y = box_ur . v_y ; } else if ( upper_y_diff < second_min_diff ) { second_min_diff = upper_y_diff ; second_nearest_projection_x = p_point . v_x ; second_nearest_projection_y = box_ur . v_y ; } result [ 0 ] = new PlaPointInt ( nearest_projection_x , nearest_projection_y ) ; if ( result . length > 1 ) { result [ 1 ] = new PlaPointInt ( second_nearest_projection_x , second_nearest_projection_y ) ; } return result ; }
calculates the sorted p_max_result_points nearest points on the border of this box . p_point is assumed to be located in the interiour of this nox . the funtion is only imoplemented for p_max_result_points < = 2 ;
