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

paulmthompson / WhiskerToolbox / 16036090729

02 Jul 2025 09:22PM UTC coverage: 72.408% (-0.06%) from 72.467%
16036090729

push

github

paulmthompson
remove obselete digitalintervalseries functions

7 of 15 new or added lines in 5 files covered. (46.67%)

74 existing lines in 8 files now uncovered.

11788 of 16280 relevant lines covered (72.41%)

1100.91 hits per line

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

89.92
/src/WhiskerToolbox/DataManager/Points/Point_Data.cpp
1
#include "Point_Data.hpp"
2

3
#include "utils/map_timeseries.hpp"
4

5
#include <algorithm>
6
#include <iostream>
7
#include <ranges>
8

9
// ========== Constructors ==========
10

11
PointData::PointData(std::map<TimeFrameIndex, Point2D<float>> const & data) {
×
UNCOV
12
    for (auto const & [time, point]: data) {
×
13
        _data[time].push_back(point);
×
14
    }
UNCOV
15
}
×
16

17
PointData::PointData(std::map<TimeFrameIndex, std::vector<Point2D<float>>> const & data) 
1✔
18
    : _data(data) {
1✔
19
}
1✔
20

21
// ========== Setters ==========
22

23
bool PointData::clearAtTime(TimeFrameIndex const time, bool notify) {
16✔
24
    if (clear_at_time(time, _data)) {
16✔
25
        if (notify) {
15✔
26
            notifyObservers();
2✔
27
        }
28
        return true;
15✔
29
    }
30
    return false;
1✔
31
}
32

UNCOV
33
bool PointData::clearAtTime(TimeFrameIndex const time, size_t const index, bool notify) {
×
UNCOV
34
    if (clear_at_time(time, index, _data)) {
×
UNCOV
35
        if (notify) {
×
UNCOV
36
            notifyObservers();
×
37
        }
UNCOV
38
        return true;
×
39
    }
UNCOV
40
    return false;
×
41
}
42

43
void PointData::overwritePointAtTime(TimeFrameIndex const time, Point2D<float> const point, bool notify) {
1✔
44
    _data[time] = {point};
1✔
45
    if (notify) {
1✔
46
        notifyObservers();
1✔
47
    }
48
}
1✔
49

50
void PointData::overwritePointsAtTime(TimeFrameIndex const time, std::vector<Point2D<float>> const & points, bool notify) {
12✔
51
    _data[time] = points;
12✔
52
    if (notify) {
12✔
53
        notifyObservers();
12✔
54
    }
55
}
12✔
56

57
void PointData::overwritePointsAtTimes(
2✔
58
        std::vector<TimeFrameIndex> const & times,
59
        std::vector<std::vector<Point2D<float>>> const & points,
60
        bool notify) {
61
    if (times.size() != points.size()) {
2✔
62
        std::cout << "overwritePointsAtTimes: times and points must be the same size" << std::endl;
1✔
63
        return;
1✔
64
    }
65

66
    for (std::size_t i = 0; i < times.size(); i++) {
3✔
67
        _data[times[i]] = points[i];
2✔
68
    }
69
    if (notify) {
1✔
70
        notifyObservers();
1✔
71
    }
72
}
73

74
void PointData::addAtTime(TimeFrameIndex const time, Point2D<float> const point, bool notify) {
22✔
75
    add_at_time(time, point, _data);
22✔
76

77
    if (notify) {
22✔
78
        notifyObservers();
4✔
79
    }
80
}
22✔
81

82
void PointData::addPointsAtTime(TimeFrameIndex const time, std::vector<Point2D<float>> const & points, bool notify) {
179✔
83
    _data[time].insert(_data[time].end(), points.begin(), points.end());
179✔
84
    
85
    if (notify) {
179✔
86
        notifyObservers();
146✔
87
    }
88
}
179✔
89

90
// ========== Getters ==========
91

92
std::vector<Point2D<float>> const & PointData::getAtTime(TimeFrameIndex const time) const {
110✔
93
    return get_at_time(time, _data, _empty);
110✔
94
}
95

96
std::vector<Point2D<float>> const & PointData::getAtTime(TimeFrameIndex const time, 
4✔
97
                                                        TimeFrame const * source_timeframe,
98
                                                        TimeFrame const * target_timeframe) const {
99
    return get_at_time(time, _data, _empty, source_timeframe, target_timeframe);
4✔
100
}
101

102
std::size_t PointData::getMaxPoints() const {
1✔
103
    std::size_t max_points = 0;
1✔
104
    for (auto const & [time, points] : _data) {
3✔
105
        max_points = std::max(max_points, points.size());
2✔
106
    }
107
    return max_points;
1✔
108
}
109

110
// ========== Image Size ==========
111

112
void PointData::changeImageSize(ImageSize const & image_size) {
3✔
113
    if (_image_size.width == -1 || _image_size.height == -1) {
3✔
114
        std::cout << "No size set for current image. "
115
                  << " Please set a valid image size before trying to scale" << std::endl;
1✔
116
        _image_size = image_size; // Set the image size if it wasn't set before
1✔
117
        return;
1✔
118
    }
119

120
    if (_image_size.width == image_size.width && _image_size.height == image_size.height) {
2✔
121
        std::cout << "Image size is the same. No need to scale" << std::endl;
1✔
122
        return;
1✔
123
    }
124

125
    float const scale_x = static_cast<float>(image_size.width) / static_cast<float>(_image_size.width);
1✔
126
    float const scale_y = static_cast<float>(image_size.height) / static_cast<float>(_image_size.height);
1✔
127

128
    for (auto & [time, points] : _data) {
2✔
129
        for (auto & point : points) {
3✔
130
            point.x *= scale_x;
2✔
131
            point.y *= scale_y;
2✔
132
        }
133
    }
134
    _image_size = image_size;
1✔
135
}
136

137
// ========== Copy and Move ==========
138

139
std::size_t PointData::copyTo(PointData& target, TimeFrameInterval const & interval, bool notify) const {
6✔
140
    if (interval.start > interval.end) {
6✔
141
        std::cerr << "PointData::copyTo: interval start (" << interval.start.getValue() 
1✔
142
                  << ") must be <= interval end (" << interval.end.getValue() << ")" << std::endl;
1✔
143
        return 0;
1✔
144
    }
145

146
    std::size_t total_points_copied = 0;
5✔
147

148
    // Iterate through all times in the source data within the interval
149
    for (auto const & [time, points] : _data) {
25✔
150
        if (time >= interval.start && time <= interval.end && !points.empty()) {
20✔
151
            target.addPointsAtTime(time, points, false); // Don't notify for each operation
8✔
152
            total_points_copied += points.size();
8✔
153
        }
154
    }
155

156
    // Notify observer only once at the end if requested
157
    if (notify && total_points_copied > 0) {
5✔
158
        target.notifyObservers();
4✔
159
    }
160

161
    return total_points_copied;
5✔
162
}
163

164
std::size_t PointData::copyTo(PointData& target, std::vector<TimeFrameIndex> const& times, bool notify) const {
5✔
165
    std::size_t total_points_copied = 0;
5✔
166

167
    // Copy points for each specified time
168
    for (TimeFrameIndex time : times) {
20✔
169
        auto it = _data.find(time);
15✔
170
        if (it != _data.end() && !it->second.empty()) {
15✔
171
            target.addPointsAtTime(time, it->second, false); // Don't notify for each operation
10✔
172
            total_points_copied += it->second.size();
10✔
173
        }
174
    }
175

176
    // Notify observer only once at the end if requested
177
    if (notify && total_points_copied > 0) {
5✔
178
        target.notifyObservers();
4✔
179
    }
180

181
    return total_points_copied;
5✔
182
}
183

184
std::size_t PointData::moveTo(PointData& target, TimeFrameInterval const & interval, bool notify) {
4✔
185
    if (interval.start > interval.end) {
4✔
UNCOV
186
        std::cerr << "PointData::moveTo: interval start (" << interval.start.getValue() 
×
UNCOV
187
                  << ") must be <= interval end (" << interval.end.getValue() << ")" << std::endl;
×
UNCOV
188
        return 0;
×
189
    }
190

191
    std::size_t total_points_moved = 0;
4✔
192
    std::vector<TimeFrameIndex> times_to_clear;
4✔
193

194
    // First, copy all points in the interval to target
195
    for (auto const & [time, points] : _data) {
20✔
196
        if (time >= interval.start && time <= interval.end && !points.empty()) {
16✔
197
            target.addPointsAtTime(time, points, false); // Don't notify for each operation
8✔
198
            total_points_moved += points.size();
8✔
199
            times_to_clear.push_back(time);
8✔
200
        }
201
    }
202

203
    // Then, clear all the times from source
204
    for (TimeFrameIndex time : times_to_clear) {
12✔
205
        clearAtTime(time, false); // Don't notify for each operation
8✔
206
    }
207

208
    // Notify observers only once at the end if requested
209
    if (notify && total_points_moved > 0) {
4✔
210
        target.notifyObservers();
4✔
211
        notifyObservers();
4✔
212
    }
213

214
    return total_points_moved;
4✔
215
}
4✔
216

217
std::size_t PointData::moveTo(PointData& target, std::vector<TimeFrameIndex> const& times, bool notify) {
2✔
218
    std::size_t total_points_moved = 0;
2✔
219
    std::vector<TimeFrameIndex> times_to_clear;
2✔
220

221
    // First, copy points for each specified time to target
222
    for (TimeFrameIndex time : times) {
7✔
223
        auto it = _data.find(time);
5✔
224
        if (it != _data.end() && !it->second.empty()) {
5✔
225
            target.addPointsAtTime(time, it->second, false); // Don't notify for each operation
5✔
226
            total_points_moved += it->second.size();
5✔
227
            times_to_clear.push_back(time);
5✔
228
        }
229
    }
230

231
    // Then, clear all the times from source
232
    for (TimeFrameIndex time : times_to_clear) {
7✔
233
        clearAtTime(time, false); // Don't notify for each operation
5✔
234
    }
235

236
    // Notify observers only once at the end if requested
237
    if (notify && total_points_moved > 0) {
2✔
238
        target.notifyObservers();
2✔
239
        notifyObservers();
2✔
240
    }
241

242
    return total_points_moved;
2✔
243
}
2✔
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