Skip to content

Commit

Permalink
Merge branch 'hotfix/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
coord-e committed Jan 12, 2019
2 parents 0b3e529 + 18466f9 commit 7b77fd2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
6 changes: 5 additions & 1 deletion include/flom/effector_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

#include "flom/effector.hpp"

#include <boost/operators.hpp>

#include <optional>

namespace flom {

enum class CoordinateSystem { World, Local };

struct EffectorType {
struct EffectorType : boost::operators<EffectorType> {
private:
std::optional<CoordinateSystem> location_;
std::optional<CoordinateSystem> rotation_;
Expand All @@ -50,6 +52,8 @@ struct EffectorType {
bool is_compatible(const Effector &) const;
};

bool operator==(const EffectorType &, const EffectorType &);

} // namespace flom

#endif
6 changes: 5 additions & 1 deletion include/flom/effector_weight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#ifndef FLOM_EFFECTOR_WEIGHT_HPP
#define FLOM_EFFECTOR_WEIGHT_HPP

#include <boost/operators.hpp>

namespace flom {

class EffectorWeight {
class EffectorWeight : boost::operators<EffectorWeight> {
private:
double location_;
double rotation_;
Expand All @@ -41,6 +43,8 @@ class EffectorWeight {
void set_rotation(double);
};

bool operator==(const EffectorWeight &, const EffectorWeight &);

} // namespace flom

#endif
1 change: 1 addition & 0 deletions include/flom/motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Motion {
};

bool operator==(const Motion &, const Motion &);
bool operator!=(const Motion &, const Motion &);

} // namespace flom

Expand Down
4 changes: 4 additions & 0 deletions lib/effector_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ bool EffectorType::is_compatible(const Effector &e) const {
return loc_v == loc_t && rot_v == rot_t;
}

bool operator==(const EffectorType &v1, const EffectorType &v2) {
return v1.location() == v2.location() && v1.rotation() == v2.rotation();
}

} // namespace flom
4 changes: 4 additions & 0 deletions lib/effector_weight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ double EffectorWeight::validate_weight(double weight) {
return weight;
}

bool operator==(const EffectorWeight &v1, const EffectorWeight &v2) {
return v1.location() == v2.location() && v1.rotation() == v2.rotation();
}

} // namespace flom
4 changes: 3 additions & 1 deletion lib/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ KeyRange<std::string> Motion::effector_names() const {
bool operator==(const Motion &m1, const Motion &m2) {
return m1.impl->model_id == m2.impl->model_id &&
m1.impl->loop == m2.impl->loop &&
m1.impl->raw_frames == m2.impl->raw_frames;
m1.impl->raw_frames == m2.impl->raw_frames &&
m1.impl->effector_types == m2.impl->effector_types &&
m1.impl->effector_weights == m2.impl->effector_weights;
}

bool operator!=(const Motion &m1, const Motion &m2) { return !(m1 == m2); }
Expand Down
42 changes: 29 additions & 13 deletions test/generators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ template <> struct Arbitrary<flom::CoordinateSystem> {
}
};

template <> struct Arbitrary<flom::EffectorWeight> {
static auto arbitrary() -> decltype(auto) {
auto const g = gen::map(gen::inRange(0, 100), [](int i) { return static_cast<double>(i) / 100; });
return gen::construct<flom::EffectorWeight>(g, g);
}
};

template <> struct Arbitrary<flom::EffectorType> {
static auto arbitrary() -> decltype(auto) {
return gen::apply(
Expand Down Expand Up @@ -176,22 +183,30 @@ template <> struct Arbitrary<flom::Motion> {
static auto arbitrary() -> decltype(auto) {
return gen::apply(
[](std::string const &model_id, flom::LoopType loop, double fps, auto const& t) {
auto const& [joint_names, effector_types, frames] = t;
auto const& [joint_names, effector_types, frames, weights] = t;
flom::Motion m(joint_names, effector_types, model_id);
m.set_loop(loop);
unsigned i = 0;
for (auto const& [p, e] : frames) {
std::unordered_map<std::string, double> positions;
std::unordered_map<std::string, flom::Effector> effectors;
for(auto const& pair : boost::combine(joint_names, p)) {
positions.emplace(boost::get<0>(pair), boost::get<1>(pair));
{
unsigned i = 0;
for (auto const& [name, type] : effector_types) {
m.set_effector_weight(name, weights[i++]);
}
for(auto const& pair : boost::combine(effector_types, e)) {
auto const& [name, type] = boost::get<0>(pair);
auto const& eff = boost::get<1>(pair);
effectors.emplace(name, convert_effector(type, eff));
}
{
unsigned i = 0;
for (auto const& [p, e] : frames) {
std::unordered_map<std::string, double> positions;
std::unordered_map<std::string, flom::Effector> effectors;
for(auto const& pair : boost::combine(joint_names, p)) {
positions.emplace(boost::get<0>(pair), boost::get<1>(pair));
}
for(auto const& pair : boost::combine(effector_types, e)) {
auto const& [name, type] = boost::get<0>(pair);
auto const& eff = boost::get<1>(pair);
effectors.emplace(name, convert_effector(type, eff));
}
m.insert_keyframe(fps * i++, flom::Frame{positions, effectors});
}
m.insert_keyframe(fps * i++, flom::Frame{positions, effectors});
}
return m;
},
Expand All @@ -218,9 +233,10 @@ template <> struct Arbitrary<flom::Motion> {

auto effector_gen = gen::construct<flom::Effector>(gen::arbitrary<flom::Location>(), gen::arbitrary<flom::Rotation>());
auto effectors_gen = gen::container<std::vector<flom::Effector>>(num_effectors, effector_gen);
auto weights_gen = gen::container<std::vector<flom::EffectorWeight>>(num_effectors, gen::arbitrary<flom::EffectorWeight>());

auto frames_gen = gen::nonEmpty(gen::container<std::vector<std::pair<std::vector<double>, std::vector<flom::Effector>>>>(gen::pair(positions_gen, effectors_gen)));
return gen::tuple(joint_names_gen, effector_names_gen, frames_gen);
return gen::tuple(joint_names_gen, effector_names_gen, frames_gen, weights_gen);
}));
}
};
Expand Down

0 comments on commit 7b77fd2

Please sign in to comment.