Extract common code (grid and vector2).