def test_ObscCompound(): import random random.seed(57721) for i in range(100): rx = random.gauss(0.0, 1.0) ry = random.gauss(0.0, 1.0) w = random.uniform(0.5, 2.5) h = random.uniform(0.5, 2.5) th = random.uniform(0.0, np.pi) rect = batoid.ObscRectangle(w, h, rx, ry, th) cx = random.gauss(0.0, 1.0) cy = random.gauss(0.0, 1.0) r = random.uniform(0.5, 1.5) circ = batoid.ObscCircle(r, cx, cy) union = batoid.ObscUnion([rect, circ]) do_pickle(union) union2 = batoid.ObscUnion([circ, rect]) assert union == union2 # commutative! assert hash(union) == hash(union2) intersection = batoid.ObscIntersection([rect, circ]) do_pickle(intersection) intersection2 = batoid.ObscIntersection([circ, rect]) assert intersection == intersection2 assert hash(intersection) == hash(intersection2) for i in range(100): x = random.gauss(0.0, 2.0) y = random.gauss(0.0, 2.0) assert (union.contains(x, y) == union2.contains(x, y) == (rect.contains(x, y) or circ.contains(x, y))) assert (intersection.contains(x, y) == intersection2.contains( x, y) == (rect.contains(x, y) and circ.contains(x, y)))
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)
def test_ObscCompound(): rng = np.random.default_rng(577215) size = 10_000 for i in range(100): rx = rng.normal(0.0, 1.0) ry = rng.normal(0.0, 1.0) w = rng.uniform(0.5, 2.5) h = rng.uniform(0.5, 2.5) th = rng.uniform(0.0, np.pi) rect = batoid.ObscRectangle(w, h, rx, ry, th) cx = rng.normal(0.0, 1.0) cy = rng.normal(0.0, 1.0) r = rng.uniform(0.5, 1.5) circ = batoid.ObscCircle(r, cx, cy) union = batoid.ObscUnion([rect, circ]) do_pickle(union) union2 = batoid.ObscUnion([circ, rect]) assert union == union2 # commutative! assert hash(union) == hash(union2) intersection = batoid.ObscIntersection([rect, circ]) do_pickle(intersection) intersection2 = batoid.ObscIntersection([circ, rect]) assert intersection == intersection2 assert hash(intersection) == hash(intersection2) for i in range(100): x = rng.normal(0.0, 2.0) y = rng.normal(0.0, 2.0) assert (union.contains(x, y) == union2.contains(x, y) == (rect.contains(x, y) or circ.contains(x, y))) assert (intersection.contains(x, y) == intersection2.contains( x, y) == (rect.contains(x, y) and circ.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(union.contains(x, y), union2.contains(x, y)) np.testing.assert_array_equal( union.contains(x, y), rect.contains(x, y) | circ.contains(x, y)) np.testing.assert_array_equal(intersection.contains(x, y), intersection2.contains(x, y)) np.testing.assert_array_equal( intersection.contains(x, y), rect.contains(x, y) & circ.contains(x, y)) rv = batoid.RayVector(x, y, 0.0, 0.0, 0.0, 0.0) batoid.obscure(union, rv) np.testing.assert_array_equal(union.contains(x, y), rv.vignetted) rv = batoid.RayVector(x, y, 0.0, 0.0, 0.0, 0.0) batoid.obscure(intersection, rv) np.testing.assert_array_equal(intersection.contains(x, y), rv.vignetted) with np.testing.assert_raises(ValueError): batoid.ObscUnion() with np.testing.assert_raises(ValueError): batoid.ObscIntersection()