Skip to content

Commit 5760b8b

Browse files
committed
replaced Vector<T, 2>::convert() with conceptual conversion constructor
1 parent a802a93 commit 5760b8b

File tree

5 files changed

+20
-65
lines changed

5 files changed

+20
-65
lines changed

src/modm/math/geometry/vector1.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ namespace modm
4343
constexpr Vector(T x) : x(x) {}
4444
constexpr Vector(const Matrix<T, 1, 1> &rhs);
4545

46+
// Use round() when constructing from float
47+
// TODO This may be extended to all other constuctors as well
48+
template<std::floating_point U>
49+
constexpr Vector(const Vector<U, 1> &v) : x(round(v.x)) {}
50+
4651
// getters and setters
4752
void set(T x) { this->x = x; }
4853
void setX(T x) { this->x = x; }

src/modm/math/geometry/vector2.cpp

-36
This file was deleted.

src/modm/math/geometry/vector2.hpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ namespace modm
6666
template<typename U>
6767
constexpr Vector(const Vector<U, 2> &v) : x(v.x), y(v.y) {}
6868

69+
// Use round() when constructing from float
70+
// TODO This may be extended to all other constuctors as well
71+
// DEPRICATED Replaces previously defined, specialized convert() methods below
72+
template<std::floating_point U>
73+
constexpr Vector(const Vector<U, 2> &v) : x(round(v.x)), y(round(v.y)) {}
74+
6975
constexpr Vector(Vector<T, 1> vx, Vector<T, 1> vy) : x(vx.x), y(vy.x) {}
7076
constexpr Vector(T x, Vector<T, 1> vy) : x(x), y(vy.x) {}
7177
constexpr Vector(Vector<T, 1> vx, T y) : x(vx.x), y(y) {}
@@ -297,33 +303,6 @@ namespace modm
297303
template<typename U>
298304
Vector<U, 2>
299305
operator / (float scale, const Vector<U, 2> &vector);
300-
301-
// ------------------------------------------------------------------------
302-
// Declaration of specialized methods
303-
// ------------------------------------------------------------------------
304-
305-
template<> template<>
306-
Vector<double, 2>
307-
Vector<float, 2>::convert() const;
308-
309-
template<> template<>
310-
Vector<float, 2>
311-
Vector<double, 2>::convert() const;
312-
313-
// round for everything that's not float => double or double => float
314-
template<> template<typename U>
315-
Vector<U, 2>
316-
Vector<float, 2>::convert() const
317-
{
318-
return Vector<U, 2>(round(this->x), round(this->y));
319-
}
320-
321-
template<> template<typename U>
322-
Vector<U, 2>
323-
Vector<double, 2>::convert() const
324-
{
325-
return Vector<U, 2>(round(this->x), round(this->y));
326-
}
327306
}
328307

329308
#include "vector2_impl.hpp"

src/modm/math/geometry/vector3.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ namespace modm
4646
constexpr explicit Vector(T xyz) : x(xyz), y(xyz), z(xyz) {}
4747
constexpr Vector(T x, T y, T z) : x(x), y(y), z(z) {}
4848

49-
template<typename U>
50-
constexpr Vector(const Vector<U, 3> &v) : x(v.x), y(v.y), z(v.z) {}
49+
// Use round() when constructing from float
50+
// TODO This may be extended to all other constuctors as well
51+
template<std::floating_point U>
52+
constexpr Vector(const Vector<U, 3> &v) : x(round(v.x)), y(round(v.y)), z(round(v.z)) {}
5153

5254
constexpr Vector(Vector<T, 1> vx, T y, T z) : x(vx.x), y(y), z(z) {}
5355
constexpr Vector(T x, Vector<T, 1> vy, T z) : x(x), y(vy.x), z(z) {}

src/modm/math/geometry/vector4.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ namespace modm
4545
constexpr explicit Vector(T xyzw) : x(xyzw), y(xyzw), z(xyzw), w(xyzw) {}
4646
constexpr Vector(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
4747

48+
// Use round() when constructing from float
49+
// TODO This may be extended to all other constuctors as well
50+
template<std::floating_point U>
51+
constexpr Vector(const Vector<U, 4> &v) : x(round(v.x)), y(round(v.y)), z(round(v.z)), w(round(v.w)) {}
52+
4853
constexpr Vector(Vector<T, 1> vx, Vector<T, 1> vy, Vector<T, 1> vz, Vector<T, 1> vw)
4954
: x(vx.x), y(vy.x), z(vz.x), w(vw.x) {}
5055
constexpr Vector(Vector<T, 1> vx, Vector<T, 1> vy, Vector<T, 1> vz, T w)

0 commit comments

Comments
 (0)