diff options
| author | Ted Gould <ted@gould.cx> | 2008-10-11 15:16:23 +0000 |
|---|---|---|
| committer | Ted Gould <ted@canonical.com> | 2008-10-11 15:16:23 +0000 |
| commit | 2f5eb047d9e05be5e68549ef6b75070d2faa7d2f (patch) | |
| tree | ca2e94164b6d7aaebfc17196ca46bfc825a7665a /src/helper/recthull.h | |
| parent | Merge from trunk. (diff) | |
| download | inkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.tar.gz inkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.zip | |
Merging from trunk
(bzr r6884)
Diffstat (limited to 'src/helper/recthull.h')
| -rw-r--r-- | src/helper/recthull.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/helper/recthull.h b/src/helper/recthull.h new file mode 100644 index 000000000..59649cfb6 --- /dev/null +++ b/src/helper/recthull.h @@ -0,0 +1,59 @@ +#ifndef SEEN_GEOM_RECT_HULL_H +#define SEEN_GEOM_RECT_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 <2geom/rect.h> + +namespace Geom { + +class RectHull { +public: + RectHull() : _bounds() {} + explicit RectHull(Point const &p) : _bounds(Rect(p, p)) {} + + boost::optional<Point> midpoint() const { + if (_bounds) { + return _bounds->midpoint(); + } else { + return boost::optional<Point>(); + } + } + + 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 = unify(_bounds, r); + } + void add(RectHull const &h) { + if (h._bounds) { + add(*h._bounds); + } + } + + boost::optional<Rect> const &bounds() const { + return _bounds; + } + +private: + boost::optional<Rect> _bounds; +}; + +} /* namespace Geom */ + +#endif |
