def enforce_multiple(unit_rect, area_rect):
    """Guarantee area rect's size is multiple of unit rect's.

    The area rect dimensions being multiple of the unit
    rect dimensions is a requirement to produce a grid
    whose lines are equidistant and scroll smoothly.

    By doing so we keep the illusion of indefinite
    scrolling whenever moving lines forming a grid.
    Otherwise, if we were to allow the area rect
    dimensions to not be multiple of the unit rect
    the last line in the non-multiple orientation(s)
    would always have a different distance from the
    others, thus preventing the proper representation
    of a grid.

    unit_rect
        pygame.Rect instance representing an unit in the
        grid.
    area_rect
        pygame.Rect instance representing the area covered
        by the grid.
    """
    ### reference unit rect and area rect dimensions

    unit_width, unit_height = unit_rect.size
    area_width, area_height = area_rect.size

    ### if any of the area rect dimensions aren't
    ### a multiple of the respective unit rect dimension,
    ### create a new area rect positioned at the same
    ### topleft position of the original one, but with
    ### dimensions extended just enough to reach the
    ### nearest multiple

    if area_width % unit_width or area_height % unit_height:

        new_width = get_reaching_multiple(unit_width, area_width)
        new_height = get_reaching_multiple(unit_height, area_height)

        area_rect = Rect(*area_rect.topleft, new_width, new_height)

    return unit_rect, area_rect
Guarantee area rect's size is multiple of unit rect's.

    The area rect dimensions being multiple of the unit
    rect dimensions is a requirement to produce a grid
    whose lines are equidistant and scroll smoothly.

    By doing so we keep the illusion of indefinite
    scrolling whenever moving lines forming a grid.
    Otherwise, if we were to allow the area rect
    dimensions to not be multiple of the unit rect
    the last line in the non-multiple orientation(s)
    would always have a different distance from the
    others, thus preventing the proper representation
    of a grid.

    unit_rect
        pygame.Rect instance representing an unit in the
        grid.
    area_rect
        pygame.Rect instance representing the area covered
        by the grid.
    
nodezator/our3rdlibs/grid/main.py