From 4785bbe9da212b788e6f2fc9c33f4ed444c9c69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 2 Nov 2022 22:07:46 +0100 Subject: [PATCH] DebugTools: remove unnecessary std::tuple usage from CompareImage. --- src/Magnum/DebugTools/CompareImage.cpp | 14 +++--- src/Magnum/DebugTools/CompareImage.h | 3 +- .../DebugTools/Test/CompareImageTest.cpp | 45 ++++++++----------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/Magnum/DebugTools/CompareImage.cpp b/src/Magnum/DebugTools/CompareImage.cpp index 14f5e448c..c255df58d 100644 --- a/src/Magnum/DebugTools/CompareImage.cpp +++ b/src/Magnum/DebugTools/CompareImage.cpp @@ -28,11 +28,12 @@ #include #include #include +#include #include #include #include #include /** @todo remove once AbstractImporter is -free */ -#include +#include #include #include #include @@ -95,7 +96,7 @@ template Float calculateImageDelta(const Containers:: } -std::tuple, Float, Float> calculateImageDelta(const PixelFormat actualFormat, const Containers::StridedArrayView3D& actualPixels, const ImageView2D& expected) { +Containers::Triple, Float, Float> calculateImageDelta(const PixelFormat actualFormat, const Containers::StridedArrayView3D& actualPixels, const ImageView2D& expected) { /* Calculate a delta image */ Containers::Array deltaData{NoInit, std::size_t(expected.size().product())}; @@ -203,7 +204,7 @@ std::tuple, Float, Float> calculateImageDelta(const Pix left that could cause the comparison to fail. */ const Float mean = Math::Algorithms::kahanSum(deltaData.begin(), deltaData.end())/deltaData.size(); - return std::make_tuple(std::move(deltaData), max, mean); + return {std::move(deltaData), max, mean}; } namespace { @@ -484,8 +485,9 @@ TestSuite::ComparisonStatusFlags ImageComparatorBase::compare(const PixelFormat return TestSuite::ComparisonStatusFlag::Failed; } - Containers::Array delta; - std::tie(delta, _state->max, _state->mean) = DebugTools::Implementation::calculateImageDelta(actualFormat, actualPixels, expected); + Containers::Triple, Float, Float> deltaMaxMean = DebugTools::Implementation::calculateImageDelta(actualFormat, actualPixels, expected); + _state->max = deltaMaxMean.second(); + _state->mean = deltaMaxMean.third(); /* Verify the max/mean is never below zero so we didn't mess up when calculating specials. Note the inverted condition to catch NaNs in @@ -511,7 +513,7 @@ TestSuite::ComparisonStatusFlags ImageComparatorBase::compare(const PixelFormat } else return TestSuite::ComparisonStatusFlags{}; /* Otherwise save the deltas and fail */ - _state->delta = std::move(delta); + _state->delta = std::move(deltaMaxMean.first()); return flags; } diff --git a/src/Magnum/DebugTools/CompareImage.h b/src/Magnum/DebugTools/CompareImage.h index 5567e2ed0..516624076 100644 --- a/src/Magnum/DebugTools/CompareImage.h +++ b/src/Magnum/DebugTools/CompareImage.h @@ -32,7 +32,6 @@ #include #include #include -#include #include "Magnum/Magnum.h" #include "Magnum/PixelFormat.h" @@ -49,7 +48,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { - MAGNUM_DEBUGTOOLS_EXPORT std::tuple, Float, Float> calculateImageDelta(PixelFormat actualFormat, const Containers::StridedArrayView3D& actualPixels, const ImageView2D& expected); + MAGNUM_DEBUGTOOLS_EXPORT Containers::Triple, Float, Float> calculateImageDelta(PixelFormat actualFormat, const Containers::StridedArrayView3D& actualPixels, const ImageView2D& expected); MAGNUM_DEBUGTOOLS_EXPORT void printDeltaImage(Debug& out, Containers::ArrayView delta, const Vector2i& size, Float max, Float maxThreshold, Float meanThreshold); diff --git a/src/Magnum/DebugTools/Test/CompareImageTest.cpp b/src/Magnum/DebugTools/Test/CompareImageTest.cpp index 32e0f892b..6cfd8bc12 100644 --- a/src/Magnum/DebugTools/Test/CompareImageTest.cpp +++ b/src/Magnum/DebugTools/Test/CompareImageTest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -280,13 +281,12 @@ void CompareImageTest::formatImplementationSpecific() { } void CompareImageTest::calculateDelta() { - Containers::Array delta; - Float max, mean; - std::tie(delta, max, mean) = Implementation::calculateImageDelta(ActualRed.format(), ActualRed.pixels(), ExpectedRed); - - CORRADE_COMPARE_AS(delta, Containers::arrayView(DeltaRed), TestSuite::Compare::Container); - CORRADE_COMPARE(max, 1.0f); - CORRADE_COMPARE(mean, 0.208889f); + Containers::Triple, Float, Float> deltaMaxMean = Implementation::calculateImageDelta(ActualRed.format(), ActualRed.pixels(), ExpectedRed); + CORRADE_COMPARE_AS(deltaMaxMean.first(), + Containers::arrayView(DeltaRed), + TestSuite::Compare::Container); + CORRADE_COMPARE(deltaMaxMean.second(), 1.0f); + CORRADE_COMPARE(deltaMaxMean.third(), 0.208889f); } /* Different storage for each */ @@ -308,16 +308,13 @@ const ImageView2D ExpectedRgb{ PixelFormat::RGB8Unorm, {2, 2}, ExpectedRgbData}; void CompareImageTest::calculateDeltaStorage() { - Containers::Array delta; - Float max, mean; - std::tie(delta, max, mean) = Implementation::calculateImageDelta(ActualRgb.format(), ActualRgb.pixels(), ExpectedRgb); - - CORRADE_COMPARE_AS(delta, Containers::arrayView({ + Containers::Triple, Float, Float> deltaMaxMean = Implementation::calculateImageDelta(ActualRgb.format(), ActualRgb.pixels(), ExpectedRgb); + CORRADE_COMPARE_AS(deltaMaxMean.first(), Containers::arrayView({ 1.0f/3.0f, (55.0f + 1.0f)/3.0f, 48.0f/3.0f, 117.0f/3.0f }), TestSuite::Compare::Container); - CORRADE_COMPARE(max, 117.0f/3.0f); - CORRADE_COMPARE(mean, 18.5f); + CORRADE_COMPARE(deltaMaxMean.second(), 117.0f/3.0f); + CORRADE_COMPARE(deltaMaxMean.third(), 18.5f); } /* Variants: @@ -352,18 +349,16 @@ const ImageView2D ActualSpecials{PixelFormat::R32F, {9, 1}, ActualDataSpecials}; const ImageView2D ExpectedSpecials{PixelFormat::R32F, {9, 1}, ExpectedDataSpecials}; void CompareImageTest::calculateDeltaSpecials() { - Containers::Array delta; - Float max, mean; - std::tie(delta, max, mean) = Implementation::calculateImageDelta(ActualSpecials.format(), ActualSpecials.pixels(), ExpectedSpecials); - CORRADE_COMPARE_AS(Containers::arrayView(delta), + Containers::Triple, Float, Float> deltaMaxMean = Implementation::calculateImageDelta(ActualSpecials.format(), ActualSpecials.pixels(), ExpectedSpecials); + CORRADE_COMPARE_AS(Containers::arrayView(deltaMaxMean.first()), Containers::arrayView(DeltaSpecials), TestSuite::Compare::Container); /* Max should be calculated *without* the specials because otherwise every other potential difference will be zero compared to infinity. OTOH mean needs to get "poisoned" by those in order to have *something* to fail the test with. */ - CORRADE_COMPARE(max, 3.1f); - CORRADE_COMPARE(mean, -Constants::nan()); + CORRADE_COMPARE(deltaMaxMean.second(), 3.1f); + CORRADE_COMPARE(deltaMaxMean.third(), -Constants::nan()); } void CompareImageTest::calculateDeltaSpecials3() { @@ -373,17 +368,15 @@ void CompareImageTest::calculateDeltaSpecials3() { const ImageView2D actualSpecials3{PixelFormat::RGB32F, {3, 1}, ActualDataSpecials}; const ImageView2D expectedSpecials3{PixelFormat::RGB32F, {3, 1}, ExpectedDataSpecials}; - Containers::Array delta; - Float max, mean; - std::tie(delta, max, mean) = Implementation::calculateImageDelta(actualSpecials3.format(), actualSpecials3.pixels(), expectedSpecials3); - CORRADE_COMPARE_AS(delta, Containers::arrayView({ + Containers::Triple, Float, Float> deltaMaxMean = Implementation::calculateImageDelta(actualSpecials3.format(), actualSpecials3.pixels(), expectedSpecials3); + CORRADE_COMPARE_AS(deltaMaxMean.first(), Containers::arrayView({ Constants::nan(), Constants::nan(), 1.15f }), TestSuite::Compare::Container); /* Max and mean should be calculated *without* the specials because otherwise every other potential difference will be zero compared to infinity */ - CORRADE_COMPARE(max, 1.15f); - CORRADE_COMPARE(mean, -Constants::nan()); + CORRADE_COMPARE(deltaMaxMean.second(), 1.15f); + CORRADE_COMPARE(deltaMaxMean.third(), -Constants::nan()); } void CompareImageTest::deltaImage() {