Skip to content

Commit

Permalink
Fill in ratios after given reference ratio of 1 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipFackler committed Jun 28, 2023
1 parent 934c569 commit 70426bb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 25 deletions.
4 changes: 3 additions & 1 deletion include/plsm/Subpaving.inl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ Subpaving<TScalar, Dim, TEnum, TItemData, TMemSpace>::processSubdivisionRatios(
auto getNextFactor = [nonSelfFactors](auto toSub, auto refFactor) {
using T = std::remove_reference_t<decltype(refFactor)>;
if (toSub % refFactor == 0) {
return refFactor;
if (refFactor != 1) {
return refFactor;
}
}
auto opt = nonSelfFactors(static_cast<T>(toSub));
if (opt.empty()) {
Expand Down
96 changes: 72 additions & 24 deletions test/unittest_Subpaving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@ struct SubpavingTester
{
using Ratio = SubdivisionRatio<TSubpaving::dimension()>;

void
bool
checkRatios(const std::vector<Ratio>& ratios)
{
bool ret = true;
auto infos = subpaving.makeMirrorCopy()._subdivisionInfos;
REQUIRE(infos.size() == ratios.size());
#define EXPR infos.size() == ratios.size()
CHECK(EXPR);
if (!(EXPR)) {
return false;
}
#undef EXPR
for (std::size_t i = 0; i < infos.size(); ++i) {
#define EXPR infos[i].getRatio() == ratios[i]
ret = ret && EXPR;
CHECK(EXPR);
#undef EXPR
}
return ret;
}

TSubpaving subpaving;
Expand All @@ -38,28 +51,63 @@ makeSubpavingTester(const TSubpaving& subpaving)
TEMPLATE_LIST_TEST_CASE(
"Process Subdivision Ratios", "[Subpaving][template]", test::IntTypes)
{
auto subpaving = Subpaving<TestType, 2>({{{0, 100}, {0, 100}}}, {{{5, 5}}});
test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {2, 2}, {2, 2}}});

subpaving = Subpaving<TestType, 2>({{{0, 250}, {0, 50}}}, {{{5, 5}}});
test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {5, 2}, {2, 2}}});

subpaving = Subpaving<TestType, 2>({{{10, 20}, {25, 35}}}, {{{5, 5}}});
test::makeSubpavingTester(subpaving).checkRatios({{{5, 5}, {2, 2}}});

subpaving = Subpaving<TestType, 2>({{{0, 300}, {0, 275}}}, {{{5, 5}}});
test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {4, 11}, {3, 1}}});

subpaving = Subpaving<TestType, 2>({{{0, 2116}, {0, 1155}}}, {{{23, 11}}});
test::makeSubpavingTester(subpaving).checkRatios(
{{{23, 11}, {23, 7}, {2, 5}, {2, 3}}});

subpaving = Subpaving<TestType, 2>({{{0, 2116}, {0, 1155}}}, {{{2, 3}}});
test::makeSubpavingTester(subpaving).checkRatios(
{{{2, 3}, {2, 5}, {23, 7}, {23, 11}}});
Subpaving<TestType, 2> subpaving;

REQUIRE_NOTHROW(
subpaving = Subpaving<TestType, 2>({{{0, 100}, {0, 100}}}, {{{5, 5}}}));
REQUIRE(test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {2, 2}, {2, 2}}}));

REQUIRE_NOTHROW(
subpaving = Subpaving<TestType, 2>({{{0, 250}, {0, 50}}}, {{{5, 5}}}));
REQUIRE(test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {5, 2}, {2, 1}}}));

REQUIRE_NOTHROW(
subpaving = Subpaving<TestType, 2>({{{10, 20}, {25, 35}}}, {{{5, 5}}}));
REQUIRE(
test::makeSubpavingTester(subpaving).checkRatios({{{5, 5}, {2, 2}}}));

REQUIRE_NOTHROW(
subpaving = Subpaving<TestType, 2>({{{0, 300}, {0, 275}}}, {{{5, 5}}}));
REQUIRE(test::makeSubpavingTester(subpaving).checkRatios(
{{{5, 5}, {5, 5}, {4, 11}, {3, 1}}}));

REQUIRE_NOTHROW(subpaving = Subpaving<TestType, 2>(
{{{0, 2116}, {0, 1155}}}, {{{23, 11}}}));
REQUIRE(test::makeSubpavingTester(subpaving).checkRatios(
{{{23, 11}, {23, 7}, {2, 5}, {2, 3}}}));

REQUIRE_NOTHROW(subpaving = Subpaving<TestType, 2>(
{{{0, 2116}, {0, 1155}}}, {{{2, 3}}}));
REQUIRE(test::makeSubpavingTester(subpaving).checkRatios(
{{{2, 3}, {2, 5}, {23, 7}, {23, 11}}}));

// Based on xolotl cases
Subpaving<TestType, 4> sp;
REQUIRE_NOTHROW(
sp = Subpaving<TestType, 4>({{{0, 256}, {0, 256}, {0, 128}, {0, 128}}},
{{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2},
{1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}}));
REQUIRE(test::makeSubpavingTester(sp).checkRatios(
{{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {1, 1, 2, 2},
{1, 1, 2, 2}, {1, 1, 1, 2}, {1, 1, 2, 1}}}));

REQUIRE_NOTHROW(
sp = Subpaving<TestType, 4>({{{0, 256}, {0, 256}, {0, 128}, {0, 128}}},
{{{1, 1, 2, 1}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2},
{4, 4, 2, 2}, {1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}}));
REQUIRE(test::makeSubpavingTester(sp).checkRatios(
{{{1, 1, 2, 1}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2},
{1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}}));

REQUIRE_NOTHROW(
sp = Subpaving<TestType, 4>({{{0, 256}, {0, 256}, {0, 64}, {0, 128}}},
{{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2},
{1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}}));
REQUIRE(test::makeSubpavingTester(sp).checkRatios(
{{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {1, 1, 2, 2},
{1, 1, 2, 2}, {1, 1, 1, 2}}}));
}

TEMPLATE_LIST_TEST_CASE(
Expand Down

0 comments on commit 70426bb

Please sign in to comment.