Esempio n. 1
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)
Esempio n. 2
0
    def test_region(self):
        grid = Grid(OrientationFlat, Point(10, 20), Point(20, 10))
        geometry = [
            Point(20, 19.99999),
            Point(20, 40),
            Point(40, 60),
            Point(60, 40),
            Point(50, 30),
            Point(40, 40)
        ]
        region = grid.make_region(geometry)
        hexes = region.hexes
        expected_codes = [0, 2, 1, 3, 9, 4]

        self.assertEqual(len(hexes), len(expected_codes))
        for hex, expected_code in zip(hexes, expected_codes):
            code = grid.hex_to_code(hex)
            self.assertEqual(code, expected_code)