66 Hermite(
const double multiplier) : m_multiplier{multiplier} {}
72 : m_multiplier{other.m_multiplier}, m_waypoints{other.m_waypoints} {}
85 m_multiplier = other.m_multiplier;
86 m_waypoints = other.m_waypoints;
109 auto tRounded = roundTime(waypoint.
getTime());
110 m_waypoints[tRounded] = waypoint;
127 auto tRounded = roundTime(waypoint.
getTime());
128 m_waypoints[tRounded] = waypoint;
138 auto tRounded = roundTime(waypoint.
getTime());
139 m_waypoints[tRounded] = waypoint;
163 const auto tRounded = roundTime(time);
164 return m_waypoints.find(tRounded) != m_waypoints.end();
189 const auto tRounded = roundTime(time);
192 auto it = m_waypoints.find(tRounded);
193 if (it == m_waypoints.end()) {
197 m_waypoints.erase(it);
206 std::vector<Pose<D>> res;
207 for (
const auto &it : m_waypoints) {
208 res.push_back(it.second);
223 if (m_waypoints.size() == 0) {
227 auto firstIt = m_waypoints.begin();
228 return firstIt->second.getTime();
240 if (m_waypoints.size() == 0) {
244 auto lastIt = m_waypoints.rbegin();
245 return lastIt->second.getTime();
264 if (m_waypoints.size() < 2) {
268 auto func = getSub(t);
269 return func.getPos(t);
286 if (m_waypoints.size() < 2) {
290 auto func = getSub(t);
291 return func.getVel(t);
310 if (m_waypoints.size() < 2) {
314 auto func = getSub(t);
315 return func.getAcc(t);
330 double getLength(
const double timeStep)
const override {
333 if (m_waypoints.size() < 2) {
339 while (time <= timeEnd) {
341 auto speed = magn(vel);
342 res += speed * timeStep;
352 std::map<std::int64_t, Pose<D>> m_waypoints;
361 std::int64_t roundTime(
double t)
const {
363 return static_cast<std::int64_t
>(t);
374 HermiteSub<D> getSub(
const double t)
const {
375 const auto tRound = roundTime(t);
376 auto itLower = m_waypoints.upper_bound(tRound);
378 if (itLower == m_waypoints.begin()) {
382 if (itLower == m_waypoints.end()) {
386 auto itUpper = itLower;
389 const auto objUpper = itUpper->second;
390 const auto objLower = itLower->second;
392 const auto p0 = objLower.getPos();
393 const auto pf = objUpper.getPos();
394 const auto v0 = objLower.getVel();
395 const auto vf = objUpper.getVel();
396 const auto lowerT = objLower.getTime();
397 const auto upperT = objUpper.getTime();
399 HermiteSub<D> res{p0, pf, v0, vf, lowerT, upperT};
T magn(const Vector< D, T > &v)
Gets the magnitude of the vector.
Definition: simplevectors.hpp:1281
Abstract base class for interpolating splines.
Definition: base_spline.hpp:20
Hermite spline class.
Definition: hermite.hpp:49
double getHighestTime() const override
Gets the upper bound of the domain of the piecewise spline function, which is the last time (highest ...
Definition: hermite.hpp:239
Vector< D > getPos(const double t) const override
Gets position at a certain time.
Definition: hermite.hpp:262
void insertOrReplace(const Pose< D > &waypoint)
Inserts a waypoint if it doesn't exist, otherwise replaces the waypoint.
Definition: hermite.hpp:137
bool exists(const Pose< D > &waypoint) const
Checks if a waypoint exists.
Definition: hermite.hpp:151
Hermite()
Default constructor.
Definition: hermite.hpp:58
double getLength(const double timeStep) const override
Gets arc length.
Definition: hermite.hpp:330
bool exists(const double time) const
Checks if a waypoint at a certain time exists.
Definition: hermite.hpp:162
Vector< D > getVel(const double t) const override
Gets velocity at a certain time.
Definition: hermite.hpp:284
std::vector< Pose< D > > getAllWaypoints() const
Gets a list of all waypoints.
Definition: hermite.hpp:205
void replace(const Pose< D > &waypoint)
Replaces a waypoint.
Definition: hermite.hpp:122
void erase(const Pose< D > &waypoint)
Removes a waypoint.
Definition: hermite.hpp:177
void insert(const Pose< D > &waypoint)
Inserts a waypoint.
Definition: hermite.hpp:104
Hermite(const Hermite< D > &other)
Copy constructor.
Definition: hermite.hpp:71
double getLowestTime() const override
Gets the lower bound of the domain of the piecewise spline function, which is the first time (lowest ...
Definition: hermite.hpp:222
Hermite< D > & operator=(const Hermite< D > &other)
Assignment operator.
Definition: hermite.hpp:79
Hermite(const double multiplier)
Constructor.
Definition: hermite.hpp:66
~Hermite() override=default
Destructor.
Vector< D > getAcc(const double t) const override
Gets acceleration of the function at a certain time.
Definition: hermite.hpp:308
void erase(const double time)
Removes a waypoint.
Definition: hermite.hpp:188
A pose object.
Definition: pose.hpp:23
double getTime() const
Gets time.
Definition: pose.hpp:88
A base vector representation.
Definition: simplevectors.hpp:63