Skip to content

Commit

Permalink
fixing a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrixString committed Sep 6, 2023
1 parent a1c2e5f commit 783fb0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/example_ear_clipping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ container<vertex2<number>> poly_3() {
}

int main() {
using number = float;
// using number = Q<12>;
// using number = float;
using number = Q<12>;

using Bitmap24= bitmap<coder::RGB888_PACKED_32>;
using Canvas24= canvas<Bitmap24>;
Expand Down
2 changes: 1 addition & 1 deletion examples/example_path_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
19 changes: 10 additions & 9 deletions examples/libs/micro-gl/include/microgl/math/Q.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
========================================================================================*/
#pragma once

namespace detail_Q {
template<int T>
struct identity { constexpr static int N = T; };
}

/**
*
* @tparam P
Expand Down Expand Up @@ -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_mul_strategy> inferred_token{};

private:
integer _value;
Expand All @@ -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_integer>(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;
Expand All @@ -83,7 +84,7 @@ class Q {
_value = int_t(((intPart1 * intPart2)<<P) + (intPart1 * fracPart2) +
(fracPart1 * intPart2) + (((fracPart1 * fracPart2)>>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:
Expand Down

0 comments on commit 783fb0c

Please sign in to comment.