|
| 1 | +// Copyright 2024 TIER IV, Inc. |
| 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. |
| 14 | + |
| 15 | +#include "../src/filter_predicted_objects.hpp" |
| 16 | + |
| 17 | +#include <autoware_auto_perception_msgs/msg/predicted_object.hpp> |
| 18 | +#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp> |
| 19 | +#include <autoware_auto_perception_msgs/msg/predicted_path.hpp> |
| 20 | + |
| 21 | +#include <gtest/gtest.h> |
| 22 | +#include <lanelet2_core/geometry/LineString.h> |
| 23 | + |
| 24 | +TEST(TestCollisionDistance, CutPredictedPathBeyondLine) |
| 25 | +{ |
| 26 | + using autoware::motion_velocity_planner::out_of_lane::cut_predicted_path_beyond_line; |
| 27 | + autoware_auto_perception_msgs::msg::PredictedPath predicted_path; |
| 28 | + lanelet::BasicLineString2d stop_line; |
| 29 | + double object_front_overhang = 0.0; |
| 30 | + const auto eps = 1e-9; |
| 31 | + |
| 32 | + EXPECT_NO_THROW(cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang)); |
| 33 | + |
| 34 | + geometry_msgs::msg::Pose pose; |
| 35 | + pose.position.x = 0.0; |
| 36 | + pose.position.y = 0.0; |
| 37 | + predicted_path.path.push_back(pose); |
| 38 | + pose.position.y = 1.0; |
| 39 | + predicted_path.path.push_back(pose); |
| 40 | + pose.position.y = 2.0; |
| 41 | + predicted_path.path.push_back(pose); |
| 42 | + pose.position.y = 3.0; |
| 43 | + predicted_path.path.push_back(pose); |
| 44 | + |
| 45 | + cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang); |
| 46 | + EXPECT_EQ(predicted_path.path.size(), 4UL); |
| 47 | + for (auto i = 0UL; i < predicted_path.path.size(); ++i) { |
| 48 | + EXPECT_EQ(predicted_path.path[i].position.x, 0.0); |
| 49 | + EXPECT_NEAR(predicted_path.path[i].position.y, static_cast<double>(i), eps); |
| 50 | + } |
| 51 | + stop_line = {{-1.0, 2.0}, {1.0, 2.0}}; |
| 52 | + cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang); |
| 53 | + EXPECT_EQ(predicted_path.path.size(), 2UL); |
| 54 | + for (auto i = 0UL; i < predicted_path.path.size(); ++i) { |
| 55 | + EXPECT_EQ(predicted_path.path[i].position.x, 0.0); |
| 56 | + EXPECT_NEAR(predicted_path.path[i].position.y, static_cast<double>(i), eps); |
| 57 | + } |
| 58 | +} |
0 commit comments