diff --git a/test/testpaint/SegmentSupportHeightCall.cpp b/test/testpaint/SegmentSupportHeightCall.cpp index 6bb5fcadc4..c769021d92 100644 --- a/test/testpaint/SegmentSupportHeightCall.cpp +++ b/test/testpaint/SegmentSupportHeightCall.cpp @@ -14,6 +14,8 @@ *****************************************************************************/ #pragma endregion +#include + #include "SegmentSupportHeightCall.hpp" extern "C" { @@ -110,3 +112,41 @@ bool SegmentSupportHeightCall::CallsEqual(std::vector lhs, s return true; } + +std::vector* SegmentSupportHeightCall::FindMostCommonSupportCall(std::vector *calls) { + std::map, int> map; + + for (int i = 0; i < 4; ++i) { + if (map.count(calls[i]) == 0) { + map[calls[i]] = 1; + } else { + map[calls[i]] += 1; + } + } + + if (map.size() == 1) { + return &calls[0]; + } + + if (map.size() == 2) { + for (auto &&item : map) { + if (item.second == 3) { + return (std::vector *)&item.first; + } + } + + return nullptr; + } + + if (map.size() == 3) { + for (auto &&item : map) { + if (item.second == 2) { + return (std::vector *)&item.first; + } + } + + return nullptr; + } + + return nullptr; +} diff --git a/test/testpaint/SegmentSupportHeightCall.hpp b/test/testpaint/SegmentSupportHeightCall.hpp index 5a87709967..bc7d159b2c 100644 --- a/test/testpaint/SegmentSupportHeightCall.hpp +++ b/test/testpaint/SegmentSupportHeightCall.hpp @@ -26,6 +26,18 @@ struct SegmentSupportCall uint16 segments; sint32 height; sint16 slope; + + bool operator<(const SegmentSupportCall &other) const { + if (height != other.height) { + return height < other.height; + } + + if (segments != other.segments) { + return segments < other.segments; + } + + return slope < other.slope; + } }; class SegmentSupportHeightCall { @@ -33,4 +45,5 @@ public: static std::vector getSegmentCalls(support_height supports[9], uint8 rotation); static bool CallsMatch(std::vector tileSegmentSupportCalls[4]); static bool CallsEqual(std::vector lhs, std::vector rhs); + static std::vector * FindMostCommonSupportCall(std::vector calls[4]); }; diff --git a/test/testpaint/intercept_2.cpp b/test/testpaint/intercept_2.cpp index c972b32bbc..8fdd7cbba7 100644 --- a/test/testpaint/intercept_2.cpp +++ b/test/testpaint/intercept_2.cpp @@ -270,13 +270,19 @@ namespace Intercept2 } } + std::vector referenceCalls = tileSegmentSupportCalls[0]; + if (!SegmentSupportHeightCall::CallsMatch(tileSegmentSupportCalls)) { - // TODO: if 3 directions do share the same mask, use that call list as a reference. - printf("Original segment calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift); - for (int i = 0; i < 4; i++) { - printf("# %d\n%s", i, Printer::PrintSegmentSupportHeightCalls(tileSegmentSupportCalls[i]).c_str()); + std::vector *found = SegmentSupportHeightCall::FindMostCommonSupportCall(tileSegmentSupportCalls); + if (found != nullptr) { + referenceCalls = *found; + } else { + printf("Original segment calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift); + for (int i = 0; i < 4; i++) { + printf("# %d\n%s", i, Printer::PrintSegmentSupportHeightCalls(tileSegmentSupportCalls[i]).c_str()); + } + continue; } - continue; } for (int direction = 0; direction < 4; direction++) { @@ -320,7 +326,6 @@ namespace Intercept2 if (!GeneralSupportHeightCall::CallsMatch(tileGeneralSupportCalls)) { SupportCall *found = GeneralSupportHeightCall::FindMostCommonSupportCall(tileGeneralSupportCalls); if (found == nullptr) { - // TODO: if 3 directions do share the output, use that. printf("Original support calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift); for (int i = 0; i < 4; ++i) { printf("[%d, 0x%02X] ", tileGeneralSupportCalls[i].height, tileGeneralSupportCalls[i].slope);