From 2000535ff25ae495a1401f964572904ff92a8e89 Mon Sep 17 00:00:00 2001 From: mental Date: Sun, 4 Mar 2007 19:06:46 +0000 Subject: [PATCH] return plain rect if both union arguments are also plain rects --- src/libnr/nr-rect.cpp | 24 +++++++++++++----------- src/libnr/nr-rect.h | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index c4e684f1f..c3d23a619 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -278,22 +278,24 @@ Maybe Rect::intersection(Maybe const &a, Maybe const &b) { } } -/** returns the smallest rectangle containing both rectangles */ Maybe Rect::union_bounds(Maybe const &a, Maybe const &b) { - if ( a == Nothing() ) { + if (a) { return b; - } else if ( b == Nothing() ) { + } else if (b) { return a; } else { - Rect const &ra=a.assume(); - Rect const &rb=b.assume(); - Rect r; - for ( int i=0; i < 2 ; i++ ) { - r._min[i] = MIN(ra._min[i], rb._min[i]); - r._max[i] = MAX(ra._max[i], rb._max[i]); - } - return r; + return union_bounds(*a, *b); + } +} + +/** returns the smallest rectangle containing both rectangles */ +Rect 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]); } + return r; } } // namespace NR diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index 91431d0e6..b6918c493 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -185,6 +185,7 @@ public: /** Returns the smallest rectangle that encloses both rectangles. */ static Maybe union_bounds(Maybe const &a, Maybe const &b); + static Rect union_bounds(Rect const &a, Rect const &b); /** Scales the rect by s, with origin at 0, 0 */ inline Rect operator*(double const s) const { -- 2.30.2