Skip to content

Drawing export: SVG and PNG cut a picture to a detail view's boundary (#4890) - #10969

Merged
bherbruck merged 3 commits into
tangency-labs:drawingsfrom
CamWight:paper-clip-4890-a8c
Nov 3, 2026
Merged

bherbruck merged 3 commits into
tangency-labs:drawingsfrom
CamWight:paper-clip-4890-a8c

Conversation

@CamWight

@CamWight CamWight commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

A detail view of a shaded view couldn't be exported: a picture inside an object cut to a boundary was refused. Now the SVG and sheet PNG exports cut such a picture to the boundary, a rectangle or a detail view's circle. So a detail view of a shaded view can be drawn. Shaded views and detail views are both planned for the first drawing release.

Part of #4890 (W10, the paper scene), into drawings: pictures in a clipped object, cut by the SVG and sheet PNG writers (A8c). Stacked on #9840 (A8b), which refuses them today, and so on #9833 (A8a). The commits before the last are the stack's; this PR's own is the last. It closes the gap #9840 names: shaded views and detail views are both in the first release, and a detail view of a shaded picture couldn't be drawn.

Changes a default: no

In crates/geom: paper/clip.rs keeps or drops a picture and says whether one lies wholly inside; paper.rs's Prepared keeps the clips; paper/grid.rs's GridItem::Picture carries the clip to the writer. The rest is tests. These modules hold drawing data only, with no kernel geometry.

What it does

Strokes and fills are cut as geometry when a scene is prepared. Pixels can't be, so a picture is cut by whichever writer draws it.

  • Wholly outside the clip: dropped when the scene is prepared, with nothing asked for. A circle is judged by the disc, not its box.
  • Wholly inside: drawn as it always was, with no clip.
  • Crossing the edge: GridItem::Picture { picture, clip } hands the writer the clip.
    • SVG: a <clipPath> holding a <rect> or <circle> on the same nanometre grid as the lines, numbered in document order, so a scene writes the same bytes each time.
    • Sheet PNG: a pixel is drawn when its middle is inside, at the sheet's own pixels even when the picture is asked for coarser. This edge isn't smoothed; a view's frame line would lie on it.
    • Both take one visible box from the grid (GridItem::Picture { visible }): the picture's part on the sheet and inside its clip's box. They ask for and embed only the pixels that meet it, so a small detail of a large picture stays small, and one past the sheet's edge asks only for the sheet's part.
  • Text in a clipped object stays refused, with its own message ((#4890 A8)), until text clips too.

For #7626

pdf.rs is left alone here. It lives on #7626, and PDF isn't part of this PR. GridItem::Picture changes shape, so that writer stops compiling at its rebase rather than silently drawing a whole picture past its clip. It then needs to honour clip, or refuse it by name.

No detail view yet

No command makes a detail view yet, and nothing on drawings sets Scene.clips. #9720 brings the boundary's geometry, with its records and commands still to come. So no user can reach this until then, and Scene.clips was set only in the local run below.

Pictures

These come from a real app run, plain test design, but not from this PR's branch alone. It was a local mix, never pushed, of this PR and #10926 (the shaded view on paper), plus a small stand-in that gives one view a clip from a file and writes a sheet PNG beside each SVG. The view is a second top view of the milestone plate at 3:1, standing for a detail view.

The SVG in Chrome, the view cut by a circle, on its sheet beside its parent:

The shaded detail cut by a circle, beside its parent

The SVG cut by a rectangle: both holes it crosses are cut at its edge.

The shaded detail cut by a rectangle

The sheet PNG at 150 dpi, zoomed twice: a pixel is in or out by its middle, so the edge isn't smoothed.

The sheet PNG's edge

What the run was tested with, and which limit applied. The mix takes the renderer from #10926's stack, which carries #6483's commits, so #6483's budget applied: 8 pixel tests a sample of the whole view, or 128 M if that's more, each triangle counted whole. On the plain plate the view drew at 1:1, twice its parent's scale, which is what's shown here. At 2:1 it was refused by name, and at 2:1, 3:1 and 5:1 cut to a 20 mm circle too: "projected product exceeds ... pixel tests". That limit is #6483's and is being fixed there, so a real detail view's scale isn't shown drawn yet. drawings doesn't have that renderer until #6483 lands and drawings takes main.

Tests

  • The visible box: the whole picture with no clip, the clip's part with a rectangle or a circle, and the sheet's part of a picture past its edge.
  • Dropped, whole or handed on, for rectangles and circles: inside, exactly on the picture, round it, clear of it, a circle whose box overlaps though its disc doesn't reach, and a circle holding three corners but not the fourth.
  • SVG's exact <clipPath> and clip-path, y flipped as the lines are; each clip its own id; none for a picture wholly inside; only the clip's pixels asked for.
  • Fuzz, 240 clip shapes through both writers: rectangles and circles at random, tiny ones, ones reaching off the sheet, ones round the whole picture, ones touching it and ones clear of it. Each PNG pixel is checked against the clip and the picture, worked out apart from the code. The SVG has a <clipPath> only when the clip crosses the picture, and no image when it misses.
  • The cut falls at the sheet's pixels at 2400 dpi, where the picture is asked for at half that; paper stays paper in RGB, grey, black and white, and transparent.
  • Mutation fuzz: a clipped line and picture as JSON, rectangle and circle, mutated, then read, prepared and written by both writers: an error or a file, never a panic.

Not covered

  • Smoothing the PNG's edge, as above.
  • Reading the SVG back: read_svg has no handling for <clipPath>, so from its code a clip's <rect> or <circle> would import as a drawn shape. It reads any SVG's that way today; not run here, and it would be its own small fix.

On this head

Re-parented onto drawings 49a3ba1c0 (#7430 landed) as af78dd6b4. The landed tree is byte for byte our A5 commit's, so every commit of the stack keeps its tree and the checks below, run on d0550d9c2, hold unchanged.

d0550d9c2 over drawings d78895de4, local, Windows, --profile ci:

  • on each of the stack's heads (A5 then in it), rustfmt and clippy -D warnings over geom, io and engine, all targets, pass;
  • on each head over 112e0a3d9 an hour before: geom's library tests (A5 355, A8a 366, A8b 371, A8c 372) and io's paper tests (34, 34, 34, 38) pass, and on the top xtask lists, xtask layers and xtask wasm. The move to d78895de4 changed one engine test line (below);
  • on the top, d0550d9c2, over d78895de4: geom's library tests (372), io's paper tests (38) and engine's drawing and paper tests (199 + 2) pass;
  • 8 planted faults in A8a's and A8b's new fixes, on the top, each caught by a test, then the clean run passes: a run carried on where its parts don't meet; the seam rejoined where its ends don't; no cut for a line just outside a circle, an arc just outside a rectangle's edge, an arc just outside a circle, or an arc round a circle; a fill's edge along the clip counted inside; and a fill that is the clip dropped. A ninth, writing the touch test both ways round, changed nothing (the two forms agree), so the original line stays.

The planted faults of earlier rounds weren't rerun.

No full gate on this head.

What this rebase changed: drawings moved from d5fd14135 to d78895de4 (#10515, #7745, #10516, #11350, #11047, #9708, #11352). #9708 put text on the grid, beside the pictures. From a review of the stack:

  • the visible box is worked out once in on_grid and both writers take it, where each worked out its own before;
  • the note on the dropped-or-handed-on test said pictures were refused; it now says what the test checks.

Integration status

Lands after #9840 and #9833 (#7430 has landed). #4891 stays the claim for #4890.

@github-actions github-actions Bot added area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES labels Nov 2, 2026
@CamWight CamWight changed the title Paper scene: pictures in a clipped object, cut by the SVG and sheet PNG writers (#4890 A8c) Drawing export A8c: a picture inside a detail view's boundary is cut to that boundary in SVG and PNG (#4890) Nov 2, 2026
@CamWight
CamWight force-pushed the paper-clip-4890-a8c branch from dc90dd5 to ee1aa04 Compare November 2, 2026 23:34
@CamWight CamWight changed the title Drawing export A8c: a picture inside a detail view's boundary is cut to that boundary in SVG and PNG (#4890) Drawing export A8c: SVG and PNG cut a picture to a detail view's boundary (#4890) Nov 2, 2026
@CamWight
CamWight marked this pull request as ready for review November 2, 2026 23:36
@CamWight
CamWight force-pushed the paper-clip-4890-a8c branch from ee1aa04 to d0550d9 Compare November 3, 2026 11:46
@CamWight CamWight changed the title Drawing export A8c: SVG and PNG cut a picture to a detail view's boundary (#4890) Drawing export: SVG and PNG cut a picture to a detail view's boundary (#4890) Nov 3, 2026
CamWight and others added 3 commits November 3, 2026 12:51
…angency-labs#4890 A8a)

Scene::prepare_clipped(clips) cuts each group of an object to that
object's Clip, a rectangle or a circle (a detail view's), and keeps what
lies inside; prepare() is prepare_clipped with none. Prepared holds a
Cow: a scene without clips is borrowed as it is, and Group and Scene are
unchanged, so today's scenes are the same bytes.

- Lines and arcs are cut where they cross the edge; a part is kept when
  its middle is inside, the edge included. Parts no longer than EPS go.
- Kept parts that follow one another stay one open stroke. A stroke
  wholly inside is kept whole, closed if it was; a closed one cut open
  rejoins across its seam.
- A dashed stroke keeps its pattern: each part's phase is where it
  starts along the stroke. Across a closed one's seam the pattern runs
  on only when its length is whole patterns, so the parts rejoin only
  then.
- Checked: one clip an object, a rectangle from its lower-left to its
  upper-right corner or a circle with a radius above 0, within 1e5 mm;
  a clipped object's items strokes of lines and arcs. What the cuts
  made is validated again.

SVG and PNG draw the cut scene through Prepared as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…angency-labs#4890 A8b)

A clipped object's strokes may now hold any curve, not only lines and
arcs, and its fills are checked against the clip.

- A line or an arc is still cut where its equation says. Any other
  curve is halved while its control points lie either side of the edge
  (widened by EPS), until they span at most CUT_MM (1e-9 mm), and is cut
  there. A curve that needs more than MAX_HALVINGS halvings (one that
  runs this close along the edge) is refused as not supported yet.
  Each part is the same kind of curve as the whole.
- Seg2::part gives the piece between two parameters, starting and
  ending exactly where split_at puts those points; a conic's tail is
  re-normalised, so its second parameter is carried into it.
  Seg2::MIN_SPLIT names split_at's distance from the ends.
- A line or a circle within EPS of touching a circle only touches it:
  one cut there, never a sliver of chord.
- A fill wholly inside its clip is kept and one wholly outside is
  dropped. One that crosses the edge, or lies round the whole clip, is
  refused as not supported yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NG writers (tangency-labs#4890 A8c)

A picture wholly outside its object's clip is dropped when the scene is prepared. One crossing the clip's edge reaches its writer with the clip, on the grid item, since pixels can't be cut as geometry: SVG cuts it with a clipPath, the sheet PNG by whether each pixel's middle is inside. Both draw only the pixels that meet the clip's box. Text in a clipped object stays refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants