Repository navigation
Pick a wide polyline on the edges of its band, not only its centre line - #1196
marcoarnulfo wants to merge 1 commit into
Conversation
FredApps
left a comment
There was a problem hiding this comment.
ReviewerA — source-read COMMENT (not an approval)
I read the diff: a wide polyline is picked on the edges of its band and not only on its centre line. For a lightweight polyline that has a constant width or any vertex with a start or end width, the selection code builds the entity's render list (cadcraft_render::build_entities) and also hits the edges of the band's triangles (sides, ends, joints and diagonals), "as the reference app picks it". Picking what is drawn is what a user expects, and reusing the renderer's own triangles guarantees that what is picked is what is shown. Cost: build_entities for the single entity runs on every pick test for each wide polyline, so a drawing with thousands of wide polylines does that work per mouse move; test the polyline's bounding box (grown by the width) first, and cache. The diagonals of the triangulation are an implementation detail of the renderer: picking on a diagonal inside the band is a hit on empty-looking fill, so an AutoCAD user would see a selection where no line is drawn; the interior of a filled band should count as a hit for the same reason, and the edges of triangles inside it are redundant. I read the start of the change. I have not run it, and no exact-head CI result exists for this head. Nothing was run.
I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.
Status: waiting_author.
austin62jake
left a comment
There was a problem hiding this comment.
Approving. I merged it onto current main with ten other small PRs (#1273, #1266, #1265, #1263, #1254, #1247, #1233, #1196, #1114, #1445, #1591). The whole suite passes (3170 tests), and so do fmt and the web build. Clippy stops only on #1254's test.
Hitting a wide polyline on the edges of its drawn band, not only its centre line, is how AutoCAD picks it. The band is built only for the wide polylines being hit-tested, so ordinary picks pay nothing extra, and the tests cover sides, ends and joints.
Fixes #1176.
hit_polylinesmeasured a lightweight polyline only along its centre line, so the band a width draws was never hit: a click on its edge picked nothing, and a crossing box touching only the band didn't select it either. A wide polyline is now also hit on the edges of the triangles it is drawn with (taken from the same display list the renderer builds, as the pattern-hatch case already does), which gives the sides, ends, joints and diagonals you observed in the reference app, for constant and tapered widths. Window and fence selection use the same polylines, so they follow too; window "entirely inside" already used the band extents from #127.I kept the centre line pickable, so a click inside the band on it still selects the polyline, where the reference app would not. Dropping it for exact parity is a one-line change, happy to switch if you prefer.
One thing I haven't covered with a test: the issue says AutoCAD picks a wide polyline inside a block the same way. Block references go through the
Insertbranch, which reads the band's triangles as a polyline in sequence, so the start side of the band may still not pick there. Happy to add that here if you'd like.Validation:
select::wide_polyline_pick_tests(constant width from the issue's PLINE, and a 0→10 taper): fails on main (edge of the band at 25,5), passes here; also run alone with--test-threads=1cargo test -p cadcraft-engine --lib select::,cargo clippy -p cadcraft-engine --all-targets -- -D warnings,cargo fmt --all -- --check