@@ -25,14 +25,14 @@ namespace modm::color
2525namespace detail
2626{
2727template <std::unsigned_integral T>
28- class RectangularFunc
28+ class RectFunc
2929{
3030protected:
3131 const T width;
3232 const modm::WideType<T> period;
3333
3434public:
35- constexpr RectangularFunc (T low, T high) : width(low), period(low + high) {}
35+ constexpr RectFunc (T low, T high) : width(low), period(low + high) {}
3636
3737 constexpr bool
3838 operator ()(modm::WideType<T> input)
@@ -41,100 +41,116 @@ class RectangularFunc
4141 }
4242};
4343
44- // Preprocesses point.x and point.y with Preprocess
45- // Passes result to RectangularFunc
46- template <class C , class Preprocess >
47- requires C::isColor
48- class PrePattern : public Pattern <C>, protected RectangularFunc<uint8_t >
44+ /* *
45+ * @brief Generic Functor to generate a homogene 2D BicolorPattern
46+ * Preprocess point.x and point.y with PreFn and pass result to RectFunc
47+ * @tparam C Color
48+ * @tparam PreFn Scalar Functor
49+ */
50+ template <Color C, class PreFn >
51+ class PrePattern : public BicolorPattern <C>, protected RectFunc<uint8_t >
4952{
5053public:
5154 constexpr PrePattern (C odd, C even, uint8_t width)
52- : Pattern <C>(odd, even), RectangularFunc <uint8_t>(width, width)
55+ : BicolorPattern <C>(odd, even), RectFunc <uint8_t>(width, width)
5356 {}
5457
5558 constexpr PrePattern (C odd, C even, uint8_t low, uint8_t high)
56- : Pattern <C>(odd, even), RectangularFunc <uint8_t>(low, high)
59+ : BicolorPattern <C>(odd, even), RectFunc <uint8_t>(low, high)
5760 {}
5861
5962 constexpr C
6063 operator ()(Point point) final
6164 {
62- return RectangularFunc <uint8_t >::operator ()(Preprocess ()(point.x , point.y )) ? this ->odd : this ->even ;
65+ return RectFunc <uint8_t >::operator ()(PreFn ()(point.x , point.y )) ? this ->odd : this ->even ;
6366 }
6467};
6568
66- // Takes results from passing point.x and point.y to RectangularFunc
67- // and Postprocesses with binary function Fn
68- template <class C , class Postprocess >
69- requires C::isColor
70- class PostPattern : public Pattern <C>, protected RectangularFunc<uint8_t >
69+ /* *
70+ * @brief Generic Functor to generate a homogene 2D BicolorPattern
71+ * Pass point.x and point.y to RectFunc and Postprocess results with PostFn
72+ * @tparam C Color
73+ * @tparam PostFn Binary Functor
74+ */
75+ template <Color C, class PostFn >
76+ class PostPattern : public BicolorPattern <C>, protected RectFunc<uint8_t >
7177{
7278public:
7379 constexpr PostPattern (C odd, C even, uint8_t width)
74- : Pattern <C>(odd, even), RectangularFunc <uint8_t>(width, width)
80+ : BicolorPattern <C>(odd, even), RectFunc <uint8_t>(width, width)
7581 {}
7682
7783 constexpr PostPattern (C odd, C even, uint8_t low, uint8_t high)
78- : Pattern <C>(odd, even), RectangularFunc <uint8_t>(low, high)
84+ : BicolorPattern <C>(odd, even), RectFunc <uint8_t>(low, high)
7985 {}
8086
8187 constexpr C
8288 operator ()(Point point) final
8389 {
8490 // return odd;
85- bool h = RectangularFunc <uint8_t >::operator ()(point.x );
86- bool v = RectangularFunc <uint8_t >::operator ()(point.y );
87- return Postprocess ()(h, v) ? this ->odd : this ->even ;
91+ bool h = RectFunc <uint8_t >::operator ()(point.x );
92+ bool v = RectFunc <uint8_t >::operator ()(point.y );
93+ return PostFn ()(h, v) ? this ->odd : this ->even ;
8894 }
8995};
9096} // namespace detail
9197
9298using namespace detail ;
9399
94- // TODO I bet there's something out of the std -box
100+ // TODO Bet there's a solution out of STL -box
95101template <class T > struct takeX {
96- T operator () (const T&, const T& y) const {return y;}
102+ constexpr T operator () (const T&, const T& y) const {return y;}
103+ };
104+ template <class T > struct takeY {
105+ constexpr T operator () (const T& x, const T&) const {return x;}
97106};
98107
99- template <class C >
108+ template <Color C>
100109class HorizontalStriped : public PrePattern <C, takeX<int16_t >>
101110{ public: using PrePattern<C, takeX<int16_t >>::PrePattern; };
102111
103- // TODO I bet there's something out of the std-box
104- template <class T > struct takeY {
105- T operator () (const T& x, const T&) const {return x;}
106- };
107-
108- template <class C >
112+ template <Color C>
109113class VerticalStriped : public PrePattern <C, takeY<int16_t >>
110114{ public: using PrePattern<C, takeY<int16_t >>::PrePattern; };
111115
112- template <class C >
116+ template <Color C>
113117class FallingDiagonalStriped : public PrePattern <C, std::plus<int16_t >>
114118{ public: using PrePattern<C, std::plus<int16_t >>::PrePattern; };
115119
116- template <class C >
120+ template <Color C>
117121class RisingDiagonalStriped : public PrePattern <C, std::minus<int16_t >>
118122{ public: using PrePattern<C, std::minus<int16_t >>::PrePattern; };
119123
120- template <class C >
124+ template <Color C>
125+ class Checkerboard : public PostPattern <C, std::bit_xor<bool >>
126+ { public: using PostPattern<C, std::bit_xor<bool >>::PostPattern; };
127+ template <Color C>
128+ class Grid : public PostPattern <C, std::bit_or<bool >>
129+ { public: using PostPattern<C, std::bit_or<bool >>::PostPattern; };
130+
131+ // These are Try & Error. Some combinations produce beautiful results
132+ template <Color C>
121133class MultiplyPattern : public PrePattern <C, std::multiplies<int16_t >>
122134{ public: using PrePattern<C, std::multiplies<int16_t >>::PrePattern; };
123135
124- template <class C >
136+ template <Color C>
125137class DividePattern : public PrePattern <C, std::divides<int16_t >>
126138{ public: using PrePattern<C, std::divides<int16_t >>::PrePattern; };
127139
128- // Well, that's useless
129- template <class C >
140+ template <Color C>
130141class ModulusPattern : public PrePattern <C, std::modulus<int16_t >>
131142{ public: using PrePattern<C, std::modulus<int16_t >>::PrePattern; };
132143
133- template <class C >
134- class Checkerboard : public PostPattern <C, std::bit_xor<bool >>
135- { public: using PostPattern<C, std::bit_xor<bool >>::PostPattern; };
144+ template <Color C>
145+ class BitwiseAndPattern : public PrePattern <C, std::bit_and<int16_t >>
146+ { public: using PrePattern<C, std::bit_and<int16_t >>::PrePattern; };
147+
148+ template <Color C>
149+ class BitwiseOrPattern : public PrePattern <C, std::bit_or<int16_t >>
150+ { public: using PrePattern<C, std::bit_or<int16_t >>::PrePattern; };
151+
152+ template <Color C>
153+ class BitwiseXorPattern : public PrePattern <C, std::bit_xor<int16_t >>
154+ { public: using PrePattern<C, std::bit_xor<int16_t >>::PrePattern; };
136155
137- template <class C >
138- class Grid : public PostPattern <C, std::bit_or<bool >>
139- { public: using PostPattern<C, std::bit_or<bool >>::PostPattern; };
140156} // namespace modm::color
0 commit comments