Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
genadz committed Oct 29, 2021
1 parent ff2e8fc commit 0ae806d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
20 changes: 6 additions & 14 deletions src/midgard/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,13 @@ float tangent_angle(size_t index,
const PointLL& point,
const std::vector<PointLL>& shape,
const float sample_distance,
bool forward) {
assert(!shape.empty());
return tangent_angle(index, 0, shape.size() - 1, point, shape, sample_distance, forward);
}

float tangent_angle(size_t index,
bool forward,
size_t first_segment_index,
size_t last_segment_index,
const PointLL& point,
const std::vector<PointLL>& shape,
const float sample_distance,
bool forward) {
// make sure that `index` belongs to the segment
assert(first_segment_index <= index);
assert(index <= last_segment_index);
size_t last_segment_index) {
assert(!shape.empty());
assert(index < shape.size());
first_segment_index = std::min(first_segment_index, index);
last_segment_index = std::min(std::max(last_segment_index, index), shape.size() - 1);
// depending on if we are going forward or backward we choose a different increment
auto increment = forward ? -1 : 1;
auto first_end =
Expand Down
4 changes: 2 additions & 2 deletions src/tyr/serializers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ std::vector<std::string> openlr_edges(const TripLeg& leg) {

const auto& start = shape[begin_index];
float forward_heading =
midgard::tangent_angle(begin_index, begin_index, end_index, start, shape, 20.f, true);
midgard::tangent_angle(begin_index, start, shape, 20.f, true, begin_index, end_index);
const auto& end = shape[end_index];
float reverse_heading =
midgard::tangent_angle(end_index, begin_index, end_index, end, shape, 20.f, false);
midgard::tangent_angle(end_index, end, shape, 20.f, false, begin_index, end_index);

std::vector<baldr::OpenLR::LocationReferencePoint> lrps;
lrps.emplace_back(start.lng(), start.lat(), forward_heading, frc, fow, nullptr,
Expand Down
4 changes: 2 additions & 2 deletions test/util_midgard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,12 @@ TEST(UtilMidgard, TestTangentAngleOnSegment) {

float expected = shape[1].Heading(shape[2]);
// calculate the angle taking into account only second and third points on the curve
float tang = tangent_angle(1, 1, 2, shape[1], shape, kTestDistance, true);
float tang = tangent_angle(1, shape[1], shape, kTestDistance, true, 1, 2);
EXPECT_NEAR(tang, expected, 5.0f) << "tangent_angle outside expected tolerance";

expected = shape[1].Heading(shape[0]);
// calculate the angle taking into account only first and second points on the curve
tang = tangent_angle(1, 0, 1, shape[1], shape, kTestDistance, false);
tang = tangent_angle(1, shape[1], shape, kTestDistance, false, 0, 1);
EXPECT_NEAR(tang, expected, 5.0f) << "tangent_angle outside expected tolerance";
}

Expand Down
27 changes: 5 additions & 22 deletions valhalla/midgard/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,34 +285,17 @@ void trim_shape(float start,
* @param shape Shape / polyline geometry.
* @param sample_distance Distance to sample when computing heading.
* @param forward Boolean value whether to test in forward or reverse direction.
* @param first_segment_index Index into the shape pointing to the first stopping point.
* @param last_segment_index Index into the shape pointing to the last stopping point.
* @return Returns the angle in degrees relative to N.
*/
float tangent_angle(size_t index,
const PointLL& point,
const std::vector<PointLL>& shape,
const float sample_distance,
bool forward);

/**
* Estimate the angle of the tangent at a point along a discretised curve. This is extended
* function that allows to use a subcurve of the curve. It may be helpful in case you don't
* want to create an additional vector by copying intermediate points.
* @param index Index into the shape.
* @param first_segment_index Index into the shape pointing to the first point of the segment.
* @param last_segment_index Index into the shape pointing to the last point of the segment.
* @param point Point to test for tangent along the curve.
* @param shape Shape / polyline geometry.
* @param sample_distance Distance to sample when computing heading.
* @param forward Boolean value whether to test in forward or reverse direction.
* @return Returns the angle in degrees relative to N.
*/
float tangent_angle(size_t index,
size_t first_segment_index,
size_t last_segment_index,
const PointLL& point,
const std::vector<PointLL>& shape,
const float sample_distance,
bool forward);
bool forward,
size_t first_segment_index = 0,
size_t last_segment_index = std::numeric_limits<size_t>::max());

// useful in converting from one iteratable map to another
// for example: ToMap<boost::property_tree::ptree, std::unordered_map<std::string, std::string>
Expand Down

0 comments on commit 0ae806d

Please sign in to comment.