def test_single_rect(self): frame = Rect(Point(0, 0), Point(42, 42)) rects = [Rect(Point(0, 0), Point(21, 42))] c_rects = get_complement(frame, rects) self.assertEqual(len(c_rects), 1) self.assertEqual(c_rects[0], Rect(Point(21, 0), Point(42, 42)))
def test_already_full_multiple_rect_horizontal(self): frame = Rect(Point(0, 0), Point(42, 42)) rects = [ Rect(Point(0, 0), Point(42, 21)), Rect(Point(0, 21), Point(42, 42)) ] c_rects = get_complement(frame, rects) self.assertEqual(len(c_rects), 0)
def test_random(self): for _ in range(100): num_inners = np.random.randint(100) frame = gen_random_frame() rects = generate_random_inner_rects(num_inners, frame) comp_rects = get_complement(frame, rects) total_area = frame.area() area_sum = sum(r.area() for r in comp_rects) area_sum += sum(r.area() for r in rects) self.assertAlmostEqual(total_area, area_sum, places=4)
#!/usr/bin/env python3 from rect_comp import Point, Rect, get_intersection, get_complement, get_intersect_points # a demonstation of the API frame = Rect(Point(0, 0), Point(100, 100)) r1 = Rect(Point(13, 13), Point(20, 25)) r2 = Rect(Point(27, 17), Point(45, 42)) r3 = Rect(Point(32, 50), Point(63, 70)) crects = get_complement(frame, [r1, r2, r3]) print( 'The complementary rectangle set (each represented by its botton left and top right corners:' ) for r in crects: print(r)
def test_empty_case(self): frame = Rect(Point(0, 0), Point(42, 42)) rects = [] c_rects = get_complement(frame, rects) self.assertEqual(len(c_rects), 1) self.assertEqual(c_rects[0], frame)
def test_already_full_single_rect(self): frame = Rect(Point(0, 0), Point(42, 42)) rects = [Rect(Point(0, 0), Point(42, 42))] c_rects = get_complement(frame, rects) self.assertEqual(len(c_rects), 0)