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

paulmthompson / WhiskerToolbox / 15430655463

04 Jun 2025 12:26AM UTC coverage: 40.974% (+17.1%) from 23.832%
15430655463

push

github

paulmthompson
fix self copy with mask data

5 of 5 new or added lines in 2 files covered. (100.0%)

945 existing lines in 24 files now uncovered.

3003 of 7329 relevant lines covered (40.97%)

731.35 hits per line

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

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

3
#include <algorithm>
4
#include <iostream>
5

UNCOV
6
PointData::PointData(std::map<int, Point2D<float>> const & data) {
×
UNCOV
7
    for (auto const & [time, point]: data) {
×
8
        _data[time].push_back(point);
×
9
    }
10
}
×
11

12
PointData::PointData(std::map<int, std::vector<Point2D<float>>> const & data) 
1✔
13
    : _data(data) {
1✔
14
}
1✔
15

16
void PointData::clearAtTime(int const time, bool notify) {
16✔
17
    auto it = _data.find(time);
16✔
18
    if (it != _data.end()) {
16✔
19
        _data.erase(it);
15✔
20
    }
21

22
    if (notify) {
16✔
23
        notifyObservers();
3✔
24
    }
25
}
16✔
26

27
void PointData::overwritePointAtTime(int const time, Point2D<float> const point, bool notify) {
1✔
28
    _data[time] = {point};
1✔
29
    if (notify) {
1✔
30
        notifyObservers();
1✔
31
    }
32
}
1✔
33

34
void PointData::overwritePointsAtTime(int const time, std::vector<Point2D<float>> const & points, bool notify) {
12✔
35
    _data[time] = points;
12✔
36
    if (notify) {
12✔
37
        notifyObservers();
12✔
38
    }
39
}
12✔
40

41
void PointData::overwritePointsAtTimes(
2✔
42
        std::vector<int> const & times,
43
        std::vector<std::vector<Point2D<float>>> const & points,
44
        bool notify) {
45
    if (times.size() != points.size()) {
2✔
46
        std::cout << "overwritePointsAtTimes: times and points must be the same size" << std::endl;
1✔
47
        return;
1✔
48
    }
49

50
    for (std::size_t i = 0; i < times.size(); i++) {
3✔
51
        _data[times[i]] = points[i];
2✔
52
    }
53
    if (notify) {
1✔
54
        notifyObservers();
1✔
55
    }
56
}
57

58
void PointData::addPointAtTime(int const time, Point2D<float> const point, bool notify) {
4✔
59
    _data[time].push_back(point);
4✔
60

61
    if (notify) {
4✔
62
        notifyObservers();
4✔
63
    }
64
}
4✔
65

66
void PointData::addPointsAtTime(int const time, std::vector<Point2D<float>> const & points, bool notify) {
125✔
67
    _data[time].insert(_data[time].end(), points.begin(), points.end());
125✔
68
    
69
    if (notify) {
125✔
70
        notifyObservers();
93✔
71
    }
72
}
125✔
73

74
std::vector<int> PointData::getTimesWithData() const {
8✔
75
    std::vector<int> times;
8✔
76
    times.reserve(_data.size());
8✔
77
    for (auto const & [time, points] : _data) {
11✔
78
        times.push_back(time);
3✔
79
    }
80
    return times;
8✔
UNCOV
81
}
×
82

83
std::vector<Point2D<float>> const & PointData::getPointsAtTime(int const time) const {
77✔
84
    auto it = _data.find(time);
77✔
85
    if (it != _data.end()) {
77✔
86
        return it->second;
61✔
87
    } else {
88
        return _empty;
16✔
89
    }
90
}
91

92
std::size_t PointData::getMaxPoints() const {
1✔
93
    std::size_t max_points = 0;
1✔
94
    for (auto const & [time, points] : _data) {
3✔
95
        max_points = std::max(max_points, points.size());
2✔
96
    }
97
    return max_points;
1✔
98
}
99

UNCOV
100
void PointData::changeImageSize(ImageSize const & image_size) {
×
UNCOV
101
    if (_image_size.width == -1 || _image_size.height == -1) {
×
102
        std::cout << "No size set for current image. "
UNCOV
103
                  << " Please set a valid image size before trying to scale" << std::endl;
×
UNCOV
104
        _image_size = image_size; // Set the image size if it wasn't set before
×
UNCOV
105
        return;
×
106
    }
107

UNCOV
108
    if (_image_size.width == image_size.width && _image_size.height == image_size.height) {
×
UNCOV
109
        std::cout << "Image size is the same. No need to scale" << std::endl;
×
UNCOV
110
        return;
×
111
    }
112

UNCOV
113
    float const scale_x = static_cast<float>(image_size.width) / static_cast<float>(_image_size.width);
×
UNCOV
114
    float const scale_y = static_cast<float>(image_size.height) / static_cast<float>(_image_size.height);
×
115

UNCOV
116
    for (auto & [time, points] : _data) {
×
UNCOV
117
        for (auto & point : points) {
×
UNCOV
118
            point.x *= scale_x;
×
UNCOV
119
            point.y *= scale_y;
×
120
        }
121
    }
UNCOV
122
    _image_size = image_size;
×
123
}
124

125
std::size_t PointData::copyTo(PointData& target, int start_time, int end_time, bool notify) const {
8✔
126
    if (start_time > end_time) {
8✔
127
        std::cerr << "PointData::copyTo: start_time (" << start_time 
1✔
128
                  << ") must be <= end_time (" << end_time << ")" << std::endl;
1✔
129
        return 0;
1✔
130
    }
131

132
    std::size_t total_points_copied = 0;
7✔
133

134
    // Iterate through all times in the source data within the range
135
    for (auto const & [time, points] : _data) {
31✔
136
        if (time >= start_time && time <= end_time && !points.empty()) {
24✔
137
            target.addPointsAtTime(time, points, false); // Don't notify for each operation
9✔
138
            total_points_copied += points.size();
9✔
139
        }
140
    }
141

142
    // Notify observer only once at the end if requested
143
    if (notify && total_points_copied > 0) {
7✔
144
        target.notifyObservers();
5✔
145
    }
146

147
    return total_points_copied;
7✔
148
}
149

150
std::size_t PointData::copyTo(PointData& target, std::vector<int> const& times, bool notify) const {
5✔
151
    std::size_t total_points_copied = 0;
5✔
152

153
    // Copy points for each specified time
154
    for (int time : times) {
20✔
155
        auto it = _data.find(time);
15✔
156
        if (it != _data.end() && !it->second.empty()) {
15✔
157
            target.addPointsAtTime(time, it->second, false); // Don't notify for each operation
10✔
158
            total_points_copied += it->second.size();
10✔
159
        }
160
    }
161

162
    // Notify observer only once at the end if requested
163
    if (notify && total_points_copied > 0) {
5✔
164
        target.notifyObservers();
4✔
165
    }
166

167
    return total_points_copied;
5✔
168
}
169

170
std::size_t PointData::moveTo(PointData& target, int start_time, int end_time, bool notify) {
5✔
171
    if (start_time > end_time) {
5✔
UNCOV
172
        std::cerr << "PointData::moveTo: start_time (" << start_time 
×
UNCOV
173
                  << ") must be <= end_time (" << end_time << ")" << std::endl;
×
UNCOV
174
        return 0;
×
175
    }
176

177
    std::size_t total_points_moved = 0;
5✔
178
    std::vector<int> times_to_clear;
5✔
179

180
    // First, copy all points in the range to target
181
    for (auto const & [time, points] : _data) {
21✔
182
        if (time >= start_time && time <= end_time && !points.empty()) {
16✔
183
            target.addPointsAtTime(time, points, false); // Don't notify for each operation
8✔
184
            total_points_moved += points.size();
8✔
185
            times_to_clear.push_back(time);
8✔
186
        }
187
    }
188

189
    // Then, clear all the times from source
190
    for (int time : times_to_clear) {
13✔
191
        clearAtTime(time, false); // Don't notify for each operation
8✔
192
    }
193

194
    // Notify observers only once at the end if requested
195
    if (notify && total_points_moved > 0) {
5✔
196
        target.notifyObservers();
4✔
197
        notifyObservers();
4✔
198
    }
199

200
    return total_points_moved;
5✔
201
}
5✔
202

203
std::size_t PointData::moveTo(PointData& target, std::vector<int> const& times, bool notify) {
2✔
204
    std::size_t total_points_moved = 0;
2✔
205
    std::vector<int> times_to_clear;
2✔
206

207
    // First, copy points for each specified time to target
208
    for (int time : times) {
7✔
209
        auto it = _data.find(time);
5✔
210
        if (it != _data.end() && !it->second.empty()) {
5✔
211
            target.addPointsAtTime(time, it->second, false); // Don't notify for each operation
5✔
212
            total_points_moved += it->second.size();
5✔
213
            times_to_clear.push_back(time);
5✔
214
        }
215
    }
216

217
    // Then, clear all the times from source
218
    for (int time : times_to_clear) {
7✔
219
        clearAtTime(time, false); // Don't notify for each operation
5✔
220
    }
221

222
    // Notify observers only once at the end if requested
223
    if (notify && total_points_moved > 0) {
2✔
224
        target.notifyObservers();
2✔
225
        notifyObservers();
2✔
226
    }
227

228
    return total_points_moved;
2✔
229
}
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