Skip to content

Add gaps at non-interacting SVG line crossings - #8562

Open
mhucka wants to merge 6 commits into
quantumlib:mainfrom
mhucka:svg-line-crossings-gap
Open

mhucka wants to merge 6 commits into
quantumlib:mainfrom
mhucka:svg-line-crossings-gap

Conversation

@mhucka

@mhucka mhucka commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

In order to make it more clear when vertical and horizontal line crossings do not represent interaction, this PR modifies the drawing algorithm to put a thin space between the lines. The space is added to the qubit lines, to make vertical lines appear to cross over the qubit lines. Here's a crude rendition of the change in ASCII: whereas crossings looked like ───┼─── before, they now look more like ───|───.

Split horizontal wires in Cirq SVG circuit diagrams around vertical
connectors that cross without interacting, leaving a transparent 3.0 px
clearance on each side of the 1.5 px vertical stroke (7.5 px opening).

- Add CROSSING_GAP, HORIZONTAL_LINE_STROKE_WIDTH, and
  VERTICAL_LINE_STROKE_WIDTH constants plus _line, _split_segment, and
  _crossing_columns helpers in cirq/contrib/svg/svg.py.
- Add optional crossing_gap parameter to tdd_to_svg (validating finite
  non-negative values; 0 preserves legacy output byte-for-byte).
- Keep all interacting junctions (controls, gate boxes, swap crosses,
  empty wire symbols, T-junctions, and moment-group brackets) unbroken.
- Add unit and SVG geometry tests in cirq/contrib/svg/svg_test.py.
# Conflicts:
#	cirq-core/cirq/contrib/svg/svg.py
Increase CROSSING_GAP by 1 px per side (3.0 -> 4.0 px, raising total
opening around 1.5 px vertical strokes from 7.5 to 9.5 px) and adjust
the tight-layout merge/keep boundary test in svg_test.py accordingly.
@github-actions github-actions Bot added size: L 250< lines changed <1000 area/contrib and removed size: L 250< lines changed <1000 labels Dec 1, 2026
@mhucka

mhucka commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Here are some before and after diagram examples.

image image

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.58%. Comparing base (e6e1221) to head (9fd83fc).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #8562    +/-   ##
========================================
  Coverage   99.58%   99.58%            
========================================
  Files        1139     1139            
  Lines      105740   106049   +309     
========================================
+ Hits       105303   105614   +311     
+ Misses        437      435     -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mhucka
mhucka marked this pull request as ready for review December 1, 2026 04:09
@mhucka
mhucka requested a review from a team as a code owner December 1, 2026 04:09
@mhucka
mhucka requested review from arettig, dstrain115 and fdmalone and removed request for fdmalone December 1, 2026 04:09
# Conflicts:
#	cirq-core/cirq/contrib/svg/svg.py
#	cirq-core/cirq/contrib/svg/svg_test.py
@mhucka
mhucka requested a review from pavoljuhas December 2, 2026 06:09
@github-actions github-actions Bot added the size: L 250< lines changed <1000 label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/contrib size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant