Skip to content

Adds Geometry Cleanup to find and fix ends that almost meet - #3603

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:geometry-cleanup
Nov 24, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:geometry-cleanup

Conversation

@travisjhughes

Copy link
Copy Markdown
Contributor

Change summary

Adds Geometry Cleanup (GEOMETRYCLEANUPOPEN, GEOMETRYCLEANUPCLOSE), as in AutoCAD 2027: a palette that scans the selected objects for ends that almost meet other geometry and repairs each error the user picks. This first part finds three error types: Gap, Overshoot and Undershoot.

This is the first of several pull requests for Geometry Cleanup. The later ones add the settings dialog (a tolerance for each error type, the proposed tolerance, .gcs files), the Absolute Angle and Relative Angle errors, markers in the drawing with a live preview of a repair, and Keep as designed. They are listed under "Not covered" below.

What specifically changed

  • crates/ocs_geom/src/geom2d/cleanup.rs: the scan. For lines, arcs and polylines it finds:

    • Gap: an end almost meets the end of another curve (or the other end of the same polyline).
    • Overshoot: an end runs a little past a curve that it crosses.
    • Undershoot: an end stops a little short of a curve, along its own line or circle.

    An end that meets other geometry is not an error. An end with more than one candidate is reported once, as the nearest one. A grid keeps the scan from testing every pair of curves. proposed_tolerance gives 1% of the mean length of the lines and polyline segments, and at least 0.0001.

  • src/modules/manage/geometry_cleanup.rs: the objects the scan reads (lines, arcs and LWPOLYLINEs on the world XY plane, in model space, on layers that are not locked or frozen), the repairs, the Select Objects prompt and the ribbon tool (Manage > Cleanup, beside OVERKILL).

  • src/ui/window/geometry_cleanup.rs: the palette. Select Objects, Rescan, the tolerance, "Remaining Errors" and a foldable list for each error type. Each row has the XY location of the error and, at its end, the buttons of its repairs, each with a tooltip that says what it changes. A click on a row zooms to the error and selects its objects. After a repair, the next row is picked and zoomed to (the row above it at the end of the list), so the user can work down the list.

  • src/app/commands/geometry_cleanup.rs: the commands and the palette's messages. While the palette is open, it scans its objects again after each change of the drawing (an edit, an undo), so the list stays true; not while a command or a grip edit runs, which change the drawing on each move. The picked error stays picked if it is still there.

  • The repairs, each one undo step, after which the palette scans again:

    • Overshoot: Trim cuts the end back to the crossing.
    • Undershoot: Extend runs the end on along its line or circle.
    • Gap: Stretch moves the end onto the other end (as a drag of its grip does), Move moves the whole object, and Extend takes both ends to the point where their lines cross, when both ends are straight and that point is within the tolerance of each.
  • The dock panel, the message, the labels in src/locale_catalog.rs and in every locale (with the English text).

Why

AutoCAD 2027 added Geometry Cleanup. A drawing with ends that almost meet does not hatch, join or offset as the user expects, and the errors are too small to see. OVERKILL removes duplicates and GAPCHECK lists end-to-end gaps, but nothing repaired overshoots, undershoots or gaps.

The help pages name the repairs but not what each one does to the geometry; the rules above are this pull request's reading of them. AutoCAD shows the repairs in a menu on the error and in the drawing; here they are buttons on the error's row until the markers come. With no settings dialog yet, the tolerance is the proposed one, from all the supported objects in model space. A rescan keeps the tolerance that the scan had.

Testing

crates/ocs_geom/src/geom2d/cleanup.rs (23 tests): each error type, ends that meet or are far apart, a short line attached at its other end (not an overshoot), both ends of an arc (counter-clockwise, and clockwise in a polyline) reaching along their circle, an arc that overshoots, a nearly closed polyline, a closed polyline as a target, a polyline's last segment, the corner of an oblique gap and a corner too far away, a large tolerance, a gap across the edge of a search cell, the nearest error winning, the proposed tolerance (with and without arcs), and a tolerance at or below the weld or not finite.

src/app/commands/geometry_cleanup_tests.rs (27 tests): the palette opens and closes, and scans the objects selected before it opens; a scan lists one Gap, one Overshoot and one Undershoot; each repair (Trim, Extend, Stretch, Move, Extend at a corner) gives the expected geometry, and Undo takes it back in one step; an arc and a polyline arc end keep their circle; a locked layer, a line off the XY plane, and an arc or polyline with another normal or an elevation are not scanned; a two-point polyline extends; Stretch moves the grip at the repaired end; a repair that the error does not offer changes nothing; a repair after the drawing changed changes nothing; Select Objects scans the selection; picking an error selects its objects; the open palette lists an error again after its repair is undone, scans again after an edit and keeps the picked error, waits for a running command, and a closed palette does not scan; a repair picks the next row, skips a folded type, and a repair that fails keeps the pick; a second fold unfolds a type.

cargo test --workspace --locked --no-fail-fast: 8139 passed, 0 failed, 48 ignored (50 new).

Not covered

  • Absolute Angle and Relative Angle errors.
  • The settings dialog: error types, a tolerance for each, the proposed tolerance column, and .gcs settings files.
  • Markers in the drawing, a repair menu on them, and a live preview of a repair on hover.
  • Keep as designed (ignored errors in the user profile).
  • GEOMETRYCLEANUPSTATE, GEOMETRYCLEANUPZOOMPAN and review mode (GEOMETRYERRORREVIEWCLOSE).
  • Elliptical arcs, the old-style POLYLINE types and splines.

Impact to Contributors

A new dock panel (PanelId::GeometryCleanup) and a new message (Message::GeometryCleanup).

🤖 Generated with Claude Code

GEOMETRYCLEANUPOPEN opens a palette that scans the selected lines,
arcs and polylines for three error types: Gap, Overshoot and
Undershoot. Each row of the list has the buttons of its repairs:
Trim, Extend, Stretch, Move, and Extend to a corner. Each repair is
one undo step. While the palette is open, it scans again after each
change of the drawing, and after a repair it picks the next row.

This is the first part of Geometry Cleanup. The settings dialog, the
angle errors, the markers and Keep as designed come later.

Co-Authored-By: Claude
Tests the scan of each error type, arcs and polylines, corners, the
search grid and the proposed tolerance. Tests each repair and its
undo, the objects that are not read, the automatic rescan, and the
pick of the next row.

Co-Authored-By: Claude
@HakanSeven12
HakanSeven12 merged commit a97593a into HakanSeven12:main Nov 24, 2026
6 of 8 checks passed
@travisjhughes
travisjhughes deleted the geometry-cleanup branch November 24, 2026 19:41
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