Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forgotten review fixes #3381

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix review comments
  • Loading branch information
genadz committed Oct 29, 2021
commit 0ae806d66e3a70ebe4e74caa8b06f10e7e4369b6
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