Skip to content

Commit

Permalink
Ensure non-square bounding boxes are rendered centered
Browse files Browse the repository at this point in the history
See #6
  • Loading branch information
pfaion committed Aug 24, 2019
1 parent 7d0f1c1 commit 5df5230
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pybeautymaps/beautymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def render_square_png(self, filename, size, padding, line_widths=dict()):

px_per_coord = (size - 2 * padding) / coord_range.min()

# offsets for non-square shaped bounding boxes
offset = (coord_range - coord_range.min()) / 2

with cairo.ImageSurface(cairo.FORMAT_ARGB32, size, size) as surface:
ctx = cairo.Context(surface)
ctx.scale(1, 1)
Expand All @@ -74,7 +77,7 @@ def render_square_png(self, filename, size, padding, line_widths=dict()):
ctx.set_line_cap(cairo.LINE_CAP_ROUND)
for way, road_type in zip(self.carthographic_data, self.road_data):
ctx.set_line_width(line_widths.get(road_type, 1))
way_zeroed = (way - coord_min) * px_per_coord + padding
way_zeroed = (way - coord_min - offset) * px_per_coord + padding
way_zeroed = np.rint(way_zeroed).astype(int)
x, y = way_zeroed[0, :]
ctx.move_to(x, size - y)
Expand Down

0 comments on commit 5df5230

Please sign in to comment.