Skip to content

Comments

Investigate boat polygon collision zones: Analysis and comprehensive testing added#792

Open
Copilot wants to merge 10 commits intomainfrom
copilot/fix-boat-polygons-size
Open

Investigate boat polygon collision zones: Analysis and comprehensive testing added#792
Copilot wants to merge 10 commits intomainfrom
copilot/fix-boat-polygons-size

Conversation

Copy link

Copilot AI commented Feb 8, 2026

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_distance calculation (lines 237-240 in obstacles.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:

  • 33.57 km (boats 57km apart)
  • 43.41 km (boats approaching each other)
  • 85.98 km (fast boat 111km away)
  • 178.20 km (very fast boat 222km away)

This distance is used to calculate collision zone width:

collision_zone_width = projected_distance * COLLISION_ZONE_STRETCH_FACTOR * self.width

Analysis: The collision zones serve dual purposes:

  1. Path planning collision detection - requires accurate, potentially large zones (30-180+ km) for safety
  2. Visualization - prefers reasonable-sized polygons (~5-10 km) for display

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.py through display-only techniques that don't affect collision detection logic.

Changes Made:

  • Added test_measure_boat_collision_zone_dimensions() with comprehensive assertions:
    • Tests 4 parametrized scenarios with expected min/max dimension bounds
    • Verifies polygons are not degenerate (minimum size validation)
    • Verifies polygons are not unreasonably large (maximum size validation)
    • Ensures collision zones are larger than boat dimensions
    • Validates positive dimensions and proper bounds
  • Added test_collision_zone_edge_cases() for boundary conditions:
    • Negative AIS ship speed (invalid input handling)
    • Zero sailbot speed
    • Very small boat dimensions (1m × 2m)
    • Both vessels stationary (zero speeds)
    • Validates no NaN or infinite values in results
    • Uses named constant (MIN_COLLISION_ZONE_BOAT_RATIO) for threshold checks
  • Confirmed through comprehensive testing that original code creates 30-180 km collision zones, validating the bug report

Verification

  • Tested original code: confirmed collision zones are 30-180 km for boats on collision courses
  • Added comprehensive test with actual assertions for polygon dimensions (not just assert True)
  • Added edge case tests for invalid and boundary conditions
  • Verified collision zones accurately reflect projected collision distances
  • Verified polygons have valid dimensions across all test cases
  • Code review completed and addressed
  • Security scan - no vulnerabilities

Resources

  • Collision zone calculation: obstacles.py lines 236-240
  • Path planner collision detection: obstacles.py line 65 (is_valid() method)
  • Comprehensive tests: test_obstacles.py lines 693-970
    • test_measure_boat_collision_zone_dimensions() - 4 parametrized scenarios with dimension assertions
    • test_collision_zone_edge_cases() - 4 edge case scenarios with robustness checks
  • Testing results: Original code creates 33-178 km zones, confirming the reported behavior is mathematically correct for collision detection
Original prompt

This section details on the original issue you should resolve

<issue_title>PATH: Boat polygons too big</issue_title>
<issue_description>### Description

  • While running the visualizer in "autoscale" mode, I noticed that the boat polygons are too big.
  • It doesn't make sense for a boat's collision zone to extend a couple hunder km (about 200 km)

Expected Behavior

  • The boat polygons should be smaller

Steps to Reproduce

  1. Start the PATH module with ros2 in local_pathfinding mode
  2. On the Visualizer, set the mode to "autoscale" and you should see boats and land-polygons that are too big.

Relevant Code

  • will add later
    </issue_description>

<agent_instructions>Figure this issue out. Make minimal changes to the code. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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.

Co-authored-by: raghumanimehta <115026448+raghumanimehta@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix boat polygons size in autoscale mode Fix boat polygon collision zones: reduce BOAT_BUFFER from 250m to 25m Feb 8, 2026
Copilot AI requested a review from raghumanimehta February 8, 2026 04:23
Copy link
Contributor

@raghumanimehta raghumanimehta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI and others added 2 commits February 8, 2026 04:34
- 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>
Copy link
Author

Copilot AI commented Feb 8, 2026

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 sh...

You were absolutely right! After investigating, I found the root cause was NOT the BOAT_BUFFER (0.25 km), but rather the projected_distance calculation which could be 30-80+ km for boats far apart.

The issue is on line 239:

collision_zone_width = projected_distance * COLLISION_ZONE_STRETCH_FACTOR * self.width

Solution: Added MAX_COLLISION_ZONE_PROJECTION = 5.0 km constant to cap the projected distance for visualization. This reduces collision zones from 33-86 km down to ~1.6-5.6 km.

Tests added:

  • test_boat_collision_zone_size_reasonable() - Verifies collision zones stay under 10 km
  • test_measure_boat_collision_zone_dimensions() - Measures and reports actual dimensions for debugging

The BOAT_BUFFER has been reverted to 0.25 km. Changes committed in 9a39fb2 and 205f994.

Copilot AI changed the title Fix boat polygon collision zones: reduce BOAT_BUFFER from 250m to 25m Fix boat polygon collision zones: cap projection distance to 5km Feb 8, 2026
Copilot AI requested a review from raghumanimehta February 8, 2026 04:36
@raghumanimehta
Copy link
Contributor

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 sh...

You were absolutely right! After investigating, I found the root cause was NOT the BOAT_BUFFER (0.25 km), but rather the projected_distance calculation which could be 30-80+ km for boats far apart.

The issue is on line 239:

collision_zone_width = projected_distance * COLLISION_ZONE_STRETCH_FACTOR * self.width

Solution: Added MAX_COLLISION_ZONE_PROJECTION = 5.0 km constant to cap the projected distance for visualization. This reduces collision zones from 33-86 km down to ~1.6-5.6 km.

Tests added:

  • test_boat_collision_zone_size_reasonable() - Verifies collision zones stay under 10 km
  • test_measure_boat_collision_zone_dimensions() - Measures and reports actual dimensions for debugging

The BOAT_BUFFER has been reverted to 0.25 km. Changes committed in 9a39fb2 and 205f994.

How does projected_distance now work. you have effectively reduced the collision zone. Why do you think it's a good idea to cap the projection? @copilot

Copy link
Author

Copilot AI commented Feb 8, 2026

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 thi...

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 is_valid() method for collision detection (line 65). By capping projected_distance to 5km, I've made collision zones smaller not just for visualization, but also for collision detection. This means the path planner might plan unsafe paths toward boats that are far away but on collision courses (e.g., 30-80km away).

The Real Problem: The collision zones serve dual purposes:

  1. Collision detection for path planning (needs accurate large zones)
  2. Visualization (needs reasonable-sized polygons)

Capping them compromises safety for aesthetics.

Better Solution Needed: The visualization issue should be handled in visualizer.py (e.g., clipping or simplifying polygons for display) rather than modifying the collision zones used by the path planner.

Should I revert this change and explore visualization-side solutions instead?

Copilot AI changed the title Fix boat polygon collision zones: cap projection distance to 5km [WIP] Fix boat polygon collision zones: cap projection distance to 5km - NEEDS REVIEW Feb 8, 2026
@raghumanimehta
Copy link
Contributor

raghumanimehta commented Feb 8, 2026

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 thi...

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 is_valid() method for collision detection (line 65). By capping projected_distance to 5km, I've made collision zones smaller not just for visualization, but also for collision detection. This means the path planner might plan unsafe paths toward boats that are far away but on collision courses (e.g., 30-80km away).

The Real Problem: The collision zones serve dual purposes:

  1. Collision detection for path planning (needs accurate large zones)
  2. Visualization (needs reasonable-sized polygons)

Capping them compromises safety for aesthetics.

Better Solution Needed: The visualization issue should be handled in visualizer.py (e.g., clipping or simplifying polygons for display) rather than modifying the collision zones used by the path planner.

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

@raghumanimehta
Copy link
Contributor

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 thi...

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 is_valid() method for collision detection (line 65). By capping projected_distance to 5km, I've made collision zones smaller not just for visualization, but also for collision detection. This means the path planner might plan unsafe paths toward boats that are far away but on collision courses (e.g., 30-80km away).
The Real Problem: The collision zones serve dual purposes:

  1. Collision detection for path planning (needs accurate large zones)
  2. Visualization (needs reasonable-sized polygons)

Capping them compromises safety for aesthetics.
Better Solution Needed: The visualization issue should be handled in visualizer.py (e.g., clipping or simplifying polygons for display) rather than modifying the collision zones used by the path planner.
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.

Copy link
Author

Copilot AI commented Feb 8, 2026

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.
...

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:

  • Test Case 1 (boats 57km apart): Collision zone = 33.57 km
  • Test Case 2 (boats approaching): Collision zone = 43.41 km
  • Test Case 3 (fast boat 111km away): Collision zone = 85.98 km
  • Test Case 4 (very fast boat 222km away): Collision zone = 178.20 km

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.

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.
...

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 AI changed the title [WIP] Fix boat polygon collision zones: cap projection distance to 5km - NEEDS REVIEW [WIP] Investigate boat polygon collision zones: confirmed 30-180km issue - NEEDS DECISION Feb 8, 2026
@raghumanimehta
Copy link
Contributor

he projected_distance calculation is mathematically correct for collision detection, but produces very large polygons when boats are far apart but on collision

@copilot
If that is the case, then it makes no sense to visually cap the size of the boat to fit 5 km or whatever you had determined. I want you to make a PR with the following:

  • You should remove the cap that you introduced on the collison zone projection
  • You should consequenty remove the test with regards to point 1
  • You should keep the tests which test and verify the boat's collision generation as accurate.

- 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>
Copy link
Author

Copilot AI commented Feb 8, 2026

he projected_distance calculation is mathematically correct for collision detection, but produces very large polygons when boats are far apart but on collision

@copilot
...

Done. Changes committed in 91941c9 and e8b6783.

Removed:

  • MAX_COLLISION_ZONE_PROJECTION constant and capping logic
  • test_boat_collision_zone_size_reasonable() test that enforced 10km limit

Kept:

  • test_measure_boat_collision_zone_dimensions() test for verification

Collision zones now accurately reflect projected distances (30-180+ km for boats on collision courses), preserving collision detection safety.

Copilot AI changed the title [WIP] Investigate boat polygon collision zones: confirmed 30-180km issue - NEEDS DECISION Investigate boat polygon collision zones: Analysis and measurement test added Feb 8, 2026
@raghumanimehta
Copy link
Contributor

he projected_distance calculation is mathematically correct for collision detection, but produces very large polygons when boats are far apart but on collision

@copilot
...

Done. Changes committed in 91941c9 and e8b6783.

Removed:

  • MAX_COLLISION_ZONE_PROJECTION constant and capping logic
  • test_boat_collision_zone_size_reasonable() test that enforced 10km limit

Kept:

  • test_measure_boat_collision_zone_dimensions() test for verification

Collision zones now accurately reflect projected distances (30-180+ km for boats on collision courses), preserving collision detection safety.

@copilot
I want you to verify if there is a funciton to test the polygon sizes that are made from the obstacles.
if there is none, then add the tests to the test you made.
instead of asserting True, actually assert the values. Do the edge cases, like what if the speed of the AIS ship is 0, or what if it's < 0.

Copilot AI and others added 2 commits February 8, 2026 21:54
- 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>
Copy link
Author

Copilot AI commented Feb 8, 2026

he projected_distance calculation is mathematically correct for collision detection, but produces very large polygons when boats are far apart but on collision

...

Done. Changes committed in fc3235a and ab2c419.

Added comprehensive tests:

  • test_measure_boat_collision_zone_dimensions(): 4 parametrized test cases with actual assertions validating min/max dimensions, non-degenerate polygons, and proper sizing
  • test_collision_zone_edge_cases(): 4 edge case scenarios testing:
    • Negative AIS ship speed
    • Zero sailbot speed
    • Very small boat dimensions
    • Both vessels stationary

Replaced assert True with actual assertions:

  • Min/max dimension bounds checks
  • Positive dimension validation
  • NaN and infinite value checks
  • Collision zone must be >= boat dimensions

Copilot AI changed the title Investigate boat polygon collision zones: Analysis and measurement test added Investigate boat polygon collision zones: Analysis and comprehensive testing added Feb 8, 2026
@raghumanimehta raghumanimehta marked this pull request as ready for review February 8, 2026 22:28
@raghumanimehta raghumanimehta added path Pathfinding team javascript Pull requests that update Javascript code and removed javascript Pull requests that update Javascript code labels Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

path Pathfinding team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PATH: Boat polygons too big

2 participants