11/*
22 * Copyright (c) 2009-2011, Fabian Greif
33 * Copyright (c) 2012, Niklas Hauser
4+ * Copyright (c) 2021, Thomas Sommer
45 *
56 * This file is part of the modm project.
67 *
1011 */
1112// ----------------------------------------------------------------------------
1213
13- #ifndef MODM_GEOMETRIC_TRAITS_HPP
14- #define MODM_GEOMETRIC_TRAITS_HPP
14+ #pragma once
1515
16+ #include < concepts>
1617#include < cmath>
17- #include < stdint.h>
1818#include < modm/architecture/utils.hpp>
19+ #include < modm/math/utils/arithmetic_traits.hpp>
1920
2021namespace modm
2122{
@@ -26,123 +27,59 @@ namespace modm
2627 * \author Fabian Greif
2728 */
2829 template <typename T>
29- struct GeometricTraits
30- {
31- static const bool isValidType = false ;
32-
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 >
49- {
50- static const bool isValidType = true ;
51-
52- using FloatType = float ;
53- using WideType = int16_t ;
54-
55- static inline int8_t
56- round (float value)
57- {
58- return ::round (value);
59- }
60- };
30+ struct GeometricTraits ;
6131
62- // TODO is this useful?
63- template <>
64- struct GeometricTraits <uint8_t >
32+ template <std::integral T>
33+ struct GeometricTraits <T>
6534 {
66- static const bool isValidType = true ;
35+ // DEPRICATED Don't validate with isValidType, use requires modm::arithmetic<T>
36+ static const bool isValidType = false ;
6737
6838 using FloatType = float ;
69- using WideType = int16_t ;
39+ using WideType = modm::WideType<T> ;
7040
71- static inline uint8_t
41+ static inline T
7242 round (float value)
7343 {
7444 return ::round (value);
7545 }
7646 };
7747
78- template <>
79- struct GeometricTraits <int16_t >
48+ template <std::floating_point T >
49+ struct GeometricTraits <T >
8050 {
51+ // DEPRICATED Don't validate with isValidType, use requires modm::arithmetic<T>
8152 static const bool isValidType = true ;
8253
83- using FloatType = float ;
84- using WideType = int32_t ;
54+ using FloatType = T ;
55+ using WideType = T ;
8556
86- static inline int16_t
87- round (float value)
57+ static inline T
58+ round (T value)
8859 {
89- return :: round ( value) ;
60+ return value;
9061 }
9162 };
9263
64+ // FIXME only avr
65+ // %% if target == "avr"
9366 template <>
9467 struct GeometricTraits <int32_t >
9568 {
69+ // DEPRICATED Don't validate with isValidType, use requires modm::arithmetic<T>
9670 static const bool isValidType = true ;
9771
9872 using FloatType = float ;
99- // %% if target == "stm32"
100- // using WideType = int64_t;
101- // %% else if target == "avr"
102-
103- // OPTIMIZE only fall back to int32_t on avr architecture
10473 // Usually the range of a int32_t is big enough so that no
10574 // conversion to int64_t is required. This exception is made because
10675 // 64-bit operations are very, very slow on an AVR.
10776 using WideType = int32_t ;
108- // %% endif
10977
11078 static inline int32_t
11179 round (float value)
11280 {
11381 return ::round (value);
11482 }
11583 };
116-
117- template <>
118- struct GeometricTraits <float >
119- {
120- static const bool isValidType = true ;
121-
122- using FloatType = float ;
123- using WideType = float ;
124-
125- static inline float
126- round (float value)
127- {
128- return value;
129- }
130- };
131-
132- template <>
133- struct GeometricTraits <double >
134- {
135- static const bool isValidType = true ;
136-
137- using FloatType = double ;
138- using WideType = double ;
139-
140- static inline double
141- round (double value)
142- {
143- return value;
144- }
145- };
146- }
147-
148- #endif // MODM_GEOMETRIC_TRAITS_HPP
84+ // %% endif
85+ }
0 commit comments