tscircuit / tscircuit/image-utils
SVG path and group transform attributes are ignored by geometry conversion
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
getTransformedSvgPathRoutes applies the caller-supplied matrix but ignores transform attributes inside the SVG. A 1×1 path translated by (2,3), either directly or through a parent group, produces the unshifted route.
Reproduction on 81a79bc3665a4fedab02d3a8e273b9ac5d1af906 (0.0.10):
import { expect, test } from "bun:test"
import { identity } from "transformation-matrix"
import { getTransformedSvgPathRoutes } from "../lib/svg-to-brep-shapes"
const convert = (body: string) => getTransformedSvgPathRoutes({
svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">${body}</svg>`,
width: 10, height: 10, transform: identity(),
})
for (const body of [
'<path transform="translate(2 3)" d="M0 0H1V1H0Z"/>',
'<g transform="translate(2 3)"><path d="M0 0H1V1H0Z"/></g>',
]) {
test(`SVG transform matches equivalent explicit coordinates: ${body}`, () => {
const actual = convert(body)
const expected = convert('<path d="M2 3H3V4H2Z"/>')
console.log(JSON.stringify({actual,expected}))
expect(expected[0]?.[0]).toEqual({x:-3,y:2})
expect(actual).toEqual(expected)
})
}
Run bun test tests/svg-element-transform.test.ts: both cases fail. The expected first vertex is (-3,2) after the existing viewBox centering/Y flip; actual is (-5,5). The explicitly positioned reference has the correct coordinates. No curves, multiline attributes, or nested viewports are involved.
The path extractor retains only d and loses both path transform attributes and ancestor group context. Preserve the cumulative element transform and apply it in SVG user space before the existing viewBox mapping and caller transform. SVG 2 coordinate systems and transforms describes child coordinate systems and the transform attribute.
This is separate from #27/#28 (per-path hole classification) and #19 (smooth-curve control points). The reproduction verifies geometry output; it does not claim full CSS or nested-viewport support.
Investigated with Codex (Astra) assistance.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running bun test tests/svg-element-transform.test.ts and inspect getTransformedSvgPathRoutes in lib/svg-to-brep-shapes. Trace how path data is extracted and how viewBox and caller transforms are applied. Done means both direct path and parent-group transform cases produce the same geometry as the explicitly positioned reference, including the expected first vertex.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100