def test_diag_growth_bug(self):
     """Regression test for a silly bug."""
     FRAGMENT_COST = 4
     bitmask = np.array([
         [True, False, False, False],
         [False, False, False, False],
         [False, False, False, False],
         [False, False, False, True],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask, FRAGMENT_COST=FRAGMENT_COST)
     self.assertEqual(cost, 2 * FRAGMENT_COST + 2)
     self.assertItemsEqual(rectangles, [(0, 0, 1, 1), (3, 3, 4, 4)])
 def test_basic(self):
     """Tests a case where the optimal solution consists of a single minimum
     average cost rectangle."""
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False],
         [False, False, False, False],
         [False, True, True, False],
         [False, True, False, False],
         [False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask, FRAGMENT_COST=FRAGMENT_COST)
     self.assertEqual(cost, FRAGMENT_COST + 4)
     self.assertItemsEqual(rectangles, [(2, 1, 4, 3)])
 def test_grow(self):
     """Tests a case where the optimal solution can be found by growing the
     initial minimum average cost rectangle."""
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False, False, False],
         [False, False, False, False, False, False],
         [False, True, True, False, False, False],
         [False, True, False, False, False, False],
         [False, True, False, False, False, False],
         [False, True, False, False, False, False],
         [False, False, False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask, FRAGMENT_COST=FRAGMENT_COST)
     self.assertEqual(cost, FRAGMENT_COST + 8)
     self.assertItemsEqual(rectangles, [(2, 1, 6, 3)])
 def test_nogrow(self):
     """Similar to test_grow, but tests a situation in which growing the
     initial rectangle is in fact not optimal."""
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False, False, False],
         [False, False, False, False, False, False],
         [False, True, True, True, False, False],
         [False, True, False, False, False, False],
         [False, True, False, False, False, False],
         [False, True, False, False, False, False],
         [False, False, False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask, FRAGMENT_COST=FRAGMENT_COST)
     self.assertEqual(cost, 2 * FRAGMENT_COST + 6)
     self.assertItemsEqual(rectangles, [(2, 1, 6, 2), (2, 2, 3, 4)])
Exemplo n.º 5
0
 def test_diag_growth_bug(self):
     """
     Regression test for a silly bug.
     """
     FRAGMENT_COST = 4
     bitmask = np.array([
         [True,  False, False, False],
         [False, False, False, False],
         [False, False, False, False],
         [False, False, False, True],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask,
         FRAGMENT_COST=FRAGMENT_COST
     )
     self.assertEqual(cost, 2 * FRAGMENT_COST + 2)
     self.assertItemsEqual(rectangles, [(0, 0, 1, 1), (3, 3, 4, 4)])
Exemplo n.º 6
0
 def test_basic(self):
     """
     Tests a case where the optimal solution consists of a single
     minimum average cost rectangle.
     """
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False],
         [False, False, False, False],
         [False, True,  True,  False],
         [False, True,  False, False],
         [False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask,
         FRAGMENT_COST=FRAGMENT_COST
     )
     self.assertEqual(cost, FRAGMENT_COST + 4)
     self.assertItemsEqual(rectangles, [(2, 1, 4, 3)])
Exemplo n.º 7
0
 def test_grow(self):
     """
     Tests a case where the optimal solution can be found
     by growing the initial minimum average cost rectangle.
     """
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False, False, False],
         [False, False, False, False, False, False],
         [False, True,  True,  False, False, False],
         [False, True,  False, False, False, False],
         [False, True,  False, False, False, False],
         [False, True,  False, False, False, False],
         [False, False, False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask,
         FRAGMENT_COST=FRAGMENT_COST
     )
     self.assertEqual(cost, FRAGMENT_COST + 8)
     self.assertItemsEqual(rectangles, [(2, 1, 6, 3)])
Exemplo n.º 8
0
 def test_nogrow(self):
     """
     Similar to test_grow, but tests a situation in which
     growing the initial rectangle is in fact not optimal.
     """
     FRAGMENT_COST = 4
     bitmask = np.array([
         [False, False, False, False, False, False],
         [False, False, False, False, False, False],
         [False, True,  True,  True,  False, False],
         [False, True,  False, False, False, False],
         [False, True,  False, False, False, False],
         [False, True,  False, False, False, False],
         [False, False, False, False, False, False],
     ])
     cost, rectangles = make_spritemap.compute_rectangle_covering(
         bitmask,
         FRAGMENT_COST=FRAGMENT_COST
     )
     self.assertEqual(cost, 2 * FRAGMENT_COST + 6)
     self.assertItemsEqual(rectangles, [(2, 1, 6, 2), (2, 2, 3, 4)])