Skip to content

TRIM highlights only the piece a click removes, EXTEND the extended object - #1126

Closed
marcoarnulfo wants to merge 2 commits into
storytold:mainfrom
marcoarnulfo:fix/trim-hover-preview
Closed

marcoarnulfo wants to merge 2 commits into
storytold:mainfrom
marcoarnulfo:fix/trim-hover-preview

Conversation

@marcoarnulfo

Copy link
Copy Markdown
Contributor

Fixes #1118.

Stacked on #1092 (Shift+click does the other one in TRIM/EXTEND): until that one is merged, this diff also shows its commit. The commit for this issue is the last one.

At "Select object to trim", the canvas used the generic rollover highlight, which always lights up the whole object under the cursor, so you couldn't see which piece a click would remove. The trim geometry in modify.rs now has a pure step, trimmed, that returns what a pick keeps and what it removes without touching the drawing. trim uses it to replace the object, and TRIM's new Interactive::highlight uses it to tell the canvas which part to highlight. With no cutting edge in Quick mode (the click erases the object), the whole object is highlighted, as before. EXTEND works the same way: extend got a pure extended step, and the highlight shows the object as the click leaves it, extension included. With Shift held, the highlight follows the command the click will run (#1092). Lines, arcs, circles, polylines, ellipses and splines (open and closed) all go through the code the click itself uses.

On the canvas side, when the command returns a part, the hover look is drawn on that part instead of on the whole object. Working the part out means running the trim against every cutting edge (every object in Quick mode), so it is cached with the rest of the hover state: it is computed again only when the object, the cursor, Shift, the zoom, the drawing or the prompt changes, never on frames where the cursor is at rest. I kept the change to the hover code since #1061 is reorganising canvas.rs; happy to rebase onto it if it lands first.

In Standard mode, picking an object that no edge crosses still highlights the whole object, as it did before: nothing would change there, so I left it alone. Happy to switch if you'd rather show nothing in that case.

Validation:

  • trim_extend_options::trim_highlights_only_the_piece_a_pick_removes: fails on main (the highlight is None, i.e. the whole object, where the piece (10,0)-(15,0) is expected), passes here
  • canvas::trim_highlight_tests::shift_shows_what_the_click_does: with Shift held in TRIM the highlight is the line extended to the boundary, not the line the click without Shift would erase
  • canvas::trim_highlight_tests::highlight_is_computed_once_while_the_cursor_rests: five frames with the cursor at rest compute the part once (five times without the cache)
  • cargo test -p cadcraft-engine --test trim_extend_options --test trim_closed_polyline --test modify_curves --test fillet_chamfer, cargo test -p cadcraft-engine --lib modify, cargo test -p cadcraft-ui-egui --lib trim_
  • cargo clippy -p cadcraft-engine -p cadcraft-ui-egui --all-targets -- -D warnings, cargo fmt --all -- --check
  • (macOS, Apple silicon)

@tanish2k09

Copy link
Copy Markdown
Member

The part highlight for TRIM and EXTEND is on main now through #3382 (landed in #3471), which built on this PR's idea and credits it. Closing this one as superseded; thank you for the first take.

@tanish2k09 tanish2k09 closed this Nov 25, 2026
grinmaul pushed a commit to grinmaul/cadcraft that referenced this pull request Nov 25, 2026
…ixes storytold#1118)

At TRIM's "Select object to trim" prompt the rollover highlight showed the whole object under
the cursor. It now shows only the piece a click there removes, and the whole object only when
Quick mode would erase it; EXTEND shows the stretch a click adds.

- modify/trim.rs: `trimmed` and `extended` work a trim or an extend out without changing the
  drawing; `trim` and `extend` apply them. The preview and the click share that code, so they
  can't disagree.
- prompt.rs, guard.rs, session: `Interactive::highlight` (under the panic guard) and
  `Session::highlight`: what the rollover highlight shows of the object under the cursor.
- trimextend.rs: TRIM/EXTEND's highlight is the object less the pieces a trim keeps (or the
  object as extended less the object), split where a piece ends, so it works the same for lines,
  arcs, circles, polylines, ellipses and splines. The edges of the object under the cursor are
  gathered once while the drawing and the edges stay the same.
- canvas: the highlighted part replaces the whole-object highlight, worked out again only when the
  object, the cursor, the zoom, the drawing or the prompt changes.

Tests: engine/tests/it/trim_highlight.rs (the piece between and past two edges, Quick-mode
erase, the drawing and undo untouched, the highlight matching what a click removes for seven
kinds of object, EXTEND, other prompts and locked layers, edges gathered again after a trim) and
a canvas test (the part is computed once while the cursor rests).

Follows the approach of storytold#1126.

Co-authored-by: Marco Arnulfo <103679419+marcoarnulfo@users.noreply.github.com>
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.

feature request trim highlight

2 participants