Calculate the optimal tile spacing instead of hard coding values