def in_bounds(x, y, margin, maxx, maxy):
    """Returns True if (x,y) is within the rectangle (margin,margin,maxx-margin,maxy-margin)."""
    return margin <= x < (maxx - margin) and margin <= y < (maxy - margin)