Long gate in ASCII art circuits - lengthen column width when necessary #2126
+246
−96
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.
See issue #1476.
I tried to keep the logic as close as possible to the original, because I wanted to keep it easy to review it in relation to the old logic.
The main change here is that instead of having the
ObjectsByColumn
of every Row be aFxHashMap<usize, String>
which contains the 7-width-wide strings, it's now aFxHashMap<usize, CircuitObject>
, whereCircuitObject
is an enum that supports every circuit object except for than blanks and wires (because those are inserted later on, on-the-go).Using this enum allows us to calculate the required
ColumnWidthsByColumn
(aFxHashMap<usize, usize>
) right before callingrow.fmt
- so we know what width theCircuitObjects
need to be when converted into strings.In the example from the ticket, this means that this circuit:
Which used to give:
Now gives
Apart from this desired change for long gates, the only notable difference is that, where ket-zero (
|0〉
) used to show as a width-5 circuit object (─ |0〉 ─
, it now shows as a width-7 circuit object (── |0〉 ──
) - you can see the difference in every test that used it.