Exemple #1
0
 def test_intersection_half_of_square(self):
     board = Board(Polygon([[0, 0], [100, 100], [100, 0]]), [0, 0])
     piece = PolygonPiece(Polygon([[0, 0], [0, 100], [100, 100], [100, 0]]),
                          [0, 0])
     actual_area = PolygonIntersector().intersection_area(
         board.get_points_in_plane(), piece.get_points_in_plane())
     self.assertEqual(piece.get_polygon().area() / 2, actual_area)
Exemple #2
0
 def test_get_intersection_area_same_as_piece_if_fully_submerged(self):
     board = Board(Polygon([[0, 0], [0, 1000], [1000, 1000], [1000, 0]]),
                   [0, 0])
     piece = PolygonPiece(Polygon([[0, 0], [100, 100], [100, 0]]), [50, 50])
     actual_area = PolygonIntersector().intersection_area(
         board.get_points_in_plane(), piece.get_points_in_plane())
     self.assertEqual(piece.get_polygon().area(), actual_area)
Exemple #3
0
 def test_get_intersection_zero_if_poly_on_a_different_planet(self):
     board = Board(Polygon([[0, 0], [0, 1000], [1000, 0], [1000, 1000]]),
                   [0, 0])
     piece = PolygonPiece(Polygon([[0, 0], [100, 100], [100, 0]]),
                          [5000, 5000])
     actual_area = PolygonIntersector().intersection_area(
         board.get_points_in_plane(), piece.get_points_in_plane())
     self.assertEqual(0, actual_area)
Exemple #4
0
 def test_adding_a_piece_does_not_decrease_coverage(self, *points):
     piece = PolygonPiece(Polygon(list(points)), [0, 0])
     piece1 = PolygonPiece(Polygon(random_polygon_points(1)[0]), [0, 0])
     board = Board(Polygon([[0, 0], [100, 100], [100, 0]]), [0, 0])
     intersector = PolygonIntersector()
     level = Level(board, [piece], intersector)
     coverage_with_one_piece = level.get_completion_percentage()
     level = Level(board, [piece, piece1], intersector)
     coverage_with_two_pieces = level.get_completion_percentage()
     if len(
             intersector.intersection_polygons(
                 piece.get_points_in_plane(),
                 piece1.get_points_in_plane())) == 0:
         self.assertGreaterEqual(coverage_with_two_pieces,
                                 coverage_with_one_piece)
     else:
         coverage_almost_equal = abs(coverage_with_two_pieces -
                                     coverage_with_one_piece) <= 1
         two_piece_coverage_greater_equal = coverage_with_two_pieces >= coverage_with_one_piece
         self.assertTrue(two_piece_coverage_greater_equal
                         or coverage_almost_equal)
Exemple #5
0
 def test_points_dont_increase_with_positive_position(self, *position):
     position = list(position)
     polygon = Polygon([[0, 0], [0, 10], [10, 0], [10, 10]])
     piece = PolygonPiece(polygon, position)
     self.assertLessEqual(piece.get_points_in_plane().sum(),
                          polygon.get_points().sum())
Exemple #6
0
 def test_points_not_same_as_poly_if_position_not_zero(self, *position):
     position = list(position)
     polygon = Polygon([[0, 0], [0, 10], [10, 0], [10, 10]])
     piece = PolygonPiece(polygon, position)
     self.assertNotEqual(polygon.get_points().tolist(),
                         piece.get_points_in_plane().tolist())
Exemple #7
0
 def test_points_same_as_poly_if_position_zero(self, *points):
     points = list(points)
     polygon = Polygon(points.copy())
     piece = PolygonPiece(polygon, [0, 0])
     self.assertEqual(polygon.get_points().tolist(),
                      piece.get_points_in_plane().tolist())