diff --git a/src/Magnum/Math/Bezier.h b/src/Magnum/Math/Bezier.h index 106de6efd..541df4750 100644 --- a/src/Magnum/Math/Bezier.h +++ b/src/Magnum/Math/Bezier.h @@ -224,5 +224,59 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili }} +namespace Corrade { namespace Utility { + +/** @configurationvalue{Magnum::Math::Bezier} */ +template struct ConfigurationValue> { + ConfigurationValue() = delete; + + /** @brief Writes elements separated with spaces */ + static std::string toString(const Magnum::Math::Bezier& value, ConfigurationValueFlags flags) { + std::string output; + + for(std::size_t o = 0; o != order + 1; ++o) { + for(std::size_t i = 0; i != dimensions; ++i) { + if(!output.empty()) output += ' '; + output += ConfigurationValue::toString(value[o][i], flags); + } + } + + return output; + } + + /** @brief Reads elements separated with whitespace */ + static Magnum::Math::Bezier fromString(const std::string& stringValue, ConfigurationValueFlags flags) { + Magnum::Math::Bezier result; + + std::size_t oldpos = 0, pos = std::string::npos, i = 0; + do { + pos = stringValue.find(' ', oldpos); + std::string part = stringValue.substr(oldpos, pos-oldpos); + + if(!part.empty()) { + result[i/dimensions][i%dimensions] = ConfigurationValue::fromString(part, flags); + ++i; + } + + oldpos = pos+1; + } while(pos != std::string::npos); + + return result; + } +}; + +#if !defined(DOXYGEN_GENERATING_OUTPUT) && !defined(__MINGW32__) +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +#endif + +}} + #endif diff --git a/src/Magnum/Math/Test/BezierTest.cpp b/src/Magnum/Math/Test/BezierTest.cpp index bd15fcd67..112962aa6 100644 --- a/src/Magnum/Math/Test/BezierTest.cpp +++ b/src/Magnum/Math/Test/BezierTest.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "Magnum/Math/Bezier.h" #include "Magnum/Math/Vector2.h" @@ -46,6 +47,7 @@ struct BezierTest : Corrade::TestSuite::Tester { void lerpCubic(); void debug(); + void configuration(); }; BezierTest::BezierTest() { @@ -54,7 +56,8 @@ BezierTest::BezierTest() { &BezierTest::lerpQuadratic, &BezierTest::lerpCubic, - &BezierTest::debug}); + &BezierTest::debug, + &BezierTest::configuration}); } void BezierTest::implicitConstructor() { @@ -91,6 +94,17 @@ void BezierTest::debug() { CORRADE_COMPARE(out.str(), "Bezier({0, 1}, {1.5, -0.3}, {2.1, 0.5}, {0, 2})\n"); } +void BezierTest::configuration() { + Corrade::Utility::Configuration c; + + CubicBezier2D bezier{Vector2{0.0f, 1.0f}, Vector2{1.5f, -0.3f}, Vector2{2.1f, 0.5f}, Vector2{0.0f, 2.0f}}; + std::string value("0 1 1.5 -0.3 2.1 0.5 0 2"); + + c.setValue("bezier", bezier); + CORRADE_COMPARE(c.value("bezier"), value); + CORRADE_COMPARE(c.value("bezier"), bezier); +} + }}} CORRADE_TEST_MAIN(Magnum::Math::Test::BezierTest) diff --git a/src/Magnum/Math/instantiation.cpp b/src/Magnum/Math/instantiation.cpp index 1a56c4e79..483f138fa 100644 --- a/src/Magnum/Math/instantiation.cpp +++ b/src/Magnum/Math/instantiation.cpp @@ -31,6 +31,15 @@ namespace Corrade { namespace Utility { #ifndef DOXYGEN_GENERATING_OUTPUT +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; + template struct ConfigurationValue>; template struct ConfigurationValue>; template struct ConfigurationValue>;