Exemplo n.º 1
0
def test_ObscRay():
    rng = np.random.default_rng(5772)
    size = 10_000

    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)
        th = rng.uniform(0.0, np.pi / 2)
        obsc = batoid.ObscRay(w, th, cx, cy)

        for i in range(100):
            x = rng.normal(0.0, 2.0)
            y = rng.normal(0.0, 2.0)
            xp = (x - cx) * np.cos(-th) - (y - cy) * np.sin(-th)
            yp = (x - cx) * np.sin(-th) + (y - cy) * np.cos(-th)
            assert obsc.contains(x, y) == (xp > 0.0 and yp > -w / 2
                                           and yp < w / 2)

        x = rng.normal(0.0, 2.0, size=size)
        y = rng.normal(0.0, 2.0, size=size)
        xp = (x - cx) * np.cos(-th) - (y - cy) * np.sin(-th)
        yp = (x - cx) * np.sin(-th) + (y - cy) * np.cos(-th)
        np.testing.assert_array_equal(obsc.contains(x, y), (xp > 0.0) &
                                      (yp > -w / 2) & (yp < w / 2))

        do_pickle(obsc)

        rv = batoid.RayVector(x, y, 0.0, 0.0, 0.0, 0.0)
        batoid.obscure(obsc, rv)
        np.testing.assert_array_equal(obsc.contains(x, y), rv.vignetted)
Exemplo n.º 2
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)