Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Points average(const Points & points, double timerange)
- {
- Points result;
- for (int i = 0; i < points.size(); ++i)
- {
- auto p = points[i];
- double start = p.first - timerange/2;
- double end = p.first + timerange/2;
- double avg = p.second;
- int num_pts_found = 1;
- int needle = i-1;
- while (needle >= 0 && points[needle].first >= start)
- {
- avg += points[needle--].second;
- ++num_pts_found;
- }
- needle = i+1;
- while (needle < points.size() && points[needle].first <= end)
- {
- avg += points[needle++].second;
- ++num_pts_found;
- }
- result.push_back({ p.first, avg/=num_pts_found });
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment