diff --git a/src/modm/math/geometry/location_2d.hpp b/src/modm/math/geometry/location_2d.hpp index c0a350e019..4b8e7d2920 100644 --- a/src/modm/math/geometry/location_2d.hpp +++ b/src/modm/math/geometry/location_2d.hpp @@ -43,6 +43,9 @@ namespace modm Location2D(const T& x, const T& y, const float& orientation); + template + constexpr Location2D(const Location2D &l) : position(l.position), orientation(l.orientation) {} + inline const Vector& getPosition() const; @@ -97,11 +100,6 @@ namespace modm Vector translated(const Vector& vector) const; - /// Convert between Location-objects with different base-types - template - Location2D - convert() const; - bool operator == (const Location2D &other) const; @@ -113,6 +111,8 @@ namespace modm friend IOStream& operator <<( IOStream&, const Location2D&); + // FIXME make friends + public: Vector position; float orientation; }; diff --git a/src/modm/math/geometry/location_2d_impl.hpp b/src/modm/math/geometry/location_2d_impl.hpp index 913449fcd7..bbec6937d0 100644 --- a/src/modm/math/geometry/location_2d_impl.hpp +++ b/src/modm/math/geometry/location_2d_impl.hpp @@ -135,14 +135,6 @@ modm::Location2D::translated(const Vector& vector) const return result; } -// ---------------------------------------------------------------------------- -template template -modm::Location2D -modm::Location2D::convert() const -{ - return Location2D(this->position.template convert(), this->orientation); -} - // ---------------------------------------------------------------------------- template bool diff --git a/src/modm/math/geometry/vector1.hpp b/src/modm/math/geometry/vector1.hpp index 13ef859f1e..b1b1e8e86e 100644 --- a/src/modm/math/geometry/vector1.hpp +++ b/src/modm/math/geometry/vector1.hpp @@ -43,6 +43,13 @@ namespace modm constexpr Vector(T x) : x(x) {} constexpr Vector(const Matrix &rhs); + template + constexpr Vector(const Vector &v) : x(v.x) {} + // Use round() when constructing from float + // TODO This may be extended to all other constuctors as well + template + constexpr Vector(const Vector &v) : x(round(v.x)) {} + // getters and setters void set(T x) { this->x = x; } void setX(T x) { this->x = x; } diff --git a/src/modm/math/geometry/vector2.cpp b/src/modm/math/geometry/vector2.cpp deleted file mode 100644 index 829f18cf2a..0000000000 --- a/src/modm/math/geometry/vector2.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010-2012, Fabian Greif - * Copyright (c) 2010, 2012, Martin Rosekeit - * Copyright (c) 2012, Georgi Grinshpun - * Copyright (c) 2012, Niklas Hauser - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -#include - -#include "vector2.hpp" - -namespace modm -{ - template<> - template<> - Vector - Vector::convert() const - { - return Vector(this->x, this->y); - } - - template<> - template<> - Vector - Vector::convert() const - { - return Vector(this->x, this->y); - } -} diff --git a/src/modm/math/geometry/vector2.hpp b/src/modm/math/geometry/vector2.hpp index ad217d049a..bcd2dc2633 100644 --- a/src/modm/math/geometry/vector2.hpp +++ b/src/modm/math/geometry/vector2.hpp @@ -65,6 +65,11 @@ namespace modm template constexpr Vector(const Vector &v) : x(v.x), y(v.y) {} + // Use round() when constructing from float + // TODO This may be extended to all other constuctors as well + // DEPRICATED Replaces previously defined, specialized convert() methods below + template + constexpr Vector(const Vector &v) : x(round(v.x)), y(round(v.y)) {} constexpr Vector(Vector vx, Vector vy) : x(vx.x), y(vy.x) {} constexpr Vector(T x, Vector vy) : x(x), y(vy.x) {} @@ -162,13 +167,6 @@ namespace modm WideType cross(const Vector& other) const; - /** - * \brief Convert between Point-objects with different base-types - */ - template - Vector - convert() const; - /** * \brief Returns a perpendicular copy of the vector * @@ -297,33 +295,6 @@ namespace modm template Vector operator / (float scale, const Vector &vector); - - // ------------------------------------------------------------------------ - // Declaration of specialized methods - // ------------------------------------------------------------------------ - - template<> template<> - Vector - Vector::convert() const; - - template<> template<> - Vector - Vector::convert() const; - - // round for everything that's not float => double or double => float - template<> template - Vector - Vector::convert() const - { - return Vector(round(this->x), round(this->y)); - } - - template<> template - Vector - Vector::convert() const - { - return Vector(round(this->x), round(this->y)); - } } #include "vector2_impl.hpp" \ No newline at end of file diff --git a/src/modm/math/geometry/vector2_impl.hpp b/src/modm/math/geometry/vector2_impl.hpp index 9488e607c2..0d57c94349 100644 --- a/src/modm/math/geometry/vector2_impl.hpp +++ b/src/modm/math/geometry/vector2_impl.hpp @@ -140,14 +140,6 @@ modm::Vector::cross(const modm::Vector& other) const static_cast(y) * static_cast(other.x)); } -// ---------------------------------------------------------------------------- -template template -modm::Vector -modm::Vector::convert() const -{ - return Vector(static_cast(x), static_cast(y)); -} - // ---------------------------------------------------------------------------- template modm::Vector diff --git a/src/modm/math/geometry/vector3.hpp b/src/modm/math/geometry/vector3.hpp index 267d878191..c7e70cdd67 100644 --- a/src/modm/math/geometry/vector3.hpp +++ b/src/modm/math/geometry/vector3.hpp @@ -48,6 +48,10 @@ namespace modm template constexpr Vector(const Vector &v) : x(v.x), y(v.y), z(v.z) {} + // Use round() when constructing from float + // TODO This may be extended to all other constuctors as well + template + constexpr Vector(const Vector &v) : x(round(v.x)), y(round(v.y)), z(round(v.z)) {} constexpr Vector(Vector vx, T y, T z) : x(vx.x), y(y), z(z) {} constexpr Vector(T x, Vector vy, T z) : x(x), y(vy.x), z(z) {} diff --git a/src/modm/math/geometry/vector4.hpp b/src/modm/math/geometry/vector4.hpp index 9c6062df7a..e973774826 100644 --- a/src/modm/math/geometry/vector4.hpp +++ b/src/modm/math/geometry/vector4.hpp @@ -45,6 +45,13 @@ namespace modm constexpr explicit Vector(T xyzw) : x(xyzw), y(xyzw), z(xyzw), w(xyzw) {} constexpr Vector(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} + template + constexpr Vector(const Vector &v) : x(v.x), y(v.y), z(v.z), w(v.w) {} + // Use round() when constructing from float + // TODO This may be extended to all other constuctors as well + template + constexpr Vector(const Vector &v) : x(round(v.x)), y(round(v.y)), z(round(v.z)), w(round(v.w)) {} + constexpr Vector(Vector vx, Vector vy, Vector vz, Vector vw) : x(vx.x), y(vy.x), z(vz.x), w(vw.x) {} constexpr Vector(Vector vx, Vector vy, Vector vz, T w) diff --git a/test/modm/math/geometry/location_2d_test.cpp b/test/modm/math/geometry/location_2d_test.cpp index b40322855f..bf1f769aef 100644 --- a/test/modm/math/geometry/location_2d_test.cpp +++ b/test/modm/math/geometry/location_2d_test.cpp @@ -110,11 +110,9 @@ Location2DTest::testMove() void Location2DTest::testConvert() { - modm::Location2D a( - modm::Vector(-10.65, 20.31), - M_PI); + modm::Location2D a({-10.65, 20.31}, M_PI); - modm::Location2D b = a.convert(); + modm::Location2D b(a); TEST_ASSERT_EQUALS(b.getX(), -11); TEST_ASSERT_EQUALS(b.getY(), 20); diff --git a/test/modm/math/geometry/vector2_test.cpp b/test/modm/math/geometry/vector2_test.cpp index c788deb84b..1f4cce3f7c 100644 --- a/test/modm/math/geometry/vector2_test.cpp +++ b/test/modm/math/geometry/vector2_test.cpp @@ -322,7 +322,7 @@ Vector2Test::testConversion() TEST_ASSERT_EQUALS(a.getX(), 12.763f); TEST_ASSERT_EQUALS(a.getY(), -13.3123f); - modm::Vector2i b = a.convert(); + modm::Vector2i b(a); TEST_ASSERT_EQUALS(b.getX(), 13); TEST_ASSERT_EQUALS(b.getY(), -13);