Skip to content

Add SVG export for cells and libraries#192

Merged
MatthewMckee4 merged 10 commits intomainfrom
feat/svg-export
Mar 5, 2026
Merged

Add SVG export for cells and libraries#192
MatthewMckee4 merged 10 commits intomainfrom
feat/svg-export

Conversation

@MatthewMckee4
Copy link
Owner

Summary

  • Add cell_to_svg and library_to_svg public functions to the gdsr crate
  • Render polygons, paths, boxes, text, and nodes as SVG elements with layer-based coloring (same 16-color palette as viewer)
  • Flatten cell references recursively so nested hierarchies render correctly
  • Auto-size viewport to bounding box with 5% margin
  • Flip Y axis (GDS Y-up → SVG Y-down) via SVG transform group
  • Escape text content for XML safety

Closes #134

Test plan

  • 11 new snapshot tests covering each element type, reference flattening, multi-layer colors, XML escaping, empty cells, and Y-flip transform
  • Full test suite passes (691 tests)
  • All pre-commit checks pass

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
@MatthewMckee4 MatthewMckee4 added the enhancement New feature or request label Mar 5, 2026
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
crates/gdsr/src/utils/svg.rs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will degrade performance by 23.08%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

❌ 1 regressed benchmark
✅ 3 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
write_medium 784.8 µs 1,020.3 µs -23.08%

Comparing feat/svg-export (e093c0f) with main (327f160)

Open in CodSpeed

MatthewMckee4 and others added 9 commits March 5, 2026 13:10
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>
@MatthewMckee4 MatthewMckee4 merged commit c216f41 into main Mar 5, 2026
8 checks passed
@MatthewMckee4 MatthewMckee4 deleted the feat/svg-export branch March 5, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG export

1 participant