0.2.0
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <vector>
17
18namespace NAV
19{
20
25template<typename T>
26void move(std::vector<T>& v, size_t sourceIdx, size_t targetIdx)
27{
28 if (sourceIdx > targetIdx)
29 {
30 std::rotate(v.rend() - static_cast<int64_t>(sourceIdx) - 1,
31 v.rend() - static_cast<int64_t>(sourceIdx), v.rend() - static_cast<int64_t>(targetIdx));
32 }
33 else
34 {
35 std::rotate(v.begin() + static_cast<int64_t>(sourceIdx),
36 v.begin() + static_cast<int64_t>(sourceIdx) + 1, v.begin() + static_cast<int64_t>(targetIdx) + 1);
37 }
38}
39
44template<typename Scalar>
45std::vector<Scalar> genRangeVector(Scalar start, Scalar stepSize, Scalar end)
46{
47 std::vector<Scalar> container;
48 container.reserve(static_cast<size_t>(std::ceil((end - start) / stepSize)));
49
50 while (start < end)
51 {
52 container.push_back(start);
53 start += stepSize;
54 }
55
56 return container;
57};
58
59} // namespace NAV
std::vector< Scalar > genRangeVector(Scalar start, Scalar stepSize, Scalar end)
Returns a container filled with the given range.
Definition Vector.hpp:45
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:26