31 return R
"(<?xml version="1.0" encoding="UTF-8"?>
33 <header revMajor="1" revMinor="4" name="" version="1"
34 north="100" south="-100" east="100" west="-100"/>
41 int id,
float x0,
float length,
42 const std::string& lane_xml,
43 bool with_speed =
true) {
44 std::string speed_block = with_speed
45 ? R
"(<type s="0" type="town"><speed max="50" unit="km/h"/></type>)"
48 " <road name=\"R" + std::to_string(
id) +
"\" length=\"" + std::to_string(length) +
49 "\" id=\"" + std::to_string(
id) +
"\" junction=\"-1\">\n" +
50 " " + speed_block +
"\n" +
51 " <planView><geometry s=\"0\" x=\"" + std::to_string(x0) +
52 "\" y=\"0\" hdg=\"0\" length=\"" + std::to_string(length) +
"\"><line/></geometry></planView>\n" +
53 " <elevationProfile><elevation s=\"0\" a=\"0\" b=\"0\" c=\"0\" d=\"0\"/></elevationProfile>\n" +
54 " <lateralProfile/>\n" +
65 <lane id="1" type="driving" level="false">
66 <width sOffset="0" a="3.5" b="0" c="0" d="0"/>
69 <center><lane id="0" type="none" level="false"/></center>
71 <lane id="-1" type="driving" level="false">
72 <width sOffset="0" a="3.5" b="0" c="0" d="0"/>
86 <lane id="1" type="driving" level="false">
87 <width sOffset="0" a="3.5" b="0" c="0" d="0"/>
89 <lane id="2" type="driving" level="false">
90 <width sOffset="0" a="3.5" b="0" c="0" d="0"/>
93 <center><lane id="0" type="none" level="false"/></center>
103 <center><lane id="0" type="none" level="false"/></center>
105 <lane id="-1" type="driving" level="false">
106 <width sOffset="0" a="3.5" b="0" c="0" d="0"/>
118TEST(
road, filter_roads_includes_positive_only_lanes_9565) {
130 ASSERT_TRUE(map.has_value());
135 const Vector3D minpos(-10.f, 20.f, -10.f);
138 auto included = map->FilterRoadsByPosition(minpos, maxpos);
141 EXPECT_EQ(included.size(), 3u)
142 <<
"FilterRoadsByPosition excluded a road with positive-only lanes";
150TEST(
road, get_trees_transform_no_crash_without_speed_9565) {
157 ASSERT_TRUE(map.has_value());
160 const Vector3D minpos(-10.f, 20.f, -10.f);
161 const Vector3D maxpos(110.f, -20.f, 10.f);
164 std::vector<std::pair<carla::geom::Transform, std::string>> result =
165 map->GetTreesTransform(minpos, maxpos, 10.f, 2.f);
168 ASSERT_GT(result.size(), 0u)
169 <<
"No trees generated for road without maxspeed tag";
172 for (
const auto& entry : result) {
173 EXPECT_EQ(entry.second,
"Town")
174 <<
"Expected \"Town\" fallback for road without maxspeed tag";
178TEST(
road, get_trees_transform_positive_lane_road_gets_trees_9565) {
186 ASSERT_TRUE(map.has_value());
189 const Vector3D minpos(-10.f, 20.f, -10.f);
190 const Vector3D maxpos(110.f, -20.f, 10.f);
192 auto result = map->GetTreesTransform(minpos, maxpos, 10.f, 2.f);
194 ASSERT_GT(result.size(), 0u)
195 <<
"No trees generated for one-way road with positive-only lanes";
201 const float lane1_width = 3.5f;
202 const float lane2_width = 3.5f;
203 const float dist_from_edge = 2.0f;
204 const float outer_road_edge = lane1_width + lane2_width;
205 const float min_expected_dist = outer_road_edge + dist_from_edge;
206 for (
const auto& entry : result) {
207 const float tree_y = std::abs(entry.first.location.y);
209 <<
"Tree Y=" << entry.first.location.y
210 <<
" is not within ±" <<
TREE_Y_TOLERANCE <<
" of the expected minimum distance (|Y| = " << min_expected_dist <<
")";
214TEST(
road, get_trees_transform_trees_outside_road_9565) {
224 ASSERT_TRUE(map.has_value());
227 const Vector3D minpos(-10.f, 20.f, -10.f);
228 const Vector3D maxpos(110.f, -20.f, 10.f);
230 auto result = map->GetTreesTransform(minpos, maxpos, 10.f, 2.f);
231 ASSERT_GT(result.size(), 0u) <<
"No trees generated for negative-only lane road";
236 const float lane_outer_edge = 3.5f;
237 const float dist_from_edge = 2.0f;
238 const float min_expected_dist = lane_outer_edge + dist_from_edge;
240 for (
const auto& entry : result) {
241 const float tree_y = std::abs(entry.first.location.y);
243 <<
"Tree Y=" << entry.first.location.y
244 <<
" is not within ±" <<
TREE_Y_TOLERANCE <<
" of the expected minimum distance (|Y| = " << min_expected_dist <<
")";
static std::optional< road::Map > Load(const std::string &opendrive)
TEST(agents_types, road_option_values_match_python)
constexpr float TREE_Y_TOLERANCE
static std::string BidirectionalLanes()
static std::string MakeHeader()
static std::string NegativeOnlyLanes()
static std::string PositiveOnlyLanes()
static std::string MakeRoad(int id, float x0, float length, const std::string &lane_xml, bool with_speed=true)