summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-04-14 21:30:26 -0400
committera1xd <[email protected]>2021-04-14 21:30:26 -0400
commit0bff91add8525c3c3b3ac00d0508d3a798dee5e2 (patch)
tree9ea777e74197ee110bf0bfe1a277313cb8d660d6
parentbump version (diff)
downloadrawaccel-0bff91add8525c3c3b3ac00d0508d3a798dee5e2.tar.xz
rawaccel-0bff91add8525c3c3b3ac00d0508d3a798dee5e2.zip
ensure normal return values from accel
-rw-r--r--common/accel-jump.hpp7
-rw-r--r--common/accel-lookup.hpp11
2 files changed, 9 insertions, 9 deletions
diff --git a/common/accel-jump.hpp b/common/accel-jump.hpp
index 30f9a49..198891a 100644
--- a/common/accel-jump.hpp
+++ b/common/accel-jump.hpp
@@ -32,7 +32,7 @@ namespace rawaccel {
double smooth(double x) const
{
- return step.y * 1 / (1 + decay(x));
+ return step.y / (1 + decay(x));
}
double smooth_antideriv(double x) const
@@ -61,8 +61,11 @@ namespace rawaccel {
double operator()(double x) const
{
+ if (x <= 0) return 1;
+
if (is_smooth()) return 1 + (smooth_antideriv(x) + C) / x;
- else if (x < step.x) return 1;
+
+ if (x < step.x) return 1;
else return 1 + step.y * (x - step.x) / x;
}
};
diff --git a/common/accel-lookup.hpp b/common/accel-lookup.hpp
index 2ca387f..99f39e9 100644
--- a/common/accel-lookup.hpp
+++ b/common/accel-lookup.hpp
@@ -181,6 +181,8 @@ namespace rawaccel {
int last_arb_index = last_arbitrary_index;
int last_log_index = last_log_lookup_index;
+ if (speed <= 0) return 1;
+
if (unsigned(last_arb_index) < capacity &&
unsigned(last_log_index) < capacity &&
speed > first_point_speed)
@@ -222,18 +224,13 @@ namespace rawaccel {
int inline search_from(int index, int last, double speed) const
{
- int prev_index;
-
do
{
- prev_index = index;
index++;
- }
+ }
while (index <= last && data[index].applicable_speed < speed);
- index--;
-
- return index;
+ return index - 1;
}
double inline apply(int index, double speed) const