def test_eq_invalid_type(empty_bbox: BoundingBox, partial_bbox: BoundingBox,
                         full_bbox: BoundingBox) -> None:
    for a, b in [
        (empty_bbox, 3),
        (partial_bbox, 'a'),
        (full_bbox, Point(5, 8)),
    ]:
        assert (a != b)
def test_scale_around_corners_maintains_corners(bbox: BoundingBox, sx: float,
                                                sy: float) -> None:
    scaled_bbox = bbox.scale(Shape(sx, sy),
                             center=Point(bbox.x_min, bbox.y_min))
    assert scaled_bbox.x_min == approx(bbox.x_min, abs=1e-6)
    assert scaled_bbox.y_min == approx(bbox.y_min, abs=1e-6)

    scaled_bbox = bbox.scale(Shape(sx, sy),
                             center=Point(bbox.x_min, bbox.y_max))
    assert scaled_bbox.x_min == approx(bbox.x_min, abs=1e-6)
    assert scaled_bbox.y_max == approx(bbox.y_max, abs=1e-6)

    scaled_bbox = bbox.scale(Shape(sx, sy),
                             center=Point(bbox.x_max, bbox.y_min))
    assert scaled_bbox.x_max == approx(bbox.x_max, abs=1e-6)
    assert scaled_bbox.y_min == approx(bbox.y_min, abs=1e-6)

    scaled_bbox = bbox.scale(Shape(sx, sy),
                             center=Point(bbox.x_max, bbox.y_max))
    assert scaled_bbox.x_max == approx(bbox.x_max, abs=1e-6)
    assert scaled_bbox.y_max == approx(bbox.y_max, abs=1e-6)
Beispiel #3
0
def test_from_origin_to_point(p: Point) -> None:
    assert Vector.from_points(Point(0, 0), p) == Vector(p.x, p.y)
Beispiel #4
0
def test_from_point_to_origin(p: Point) -> None:
    assert Vector.from_points(p, Point(0, 0)) == Vector(-p.x, -p.y)
Beispiel #5
0
def test_from_points() -> None:
    assert Vector.from_points(Point(1, 2), Point(-1, -2)) == Vector(-2, -4)
Beispiel #6
0
def top_left_point() -> Iterator[Point]:
    yield Point(0.0, 0.0)
Beispiel #7
0
def neg_point() -> Iterator[Point]:
    yield Point(-10.0, -10.0)
Beispiel #8
0
def bot_right_point() -> Iterator[Point]:
    yield Point(100.0, 100.0)
Beispiel #9
0
def bot_left_point() -> Iterator[Point]:
    yield Point(0.0, 100.0)
Beispiel #10
0
def top_right_point() -> Iterator[Point]:
    yield Point(100.0, 0.0)
Beispiel #11
0
def test_add_other_type_raises(full_bbox: BoundingBox,
                               partial_bbox: BoundingBox) -> None:
    for a, b in [(partial_bbox, 3), (partial_bbox, 'a'),
                 (full_bbox, Point(0.0, 3.0))]:
        with pytest.raises(NotImplementedError):
            a + b