Code

Disable the page selector when there's only one page
[inkscape.git] / src / libnr / nr-rect.cpp
index 21d3f470ad129e1d60b5def6035b06a16084f4ee..72bced37bb048ca9337d8c03658710f412c2dd81 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include "nr-rect-l.h"
+#include <algorithm>
 
 NRRect::NRRect(NR::Rect const &rect)
 : x0(rect.min()[NR::X]), y0(rect.min()[NR::Y]),
@@ -242,8 +243,9 @@ nr_rect_l_enlarge(NRRectL *d, int amount)
 namespace NR {
 
 Rect::Rect(const Point &p0, const Point &p1)
-: _min(MIN(p0[X], p1[X]), MIN(p0[Y], p1[Y])),
-  _max(MAX(p0[X], p1[X]), MAX(p0[Y], p1[Y])) {}
+: _min(std::min(p0[X], p1[X]), std::min(p0[Y], p1[Y])),
+  _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y]))
+{}
 
 /** returns the four corners of the rectangle in the correct winding order */
 Point Rect::corner(unsigned i) const {
@@ -278,20 +280,30 @@ void Rect::offset(Point p) {
 /** Makes this rectangle large enough to include the point p. */
 void Rect::expandTo(Point p) {
        for ( int i=0 ; i < 2 ; i++ ) {
-               _min[i] = MIN(_min[i], p[i]);
-               _max[i] = MAX(_max[i], p[i]);
+               _min[i] = std::min(_min[i], p[i]);
+               _max[i] = std::max(_max[i], p[i]);
        }
 }
 
+void Rect::growBy(double size) {
+  for ( unsigned d = 0 ; d < 2 ; d++ ) {
+    _min[d] -= size;
+    _max[d] += size;
+    if ( _min[d] > _max[d] ) {
+      _min[d] = _max[d] = ( _min[d] + _max[d] ) / 2;
+    }
+  }
+} 
+
 /** Returns the set of points shared by both rectangles. */
-Maybe<Rect> Rect::intersection(Maybe<Rect> const &a, Maybe<Rect> const &b) {
+Maybe<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> const & b) {
     if ( !a || !b ) {
         return Nothing();
     } else {
         Rect r;
         for ( int i=0 ; i < 2 ; i++ ) {
-            r._min[i] = MAX(a->_min[i], b->_min[i]);
-            r._max[i] = MIN(a->_max[i], b->_max[i]);
+            r._min[i] = std::max(a->_min[i], b->_min[i]);
+            r._max[i] = std::min(a->_max[i], b->_max[i]);
             if ( r._min[i] > r._max[i] ) {
                return Nothing();
             }
@@ -301,11 +313,11 @@ Maybe<Rect> Rect::intersection(Maybe<Rect> const &a, Maybe<Rect> const &b) {
 }
 
 /** returns the smallest rectangle containing both rectangles */
-Rect Rect::union_bounds(Rect const &a, Rect const &b) {
+Rect union_bounds(Rect const &a, Rect const &b) {
     Rect r;
     for ( int i=0 ; i < 2 ; i++ ) {
-        r._min[i] = MIN(a._min[i], b._min[i]);
-        r._max[i] = MAX(a._max[i], b._max[i]);
+        r._min[i] = std::min(a._min[i], b._min[i]);
+        r._max[i] = std::max(a._max[i], b._max[i]);
     }
     return r;
 }