def test_region_invert_compare_invert():
    """-r and field()-r should ideally filter the same way
    but they are potentially different.
    """

    shape = "rect(100, 100, 104, 106)"
    r = Region(shape)
    r.invert()
    check_region_invert_compare(r)
def test_region_invert():
    """Can we invert a region?"""

    x = np.asarray([50, 95, 105])
    y = np.asarray([50, 105, 115])

    r = Region("box(100,100,10,20)")

    assert r.mask(x, y) == pytest.approx([0, 1, 0])

    r.invert()
    assert str(r) == "!Box(100,100,10,20)"

    assert r.mask(x, y) == pytest.approx([1, 0, 1])
Esempio n. 3
0
def test_region_invert_empty():
    """Can we invert an empty region?"""

    x = np.asarray([50, 95, 105])
    y = np.asarray([50, 105, 115])

    r = Region()

    assert r.mask(x, y) == pytest.approx([0, 0, 0])

    r.invert()
    assert str(r) == ''

    assert r.mask(x, y) == pytest.approx([0, 0, 0])