Skip to content

Drawing export: any curve is cut to a detail view's boundary, and fills are kept or dropped whole (#4890) - #9840

Closed
CamWight wants to merge 2 commits into
tangency-labs:drawingsfrom
CamWight:paper-clip-4890-a8b
Closed

CamWight wants to merge 2 commits into
tangency-labs:drawingsfrom
CamWight:paper-clip-4890-a8b

Conversation

@CamWight

@CamWight CamWight commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Only lines and arcs could be cut to a boundary, such as a detail view's circle, so other curves inside one were refused. Now any curve is cut where it crosses the boundary, and a filled area wholly inside is kept and one wholly outside is dropped. A fill that crosses the boundary is still refused, by name.

Part of #4890 (W10, the paper scene), into drawings: clips of every curve, and fills kept or dropped whole (A8b). Stacked on #9833 (A8a, clips of lines and arcs). The commits before the last are the stack's; this PR's own is the last.

Changes a default: no

In crates/geom: paper/clip.rs cuts every curve and keeps or drops fills whole. profile.rs gains Seg2::part, a piece of any 2D segment, with a test in tests.rs. The rest is tests. These modules hold drawing data only, with no kernel geometry.

What it does

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 would need more than MAX_HALVINGS halvings, one that runs that 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. The clip's own copy of part goes.
  • A line or an arc within EPS of touching the edge, on either side, only touches it: one cut there. So there's never a sliver of chord, and never a piece outside kept whole because its middle is on the edge.
  • A fill wholly inside its clip is kept, and one wholly outside is dropped. An edge lying along the clip's, within EPS, counts as either side: a fill beside the clip is dropped, and one that is the clip's own outline is kept. One that crosses the edge, or lies round the whole clip, is refused as not supported yet.
  • Each "not supported yet" says (#4890 A8).

Pictures

No view draws a clip yet: detail views will be the first. So this picture comes from the SVG writer itself, the same path a sheet export takes. One sheet holds the same object three times: as drawn, cut to a detail view's circle, and cut to a rectangle. Each boundary is drawn thin and dashed in a group of its own, which isn't clipped. The SVG was rendered to PNG in Chrome.

The object is a square outline, two parabolas, two cubics (one dashed) and two fills. Parabolas and cubics are the curves the SVG writer takes before A3b (#9846). Each curve is cut where it crosses the edge. The fill in the middle lies inside both clips and is kept. The one at the top left lies outside both and is dropped.

Three copies of one drawing. On the left, uncut: a square, two parabolas, two cubic curves (one dashed), a filled square at the centre and one at the top left. In the middle, the same cut to a dashed circle boundary: the curves end at the circle, the centre fill is kept and the top-left fill is gone. On the right, the same cut to a dashed rectangle

Tests

  • Every curve kind cut where it crosses a rectangle and a circle, and the parts keeping their kind.
  • A dashed curve keeping its pattern across its cuts.
  • A fill inside, outside, round the clip and across its edge.
  • A line reaching into a circle by less than EPS: a touch, no chord.
  • Shapes at the edge, not only random ones: vertices on it, half an EPS and two EPS either side; zigzags 10°, 50° and 80° off its normal, open and closed; lines along it, through a corner and tangent to it; arcs touching it from either side and one round a circle clip; pieces from 0.1 µm to 3 mm; every other one dashed. Each is cut without refusal, 64 points a kept piece lie inside, every point well inside is drawn, nothing grows and the dash pattern stays. Squares on the edge, either side, are kept or dropped whole, and a fill that is the clip is kept.
  • Fuzzed clips of every kind keep exactly what lies inside.
  • Seg2::part ends where the whole is, for every kind, a conic's tail included.

On this head

Re-parented onto drawings 49a3ba1c0 (#7430 landed) as 4e845f8d3. 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 d50f548c2, hold unchanged.

d50f548c2 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). The stack's commits apply as they were. A review of the stack asked for the shapes-at-the-edge test above. It found two faults, both fixed here:

  • A piece just outside kept whole. A line or an arc just outside the edge (within EPS) had no cut, so its middle, on the edge, kept all of it, its far-outside ends included. A touch within EPS either side is now one cut, for lines on circles, arcs on rectangles and arcs on circles.
  • A fill beside the clip refused. A fill sharing an edge with the clip from outside was refused as crossing, because its edge on the clip's counted as inside. Such an edge now says neither side.
    Each fails its test without the fix.

Integration status

Lands after #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 Oct 31, 2026
@CamWight
CamWight force-pushed the paper-clip-4890-a8b branch from 732a817 to 09ea1e9 Compare November 1, 2026 05:53
@CamWight
CamWight force-pushed the paper-clip-4890-a8b branch from 09ea1e9 to 41e868f Compare November 2, 2026 03:05
@CamWight CamWight changed the title Paper scene: clips of every curve, and fills kept or dropped whole (#4890 A8b) Drawing export A8b: any curve is cut to a detail view's boundary, and fills are kept or dropped whole (#4890) Nov 2, 2026
@CamWight
CamWight force-pushed the paper-clip-4890-a8b branch from 41e868f to 00de7a8 Compare November 2, 2026 23:34
@CamWight
CamWight marked this pull request as ready for review November 2, 2026 23:36
@CamWight
CamWight force-pushed the paper-clip-4890-a8b branch from 00de7a8 to d50f548 Compare November 3, 2026 11:46
@CamWight CamWight changed the title Drawing export A8b: any curve is cut to a detail view's boundary, and fills are kept or dropped whole (#4890) Drawing export: any curve is cut to a detail view's boundary, and fills are kept or dropped whole (#4890) Nov 3, 2026
CamWight and others added 2 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>
@CamWight
CamWight force-pushed the paper-clip-4890-a8b branch from d50f548 to 4e845f8 Compare November 3, 2026 12:52
@CamWight

CamWight commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing: this work landed in drawings inside #10969, merged with it at 12:58.

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.

1 participant