[patch] simplify Region::addRectangle ()
Hi, the patch below simplifies Region::addRectangle () quite a bit. It now simply tries to minimize the sum of the areas of all rectangles in the Region while still covering all rectangles that have been added with addRectangle (). For example if we have Thereby the total area that is actually redrawn is reduced and the code gets much simpler. However it may now happen that small parts of the screen are drawn that were not requested to be drawn. This patch does not reduce any flickering. Cheers, Johannes diff --git a/dw/types.cc b/dw/types.cc --- a/dw/types.cc +++ b/dw/types.cc @@ -240,40 +240,22 @@ void Region::addRectangle (Rectangle *rP for (it = rectangleList->iterator (); it.hasNext (); ) { Rectangle *ownRect = it.getNext (); - /* check if r an ownRect can be combined vertically */ - if (r->x == ownRect->x && r->width == ownRect->width) { - int combinedHeight = - misc::max(r->y + r->height, ownRect->y + ownRect->height) - - misc::min(r->y, ownRect->y); + int combinedHeight = + misc::max(r->y + r->height, ownRect->y + ownRect->height) - + misc::min(r->y, ownRect->y); + int combinedWidth = + misc::max(r->x + r->width, ownRect->x + ownRect->width) - + misc::min(r->x, ownRect->x); - if (combinedHeight <= r->height + ownRect->height) { + if (combinedWidth * combinedHeight <= + ownRect->width * ownRect->height + r->width * r->height) { + + r->x = misc::min(r->x, ownRect->x); r->y = misc::min(r->y, ownRect->y); + r->width = combinedWidth; r->height = combinedHeight; + rectangleList->removeRef (ownRect); - } - - /* check if r an ownRect can be combined horizontally */ - } else if (r->y == ownRect->y && r->height == ownRect->height) { - int combinedWidth = - misc::max(r->x + r->width, ownRect->x + ownRect->width) - - misc::min(r->x, ownRect->x); - - if (combinedWidth <= r->width + ownRect->width) { - r->x = misc::min(r->x, ownRect->x); - r->width = combinedWidth; - rectangleList->removeRef (ownRect); - } - } - } - - for (it = rectangleList->iterator (); it.hasNext (); ) { - Rectangle *ownRect = it.getNext (); - - if (r->isSubsetOf (ownRect)) { - delete r; - return; - } else if (ownRect->isSubsetOf (r)) { - rectangleList->removeRef (ownRect); } } diff --git a/dw/types.hh b/dw/types.hh --- a/dw/types.hh +++ b/dw/types.hh @@ -121,6 +121,8 @@ public: * \brief dw::core::Shape implementation for a point set. * Currently represented as a set of rectangles not containing * each other. + * It is guaranteed that the rectangles returned by rectangles () + * cover all rectangles that were added with addRectangle (). */ class Region: public Shape {
On Wed, Mar 05, 2008 at 06:19:49PM +0100, Johannes Hofmann wrote:
Hi,
the patch below simplifies Region::addRectangle () quite a bit. It now simply tries to minimize the sum of the areas of all rectangles in the Region while still covering all rectangles that have been added with addRectangle (). For example if we have
Thereby the total area that is actually redrawn is reduced and the code gets much simpler. However it may now happen that small parts of the screen are drawn that were not requested to be drawn.
It looks like a part of the explanation got trimmed. Would you mind resend it? -- Cheers Jorge.-
On Wed, Mar 05, 2008 at 03:22:09PM -0300, Jorge Arellano Cid wrote:
On Wed, Mar 05, 2008 at 06:19:49PM +0100, Johannes Hofmann wrote:
Hi,
the patch below simplifies Region::addRectangle () quite a bit. It now simply tries to minimize the sum of the areas of all rectangles in the Region while still covering all rectangles that have been added with addRectangle (). For example if we have
Thereby the total area that is actually redrawn is reduced and the code gets much simpler. However it may now happen that small parts of the screen are drawn that were not requested to be drawn.
It looks like a part of the explanation got trimmed. Would you mind resend it?
Yeah, I had started some fancy ASCII art which got more complex than the code involved :-) Cheers, Johannes
On Wed, Mar 05, 2008 at 06:19:49PM +0100, Johannes Hofmann wrote:
Hi,
the patch below simplifies Region::addRectangle () quite a bit. It now simply tries to minimize the sum of the areas of all rectangles in the Region while still covering all rectangles that have been added with addRectangle (). For example if we have
Thereby the total area that is actually redrawn is reduced and the code gets much simpler. However it may now happen that small parts of the screen are drawn that were not requested to be drawn.
OK, forget the extra explanation, I read and understood the code and it looks quite reasonable. Committed. -- Cheers Jorge.-
participants (2)
-
jcid@dillo.org
-
Johannes.Hofmann@gmx.de