From ac34096d03a156d000506dc23e9281d97d7ace66 Mon Sep 17 00:00:00 2001 From: Hiroki OTA Date: Tue, 23 Aug 2022 17:18:52 +0900 Subject: [PATCH] refactor(tier4_autoware_utils): apply clang-tidy (#1660) * refactor(tier4_autoware_utils): apply clang-tidy Signed-off-by: h-ohta * ci(pre-commit): autofix Signed-off-by: h-ohta Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../geometry/boost_polygon_utils.hpp | 1 - .../geometry/geometry.hpp | 21 ++++++++----------- .../geometry/pose_deviation.hpp | 6 +++--- .../src/geometry/boost_polygon_utils.cpp | 4 ++-- .../src/geometry/test_boost_polygon_utils.cpp | 2 -- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/boost_polygon_utils.hpp b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/boost_polygon_utils.hpp index afafa86884fba..835f0c37d3031 100644 --- a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/boost_polygon_utils.hpp +++ b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/boost_polygon_utils.hpp @@ -28,7 +28,6 @@ namespace tier4_autoware_utils { -namespace bg = boost::geometry; bool isClockwise(const Polygon2d & polygon); Polygon2d inverseClockwise(const Polygon2d & polygon); diff --git a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/geometry.hpp b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/geometry.hpp index 68062da7941db..115b544726bdf 100644 --- a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/geometry.hpp +++ b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/geometry.hpp @@ -421,7 +421,7 @@ inline geometry_msgs::msg::Transform pose2transform(const geometry_msgs::msg::Po } inline geometry_msgs::msg::TransformStamped pose2transform( - const geometry_msgs::msg::PoseStamped & pose, const std::string child_frame_id) + const geometry_msgs::msg::PoseStamped & pose, const std::string & child_frame_id) { geometry_msgs::msg::TransformStamped transform; transform.header = pose.header; @@ -453,7 +453,7 @@ inline Point2d transformPoint( } inline Eigen::Vector3d transformPoint( - const Eigen::Vector3d point, const geometry_msgs::msg::Pose pose) + const Eigen::Vector3d & point, const geometry_msgs::msg::Pose & pose) { geometry_msgs::msg::Transform transform; transform.translation.x = pose.position.x; @@ -466,7 +466,7 @@ inline Eigen::Vector3d transformPoint( } inline geometry_msgs::msg::Point transformPoint( - const geometry_msgs::msg::Point point, const geometry_msgs::msg::Pose pose) + const geometry_msgs::msg::Point & point, const geometry_msgs::msg::Pose & pose) { const Eigen::Vector3d vec = Eigen::Vector3d(point.x, point.y, point.z); auto transformed_vec = transformPoint(vec, pose); @@ -554,21 +554,21 @@ inline geometry_msgs::msg::Pose inverseTransformPose( // Transform point in world coordinates to local coordinates inline Eigen::Vector3d inverseTransformPoint( - const Eigen::Vector3d point, const geometry_msgs::msg::Pose pose) + const Eigen::Vector3d & point, const geometry_msgs::msg::Pose & pose) { const Eigen::Quaterniond q( pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z); const Eigen::Matrix3d R = q.normalized().toRotationMatrix(); const Eigen::Vector3d local_origin(pose.position.x, pose.position.y, pose.position.z); - const Eigen::Vector3d local_point = R.transpose() * point - R.transpose() * local_origin; + Eigen::Vector3d local_point = R.transpose() * point - R.transpose() * local_origin; return local_point; } // Transform point in world coordinates to local coordinates inline geometry_msgs::msg::Point inverseTransformPoint( - const geometry_msgs::msg::Point point, const geometry_msgs::msg::Pose pose) + const geometry_msgs::msg::Point & point, const geometry_msgs::msg::Pose & pose) { const Eigen::Vector3d local_vec = inverseTransformPoint(Eigen::Vector3d(point.x, point.y, point.z), pose); @@ -599,11 +599,7 @@ bool isDrivingForward(const Pose1 & src_pose, const Pose2 & dst_pose) // check the first point direction const double src_yaw = tf2::getYaw(getPose(src_pose).orientation); const double pose_direction_yaw = calcAzimuthAngle(getPoint(src_pose), getPoint(dst_pose)); - if (std::fabs(normalizeRadian(src_yaw - pose_direction_yaw)) < pi / 2.0) { - return true; - } - - return false; + return std::fabs(normalizeRadian(src_yaw - pose_direction_yaw)) < pi / 2.0; } /** @@ -700,7 +696,8 @@ geometry_msgs::msg::Pose calcInterpolatedPose( } } else { // Get orientation by spherical linear interpolation - tf2::Transform src_tf, dst_tf; + tf2::Transform src_tf; + tf2::Transform dst_tf; tf2::fromMsg(getPose(src_pose), src_tf); tf2::fromMsg(getPose(dst_pose), dst_tf); const auto & quaternion = tf2::slerp(src_tf.getRotation(), dst_tf.getRotation(), clamped_ratio); diff --git a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/pose_deviation.hpp b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/pose_deviation.hpp index cd9e109c5c9ed..32b4ba663fcd7 100644 --- a/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/pose_deviation.hpp +++ b/common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/pose_deviation.hpp @@ -24,9 +24,9 @@ namespace tier4_autoware_utils { struct PoseDeviation { - double lateral; - double longitudinal; - double yaw; + double lateral{0.0}; + double longitudinal{0.0}; + double yaw{0.0}; }; inline double calcLateralDeviation( diff --git a/common/tier4_autoware_utils/src/geometry/boost_polygon_utils.cpp b/common/tier4_autoware_utils/src/geometry/boost_polygon_utils.cpp index 7abb9c503cc30..f9ba0f537f07f 100644 --- a/common/tier4_autoware_utils/src/geometry/boost_polygon_utils.cpp +++ b/common/tier4_autoware_utils/src/geometry/boost_polygon_utils.cpp @@ -33,7 +33,7 @@ void appendPointToPolygon(Polygon2d & polygon, const geometry_msgs::msg::Point & bg::append(polygon.outer(), point); } -void appendPointToPolygon(Polygon2d & polygon, const Point2d point) +void appendPointToPolygon(Polygon2d & polygon, const Point2d & point) { bg::append(polygon.outer(), point); } @@ -160,7 +160,7 @@ Polygon2d toPolygon2d( } // NOTE: push back the first point in order to close polygon - if (polygon.outer().size() > 0) { + if (!polygon.outer().empty()) { appendPointToPolygon(polygon, polygon.outer().front()); } diff --git a/common/tier4_autoware_utils/test/src/geometry/test_boost_polygon_utils.cpp b/common/tier4_autoware_utils/test/src/geometry/test_boost_polygon_utils.cpp index 8d2af01ea703a..421e434c60e1e 100644 --- a/common/tier4_autoware_utils/test/src/geometry/test_boost_polygon_utils.cpp +++ b/common/tier4_autoware_utils/test/src/geometry/test_boost_polygon_utils.cpp @@ -19,8 +19,6 @@ #include -namespace bg = boost::geometry; - using tier4_autoware_utils::Polygon2d; namespace