Fixes in grid generation for pedantic special cases when one or both grid dimensions are very small. [originally from svn r5390]