Skip to content

Fix centering of graphics with zero-width or zero-height bounds - #233

Open
gaboolthewild wants to merge 1 commit into
tscircuit:mainfrom
gaboolthewild:fix/center-degenerate-bounds
Open

gaboolthewild wants to merge 1 commit into
tscircuit:mainfrom
gaboolthewild:fix/center-degenerate-bounds

Conversation

@gaboolthewild

Copy link
Copy Markdown

Single points and axis-aligned lines are shifted away from the output center in SVG, canvas, and PNG rendering. The transforms replace a zero-sized span with 1 to avoid division by zero, then incorrectly use that fallback span when computing the center.

This change computes the center from the actual bounds while preserving the existing scale fallback. It fixes both the SVG transform and the shared canvas/PNG transform.

Validation:

  • Added 18 regression tests covering single points, horizontal and vertical lines, both coordinate systems, both viewbox formats, SVG output, and decoded PNG pixels.
  • Confirmed all 18 regressions fail against the original source and pass with the fix.
  • Full test suite: 87 passed, 0 failed.
  • Type check, package build, and changed-file formatting pass.

AI assistance: implemented and tested with OpenAI Codex.

Compute SVG and canvas/PNG centers from the actual bounds while retaining safe fallback spans for scaling. Add regression coverage for points and axis-aligned lines.

Implemented and tested with OpenAI Codex assistance.
@vercel

vercel Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
graphics-debug Ready Ready Preview Sep 21, 2026 5:14pm UTC

Request Review

Copy link
Copy Markdown
Author

Could you confirm whether this fix, if merged, will be picked up by the contribution tracker, and whether any contributor onboarding is needed beyond GitHub Sponsors enrollment? I understand this PR has no fixed bounty and sponsorship depends on the assessed contribution score.

This branch was successfully deployed

1 active deployment
Preview — 6411408c Deployed Sep 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant