From edc6e254f31e94ba0da5a7adb534bc0ad411c035 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 1 Jul 2004 06:16:00 +0000 Subject: [PATCH] Fixed the outstanding BRegion bug. It turned out that rects_intersect() returned true in some cases when called with an invalid clipping_rect. Added an ASSERT() call to BRegion::_AddRect(), which would've saved my day. Added some comments git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8246 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/clipping.h | 22 +++++++++++++++++++++- src/kits/interface/Region.cpp | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/headers/private/interface/clipping.h b/headers/private/interface/clipping.h index fc38cd515e..af9e7ddde8 100644 --- a/headers/private/interface/clipping.h +++ b/headers/private/interface/clipping.h @@ -12,6 +12,8 @@ calculations). */ + +// Returns the union of the given rects. static inline clipping_rect union_rect(clipping_rect r1, clipping_rect r2) { @@ -43,6 +45,7 @@ sect_rect(clipping_rect r1, clipping_rect r2) } +// Adds the given offsets to the given rect. static inline void offset_rect(clipping_rect &rect, int32 x, int32 y) { @@ -53,13 +56,15 @@ offset_rect(clipping_rect &rect, int32 x, int32 y) } +// Converts the given clipping_rect to a BRect static inline BRect to_BRect(clipping_rect rect) { - return BRect(rect.left, rect.top, rect.right, rect.bottom); + return BRect((float)rect.left, (float)rect.top, (float)rect.right, (float)rect.bottom); } +// Converts the given BRect to a clipping_rect. static inline clipping_rect to_clipping_rect(BRect rect) { @@ -74,6 +79,7 @@ to_clipping_rect(BRect rect) } +// Checks if the given point lies in the given rect's area static inline bool point_in(clipping_rect rect, int32 px, int32 py) { @@ -84,6 +90,7 @@ point_in(clipping_rect rect, int32 px, int32 py) } +// Same as above, but it accepts a BPoint parameter static inline bool point_in(clipping_rect rect, BPoint pt) { @@ -94,6 +101,7 @@ point_in(clipping_rect rect, BPoint pt) } +// Checks if the rect is valid static inline bool valid_rect(clipping_rect rect) { @@ -103,14 +111,25 @@ valid_rect(clipping_rect rect) } +// Checks if the two rects intersect. static inline bool rects_intersect(clipping_rect rectA, clipping_rect rectB) { + // TODO: should we skip that check and let the caller do this + // kind of work ? + if (!valid_rect(rectA) || !valid_rect(rectB)) + return false; + + // TODO: Is there a better algorithm ? + // the one we used is faster than + // ' return valid_rect(sect_rect(rectA, rectB)); ', though. + return !(rectA.left > rectB.right || rectA.top > rectB.bottom || rectA.right < rectB.left || rectA.bottom < rectB.top); } +// Returns the width of the given rect. static inline int32 rect_width(clipping_rect rect) { @@ -118,6 +137,7 @@ rect_width(clipping_rect rect) } +// Returns the height of the given rect. static inline int32 rect_height(clipping_rect rect) { diff --git a/src/kits/interface/Region.cpp b/src/kits/interface/Region.cpp index da1fe04d99..4214cb11e0 100644 --- a/src/kits/interface/Region.cpp +++ b/src/kits/interface/Region.cpp @@ -435,7 +435,8 @@ BRegion::_AddRect(clipping_rect rect) { ASSERT(count >= 0); ASSERT(data_size >= 0); - + ASSERT(valid_rect(rect)); + // Should we just reallocate the memory and // copy the rect ? bool addRect = true;