diff --git a/storm/Region.cpp b/storm/Region.cpp index b689c98..d5787eb 100644 --- a/storm/Region.cpp +++ b/storm/Region.cpp @@ -62,30 +62,17 @@ void CombineRectangles(TSGrowableArray* combinedArray) { if (rctA->bottom < rctB->top && rctB->bottom < rctA->top) { RECTF newrect[5]; - newrect[0].left = rctA->left; - newrect[0].bottom = rctA->bottom; - newrect[0].right = rctA->right; - newrect[0].top = rctB->bottom; + newrect[0] = { rctA->left, rctA->bottom, rctA->right, rctB->bottom }; + newrect[1] = { rctB->left, rctB->bottom, rctB->right, rctA->bottom }; + newrect[2] = { rctA->left, rctB->top, rctA->right, rctA->top }; + newrect[3] = { rctB->left, rctA->top, rctB->right, rctB->top }; - newrect[1].left = rctB->left; - newrect[1].bottom = rctB->bottom; - newrect[1].right = rctB->right; - newrect[1].top = rctA->bottom; - - newrect[2].left = rctA->left; - newrect[2].bottom = rctB->top; - newrect[2].right = rctA->right; - newrect[2].top = rctA->top; - - newrect[3].left = rctB->left; - newrect[3].bottom = rctA->top; - newrect[3].right = rctB->right; - newrect[3].top = rctB->top; - - newrect[4].left = std::min(rctB->left, rctA->left); - newrect[4].bottom = std::max(rctB->bottom, rctA->bottom); - newrect[4].right = std::max(rctB->right, rctA->right); - newrect[4].top = std::min(rctB->top, rctA->top); + newrect[4] = { + std::min(rctB->left, rctA->left), + std::max(rctB->bottom, rctA->bottom), + std::max(rctB->right, rctA->right), + std::min(rctB->top, rctA->top) + }; for (uint32_t k = 0; k < 5; k++) { if (!IsNullRect(&newrect[k])) { @@ -135,25 +122,20 @@ void FragmentCombinedRectangles(TSGrowableArray* combinedArray, uint32_t } RECTF newrect[4]; - newrect[0].left = rect->left; - newrect[0].bottom = rect->bottom; - newrect[0].right = rect->right; - newrect[0].top = checkRect->bottom; - - newrect[1].left = rect->left; - newrect[1].bottom = checkRect->top; - newrect[1].right = rect->right; - newrect[1].top = rect->top; - - newrect[2].left = rect->left; - newrect[2].bottom = std::max(checkRect->bottom, rect->bottom); - newrect[2].right = checkRect->left; - newrect[2].top = std::min(checkRect->top, rect->top); - - newrect[3].left = checkRect->right; - newrect[3].bottom = std::max(checkRect->bottom, rect->bottom); - newrect[3].right = rect->right; - newrect[3].top = std::min(checkRect->top, rect->top); + newrect[0] = { rect->left, rect->bottom, rect->right, checkRect->bottom }; + newrect[1] = { rect->left, checkRect->top, rect->right, rect->top }; + newrect[2] = { + rect->left, + std::max(checkRect->bottom, rect->bottom), + checkRect->left, + std::min(checkRect->top, rect->top) + }; + newrect[3] = { + checkRect->right, + std::max(checkRect->bottom, rect->bottom), + rect->right, + std::min(checkRect->top, rect->top) + }; for (uint32_t i = 0; i < 4; i++) { if (!IsNullRect(&newrect[i])) { @@ -331,6 +313,20 @@ void SRgnCombineRectf(HSRGN handle, RECTF* rect, void* param, int32_t combineMod s_rgntable.Unlock(lockedHandle); } +void SRgnClear(HSRGN handle) { + STORM_VALIDATE_BEGIN; + STORM_VALIDATE(handle); + STORM_VALIDATE_END_VOID; + + HLOCKEDRGN lockedHandle; + auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); + + if (rgn) { + ClearRegion(rgn); + s_rgntable.Unlock(lockedHandle); + } +} + void SRgnCreate(HSRGN* handlePtr, uint32_t reserved) { STORM_VALIDATE_BEGIN; STORM_VALIDATE(handlePtr); diff --git a/storm/Region.hpp b/storm/Region.hpp index 9466f40..8f42742 100644 --- a/storm/Region.hpp +++ b/storm/Region.hpp @@ -4,6 +4,8 @@ #include "storm/region/Types.hpp" #include +void SRgnClear(HSRGN handle); + void SRgnCombineRectf(HSRGN handle, RECTF* rect, void* param, int32_t combineMode); void SRgnCreate(HSRGN* handlePtr, uint32_t reserved); diff --git a/test/Region.cpp b/test/Region.cpp index b5e9450..8da9cf0 100644 --- a/test/Region.cpp +++ b/test/Region.cpp @@ -1,5 +1,33 @@ #include "RegionTest.hpp" +TEST_CASE("SRgnClear", "[region]") { + RgnDataTest region; + + SECTION("operates on an empty object") { + uint32_t numrects = 0; + + SRgnClear(region); + + SRgnGetRectsf(region, &numrects, nullptr); + CHECK(numrects == 0); + } + + SECTION("clears rects out of a region object") { + uint32_t numrects = 0; + + RECTF baseRect = { 0.0f, 0.0f, 1.0f, 1.0f }; + SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR); + + SRgnGetRectsf(region, &numrects, nullptr); + CHECK(numrects == 1); + + SRgnClear(region); + + SRgnGetRectsf(region, &numrects, nullptr); + CHECK(numrects == 0); + } +} + TEST_CASE("SRgnCreate", "[region]") { SECTION("sets handle pointer to new region handle") { HSRGN region = nullptr;