Skip to content

Refactor is_close: fix broken overloads, add operator==, centralize eps#69

Merged
gallantandre merged 2 commits into
mainfrom
refactor/is-close-comparisons
Jun 14, 2026
Merged

Refactor is_close: fix broken overloads, add operator==, centralize eps#69
gallantandre merged 2 commits into
mainfrom
refactor/is-close-comparisons

Conversation

@gallantandre

Copy link
Copy Markdown
Member

Summary

Refactors the is_close family of comparison functions, which had accumulated several broken and inconsistent overloads.

Bugs fixed

  • Infinite recursion: the generic is_close<T> template called itself unconditionally. Removed entirely.
  • Inverted logic: Guess::random returned "not close" when the shot counts were equal.
  • Incomplete ObjMatrix: is_close(ObjMatrix<T>) only compared .size, never the elements; ObjMatrix::operator== had an empty is_close() call that wouldn't compile once instantiated.
  • Dropped eps: several call sites (n_points, static_rotations, Result fields) silently fell through to the broken generic template instead of forwarding the tolerance.
  • Non-const parameter: is_close(const Result&, Result&, ...) took its second argument by non-const reference.

Changes

  • Integral comparisons now use == / != directly instead of dedicated overloads.
  • ObjMatrix::operator== dispatches with if constexpr: is_close for floating-point elements, == for integral and custom types. Forward-declares is_close(real,...) so the floating path resolves under strict two-phase lookup (Clang/GCC), not just MSVC.
  • Converted the per-type is_close overloads for Manipulator, Bspline, ConstraintSelection, Objective, Guess, Optimization, and Result to operator==; added operator== for Mat3.
  • Removed the redundant per-joint limit loop in the Manipulator comparison (it duplicated the array-level checks).
  • Centralized the default tolerance on the previously-unused BLAST_EPSILON constant so it can be changed in one place.

Test plan

  • Builds clean (cmake --build build --config Release, exit 0).
  • tests/manipulators/test_auto_manip.cpp updated to use == and exercises Manipulator::operator== (and transitively ObjMatrix<u8>::operator==).

🤖 Generated with Claude Code

gallantandre and others added 2 commits June 14, 2026 15:42
Cleans up the is_close family of comparison functions:

- Remove the infinitely-recursive generic is_close<T> template and the
  redundant integer overloads; integral comparisons now use == / !=.
- Fix is_close(ObjMatrix<T>) to actually compare elements, and add a
  working ObjMatrix::operator== that dispatches via if constexpr
  (is_close for floating-point, == for integral/custom types).
- Replace the per-type is_close overloads for Manipulator, Bspline,
  ConstraintSelection, Objective, Guess, Optimization and Result with
  operator==; add operator== for Mat3.
- Fix correctness bugs: inverted logic in Guess::random comparison,
  dropped eps forwarding, missing element comparison in ObjMatrix,
  and a non-const Result parameter.
- Centralize the default tolerance on the previously-unused
  BLAST_EPSILON constant so it can be changed in one place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…e, early-out

Follow-up fixes from code review of the is_close refactor:

- Manipulator::operator== compares the joint limit arrays (position/velocity/
  acceleration/torque max, position min) with is_close over [0, n_joints)
  instead of exact std::array == over all MAX_JOINTS slots, restoring eps
  tolerance and ignoring unused trailing slots.
- Result::operator== guards the raw opt pointer before dereferencing, avoiding
  UB on a null/equal pointer.
- is_close(real) collapses the nested INF ternary to
  r1 == r2 || abs(r1 - r2) < eps (equivalent, adds an exact-equality fast path).
- Manipulator::operator== hoists the cheap _n_caps / _n_internal_collisions
  integer checks above the per-joint loops to fail fast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gallantandre gallantandre merged commit 944115f into main Jun 14, 2026
5 checks passed
@gallantandre gallantandre deleted the refactor/is-close-comparisons branch June 14, 2026 19:45
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