Skip to content

Fix geometry, range, and chrono wrapper bugs and improve performance in ad_physics - #262

Open
M-Colley wants to merge 2 commits into
carla-simulator:mainfrom
M-Colley:fix/ad-physics-bugs-and-perf
Open

M-Colley wants to merge 2 commits into
carla-simulator:mainfrom
M-Colley:fix/ad-physics-bugs-and-perf

Conversation

@M-Colley

@M-Colley M-Colley commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes correctness/edge-case bugs and eliminates unnecessary allocations across ad_physics (ad::geometry, ad::physics::RangeOperation, and Python bindings), with accompanying unit and Python interface regression tests.

Note: Part 1 of 5 independent, modular PRs branched directly from main with strictly disjoint file sets (each builds, tests, and merges cleanly in any order).

Bug Fixes

  • ad_physics/include/ad/physics/RangeOperation.hpp:
    • Handle invalid/inverted input ranges safely across isRangeSubRangeOf, doRangesOverlap, getIntersectionRange, subtractRangeFrom, and combineRanges instead of producing inverted range invariants or false positives.
  • ad_physics/src/GeometryOperation.cpp & Types.hpp / GeometryOperation.hpp:
    • Guard empty polygons/linestrings and degenerate calculations in Boost.Geometry operations (combinePolygonBox, toPolygon, restrictHeadingRange, etc.) instead of out-of-bounds element access.
    • Fix PolygonVector stream formatting separator logic.
  • ad_physics/python/src/ChronoPythonWrapper.cpp & generate_python_lib.py.in:
    • Fix integer truncation / overflow conversion and duration construction in std::chrono Boost.Python converters; scope Python binding generation cleanly.

Performance Improvements

  • Pass geometry containers (Line2d, Polygon2d, MultiPolygon2d, PolygonVector) by const & instead of by value and pre-reserve output vectors during conversion/combination.

Tests

  • Added unit regression tests in ad_physics/tests/GeometryOperationTest.cpp and ad_physics/tests/RangeOperationTests.cpp (registered in ad_physics/tests/CMakeLists.txt) and Python tests in ad_physics/python/tests/interface_test.py.

This change is Reviewable

The build treats warnings as errors and enables -Wfloat-equal, so the
`a.x() != b.x()` test in `operator<(Point, Point)` broke the build of
ad_physics ("comparing floating-point with '==' or '!=' is unsafe").
Order the points lexicographically using only `<`, which gives the same
result for all non-NaN coordinates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

No deployments
pypi — 53e0c01a Deployed Nov 16, 2026 by M-Colley via ubuntu-22.04, python-3.11 #171
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