diff --git a/examples/example_ear_clipping.cpp b/examples/example_ear_clipping.cpp index 62f4796..91df65b 100644 --- a/examples/example_ear_clipping.cpp +++ b/examples/example_ear_clipping.cpp @@ -148,8 +148,8 @@ container> poly_3() { } int main() { - using number = float; -// using number = Q<12>; +// using number = float; + using number = Q<12>; using Bitmap24= bitmap; using Canvas24= canvas; diff --git a/examples/example_path_fill.cpp b/examples/example_path_fill.cpp index 5f9770a..2113420 100644 --- a/examples/example_path_fill.cpp +++ b/examples/example_path_fill.cpp @@ -120,7 +120,7 @@ int main() { using number = float; // using number = double; // using number = Q<15, long long>; -// using number = Q<8, int32_t, int64_t, 0>; +// using number = Q<8, int32_t, int64_t>; // using number = Q<2, int64_t>; // using number = Q<4, int32_t>; // using number = Q<12>; diff --git a/examples/libs/micro-gl/include/microgl/math/Q.h b/examples/libs/micro-gl/include/microgl/math/Q.h index 10b344a..9e61895 100644 --- a/examples/libs/micro-gl/include/microgl/math/Q.h +++ b/examples/libs/micro-gl/include/microgl/math/Q.h @@ -10,6 +10,11 @@ ========================================================================================*/ #pragma once +namespace detail_Q { + template + struct identity { constexpr static int N = T; }; +} + /** * * @tparam P @@ -39,6 +44,7 @@ class Q { ((intermid_size>integer_size) || integer_size==8) ? 2 : 1; static constexpr char inferred_mul_strategy = multiplication_strategy==-1 ? recommended_mul_strategy : multiplication_strategy; + static constexpr detail_Q::identity inferred_token{}; private: integer _value; @@ -60,18 +66,13 @@ class Q { } inline void multiply(const integer val) { - constexpr bool is_0 = inferred_mul_strategy==0; - constexpr bool is_1 = inferred_mul_strategy==1; - constexpr bool is_2 = inferred_mul_strategy==2; - if(is_0) multiply_0(val); - else if(is_1) multiply_1(val); - else multiply_2(val); + _multiply(val, inferred_token); } - inline void multiply_0(const integer val) { + inline void _multiply(const integer val, detail_Q::identity<0>) { inter_integer inter = ((inter_integer)_value)*val; _value = shift_right_correctly_by(inter, P); } - inline void multiply_1(const integer val) { + inline void _multiply(const integer val, detail_Q::identity<1>) { using int_t = inter_integer; const int_t fpValue1 = _value; const int_t fpValue2 = val; @@ -83,7 +84,7 @@ class Q { _value = int_t(((intPart1 * intPart2)<>P) & int_t(MASK_FRAC_BITS))); } - inline void multiply_2(const integer val) + inline void _multiply(const integer val, detail_Q::identity<2>) { _value = (((inter_integer)_value)*val)>>P; } public: