def countRectsInGrid(gridWidth, gridHeight, abortLimit=None):
    """Count how many rectangles fit in a grid with given dimensions.

    'abortLimit' is an optional argument to avoid counting beyond a
    certain limit."""

    return gridWidth * (gridWidth + 1) * gridHeight * (gridHeight + 1) // 4