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

transform polygone: Do not clear poly_in before transforming points #697

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,11 @@ void doTransform(
geometry_msgs::msg::Polygon & poly_out,
const geometry_msgs::msg::TransformStamped & transform)
{
poly_out.points.clear();
for (auto & point : poly_in.points) {
geometry_msgs::msg::Point32 point_transformed;
doTransform(point, point_transformed, transform);
poly_out.points.push_back(point_transformed);
std::vector<geometry_msgs::msg::Point32> points_transformed(poly_in.points.size(), {});
for (size_t i=0; i < poly_in.points.size(); ++i) {
doTransform(poly_in.points[i], points_transformed[i], transform);
}
poly_out.points = points_transformed;
}

/** \brief Trivial "conversion" function for Polygon message type.
Expand Down
17 changes: 17 additions & 0 deletions tf2_geometry_msgs/test/test_tf2_geometry_msgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ TEST(TfGeometry, Polygon)
EXPECT_NEAR(res.points[0].z, 27, EPS);
}

// non-stamped by reference
{
geometry_msgs::msg::Polygon res;
geometry_msgs::msg::Point32 p;
p.x = 1;
p.y = 2;
p.z = 3;
res.points.push_back(p);

geometry_msgs::msg::TransformStamped t = generate_stamped_transform();

tf2::doTransform(res, res, t);
EXPECT_NEAR(res.points[0].x, 11, EPS);
EXPECT_NEAR(res.points[0].y, 18, EPS);
EXPECT_NEAR(res.points[0].z, 27, EPS);
}

// stamped
{
geometry_msgs::msg::PolygonStamped v1, res;
Expand Down