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

paulmthompson / WhiskerToolbox / 15538997985

09 Jun 2025 04:05PM UTC coverage: 51.194% (+10.2%) from 40.974%
15538997985

push

github

paulmthompson
mac install should include dataviewer library

4609 of 9003 relevant lines covered (51.19%)

783.96 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
{
9
    _times = times;
10✔
10
    _total_frame_count = static_cast<int>(times.size());
10✔
11
}
10✔
12

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

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

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

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

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

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

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

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

59
int64_t getTimeIndexForSeries(TimeIndex source_index,
×
60
                              TimeFrame const * source_time_frame,
61
                              TimeFrame const * destination_time_frame) {
62
    if (source_time_frame == destination_time_frame) {
×
63
        // Frames are the same. The time value can be used directly.
64
        return source_index.getValue();
×
65
    } else {
66
        auto destination_index = destination_time_frame->getIndexAtTime(source_index.getValue());
×
67
        return destination_index;
×
68
    }
69
}
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