1
1
/*
2
2
* Copyright (c) 2009-2011, Fabian Greif
3
3
* Copyright (c) 2012, Niklas Hauser
4
+ * Copyright (c) 2022, Thomas Sommer
4
5
*
5
6
* This file is part of the modm project.
6
7
*
10
11
*/
11
12
// ----------------------------------------------------------------------------
12
13
13
- #ifndef MODM_GEOMETRIC_TRAITS_HPP
14
- #define MODM_GEOMETRIC_TRAITS_HPP
14
+ #pragma once
15
15
16
+ #include < concepts>
16
17
#include < cmath>
17
- #include < stdint.h >
18
+ #include < limits >
18
19
#include < modm/architecture/utils.hpp>
20
+ #include < modm/math/utils/arithmetic_traits.hpp>
19
21
20
22
namespace modm
21
23
{
@@ -24,120 +26,42 @@ namespace modm
24
26
*
25
27
* \ingroup modm_math_geometry
26
28
* \author Fabian Greif
29
+ * \author Thomas Sommer
27
30
*/
28
31
template <typename T>
29
- struct GeometricTraits
30
- {
31
- static const bool isValidType = false ;
32
+ struct GeometricTraits ;
32
33
33
- /* *
34
- * \brief Round if converting from a floating point base to
35
- * a integer base.
36
- *
37
- * For T = \c float and \c double this method is specialized to return
38
- * the result directly without any rounding.
39
- */
40
- static inline T
41
- round (float value)
42
- {
43
- return ::round (value);
44
- }
45
- };
46
-
47
- template <>
48
- struct GeometricTraits <int8_t >
34
+ template <std::integral T>
35
+ struct GeometricTraits <T>
49
36
{
50
- static const bool isValidType = true ;
51
-
52
- typedef float FloatType;
53
- typedef int16_t WideType;
54
-
55
- static inline int8_t
56
- round (float value)
57
- {
58
- return ::round (value);
59
- }
60
- };
61
-
62
- // TODO is this useful?
63
- template <>
64
- struct GeometricTraits <uint8_t >
65
- {
66
- static const bool isValidType = true ;
67
-
68
- typedef float FloatType;
69
- typedef int16_t WideType;
37
+ [[deprecated(" Use an appropriate C++ concept instead!" )]]
38
+ static const bool isValidType = false ;
70
39
71
- static inline uint8_t
72
- round (float value)
73
- {
74
- return ::round (value);
75
- }
40
+ using FloatType = float ;
41
+ using WideType = modm::WideType<T>;
76
42
};
77
43
78
- template <>
79
- struct GeometricTraits <int16_t >
44
+ template <std::floating_point T >
45
+ struct GeometricTraits <T >
80
46
{
47
+ [[deprecated(" Use an appropriate C++ concept instead!" )]]
81
48
static const bool isValidType = true ;
82
49
83
- typedef float FloatType;
84
- typedef int32_t WideType;
85
-
86
- static inline int16_t
87
- round (float value)
88
- {
89
- return ::round (value);
90
- }
50
+ using FloatType = T;
51
+ using WideType = T;
91
52
};
92
53
54
+ #ifdef __AVR__
93
55
template <>
94
56
struct GeometricTraits <int32_t >
95
57
{
58
+ [[deprecated(" Use an appropriate C++ concept instead!" )]]
96
59
static const bool isValidType = true ;
97
60
98
- typedef float FloatType;
99
-
100
- // Usually the range of a int32_t is big enough so that no
61
+ using FloatType = float ;
101
62
// conversion to int64_t is required. This exception is made because
102
63
// 64-bit operations are very, very slow on an AVR.
103
- typedef int32_t WideType;
104
-
105
- static inline int32_t
106
- round (float value)
107
- {
108
- return ::round (value);
109
- }
110
- };
111
-
112
- template <>
113
- struct GeometricTraits <float >
114
- {
115
- static const bool isValidType = true ;
116
-
117
- typedef float FloatType;
118
- typedef float WideType;
119
-
120
- static inline float
121
- round (float value)
122
- {
123
- return value;
124
- }
64
+ using WideType = int32_t ;
125
65
};
126
-
127
- template <>
128
- struct GeometricTraits <double >
129
- {
130
- static const bool isValidType = true ;
131
-
132
- typedef double FloatType;
133
- typedef double WideType;
134
-
135
- static inline double
136
- round (double value)
137
- {
138
- return value;
139
- }
140
- };
141
- }
142
-
143
- #endif // MODM_GEOMETRIC_TRAITS_HPP
66
+ #endif
67
+ }
0 commit comments