diff options
| author | MenTaLguY <mental@rydia.net> | 2007-03-04 19:05:38 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2007-03-04 19:05:38 +0000 |
| commit | d9f05c15b5c63cbf1b72b057c2094ca8221b02e9 (patch) | |
| tree | 4caed26f09c6932f31f34a54ca28ddc7eacf58d8 /src/libnr/nr-rect.cpp | |
| parent | redo NR::Maybe to be less clever (diff) | |
| download | inkscape-d9f05c15b5c63cbf1b72b057c2094ca8221b02e9.tar.gz inkscape-d9f05c15b5c63cbf1b72b057c2094ca8221b02e9.zip | |
Convert union and intersection to use NR::Maybe<NR::Rect>
(bzr r2533)
Diffstat (limited to 'src/libnr/nr-rect.cpp')
| -rw-r--r-- | src/libnr/nr-rect.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index 460816021..c4e684f1f 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -260,27 +260,40 @@ void Rect::expandTo(Point p) { } /** Returns the set of points shared by both rectangles. */ -Maybe<Rect> Rect::intersection(const Rect &a, const Rect &b) { - 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]); - - if ( r._min[i] > r._max[i] ) { - return Nothing(); - } +Maybe<Rect> Rect::intersection(Maybe<Rect> const &a, Maybe<Rect> const &b) { + if ( a == Nothing() || b == Nothing() ) { + return Nothing(); + } else { + Rect const &ra=a.assume(); + Rect const &rb=b.assume(); + Rect r; + for ( int i=0 ; i < 2 ; i++ ) { + r._min[i] = MAX(ra._min[i], rb._min[i]); + r._max[i] = MIN(ra._max[i], rb._max[i]); + if ( r._min[i] > r._max[i] ) { + return Nothing(); + } } return r; + } } /** returns the smallest rectangle containing both rectangles */ -Rect Rect::union_bounds(const Rect &a, const Rect &b) { - Rect r; +Maybe<Rect> Rect::union_bounds(Maybe<Rect> const &a, Maybe<Rect> const &b) { + if ( a == Nothing() ) { + return b; + } else if ( b == Nothing() ) { + 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(a._min[i], b._min[i]); - r._max[i] = MAX(a._max[i], b._max[i]); + r._min[i] = MIN(ra._min[i], rb._min[i]); + r._max[i] = MAX(ra._max[i], rb._max[i]); } return r; + } } } // namespace NR |
