summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2021-04-07 23:56:00 -0700
committerJacob Palecki <[email protected]>2021-04-07 23:56:00 -0700
commitb1d1a6ba629acb2e3748398a962ed274fade4e5f (patch)
tree4b812cb7a123edcd513203d58a6d9fb2ff291b5c /common
parentMerge remote-tracking branch 'upstream/dyn-lut-b' into lut2 (diff)
downloadrawaccel-b1d1a6ba629acb2e3748398a962ed274fade4e5f.tar.xz
rawaccel-b1d1a6ba629acb2e3748398a962ed274fade4e5f.zip
add constructor and improvements
Diffstat (limited to 'common')
-rw-r--r--common/accel-lookup.hpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/common/accel-lookup.hpp b/common/accel-lookup.hpp
index 965cbec..5778de2 100644
--- a/common/accel-lookup.hpp
+++ b/common/accel-lookup.hpp
@@ -165,7 +165,8 @@ namespace rawaccel {
int log_lookup[LUT_CAPACITY] = {};
double first_point_speed;
double last_point_speed;
- int last_index;
+ int last_arbitrary_index;
+ int last_log_lookup_index;
double operator()(double speed) const
{
@@ -177,11 +178,11 @@ namespace rawaccel {
}
else if (speed > last_point_speed)
{
- index = last_index;
+ index = last_arbitrary_index;
}
else if (speed > range.stop)
{
- index = search_from(log_lookup[LUT_CAPACITY - 1], speed);
+ index = search_from(log_lookup[last_log_lookup_index], speed);
}
else if (speed < range.start)
{
@@ -212,7 +213,7 @@ namespace rawaccel {
prev_index = index;
index++;
}
- while (index <= last_index && data[index].applicable_speed < speed);
+ while (index <= last_arbitrary_index && data[index].applicable_speed < speed);
index--;
}
@@ -251,5 +252,21 @@ namespace rawaccel {
}
}
}
+
+ arbitrary_lut(vec2d* points, int length)
+ {
+ first_point_speed = points[0].x;
+ // -2 because the last index in the arbitrary array is used for slope-intercept only
+ last_arbitrary_index = length - 2;
+ last_point_speed = points[last_arbitrary_index].x;
+
+ double start = (int)floor(log(first_point_speed));
+ double end = (int)floor(log(last_point_speed));
+ double num = (int)floor(LUT_CAPACITY / (end - start));
+ range = fp_rep_range{ start, end, num };
+ last_log_lookup_index = num * (end - start) - 1;
+
+ fill(points, length);
+ }
};
}