-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb_point_filter.hpp
54 lines (42 loc) · 1.44 KB
/
bb_point_filter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef BB_POINT_FILTER_HPP
#define BB_POINT_FILTER_HPP
#include "poly_line.hpp"
#include "point.hpp"
#include <algorithm>
/// Filters the given point sets to only points contained in the axis-aligned bounding
/// box of the given line.
class bb_point_filter
{
public:
template<typename ForwardIter>
bb_point_filter(ForwardIter begin, ForwardIter end, unsigned id)
: id(id)
{
min = coordinate {std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
max = coordinate {-std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()};
for (auto iter = begin; iter != end; ++iter)
{
if (iter->x < min.x) min.x = iter->x;
if (iter->y < min.y) min.y = iter->y;
if (iter->x > max.x) max.x = iter->x;
if (iter->y > max.y) max.y = iter->y;
}
}
std::vector<point> operator()(const std::vector<point>& points)
{
std::vector<point> filtered_points;
std::copy_if(points.begin(), points.end(), std::back_inserter(filtered_points),
[this](const point& p) { return p.line_id != id && in_bounding_box(p.location); });
return filtered_points;
}
private:
bool in_bounding_box(const coordinate& coord)
{
return coord.x > min.x && coord.y > min.y &&
coord.x < max.x && coord.y < max.y;
}
unsigned id;
coordinate min;
coordinate max;
};
#endif