"The JPS algorithm that I have learned will continuously search along a certain direction during pathfinding, until it encounters an obstacle or reaches a jump node. However, I found that the jump() function is not like that. It may have various unexpected search mutations during recursion, due to the const Node& motion parameter. In some cases, the search path may exhibit strange curved paths."
Node JumpPointSearch::jump(const Node& point, const Node& motion )
{
Node new_point = point + motion;
new_point.id_ = grid2Index(new_point.x_, new_point.y_);
new_point.pid_ = point.id_;
new_point.h_ = std::sqrt(std::pow(new_point.x_ - goal_.x_, 2) + std::pow(new_point.y_ - goal_.y_, 2));
// next node hit the boundary or obstacle
if (new_point.id_ < 0 || new_point.id_ >= ns_ || costs_[new_point.id_] >= lethal_cost_ * factor_)
return Node(-1, -1, -1, -1, -1, -1);
// goal found
if (new_point == goal_)
return new_point;
// diagonal
if (motion.x_ && motion.y_)
{
// if exists jump point at horizontal or vertical
Node x_dir = Node(motion.x_, 0, 1, 0, 0, 0);
Node y_dir = Node(0, motion.y_, 1, 0, 0, 0);
if (jump(new_point, x_dir).id_ != -1 || jump(new_point, y_dir).id_ != -1)
return new_point;
}
// exists forced neighbor
if (detectForceNeighbor(new_point, motion))
return new_point;
else
return jump(new_point, motion); //
}
``