Skip to content

Commit 6ba3359

Browse files
committed
2 vector
1 parent 9af3c48 commit 6ba3359

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/modm/math/geometry/vector.hpp

+15-17
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,28 @@ class Vector : public std::array<T, N>
7777
constexpr Vector()
7878
{ this->fill(0); }
7979

80+
template <typename U>
81+
requires std::convertible_to<U, T>
82+
constexpr explicit Vector(U v)
83+
{ this->fill(modm::round_smart<T, U>(v)); }
84+
85+
template <typename U>
86+
constexpr Vector(const U (&arr)[N])
87+
{ std::transform(std::begin(arr), std::end(arr), this->begin(), [] (U v) { return modm::round_smart<T, U>(v); }); }
88+
8089
/**
8190
* @brief Multi purpose constructor.
8291
*
83-
* @param args scalars, Vectors and Arrays in your desired order
92+
* @param args Scalar type(s), modm::Vector(s) or std::array(s) in any order
8493
*/
8594
template <class... Args>
8695
constexpr Vector(Args... args)
8796
{
88-
// Is perfect forwarding required here?
97+
// Not sure if perfect forwarding is required here !?
8998
// assign<0>(std::forward<Args>(args)...);
9099
assign<0>(args...);
91100
}
92101

93-
template <typename U>
94-
requires std::convertible_to<U, T>
95-
constexpr explicit Vector(U v)
96-
{ this->fill(modm::round_smart<T, U>(v)); }
97-
98-
template <typename U>
99-
constexpr Vector(const U (&arr)[N])
100-
{
101-
std::transform(std::begin(arr), std::end(arr), this->begin(), [] (U v) { return modm::round_smart<T, U>(v); });
102-
}
103-
104102
template<typename U>
105103
[[deprecated("Use constructor instead!")]]
106104
Vector<U, N> convert() const
@@ -157,7 +155,7 @@ class Vector : public std::array<T, N>
157155
{
158156
Vector<U, N> res;
159157

160-
// no clue why, but RVO / Loop unrolling is not applied for this ...
158+
// no clue why, but RVO / Loop unrolling does not apply here ...
161159
// std::transform(this->begin(), this->end(), other.begin(), res.begin(), Func{});
162160

163161
// ... but this optimizes perfectly.
@@ -183,7 +181,7 @@ class Vector : public std::array<T, N>
183181
{
184182
Vector<U, N> res;
185183

186-
// no clue why, but RVO / Loop unrolling is not applied for this ...
184+
// no clue why, but RVO / Loop unrolling does not apply here ...
187185
// std::transform(this->begin(), this->end(), res.begin(), Func{});
188186

189187
// ... but this optimizes perfectly.
@@ -209,7 +207,7 @@ class Vector : public std::array<T, N>
209207
{
210208
Vector<U, N> res;
211209

212-
// no clue why, but RVO / Loop unrolling is not applied for this ...
210+
// no clue why, but RVO / Loop unrolling does not apply here ...
213211
// std::transform(this->begin(), this->end(), res.begin(), Func{});
214212

215213
// ... but this optimizes perfectly.
@@ -430,7 +428,7 @@ class Vector : public std::array<T, N>
430428
constexpr float getAngleTo(const Vector& other) const requires (N == 2)
431429
{ return (other - *this).getAngle(); }
432430

433-
// TODO implement as operator+=(Angle phi), operator-=(Angle phi) instead ??
431+
// TODO implement as operator+=(Angle phi), operator-=(Angle phi) ??
434432
constexpr Vector& rotate(float phi) requires (N == 2)
435433
{
436434
const float c = std::cos(phi);

0 commit comments

Comments
 (0)