コード例 #1
0
def test_ObscPolygon():
    rng = np.random.default_rng(57721)
    # size = 10_000
    size = 10

    # Test equivalency with ObscRectangle
    for i in range(100):
        cx = rng.normal(0.0, 1.0)
        cy = rng.normal(0.0, 1.0)
        w = rng.uniform(0.5, 2.5)
        h = rng.uniform(0.5, 2.5)

        xs = [cx - w / 2, cx + w / 2, cx + w / 2, cx - w / 2]
        ys = [cy - h / 2, cy - h / 2, cy + h / 2, cy + h / 2]
        obscPoly = batoid.ObscPolygon(xs, ys)
        obscRect = batoid.ObscRectangle(w, h, cx, cy, 0.0)

        for i in range(100):
            x = rng.normal(0.0, 2.0)
            y = rng.normal(0.0, 2.0)
            assert obscPoly.contains(x, y) == obscRect.contains(x, y)

        x = rng.normal(0.0, 2.0, size=size)
        y = rng.normal(0.0, 2.0, size=size)
        np.testing.assert_array_equal(obscPoly.contains(x, y),
                                      obscRect.contains(x, y))

        do_pickle(obscPoly)

        rv = batoid.RayVector(x, y, 0.0, 0.0, 0.0, 0.0)
        batoid.obscure(obscPoly, rv)
        np.testing.assert_array_equal(obscPoly.contains(x, y), rv.vignetted)

    # Try Union of two Rectangles equal to Polygon.
    # Center of both rectangles at (1, 2)
    # One is width=4, height=2
    # Other is width=2, height=4
    r1 = batoid.ObscRectangle(4, 2, 1, 2)
    r2 = batoid.ObscRectangle(2, 4, 1, 2)
    o1 = batoid.ObscUnion([r1, r2])
    xs = [-2, -1, -1, 1, 1, 2, 2, 1, 1, -1, -1, -2, -2]
    ys = [1, 1, 2, 2, 1, 1, -1, -1, -2, -2, -1, -1, 1]
    o2 = batoid.ObscPolygon(np.array(xs) + 1, np.array(ys) + 2)

    x = rng.normal(0.0, 2.0, size=size)
    y = rng.normal(0.0, 2.0, size=size)
    np.testing.assert_array_equal(o1.contains(x, y), o2.contains(x, y))
コード例 #2
0
def test_ObscPolygon():
    import random
    random.seed(577215)

    # Test equivalency with ObscRectangle
    for i in range(100):
        cx = random.gauss(0.0, 1.0)
        cy = random.gauss(0.0, 1.0)
        w = random.uniform(0.5, 2.5)
        h = random.uniform(0.5, 2.5)

        xs = [cx - w / 2, cx + w / 2, cx + w / 2, cx - w / 2, cx - w / 2]
        ys = [cy - h / 2, cy - h / 2, cy + h / 2, cy + h / 2, cy - h / 2]
        obscPoly = batoid.ObscPolygon(xs, ys)
        obscRect = batoid.ObscRectangle(w, h, cx, cy, 0.0)

        for i in range(100):
            x = random.gauss(0.0, 2.0)
            y = random.gauss(0.0, 2.0)
            assert obscPoly.contains(x, y) == obscRect.contains(x, y)

    # Try Union of two Rectangles equal to Polygon.
    # Center of both rectangles at (1, 2)
    # One is width=4, height=2
    # Other is width=2, height=4
    r1 = batoid.ObscRectangle(4, 2, 1, 2)
    r2 = batoid.ObscRectangle(2, 4, 1, 2)
    o1 = batoid.ObscUnion([r1, r2])
    xs = [-2, -1, -1, 1, 1, 2, 2, 1, 1, -1, -1, -2, -2]
    ys = [1, 1, 2, 2, 1, 1, -1, -1, -2, -2, -1, -1, 1]
    o2 = batoid.ObscPolygon(np.array(xs) + 1, np.array(ys) + 2)

    for i in range(10000):
        x = random.gauss(0.0, 2.0)
        y = random.gauss(0.0, 2.0)
        assert o1.contains(x, y) == o2.contains(x, y)
    do_pickle(o2)
コード例 #3
0
def test_ne():
    objs = [
        batoid.ObscCircle(1.0),
        batoid.ObscCircle(2.0),
        batoid.ObscCircle(1.0, 0.1, 0.1),
        batoid.ObscAnnulus(0.0, 1.0),
        batoid.ObscAnnulus(0.1, 1.0),
        batoid.ObscAnnulus(0.1, 1.0, 0.1, 0.1),
        batoid.ObscRectangle(1.0, 2.0),
        batoid.ObscRectangle(1.0, 2.0, 0.1, 0.1),
        batoid.ObscRectangle(1.0, 2.0, 0.1, 0.1, 1.0),
        batoid.ObscRay(1.0, 2.0),
        batoid.ObscRay(1.0, 2.0, 0.1, 0.1),
        batoid.ObscNegation(batoid.ObscCircle(1.0)),
        batoid.ObscPolygon([0,1,1,0],[0,0,1,1]),
        batoid.ObscUnion([batoid.ObscCircle(1.0)]),
        batoid.ObscUnion([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.0)
        ]),
        batoid.ObscUnion([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.2)
        ]),
        batoid.ObscUnion([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.2),
            batoid.ObscAnnulus(1.0, 2.0)
        ]),
        batoid.ObscIntersection([batoid.ObscCircle(1.0)]),
        batoid.ObscIntersection([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.0)
        ]),
        batoid.ObscIntersection([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.2)
        ]),
        batoid.ObscIntersection([
            batoid.ObscCircle(1.0),
            batoid.ObscCircle(2.2),
            batoid.ObscAnnulus(1.0, 2.0)
        ]),
    ]
    all_obj_diff(objs)