Skip to content

Commit 2ec7b6c

Browse files
committed
tf2_eigen uncrustify
1 parent 007ddfa commit 2ec7b6c

File tree

2 files changed

+64
-46
lines changed

2 files changed

+64
-46
lines changed

tf2_eigen/include/tf2_eigen/tf2_eigen.h

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
/** \author Koji Terada, Bjarne von Horn */
2828

29-
#ifndef TF2_EIGEN_H
30-
#define TF2_EIGEN_H
29+
#ifndef TF2_EIGEN__TF2_EIGEN_H_
30+
#define TF2_EIGEN__TF2_EIGEN_H_
3131

3232
#include <tf2/convert.h>
3333
#include <tf2/transform_datatypes.h>
@@ -59,7 +59,8 @@ inline Eigen::Isometry3d transformToEigen(const geometry_msgs::msg::Transform &
5959
* \return The transform message converted to an Eigen Isometry3d transform.
6060
*/
6161
inline
62-
Eigen::Isometry3d transformToEigen(const geometry_msgs::msg::TransformStamped& t) {
62+
Eigen::Isometry3d transformToEigen(const geometry_msgs::msg::TransformStamped & t)
63+
{
6364
return transformToEigen(t.transform);
6465
}
6566

@@ -147,7 +148,6 @@ struct ImplDetails<Eigen::Vector3d, geometry_msgs::msg::Vector3>
147148
{
148149
};
149150

150-
151151
/// \brief Default Type for automatic tf2::doTransform() implementation for Eigen::Vector3d.
152152
template<>
153153
struct DefaultTransformType<Eigen::Vector3d>
@@ -157,7 +157,7 @@ struct DefaultTransformType<Eigen::Vector3d>
157157
};
158158

159159
/// \brief Default return type of tf2::toMsg() for Eigen::Vector3d.
160-
template <>
160+
template<>
161161
struct defaultMessage<Eigen::Vector3d>
162162
{
163163
/// \brief Default return type of tf2::toMsg() for Eigen::Vector3d.
@@ -168,7 +168,6 @@ struct defaultMessage<Eigen::Vector3d>
168168
template<>
169169
struct ImplDetails<Eigen::Quaterniond, geometry_msgs::msg::Quaternion>
170170
{
171-
172171
/** \brief Convert a Eigen Quaterniond type to a Quaternion message.
173172
* \param[in] in The Eigen Quaterniond to convert.
174173
* \param[out] msg The quaternion converted to a Quaterion message.
@@ -192,7 +191,7 @@ struct ImplDetails<Eigen::Quaterniond, geometry_msgs::msg::Quaternion>
192191
};
193192

194193
/// \brief Default return type of tf2::toMsg() for Eigen::Quaterniond.
195-
template <>
194+
template<>
196195
struct defaultMessage<Eigen::Quaterniond>
197196
{
198197
/// \brief Default return type of tf2::toMsg() for Eigen::Quaterniond.
@@ -227,7 +226,7 @@ namespace impl
227226
/** \brief Pose conversion template for Eigen types.
228227
* \tparam T Eigen transform type.
229228
*/
230-
template <typename T>
229+
template<typename T>
231230
struct EigenPoseImpl
232231
{
233232
/** \brief Convert a Eigen transform type to a Pose message.
@@ -238,7 +237,7 @@ struct EigenPoseImpl
238237
{
239238
tf2::toMsg<>(Eigen::Vector3d(in.translation()), msg.position);
240239
Eigen::Quaterniond q(in.linear());
241-
if (q.w() < 0) q.coeffs() *= -1;
240+
if (q.w() < 0) {q.coeffs() *= -1;}
242241
tf2::toMsg<>(q, msg.orientation);
243242
}
244243

@@ -257,37 +256,37 @@ struct EigenPoseImpl
257256
};
258257

259258
/// \brief Conversion implementation for geometry_msgs::msg::Pose and Eigen::Affine3d.
260-
template <>
259+
template<>
261260
struct ImplDetails<Eigen::Affine3d, geometry_msgs::msg::Pose>
262-
: public EigenPoseImpl<Eigen::Affine3d>
261+
: public EigenPoseImpl<Eigen::Affine3d>
263262
{
264263
};
265264

266265
/// \brief Conversion implementation for geometry_msgs::msg::Pose and Eigen::Isometry3d.
267-
template <>
266+
template<>
268267
struct ImplDetails<Eigen::Isometry3d, geometry_msgs::msg::Pose>
269-
: public EigenPoseImpl<Eigen::Isometry3d>
268+
: public EigenPoseImpl<Eigen::Isometry3d>
270269
{
271270
};
272271

273272
/// \brief Default return type of tf2::toMsg() for Eigen::Affine3d.
274-
template <>
273+
template<>
275274
struct defaultMessage<Eigen::Affine3d>
276275
{
277276
/// \brief Default return type of tf2::toMsg() for Eigen::Affine3d.
278277
using type = geometry_msgs::msg::Pose;
279278
};
280279

281280
/// \brief Default return type of tf2::toMsg() for Eigen::Affine3d.
282-
template <>
281+
template<>
283282
struct defaultMessage<Eigen::Isometry3d>
284283
{
285284
/// \brief Default return type of tf2::toMsg() for Eigen::Affine3d.
286285
using type = geometry_msgs::msg::Pose;
287286
};
288287

289288
/// \brief Conversion implementation for geometry_msgs::msg::Twist and Eigen::Matrix<double, 6, 1>.
290-
template <>
289+
template<>
291290
struct ImplDetails<Eigen::Matrix<double, 6, 1>, geometry_msgs::msg::Twist>
292291
{
293292
/** \brief Convert a Eigen 6x1 Matrix type to a Twist message.
@@ -320,21 +319,21 @@ struct ImplDetails<Eigen::Matrix<double, 6, 1>, geometry_msgs::msg::Twist>
320319
};
321320

322321
/// \brief Default return type of tf2::toMsg() for Eigen::Matrix<double, 6, 1>.
323-
template <>
322+
template<>
324323
struct defaultMessage<Eigen::Matrix<double, 6, 1>>
325324
{
326325
/// \brief Default return type of tf2::toMsg() for Eigen::Matrix<double, 6, 1>.
327326
using type = geometry_msgs::msg::Twist;
328327
};
329328

330329
/// \brief Conversion implementation for geometry_msgs::msg::Wrench and Eigen::Matrix<double, 6, 1>.
331-
template <>
330+
template<>
332331
struct ImplDetails<Eigen::Matrix<double, 6, 1>, geometry_msgs::msg::Wrench>
333332
{
334-
/** \brief Convert a Eigen 6x1 Matrix type to a Wrench message.
335-
* \param[in] in The 6x1 Eigen Matrix to convert.
336-
* \param[out] msg The Eigen Matrix converted to a Wrench message.
337-
*/
333+
/** \brief Convert a Eigen 6x1 Matrix type to a Wrench message.
334+
* \param[in] in The 6x1 Eigen Matrix to convert.
335+
* \param[out] msg The Eigen Matrix converted to a Wrench message.
336+
*/
338337
static void toMsg(const Eigen::Matrix<double, 6, 1> & in, geometry_msgs::msg::Wrench & msg)
339338
{
340339
msg.force.x = in[0];
@@ -389,11 +388,11 @@ struct DefaultTransformType<Eigen::Isometry3d>
389388
inline geometry_msgs::msg::Vector3 toMsg2(const Eigen::Vector3d & in)
390389
{
391390
geometry_msgs::msg::Vector3 msg;
392-
msg.x = in(0);
393-
msg.y = in(1);
394-
msg.z = in(2);
391+
msg.x = in[0];
392+
msg.y = in[1];
393+
msg.z = in[2];
395394
return msg;
396395
}
397396
} // namespace tf2
398397

399-
#endif // TF2_EIGEN_H
398+
#endif // TF2_EIGEN__TF2_EIGEN_H_

tf2_eigen/test/tf2_eigen-test.cpp

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* Copyright (c) Koji Terada
3-
* All rights reserved.
2+
* Copyright (c) Koji Terada. All rights reserved.
43
*
54
* Redistribution and use in source and binary forms, with or without
65
* modification, are permitted provided that the following conditions are met:
@@ -34,20 +33,26 @@
3433

3534
// To get M_PI, especially on Windows.
3635
#include <math.h>
37-
#include <memory>
3836

3937
#include <tf2_eigen/tf2_eigen.h>
4038
#include <gtest/gtest.h>
4139
#include <rclcpp/clock.hpp>
4240
#include <tf2_ros/transform_listener.h>
4341
#include <tf2_ros/buffer.h>
4442
#include <tf2/convert.h>
43+
44+
4545
#include <geometry_msgs/msg/vector3_stamped.hpp>
4646
#include <geometry_msgs/msg/quaternion_stamped.hpp>
4747

48+
#include <memory>
49+
50+
4851
TEST(TfEigen, ConvertVector3dStamped)
4952
{
50-
const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1,2,3), tf2::TimePoint(std::chrono::seconds(5)), "test");
53+
const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1, 2, 3), tf2::TimePoint(
54+
std::chrono::seconds(
55+
5)), "test");
5156

5257
tf2::Stamped<Eigen::Vector3d> v1;
5358
geometry_msgs::msg::PointStamped p1;
@@ -59,7 +64,7 @@ TEST(TfEigen, ConvertVector3dStamped)
5964

6065
TEST(TfEigen, ConvertVector3d)
6166
{
62-
const Eigen::Vector3d v(1,2,3);
67+
const Eigen::Vector3d v(1, 2, 3);
6368

6469
Eigen::Vector3d v1;
6570
geometry_msgs::msg::Point p1;
@@ -71,8 +76,12 @@ TEST(TfEigen, ConvertVector3d)
7176

7277
TEST(TfEigen, ConvertAffine3dStamped)
7378
{
74-
const Eigen::Affine3d v_nonstamped(Eigen::Translation3d(1,2,3) * Eigen::AngleAxis<double>(1, Eigen::Vector3d::UnitX()));
75-
const tf2::Stamped<Eigen::Affine3d> v(v_nonstamped, tf2::TimePoint(std::chrono::seconds(42)), "test_frame");
79+
const Eigen::Affine3d v_nonstamped(Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxis<double>(
80+
1,
81+
Eigen::Vector3d::UnitX()));
82+
const tf2::Stamped<Eigen::Affine3d> v(v_nonstamped, tf2::TimePoint(
83+
std::chrono::seconds(
84+
42)), "test_frame");
7685

7786
tf2::Stamped<Eigen::Affine3d> v1;
7887
geometry_msgs::msg::PoseStamped p1;
@@ -87,7 +96,9 @@ TEST(TfEigen, ConvertAffine3dStamped)
8796

8897
TEST(TfEigen, ConvertAffine3d)
8998
{
90-
const Eigen::Affine3d v(Eigen::Translation3d(1,2,3) * Eigen::AngleAxis<double>(1, Eigen::Vector3d::UnitX()));
99+
const Eigen::Affine3d v(Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxis<double>(
100+
1,
101+
Eigen::Vector3d::UnitX()));
91102

92103
Eigen::Affine3d v1;
93104
geometry_msgs::msg::Pose p1;
@@ -102,14 +113,20 @@ TEST(TfEigen, ConvertTransform)
102113
{
103114
Eigen::Matrix4d tm;
104115

105-
double alpha = M_PI/4.0;
106-
double theta = M_PI/6.0;
107-
double gamma = M_PI/12.0;
108-
109-
tm << cos(theta)*cos(gamma),-cos(theta)*sin(gamma),sin(theta), 1, //
110-
cos(alpha)*sin(gamma)+sin(alpha)*sin(theta)*cos(gamma),cos(alpha)*cos(gamma)-sin(alpha)*sin(theta)*sin(gamma),-sin(alpha)*cos(theta), 2, //
111-
sin(alpha)*sin(gamma)-cos(alpha)*sin(theta)*cos(gamma),cos(alpha)*sin(theta)*sin(gamma)+sin(alpha)*cos(gamma),cos(alpha)*cos(theta), 3, //
112-
0, 0, 0, 1;
116+
double alpha = M_PI / 4.0;
117+
double theta = M_PI / 6.0;
118+
double gamma = M_PI / 12.0;
119+
120+
tm << cos(theta) * cos(gamma), -cos(theta) * sin(gamma), sin(theta), 1, //
121+
//
122+
cos(alpha) * sin(gamma) + sin(alpha) * sin(theta) * cos(gamma), //
123+
cos(alpha) * cos(gamma) - sin(alpha) * sin(theta) * sin(gamma), //
124+
-sin(alpha) * cos(theta), 2, //
125+
//
126+
sin(alpha) * sin(gamma) - cos(alpha) * sin(theta) * cos(gamma), //
127+
cos(alpha) * sin(theta) * sin(gamma) + sin(alpha) * cos(gamma), //
128+
cos(alpha) * cos(theta), 3, //
129+
0, 0, 0, 1;
113130

114131
Eigen::Affine3d T(tm);
115132

@@ -251,24 +268,26 @@ TEST_F(EigenBufferTransform, Vector)
251268

252269
TEST_F(EigenBufferTransform, Quaternion)
253270
{
254-
using namespace Eigen;
255271
// rotated by -90° around y
256272
// 0, 0, -1
257273
// 0, 1, 0,
258274
// 1, 0, 0
259-
const tf2::Stamped<Quaterniond> q1 {{Quaterniond(AngleAxisd(-0.5 * M_PI, Vector3d::UnitY()))},
275+
const tf2::Stamped<Eigen::Quaterniond> q1 {{Eigen::Quaterniond(
276+
Eigen::AngleAxisd(
277+
-0.5 * M_PI,
278+
Eigen::Vector3d::UnitY()))},
260279
tf2::toMsg(tf2::timeFromSec(2)), "A"};
261280

262281
// simple api
263-
const tf2::Stamped<Quaterniond> q_simple =
282+
const tf2::Stamped<Eigen::Quaterniond> q_simple =
264283
tf_buffer->transform(q1, "B", tf2::durationFromSec(2.0));
265284
EXPECT_NEAR(q_simple.x(), 0.707107, EPS);
266285
EXPECT_NEAR(q_simple.y(), 0, EPS);
267286
EXPECT_NEAR(q_simple.z(), -0.707107, EPS);
268287
EXPECT_NEAR(q_simple.w(), 0, EPS);
269288

270289
// advanced api
271-
const tf2::Stamped<Quaterniond> q_advanced = tf_buffer->transform(
290+
const tf2::Stamped<Eigen::Quaterniond> q_advanced = tf_buffer->transform(
272291
q1, "B", tf2::timeFromSec(2.0),
273292
"A", tf2::durationFromSec(3.0));
274293
EXPECT_NEAR(q_advanced.x(), 0.707107, EPS);

0 commit comments

Comments
 (0)