public double calcDistance(final double x,final double y){
  double distanceX;
  double distanceY;
  if (this.minX <= x && x <= this.maxX) {
    distanceX=0;
  }
 else {
    distanceX=Math.min(Math.abs(this.minX - x),Math.abs(this.maxX - x));
  }
  if (this.minY <= y && y <= this.maxY) {
    distanceY=0;
  }
 else {
    distanceY=Math.min(Math.abs(this.minY - y),Math.abs(this.maxY - y));
  }
  return Math.sqrt(distanceX * distanceX + distanceY * distanceY);
}

public double calcDistance ( final double x , final double y ) { double distanceX ; double distanceY ; if ( this . minX <= x && x <= this . maxX ) { distanceX = 0 ; } else { distanceX = Math . min ( Math . abs ( this . minX - x ) , Math . abs ( this . maxX - x ) ) ; } if ( this . minY <= y && y <= this . maxY ) { distanceY = 0 ; } else { distanceY = Math . min ( Math . abs ( this . minY - y ) , Math . abs ( this . maxY - y ) ) ; } return Math . sqrt ( distanceX * distanceX + distanceY * distanceY ) ; }
calculates the ( minimum ) distance of a given point to the border of the rectangle . if the point lies within the rectangle , the distance is zero .
