Exemplo n.º 1
0
def convert_coord_to_pixel(coord):
    """docstring for convert_coord_to_pixel"""
    hexa = Hexagon((0, 0), SIZE, RED, BORDER)
    y_pos = MARGIN + coord[1] * hexa.get_apothem() * 2 - coord[0] * \
        hexa.get_apothem()
    x_pos = MARGIN + coord[0] * hexa.get_radius() * 1.5
    return (x_pos, y_pos)
Exemplo n.º 2
0
def convert_pixel_to_coord(position):
    """docstring for convert_pixel_to_coord"""
    hexa = Hexagon((0, 0), SIZE, RED, BORDER)
    x_coord = (position[0] - MARGIN) / (hexa.get_radius() * 1.5)
    y_coord = (position[1] - MARGIN + x_coord + hexa.get_apothem()) / \
        (hexa.get_radius() * 2)
    return (x_coord, y_coord)
Exemplo n.º 3
0
class TestHexagon(unittest.TestCase):
    """
    Test Hexagon class
    """
    def setUp(self):
        """intialize the environment for all tests"""
        self.hexagon = Hexagon((0, 0), 50, sf.Color(127, 127, 127),
                               sf.Color(127, 127, 127))

    def test_radius(self):
        """test the radius value of hexagon"""
        radius = self.hexagon.get_radius()
        self.assertEqual(radius, 50)

    def test_apothem(self):
        """test the apothem value of hexagon"""
        apothem = self.hexagon.get_apothem()
        self.assertAlmostEqual(apothem, 43.301270189)