• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 15588766412

11 Jun 2025 03:13PM UTC coverage: 62.388% (+0.003%) from 62.385%
15588766412

push

github

paulmthompson
try to use caching for windows CI

6922 of 11095 relevant lines covered (62.39%)

609.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.38
/src/WhiskerToolbox/DataManager/TimeFrame.cpp
1

2
#include "TimeFrame.hpp"
3

4
#include <cmath>
5
#include <cstdint>// For int64_t
6

7
TimeFrame::TimeFrame(std::vector<int> const & times) {
10✔
8
    _times = times;
10✔
9
    _total_frame_count = static_cast<int>(times.size());
10✔
10
}
10✔
11

12
int TimeFrame::getTimeAtIndex(TimeIndex index) const {
30,022✔
13
    if (index < TimeIndex(0) || index.getValue() >= _times.size()) {
30,022✔
14
        std::cout << "Index " << index.getValue() << " out of range" << " for time frame of size " << _times.size() << std::endl;
×
15
        return 0;
×
16
    }
17
    return _times[static_cast<size_t>(index.getValue())];
30,022✔
18
}
19

20
int TimeFrame::getIndexAtTime(float time) const {
12✔
21
    // Binary search to find the index closest to the given time
22
    auto it = std::lower_bound(_times.begin(), _times.end(), time);
12✔
23

24
    // If exact match found
25
    if (it != _times.end() && static_cast<float>(*it) == time) {
12✔
26
        return static_cast<int>(std::distance(_times.begin(), it));
12✔
27
    }
28

29
    // If time is beyond the last time point
30
    if (it == _times.end()) {
6✔
31
        return static_cast<int>(_times.size() - 1);
1✔
32
    }
33

34
    // If time is before the first time point
35
    if (it == _times.begin()) {
5✔
36
        return 0;
1✔
37
    }
38

39
    // Find the closest time point
40
    auto prev = it - 1;
4✔
41
    if (std::abs(static_cast<float>(*prev) - time) <= std::abs(static_cast<float>(*it) - time)) {
4✔
42
        return static_cast<int>(std::distance(_times.begin(), prev));
6✔
43
    } else {
44
        return static_cast<int>(std::distance(_times.begin(), it));
2✔
45
    }
46
}
47

48
int TimeFrame::checkFrameInbounds(int frame_id) const {
×
49

50
    if (frame_id < 0) {
×
51
        frame_id = 0;
×
52
    } else if (frame_id >= _total_frame_count) {
×
53
        frame_id = _total_frame_count;
×
54
    }
55
    return frame_id;
×
56
}
57

58
int64_t getTimeIndexForSeries(TimeIndex source_index,
×
59
                              TimeFrame const * source_time_frame,
60
                              TimeFrame const * destination_time_frame) {
61
    if (source_time_frame == destination_time_frame) {
×
62
        // Frames are the same. The time value can be used directly.
63
        return source_index.getValue();
×
64
    } else {
65
        auto destination_index = destination_time_frame->getIndexAtTime(source_index.getValue());
×
66
        return destination_index;
×
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc