Add animated detector slice diagrams - #1103
Conversation
Add a self-contained animation for detector slices with operations. Preserve exact Stim SVG frames at integer ticks and interpolate detector regions between ticks.
| } | ||
| }; | ||
|
|
||
| DetectorSliceSvgPath parse_shape(std::string_view tag) { |
There was a problem hiding this comment.
Why is this code doing any parsing? It should be generating images, not parsing images.
Is it consuming images produced elsewhere in the code and editing them? That is far too brittle.
There was a problem hiding this comment.
Removed the SVG parsing. Detector geometry and style are now collected directly while the existing detector-slice renderer writes the SVG.
| std::map<uint64_t, DetectorRegion> detector_regions; | ||
| }; | ||
|
|
||
| struct StringBuffer : std::streambuf { |
There was a problem hiding this comment.
Why not just std::stringstream?
| function fillOpacity(group){for(const e of group.querySelectorAll('path,circle'))if(e.getAttribute('stroke')==='none'&&e.getAttribute('fill')!=='none'){const value=Number(e.getAttribute('fill-opacity')||1);if(Number.isFinite(value))return value}return 1} | ||
| function decodePoints(text){const raw=atob(text),bytes=new Uint8Array(raw.length);for(let k=0;k<raw.length;k++)bytes[k]=raw.charCodeAt(k);return new Float32Array(bytes.buffer)} | ||
| function pathData(a,b,t){let d='M';for(let k=0;k<a.length/2;k++){if(k)d+='L';d+=(a[2*k]+(b[2*k]-a[2*k])*t).toFixed(4)+','+(a[2*k+1]+(b[2*k+1]-a[2*k+1])*t).toFixed(4)}return d+'Z'} | ||
| function replaceShape(element){if(!element)return null;const path=document.createElementNS(NS,'path');for(const attr of element.attributes){if(attr.name!=='d'&&attr.name!=='cx'&&attr.name!=='cy'&&attr.name!=='r')path.setAttribute(attr.name,attr.value)}element.replaceWith(path);return path} |
There was a problem hiding this comment.
Why does is this all mushed together?
There was a problem hiding this comment.
Expanded the embedded JavaScript into readable functions
| StringBuffer buffer(capacity); | ||
| std::ostream out(&buffer); | ||
| write_animation_frames(std::move(frames), tick_slice_start, out); | ||
| return std::move(buffer.data); |
There was a problem hiding this comment.
Added focused unit tests covering exact frame generation and detector transition behavior.
Remove SVG parsing by collecting detector geometry during rendering. Use std::stringstream, format the embedded player, and add focused tests.
f44d7d0 to
1524b11
Compare
Adds
animated-detslice-with-opstostim.Circuit.diagramandstim diagram.The result is a self-contained HTML animation of Stim’s existing
detslice-with-ops-svgoutput. Integer ticks use exact Stim SVG frames, while detector regions interpolate smoothly between ticks.Supports tick ranges and coordinate filtering. No external dependencies.