test_boolean_regions.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:yt 作者: yt-project 项目源码 文件源码
def test_boolean_cylinders_overlap():
    r"""Test to make sure that boolean objects (cylinders, overlap)
    behave the way we expect.

    Test overlapping cylinders.
    """
    ds = fake_amr_ds()
    cyl1 = ds.disk([0.45]*3, [1, 0, 0], 0.2, 0.2)
    cyl2 = ds.disk([0.55]*3, [1, 0, 0], 0.2, 0.2)
    # Get indices of both.
    i1 = cyl1["index","morton_index"]
    i2 = cyl2["index","morton_index"]
    # Make some booleans
    bo1 = cyl1 & cyl2
    bo2 = cyl1 - cyl2
    bo3 = cyl1 | cyl2
    bo4 = ds.union([cyl1, cyl2])
    bo5 = ds.intersection([cyl1, cyl2])
    # Now make sure the indices also behave as we expect.
    vlens = np.intersect1d(i1, i2)
    bite_disk = np.setdiff1d(i1, i2)
    both = np.union1d(i1, i2)
    b1 = bo1["index","morton_index"]
    b1.sort()
    b2 = bo2["index","morton_index"]
    b2.sort()
    b3 = bo3["index","morton_index"]
    b3.sort()
    assert_array_equal(b1, vlens)
    assert_array_equal(b2, bite_disk)
    assert_array_equal(b3, both)
    b4 = bo4["index","morton_index"]
    b4.sort()
    b5 = bo5["index","morton_index"]
    b5.sort()
    assert_array_equal(b3, b4)
    assert_array_equal(b1, b5)
    bo6 = cyl1 ^ cyl2
    b6 = bo6["index", "morton_index"]
    b6.sort()
    assert_array_equal(b6, np.setxor1d(i1, i2))
    del ds
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号