Investigate boat polygon collision zones: Analysis and comprehensive testing added#792
Investigate boat polygon collision zones: Analysis and comprehensive testing added#792
Conversation
Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
raghumanimehta
left a comment
There was a problem hiding this comment.
Does this explain why the visualizer.py was showing the buffers that were too long? I want you to write tests for obstacles that ensure that ending polygons are not 100s of km long.
For this you should use the old value of 0.25 km.
I don't think 0.025 km is the problem fix. There is a good chance that the polygons are not rendered properly on the visualizer. You should add tests to obstacles to verify what the size of the polygons are based on the testing we use for defined ais mock ships.
- Added MAX_COLLISION_ZONE_PROJECTION constant (5km) - Cap projected_distance to prevent 30-80km collision zones - Added tests to verify collision zones stay under 10km - Added measurement test to debug actual polygon dimensions Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
You were absolutely right! After investigating, I found the root cause was NOT the BOAT_BUFFER (0.25 km), but rather the The issue is on line 239: collision_zone_width = projected_distance * COLLISION_ZONE_STRETCH_FACTOR * self.widthSolution: Added Tests added:
The BOAT_BUFFER has been reverted to 0.25 km. Changes committed in 9a39fb2 and 205f994. |
How does |
You raise an excellent point. After further consideration, I realize capping projected_distance has a significant problem: The Issue: The collision_zone is used by the path planner's The Real Problem: The collision zones serve dual purposes:
Capping them compromises safety for aesthetics. Better Solution Needed: The visualization issue should be handled in Should I revert this change and explore visualization-side solutions instead? |
First, tell me based on your testing the raw existing code before you made changes was making right sized polygons that were not 100s kms long? @copilot |
@copilot answer this. |
No, the original code was NOT making right-sized polygons. Based on my testing with the original code (BOAT_BUFFER = 0.25 km, no cap): Test Results:
The original code DID create collision zones ranging from 30-180 km, confirming the bug report that described "200 km" polygons. The issue is real and the projected_distance calculation creates very large zones for boats far apart on collision courses.
No, the original code was NOT making right-sized polygons. Testing confirms the original code created collision zones of 33-178 km for boats on collision courses at realistic distances. Test Case 4 (boat 222km away moving at 60 kmph) produced a 178 km collision zone, matching the "~200 km" described in the bug report. The projected_distance calculation is mathematically correct for collision detection, but produces very large polygons when boats are far apart but on collision courses. |
@copilot
|
- Removed MAX_COLLISION_ZONE_PROJECTION constant - Removed capping logic that limited projected_distance to 5km - Removed test_boat_collision_zone_size_reasonable test that enforced 10km limit - Kept test_measure_boat_collision_zone_dimensions for verification - Collision zones will now reflect accurate projected distances for proper collision detection Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
Done. Changes committed in 91941c9 and e8b6783. Removed:
Kept:
Collision zones now accurately reflect projected distances (30-180+ km for boats on collision courses), preserving collision detection safety. |
@copilot |
- Replace generic assert True with actual dimension assertions - Add 4 parametrized test cases with expected min/max dimensions - Add separate test_collision_zone_edge_cases for edge cases: * Negative AIS ship speed * Zero sailbot speed * Very small boat dimensions * Both vessels stationary - Verify polygons have valid, non-degenerate dimensions - Ensure collision zones are larger than boat dimensions - Test for NaN and infinite values in edge cases Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
- Extract 0.5 magic number to MIN_COLLISION_ZONE_BOAT_RATIO constant - Add inline documentation explaining why 50% threshold is used - Clarify that edge cases (stationary boats) may have smaller zones Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
... Done. Changes committed in fc3235a and ab2c419. Added comprehensive tests:
Replaced
|
Description
Investigated the reported issue of boat collision zones appearing too large (200 km) in the visualizer's autoscale mode.
Root cause confirmed: The
projected_distancecalculation (lines 237-240 inobstacles.py) creates large collision zones (30-180+ km) for boats far apart on collision courses. Testing with the original code confirmed collision zones ranging from:This distance is used to calculate collision zone width:
Analysis: The collision zones serve dual purposes:
The large collision zones (30-180 km) are mathematically correct for collision detection. They represent the actual projected collision points for boats that are far away but on collision courses. Artificially capping these zones would compromise the safety of the path planner's
is_valid()method, potentially allowing unsafe path planning.Conclusion: The collision zones are functioning correctly for their primary purpose (collision detection). If visualization is an issue, it should be addressed in
visualizer.pythrough display-only techniques that don't affect collision detection logic.Changes Made:
test_measure_boat_collision_zone_dimensions()with comprehensive assertions:test_collision_zone_edge_cases()for boundary conditions:Verification
Resources
obstacles.pylines 236-240obstacles.pyline 65 (is_valid()method)test_obstacles.pylines 693-970test_measure_boat_collision_zone_dimensions()- 4 parametrized scenarios with dimension assertionstest_collision_zone_edge_cases()- 4 edge case scenarios with robustness checksOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.