Skip to content

Conversation

@castelao
Copy link
Member

The cost value read is the average value for the grid point. Before we were simplifying and just taking the next grid point value as the transition.

The correct estimate is half the path is along the origin gridpoint, plus half of the target grid point to reach the center of the target gridoint, therefore, the transition wheight should be the average between the current grid point cost and the target gridpoint cost.

Note that the same principle is valid for diagonals, it is still the average of both values, but we have to scale for the longer distance along the diagonal, thus a sqrt(2) factor.

@castelao castelao added this to the 0.0.6 - Validation milestone Aug 21, 2025
@castelao castelao requested a review from ppinchuk August 21, 2025 21:01
@castelao castelao self-assigned this Aug 21, 2025
@castelao castelao added the bugfix Fixed a known bug label Aug 21, 2025
@ppinchuk ppinchuk added p-critical Priority: critical topic-rust-routing Issues/pull requests related to rust routing code labels Aug 21, 2025
@ppinchuk ppinchuk linked an issue Aug 21, 2025 that may be closed by this pull request
@castelao
Copy link
Member Author

@ppinchuk , something very interesting going on here. In this run, the regular tests (unit + integration) ran just fine, but TOX failed for everything.

The cost value read is the average value for the grid point. Before we
were simplifying and just taking the next grid point value as the
transition.

The correct estimate is half the path is along the origin gridpoint,
plus half of the target grid point to reach the center of the target
gridoint, therefore, the transition wheight should be the average
between the current grid point cost and the target gridpoint cost.

Note that the same principle is valid for diagonals, it is still the
average of both values, but we have to scale for the longer distance
along the diagonal, thus a sqrt(2) factor.
Correcting expected values to include the diagonal factor.
Updating expected solution to consider diagonal factor
Correcting expected answer to consider the diagonal effect. In this
case, two successive diagonal moves for both cases, despite opposite
dirrections.
Correcting expected cost to include 3 diagonal moves.
Before we didn't consider the diagonal factor, so it made sense to just
add the full grid point value. Now, we have to add the average between
the two points plus the diagonal factor when relevant.
Comparison with scikit-image should be with MCP_Geometric instead of
MCP, since MCP does not penalize diagonal movements with longer distance
while MCP_Geometric does.
The original pathfinder accepted only u64, so we truncated the f32
costs. Let's allow using truncated value of sqrt(2) for now.
@castelao
Copy link
Member Author

@ppinchuk , this is ready for review. I'm postponing two tests that require corrections for later. But it is better to have everything else working now.

@castelao castelao merged commit 40ed1ce into main Aug 25, 2025
21 checks passed
@castelao castelao deleted the fix/cost_step branch August 25, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixed a known bug p-critical Priority: critical topic-rust-routing Issues/pull requests related to rust routing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properly handle diagonal movement

3 participants