INSTINCT Code Coverage Report


Directory: src/
File: util/Container/Vector.hpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 4 6 66.7%
Functions: 1 3 33.3%
Branches: 2 6 33.3%

Line Branch Exec Source
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
9 /// @file Vector.hpp
10 /// @brief Vector Utility functions
11 /// @author T. Topp (topp@ins.uni-stuttgart.de)
12 /// @date 2022-03-07
13
14 #pragma once
15
16 #include <vector>
17
18 namespace NAV
19 {
20
21 /// @brief Moves an element within a vector to a new position
22 /// @param[in, out] v Vector with the elements
23 /// @param[in] sourceIdx Old index which will be moved
24 /// @param[in] targetIdx New index which is the target
25 template<typename T>
26 192 void move(std::vector<T>& v, size_t sourceIdx, size_t targetIdx)
27 {
28
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
192 if (sourceIdx > targetIdx)
29 {
30
1/2
✓ Branch 8 taken 96 times.
✗ Branch 9 not taken.
192 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 192 }
39
40 /// @brief Returns a container filled with the given range
41 /// @param start Inclusive start value of the range
42 /// @param stepSize Step size of the range
43 /// @param end Exclusive end value of the range
44 template<typename Scalar>
45 std::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
60