public double getNearestDistanceFrom(int i, int j) {
		if (i<0) {
			return getNearestDistanceFrom(0, j)-i;
		}
		if(j<0) {
			return getNearestDistanceFrom(i, 0)-j;
		}
		if (i>= img.getWidth()) {
			return getNearestDistanceFrom(img.getWidth()-1, j)+(i-img.getWidth());
		}
		if (j>= img.getHeight()) {
			return getNearestDistanceFrom(i, img.getHeight()-1)+(j-img.getHeight());
		}
		return nearestArr[i][j];
	}