Skip to content

Adds Geometry Cleanup settings with a tolerance for each error type - #3618

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

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

Conversation

@travisjhughes

Copy link
Copy Markdown
Contributor

Change summary

Adds the Geometry Cleanup Settings dialog, as in AutoCAD 2027: the error types to find, a tolerance for each, the proposed tolerance, and Import and Export of .gcs settings files. The settings are kept in the user profile and apply to all drawings.

This is the second pull request for Geometry Cleanup, after #3603.

What specifically changed

  • crates/ocs_geom/src/geom2d/cleanup.rs: end_errors takes a tolerance for each error type (Tolerances; None for a type that is not scanned). The search reaches as far as the largest tolerance, and each candidate is held to the tolerance of its own type before the nearest error of each end is picked. (A filter after the pick would lose errors: an end with a 0.5 gap and a 0.6 undershoot, with a gap tolerance of 0.2, would report nothing.)
  • src/modules/manage/geometry_cleanup_settings.rs: the settings, in the form of a .gcs file: {"tolerances": [{"name": "gap", "subName": "", "tolerance": 0.4}, ...]}. A type that is not in the list is not scanned. A tolerance less than 0.0001 becomes 0.0001, and a tolerance has at most 6 decimals. The angle types (absolute-angle, relative-angle) are kept and written back, but not shown or scanned until the angle errors come.
  • src/ui/window/geometry_cleanup_settings.rs: the dialog. Import settings (the file and Browse), a row for each error type with its tolerance, the proposed tolerance (a click puts it in the box) and ✕ (remove), "Add error type" for a removed type, and Cancel, Export and Scan (Rescan after the first scan). Scan and Export are disabled while a box does not hold a number.
  • src/ui/window/geometry_cleanup.rs: a Settings button in the palette toolbar. Each type's category bar shows its tolerance ("Gap: 3 (0.4)") in place of the one "Tolerance:" line.
  • src/app/commands/geometry_cleanup.rs: the dialog's messages. Scan saves the settings, closes the dialog and scans: the objects of the palette's scan again, or all the supported objects in model space when the palette has no scan of the drawing.
  • src/app/config.rs: geometry_cleanup, the saved settings. None until the user saves settings; each drawing then uses its proposed tolerance, as before.
  • src/app/commands/geometry_cleanup_tests.rs: corrects a comment from Adds Geometry Cleanup to find and fix ends that almost meet #3603. The proposed tolerance of the test drawing is 0.5198 (1% of a mean length of 51.98), not 0.64.
  • The new labels in src/locale_catalog.rs and in every locale (with the English text); the label "Tolerance: {}" is removed.

Why

AutoCAD's Geometry Cleanup has this dialog, and #3603 had none: it used the proposed tolerance for all three types.

The .gcs format is not published. This pull request reads and writes the format of a file exported from AutoCAD 2027, and its tests use that file's text. That a removed type is left out of the file is this pull request's reading of the format: the file has no other place for it.

A .gcs file that cannot be read (not JSON, no tolerances, a negative tolerance, a tolerance too large to keep) gives an error on the command line and changes nothing. In the user profile, Geometry Cleanup settings that cannot be read are dropped; the rest of the profile loads as before.

Testing

crates/ocs_geom/src/geom2d/cleanup.rs (3 new tests): a type with no tolerance is not reported; each type uses its own tolerance (the case above); the corner of a gap is held to the gap tolerance.

src/modules/manage/geometry_cleanup_settings/tests.rs (8 tests): AutoCAD's file gives its tolerances and keeps its angle rows; a file written and read again is the same; a type left out of the file is not scanned; files that cannot be used are errors; the minimum tolerance (also for a tolerance of 0) and the 6 decimals; a tolerance too large to keep is an error; a type added back goes before the angle rows.

src/app/commands/geometry_cleanup_tests.rs (18 new tests): the settings are kept in the user profile, a profile from before has none, and settings in the profile that cannot be read are dropped without the rest of the profile; the proposed tolerance has at most 6 decimals; a scan uses the saved tolerance of each type, and the proposed one when none is saved; the dialog opens with the proposed tolerances; Scan saves and scans model space, rescans the objects of the last scan, waits for boxes that hold numbers (and for a tolerance that is not too large to keep), finds nothing with no types, and scans the current drawing when the last scan is of another tab; Cancel changes nothing; the proposed tolerance goes in the box, a typed tolerance changes only its own type, and a removed type is added back; Import reads AutoCAD's file and Export writes its angle rows back; a file that cannot be read changes nothing.

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

Not covered

  • The Absolute Angle and Relative Angle errors. Their rows are kept, not used.
  • Markers in the drawing and a live preview of a repair.
  • Keep as designed.
  • GEOMETRYCLEANUPSTATE, GEOMETRYCLEANUPZOOMPAN and review mode.
  • Elliptical arcs, the old-style POLYLINE types and splines.
  • The file name in "Import settings" is kept for the session only: after a restart it shows "(default)" while the saved values apply.
  • A .gcs field that OCS does not know is not kept on Import and Export, and a file that starts with a byte order mark is not read. The file from AutoCAD 2027 has neither.

Impact to Contributors

end_errors takes Tolerances in place of one f64. A new ModalKind::GeometryCleanupSettings and a new AppConfig field.

🤖 Generated with Claude Code

A Settings button in the Geometry Cleanup palette opens the Geometry
Cleanup Settings dialog, as in AutoCAD 2027. It sets the error types to
find and a tolerance for each, shows the proposed tolerance, and imports
and exports AutoCAD .gcs files. Scan saves the settings in the user
profile, closes the dialog and scans. Until the user saves settings,
each drawing uses its proposed tolerance, as before.

The scan holds each candidate to the tolerance of its own type before
it picks the nearest error of each end. The angle rows of a .gcs file
are kept and written back, but not used yet.

Co-Authored-By: Claude
Tests a tolerance for each error type in the scan, the gap corner held
to the gap tolerance, the .gcs file with a file from AutoCAD 2027, the
settings in the user profile, and the Settings dialog: Scan, Cancel,
Import, Export, removed and added types, values that cannot be kept,
and a scan from another drawing tab. Also corrects the proposed
tolerance in the comment of the test drawing (0.5198, not 0.64).

Co-Authored-By: Claude
@HakanSeven12
HakanSeven12 merged commit 778297d into HakanSeven12:main Nov 24, 2026
8 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