def test_zipped_lines() -> None: inst = Line(x, 0, 1, 5) + Line(y, 1, 2, 5) assert inst.axes() == [x, y] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([0, 0.25, 0.5, 0.75, 1]), y: pytest.approx([1, 1.25, 1.5, 1.75, 2]), }
def test_rect_region_symmetricdifference() -> None: inst = Line(y, 1, 3, 5) * Line(x, 0, 2, 3) & Rectangle( x, y, 0, 1, 1.5, 2.2) ^ Rectangle(x, y, 0.5, 1.5, 2, 2.5) assert inst.axes() == [y, x] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([0, 1, 0, 2, 0, 2, 1, 2]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2, 2.5, 2.5]), }
def test_zipped_product_lines() -> None: inst = Line(y, 1, 2, 3) * Line(x, 0, 1, 5) + Line(z, 2, 3, 5) assert inst.axes() == [y, x, z] dimy, dimxz = inst.create_dimensions() assert dimxz.midpoints == { x: pytest.approx([0, 0.25, 0.5, 0.75, 1]), z: pytest.approx([2, 2.25, 2.5, 2.75, 3]), } assert dimy.midpoints == { y: pytest.approx([1, 1.5, 2]), }
def test_squashed_multiplied_snake_scan() -> None: inst = Line(z, 1, 2, 2) * Squash( Line(y, 1, 2, 2) * ~Line.bounded(x, 3, 7, 2) * Static.duration(9, 2)) assert inst.axes() == [z, y, x, DURATION] dimz, dimxyt = inst.create_dimensions() for d in dimxyt.midpoints, dimxyt.lower, dimxyt.upper: assert d == { x: pytest.approx([4, 4, 6, 6, 6, 6, 4, 4]), y: pytest.approx([1, 1, 1, 1, 2, 2, 2, 2]), DURATION: pytest.approx([9, 9, 9, 9, 9, 9, 9, 9]), } assert dimz.midpoints == dimz.lower == dimz.upper == { z: pytest.approx([1, 2]) }
def test_circle_region() -> None: inst = Line(y, 1, 3, 3) * Line(x, 0, 2, 3) & Circle(x, y, 1, 2, 1) assert inst.axes() == [y, x] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([1, 0, 1, 2, 1]), y: pytest.approx([1, 2, 2, 2, 3]), } assert dim.lower == { x: pytest.approx([0.5, -0.5, 0.5, 1.5, 0.5]), y: pytest.approx([1, 2, 2, 2, 3]), } assert dim.upper == { x: pytest.approx([1.5, 0.5, 1.5, 2.5, 1.5]), y: pytest.approx([1, 2, 2, 2, 3]), }
def test_ellipse_region() -> None: inst = Line("y", 1, 3, 3) * Line("x", 0, 2, 3) & Ellipse( x, y, 1, 2, 2, 1, 45) assert inst.axes() == [y, x] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([0, 1, 0, 1, 2, 1, 2]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3]), } assert dim.lower == { x: pytest.approx([-0.5, 0.5, -0.5, 0.5, 1.5, 0.5, 1.5]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3]), } assert dim.upper == { x: pytest.approx([0.5, 1.5, 0.5, 1.5, 2.5, 1.5, 2.5]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3]), }
def test_rect_region() -> None: inst = Line(y, 1, 3, 5) * Line(x, 0, 2, 3) & Rectangle( x, y, 0, 1, 1.5, 2.2) assert inst.axes() == [y, x] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([0, 1, 0, 1, 0, 1]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), } assert dim.lower == { x: pytest.approx([-0.5, 0.5, -0.5, 0.5, -0.5, 0.5]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), } assert dim.upper == { x: pytest.approx([0.5, 1.5, 0.5, 1.5, 0.5, 1.5]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), }
def test_product_snaking_lines() -> None: inst = Line(y, 1, 2, 3) * ~Line(x, 0, 1, 2) assert inst.axes() == [y, x] dims = inst.create_dimensions() assert len(dims) == 2 dim = Path(dims).consume() assert dim.midpoints == { x: pytest.approx([0, 1, 1, 0, 0, 1]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), } assert dim.lower == { x: pytest.approx([-0.5, 0.5, 1.5, 0.5, -0.5, 0.5]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), } assert dim.upper == { x: pytest.approx([0.5, 1.5, 0.5, -0.5, 0.5, 1.5]), y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]), }
def test_polygon_region() -> None: x_verts = [0, 0.5, 4.0, 2.5] y_verts = [0, 3.5, 3.5, 0.5] inst = Line("y", 1, 3, 3) * Line("x", 0, 4, 5) & Polygon( x, y, x_verts, y_verts) assert inst.axes() == [y, x] (dim, ) = inst.create_dimensions() assert dim.midpoints == { x: pytest.approx([1, 2, 1, 2, 3, 1, 2, 3]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]), } assert dim.lower == { x: pytest.approx([0.5, 1.5, 0.5, 1.5, 2.5, 0.5, 1.5, 2.5]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]), } assert dim.upper == { x: pytest.approx([1.5, 2.5, 1.5, 2.5, 3.5, 1.5, 2.5, 3.5]), y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]), }