Skip to content

Commit

Permalink
fix off-by-one issue when number of valid profiles is 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sciprosk committed May 2, 2024
1 parent 8eac665 commit 50e206b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions include/ruckig/position.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <array>
#include <cassert>
#include <iterator>
#include <optional>


Expand Down Expand Up @@ -105,8 +107,11 @@ class PositionSecondOrderStep1 {
double pd;

// Max 3 valid profiles
using ProfileIter = std::array<Profile, 3>::iterator;
std::array<Profile, 3> valid_profiles;
static constexpr int max_num_valid_profiles = 3;
using Profiles = std::array<Profile, max_num_valid_profiles + 1>;
using ProfileIter = Profiles::iterator;

Profiles valid_profiles;

void time_acc0(ProfileIter& profile, double vMax, double vMin, double aMax, double aMin, bool return_after_found) const;
void time_none(ProfileIter& profile, double vMax, double vMin, double aMax, double aMin, bool return_after_found) const;
Expand All @@ -115,6 +120,7 @@ class PositionSecondOrderStep1 {
bool time_all_single_step(Profile* profile, double vMax, double vMin, double aMax, double aMin) const;

inline void add_profile(ProfileIter& profile) const {
assert(std::next(profile) != this->valid_profiles.end() && "number of valid profiles exceeded");
const auto prev_profile = profile;
++profile;
profile->set_boundary(*prev_profile);
Expand Down
7 changes: 5 additions & 2 deletions include/ruckig/velocity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class VelocityThirdOrderStep1 {
double vd;

// Max 3 valid profiles
using ProfileIter = std::array<Profile, 3>::iterator;
std::array<Profile, 3> valid_profiles;
static constexpr int max_num_valid_profiles = 3;
using Profiles = std::array<Profile, max_num_valid_profiles + 1>;
using ProfileIter = Profiles::iterator;

Profiles valid_profiles;

void time_acc0(ProfileIter& profile, double aMax, double aMin, double jMax, bool return_after_found) const;
void time_none(ProfileIter& profile, double aMax, double aMin, double jMax, bool return_after_found) const;
Expand Down

0 comments on commit 50e206b

Please sign in to comment.