2025-04-20 21:53:01 -07:00
|
|
|
#include "RegionTest.hpp"
|
2023-03-30 14:37:05 -05:00
|
|
|
|
2025-04-20 23:17:39 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 14:37:05 -05:00
|
|
|
TEST_CASE("SRgnCreate", "[region]") {
|
|
|
|
|
SECTION("sets handle pointer to new region handle") {
|
2025-04-20 21:53:01 -07:00
|
|
|
HSRGN region = nullptr;
|
2025-04-21 00:10:10 -07:00
|
|
|
SRgnCreate(®ion);
|
2023-03-30 14:37:05 -05:00
|
|
|
|
|
|
|
|
REQUIRE(region != nullptr);
|
|
|
|
|
|
|
|
|
|
SRgnDelete(region);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("SRgnCombineRectf", "[region]") {
|
2025-04-20 21:53:01 -07:00
|
|
|
RgnDataTest region;
|
2023-03-30 14:37:05 -05:00
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
SECTION("combines the region with a single given rect 1") {
|
2023-03-30 14:37:05 -05:00
|
|
|
RECTF baseRect = { 0.0f, 0.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
2023-03-30 14:37:05 -05:00
|
|
|
|
|
|
|
|
RECTF boundingRect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
SRgnGetBoundingRectf(region, &boundingRect);
|
|
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(boundingRect, MatchesRect({ 0.0f, 0.0f, 1.0f, 1.0f }));
|
2023-03-30 14:37:05 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-31 22:29:49 -05:00
|
|
|
SECTION("combines the region with multiple given rects 1") {
|
2023-03-30 14:37:05 -05:00
|
|
|
RECTF baseRect = { 0.0f, 0.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
2023-03-30 14:37:05 -05:00
|
|
|
|
|
|
|
|
RECTF newRect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &newRect, nullptr, SRGN_DIFF);
|
2023-03-30 14:37:05 -05:00
|
|
|
|
|
|
|
|
RECTF boundingRect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
SRgnGetBoundingRectf(region, &boundingRect);
|
|
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(boundingRect, MatchesRect({ 0.0f, 0.0f, 1.0f, 1.0f }));
|
2023-03-30 14:37:05 -05:00
|
|
|
}
|
2023-03-31 22:29:49 -05:00
|
|
|
|
|
|
|
|
SECTION("combines the region with multiple given rects 2") {
|
|
|
|
|
RECTF baseRect = { 0.0f, 0.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
2023-03-31 22:29:49 -05:00
|
|
|
|
|
|
|
|
RECTF newRect = { 0.0f, 0.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &newRect, nullptr, SRGN_DIFF);
|
2023-03-31 22:29:49 -05:00
|
|
|
|
|
|
|
|
RECTF boundingRect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
SRgnGetBoundingRectf(region, &boundingRect);
|
|
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(boundingRect, MatchesRect({ 0.0f, 0.0f, 0.0f, 0.0f }));
|
2023-03-31 22:29:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("combines the region with multiple given rects 3") {
|
|
|
|
|
RECTF baseRect = { 0.0f, 0.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
2023-03-31 22:29:49 -05:00
|
|
|
|
|
|
|
|
RECTF newRect = { 0.0f, 1.0f, 1.0f, 1.0f };
|
2025-04-20 13:06:12 -07:00
|
|
|
SRgnCombineRectf(region, &newRect, nullptr, SRGN_DIFF);
|
2023-03-31 22:29:49 -05:00
|
|
|
|
|
|
|
|
RECTF boundingRect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
SRgnGetBoundingRectf(region, &boundingRect);
|
|
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(boundingRect, MatchesRect({ 0.0f, 0.0f, 1.0f, 1.0f }));
|
2023-03-31 22:29:49 -05:00
|
|
|
}
|
2023-03-30 14:37:05 -05:00
|
|
|
}
|
2025-04-20 19:56:40 -07:00
|
|
|
|
2025-04-21 00:10:10 -07:00
|
|
|
TEST_CASE("SRgnDelete", "[region]") {
|
|
|
|
|
SECTION("deletes region data") {
|
|
|
|
|
HSRGN region = nullptr;
|
|
|
|
|
SRgnCreate(®ion);
|
|
|
|
|
|
|
|
|
|
RECTF baseRect = { -1.0f, 1.0f, 1.0f, 2.0f };
|
|
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
|
|
|
|
|
|
|
|
|
uint32_t numrects = 0;
|
|
|
|
|
|
|
|
|
|
SRgnGetRectsf(region, &numrects, nullptr);
|
|
|
|
|
CHECK(numrects == 1);
|
|
|
|
|
|
|
|
|
|
SRgnDelete(region);
|
|
|
|
|
|
|
|
|
|
SRgnGetRectsf(region, &numrects, nullptr);
|
|
|
|
|
CHECK(numrects == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-21 00:03:37 -07:00
|
|
|
TEST_CASE("SRgnDuplicate", "[region]") {
|
|
|
|
|
RgnDataTest region;
|
|
|
|
|
|
|
|
|
|
SECTION("creates an independent copy of a region") {
|
|
|
|
|
RECTF baseRect = { -1.0f, 1.0f, 1.0f, 2.0f };
|
|
|
|
|
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
|
|
|
|
|
|
|
|
|
|
HSRGN newrgn = nullptr;
|
|
|
|
|
SRgnDuplicate(region, &newrgn);
|
|
|
|
|
|
|
|
|
|
REQUIRE(newrgn != nullptr);
|
|
|
|
|
SRgnClear(region);
|
|
|
|
|
|
|
|
|
|
uint32_t numrects = 1;
|
|
|
|
|
RECTF buffer[1];
|
|
|
|
|
SRgnGetRectsf(newrgn, &numrects, buffer);
|
|
|
|
|
|
|
|
|
|
REQUIRE(numrects == 1);
|
|
|
|
|
CHECK_THAT(buffer[0], MatchesRect(baseRect));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("sets handle to null when using an invalid region object") {
|
|
|
|
|
HSRGN inval = reinterpret_cast<HSRGN>(1234);
|
|
|
|
|
|
|
|
|
|
HSRGN newrgn = reinterpret_cast<HSRGN>(12345);
|
|
|
|
|
SRgnDuplicate(inval, &newrgn);
|
|
|
|
|
|
|
|
|
|
CHECK(newrgn == nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-21 15:20:25 -07:00
|
|
|
TEST_CASE("SRgnGetRectParamsf", "[region]") {
|
|
|
|
|
RgnDataTest region;
|
|
|
|
|
|
|
|
|
|
SECTION("retrieves empty list if nothing put in") {
|
|
|
|
|
uint32_t numParams = 1;
|
|
|
|
|
void* buffer[1];
|
|
|
|
|
|
|
|
|
|
RECTF rect = { 0, 0, 1, 1 };
|
|
|
|
|
SRgnGetRectParamsf(region, &rect, &numParams, buffer);
|
|
|
|
|
|
|
|
|
|
CHECK(numParams == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("retrieves 0 when using an invalid region object") {
|
|
|
|
|
HSRGN inval = reinterpret_cast<HSRGN>(1234);
|
|
|
|
|
|
|
|
|
|
uint32_t numParams = 1;
|
|
|
|
|
RECTF rect = { 0, 0, 1, 1 };
|
|
|
|
|
SRgnGetRectParamsf(inval, &rect, &numParams, nullptr);
|
|
|
|
|
|
|
|
|
|
CHECK(numParams == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("retrieves only overlapping params") {
|
|
|
|
|
RECTF rect1 = { 0, 0, 1, 1 };
|
|
|
|
|
RECTF rect2 = { 2, 2, 4, 4 };
|
|
|
|
|
RECTF rect3 = { 2.5, 2.5, 5, 5 };
|
|
|
|
|
RECTF queryRect = { 3, 3, 5, 5 };
|
|
|
|
|
int param1 = 5;
|
|
|
|
|
int param2 = 10;
|
|
|
|
|
int param3 = 11;
|
|
|
|
|
|
|
|
|
|
SRgnCombineRectf(region, &rect1, ¶m1, SRGN_PARAMONLY);
|
|
|
|
|
SRgnCombineRectf(region, &rect2, ¶m2, SRGN_PARAMONLY);
|
|
|
|
|
SRgnCombineRectf(region, &rect3, ¶m3, SRGN_PARAMONLY);
|
|
|
|
|
|
|
|
|
|
uint32_t numParams = 0;
|
|
|
|
|
SRgnGetRectParamsf(region, &queryRect, &numParams, nullptr);
|
|
|
|
|
REQUIRE(numParams == 2);
|
|
|
|
|
|
|
|
|
|
void* buffer[2];
|
|
|
|
|
SRgnGetRectParamsf(region, &queryRect, &numParams, buffer);
|
|
|
|
|
CHECK(numParams == 2);
|
|
|
|
|
CHECK(buffer[0] == ¶m2);
|
|
|
|
|
CHECK(buffer[1] == ¶m3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 19:56:40 -07:00
|
|
|
TEST_CASE("SRgnGetRectsf", "[region]") {
|
2025-04-20 21:53:01 -07:00
|
|
|
RgnDataTest region;
|
2025-04-20 19:56:40 -07:00
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
SECTION("retrieves empty list if nothing put in") {
|
2025-04-20 19:56:40 -07:00
|
|
|
uint32_t numrects = 1;
|
|
|
|
|
RECTF buffer[1];
|
|
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnGetRectsf(region, &numrects, buffer);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
|
|
|
|
CHECK(numrects == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-21 15:20:25 -07:00
|
|
|
SECTION("retrieves 0 when using an invalid region object") {
|
|
|
|
|
HSRGN inval = reinterpret_cast<HSRGN>(1234);
|
|
|
|
|
|
|
|
|
|
uint32_t numrects = 1;
|
|
|
|
|
SRgnGetRectsf(inval, &numrects, nullptr);
|
|
|
|
|
|
|
|
|
|
CHECK(numrects == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 19:56:40 -07:00
|
|
|
SECTION("retrieves all rects that were put in") {
|
|
|
|
|
RECTF rct1 = { 5, 5, 10, 10 };
|
|
|
|
|
RECTF rct2 = { 0, 0, 1, 1 };
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnCombineRectf(region, &rct1, nullptr, SRGN_OR);
|
|
|
|
|
SRgnCombineRectf(region, &rct2, nullptr, SRGN_OR);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
|
|
|
|
uint32_t numrects = 0;
|
|
|
|
|
RECTF buffer[2];
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnGetRectsf(region, &numrects, nullptr);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
|
|
|
|
REQUIRE(numrects == 2);
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnGetRectsf(region, &numrects, buffer);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(buffer[0], MatchesRect(rct2));
|
|
|
|
|
CHECK_THAT(buffer[1], MatchesRect(rct1));
|
2025-04-20 19:56:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("automatically merges overlapping rects") {
|
|
|
|
|
RECTF rct1 = { -10, -10, 10, 10 };
|
|
|
|
|
RECTF rct2 = { 0, 0, 1, 1 };
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnCombineRectf(region, &rct1, nullptr, SRGN_OR);
|
|
|
|
|
SRgnCombineRectf(region, &rct2, nullptr, SRGN_OR);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
|
|
|
|
uint32_t numrects = 0;
|
|
|
|
|
RECTF buffer[1];
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnGetRectsf(region, &numrects, nullptr);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
|
|
|
|
REQUIRE(numrects == 1);
|
2025-04-20 21:53:01 -07:00
|
|
|
SRgnGetRectsf(region, &numrects, buffer);
|
2025-04-20 19:56:40 -07:00
|
|
|
|
2025-04-20 21:53:01 -07:00
|
|
|
CHECK_THAT(buffer[0], MatchesRect(rct1));
|
2025-04-20 19:56:40 -07:00
|
|
|
}
|
|
|
|
|
}
|