|
| 1 | +// Copyright (c) 2025 Open Navigation LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. Reserved. |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +#include "rclcpp/rclcpp.hpp" |
| 18 | +#include "nav2_costmap_2d/costmap_2d.hpp" |
| 19 | + |
| 20 | + |
| 21 | +/** |
| 22 | + * Test for mapToWorldNoBounds |
| 23 | + */ |
| 24 | + |
| 25 | +TEST(mapToWorldNoBounds, MapToWorldNoBoundsNegativeMapCoords) |
| 26 | +{ |
| 27 | + double wx, wy; |
| 28 | + |
| 29 | + std::unique_ptr<nav2_costmap_2d::Costmap2D> map; |
| 30 | + |
| 31 | + map = std::make_unique<nav2_costmap_2d::Costmap2D>(10, 10, 1.0, 0.0, 0.0); |
| 32 | + map->mapToWorldNoBounds(-1, -1, wx, wy); |
| 33 | + EXPECT_DOUBLE_EQ(wx, -0.5); |
| 34 | + EXPECT_DOUBLE_EQ(wy, -0.5); |
| 35 | + |
| 36 | + map = std::make_unique<nav2_costmap_2d::Costmap2D>(10, 10, 1.0, 1.0, 2.0); |
| 37 | + map->mapToWorldNoBounds(-5, -5, wx, wy); |
| 38 | + EXPECT_DOUBLE_EQ(wx, -3.5); |
| 39 | + EXPECT_DOUBLE_EQ(wy, -2.5); |
| 40 | + |
| 41 | + map = std::make_unique<nav2_costmap_2d::Costmap2D>(10, 10, 2.0, 3.0, 4.0); |
| 42 | + map->mapToWorldNoBounds(-10, -10, wx, wy); |
| 43 | + EXPECT_DOUBLE_EQ(wx, -16.0); |
| 44 | + EXPECT_DOUBLE_EQ(wy, -15.0); |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +int main(int argc, char **argv) |
| 49 | +{ |
| 50 | + ::testing::InitGoogleTest(&argc, argv); |
| 51 | + |
| 52 | + rclcpp::init(0, nullptr); |
| 53 | + |
| 54 | + int result = RUN_ALL_TESTS(); |
| 55 | + |
| 56 | + rclcpp::shutdown(); |
| 57 | + |
| 58 | + return result; |
| 59 | +} |
0 commit comments