special-case region intersection for rectangular regions

svn: r6123
This commit is contained in:
Matthew Flatt 2007-05-03 06:14:41 +00:00
parent 9ed4e691c8
commit 78e128b380
2 changed files with 48 additions and 3 deletions

View File

@ -705,15 +705,57 @@ void wxRegion::Union(wxRegion *r)
void wxRegion::Intersect(wxRegion *r) void wxRegion::Intersect(wxRegion *r)
{ {
if (r->dc != dc) return; if (r->dc != dc) return;
if (ReallyEmpty())
return;
if (r->ReallyEmpty()) { if (r->ReallyEmpty()) {
Cleanup(); Cleanup();
return; return;
} }
if (!no_prgn) { if (!no_prgn) {
wxPathRgn *pr; wxPathRgn *rprgn, *pr;
if (!r->prgn) abort(); rprgn = r->prgn;
if (!rprgn) abort();
if (prgn->is_rect
&& rprgn->is_rect
&& (prgn->ox == rprgn->ox)
&& (prgn->oy == rprgn->oy)
&& (prgn->sx == rprgn->sx)
&& (prgn->sy == rprgn->sy)) {
/* Special case: both are rectangles with the same
origin and scale. This is a common case, and it
can be a lot faster making a rectangle directly. */
wxRectanglePathRgn *r1 = (wxRectanglePathRgn *)prgn;
wxRectanglePathRgn *r2 = (wxRectanglePathRgn *)rprgn;
double px, py, pw, ph;
if (r1->x < r2->x)
px = r2->x;
else
px = r1->x;
if (r1->y < r2->y)
py = r2->y;
else
py = r1->y;
if (r1->x + r1->width < r2->x + r2->width)
pw = (r1->x + r1->width) - px;
else
pw = (r2->x + r2->width) - px;
if (r1->y + r1->height < r2->y + r2->height)
ph = (r1->y + r1->height) - py;
else
ph = (r2->y + r2->height) - py;
if ((pw > 0) && (ph > 0))
pr = new WXGC_PTRS wxRectanglePathRgn(dc, px, py, pw, ph);
else {
/* empty */
Cleanup();
return;
}
} else {
pr = new WXGC_PTRS wxIntersectPathRgn(prgn, r->prgn); pr = new WXGC_PTRS wxIntersectPathRgn(prgn, r->prgn);
}
prgn = pr; prgn = pr;
} }
@ -1106,6 +1148,7 @@ wxPathRgn::wxPathRgn(wxDC *dc)
ox = oy = 0.0; ox = oy = 0.0;
sx = sy = 1.0; sx = sy = 1.0;
} }
is_rect = 0;
} }
wxPathRgn::~wxPathRgn() wxPathRgn::~wxPathRgn()
@ -1223,6 +1266,7 @@ wxRectanglePathRgn::wxRectanglePathRgn(wxDC *dc_for_scale, double _x, double _y,
y = _y; y = _y;
width = _width; width = _width;
height = _height; height = _height;
is_rect = 1;
} }
Bool wxRectanglePathRgn::Install(long target, Bool reverse, Bool align) Bool wxRectanglePathRgn::Install(long target, Bool reverse, Bool align)

View File

@ -104,6 +104,7 @@ class wxPathRgn : public wxObject
{ {
public: public:
double ox, oy, sx, sy; double ox, oy, sx, sy;
int is_rect;
wxPathRgn(wxDC *dc_for_scale); wxPathRgn(wxDC *dc_for_scale);
~wxPathRgn(); ~wxPathRgn();