diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index a92da34c4..a495f64d6 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -18,6 +18,7 @@ install(FILES ${MagnumMath_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Ma add_subdirectory(Algorithms) add_subdirectory(Geometry) +add_subdirectory(VectorFields) if(BUILD_TESTS) enable_testing() diff --git a/src/Math/VectorFields/CMakeLists.txt b/src/Math/VectorFields/CMakeLists.txt new file mode 100644 index 000000000..e70e0d132 --- /dev/null +++ b/src/Math/VectorFields/CMakeLists.txt @@ -0,0 +1,4 @@ +if(BUILD_TESTS) + enable_testing() + add_subdirectory(Test) +endif() diff --git a/src/Math/VectorFields/Function.h b/src/Math/VectorFields/Function.h new file mode 100644 index 000000000..de66cad55 --- /dev/null +++ b/src/Math/VectorFields/Function.h @@ -0,0 +1,89 @@ +#ifndef Magnum_Math_VectorFields_Function_h +#define Magnum_Math_VectorFields_Function_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace VectorFields { + +template class VariableValue { + VariableValue(const VariableValue&) = delete; + VariableValue(VariableValue&&) = delete; + VariableValue& operator=(const VariableValue&) = delete; + VariableValue& operator=(VariableValue&&) = delete; + + public: + static const char Character = character; + + inline constexpr VariableValue(T value): _value(value) {} + + inline constexpr operator T() const { return _value; } + + private: + T _value; +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template inline constexpr T extract() { + throw; + } + template inline constexpr T extract(const VariableValue& first, const U&...) { + return first; + } + template inline constexpr typename std::enable_if>::value, T>::type extract(const U&, const V&... next) { + return extract(next...); + } +} +#endif + +template class Variable { + public: + static const char Character = character; + + template T operator()(U... values) { + return Implementation::extract(values...); + } +}; + +template class UnaryOperator { + public: + UnaryOperator(const Operand& operand): operand(operand) {} + + template T operator()(U... values) { + return Functor()(operand(values...)); + } + + private: + Operand operand; +}; + +template class BinaryOperator { + public: + BinaryOperator(const Operand& left, const Operand& right) {} + + template T operator()(U... values) { + return Functor()(leftOperand(values...), rightOperand(values...)); + } + + protected: + LeftOperand leftOperand; + RightOperand rightOperand; +}; + +}}} + +#endif diff --git a/src/Math/VectorFields/Test/CMakeLists.txt b/src/Math/VectorFields/Test/CMakeLists.txt new file mode 100644 index 000000000..f937d46f4 --- /dev/null +++ b/src/Math/VectorFields/Test/CMakeLists.txt @@ -0,0 +1 @@ +corrade_add_test2(MathVectorFieldsFunctionTest FunctionTest.cpp) diff --git a/src/Math/VectorFields/Test/FunctionTest.cpp b/src/Math/VectorFields/Test/FunctionTest.cpp new file mode 100644 index 000000000..15a0c269b --- /dev/null +++ b/src/Math/VectorFields/Test/FunctionTest.cpp @@ -0,0 +1,36 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "FunctionTest.h" + +#include "Math/VectorFields/Function.h" + +CORRADE_TEST_MAIN(Magnum::Math::VectorFields::Test::FunctionTest) + +namespace Magnum { namespace Math { namespace VectorFields { namespace Test { + +FunctionTest::FunctionTest() { + addTests(&FunctionTest::extract); +} + +void FunctionTest::extract() { + VariableValue<'x', float> x(1.0f); + VariableValue<'y', float> y(-1.0f); + VariableValue<'z', float> z(10.0f); + + CORRADE_COMPARE((Implementation::extract<'y', float>(x, y, z)), -1.0f); +} + +}}}} diff --git a/src/Math/VectorFields/Test/FunctionTest.h b/src/Math/VectorFields/Test/FunctionTest.h new file mode 100644 index 000000000..2bf2e3b9a --- /dev/null +++ b/src/Math/VectorFields/Test/FunctionTest.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Math_VectorFields_Test_FunctionTest_h +#define Magnum_Math_VectorFields_Test_FunctionTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace VectorFields { namespace Test { + +class FunctionTest: public Corrade::TestSuite::Tester { + public: + FunctionTest(); + + void extract(); +}; + +}}}} + +#endif