os/include: use C++20 function template syntax

Issue #5227
This commit is contained in:
Norman Feske
2024-05-22 17:22:53 +02:00
committed by Christian Helmuth
parent 5e862b2cd3
commit cfd013a01a
32 changed files with 183 additions and 293 deletions

View File

@ -17,18 +17,17 @@
/**
* Calculate quadratic bezier curve
*
* \param draw_line functor to be called to draw a line segment
* \param levels number of sub divisions
* \param draw_line_fn functor to be called to draw a line segment
* \param levels number of sub divisions
*
* The coordinates are specified in clock-wise order with point 1 being
* the start and point 3 the end of the curve.
*/
template <typename FUNC>
static inline void bezier(long x1, long y1, long x2, long y2, long x3, long y3,
FUNC const &draw_line, unsigned levels)
auto const &draw_line_fn, unsigned levels)
{
if (levels-- == 0) {
draw_line(x1, y1, x3, y3);
draw_line_fn(x1, y1, x3, y3);
return;
}
@ -36,8 +35,8 @@ static inline void bezier(long x1, long y1, long x2, long y2, long x3, long y3,
x23 = (x2 + x3) / 2, y23 = (y2 + y3) / 2,
x123 = (x12 + x23) / 2, y123 = (y12 + y23) / 2;
bezier(x1, y1, x12, y12, x123, y123, draw_line, levels);
bezier(x123, y123, x23, y23, x3, y3, draw_line, levels);
bezier(x1, y1, x12, y12, x123, y123, draw_line_fn, levels);
bezier(x123, y123, x23, y23, x3, y3, draw_line_fn, levels);
}
@ -47,13 +46,12 @@ static inline void bezier(long x1, long y1, long x2, long y2, long x3, long y3,
* The arguments correspond to those of the quadratic version but with point 4
* being the end of the curve.
*/
template <typename FUNC>
static inline void bezier(long x1, long y1, long x2, long y2,
long x3, long y3, long x4, long y4,
FUNC const &draw_line, unsigned levels)
auto const &draw_line_fn, unsigned levels)
{
if (levels-- == 0) {
draw_line(x1, y1, x4, y4);
draw_line_fn(x1, y1, x4, y4);
return;
}
@ -64,8 +62,8 @@ static inline void bezier(long x1, long y1, long x2, long y2,
x234 = (x23 + x34) / 2, y234 = (y23 + y34) / 2,
x1234 = (x123 + x234) / 2, y1234 = (y123 + y234) / 2;
bezier(x1, y1, x12, y12, x123, y123, x1234, y1234, draw_line, levels);
bezier(x1234, y1234, x234, y234, x34, y34, x4, y4, draw_line, levels);
bezier(x1, y1, x12, y12, x123, y123, x1234, y1234, draw_line_fn, levels);
bezier(x1234, y1234, x234, y234, x34, y34, x4, y4, draw_line_fn, levels);
}
#endif /* _INCLUDE__GEMS__BEZIER_H_ */