Skip to content

Commit

Permalink
Enables spiral geometries parsing. (#262)
Browse files Browse the repository at this point in the history
Signed-off-by: Franco Cipollone <[email protected]>
  • Loading branch information
francocipollone authored Jan 2, 2024
1 parent 7e8716b commit c72050e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/maliput_malidrive/xodr/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ Geometry::Arc NodeParser::As() const {
return Geometry::Arc{ValidateDouble(curvature, kDontAllowNan)};
}

// Specialization to parse `Spiral`'s node.
template <>
Geometry::Spiral NodeParser::As() const {
if (NumberOfAttributes() != 2) {
MALIDRIVE_THROW_MESSAGE(std::string("Bad Spiral description. Spiral demands only two arguments: 'curvStart' and "
"'curvEnd'. ") +
ConvertXMLNodeToText(element_));
}
const AttributeParser attribute_parser(element_, parser_configuration_);
const auto curv_start = attribute_parser.As<double>(Geometry::Spiral::kCurvStart);
const auto curv_end = attribute_parser.As<double>(Geometry::Spiral::kCurvEnd);
return Geometry::Spiral{ValidateDouble(curv_start, kDontAllowNan), ValidateDouble(curv_end, kDontAllowNan)};
}

// Specialization to parse `LaneWidth`'s node.
template <>
LaneWidth NodeParser::As() const {
Expand Down Expand Up @@ -689,6 +703,9 @@ Geometry NodeParser::As() const {
case Geometry::Type::kArc:
geometry.description = geometry_type.As<Geometry::Arc>();
break;
case Geometry::Type::kSpiral:
geometry.description = geometry_type.As<Geometry::Spiral>();
break;
default:
MALIDRIVE_THROW_MESSAGE(std::string("The Geometry type '") + Geometry::type_to_str(geometry.type) +
std::string("' is not supported."));
Expand Down
21 changes: 21 additions & 0 deletions test/regression/xodr/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,27 @@ TEST_F(ParsingTests, NodeParserArcGeometry) {
EXPECT_EQ(kExpectedGeometry, geometry);
}

// Tests `Geometry` parsing.
TEST_F(ParsingTests, NodeParserSpiralGeometry) {
const Geometry kExpectedGeometry{
1.23 /* s_0 */, {523.2 /* x */, 83.27 /* y */}, 0.77 /* orientation */,
100. /* length */, Geometry::Type::kSpiral /* Type */, Geometry::Spiral{0.5, 0.25} /* description */};
const std::string geometry_description =
Geometry::type_to_str(kExpectedGeometry.type) + " " + Geometry::Spiral::kCurvStart + "='" +
std::to_string(std::get<Geometry::Spiral>(kExpectedGeometry.description).curv_start) + "' " +
Geometry::Spiral::kCurvEnd + "='" +
std::to_string(std::get<Geometry::Spiral>(kExpectedGeometry.description).curv_end) + "'";
const std::string xml_description =
GetGeometry(kExpectedGeometry.s_0, kExpectedGeometry.start_point.x(), kExpectedGeometry.start_point.y(),
kExpectedGeometry.orientation, kExpectedGeometry.length, geometry_description);

const NodeParser dut(LoadXMLAndGetNodeByName(xml_description, Geometry::kGeometryTag),
{kNullParserSTolerance, kDontAllowSchemaErrors, kDontAllowSemanticErrors});
EXPECT_EQ(Geometry::kGeometryTag, dut.GetName());
const Geometry geometry = dut.As<Geometry>();
EXPECT_EQ(kExpectedGeometry, geometry);
}

// Get a XML description that contains a XODR PlanView.
// @param s_0 The s_0 value of first geometry.
// @param x_0 The x_0 value of first geometry.
Expand Down

0 comments on commit c72050e

Please sign in to comment.