Add SVG export for cells and libraries#192
Merged
MatthewMckee4 merged 10 commits intomainfrom Mar 5, 2026
Merged
Conversation
Adds `cell_to_svg` and `library_to_svg` functions that render GDS elements (polygons, paths, boxes, text, nodes) to SVG with layer-based coloring. References are flattened, the Y axis is flipped for correct orientation, and the viewport auto-sizes to the bounding box. Closes #134
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 23.08%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | write_medium |
784.8 µs | 1,020.3 µs | -23.08% |
Comparing feat/svg-export (e093c0f) with main (327f160)
Compute bounding box from flattened elements instead of the cell directly, so cells containing only references get a correct viewport. Also add SVG export to the sample example.
- Compute bounding box from flattened elements so cells with only references get a correct viewport - Scale text font-size and node radius relative to the design extent - Format coordinates with limited precision and strip trailing zeros - Add SVG export to the sample example
Add a `dbu` parameter to `cell_to_svg` and `library_to_svg` so all coordinates are divided by the database unit, producing human-readable numbers (e.g. 1000 instead of 0.000001).
Apply a counter-flip transform on text elements so they read correctly despite the parent group's Y-axis flip.
Replace monolithic render_element match with a ToSvg trait implemented for each element type (Polygon, Path, GdsBox, Text, Node, Reference, Element, Cell). Reference handles its own flattening via flatten(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Cell::elements() method that returns an iterator over all elements without flattening references. Use it in the ToSvg impl for Cell. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove redundant elements() method — main already provides iter_elements() which returns borrowed references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cell_to_svgandlibrary_to_svgpublic functions to thegdsrcrateCloses #134
Test plan