-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add virtual machine based on shapely library (#311)
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](https://github.com/Argmaster/pygerber/blob/main/test/assets/gerberx3/A64_OLinuXino_rev_G/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: <p align="center"> <img width="500" src=https://github.com/user-attachments/assets/a5a99999-59b2-46bc-befe-2eeee82bc6ad /> </p> 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: ```bash pip install pygerber[shapely] ``` Also, it is sick how easy it is to implement new virtual machines, VM code itself is like 370 lines.
- Loading branch information
Showing
18 changed files
with
1,781 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""The `shapely` package contains concrete implementation of `VirtualMachine` using | ||
Shapely library. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from pygerber.vm.shapely.errors import ( | ||
ShapelyNotInstalledError, | ||
ShapelyVirtualMachineError, | ||
) | ||
from pygerber.vm.shapely.vm import ( | ||
ShapelyDeferredLayer, | ||
ShapelyEagerLayer, | ||
ShapelyResult, | ||
ShapelyVirtualMachine, | ||
) | ||
|
||
__all__ = [ | ||
"ShapelyVirtualMachine", | ||
"ShapelyEagerLayer", | ||
"ShapelyDeferredLayer", | ||
"ShapelyResult", | ||
"ShapelyNotInstalledError", | ||
"ShapelyVirtualMachineError", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""`errors` module aggregates all exceptions related to the `ShapelyVirtualMachine`.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pygerber.vm.types.errors import VirtualMachineError | ||
|
||
|
||
class ShapelyVirtualMachineError(VirtualMachineError): | ||
"""Base class for all exceptions in the `ShapelyVirtualMachine`.""" | ||
|
||
|
||
class ShapelyNotInstalledError(ShapelyVirtualMachineError): | ||
"""Raised when shapely package or other dependencies of `ShapelyVirtualMachine` | ||
are not installed. | ||
To install all dependencies of `ShapelyVirtualMachine`, run: | ||
```bash | ||
pip install pygerber[shapely] | ||
``` | ||
""" |
Oops, something went wrong.