summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ce3c006)
raw | patch | inline | side by side (parent: ce3c006)
author | mental <mental@users.sourceforge.net> | |
Sun, 4 Mar 2007 19:05:38 +0000 (19:05 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sun, 4 Mar 2007 19:05:38 +0000 (19:05 +0000) |
src/libnr/nr-rect.cpp | patch | blob | history | |
src/libnr/nr-rect.h | patch | blob | history |
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index 460816021f13257ca7e9c3478fc6c3ed60c163ec..c4e684f1f23f6ec0929519e6d8b07a8f1f62519a 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
}
/** 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
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index e0b3f30ae0150309412db49978c9f96653c4dd6f..91431d0e6f21a85ebc0b8d5fc0b28fda3ea0b41d 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
}
/** Returns the set of points shared by both rectangles. */
- static Maybe<Rect> intersection(Rect const &a, Rect const &b);
+ static Maybe<Rect> intersection(Maybe<Rect> const &a, Maybe<Rect> const &b);
/** Returns the smallest rectangle that encloses both rectangles. */
- static Rect union_bounds(Rect const &a, Rect const &b);
+ static Maybe<Rect> union_bounds(Maybe<Rect> const &a, Maybe<Rect> const &b);
/** Scales the rect by s, with origin at 0, 0 */
inline Rect operator*(double const s) const {