Skip to content

Drawing export: ellipses, hyperbolas and other complex curves draw smoothly in every format (#4890) - #9846

Merged
bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:paper-curves-4890-a3b
Nov 3, 2026
Merged

bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:paper-curves-4890-a3b

Conversation

@CamWight

@CamWight CamWight commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Drawing exports could draw lines, arcs and simple curves, but not ellipses, hyperbolas or higher-order curves. Now each one becomes curves that every format can write, within 0.0001 mm of the true shape. A curve that needs too many pieces is refused. It is never drawn coarser.

Part of #4890 (W10, the paper scene), into drawings: ellipses, hyperbolas and higher Béziers as cubics on the grid (A3b). This PR holds only its own commit.

Changes a default: no

In crates/geom: paper/cubic_pieces.rs is new and turns a conic or a high-degree Bézier into cubics for paper. paper/grid.rs calls it from the walk onto a writer's grid, paper.rs declares it, and paper_tests.rs and cubic_pieces_tests.rs test it. No kernel code is involved.

What it does

  • A conic of weight other than 1, and a Bézier above degree 3, become cubic Béziers within 1e-4 mm of the curve (paper::cubic_pieces). The walk takes them, and every writer draws them with the cubics it already writes.
  • Each piece's cubic has the curve's ends and end tangents. Its distance from the curve is bounded from the Bernstein form, not sampled: for a Bézier, by the control points of its difference with the cubic raised to its degree; for a conic, by Q·D − N over the denominator's least value.
  • A piece over the error is halved exactly and tried again, up to 4096 cubics a curve and 1,000,000 a scene. Past that the curve is refused, never drawn coarser.
  • The walk counts the cubics it made.
  • Circular arcs are left to the shared paper::cubics helper.

Pictures

No command on drawings puts these curves on a sheet yet. A view's round edges reach the sheet as short lines from the mesh, and drawing sketches (W38a) will be the first to bring ellipses and splines. So these pictures come from the SVG writer itself, the same path a sheet export takes. The test sheet is a plain A4 sheet with a border, a full ellipse made of four quarter conics (120 x 70 mm), a hyperbola arc (a conic of weight 2) and a Bézier wave of degree 5.

Before, on drawings d5fd14135: the writer refuses the whole sheet:
paper scene: not supported yet: ellipses, hyperbolas and Béziers above degree 3 on paper (#4890, A3b)

After, on 4a29e9034 (this commit before the moves): the sheet is written, and each curve is drawn as SVG cubics. The SVG was rendered to PNG in Chrome.

After: an A4 sheet with its border, a full ellipse on the left, a hyperbola arc at the top right and a wave-shaped degree 5 Bézier at the bottom right, all drawn as smooth curves

Tests

  • A parabola is one exact cubic.
  • Conics of every kind and Béziers of degree 4 to 9 keep within the error, each point checked against the bound the piece reports.
  • A circular conic keeps within the error of the circle.
  • A curve past the cap is refused: a 10 m quarter circle takes exactly 4096 cubics at 1e-8 mm and is refused at 1e-9.
  • Random curves, fuzzed.

On this head

7b21de6a7 over drawings cca77b176, local, Windows, --profile ci:

  • cargo fmt --check, xtask lists and xtask i18n --check pass;
  • clippy -D warnings over geom, doc, io, engine and ui-egui, all targets, passes;
  • the library tests of geom (379) and io (222), engine's drawing, paper and product tests (233) and sketch's paper and font tests (78): 912 passed, 0 failed.

Planted faults, on this commit over 49a3ba1c0 (the same code; the moves since changed only other lines): 7 faults, planted afresh for this run, all caught by a test, then the clean run passes. The first run missed one: the walk asking cubic_pieces for a coarser error than CURVE_ERROR_MM. A new check in slivers_and_radii_are_in_the_grids_own_steps now catches it. It flattens the walked ellipse and checks that every point is within the error of the true ellipse.

No full gate on this head.

What these moves changed: drawings moved from d5fd14135 to cca77b176 (#9254, #10713, #5349, #10515, #7745, #10516, #11350, #11047, #9708, #11352, #7430, #10969 with #9833 and #9840, #10926). The conflicts were only lines side by side: the report's new dashes_snapped field beside curve_cubics, the clip module beside cubic_pieces, and the grid's imports. what_cannot_be_drawn_is_refused's note now says an ellipse draws.

Integration status

Draft. #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-curves-4890-a3b branch 2 times, most recently from 341eb0a to c39154a Compare November 2, 2026 02:10
@CamWight CamWight changed the title Paper scene: ellipses, hyperbolas and higher Béziers as cubics on the grid (#4890 A3b) Drawing export A3b: ellipses, hyperbolas and other complex curves draw smoothly in every format (#4890) Nov 2, 2026
@CamWight
CamWight force-pushed the paper-curves-4890-a3b branch from c39154a to 4a29e90 Compare November 2, 2026 20:29
@CamWight
CamWight marked this pull request as ready for review November 2, 2026 20:32
@CamWight CamWight changed the title Drawing export A3b: ellipses, hyperbolas and other complex curves draw smoothly in every format (#4890) Drawing export: ellipses, hyperbolas and other complex curves draw smoothly in every format (#4890) Nov 3, 2026
… grid (tangency-labs#4890 A3b)

A conic of weight other than 1 and a Bézier above degree 3 become cubic Béziers within
1e-4 mm of the curve (`paper::cubic_pieces`), so the walk takes them and every writer
draws them with the cubics it already writes. Each piece's cubic has the curve's ends
and end tangents; its distance is bounded from the Bernstein form, not sampled: for a
Bézier, by the control points of its difference with the cubic raised to its degree;
for a conic, by Q·D − N over the denominator's least value. A piece over the error is
halved exactly and tried again, up to 4096 a curve and 1,000,000 a scene; past that the
curve is refused, never drawn coarser. The walk counts the cubics it made. Circular arcs
are left to the shared `paper::cubics` helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CamWight
CamWight force-pushed the paper-curves-4890-a3b branch from 4a29e90 to 7b21de6 Compare November 3, 2026 14:18
@bherbruck
bherbruck merged commit c5dab0b into tangency-labs:drawings Nov 3, 2026
27 of 28 checks passed
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