Code

Disable the page selector when there's only one page
[inkscape.git] / src / libnr / nr-convex-hull.h
index 28cde376d7339dcd63cebc7e9c451f2756239b69..51dabcf07f1300a8c91bf336d9156eddbc94e7ff 100644 (file)
@@ -17,31 +17,41 @@ namespace NR {
 
 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)) {}
+
+    Maybe<Point> midpoint() const {
+        if (_bounds) {
+            return _bounds->midpoint();
+        } else {
+            return Nothing();
+        }
     }
 
        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 {
+
+       Maybe<Rect> const &bounds() const {
                return _bounds;
        }
        
 private:
-       Rect _bounds;
+    Maybe<Rect> _bounds;
 };
 
 } /* namespace NR */