Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapaspyros committed Feb 8, 2025
1 parent 6645d93 commit 2656478
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class CartesianTrajectory : public TrajectoryBase<CartesianTrajectoryPoint> {
* @throw EmptyStateException if point is empty
*/
explicit CartesianTrajectory(
const std::string& name, const CartesianState& point, const std::chrono::nanoseconds& duration
);
const std::string& name, const CartesianState& point, const std::chrono::nanoseconds& duration);

/**
* @brief Constructor with name, intial points, and durations provided
Expand All @@ -76,8 +75,7 @@ class CartesianTrajectory : public TrajectoryBase<CartesianTrajectoryPoint> {
*/
explicit CartesianTrajectory(
const std::string& name, const std::vector<CartesianState>& points,
const std::vector<std::chrono::nanoseconds>& durations
);
const std::vector<std::chrono::nanoseconds>& durations);

/**
* @brief Copy constructor of a CartesianTrajectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class JointTrajectory : public TrajectoryBase<JointTrajectoryPoint> {
*/
explicit JointTrajectory(
const std::string& name, const std::vector<JointState>& points,
const std::vector<std::chrono::nanoseconds>& durations
);
const std::vector<std::chrono::nanoseconds>& durations);

/**
* @brief Copy constructor of a JointTrajectory
Expand Down Expand Up @@ -173,8 +172,8 @@ class JointTrajectory : public TrajectoryBase<JointTrajectoryPoint> {
* @param reference_frame the joint names to check against
* @throw IncompatibleStatesException if a state has a different joint names
*/
void assert_compatible_joint_names(const std::vector<JointState>& states, const std::vector<std::string>& joint_names)
const;
void assert_compatible_joint_names(
const std::vector<JointState>& states, const std::vector<std::string>& joint_names) const;

std::vector<std::string> joint_names_;///< names of the joints
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ inline void TrajectoryBase<TrajectoryT>::assert_points_size(const std::vector<T>
template<typename TrajectoryT>
template<typename T>
inline void TrajectoryBase<TrajectoryT>::assert_points_durations_sizes_equal(
const std::vector<T>& points, const std::vector<std::chrono::nanoseconds>& durations
) const {
const std::vector<T>& points, const std::vector<std::chrono::nanoseconds>& durations) const {
if (points.size() != durations.size()) {
throw exceptions::IncompatibleSizeException(
"The size of the provided points and durations vectors are not equal (" + std::to_string(points.size())
Expand Down
24 changes: 8 additions & 16 deletions source/state_representation/src/trajectory/CartesianTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ CartesianTrajectory::CartesianTrajectory(const std::string& name, const std::str
}

CartesianTrajectory::CartesianTrajectory(
const std::string& name, const CartesianState& point, const std::chrono::nanoseconds& duration
)
const std::string& name, const CartesianState& point, const std::chrono::nanoseconds& duration)
: CartesianTrajectory(name, point.get_reference_frame()) {
this->add_point(point, duration);
}

CartesianTrajectory::CartesianTrajectory(
const std::string& name, const std::vector<CartesianState>& points,
const std::vector<std::chrono::nanoseconds>& durations
)
const std::vector<std::chrono::nanoseconds>& durations)
: CartesianTrajectory(name) {
this->assert_points_not_empty(points);
this->reference_frame_ = points[0].get_reference_frame();
Expand Down Expand Up @@ -71,8 +69,7 @@ void CartesianTrajectory::add_point(const CartesianState& point, const std::chro
}

void CartesianTrajectory::add_points(
const std::vector<CartesianState>& points, const std::vector<std::chrono::nanoseconds>& durations
) {
const std::vector<CartesianState>& points, const std::vector<std::chrono::nanoseconds>& durations) {
this->assert_points_not_empty(points);
this->assert_points_durations_sizes_equal(points, durations);
this->assert_not_contains_empty_state(points);
Expand All @@ -83,24 +80,21 @@ void CartesianTrajectory::add_points(
}

void CartesianTrajectory::insert_point(
const CartesianState& point, const std::chrono::nanoseconds& duration, unsigned int index
) {
const CartesianState& point, const std::chrono::nanoseconds& duration, unsigned int index) {
this->assert_not_contains_empty_state<CartesianState>({point});
this->assert_same_reference_frame({point}, this->reference_frame_);
this->TrajectoryBase<CartesianTrajectoryPoint>::insert_point(CartesianTrajectoryPoint(point, duration), index);
}

void CartesianTrajectory::set_point(
const CartesianState& point, const std::chrono::nanoseconds& duration, unsigned int index
) {
const CartesianState& point, const std::chrono::nanoseconds& duration, unsigned int index) {
this->assert_not_contains_empty_state<CartesianState>({point});
this->assert_same_reference_frame({point}, this->reference_frame_);
this->TrajectoryBase<CartesianTrajectoryPoint>::set_point(CartesianTrajectoryPoint(point, duration), index);
}

void CartesianTrajectory::set_points(
const std::vector<CartesianState>& points, const std::vector<std::chrono::nanoseconds>& durations
) {
const std::vector<CartesianState>& points, const std::vector<std::chrono::nanoseconds>& durations) {
this->assert_points_not_empty(points);
this->assert_points_size(points);
this->assert_points_durations_sizes_equal(points, durations);
Expand Down Expand Up @@ -130,12 +124,10 @@ void CartesianTrajectory::assert_same_reference_frame(const std::vector<Cartesia
}

void CartesianTrajectory::assert_same_reference_frame(
const std::vector<CartesianState>& states, const std::string& reference_frame
) const {
const std::vector<CartesianState>& states, const std::string& reference_frame) const {
if (!std::ranges::all_of(states, [&](const auto& state) { return state.get_reference_frame() == reference_frame; })) {
throw exceptions::IncompatibleReferenceFramesException(
"Incompatible reference frame " + states.front().get_reference_frame() + " and " + reference_frame
);
"Incompatible reference frame " + states.front().get_reference_frame() + " and " + reference_frame);
}
}
}// namespace state_representation
18 changes: 6 additions & 12 deletions source/state_representation/src/trajectory/JointTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ JointTrajectory::JointTrajectory(const std::string& name) : TrajectoryBase<Joint
}

JointTrajectory::JointTrajectory(
const std::string& name, const JointState& point, const std::chrono::nanoseconds& duration
)
const std::string& name, const JointState& point, const std::chrono::nanoseconds& duration)
: JointTrajectory(name) {
this->assert_points_not_empty<JointState>({point});
this->joint_names_ = point.get_names();
Expand All @@ -22,8 +21,7 @@ JointTrajectory::JointTrajectory(

JointTrajectory::JointTrajectory(
const std::string& name, const std::vector<JointState>& points,
const std::vector<std::chrono::nanoseconds>& durations
)
const std::vector<std::chrono::nanoseconds>& durations)
: JointTrajectory(name) {
this->assert_points_not_empty(points);
this->joint_names_ = points[0].get_names();
Expand Down Expand Up @@ -63,8 +61,7 @@ void JointTrajectory::add_point(const JointState& point, const std::chrono::nano
}

void JointTrajectory::add_points(
const std::vector<JointState>& points, const std::vector<std::chrono::nanoseconds>& durations
) {
const std::vector<JointState>& points, const std::vector<std::chrono::nanoseconds>& durations) {
this->assert_points_not_empty(points);
this->assert_points_durations_sizes_equal(points, durations);
this->assert_not_contains_empty_state(points);
Expand All @@ -75,8 +72,7 @@ void JointTrajectory::add_points(
}

void JointTrajectory::insert_point(
const JointState& point, const std::chrono::nanoseconds& duration, unsigned int index
) {
const JointState& point, const std::chrono::nanoseconds& duration, unsigned int index) {
this->assert_not_contains_empty_state<JointState>({point});
this->assert_compatible_joint_names({point}, this->joint_names_);
this->TrajectoryBase<JointTrajectoryPoint>::insert_point(JointTrajectoryPoint(point, duration), index);
Expand All @@ -89,8 +85,7 @@ void JointTrajectory::set_point(const JointState& point, const std::chrono::nano
}

void JointTrajectory::set_points(
const std::vector<JointState>& points, const std::vector<std::chrono::nanoseconds>& durations
) {
const std::vector<JointState>& points, const std::vector<std::chrono::nanoseconds>& durations) {
this->assert_points_not_empty(points);
this->assert_points_size(points);
this->assert_points_durations_sizes_equal(points, durations);
Expand Down Expand Up @@ -120,8 +115,7 @@ void JointTrajectory::assert_compatible_joint_names(const std::vector<JointState
}

void JointTrajectory::assert_compatible_joint_names(
const std::vector<JointState>& states, const std::vector<std::string>& joint_names
) const {
const std::vector<JointState>& states, const std::vector<std::string>& joint_names) const {
if (!std::ranges::all_of(states, [&](const auto& state) { return state.get_names() == joint_names; })) {
throw exceptions::IncompatibleStatesException("Incompatible joint names");
}
Expand Down
45 changes: 15 additions & 30 deletions source/state_representation/test/tests/test_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,48 +114,37 @@ TEST(TrajectoryTest, ConstructTrajectory) {
EXPECT_NO_THROW(CartesianTrajectory trajectory("foo"));
EXPECT_NO_THROW(CartesianTrajectory trajectory("foo", CartesianState::Random("foo"), std::chrono::nanoseconds(100)));
EXPECT_NO_THROW(
CartesianTrajectory trajectory("foo", {CartesianState::Random("foo")}, {std::chrono::nanoseconds(100)})
);
CartesianTrajectory trajectory("foo", {CartesianState::Random("foo")}, {std::chrono::nanoseconds(100)}));

EXPECT_THROW(
CartesianTrajectory trajectory("foo", CartesianState(), std::chrono::nanoseconds(100)),
exceptions::EmptyStateException
);
exceptions::EmptyStateException);
EXPECT_THROW(
CartesianTrajectory trajectory(
"foo", {CartesianState::Random("foo", "some_world"), CartesianState::Random("foo")},
{std::chrono::nanoseconds(100), std::chrono::nanoseconds(200)}
),
exceptions::IncompatibleReferenceFramesException
);
{std::chrono::nanoseconds(100), std::chrono::nanoseconds(200)}),
exceptions::IncompatibleReferenceFramesException);
EXPECT_THROW(
CartesianTrajectory trajectory(
"foo", {CartesianState::Random("foo"), CartesianState::Random("foo")}, {std::chrono::nanoseconds(100)}
),
exceptions::IncompatibleSizeException
);
"foo", {CartesianState::Random("foo"), CartesianState::Random("foo")}, {std::chrono::nanoseconds(100)}),
exceptions::IncompatibleSizeException);

// Joint trajectory
EXPECT_NO_THROW(JointTrajectory trajectory("foo"));
EXPECT_NO_THROW(JointTrajectory trajectory("foo", JointState::Random("foo", 25), std::chrono::nanoseconds(100)));
EXPECT_NO_THROW(JointTrajectory trajectory("foo", {JointState::Random("foo", 25)}, {std::chrono::nanoseconds(100)}));

EXPECT_THROW(
JointTrajectory trajectory("foo", JointState(), std::chrono::nanoseconds(100)), exceptions::EmptyStateException
);
JointTrajectory trajectory("foo", JointState(), std::chrono::nanoseconds(100)), exceptions::EmptyStateException);
EXPECT_THROW(
JointTrajectory trajectory(
"foo", {JointState::Random("foo", 25), JointState::Random("foo", 24)},
{std::chrono::nanoseconds(100), std::chrono::nanoseconds(200)}
),
exceptions::IncompatibleStatesException
);
{std::chrono::nanoseconds(100), std::chrono::nanoseconds(200)}),
exceptions::IncompatibleStatesException);
EXPECT_THROW(
JointTrajectory trajectory(
"foo", {JointState::Random("foo", 25), JointState::Random("foo", 25)}, {std::chrono::nanoseconds(100)}
),
exceptions::IncompatibleSizeException
);
"foo", {JointState::Random("foo", 25), JointState::Random("foo", 25)}, {std::chrono::nanoseconds(100)}),
exceptions::IncompatibleSizeException);
}

TYPED_TEST_P(TrajectoryTest, AddRemovePoints) {
Expand Down Expand Up @@ -220,16 +209,14 @@ TYPED_TEST_P(TrajectoryTest, AddRemovePoints) {
// additons and insertions of multiple points
std::vector<PointType> points = {point0, point1, point2};
std::vector<std::chrono::nanoseconds> durations = {
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)
};
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)};
EXPECT_NO_THROW(this->add_points(points, durations));
for (unsigned int i = 0; i < this->trajectory->get_size(); ++i) {
this->expect_equal(points[i], i, durations[i]);
}
std::vector<PointType> shuffled_points = {point2, point0, point1};
std::vector<std::chrono::nanoseconds> shuffled_durations = {
std::chrono::nanoseconds(30), std::chrono::nanoseconds(10), std::chrono::nanoseconds(20)
};
std::chrono::nanoseconds(30), std::chrono::nanoseconds(10), std::chrono::nanoseconds(20)};
EXPECT_NO_THROW(this->set_points(shuffled_points, shuffled_durations));
for (unsigned int i = 0; i < this->trajectory->get_size(); ++i) {
this->expect_equal(shuffled_points[i], i, shuffled_durations[i]);
Expand Down Expand Up @@ -274,8 +261,7 @@ TYPED_TEST_P(TrajectoryTest, Exceptions) {

std::vector<PointType> points = {point0, point1, point2};
std::vector<std::chrono::nanoseconds> durations = {
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)
};
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)};
EXPECT_NO_THROW(this->add_points(points, durations));

EXPECT_THROW(this->delete_point_index(10), std::out_of_range);
Expand Down Expand Up @@ -338,8 +324,7 @@ TYPED_TEST_P(TrajectoryTest, Getters) {

std::vector<PointType> points = {point0, point1, point2};
std::vector<std::chrono::nanoseconds> durations = {
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)
};
std::chrono::nanoseconds(10), std::chrono::nanoseconds(20), std::chrono::nanoseconds(30)};
EXPECT_NO_THROW(this->add_points(points, durations));
ASSERT_FALSE(this->trajectory->is_empty());
auto trajectory_points = this->trajectory->get_points();
Expand Down

0 comments on commit 2656478

Please sign in to comment.