tscircuit / tscircuit/image-utils

Unreferenced defs and symbol paths become filled output geometry

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
0
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Unreferenced path definitions become filled output geometry in getSvgBRepShapes. Reproduced on v0.0.10, commit 81a79bc3665a4fedab02d3a8e273b9ac5d1af906.

An SVG containing only <defs><path id="unused" d="M1 1H2V2H1Z"/></defs> should produce no visible shapes. It currently returns one BRep square (bounds x=-4..-3, y=3..4 with a 10x10 viewBox/output). An unreferenced symbol produces the same result. Adding a separate visible path results in two output shapes instead of one, including when the definition is nested in a group.

The SVG 2 defs and symbol rules specify that these contents are not directly rendered. There is no use element or other reference in this reproduction, so reference expansion is not required to establish the expected output.

Reproduction test (Bun, from repository root):

import { expect, test } from "bun:test"
import { identity } from "transformation-matrix"
import { getSvgBRepShapes } from "../lib/svg-to-brep-shapes"

const convert = (body: string) => getSvgBRepShapes({
  svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">${body}</svg>`,
  width: 10, height: 10, transform: identity(),
})
const definition = '<path id="unused" d="M1 1H2V2H1Z"/>'
const visible = '<path d="M7 7H8V8H7Z"/>'

for (const container of ["defs", "symbol"]) {
  test(`unreferenced ${container} content produces no filled shapes`, () => {
    const actual = convert(`<${container}>${definition}</${container}>`)
    console.log(JSON.stringify({container, actual}))
    expect(actual).toEqual([])
  })
  test(`unreferenced ${container} does not add geometry beside a visible path`, () => {
    const expected = convert(visible)
    expect(expected).toHaveLength(1)
    expect(convert(`<${container}><g>${definition}</g></${container}>${visible}`))
      .toEqual(expected)
  })
}

Run bun test tests/unreferenced-definitions.test.ts. All four regressions fail on the current implementation; the visible-only controls each return one shape.

The path extraction scans every path tag without distinguishing definition content from directly rendered paths. #29/#30 address transform attributes; this report concerns whether the path should contribute any visible geometry. A fix should exclude unreferenced definition content while preserving ordinary visible paths, with referenced definitions handled separately as appropriate.

Investigated with Codex (Astra) assistance; reproduction verified locally.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/svg-to-brep-shapes and run bun test tests/unreferenced-definitions.test.ts. Trace how path tags inside defs and symbol elements are collected, including nested groups, while checking the visible-path controls. Done means all four regression tests pass, unreferenced definitions produce no shapes, and visible paths still produce exactly one shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.