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

fix(lanelet2_extension): fix getAngleDifference #264

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "lanelet2_extension/regulatory_elements/detection_area.hpp"
#include "lanelet2_extension/regulatory_elements/no_stopping_area.hpp"

#include <tier4_autoware_utils/tier4_autoware_utils.hpp>

#include <geometry_msgs/msg/point.hpp>
#include <geometry_msgs/msg/pose.hpp>

Expand All @@ -45,6 +47,11 @@ namespace lanelet
{
namespace utils
{
inline double getAngleDifference(const double angle1, const double angle2)
taikitanaka3 marked this conversation as resolved.
Show resolved Hide resolved
{
const double diff_angle = std::abs(tier4_autoware_utils::normalizeRadian(angle1 - angle2));
return diff_angle;
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
}
namespace query
{
/**
Expand Down
12 changes: 0 additions & 12 deletions map/lanelet2_extension/lib/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "lanelet2_extension/utility/utilities.hpp"

#include <Eigen/Eigen>
#include <tier4_autoware_utils/tier4_autoware_utils.hpp>

#include <lanelet2_core/geometry/Lanelet.h>
#include <lanelet2_routing/RoutingGraph.h>
Expand All @@ -34,17 +33,6 @@
#include <vector>

using lanelet::utils::to2D;
namespace
{
double getAngleDifference(const double angle1, const double angle2)
{
const double normalized_angle1 = tier4_autoware_utils::normalizeRadian(angle1);
const double normalized_angle2 = tier4_autoware_utils::normalizeRadian(angle2);
const double diff_angle = std::fabs(normalized_angle1 - normalized_angle2);
return diff_angle;
}

} // namespace

namespace lanelet
{
Expand Down
45 changes: 45 additions & 0 deletions map/lanelet2_extension/test/src/test_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "lanelet2_extension/utility/query.hpp"
#include "tier4_autoware_utils/math/normalization.hpp"

#include <gtest/gtest.h>
#include <math.h>
Expand All @@ -24,6 +25,50 @@ using lanelet::Point3d;
using lanelet::Points3d;
using lanelet::utils::getId;

// Copyright 2020 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

TEST(normalizedAngleDifference, getAngleDifference)
{
using lanelet::utils::getAngleDifference;

constexpr double eps = 0.1;
constexpr double pi = M_PI;
constexpr double pi2 = 2.0 * M_PI;
// case normal
{
// abs diff
EXPECT_FLOAT_EQ(getAngleDifference(-pi, 0), pi);
// abs diff
EXPECT_FLOAT_EQ(getAngleDifference(pi, 0), pi);
}
// case inverse angle
{
// return normalized angle diff
EXPECT_FLOAT_EQ(getAngleDifference(-pi - eps, pi), eps);
// return 0 if same direction
EXPECT_FLOAT_EQ(getAngleDifference(-pi, pi), 0);
}
// case more than 2PI angle
{
// return normalized angle diff
EXPECT_FLOAT_EQ(getAngleDifference(-pi2 - eps, pi2), eps);
// return pi if invert direction
EXPECT_FLOAT_EQ(getAngleDifference(-pi2, pi), pi);
}
}

class TestSuite : public ::testing::Test
{
public:
Expand Down