Пример #1
0
 def test_polyline_circle_intersection(self, unit_circle):
     polyline = Polyline([
         Line(Vector2(0, 0), Vector2(3, 4)),
         Line(Vector2(4, 5), Vector2(5, 6))
     ])
     assert polyline.intersects(unit_circle)
     assert unit_circle.intersects(polyline)
Пример #2
0
 def test_polyline_polyline_no_intersection(self, polyline1):
     polyline2 = Polyline([
         Line(Vector2(10, 23), Vector2(23, 42)),
         Line(Vector2(12, 10), Vector2(33, 44))
     ])
     assert not polyline1.intersects(polyline2)
     assert not polyline2.intersects(polyline1)
Пример #3
0
 def test_setting_rotation_moves_sides_correctly(self, polyline1):
     polyline1.rotation = math.pi / 2
     assert polyline_eq(
         polyline1,
         Polyline([
             Line(Vector2(0, 0), Vector2(0, -2)),
             Line(Vector2(1, 0), Vector2(2, -2))
         ]))
Пример #4
0
 def test_setting_location_moves_sides_correctly(self, polyline1):
     polyline1.location = Vector2(1, 3)
     assert polyline_eq(
         polyline1,
         Polyline([
             Line(Vector2(0 + 1, 0 + 3), Vector2(2 + 1, 0 + 3)),
             Line(Vector2(0 + 1, 1 + 3), Vector2(2 + 1, 2 + 3))
         ]))
Пример #5
0
 def test_location_plus_rotation_change_endpoints_correctly(
         self, polyline1):
     polyline1.location = Vector2(1, 3)
     polyline1.rotation = math.pi / 2
     assert polyline_eq(
         polyline1,
         Polyline([
             Line(Vector2(0 + 1, 0 + 3), Vector2(0 + 1, -2 + 3)),
             Line(Vector2(1 + 1, 0 + 3), Vector2(2 + 1, -2 + 3))
         ]))
Пример #6
0
 def test_polyline_line_no_intersection(self, polyline1):
     line = Line(Vector2(10, 12), Vector2(13, 14))
     assert not polyline1.intersects(line)
     assert not line.intersects(polyline1)
Пример #7
0
 def test_line_line_intersection(self):
     line1 = Line(Vector2(-1, -1), Vector2(1, 1))
     line2 = Line(Vector2(-1, 1), Vector2(1, -1))
     assert line1.intersects(line2)
     assert line2.intersects(line1)
Пример #8
0
 def test_line_line_intersection_with_itself(self):
     line1 = Line(Vector2(1, 1), Vector2(1, 2))
     line2 = Line(Vector2(1, 1), Vector2(1, 2))
     assert line1.intersects(line2)
     assert line2.intersects(line1)
Пример #9
0
 def polyline1(self):
     return Polyline([
         Line(Vector2(0, 0), Vector2(2, 0)),
         Line(Vector2(0, 1), Vector2(2, 2))
     ])
Пример #10
0
 def line_45_degrees(self):
     return Line(Vector2(1, 2), Vector2(2, 3))
Пример #11
0
 def test_polyline_polyline_intersection(self, polyline1):
     polyline2 = Polyline(
         [Line(Vector2(2.5 + 1, 3.5 - 1), Vector2(3 - 1, 4 + 1))])
     assert polyline1.intersects(polyline2)
     assert polyline2.intersects(polyline1)
Пример #12
0
 def polyline1(self):
     return Polyline([
         Line(Vector2(2, 3), Vector2(3, 4)),
         Line(Vector2(4, 5), Vector2(5, 6))
     ])
Пример #13
0
 def test_from_points_sets_data_members_correctly(self):
     polyline = Polyline.from_points(
         [Vector2(0, 0), Vector2(0, 1),
          Vector2(1, 3)])
     assert line_eq(polyline.lines[0], Line(Vector2(0, 0), Vector2(0, 1)))
     assert line_eq(polyline.lines[1], Line(Vector2(0, 1), Vector2(1, 3)))
Пример #14
0
 def test_contructor_sets_data_members_correctly(self, polyline1):
     assert line_eq(polyline1.lines[0], Line(Vector2(0, 0), Vector2(2, 0)))
     assert line_eq(polyline1.lines[1], Line(Vector2(0, 1), Vector2(2, 2)))
Пример #15
0
 def test_polyline_line_intersection(self, polyline1):
     line = Line(Vector2(3, 4), Vector2(4.5, 5.5))
     assert polyline1.intersects(line)
     assert line.intersects(polyline1)
Пример #16
0
 def test_line_circle_no_intersection(self, unit_circle):
     line = Line(Vector2(1, 1), Vector2(1, 2))
     assert not unit_circle.intersects(line)
     assert not line.intersects(unit_circle)
Пример #17
0
 def test_line_circle_intersection(self, unit_circle):
     line = Line(Vector2(0, 0.8), Vector2(1, 2))
     assert unit_circle.intersects(line)
     assert line.intersects(unit_circle)
Пример #18
0
 def line1(self):
     return Line(Vector2(1, 2), Vector2(3, 1))
Пример #19
0
 def test_line_line_no_intersection(self):
     line1 = Line(Vector2(1, 1), Vector2(1, 2))
     line2 = Line(Vector2(1 + 1, 1 + 1), Vector2(1 + 1, 2 + 1))
     assert not line1.intersects(line2)
     assert not line2.intersects(line1)
Пример #20
0
    def test_constructor_fails_when_line_length_is_zero(self):
        with pytest.raises(ValueError) as e:
            Line(Vector2(12, 13), Vector2(12, 13))

        assert "The Line must have a positive length" == str(e.value)
Пример #21
0
 def test_contructor_sets_data_members_correctly(self, rect1):
     assert line_eq(rect1.sides[0], Line(Vector2(0, 0), Vector2(0, 1)))
     assert line_eq(rect1.sides[1], Line(Vector2(0, 1), Vector2(2, 1)))
     assert line_eq(rect1.sides[2], Line(Vector2(2, 1), Vector2(2, 0)))
     assert line_eq(rect1.sides[3], Line(Vector2(2, 0), Vector2(0, 0)))