protected Point2D.Double constrainPoint(Point2D.Double p,TranslationDirection dir){
  Point2D.Double p0=constrainPoint((Point2D.Double)p.clone());
switch (dir) {
case NORTH:
case NORTH_WEST:
case NORTH_EAST:
    if (p0.y < p.y) {
      p.y=p0.y;
    }
 else     if (p0.y > p.y) {
      p.y=p0.y - height;
    }
  break;
case SOUTH:
case SOUTH_WEST:
case SOUTH_EAST:
if (p0.y < p.y) {
  p.y=p0.y + height;
}
 else if (p0.y > p.y) {
  p.y=p0.y;
}
break;
}
switch (dir) {
case WEST:
case NORTH_WEST:
case SOUTH_WEST:
if (p0.x < p.x) {
p.x=p0.x;
}
 else if (p0.x > p.x) {
p.x=p0.x - width;
}
break;
case EAST:
case NORTH_EAST:
case SOUTH_EAST:
if (p0.x < p.x) {
p.x=p0.x + width;
}
 else if (p0.x > p.x) {
p.x=p0.x;
}
break;
}
return p;
}

protected Point2D . Double constrainPoint ( Point2D . Double p , TranslationDirection dir ) { Point2D . Double p0 = constrainPoint ( ( Point2D . Double ) p . clone ( ) ) ; switch ( dir ) { case NORTH : case NORTH_WEST : case NORTH_EAST : if ( p0 . y < p . y ) { p . y = p0 . y ; } else if ( p0 . y > p . y ) { p . y = p0 . y - height ; } break ; case SOUTH : case SOUTH_WEST : case SOUTH_EAST : if ( p0 . y < p . y ) { p . y = p0 . y + height ; } else if ( p0 . y > p . y ) { p . y = p0 . y ; } break ; } switch ( dir ) { case WEST : case NORTH_WEST : case SOUTH_WEST : if ( p0 . x < p . x ) { p . x = p0 . x ; } else if ( p0 . x > p . x ) { p . x = p0 . x - width ; } break ; case EAST : case NORTH_EAST : case SOUTH_EAST : if ( p0 . x < p . x ) { p . x = p0 . x + width ; } else if ( p0 . x > p . x ) { p . x = p0 . x ; } break ; } return p ; }
constrains the placement of a point towards a direction . < p > this method changes the point which is passed as a parameter .
