diff --git a/include/flom/effector_type.hpp b/include/flom/effector_type.hpp index dae9bf6..939992d 100644 --- a/include/flom/effector_type.hpp +++ b/include/flom/effector_type.hpp @@ -22,13 +22,15 @@ #include "flom/effector.hpp" +#include + #include namespace flom { enum class CoordinateSystem { World, Local }; -struct EffectorType { +struct EffectorType : boost::operators { private: std::optional location_; std::optional rotation_; @@ -50,6 +52,8 @@ struct EffectorType { bool is_compatible(const Effector &) const; }; +bool operator==(const EffectorType &, const EffectorType &); + } // namespace flom #endif diff --git a/include/flom/effector_weight.hpp b/include/flom/effector_weight.hpp index b790b0c..84507f9 100644 --- a/include/flom/effector_weight.hpp +++ b/include/flom/effector_weight.hpp @@ -20,9 +20,11 @@ #ifndef FLOM_EFFECTOR_WEIGHT_HPP #define FLOM_EFFECTOR_WEIGHT_HPP +#include + namespace flom { -class EffectorWeight { +class EffectorWeight : boost::operators { private: double location_; double rotation_; @@ -41,6 +43,8 @@ class EffectorWeight { void set_rotation(double); }; +bool operator==(const EffectorWeight &, const EffectorWeight &); + } // namespace flom #endif diff --git a/include/flom/motion.hpp b/include/flom/motion.hpp index 4aa2552..77fec02 100644 --- a/include/flom/motion.hpp +++ b/include/flom/motion.hpp @@ -94,6 +94,7 @@ class Motion { }; bool operator==(const Motion &, const Motion &); +bool operator!=(const Motion &, const Motion &); } // namespace flom diff --git a/lib/effector_type.cpp b/lib/effector_type.cpp index ad1b497..34cbc01 100644 --- a/lib/effector_type.cpp +++ b/lib/effector_type.cpp @@ -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 diff --git a/lib/effector_weight.cpp b/lib/effector_weight.cpp index e546408..2fc630b 100644 --- a/lib/effector_weight.cpp +++ b/lib/effector_weight.cpp @@ -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 diff --git a/lib/motion.cpp b/lib/motion.cpp index 8eda401..206d9b5 100644 --- a/lib/motion.cpp +++ b/lib/motion.cpp @@ -246,7 +246,9 @@ KeyRange 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); } diff --git a/test/generators.hpp b/test/generators.hpp index 8bbbf71..8eaebe2 100644 --- a/test/generators.hpp +++ b/test/generators.hpp @@ -101,6 +101,13 @@ template <> struct Arbitrary { } }; +template <> struct Arbitrary { + static auto arbitrary() -> decltype(auto) { + auto const g = gen::map(gen::inRange(0, 100), [](int i) { return static_cast(i) / 100; }); + return gen::construct(g, g); + } +}; + template <> struct Arbitrary { static auto arbitrary() -> decltype(auto) { return gen::apply( @@ -176,22 +183,30 @@ template <> struct Arbitrary { 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 positions; - std::unordered_map 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 positions; + std::unordered_map 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; }, @@ -218,9 +233,10 @@ template <> struct Arbitrary { auto effector_gen = gen::construct(gen::arbitrary(), gen::arbitrary()); auto effectors_gen = gen::container>(num_effectors, effector_gen); + auto weights_gen = gen::container>(num_effectors, gen::arbitrary()); auto frames_gen = gen::nonEmpty(gen::container, std::vector>>>(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); })); } };