gRegion::gRegion(const eRect &rect) : extends(rect)
{
- rects.push_back(rect);
+ if (rect.valid() && !rect.empty())
+ rects.push_back(rect);
}
-gRegion::gRegion()
+gRegion::gRegion() : extends(eRect::emptyRect())
{
}
{
// Figure out how many rectangles are in the band.
unsigned int numRects = curStart - prevStart;
- assert(numRects == rects.size() - curStart);
+ ASSERT(numRects == rects.size() - curStart);
if (!numRects)
return curStart;
std::vector<eRect>::iterator prevBox = rects.begin() + prevStart;
std::vector<eRect>::const_iterator rEnd, int y1, int y2)
{
int newRects = rEnd - r;
- assert(y1 < y2);
- assert(newRects != 0);
+ ASSERT(y1 < y2);
+ ASSERT(newRects != 0);
rects.reserve(rects.size() + newRects);
do {
- assert(r->x1 < r->x2);
+ ASSERT(r->x1 < r->x2);
rects.push_back(eRect(r->x1, y1, r->x2 - r->x1, y2 - y1));
r++;
} while (r != rEnd);
{
int x1, x2;
- assert(y1 < y2);
- assert(r1 != r1End && r2 != r2End);
+ ASSERT(y1 < y2);
+ ASSERT(r1 != r1End && r2 != r2End);
do {
x1 = max(r1->x1, r2->x1);
int x1;
x1 = r1->x1;
- assert(y1<y2);
- assert(r1 != r1End && r2 != r2End);
+ ASSERT(y1<y2);
+ ASSERT(r1 != r1End && r2 != r2End);
do {
if (r2->x2 <= x1)
} else
++r2;
} else if (r2->x1 < r1->x2) {
- assert(x1<r2->x1);
+ ASSERT(x1<r2->x1);
rects.push_back(eRect(x1, y1, r2->x1 - x1, y2 - y1));
x1 = r2->x2;
if (x1 >= r1->x2) {
} while ((r1 != r1End) && (r2 != r2End));
while (r1 != r1End)
{
- assert(x1<r1->x2);
+ ASSERT(x1<r1->x2);
rects.push_back(eRect(x1, y1, r1->x2 - x1, y2 - y1));
++r1;
if (r1 != r1End)
{
int x1, x2;
- assert(y1 < y2);
- assert(r1 != r1End && r2 != r2End);
+ ASSERT(y1 < y2);
+ ASSERT(r1 != r1End && r2 != r2End);
if (r1->x1 < r2->x1)
{
int newSize = reg1.rects.size();
int numRects = reg2.rects.size();
- assert(r1 != r1End);
- assert(r2 != r2End);
+ ASSERT(r1 != r1End);
+ ASSERT(r2 != r2End);
if (numRects > newSize)
newSize = numRects;
int ybot = min(r1->y1, r2->y1);
prevBand = 0;
do {
- assert(r1 != r1End);
- assert(r2 != r2End);
+ ASSERT(r1 != r1End);
+ ASSERT(r2 != r2End);
FindBand(r1, r1BandEnd, r1End, r1y1);
FindBand(r2, r2BandEnd, r2End, r2y1);
if (r1y1 < r2y1) {
bot = min(r1->y2, r2y1);
if (top != bot) {
curBand = rects.size();
- appendNonO(r1, r1BandEnd, top, bot);
- coalesce(prevBand, curBand);
+ appendNonO(r1, r1BandEnd, top, bot);
+ coalesce(prevBand, curBand);
}
}
ytop = r2y1;
mergeO(r1, r1BandEnd, r2, r2BandEnd, ytop, ybot, overlap);
break;
default:
- assert(0);
+ ASSERT(0);
break;
}
coalesce(prevBand, curBand);
coalesce(prevBand, curBand);
AppendRegions(r2BandEnd, r2End);
}
+
extends = eRect();
- for (int a=0; a<rects.size(); ++a)
- extends = extends | eRect(rects[0].topLeft(), rects[rects.size()-1].bottomRight());
+ for (unsigned int a = 0; a<rects.size(); ++a)
+ extends = extends | rects[a];
+ if (!extends.valid())
+ extends = eRect::emptyRect();
}
void gRegion::intersect(const gRegion &r1, const gRegion &r2)
{
+ /* in case one region is empty, the resulting regions is empty, too. */
if (r1.rects.empty())
{
- *this = r2;
+ *this = r1;
return;
}
if (r2.rects.empty())
{
- *this = r1;
+ *this = r2;
return;
}
int overlap;
void gRegion::moveBy(ePoint offset)
{
extends.moveBy(offset);
- int i;
+ unsigned int i;
for (i=0; i<rects.size(); ++i)
rects[i].moveBy(offset);
}
+void gRegion::scale(int x_n, int x_d, int y_n, int y_d)
+{
+ unsigned int i;
+ for (i=0; i<rects.size(); ++i)
+ rects[i].scale(x_n, x_d, y_n, y_d);
+}
+