Skip to content

Commit da75597

Browse files
committed
unsgined scaling
1 parent 649b37c commit da75597

File tree

11 files changed

+259
-235
lines changed

11 files changed

+259
-235
lines changed

src/modm/math/filter/s_curve_controller_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ modm::SCurveController<T>::update(T error, const T& speed)
113113
outputDecrement = std::sqrt(error * parameter.decreaseFactor * 2);
114114
}
115115

116-
output = modm::min(outputIncrement, outputDecrement);
116+
output = std::min(outputIncrement, outputDecrement);
117117
// TODO smooth breaking if the speedMaximum has changed to a lower value
118-
output = modm::min(output, parameter.speedMaximum);
118+
output = std::min(output, parameter.speedMaximum);
119119

120120
if (output < parameter.speedMinimum) {
121121
output = parameter.speedMinimum;

src/modm/math/utils/misc.hpp

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2011-2012, 2014-2015, Niklas Hauser
55
* Copyright (c) 2015, Sascha Schade
66
* Copyright (c) 2020, Christopher Durand
7+
* Copyright (c) 2021, Thomas Sommer
78
*
89
* This file is part of the modm project.
910
*
@@ -60,65 +61,51 @@ pow(uint32_t base, uint8_t exponent)
6061
}
6162

6263
/**
63-
* @brief This does what you think it does.
64-
*
65-
* @param a A thing of arbitrary type.
66-
* @param b Another thing of arbitrary type.
67-
* @return The lesser of the parameters.
64+
* @brief Variadic min for 2-∞ objects
6865
*
69-
* This is the simple classic generic implementation. It will work on
70-
* temporary expressions, since they are only evaluated once, unlike a
71-
* preprocessor macro.
66+
* @param a first object to compare
67+
* @param b second object to compare
68+
* @param cs More optional objects to compare
69+
* @return The smallest object
70+
*
71+
* @see https://stackoverflow.com/questions/23815138/implementing-variadic-min-max-functions
7272
*/
7373
template<typename T>
74-
inline const T&
75-
min(const T& a, const T& b)
74+
constexpr T vmin(T a, T b)
7675
{
77-
if (b < a)
78-
return b;
79-
else
80-
return a;
76+
return a < b ? a : b;
8177
}
8278

83-
/**
84-
* @brief This does what you think it does.
85-
*
86-
* @param a A thing of arbitrary type.
87-
* @param b Another thing of arbitrary type.
88-
* @return The greater of the parameters.
89-
*
90-
* This is the simple classic generic implementation. It will work on
91-
* temporary expressions, since they are only evaluated once, unlike a
92-
* preprocessor macro.
93-
*/
94-
template<typename T>
95-
inline const T&
96-
max(const T& a, const T& b)
79+
template<typename T, typename... Ts>
80+
constexpr T vmin(T a, T b, Ts&&... cs)
9781
{
98-
if (a < b)
99-
return b;
100-
else
101-
return a;
82+
return a < b ?
83+
vmin(a, std::forward<Ts>(cs)...) :
84+
vmin(b, std::forward<Ts>(cs)...);
10285
}
10386

10487
/**
105-
* @brief This does what you think it does.
88+
* @brief Variadic max for 2-∞ objects
10689
*
107-
* @param a A thing of arbitrary type.
108-
* @param b Another thing of arbitrary type.
109-
* @param c Something else of arbitrary type.
110-
* @return The greater of the three parameters.
111-
*
112-
* This is the simple classic generic implementation. It will work on
113-
* temporary expressions, since they are only evaluated once, unlike a
114-
* preprocessor macro.
90+
* @param a first object to compare
91+
* @param b second object to compare
92+
* @param cs More optional objects to compare
93+
* @return The greatest object
94+
*
95+
* @see https://stackoverflow.com/questions/23815138/implementing-variadic-min-max-functions
11596
*/
11697
template<typename T>
117-
constexpr T
118-
max(const T a, const T b, const T c)
98+
constexpr T vmax(T& a, T& b)
99+
{
100+
return a > b ? a : b;
101+
}
102+
103+
template<typename T, typename... Ts>
104+
constexpr T vmax(T& a, T& b, Ts&... cs)
119105
{
120-
return ( ( (b > c) ? b : c ) > a ) ?
121-
( (b > c) ? b : c) : a;
106+
return a > b ?
107+
vmax(a, std::forward<Ts>(cs)...) :
108+
vmax(b, std::forward<Ts>(cs)...);
122109
}
123110

124111
/**
@@ -136,10 +123,7 @@ template<typename T, typename Compare>
136123
inline const T&
137124
min(const T& a, const T& b, Compare compare)
138125
{
139-
if (compare(b, a))
140-
return b;
141-
else
142-
return a;
126+
return compare(b, a) ? b : a;
143127
}
144128

145129
/**
@@ -157,24 +141,16 @@ template<typename T, typename Compare>
157141
inline const T&
158142
max(const T& a, const T& b, Compare compare)
159143
{
160-
if (compare(a, b))
161-
return b;
162-
else
163-
return a;
144+
return compare(a, b) ? b : a;
164145
}
165146

166147
/**
167148
* @brief constexpr implementation of fabs
168149
*/
169-
template <typename Float>
170-
requires std::is_floating_point_v<Float>
150+
template <std::floating_point Float>
171151
constexpr Float constexpr_fabs(Float number)
172152
{
173-
if (number >= 0) {
174-
return number;
175-
} else {
176-
return -number;
177-
}
153+
return number >= 0 ? number : -number;
178154
}
179155

180156
/// @}

src/modm/ui/color/concepts.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
/*
2+
* Copyright (c) 2021, Thomas Sommer
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
112
#pragma once
213

314
#include <bit>
4-
#include <modm/ui/shape/point.hpp>
515

616
namespace modm::color {
717

@@ -28,7 +38,7 @@ template<class C>
2838
concept ColorGray = is_instance<C, GrayD>::value;
2939

3040
template<class C>
31-
concept ColorGrayBase2 = ColorGray<C> && std::popcount(unsigned(C::Wide)) == 1;
41+
concept ColorGrayBase2 = ColorGray<C> && std::popcount(unsigned(C::Digits)) == 1;
3242

3343
template<class C>
3444
concept ColorRgb = is_instance<C, RgbD>::value;
@@ -43,15 +53,4 @@ template<class C>
4353
// concept Color = std::convertible_to<C, RgbD<8,8,8> >; // convertability
4454
concept Color = ColorGray<C> || ColorRgb<C> || ColorHsv<C> || ColorRgbStacked<C>; // conjunction of types
4555

46-
/**
47-
* @brief Concept for a function or functor, that returns a Color for a Point
48-
*
49-
* @tparam F
50-
*/
51-
template <typename F>
52-
concept ColorPattern = requires(F p)
53-
{
54-
{ p.operator()(modm::shape::Point()) } -> Color; // -> std::convertible_to<modm::color::Rgb888>;
55-
};
56-
5756
}

0 commit comments

Comments
 (0)