blob: 51dabcf07f1300a8c91bf336d9156eddbc94e7ff (
plain)
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
55
56
57
58
59
|
#ifndef SEEN_NR_CONVEX_HULL_H
#define SEEN_NR_CONVEX_HULL_H
/* ex:set et ts=4 sw=4: */
/*
* A class representing the convex hull of a set of points.
*
* Copyright 2004 MenTaLguY <mental@rydia.net>
*
* This code is licensed under the GNU GPL; see COPYING for more information.
*/
#include <libnr/nr-rect.h>
namespace NR {
class ConvexHull {
public:
ConvexHull() : _bounds() {}
explicit ConvexHull(Point const &p) : _bounds(Rect(p, p)) {}
Maybe<Point> midpoint() const {
if (_bounds) {
return _bounds->midpoint();
} else {
return Nothing();
}
}
void add(Point const &p) {
if (_bounds) {
_bounds->expandTo(p);
} else {
_bounds = Rect(p, p);
}
}
void add(Rect const &r) {
// Note that this is a hack. when convexhull actually works
// you will need to add all four points.
_bounds = union_bounds(_bounds, r);
}
void add(ConvexHull const &h) {
if (h._bounds) {
add(*h._bounds);
}
}
Maybe<Rect> const &bounds() const {
return _bounds;
}
private:
Maybe<Rect> _bounds;
};
} /* namespace NR */
#endif
|