Code

Prune initial timer work.
[inkscape.git] / src / libnr / nr-convex-hull.h
1 #ifndef SEEN_NR_CONVEX_HULL_H
2 #define SEEN_NR_CONVEX_HULL_H
4 /* ex:set et ts=4 sw=4: */
6 /*
7  * A class representing the convex hull of a set of points.
8  *
9  * Copyright 2004  MenTaLguY <mental@rydia.net>
10  *
11  * This code is licensed under the GNU GPL; see COPYING for more information.
12  */
14 #include <libnr/nr-rect.h>
16 namespace NR {
18 class ConvexHull {
19 public:
20     ConvexHull() : _bounds() {}
21         explicit ConvexHull(Point const &p) : _bounds(Rect(p, p)) {}
23     boost::optional<Point> midpoint() const {
24         if (_bounds) {
25             return _bounds->midpoint();
26         } else {
27             return boost::optional<Point>();
28         }
29     }
31         void add(Point const &p) {
32         if (_bounds) {
33                     _bounds->expandTo(p);
34         } else {
35             _bounds = Rect(p, p);
36         }
37         }
38         void add(Rect const &r) {
39                 // Note that this is a hack.  when convexhull actually works
40                 // you will need to add all four points.
41         _bounds = union_bounds(_bounds, r);
42         }
43         void add(ConvexHull const &h) {
44         if (h._bounds) {
45             add(*h._bounds);
46         }
47         }
49         boost::optional<Rect> const &bounds() const {
50                 return _bounds;
51         }
52         
53 private:
54     boost::optional<Rect> _bounds;
55 };
57 } /* namespace NR */
59 #endif