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

Builder for BranchPoints #24

Merged
merged 12 commits into from Oct 12, 2022
Merged

Conversation

agalbachicar
Copy link
Contributor

🎉 New feature

Part of #10

Summary

Implements the BranchPoint builder.

Test it

Via unit tests (not yet).

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if it affects the public API)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Note to maintainers: this PR is in draft state. There are missing tests and it doesn't compile yet but it just aims to show how it would be used for preliminary discussions.

Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
@agalbachicar
Copy link
Contributor Author

@francocipollone I would appreciate your review on 90ccc36. I am mostly interested in knowing your thoughts on its use.

Copy link
Contributor

@francocipollone francocipollone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm overall.
I agree with the proposed api for the branchpoint building. I left some minor comments.

Populating the branchpoints is something that in general has to be implemented in each backend. I think that having this helper as agnostic to the backend as it is at maliput::base could be beneficial to avoid reimplementing code? Wdyt?

@@ -337,6 +376,12 @@ class RoadGeometryBuilder final {
void SetJunction(maliput::common::Passkey<JunctionBuilder>,
std::unique_ptr<maliput::geometry_base::Junction> junction);

void SetBranchPoints(maliput::common::Passkey<BranchPointBuilder>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

std::set<BranchPointBuilder::LaneEnd> b_side{};
};

// Proivdes maliput::api::BranchPointId with an increasing counter to make each ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Proivdes to Provides

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

private:
int branch_point_count_{0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be unsigned as negatives aren't being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it actually won't go negative until we go over int range. Do you think this is a problem?


void RoadGeometryBuilder::SetBranchPoints(
maliput::common::Passkey<BranchPointBuilder>,
std::vector<std::unique_ptr<maliput::geometry_base::BranchPoint>>&& branch_points) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably have to assert that the vector isn't size zero also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

for (int i = 0; i < junction->num_segments(); ++i) {
const maliput::api::Segment* segment = junction->segment(j);
for (int j = 0; j < segment->num_lanes(); ++j) {
maliput::geometry_base::Lane* lane = segment->lane(j);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const maliput::api::LaneId& lane_id_a, const maliput::api::LaneEnd::Which which_a,
const maliput::api::LaneId& lane_id_b, const maliput::api::LaneEnd::Which which_b) {
const LaneEnd lane_end_a = std::make_pair(lane_id_a, which_a);
const LaneEnd lane_end_b = std::make_pair(lane_id_a, which_b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const LaneEnd lane_end_b = std::make_pair(lane_id_a, which_b);
const LaneEnd lane_end_b = std::make_pair(lane_id_b, which_b);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the implementation.

it_a_side->b_side.insert(b_side_set.begin(), b_side_set.end());
} else if (it_b_side != branch_point_sets->end()) {
auto a_side_set = GetLaneEndSet(lane_end, lane_ends);
it_b_side->b_side.insert(a_side_set.begin(), a_side_set.end());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it_b_side->b_side.insert(a_side_set.begin(), a_side_set.end());
it_b_side->b_side.insert(b_side_set.begin(), a_side_set.end());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the implementation.

Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
@agalbachicar
Copy link
Contributor Author

This PR now depends on maliput/maliput#524

@agalbachicar agalbachicar marked this pull request as ready for review October 10, 2022 14:55
@agalbachicar
Copy link
Contributor Author

I've just triggered CI again @francocipollone

Copy link
Contributor

@francocipollone francocipollone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice job! This is a great addition!

Comment on lines 142 to 143
auto range_a_b = lane_ends_.equal_range(lane_end_a);
auto range_b_a = lane_ends_.equal_range(lane_end_b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't these be const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch!

Comment on lines 267 to 268
// When @p lane_ends appears on the A side of a BranchPointSets, the B side of such entity is updated.
// When @p lane_ends appears on the B side of a BranchPointSets, the A side of such entity is updated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// When @p lane_ends appears on the A side of a BranchPointSets, the B side of such entity is updated.
// When @p lane_ends appears on the B side of a BranchPointSets, the A side of such entity is updated.
// When @p lane_end appears on the A side of a BranchPointSets, the B side of such entity is updated.
// When @p lane_end appears on the B side of a BranchPointSets, the A side of such entity is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed a bit the entire docstring.

return branch_point;
}

const std::unordered_map<maliput::api::LaneId, const maliput::geometry_base::Lane*> lanes_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you receive a reference here instead of copying the unordered map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for catching it.

Comment on lines +564 to +566
ASSERT_TRUE(lane_end_is_in(lane_a->GetOngoingBranches(finish)->get(0), expected_lane_ends));
ASSERT_TRUE(lane_end_is_in(lane_a->GetOngoingBranches(finish)->get(1), expected_lane_ends));
ASSERT_TRUE(lane_end_is_in(lane_a->GetOngoingBranches(finish)->get(2), expected_lane_ends));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This might hide one case:

  • when get(0), get(1) and get(2) returns the same value for example.

expected_lane_ends should be iterated and for each value, there should be one value in the lane_a->GetOngoingBranches(finish) set that matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I did not think of it. Let me address that in a follow up PR.

Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
Copy link
Contributor

@francocipollone francocipollone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@agalbachicar agalbachicar merged commit f6016d2 into main Oct 12, 2022
@agalbachicar agalbachicar deleted the agalbachicar/#10_builder_branch_points branch October 12, 2022 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants