15 #ifndef BELUGA_TEST_RAYCASTING_HPP
16 #define BELUGA_TEST_RAYCASTING_HPP
23 std::optional<double>
raycast(
const Map& map, Eigen::Vector2i source, Eigen::Vector2i target) {
24 const bool steep = std::abs(target.y() - source.y()) > std::abs(target.x() - source.x());
31 const auto delta = Eigen::Vector2i{
32 std::abs(target.x() - source.x()),
33 std::abs(target.y() - source.y()),
38 const auto step = Eigen::Vector2i{
39 source.x() < target.x() ? 1 : -1,
40 source.y() < target.y() ? 1 : -1,
43 auto current = source;
47 if (
auto opt = map.data_at(current.y(), current.x()); opt.has_value()) {
55 if (
auto opt = map.data_at(current.x(), current.y()); opt.has_value()) {
64 current.x() += step.x();
66 if (delta.x() <= 2 * error) {
67 current.y() += step.y();
71 if (current.x() == (target.x() + step.x())) {
76 return (current - source).cast<
double>().norm() * map.resolution();