Skip to content

Commit

Permalink
fixed consistency issues
Browse files Browse the repository at this point in the history
changed the join mode for polygon outlines
  • Loading branch information
felix-ht committed Nov 27, 2024
1 parent 76734b9 commit cc3a53c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ polygon = shape(json)
fill_layer = mapsy.FillLayer(
[
mapsy.FillItem(
polygon,
geometry=polygon,
fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3),
line_color=mapsy.Color(0, 0, 0),
line_width=2,
Expand All @@ -120,7 +120,7 @@ line = shape(json)
fill_layer = mapsy.LineLayer(
[
mapsy.LineItem(
line,
geometry=line,
join=mapsy.LineJoin.round,
cap=mapsy.LineCap.round
width=12,
Expand All @@ -147,7 +147,7 @@ point = shape(json)
circle_layer = mapsy.CircleLayer(
[
mapsy.CircleItem(
point,
geometry=point,
fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3),
line_color=mapsy.Color(0, 0, 0),
line_width=2,
Expand Down Expand Up @@ -175,7 +175,7 @@ point = shape(json)
symbol_layer = mapsy.SymbolLayer(
[
mapsy.SymbolItem(
point,
geometry=point,
icon=mapsy.Icons.PIN_24,
text="Hello World",
text_offset=(0, 16)
Expand Down
4 changes: 2 additions & 2 deletions example/simple_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def main():
fill = mapsy.FillLayer(
[
mapsy.FillItem(
polygon,
fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3),
geometry=polygon,
color=mapsy.Color(0.5, 0.5, 0.5, 0.3),
line_color=mapsy.Color(0, 0, 0),
line_width=2,
)
Expand Down
10 changes: 5 additions & 5 deletions mapsy/layer/fill_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

@dataclass
class FillItem:
polygon: Polygon | MultiPolygon
fill_color: Color
geometry: Polygon | MultiPolygon
color: Color
line_color: Color
line_width: int = 0

Expand All @@ -21,20 +21,20 @@ def __init__(self, items: list[FillItem]) -> None:
def render(self, context: RenderContext) -> None:
for item in self.items:
polygon_in_img_crs = context.transformer.transform_to_image_crs(
item.polygon
item.geometry
)
if isinstance(polygon_in_img_crs, MultiPolygon):
for poly in polygon_in_img_crs.geoms:
context.render_backend.draw_polygon(
polygon=poly,
line_color=item.line_color,
fill_color=item.fill_color,
fill_color=item.color,
line_width=item.line_width,
)
else:
context.render_backend.draw_polygon(
polygon=polygon_in_img_crs,
line_color=item.line_color,
fill_color=item.fill_color,
fill_color=item.color,
line_width=item.line_width,
)
6 changes: 3 additions & 3 deletions mapsy/layer/line_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class LineItem:
color: str | None = None
width: float | None = 1
cap: LineCap | None = LineCap.BUTT
join: LineJoin | None = LineJoin.MITER
join: LineJoin | None = LineJoin.ROUND
outline_color: str | None = None
outline_width: float | None = None


class LineLayer(Layer):
def __init__(self, lines: list[LineItem]) -> None:
self.items = lines
def __init__(self, items: list[LineItem]) -> None:
self.items = items

def render(self, context: RenderContext) -> None:
def render_line(geom: LineString, item: LineItem) -> None:
Expand Down
4 changes: 2 additions & 2 deletions mapsy/layer/symbol_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class SymbolItem:
class SymbolLayer(Layer):
items: list[SymbolItem]

def __init__(self, symbols: list[SymbolItem]) -> None:
self.items = symbols
def __init__(self, items: list[SymbolItem]) -> None:
self.items = items
super().__init__()

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion mapsy/render/cairo_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def draw_paths(color: Color):

if line_width > 0:
context.set_line_width(line_width)
context.set_line_join(cairo.LINE_JOIN_ROUND)

draw_paths(line_color)
context.stroke()

Expand All @@ -148,7 +150,7 @@ def draw_line(
color: Color,
width: float,
cap: LineCap = LineCap.BUTT,
join: LineJoin = LineJoin.MITER,
join: LineJoin = LineJoin.ROUND,
outline_color: Color = None,
outline_width: float = 0,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mapsy"
version = "0.1.0"
version = "0.2.0"
description = "Mapsy is a Python library designed easily render static maps in python."
authors = ["Felix Horvat <[email protected]>"]
readme = "README.md"
Expand Down
Binary file modified test/data/test_fill_layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/test_line_layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/test_fill_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
def test_fill_layer(tmp_path):
items = [
mapsy.FillItem(
polygon=Polygon([(0, 0), (0.5, 0), (0.5, 0.5), (0, 0.5)]),
fill_color=mapsy.Color(1, 0, 0),
geometry=Polygon([(0, 0), (0.5, 0), (0.5, 0.5), (0, 0.5)]),
color=mapsy.Color(1, 0, 0),
line_color=mapsy.Color(0, 0, 0),
line_width=1,
),
mapsy.FillItem(
polygon=Polygon([(0.5, 0.5), (1, 0.5), (1, 1), (0.5, 1)]),
fill_color=mapsy.Color(0, 1, 0),
geometry=Polygon([(0.5, 0.5), (1, 0.5), (1, 1), (0.5, 1)]),
color=mapsy.Color(0, 1, 0),
line_color=mapsy.Color(1, 1, 1),
line_width=10,
),
Expand Down

0 comments on commit cc3a53c

Please sign in to comment.