From 4b03a2b262125a7cfe65793ba5ad73668e383e20 Mon Sep 17 00:00:00 2001 From: Franco Cipollone Date: Mon, 6 Feb 2023 11:42:59 -0300 Subject: [PATCH] Addresses comments. Signed-off-by: Franco Cipollone --- include/maliput_sparse/geometry/line_string.h | 10 +++++----- src/geometry/utility/geometry.cc | 7 ++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/maliput_sparse/geometry/line_string.h b/include/maliput_sparse/geometry/line_string.h index 8e81a8e..6bc7204 100644 --- a/include/maliput_sparse/geometry/line_string.h +++ b/include/maliput_sparse/geometry/line_string.h @@ -78,13 +78,13 @@ class LineString final { /// A segment of a LineString. /// A segment is defined by a: /// - start index: index of the first coordinate of the segment. - /// - end index: index of the last coordinate of the segment, in general it is the start index + 1. + /// - end index: index of the last coordinate of the segment, it is expected to be `start index + 1` as `LineString`'s + /// constructor + /// builds the segments from consecutive coordinates. struct Segment { - /// Defines an interval in the P value of the parametrized LineString. + /// Defines an interval in the @f$ p @f$ value of the parametrized LineString. /// The Less than operator is defined to allow the use of this struct as a key in a collection like std::map. struct Interval { - // Interval() = default; - /// Creates a Interval. /// @param min_in Is the minimum value of the interval. /// @param max_in Is the maximum value of the interval. @@ -96,7 +96,7 @@ class LineString final { /// @param min_max Is the minimum and maximum value of the interval. Interval(double min_max) : min(min_max), max(min_max) {} - // Less than operator. + /// Less than operator. bool operator<(const Interval& rhs) const { if (min < rhs.min) { return max <= rhs.max ? true : false; diff --git a/src/geometry/utility/geometry.cc b/src/geometry/utility/geometry.cc index aba0b09..7c75b88 100644 --- a/src/geometry/utility/geometry.cc +++ b/src/geometry/utility/geometry.cc @@ -290,10 +290,7 @@ CoordinateT InterpolatedPointAtP(const LineString& line_string, dou const CoordinateT& end = line_string[bound_points.idx_end]; const CoordinateT d_segment{end - start}; const double remaining_distance = p - bound_points.length; - if (remaining_distance < kEpsilon) { - return start; - } - return start + d_segment.normalized() * remaining_distance; + return remaining_distance < kEpsilon ? start : start + d_segment.normalized() * remaining_distance; } double GetSlopeAtP(const LineString3d& line_string, double p, double tolerance) { @@ -309,7 +306,7 @@ double GetSlopeAtP(const LineString3d& line_string, double p, double tolerance) template BoundPointsResult GetBoundPointsAtP(const LineString& line_string, double p, double tolerance) { p = maliput::common::RangeValidator::GetAbsoluteEpsilonValidator(0., line_string.length(), tolerance, kEpsilon)(p); - const auto segment = line_string.segments().at(typename LineString::Segment::Interval{p}); + const auto segment = line_string.segments().at({p}); return {segment.idx_start, segment.idx_end, segment.p_interval.min}; }