Skip to content

Waterline: scallop-bounded in-between levels, ramped entries and island-by-island linking for ball end mills (#46) - #379

Merged
10-X-eng merged 15 commits into
stevecad:mainfrom
Wookie1:waterline-46-pr
Nov 22, 2026
Merged

10-X-eng merged 15 commits into
stevecad:mainfrom
Wookie1:waterline-46-pr

Conversation

@Wookie1

@Wookie1 Wookie1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #46. Planning time remains an open acceptance criterion.

Final behavior at 6c06b47

Ball waterlines add scallop-bounded intermediate levels, group contours by island, and link levels only when the emitted route passes the part, machining-limit and live-stock checks. The ramp uses the operation's plunge feed unless the caller explicitly supplies a ramp feed. Open ramps honor a declared minimum reversal span.

A stock cell can intersect the swept ball even when its centre is outside the tool radius. The added Rust regression puts over 1 mm of stock into that overlap. The previous check returned zero. The link proof now covers the full cell. It bounds penetration by the level gap or by what the lower lap is guaranteed to meet. Where the finishing ball reaches at least as deep at the same XY, the comparison holds for every possible stock height there. Cells that cannot establish the bound are refused. Side entries also use the whole-cell check.

The sloped-wall fixture previously required at most one entry per four runs. That quota depended on centre sampling. The fixture now checks 18 proven links, 12 entries and at least six stock refusals across its 30 runs. The independent test comparing links to the lower lap still passes, as do the active cutting limits, ramp-angle, scallop and material checks.

Release workload Moves Retracts Modeled cycle, exact stop
Waterline 251 1 77.957 s
Waterline dense 1,967 1 346.743 s
Steep-and-shallow, steep operation 2,532 13 344.046 s

All three programs posted. Each retained its previous material bounds, with zero certain overcut. The dense baseline on main was 476.247 s and 56 retracts. The smaller waterline takes longer than main's 34.047 s. The expected paths and modeled times were regenerated from three sequential release runs per workload.

On Linux, 10 Rust unit tests and 45 waterline-related integration tests passed, along with seven Python waterline/ramp tests, nine package tests, formatting and workspace Clippy. All 64 release workloads matched their toolpath expectations. The PR checks cover the pushed commit and the merge queue tests the integration with main.

Original implementation and measurements at d0c30e2, before the whole-cell proof and entry-feed fix

Waterline: scallop-bounded in-between levels, ramped entries and island-by-island linking for ball end mills (#46)

What changes

1. In-between levels keep the scallop of a vertical wall (ball end mills).
On a slope at contact angle t, levels stepdown_mm apart are stepdown_mm / sin(t) apart along the surface, so shallow areas get a much taller scallop than a wall. A ball waterline now adds sub-levels between two main levels wherever the spacing along the surface exceeds what the vertical-wall scallop allows.

  • The bound: scallop_mm = R - sqrt(R^2 - stepdown_mm^2/4) + contour_error_mm.
  • The widest allowed spacing: D = 2 sqrt(R^2 - (R - scallop_mm)^2).
  • Sub-levels halve the gap (depth 1, 2, ...). Each keeps only the parts of the parent contour where sin(t) < P / D - 1e-9, with P the parent level spacing.
  • A level is added only where it lowers the scallop by more than contour_error_mm, so a short last gap, or a stepdown already fine enough, adds none.
  • An exactly vertical wall never gets a sub-level.
  • In-between rings whose gaps are all under 4 R are cut whole rather than as fragments, unless slope or region limits apply.
  • The report adds scallop_levels and scallop_from_deg, the contact angle below which the bound is not claimed. Flat and bull-nose cutters are unchanged and report neither.

2. Entries never plunge into stock.

  • A loop is entered from the side only where the lead onto the wall is pure air.
  • If no such point exists beside its start, a closed loop moves its start to the first clear point along itself (moved_entries).
  • Otherwise the ball plunges in air to the stock top at the loop start, then ramps down along the loop. An open run goes along itself and back (helical_entries).
  • Where no entry exists, the operation is refused with the level and XY: rough or rest-rough there first.

3. Island by island, levels linked by ramps.

  • Every level's contours are grouped into stacks (connected wall regions; a merge starts a new stack). Each stack is cut top to bottom before the tool moves to the next island.
  • If a proof refuses that order (the shank or holder would meet stock a neighbour still carries), the stack is finished last, level by level (stacks_level_ordered).
  • Within a stack, a closed loop below a closed loop is reached without a retract:
    • a short link at the upper level to the nearest point of the lower loop;
    • a ramp down along that loop;
    • the whole loop cut flat from the end of the ramp, so the flat lap passes over the entire ramp again (ramp_links).
  • A link is taken only if it is proven clear of the part and meets no more stock than the larger of:
    • the level gap;
    • what the lower loop's own cut meets where the link arrives.
  • Refused links are counted by reason: links_refused_stock, links_refused_link_clearance, links_refused_ramp_clearance.
  • Ramp and link splits snap onto contour vertices (0.005 mm), so a posted program at 3 decimals keeps every move (no zero-length lines).

3b. Slope- and region-limited runs are linked too.

  • Limits cut a contour into open runs (on steep-and-shallow, the two gable ends of one roof). Each run used to be entered after its own retract.
  • A run is now linked like a loop: from the end of the run just cut to the start of the next, at the upper level; down along the run at the ramp angle to half the gap and back to its start (no ramp at the same level); then the run cut.
  • Runs of one wall all run the same way, so the next starts at the far end and a straight link would cross the part. The link then goes back along the run just cut, at its level, to its point nearest the next start, then straight to it.
  • Same proofs and stock bound as the loop links.
  • Order: in a stack, the next piece is the nearest ready one. A piece may go before pieces it is more than two cutter radii from (bounding boxes), unless one of them is a closed loop. So separate walls of one contour are cut one after the other, each top to bottom, instead of switching walls at every level. Order only; every move keeps its proofs on the live stock.
  • On in-between levels under limits, the scallop rule's fragments within one run the limits allow are cut as one piece across gaps under 4 R; the gaps are inside the limits.
  • Open-run descents (entries and links) now use the ramp angle (out and back over gap / (2 tan angle), at most the run) instead of running the whole run twice.

4. Default ramp: 3 degrees at the cutting feed.

  • Without entry, every ramp (entry or level link) descends at no more than 3 degrees, at feed_mm_min. A declared or default angle is a maximum: where one lap of a loop (or one out-and-back on a run) is too short, the ramp takes as many laps or passes as the angle needs, each descending an equal share; past 1000 it is refused by name. A split onto a loop vertex only ever lengthens a ramp, so a tiny descent never collapses to zero length.
  • I chose the cutting feed, not the plunge feed: a 3 degree ramp along the contour cuts no deeper than the flat lap that follows it, so it needs no slower feed. A plunge-feed ramp would only add cycle time.
  • entry=RampEntry(angle_deg, feed_mm_min=...) still sets both. Its feed defaults to the plunge feed, as in every other operation.
  • Only RampEntry is accepted on a ball waterline.

5. Unroughed-stock warning.

  • An entry that reaches its level in stock more than three stepdown_mm deep is counted in deep_stock_entries, and the simulation warns: "... Rough or rest-rough first".
  • A link counts when it goes more than three stepdown_mm beyond the level gap it descends.
  • The rule: a rough in steps up to three times the finishing stepdown, plus its allowance, leaves no more than that on a slope, so it does not warn. A raw blank, or a gap the rough tool could not reach, does. The margin is tied to the declared stepdown_mm; no new switches.
  • On the dome demo (3 mm rough steps, 1 mm waterline) this leaves 3 warnings, all real unroughed stock the 1/2 in rough tool could not reach: the link into Z12 ends at (49.6, 33.9) in the 4.6 mm gap between dome and boss; the link into Z11 leaves that gap; the link into Z13 comes from (74.4, 32.0) in the 8 mm strip east of the boss. A one-stepdown margin warned on 13 loops, 10 of them the rough's normal 3 mm steps.
  • No new switches. The old wall_entries report field and its warning are gone, since a loop is no longer entered on the wall.

6. Removed dead code. ProfileMotion.helix_entries, its Phase::Cut branch and loop_closes in src/profiles.rs; src/profiles.rs is back to its state before this branch. Waterline uses its own loop_is_closed.

7. Links and snapped moves are proven against the machining limits.

  • Every link segment, the glide-back route, every ramp (link and entry) and a cut whose start a sub-0.005 mm link snapped is checked with the part clearance and the limits' allows_curve(..., cutting=true). Leads and ramps are not checked by the run's LinkGuard (rapids and links only), so the emitter checks them; where no allowed route exists the piece is entered after a retract.
  • Bridged fragments are placed in order along the run the limits allow, so a run that closes on itself (a region limit admitting the whole ring) is never bridged by a chord back to its start.
  • A reorder the reach check refuses is undone before the stack is deferred, so the level-order fallback sees the stack's pieces top-down.
  • A side entry that moves the loop's start snaps the candidate onto the loop vertex first, so the part, limit and stock checks prove the lead actually emitted; the final check before emitting covers side leads as well as ramps.
  • No ramp is steeper than the declared or default angle, on short runs and loops too (see 4), and no ramp collapses to zero length (a tiny final level gap used to give a NaN coordinate).

Known limit of the link stock measure. The link stock measure uses stock-cell centres, so a cell's material can be under-counted by about 0.009 mm. This affects tool load only, never the part: every move carries the part-clearance proof.

Cycle-time cost (bench, waterline and waterline-dense)

Simulated cycle time (exact stop), moves and retracts. All runs are on the benchmark's roughed blanks.

waterline waterline-dense
main (4ddb3c4) 34.047 s, 116 moves, 4 retracts 476.247 s, 1903 moves, 56 retracts
scallop levels and entries (bb67409) 50.072 s, 184 moves, 6 retracts 476.247 s, 1903 moves, 56 retracts
linking, ramps at one lap and plunge feed (82ac338) 151.282 s, 338 moves, 1 retract 1431.660 s, 3526 moves, 1 retract
this PR (3 degree default ramp at cut feed) 45.250 s, 251 moves, 1 retract 314.384 s, 1967 moves, 1 retract
  • steep-and-shallow (the Waterline half, finish-steep, with slope limits from 25 degrees) also changes. Its 25 degree limit cuts every contour into runs on the two gable ends, and the in-between levels add 9 sub-levels on the roof edges:
    • main: 176.078 s, 892 moves, 23 retracts (one entry per run);
    • with the in-between levels, each run still entered after a retract: 271.792 s, 1346 moves, 48 retracts;
    • this PR (runs linked wall by wall, see 3b; every ramp within 3 degrees): 201.628 s, 1995 moves, 13 retracts;
    • finish-shallow (Parallel, after it): 157.827 → 158.113 s, the same 804 moves;
    • whole workload: 333.905 → 359.741 s; leftover and overcut unchanged ([0.0, 149.82] and [0.0, 151.979] mm³).
    • The remaining +25.6 s on finish-steep is the extra cutting of the in-between levels (1487.1 vs 1074.5 mm of cut) and ramps that keep the 3 degree angle on short runs.
  • Leftover and overcut are identical to the 82ac338 run on both waterline workloads. The possible over-cut bound on waterline rises from main's 91.427 to 95.052 mm³ (certain over-cut stays 0.0).
    • waterline: leftover [33.219, 249.994] mm³, overcut [0.0, 95.052] mm³.
    • waterline-dense: leftover [33.219, 244.694] mm³, overcut [0.0, 102.537] mm³.
  • Neither workload has a post error.
  • Planning (engine) time on this Mac rises from 0.026 s to 0.049 s on waterline and from 0.197 s to 0.640 s on waterline-dense (main measured at 4ddb3c4 on the same machine).
  • What the costs come from:
    • On waterline, the remaining +11 s over main is the in-between levels on its tapered island. That is the price of the bounded scallop.
    • On waterline-dense, linking removes 55 of 56 retracts and the run is 34 % faster than main.
    • With one-lap ramps at the plunge feed, the same linking tripled the cycle. The 3 degree default is what makes it a win.

Benchmark expectations

Updated in this PR, as AGENTS.md asks ("Update only intentionally changed workload expectations from measurements and explain the differences in the PR"): bench/expectations/waterline.json, waterline-dense.json and steep-and-shallow.json. Each was written by bench/expectations.py from a release run of bench/run.py --only <workload>. Every other workload matches its expectation in a full release run. The figures above are those runs.

Changed existing test asserts

Rust, tests/waterline.rs:

  • cad_frustum_levels_stream_actual_stock_and_preserve_every_target_cell: levels [7, 5, 3, 2.5] → [8, 7, 6, 5, 4, 3, 2.5]. The 70 degree flanks get depth-1 in-between levels; the short last gap gets none.
  • waterline_heights_keep_rapids_above_feed_height_and_end_at_clearance: "every plunge starts at the feed height" now applies to vertical plunges only. A ramp is a travelling plunge along the contour.
  • every_entry_plunge_ends_at_or_above_the_stock_under_the_ball:
    • It checks vertical plunges only.
    • plunges > 0 && beside > 0 → plunges > 0.
    • wall_entries == 0 → moved_entries == 0 and helical_entries >= 1.
  • a_loop_with_no_stock_free_entry_is_reported_not_hidden:
    • The fixture's plate now runs at a 1 mm stepdown from Z3.5 (levels Z3.5, Z2.5) instead of the fixture's 2 mm from Z8, so the raw blank stands 6.5 mm (more than three stepdowns) above the first level and the roughed band 2.8 mm (a rough in 3 mm steps).
    • Raw stock: wall_entries > 0 → moved_entries == 0, helical_entries >= 1, deep_stock_entries >= 1.
    • Roughed stock: wall_entries == 0 → moved_entries == 0, helical_entries >= 1, deep_stock_entries == 0.
    • It fails if the raw blank stops warning, and with the old one-stepdown margin (roughed: deep_stock_entries 1, expected 0).

Python:

  • test_waterline.py, frustum levels: {8, 6, 4, 2.5} → {8, 7, 6, 5, 4, 2.5} (in-between levels, as above).
  • test_waterline.py: test_a_loop_entered_on_the_wall_is_warned_about_and_a_roughed_blank_is_not → test_a_raw_blank_enters_on_a_ramp_and_warns_to_rough_first_a_roughed_blank_does_not.
    • Raw blank, before: wall_entries > 0 and one "on the wall" warning.
    • Raw blank, now: run at a 1 mm stepdown (the example job's is 2 mm, which leaves its raw blank under three stepdowns above some levels); no moved_entries or wall_entries; helical_entries > 0; deep_stock_entries > 0; exactly one warning containing "more than three stepdowns deep" and "Rough or rest-rough first".
    • Roughed blank, before: no warning.
    • Roughed blank, now: no moved_entries, helical_entries == 1, ramp_links > 0, no deep_stock_entries, and no warning.
  • test_ramp.py, test_ramp_descends_along_the_contours_without_gouging: the "some cut descends" check now also counts travelling plunge moves. A ball's ramps link its levels as plunge moves at the ramp feed, so for the ball subtest no cut move descends any more. The flat-cutter subtest is unchanged.

New tests cover:

  • the scallop bound, vertical walls, sloped flanks, fine stepdowns, slope limits and ramp finishing;
  • side, moved and ramped entries, including open runs;
  • island-by-island order and the level-order fallback;
  • ramp links that the next lap recuts;
  • ramps on short runs that keep the 3 degree angle, checked on every travelling plunge (ramps_on_short_runs_keep_the_ramp_angle), and a 0.0002 mm ramp descent that streams finite moves (a_tiny_ramp_descent_streams_finite_moves);
  • a moved side entry whose proven sample and snapped vertex differ by 0.003 mm, with stock within the ball radius of the vertex only (a_moved_side_entry_proves_the_lead_it_emits);
  • links that stay out of an avoid area between two runs (links_stay_out_of_avoid_areas_between_runs) and bridged fragments that follow a run closing at its seam (bridged_fragments_follow_a_run_that_closes_at_its_seam);
  • slope-limited walls cut wall by wall and linked (slope_limited_walls_are_cut_wall_by_wall_and_linked: 30 runs, 24 linked, 6 entries; without the fix all 36 runs are entries);
  • the link stock bound, measured independently against the lap's own cut;
  • stream continuity and posting at 3 decimals.

Tested

macOS arm64 only, release builds, at d0c30e2 (this branch rebased onto main b636cc4). Linux and Windows are left to CI.

  • cargo test --release --workspace --all-features --lib --tests: 1147 passed, 5 ignored. cargo test --release --doc: 1 passed.
  • PYTHONPATH=python python -m unittest discover -s python/tests: 1087 tests, OK, 19 skipped. This includes test_package.py, which runs both examples with and without --accept-unchecked-machine.
  • Benchmark tests (bench/test_*.py): OK. A full bench/run.py run compared with bench/expectations: every toolpath matches. The figures above come from that run.
  • cargo fmt --check, ruff check and ruff format --check: clean.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean except two needless_range_loop errors in src/surface/spline_bounds.rs. This PR does not touch that file, and main gives the same errors under the local rustc 1.99.1.

A real-part check (dome and filleted boss, a 3/16 in ball after a 3 mm-step rough, a declared 3 degree ramp):

  • 48 pieces, 3 lifts (the first entry and two island changes), 45 level links;
  • 0 vertical plunges into stock;
  • it exports (G-code 359,889 bytes), waterline 8596 moves, 383.6 s;
  • it warns on 3 loops, all unroughed stock the 1/2 in rough tool could not reach (the dome-boss gap and the 8 mm strip east of the boss; see 5).

…, skipping levels that gain less than the contour error (stevecad#46)
… prints (stevecad#46)

Waterline no longer sets ProfileMotion.helix_entries (its entries ramp along
the loop in its own emitter), so the field, its Phase::Cut branch and
loop_closes go; waterline uses its own loop_is_closed.
…roughed stock (stevecad#46)

Without a declared RampEntry each level is reached by a 3 degree ramp at the
cutting feed instead of one lap at the plunge feed. Entry ramps and level
links that meet stock more than one stepdown deep (for a link, beyond the
level gap) are counted in the report (deep_stock_entries) and the simulation
warns to rough or rest-rough first.
… for each (stevecad#46)

The runs slope or region limits cut a contour into are linked like closed
loops: to the next run's start at the upper level (back along the run just
cut where a straight link would cross the part), down along the run at the
ramp angle and back, then cut. Pieces of a stack more than two cutter radii
from the pieces they skip are taken nearest first, so separate walls are cut
one after the other, each top to bottom. On in-between levels under limits,
scallop fragments within one allowed run bridge across gaps under 4 R.
steep-and-shallow finish-steep: 48 -> 13 retracts, 271.8 -> 197.7 s.
…vecad#46)

A rough in steps up to three times the finishing stepdown, plus its
allowance, no longer warns; a raw blank or a gap the rough tool could not
reach still does. The raw-blank tests use a 1 mm stepdown so their blanks
stand more than three stepdowns above the levels.
…limits (stevecad#46)

Every link segment, the glide-back route, every ramp and a cut whose start
a sub-0.005 mm link snapped is checked against the part and the limits
(leads and ramps are not checked by LinkGuard); without an allowed route the
piece is entered after a retract. Bridged fragments are placed in order
along their run, so a run closing at its seam is not bridged by a chord. A
reorder the reach check refuses is undone before the stack is deferred.
…mitted (stevecad#46)

A ramp too long for one lap (or one out-and-back on a run) takes as many
laps or passes as the angle needs, refused by name past 1000; a split onto
a vertex only lengthens a ramp, so a tiny descent no longer collapses to a
zero-length ramp with a NaN coordinate. A moved side entry snaps its
candidate onto the vertex before it is checked, and the final check covers
side leads too.
@Wookie1 Wookie1 self-assigned this Nov 22, 2026

@10-X-eng 10-X-eng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The side-entry air check can accept a lead that cuts stock. In stock_met, a cell is skipped when its centre is outside the swept ball radius, even if its near edge is inside. For a 1 mm radius and a cell spanning perpendicular distances 0.9–1.3 mm from the interior of a straight lead, the centre distance is 1.1 mm. With the tip at Z0 the ball reaches Z0.564 at the near edge. Stock up to Z1 there gives 0.436 mm of interference and the current check counts zero. Part clearance cannot establish air clearance on uncut stock. The same estimate controls link acceptance. Please use a conservative whole-cell or committed-sweep proof for the emitted lead and link. Add a regression with the cell centre outside the sweep, and check the comparison against the finishing lap independently.

The measured planning times also go from 0.026 to 0.049 s and 0.197 to 0.640 s. The dense cycle improvement is real, but #46 explicitly requires lower planning time. Please keep #46 open if that acceptance criterion is deferred.

@10-X-eng

Copy link
Copy Markdown
Contributor

Reproduced the missed stock in a native regression. A 2 mm ball passes 1.9 mm from the near edge of an elevated cell. It intersects more than 1 mm of solid stock, and the current check returns 0 mm. I’m fixing this on the PR branch and checking the resulting entry, link and posted paths.

@10-X-eng 10-X-eng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cell-edge regression now catches the original missed contact. The whole-cell proof and finishing-lap comparison pass the independent geometry checks. The three release workloads post with unchanged material bounds. The planning-time work remains open in #46.

@10-X-eng
10-X-eng enabled auto-merge November 22, 2026 21:32
@10-X-eng
10-X-eng added this pull request to the merge queue Nov 22, 2026
Merged via the queue into stevecad:main with commit 4157d12 Nov 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants