public double distance(int x, int y) {
		if (x >= left && x <= right) {
			if (y >= top) {
				if (y <= bottom) {
					return 0;
				}
				else {
					return y - bottom;
				}
			}
			else {
				return top - y;
			}
		}
		else if (y >= top && y <= bottom) {
			if (x < left) {
				return left - x;
			}
			else {
				return x - right;
			}
		}

		int dx = x < left ? left - x : x - right;
		int dy = y < top ? top - y : y - bottom;

		return Math.sqrt((double) dx * dx + (double) dy * dy);
	}