def test_find_common_side_touches_corner(self): bounds_two = Rect(Line((1, 1), (2, 1)), Line((2, 1), (2, 2)), Line((1, 2), (2, 2)), Line((1, 1), (1, 2))) bounds_one = Rect(Line((2, 2), (3, 2)), Line((3, 2), (3, 3)), Line((2, 3), (3, 3)), Line((2, 2), (2, 3))) result = find_common_rect(bounds_one, bounds_two) self.assertIsNone(result)
def test_lines_intersect_horizontal(self): line_1 = Line((1, 5), (4, 5)) line_2 = Line((2, 5), (3, 5)) result = line_1.split_via(line_2) expected = [ Line((1, 5), (2, 5)), Line((2, 5), (3, 5)), Line((3, 5), (4, 5)) ] self.assertEquals(result, expected)
def test_lines_not_parallel(self): line_1 = Line((5, 0), (5, 3)) line_2 = Line((2, 3), (5, 3)) result = line_1.split_via(line_2) self.assertEquals(len(result), 0)
def test_lines_parallel_not_intersect_vertical(self): line_1 = Line((5, 0), (5, 3)) line_2 = Line((2, 2), (2, 5)) result = line_1.split_via(line_2) self.assertEquals(len(result), 0)
def test_lines_parallel_not_intersect_horizontal(self): line_1 = Line((1, 5), (4, 5)) line_2 = Line((2, 3), (5, 3)) result = line_1.split_via(line_2) self.assertEquals(len(result), 0)
def test_lines_intersect_vertical(self): line_1 = Line((5, 0), (5, 6)) line_2 = Line((5, 4), (5, 6)) result = line_1.split_via(line_2) expected = [Line((5, 0), (5, 4)), Line((5, 4), (5, 6))] self.assertEquals(result, expected)
def test_lines_same_axis_no_intersection_horizontal(self): line_1 = Line((1, 5), (4, 5)) line_2 = Line((5, 5), (8, 5)) result = line_1.split_via(line_2) self.assertEquals(result, [])
def test_lines_equal(self): line_1 = Line((1, 5), (4, 5)) line_2 = Line((1, 5), (4, 5)) result = line_1.split_via(line_2) expected = [Line((1, 5), (4, 5))] self.assertEquals(result, expected)
def test_find_common_rect_disjoint(self): bounds_one = Rect(Line((5, 1), (7, 1)), Line((7, 1), (7, 3)), Line((5, 3), (7, 3)), Line((5, 1), (5, 3))) bounds_two = Rect(Line((1, 3), (3, 3)), Line((3, 3), (3, 6)), Line((1, 6), (3, 6)), Line((1, 3), (1, 6))) self.assertIsNone(find_common_rect(bounds_one, bounds_two))
def test_find_common_side_intersects_rt(self): bounds_one = Rect(Line((1, 2), (4, 2)), Line((4, 2), (4, 5)), Line((1, 5), (4, 5)), Line((1, 2), (1, 5))) bounds_two = Rect(Line((3, 1), (7, 1)), Line((7, 1), (7, 3)), Line((3, 3), (7, 3)), Line((3, 1), (3, 3))) result = find_common_rect(bounds_one, bounds_two) common_rect = Rect(Line((3, 2), (4, 2)), Line((4, 2), (4, 3)), Line((3, 3), (4, 3)), Line((3, 2), (3, 3))) self.assertEquals(result, common_rect)
def test_find_common_side_inside(self): bounds_one = Rect(Line((5, 1), (7, 1)), Line((7, 1), (7, 4)), Line((5, 4), (7, 4)), Line((5, 1), (5, 4))) bounds_two = Rect(Line((1, 3), (9, 3)), Line((9, 3), (9, 6)), Line((1, 6), (9, 6)), Line((1, 3), (1, 6))) result = find_common_rect(bounds_one, bounds_two) common_rect = Rect(Line((5, 3), (7, 3)), Line((7, 3), (7, 4)), Line((5, 4), (7, 4)), Line((5, 3), (5, 4))) self.assertEquals(result, common_rect)