]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/utils/grid.py
implement BDD osm2pgsql tests with pytest-bdd
[nominatim.git] / test / bdd / utils / grid.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 A grid describing node placement in an area.
9 Useful for visually describing geometries.
10 """
11
12
13 class Grid:
14
15     def __init__(self, table, step, origin):
16         if step is None:
17             step = 0.00001
18         if origin is None:
19             origin = (0.0, 0.0)
20         self.grid = {}
21
22         y = origin[1]
23         for line in table:
24             x = origin[0]
25             for pt_id in line:
26                 if pt_id:
27                     self.grid[pt_id] = (x, y)
28                 x += step
29             y += step
30
31     def get(self, nodeid):
32         """ Get the coordinates for the given grid node.
33         """
34         return self.grid.get(nodeid)