Exemplo n.º 1
0
 def test_doesnt_intersect_triangle_common_side(self):
     p1 = IntegerPoint(0, 0)
     p2 = IntegerPoint(2, 1)
     p3 = IntegerPoint(1, 2)
     t1 = IntegerTriangle(p1, p2, p3)
     s1 = IntegerSegment((-2, -1), (4, 2))
     self.assertFalse(s1.intersects_triangle(t1))
Exemplo n.º 2
0
 def test_intersects_triangle(self):
     p1 = IntegerPoint(0, 0)
     p2 = IntegerPoint(2, 1)
     p3 = IntegerPoint(1, 2)
     t1 = IntegerTriangle(p1, p2, p3)
     s1 = IntegerSegment((0, 1), (3, 1))
     self.assertTrue(s1.intersects_triangle(t1))
Exemplo n.º 3
0
 def test_like_reversed_points(self):
     p1 = IntegerPoint(0, 1)
     p2 = IntegerPoint(1, 1)
     s1 = IntegerSegment(p1, p2)
     p3 = IntegerPoint(0, 1)
     p4 = IntegerPoint(1, 1)
     s2 = IntegerSegment(p4, p3)
     self.assertTrue(s1.like(s2))
     self.assertTrue(s2.like(s1))
Exemplo n.º 4
0
 def test_like_same_points(self):
     p1 = IntegerPoint(0, 1)
     p2 = IntegerPoint(1, 1)
     s1 = IntegerSegment(p1, p2)
     p3 = IntegerPoint(0, 1)
     p4 = IntegerPoint(1, 1)
     s2 = IntegerSegment(p3, p4)
     self.assertTrue(s1.like(s2))
     self.assertTrue(s2.like(s1))
Exemplo n.º 5
0
 def test_containing_pt_ct_vertical(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(0, 2))
     res = s1.containing_pt_ct()
     self.assertEqual(res, 3)
Exemplo n.º 6
0
 def test_containing_pt_ct_zero_length(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(0, 0))
     res = s1.containing_pt_ct()
     self.assertEqual(res, 1)
Exemplo n.º 7
0
 def test_tuple(self):
     p1 = IntegerPoint(0, 1)
     p2 = IntegerPoint(1, 1)
     res = IntegerSegment(p1, p2)
     self.assertTupleEqual(res.tuple(), (p1.tuple(), p2.tuple()))
Exemplo n.º 8
0
 def test_creation_from_tuple(self):
     s1 = IntegerSegment((0, 0), (2, 0))
     self.assertTupleEqual(s1.tuple(), ((0, 0), (2, 0)))
Exemplo n.º 9
0
 def test_ortho_vertical(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(0, 3))
     self.assertTrue(s1.ortho())
Exemplo n.º 10
0
 def test_ortho_horiz(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(3, 0))
     self.assertTrue(s1.ortho())
Exemplo n.º 11
0
 def test_length(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(3, 2))
     self.assertEqual(s1.length(), sqrt(3 ** 2 + 2 ** 2))
Exemplo n.º 12
0
 def test_slope_negative(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(2, -1))
     self.assertEqual(s1.slope(), -0.5)
Exemplo n.º 13
0
 def test_slope_positive(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(2, 1))
     self.assertEqual(s1.slope(), 0.5)
Exemplo n.º 14
0
 def test_slope_zero(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(1, 0))
     self.assertEqual(s1.slope(), 0)
Exemplo n.º 15
0
 def test_slope_inf(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(0, 1))
     self.assertEqual(s1.slope(), float("inf"))
Exemplo n.º 16
0
 def test_containing_pt_ct_positive_unity_slope(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(2, 2))
     res = s1.containing_pt_ct()
     self.assertEqual(res, 3)
Exemplo n.º 17
0
 def test_containing_pt_ct_negative_nonunity_slope(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(4, -6))
     res = s1.containing_pt_ct()
     self.assertEqual(res, 3)
Exemplo n.º 18
0
 def test_not_ortho(self):
     s1 = IntegerSegment(IntegerPoint(0, 0), IntegerPoint(3, 2))
     self.assertFalse(s1.ortho())
Exemplo n.º 19
0
 def test_points(self):
     p1 = IntegerPoint(0, 1)
     p2 = IntegerPoint(1, 1)
     res = IntegerSegment(p1, p2)
     self.assertTupleEqual(res.vertices(), (p1, p2))
Exemplo n.º 20
0
 def test_default_initialization(self):
     s1 = IntegerSegment()
     self.assertTupleEqual(s1.tuple(), ((0, 0), (0, 0)))