def test_boolean_mix_periodicity():
r"""Test that a hybrid boolean region behaves as we expect.
This also tests nested logic and that periodicity works.
"""
ds = fake_amr_ds()
re = ds.region([0.5]*3, [0.0]*3, [1]*3) # whole thing
sp = ds.sphere([0.95]*3, 0.3) # wraps around
cyl = ds.disk([0.05]*3, [1,1,1], 0.1, 0.4) # wraps around
# Get original indices
rei = re["index","morton_index"]
spi = sp["index","morton_index"]
cyli = cyl["index","morton_index"]
# Make some booleans
# whole box minux spherical bites at corners
bo1 = re - sp
# sphere plus cylinder
bo2 = sp | cyl
# a jumble, the region minus the sp+cyl
bo3 = re - (sp | cyl)
# Now make sure the indices also behave as we expect.
bo4 = ds.union([re, sp, cyl])
bo5 = ds.intersection([re, sp, cyl])
expect = np.setdiff1d(rei, spi)
ii = bo1["index","morton_index"]
ii.sort()
assert_array_equal(expect, ii)
#
expect = np.union1d(spi, cyli)
ii = bo2["index","morton_index"]
ii.sort()
assert_array_equal(expect, ii)
#
expect = np.union1d(spi, cyli)
expect = np.setdiff1d(rei, expect)
ii = bo3["index","morton_index"]
ii.sort()
assert_array_equal(expect, ii)
b4 = bo4["index","morton_index"]
b4.sort()
b5 = bo5["index","morton_index"]
b5.sort()
ii = np.union1d(np.union1d(rei, cyli), spi)
ii.sort()
assert_array_equal(ii, b4)
ii = np.intersect1d(np.intersect1d(rei, cyli), spi)
ii.sort()
assert_array_equal(ii, b5)
bo6 = (re ^ sp) ^ cyl
b6 = bo6["index", "morton_index"]
b6.sort()
assert_array_equal(b6, np.setxor1d(np.setxor1d(rei, spi), cyli))
评论列表
文章目录