def apply_bounds(grid, lVec):
    """
    Assumes periodicity and restricts grid positions to a box in x- and
    y-direction.
    """
    dx = lVec[1,0]-lVec[0,0]
    grid[0][grid[0] >= lVec[1,0]] -= dx
    grid[0][grid[0] < lVec[0,0]]  += dx
    dy = lVec[2,1]-lVec[0,1]
    grid[1][grid[1] >= lVec[2,1]] -= dy
    grid[1][grid[1] < lVec[0,1]]  += dy
    return grid