11/*
22 * Copyright (c) 2009-2011, Fabian Greif
33 * Copyright (c) 2012, Niklas Hauser
4+ * Copyright (c) 2022, 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 >
18+ #include < limits >
1819#include < modm/architecture/utils.hpp>
20+ #include < modm/math/utils/arithmetic_traits.hpp>
1921
2022namespace modm
2123{
@@ -24,120 +26,42 @@ namespace modm
2426 *
2527 * \ingroup modm_math_geometry
2628 * \author Fabian Greif
29+ * \author Thomas Sommer
2730 */
2831 template <typename T>
29- struct GeometricTraits
30- {
31- static const bool isValidType = false ;
32+ struct GeometricTraits ;
3233
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>
4936 {
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 ;
7039
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>;
7642 };
7743
78- template <>
79- struct GeometricTraits <int16_t >
44+ template <std::floating_point T >
45+ struct GeometricTraits <T >
8046 {
47+ [[deprecated(" Use an appropriate C++ concept instead!" )]]
8148 static const bool isValidType = true ;
8249
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;
9152 };
9253
54+ #ifdef __AVR__
9355 template <>
9456 struct GeometricTraits <int32_t >
9557 {
58+ [[deprecated(" Use an appropriate C++ concept instead!" )]]
9659 static const bool isValidType = true ;
9760
98- typedef float FloatType;
99-
100- // Usually the range of a int32_t is big enough so that no
61+ using FloatType = float ;
10162 // conversion to int64_t is required. This exception is made because
10263 // 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 ;
12565 };
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