Argmaster / pygerber

Python implementation of Gerber X3/X2 standard with 2D rendering engine.
https://argmaster.github.io/pygerber/stable
MIT License
54 stars 10 forks source link

Add virtual machine based on shapely library #311

Closed Argmaster closed 1 month ago

Argmaster commented 1 month ago

This pull request introduces new implementation of VirtualMachine interface, ShapelyVirtualMachine utilizing shapely library for generation of complex geometry. Alongside the implementation, unit and e2e tests are included. Currently ShapelyResult allows only SVG export. Overall performance of implementation is above expectations, seems to be very close to what pillow based implementation offers. On Ryzen 9 7950X rendering of A64-OlinuXino_Rev_G-B_Cu.gbr takes around 20s, including parsing and compilation to RVMC. However I must admit that this is still like 10x slower than Reference Gerber Viewer, no idea what kind of black magic they are using to render this so quickly šŸ˜„

Here is sample output:

Also, output is much cleaner than with masking approach used in drawsvg based rendering in PyGerber 2.4.1. Still, drawsvg backend will be likely implemented, since it is so easy to do so.

This virtual machine is not enabled by default in PyGerber to avoid depending on shapely and GEOS. It can be installed with shapely extras:

pip install pygerber[shapely]

Also, it is sick how easy it is to implement new virtual machines, VM code itself is like 370 lines.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 90.95745% with 17 lines in your changes missing coverage. Please review.

Project coverage is 90.49%. Comparing base (b467888) to head (60e789a). Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/pygerber/vm/shapely/vm.py 93.56% 11 Missing :warning:
src/pygerber/gerber/pygments.py 0.00% 3 Missing :warning:
src/pygerber/vm/__init__.py 0.00% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #311 +/- ## ========================================== + Coverage 90.33% 90.49% +0.16% ========================================== Files 151 154 +3 Lines 6619 6797 +178 ========================================== + Hits 5979 6151 +172 - Misses 640 646 +6 ``` | [Flag](https://app.codecov.io/gh/Argmaster/pygerber/pull/311/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Krzysztof+Wi%C5%9Bniewski) | Coverage Ī” | | |---|---|---| | [unittests](https://app.codecov.io/gh/Argmaster/pygerber/pull/311/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Krzysztof+Wi%C5%9Bniewski) | `90.49% <90.95%> (+0.16%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Krzysztof+Wi%C5%9Bniewski#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.