Exemplo n.º 1
0
    def test_pointy(self):
        grid = Grid(OrientationPointy, Point(10, 20), Point(20, 10))

        self.assertHexEqual(Hex(-21, 43), grid.hex_at(Point(13, 666)))
        self.assertHexEqual(Hex(19, 0), grid.hex_at(Point(666, 13)))
        self.assertHexEqual(Hex(22, -46), grid.hex_at(Point(-13, -666)))
        self.assertHexEqual(Hex(-19, -2), grid.hex_at(Point(-666, -13)))
Exemplo n.º 2
0
    def test_flat(self):
        grid = Grid(OrientationFlat, Point(10, 20), Point(20, 10))

        self.assertHexEqual(Hex(0, 37), grid.hex_at(Point(13, 666)))
        self.assertHexEqual(Hex(22, -11), grid.hex_at(Point(666, 13)))
        self.assertHexEqual(Hex(-1, -39), grid.hex_at(Point(-13, -666)))
        self.assertHexEqual(Hex(-22, 9), grid.hex_at(Point(-666, -13)))

        grid = Grid(OrientationFlat, Point(0, 0), Point(5, 5))
        self.assertHexEqual(Hex(0, 37), grid.hex_at(Point(0, 320)))
Exemplo n.º 3
0
    def test_neighbors(self):
        grid = Grid(OrientationFlat, Point(10, 20), Point(20, 10))
        hex = grid.hex_at(Point(666, 666))
        expected_codes = [
            920, 922, 944, 915, 921, 923, 945, 916, 918, 926, 948, 917, 919,
            925, 927, 960, 962, 968
        ]

        neighbors = grid.hex_neighbors(hex, 2)

        for expected_code, neighbor_hex in zip(expected_codes, neighbors):
            code = grid.hex_to_code(neighbor_hex)
            self.assertEqual(code, expected_code, neighbor_hex)
Exemplo n.º 4
0
    def test_coordinates_pointy(self):
        grid = Grid(OrientationPointy, Point(10, 20), Point(20, 10))
        hex = grid.hex_at(Point(666, 666))

        self.assertPointEqual(Point(650.85880, 665.00000),
                              grid.hex_center(hex), 0.00001)

        corners = grid.hex_corners(hex)

        expected_corners = [
            Point(668.17930, 670.00000),
            Point(650.85880, 675.00000),
            Point(633.53829, 670.00000),
            Point(633.53829, 660.00000),
            Point(650.85880, 655.00000),
            Point(668.17930, 660.00000),
        ]
        for expected_point, point in zip(expected_corners, corners):
            self.assertPointEqual(expected_point, point, 0.00001)
Exemplo n.º 5
0
    def test_coordinates_flat(self):
        grid = Grid(OrientationFlat, Point(10, 20), Point(20, 10))
        hex = grid.hex_at(Point(666, 666))

        self.assertPointEqual(Point(670.00000, 660.85880),
                              grid.hex_center(hex), 0.00001)

        corners = grid.hex_corners(hex)

        expected_corners = [
            Point(690.00000, 660.85880),
            Point(680.00000, 669.51905),
            Point(660.00000, 669.51905),
            Point(650.00000, 660.85880),
            Point(660.00000, 652.19854),
            Point(680.00000, 652.19854),
        ]
        for expected_point, point in zip(expected_corners, corners):
            self.assertPointEqual(expected_point, point, 0.00001)