From cc3a53cd44447f8135974b5bca17b69803b774ea Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Wed, 27 Nov 2024 11:39:11 +0100 Subject: [PATCH] fixed consistency issues changed the join mode for polygon outlines --- README.md | 8 ++++---- example/simple_map.py | 4 ++-- mapsy/layer/fill_layer.py | 10 +++++----- mapsy/layer/line_layer.py | 6 +++--- mapsy/layer/symbol_layer.py | 4 ++-- mapsy/render/cairo_backend.py | 4 +++- pyproject.toml | 2 +- test/data/test_fill_layer.png | Bin 632 -> 622 bytes test/data/test_line_layer.png | Bin 505 -> 504 bytes test/test_fill_layer.py | 8 ++++---- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 17e73aa..5b03f4a 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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, @@ -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, @@ -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) diff --git a/example/simple_map.py b/example/simple_map.py index 9c2d402..232bad5 100644 --- a/example/simple_map.py +++ b/example/simple_map.py @@ -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, ) diff --git a/mapsy/layer/fill_layer.py b/mapsy/layer/fill_layer.py index ab81e93..ed4c645 100644 --- a/mapsy/layer/fill_layer.py +++ b/mapsy/layer/fill_layer.py @@ -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 @@ -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, ) diff --git a/mapsy/layer/line_layer.py b/mapsy/layer/line_layer.py index a33cf17..9db490b 100644 --- a/mapsy/layer/line_layer.py +++ b/mapsy/layer/line_layer.py @@ -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: diff --git a/mapsy/layer/symbol_layer.py b/mapsy/layer/symbol_layer.py index 2945276..81a0c51 100644 --- a/mapsy/layer/symbol_layer.py +++ b/mapsy/layer/symbol_layer.py @@ -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 diff --git a/mapsy/render/cairo_backend.py b/mapsy/render/cairo_backend.py index 34e0a92..99c9faf 100644 --- a/mapsy/render/cairo_backend.py +++ b/mapsy/render/cairo_backend.py @@ -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() @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 06f8ef3..283a4a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" diff --git a/test/data/test_fill_layer.png b/test/data/test_fill_layer.png index 2b5817331c1784b150ee574df5925116c12af0c2..4cceb135467f93784fa5e947ba6350fc32ef2150 100644 GIT binary patch delta 579 zcmeyt@{VPKS-rBSi(^Q|oVRxz{cZ<{v_4EuezWA23eQdV^jIhH%aJ!3SHF)OTL?Cy%aOj=8)+%i71bgeDJH^B}`Cd12D z`Bb=T3YQmO9Y)&haC0T+5WrZBBIJ^+hX?DwN2@XAIWrj;E*{0dnLB^=Wn!MX)HX0B)qcx7Q{rNY2uC~PWV#d6%eokig1|112r zG8Rt_t1muZ6!LM}nk7M}!Y=LlCR5z8Yg5gB-h@Rf8ke{#q*-}RH+nNEEX&UOaJ2pI zo%`f|@4Nr^_nlXlt2!#~e+>E@TJ=M1?iIO|uKSbf-j;o@y+8ljywp|ix=sFZ$ayT= zJNso+kcY6xwD(8f7{$0Lzs%cxm-lc%boI2AR;oKsTG?CwuCG+DU2l6lBr_~bj3sH= z*$wMw?QOqtY0iW;2LpCs7_`sG^q%y4f=)za8pjbH*(9~IoSB>~#XujIbV&Mv0@_(2 z?S+8xp6RJ=u%Pt1>oZIEP`iu)H`suOEi)7aj9HS}_zW+1nTxO8un832R!2aJ*lnJo ysap11xm0}X@(MGr{>3H#_wWB6Zl&pI^@OvlJH9}#yU2h62s~Z=T-G@yGywo4mHYGn delta 589 zcmV-T0_(uafBQuJ930vf-~d} zS!I`_08${bAk*2fAilxGf@NaEru6( za~;wJ{LGR%kcbGx41qM1sYCWEbvgu-5r`QAY3R*$NJLQs*$btP$q1yOOdXO|)Ihix zVi^R|5FHW#ftZOJ2&Il?5J*FmdH_)ap+m3?0%?d234lP%L=A*e$KlZ-0T76psDaQS zI6OKefXM%+zJJqNYpt}JdzOQWw`3*NTJI#Cww_}SQCAkv_F@?XVrG!^we=9&^iua; zI@$KKo9pYbl(KpH+UniuNyK}{|GIPO;gfXKdXOo;OZv9i+?P_0ThB7p@KG8sf(Mdm z?`C>0DG-R6A;SmyPSV}&?WUCStMx2X4N7v!`fzr3`F~sb++CasR;fiPu%qucohgs>}`2 z(-`SiH2=w#UlX=YbN1u={Yv{<^rSscel*9t=fAm~W0SYs>i&pqmHD1|tKQ#el4iQB z>Cr8J@Xe>`zbvXx|301>x0*k2(!@J`PZs{_(=Dk=*_t3QL(kD|)}O^&yeF9PFeQVy zcLdHR3IKgr!uhBzgAe4tW!?hjF2x`p8^kv4P@Hub_s!nNz^G*KboFyt=akR{ E08F0QdH?_b literal 505 zcmeAS@N?(olHy`uVBq!ia0vp^DImPcyWbkzLb6Mw<&;$Ty8_@;; diff --git a/test/test_fill_layer.py b/test/test_fill_layer.py index e3e3d97..9a93a9b 100644 --- a/test/test_fill_layer.py +++ b/test/test_fill_layer.py @@ -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, ),