Skip to content

Readability refactor: kill the error-conversion boilerplate and wrapped chains#8

Merged
basnijholt merged 3 commits into
mainfrom
refactor/readability
Jun 10, 2026
Merged

Readability refactor: kill the error-conversion boilerplate and wrapped chains#8
basnijholt merged 3 commits into
mainfrom
refactor/readability

Conversation

@basnijholt

Copy link
Copy Markdown
Member

Summary

Pure readability pass, net −108 lines (251+/359−) with zero behavior change. Three thematic commits:

PyO3 layerimpl From<TriangulationError> for PyErr replaces the inherent into_pyerr, so the 31 call sites that wrapped every core call in .map_err(TriangulationError::into_pyerr) now just use ?. This was the single biggest source of awkward rustfmt line splits; most bindings collapse back to one line per call. Also: a given() helper for the repeated "absent argument or explicit Python None" three-arm matches, and the eight SimplicesProxy set operators delegate through one shared set_op/set_rop pair.

Geometrycoord_2d/coord_3d replace the robust::Coord closures redefined inline in every predicate, sign() replaces the repeated three-way if/else blocks, and validate_simplex() dedupes the "dim+1 points of equal dimension" check spelled out in four functions.

CoreTriangulationError::value() collapses the three-line error returns, containing() uses plain loops instead of dozen-line map/filter chains, facet_neighbour() names the "other simplex across this facet" lookup shared by the walk and opposing_vertices, detach_vertex() dedupes the failed-insertion rollback duplicated between extend_hull and add_point, and summed_volume trades a turbofish try_fold for a for loop.

Verification (identical to main on every axis)

  • pytest: 112 passed; cargo test --lib --tests: 18 passed
  • Stress sweeps (50 seeds × 4 patterns × 2D/3D): byte-for-byte identical classification including per-pattern rejection totals (10/21/615/7/117), i.e. the refactor provably didn't alter any numerical path
  • A/B benchmark: unchanged (2D 5k 0.134 s, 3D 2k 0.156 s, 4D 500 0.241 s, hull-heavy unchanged)
  • pre-commit clean

Readability only; no behavior change (the full suite, stress sweeps,
and benchmarks are identical).

- impl From<TriangulationError> for PyErr replaces the inherent
  into_pyerr method, so the 31 call sites that wrapped every core call
  in .map_err(TriangulationError::into_pyerr) now just use ?; most of
  the awkward multi-line method chains in the bindings collapse back
  to single lines
- given() collapses the repeated three-arm 'absent argument or
  explicit Python None' matches to one helper
- the eight SimplicesProxy set operators delegate through a shared
  set_op/set_rop pair instead of repeating the snapshot dance
Readability only; no behavior change.

- coord_2d/coord_3d replace the robust::Coord construction closures
  that were redefined inline in every predicate
- sign() replaces the repeated three-way if/else blocks
- validate_simplex() dedupes the 'dim + 1 points of equal dimension'
  check that circumsphere, volume, precise_volume, and
  robust_in_circumsphere each spelled out
Readability only; no behavior change.

- TriangulationError::value() collapses the three-line
  Err(TriangulationError::Value("...".to_string())) returns
- containing() uses plain loops instead of nested map/filter/collect
  chains wrapped across a dozen lines
- facet_neighbour() names the 'other simplex across this facet'
  lookup shared by the walk and opposing_vertices
- detach_vertex() dedupes the failed-insertion rollback that
  extend_hull and add_point both spelled out
- summed_volume uses a for loop instead of a try_fold with a
  turbofish
@basnijholt basnijholt merged commit 6a68633 into main Jun 10, 2026
17 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.

1 participant