Skip to content

Commit

Permalink
Code format: distance (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Apr 15, 2017
1 parent 6740dbc commit 1accfe6
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IncludeCategories:
Priority: 1
- Regex: '^(<|")aikido/' # Aikido headers
Priority: 3
- Regex: '^(<[a-z]+)' # dependency headers
- Regex: '^(<[A-z]+)' # dependency headers
Priority: 2
- Regex: '^".*' # headers relative to this project
Priority: 4
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ endfunction()
# TODO: Temporarily split header list per subdirectories.
file(GLOB_RECURSE headers_planner "${CMAKE_SOURCE_DIR}/include/aikido/planner/*.hpp")
file(GLOB_RECURSE headers_util "${CMAKE_SOURCE_DIR}/include/aikido/util/*.hpp")
file(GLOB_RECURSE headers_distance "${CMAKE_SOURCE_DIR}/include/aikido/distance/*.hpp")
format_add_sources(${headers_planner})
format_add_sources(${headers_util})
format_add_sources(${headers_distance})

#==============================================================================
# Helper functions.
Expand Down
2 changes: 1 addition & 1 deletion cmake/Findactionlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ find_package(PkgConfig QUIET REQUIRED)

# Check to see if pkgconfig is installed.
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
pkg_check_modules(PC_actionlib actionlib QUIET REQUIRED)
pkg_check_modules(PC_actionlib actionlib QUIET)

# Include directories
find_path(actionlib_INCLUDE_DIRS
Expand Down
2 changes: 1 addition & 1 deletion cmake/Findcontrol_msgs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ find_package(PkgConfig QUIET REQUIRED)

# Check to see if pkgconfig is installed.
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
pkg_check_modules(PC_control_msgs control_msgs QUIET REQUIRED)
pkg_check_modules(PC_control_msgs control_msgs QUIET)

# Include directories
find_path(control_msgs_INCLUDE_DIRS
Expand Down
13 changes: 7 additions & 6 deletions include/aikido/distance/DistanceMetric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include "../statespace/StateSpace.hpp"

namespace aikido
{
namespace distance
{
namespace aikido {
namespace distance {

/// Implements a distance metric defined on a StateSpace
class DistanceMetric
{
Expand All @@ -29,6 +28,8 @@ class DistanceMetric
};

using DistanceMetricPtr = std::shared_ptr<DistanceMetric>;
}
}

} // namespace distance
} // namespace aikido

#endif
14 changes: 7 additions & 7 deletions include/aikido/distance/RnEuclidean.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef AIKIDO_DISTANCE_EUCLIDEANDISTANCEMETRIC_HPP_
#define AIKIDO_DISTANCE_EUCLIDEANDISTANCEMETRIC_HPP_

#include "DistanceMetric.hpp"
#include "../statespace/Rn.hpp"
#include "DistanceMetric.hpp"

namespace aikido {
namespace distance {

namespace aikido
{
namespace distance
{
/// Implements a Euclidean distance metric
template <int N>
class REuclidean : public DistanceMetric
Expand All @@ -23,8 +22,9 @@ class REuclidean : public DistanceMetric
/// Computes Euclidean distance between two states.
/// \param _state1 The first state (type Rn::State)
/// \param _state2 The second state (type Rn::State)
double distance(const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;
double distance(
const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;

private:
std::shared_ptr<statespace::R<N>> mStateSpace;
Expand Down
26 changes: 14 additions & 12 deletions include/aikido/distance/SO2Angular.hpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
#ifndef AIKIDO_DISTANCE_ANGULARDISTANCEMETRIC_HPP_
#define AIKIDO_DISTANCE_ANGULARDISTANCEMETRIC_HPP_

#include "DistanceMetric.hpp"
#include "../statespace/SO2.hpp"
#include "DistanceMetric.hpp"

namespace aikido {
namespace distance {

namespace aikido
{
namespace distance
{
/// Computes the shortest distance between two angles in SO(2)
class SO2Angular : public DistanceMetric
{
public:
/// Constructor.
/// \param _space The SO2 this distance metric operates on
explicit SO2Angular(
std::shared_ptr<statespace::SO2> _space);
explicit SO2Angular(std::shared_ptr<statespace::SO2> _space);

// Documentation inherited
statespace::StateSpacePtr getStateSpace() const override;

/// Computes shortest distance between two angles. (return value between 0 and pi)
/// Computes shortest distance between two angles. (return value between 0 and
/// pi)
/// \param _state1 The first state (type: SO2::State)
/// \param _state2 The second state (type: SO2::State)
double distance(const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;
double distance(
const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;

private:
std::shared_ptr<statespace::SO2> mStateSpace;
};
}
}

} // namespace distance
} // namespace aikido

#endif
23 changes: 12 additions & 11 deletions include/aikido/distance/SO3Angular.hpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#ifndef AIKIDO_DISTANCE_GEODESICDISTANCEMETRIC_HPP_
#define AIKIDO_DISTANCE_GEODESICDISTANCEMETRIC_HPP_

#include "DistanceMetric.hpp"
#include "../statespace/SO3.hpp"
#include "DistanceMetric.hpp"

namespace aikido {
namespace distance {

namespace aikido
{
namespace distance
{
/// Implements a distance metric on SO(3)
class SO3Angular : public DistanceMetric
{
public:
/// Constructor.
/// \param _space The SO3 this distance metric operates on
explicit SO3Angular(
std::shared_ptr<statespace::SO3> _space);
explicit SO3Angular(std::shared_ptr<statespace::SO3> _space);

// Documentation inherited
statespace::StateSpacePtr getStateSpace() const override;

/// Computes distance (in radians) between the two states
/// \param _state1 The first state (type SO3::State)
/// \param _state2 The second state (type SO3::State)
double distance(const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;
double distance(
const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;

private:
std::shared_ptr<statespace::SO3> mStateSpace;
};
}
}

} // namespace distance
} // namespace aikido

#endif
31 changes: 17 additions & 14 deletions include/aikido/distance/Weighted.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef AIKIDO_DISTANCE_WEIGHTEDDISTANCEMETRIC_HPP_
#define AIKIDO_DISTANCE_WEIGHTEDDISTANCEMETRIC_HPP_

#include "DistanceMetric.hpp"
#include "../statespace/CartesianProduct.hpp"
#include "DistanceMetric.hpp"

namespace aikido {
namespace distance {

namespace aikido
{
namespace distance
{
/// Implements a distance metric on a CartesianProduct. This metric computes
/// the weighted
/// sum of distances on the individual components of the statespace.
Expand All @@ -18,18 +17,19 @@ class Weighted : public DistanceMetric
/// \param _space The state space
/// \param _metrics A vector containing one element for every component of the
/// CartesianProduct
Weighted(std::shared_ptr<statespace::CartesianProduct> _space,
std::vector<DistanceMetricPtr> _metrics);
Weighted(
std::shared_ptr<statespace::CartesianProduct> _space,
std::vector<DistanceMetricPtr> _metrics);

/// Constructor.
/// \param _space The state space
/// \param _metrics A vector containing one element for every component of the
/// CartesianProduct. The first element of every pair in the vector is the
/// metric and the second is the weight to be applied to the metric. The
/// weights must all be positive.
Weighted(std::shared_ptr<statespace::CartesianProduct> _space,
std::vector<std::pair<DistanceMetricPtr, double>> _metrics);

Weighted(
std::shared_ptr<statespace::CartesianProduct> _space,
std::vector<std::pair<DistanceMetricPtr, double>> _metrics);

// Documentation inherited
statespace::StateSpacePtr getStateSpace() const override;
Expand All @@ -38,13 +38,16 @@ class Weighted : public DistanceMetric
/// of distances between their matching subcomponents.
/// \param _state1 The first state (type CartesianProduct::State)
/// \param _state2 The second state (type CartesianProduct::State)
double distance(const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;
double distance(
const statespace::StateSpace::State* _state1,
const statespace::StateSpace::State* _state2) const override;

private:
std::shared_ptr<statespace::CartesianProduct> mStateSpace;
std::vector<std::pair<DistanceMetricPtr, double>> mMetrics;
};
}
}

} // namespace distance
} // namespace aikido

#endif
10 changes: 4 additions & 6 deletions include/aikido/distance/defaults.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef AIKIDO_DISTANCE_DISTANCEMETRICDEFAULTS_HPP_
#define AIKIDO_DISTANCE_DISTANCEMETRICDEFAULTS_HPP_

#include "DistanceMetric.hpp"
#include "../statespace/StateSpace.hpp"
#include "DistanceMetric.hpp"

namespace aikido
{
namespace distance
{
namespace aikido {
namespace distance {
/// Creates a DistanceMetric that is appropriate for the statespace of type
/// Space
/// \param _sspace The StateSpace the distance metric will operator on
template <class Space>
std::unique_ptr<DistanceMetric> createDistanceMetricFor(
std::shared_ptr<Space> _sspace);

/// Creates a DistanceMetric that is appropriate for the statespace.
/// Creates a DistanceMetric that is appropriate for the statespace.
/// \param _sspace The StateSpace the distance metric will operator on
std::unique_ptr<DistanceMetric> createDistanceMetric(
statespace::StateSpacePtr _sspace);
Expand Down
23 changes: 9 additions & 14 deletions include/aikido/distance/detail/RnEuclidean-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@ namespace aikido {
namespace distance {

//==============================================================================
extern template
class REuclidean<0>;
extern template class REuclidean<0>;

extern template
class REuclidean<1>;
extern template class REuclidean<1>;

extern template
class REuclidean<2>;
extern template class REuclidean<2>;

extern template
class REuclidean<3>;
extern template class REuclidean<3>;

extern template
class REuclidean<6>;
extern template class REuclidean<6>;

extern template
class REuclidean<Eigen::Dynamic>;
extern template class REuclidean<Eigen::Dynamic>;

//=============================================================================
template <int N>
REuclidean<N>::REuclidean(std::shared_ptr<statespace::R<N>> _space)
: mStateSpace(std::move(_space))
: mStateSpace(std::move(_space))
{
if (mStateSpace == nullptr) {
if (mStateSpace == nullptr)
{
throw std::invalid_argument("Rn is nullptr.");
}
}
Expand Down
43 changes: 21 additions & 22 deletions include/aikido/distance/detail/defaults-impl.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "../Weighted.hpp"
#include "../SO2Angular.hpp"
#include "../SO3Angular.hpp"
#include "../RnEuclidean.hpp"
#include <dart/common/StlHelpers.hpp>
#include "../../statespace/CartesianProduct.hpp"
#include "../../statespace/Rn.hpp"
#include "../../statespace/SO2.hpp"
#include "../../statespace/SO3.hpp"
#include "../../statespace/Rn.hpp"
#include "../../statespace/CartesianProduct.hpp"
#include "../../util/metaprogramming.hpp"
#include <dart/common/StlHelpers.hpp>
#include "../RnEuclidean.hpp"
#include "../SO2Angular.hpp"
#include "../SO3Angular.hpp"
#include "../Weighted.hpp"

namespace aikido {
namespace distance {
Expand All @@ -18,7 +18,9 @@ using Ptr = std::unique_ptr<DistanceMetric>;

//=============================================================================
template <class Space>
struct createDistanceMetricFor_impl {};
struct createDistanceMetricFor_impl
{
};

//=============================================================================
template <>
Expand Down Expand Up @@ -110,22 +112,19 @@ struct createDistanceMetricFor_impl<statespace::CartesianProduct>
metrics.emplace_back(std::move(metric));
}

return make_unique<Weighted>(
std::move(_sspace), std::move(metrics));
return make_unique<Weighted>(std::move(_sspace), std::move(metrics));
}
};

//=============================================================================
using SupportedStateSpaces = util::type_list<
statespace::CartesianProduct,
statespace::R0,
statespace::R1,
statespace::R2,
statespace::R3,
statespace::R6,
statespace::SO2,
statespace::SO3
>;
using SupportedStateSpaces = util::type_list<statespace::CartesianProduct,
statespace::R0,
statespace::R1,
statespace::R2,
statespace::R3,
statespace::R6,
statespace::SO2,
statespace::SO3>;

} // namespace detail

Expand All @@ -137,8 +136,8 @@ std::unique_ptr<DistanceMetric> createDistanceMetricFor(
if (_sspace == nullptr)
throw std::invalid_argument("_sspace is null.");

return detail::createDistanceMetricFor_impl<Space>
::create(std::move(_sspace));
return detail::createDistanceMetricFor_impl<Space>::create(
std::move(_sspace));
}

} // namespace distance
Expand Down
Loading

0 comments on commit 1accfe6

Please sign in to comment.