index 28cde376d7339dcd63cebc7e9c451f2756239b69..dafdd8840bb69c7e7cf4b23ec652ff2f938888c6 100644 (file)
class ConvexHull {
public:
- explicit ConvexHull(Point const &p) : _bounds(p, p) {}
-
- Point midpoint() const {
- return _bounds.midpoint();
+ ConvexHull() : _bounds() {}
+ explicit ConvexHull(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) {
- _bounds.expandTo(p);
+ if (_bounds) {
+ _bounds->expandTo(p);
+ } else {
+ _bounds = Rect(p, p);
+ }
}
- void add(Rect const &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.expandTo(p.min());
- _bounds.expandTo(p.max());
+ _bounds = union_bounds(_bounds, r);
}
void add(ConvexHull const &h) {
- _bounds.expandTo(h._bounds);
+ if (h._bounds) {
+ add(*h._bounds);
+ }
}
-
- Rect const &bounds() const {
+
+ boost::optional<Rect> const &bounds() const {
return _bounds;
}
private:
- Rect _bounds;
+ boost::optional<Rect> _bounds;
};
} /* namespace NR */