Skip to content

Commit dbfded3

Browse files
committed
inlined basic constructors, getters and setters, typedef -> using
1 parent ec08ab3 commit dbfded3

File tree

11 files changed

+186
-614
lines changed

11 files changed

+186
-614
lines changed

src/modm/math/geometry/geometric_traits.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace modm
4949
{
5050
static const bool isValidType = true;
5151

52-
typedef float FloatType;
53-
typedef int16_t WideType;
52+
using FloatType = float;
53+
using WideType = int16_t;
5454

5555
static inline int8_t
5656
round(float value)
@@ -65,8 +65,8 @@ namespace modm
6565
{
6666
static const bool isValidType = true;
6767

68-
typedef float FloatType;
69-
typedef int16_t WideType;
68+
using FloatType = float;
69+
using WideType = int16_t;
7070

7171
static inline uint8_t
7272
round(float value)
@@ -80,8 +80,8 @@ namespace modm
8080
{
8181
static const bool isValidType = true;
8282

83-
typedef float FloatType;
84-
typedef int32_t WideType;
83+
using FloatType = float;
84+
using WideType = int32_t;
8585

8686
static inline int16_t
8787
round(float value)
@@ -95,12 +95,14 @@ namespace modm
9595
{
9696
static const bool isValidType = true;
9797

98-
typedef float FloatType;
98+
using FloatType = float;
99+
// using WideType = int64_t;
99100

101+
// OPTIMIZE only fall back to int32_t on avr architecture
100102
// Usually the range of a int32_t is big enough so that no
101103
// conversion to int64_t is required. This exception is made because
102104
// 64-bit operations are very, very slow on an AVR.
103-
typedef int32_t WideType;
105+
using WideType = int32_t;
104106

105107
static inline int32_t
106108
round(float value)
@@ -114,8 +116,8 @@ namespace modm
114116
{
115117
static const bool isValidType = true;
116118

117-
typedef float FloatType;
118-
typedef float WideType;
119+
using FloatType = float;
120+
using WideType = float;
119121

120122
static inline float
121123
round(float value)

src/modm/math/geometry/vector1.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ namespace modm
4040

4141
// basic constructors
4242
constexpr Vector() = default;
43-
constexpr Vector(T inX);
43+
constexpr Vector(T x) : x(x) {}
4444
constexpr Vector(const Matrix<T, 1, 1> &rhs);
4545

46-
inline void
47-
set(const T& x);
46+
// getters and setters
47+
void set(T x) { this->x = x; }
48+
void setX(T x) { this->x = x; }
4849

49-
inline void
50-
setX(const T& value);
51-
52-
inline const T&
53-
getX() const;
50+
T getX() const { return x; }
5451

52+
// other methods
5553
Vector& operator = (const Matrix<T, 1, 1> &rhs);
5654

5755
auto operator<=>(const Vector &) const = default;
@@ -99,8 +97,8 @@ namespace modm
9997
return rhs * lhs;
10098
}
10199

102-
typedef Vector<float, 1> Vector1f;
103-
typedef Vector<int16_t, 1> Vector1i;
100+
using Vector1f = Vector<float, 1>;
101+
using Vector1i = Vector<int16_t, 1>;
104102
}
105103

106104
#include "vector1_impl.hpp"

src/modm/math/geometry/vector1_impl.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,11 @@
1212
#pragma once
1313
#include "vector1.hpp"
1414

15-
template<typename T>
16-
constexpr modm::Vector<T, 1>::Vector(T inX) :
17-
x(inX)
18-
{}
19-
2015
template<typename T>
2116
constexpr modm::Vector<T, 1>::Vector(const modm::Matrix<T, 1, 1> &rhs) :
2217
x(*reinterpret_cast<const T*>(&rhs))
2318
{}
2419

25-
// ----------------------------------------------------------------------------
26-
template<typename T>
27-
void
28-
modm::Vector<T, 1>::set(const T& value)
29-
{ this->x = value; }
30-
31-
template<typename T>
32-
void
33-
modm::Vector<T, 1>::setX(const T& value)
34-
{ this->x = value; }
35-
36-
template<typename T>
37-
const T&
38-
modm::Vector<T, 1>::getX() const
39-
{ return this->x; }
40-
4120
// ----------------------------------------------------------------------------
4221
template<typename T>
4322
modm::Vector<T, 1>&

src/modm/math/geometry/vector2.hpp

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -52,65 +52,40 @@ namespace modm
5252
template<typename T>
5353
class Vector<T, 2>
5454
{
55-
friend class Location2D<T>;
56-
5755
public:
58-
typedef typename GeometricTraits<T>::WideType WideType;
59-
typedef typename GeometricTraits<T>::FloatType FloatType;
56+
using WideType = GeometricTraits<T>::WideType;
57+
using FloatType = GeometricTraits<T>::FloatType;
6058

6159
T x = 0, y = 0;
6260

6361
// basic constructors
6462
constexpr Vector() = default;
65-
constexpr Vector(const T& inX, const T& inY);
66-
constexpr Vector(const Vector<T, 1> &inX, const Vector<T, 1> &inY);
67-
constexpr Vector(const T &inX, const Vector<T, 1> &inY);
68-
constexpr Vector(const Vector<T, 1> &inX, const T &inY);
69-
constexpr explicit Vector(T inVal);
70-
constexpr Vector(const Matrix<T, 2, 1> &rhs);
71-
72-
inline void
73-
setX(const T& value);
63+
constexpr explicit Vector(T xy) : x(xy), y(xy) {}
64+
constexpr Vector(T x, T y) : x(x), y(y) {}
7465

75-
inline void
76-
setY(const T& value);
66+
template<typename U>
67+
constexpr Vector(const Vector<U, 2> &v) : x(v.x), y(v.y) {}
7768

78-
inline void
79-
set(const T& x, const T& y);
69+
constexpr Vector(Vector<T, 1> vx, Vector<T, 1> vy) : x(vx.x), y(vy.x) {}
70+
constexpr Vector(T x, Vector<T, 1> vy) : x(x), y(vy.x) {}
71+
constexpr Vector(Vector<T, 1> vx, T y) : x(vx.x), y(y) {}
8072

73+
// advanced constructors
74+
constexpr Vector(const Matrix<T, 2, 1> &rhs);
8175

82-
inline const T&
83-
getX() const;
76+
// getters and setters
77+
void set(const T x, const T y) { this->x = x; this->y = y; }
78+
void setX(const T x) { this->x = x; }
79+
void setY(const T y) { this->y = y; }
8480

85-
inline const T&
86-
getY() const;
81+
T getX() const { return x; }
82+
T getY() const { return y; }
8783

88-
/**
89-
* \brief Calculate length of the vector
90-
*/
91-
T
92-
getLength() const;
84+
// other methods
85+
T getLength() const;
86+
WideType getLengthSquared() const;
9387

94-
/**
95-
* \brief Calculate squared length of the vector
96-
*
97-
* This method is considerably faster than getLength() because it
98-
* doesn't need to calculate the square root.
99-
*
100-
* \return squared length (x*x + y*y)
101-
*/
102-
WideType
103-
getLengthSquared() const;
104-
105-
/**
106-
* \brief Calculate the absolute angle
107-
*
108-
* \code
109-
* atan2(y, x)
110-
* \endcode
111-
*/
112-
float
113-
getAngle() const;
88+
float getAngle() const;
11489

11590
/**
11691
* \brief Normalize length to 1
@@ -291,9 +266,9 @@ namespace modm
291266
operator * (float scale, const Vector<U, 2> &vector);
292267
};
293268

294-
typedef Vector<float, 2> Vector2f;
295-
typedef Vector<int16_t, 2> Vector2i;
296-
typedef Vector<uint16_t, 2> Vector2u;
269+
using Vector2f = Vector<float, 2>;
270+
using Vector2i = Vector<int16_t, 2>;
271+
using Vector2u = Vector<uint16_t, 2>;
297272

298273
// ------------------------------------------------------------------------
299274
// Global functions

0 commit comments

Comments
 (0)