bool RegionTestcase::RegionsAreEqual(BRegion *regionA, BRegion *regionB) { bool result = false; if (regionA->CountRects() == regionB->CountRects()) { bool gotAMatch = true; for(int i = 0; i < regionA->CountRects(); i++) { gotAMatch = false; for(int j = 0; j < regionB->CountRects(); j++) { if (regionA->RectAt(i) == regionB->RectAt(j)) { gotAMatch = true; break; } } if (!gotAMatch) { break; } } if (gotAMatch) { result = true; } } if (!result) { BRegion tempRegion(*regionA); tempRegion.Exclude(regionB); if (RegionIsEmpty(&tempRegion)) { tempRegion = *regionB; tempRegion.Exclude(regionA); if (RegionIsEmpty(&tempRegion)) { result = true; } } } if (result) { assert(regionA->Frame() == regionB->Frame()); if (regionA->CountRects() == 0) { assert(RegionIsEmpty(regionA)); assert(RegionIsEmpty(regionB)); } } return(result); }
void RegionTestcase::CheckFrame(BRegion *theRegion) { BRect theFrame = theRegion->Frame(); if (theFrame.IsValid()) { assert(!RegionIsEmpty(theRegion)); BRect testFrame = theRegion->RectAt(0); assert(theFrame.Contains(testFrame)); for(int i = 1; i < theRegion->CountRects(); i++) { BRect tempRect = theRegion->RectAt(i); assert(theFrame.Contains(tempRect)); testFrame = testFrame | tempRect; } assert(testFrame == theFrame); } else { assert(RegionIsEmpty(theRegion)); } }
void RegionExclude::CheckExclude(BRegion *resultRegion, BRegion *testRegionA, BRegion *testRegionB) { bool resultRegionEmpty = RegionIsEmpty(resultRegion); bool testRegionAEmpty = RegionIsEmpty(testRegionA); bool testRegionBEmpty = RegionIsEmpty(testRegionB); if (RegionsAreEqual(testRegionA, testRegionB)) { assert(resultRegionEmpty); } if (RegionsAreEqual(resultRegion, testRegionA)) { BRegion tempRegion(*testRegionA); tempRegion.IntersectWith(testRegionB); assert(RegionIsEmpty(&tempRegion)); } if (RegionsAreEqual(resultRegion, testRegionB)) { assert(resultRegionEmpty); assert(testRegionAEmpty); assert(testRegionBEmpty); } if ((!resultRegionEmpty) && (!testRegionAEmpty) && (!testRegionBEmpty)) { BRect resultRegionFrame(resultRegion->Frame()); BRect testRegionAFrame(testRegionA->Frame()); BRect testRegionBFrame(testRegionB->Frame()); if (!testRegionAFrame.Intersects(testRegionBFrame)) { assert(testRegionAFrame == resultRegionFrame); assert(RegionsAreEqual(resultRegion, testRegionA)); } else { assert(testRegionAFrame.Contains(resultRegionFrame)); } } if (testRegionBEmpty) { assert(RegionsAreEqual(resultRegion, testRegionA)); } else { assert(!RegionsAreEqual(resultRegion, testRegionB)); for(int i = 0; i < testRegionB->CountRects(); i++) { BRect tempRect = testRegionB->RectAt(i); assert(testRegionB->Intersects(tempRect)); assert(!resultRegion->Intersects(tempRect)); BPoint *pointArray; int numPoints = GetPointsInRect(tempRect, &pointArray); for (int j = 0; j < numPoints; j++) { assert(testRegionB->Contains(pointArray[j])); assert(!resultRegion->Contains(pointArray[j])); } } } if (testRegionAEmpty) { assert(resultRegionEmpty); } else { for(int i = 0; i < testRegionA->CountRects(); i++) { BRect tempRect = testRegionA->RectAt(i); assert(testRegionA->Intersects(tempRect)); if (!testRegionB->Intersects(tempRect)) { assert(resultRegion->Intersects(tempRect)); } BPoint *pointArray; int numPoints = GetPointsInRect(tempRect, &pointArray); for (int j = 0; j < numPoints; j++) { assert(testRegionA->Contains(pointArray[j])); if (testRegionB->Contains(pointArray[j])) { assert(!resultRegion->Contains(pointArray[j])); } else { assert(resultRegion->Contains(pointArray[j])); } } } } if (resultRegionEmpty) { BRegion tempRegion(*testRegionA); tempRegion.IntersectWith(testRegionB); assert(RegionsAreEqual(&tempRegion, testRegionA)); } else { assert(!RegionsAreEqual(resultRegion, testRegionB)); for(int i = 0; i < resultRegion->CountRects(); i++) { BRect tempRect = resultRegion->RectAt(i); assert(resultRegion->Intersects(tempRect)); assert(testRegionA->Intersects(tempRect)); assert(!testRegionB->Intersects(tempRect)); BPoint *pointArray; int numPoints = GetPointsInRect(tempRect, &pointArray); for (int j = 0; j < numPoints; j++) { assert(resultRegion->Contains(pointArray[j])); assert(testRegionA->Contains(pointArray[j])); assert(!testRegionB->Contains(pointArray[j])); } } } }