From 9bbbee6f565a5718945de7f7a6aae6b1eb2b20ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 9 Apr 2023 18:18:53 +0200 Subject: [PATCH] MeshTools: port away from std::pair in remaining APIs. Same here, PairStl.h added for backwards compatibility. Finally allows me to remove silly std::tie() and includes from most example code. --- doc/changelog.dox | 3 + doc/snippets/MagnumGL.cpp | 11 ++-- doc/snippets/MagnumMeshTools-gl.cpp | 12 ++-- doc/snippets/MagnumMeshTools.cpp | 12 ++-- src/Magnum/MeshTools/CompressIndices.cpp | 33 ++++++----- src/Magnum/MeshTools/CompressIndices.h | 20 ++++--- src/Magnum/MeshTools/RemoveDuplicates.cpp | 17 +++--- src/Magnum/MeshTools/RemoveDuplicates.h | 13 +++-- .../MeshTools/Test/CompressIndicesTest.cpp | 57 ++++++++++--------- .../MeshTools/Test/RemoveDuplicatesTest.cpp | 28 ++++----- 10 files changed, 106 insertions(+), 100 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 77e50b35c..f5ec66820 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1304,6 +1304,9 @@ See also: @ref GL::Buffer::setLabel() "setLabel()" APIs now work with a @relativeref{Corrade,Containers::StringView} / @relativeref{Corrade,Containers::String} instead of a @ref std::string + - @ref MeshTools::compressIndices(), @ref MeshTools::removeDuplicates() + and related APIs now return a @relativeref{Corrade,Containers::Pair} + instead of a @ref std::pair - @ref Vk::DescriptorPoolCreateInfo and @ref Vk::AttachmentDescription APIs now take a @relativeref{Corrade,Containers::Pair} instead of a @ref std::pair diff --git a/doc/snippets/MagnumGL.cpp b/doc/snippets/MagnumGL.cpp index 423de2efd..df2478cd7 100644 --- a/doc/snippets/MagnumGL.cpp +++ b/doc/snippets/MagnumGL.cpp @@ -23,9 +23,9 @@ DEALINGS IN THE SOFTWARE. */ -#include /* for std::tie() :( */ #include #include +#include #include #include #include @@ -1146,13 +1146,12 @@ mesh.addVertexBuffer(vertices, 0, GL::Mesh mesh; const UnsignedInt indexData[1]{}; /* [Mesh-indices-tool] */ -Containers::Array compressed; -MeshIndexType type; -std::tie(compressed, type) = MeshTools::compressIndices(indexData); -GL::Buffer indices{compressed}; +Containers::Pair, MeshIndexType> compressed = + MeshTools::compressIndices(indexData); +GL::Buffer indices{compressed.first()}; DOXYGEN_ELLIPSIS() -mesh.setIndexBuffer(indices, 0, type); +mesh.setIndexBuffer(indices, 0, compressed.second()); /* [Mesh-indices-tool] */ } diff --git a/doc/snippets/MagnumMeshTools-gl.cpp b/doc/snippets/MagnumMeshTools-gl.cpp index 9401d59ee..d85539add 100644 --- a/doc/snippets/MagnumMeshTools-gl.cpp +++ b/doc/snippets/MagnumMeshTools-gl.cpp @@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE. */ -#include /* for std::tie() :( */ +#include #include #include "Magnum/GL/AbstractShaderProgram.h" @@ -36,6 +36,7 @@ #include "Magnum/Trade/MeshData.h" #ifdef MAGNUM_BUILD_DEPRECATED +#include #include #endif @@ -83,16 +84,15 @@ mesh.addVertexBuffer(std::move(vertices), /* [compressIndices] */ Containers::Array indices; -Containers::Array indexData; -MeshIndexType indexType; -std::tie(indexData, indexType) = MeshTools::compressIndices(indices); +Containers::Pair, MeshIndexType> compressed = + MeshTools::compressIndices(indices); GL::Buffer indexBuffer; -indexBuffer.setData(indexData); +indexBuffer.setData(compressed.first()); GL::Mesh mesh; mesh.setCount(indices.size()) - .setIndexBuffer(indexBuffer, 0, indexType); + .setIndexBuffer(indexBuffer, 0, compressed.second()); /* [compressIndices] */ } diff --git a/doc/snippets/MagnumMeshTools.cpp b/doc/snippets/MagnumMeshTools.cpp index e255bdc04..53138ef50 100644 --- a/doc/snippets/MagnumMeshTools.cpp +++ b/doc/snippets/MagnumMeshTools.cpp @@ -23,8 +23,8 @@ DEALINGS IN THE SOFTWARE. */ -#include #include +#include #include "Magnum/Math/Color.h" #include "Magnum/Math/FunctionsBatch.h" @@ -73,7 +73,7 @@ CORRADE_IGNORE_DEPRECATED_POP /* [compressIndices-offset] */ Containers::ArrayView indices; UnsignedInt offset = Math::min(indices); -std::pair, MeshIndexType> result = +Containers::Pair, MeshIndexType> compressed = MeshTools::compressIndices(indices, offset); // use `offset` to adjust vertex attribute offset … @@ -153,11 +153,9 @@ Trade::MeshData indexed{data.primitive(), /* [removeDuplicates] */ Containers::ArrayView data; -std::size_t size; -Containers::Array indices; -std::tie(indices, size) = MeshTools::removeDuplicatesInPlace( - Containers::arrayCast<2, char>(data)); -data = data.prefix(size); +Containers::Pair, std::size_t> unique = + MeshTools::removeDuplicatesInPlace(Containers::arrayCast<2, char>(data)); +data = data.prefix(unique.second()); /* [removeDuplicates] */ } diff --git a/src/Magnum/MeshTools/CompressIndices.cpp b/src/Magnum/MeshTools/CompressIndices.cpp index be3c9e9e1..95d9b2cc4 100644 --- a/src/Magnum/MeshTools/CompressIndices.cpp +++ b/src/Magnum/MeshTools/CompressIndices.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include "Magnum/Math/FunctionsBatch.h" @@ -54,10 +55,10 @@ template inline Containers::Array compress(const Contain return buffer; } -template std::pair, MeshIndexType> compressIndicesImplementation(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { +template Containers::Pair, MeshIndexType> compressIndicesImplementation(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { CORRADE_ASSERT(!isMeshIndexTypeImplementationSpecific(atLeast), "MeshTools::compressIndices(): can't compress to an implementation-specific index type" << reinterpret_cast(meshIndexTypeUnwrap(atLeast)), - (std::pair, MeshIndexType>{nullptr, MeshIndexType::UnsignedInt})); + (Containers::Pair, MeshIndexType>{nullptr, MeshIndexType::UnsignedInt})); const UnsignedInt max = Math::max(indices) - offset; Containers::Array out; @@ -86,31 +87,31 @@ template std::pair, MeshIndexType> compressIndi } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { return compressIndicesImplementation(indices, atLeast, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { return compressIndicesImplementation(indices, atLeast, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const MeshIndexType atLeast, const Long offset) { return compressIndicesImplementation(indices, atLeast, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { return compressIndicesImplementation(indices, MeshIndexType::UnsignedShort, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { return compressIndicesImplementation(indices, MeshIndexType::UnsignedShort, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, const Long offset) { return compressIndicesImplementation(indices, MeshIndexType::UnsignedShort, offset); } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, const MeshIndexType atLeast, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, const MeshIndexType atLeast, const Long offset) { CORRADE_ASSERT(indices.isContiguous<1>(), "MeshTools::compressIndices(): second view dimension is not contiguous", {}); if(indices.size()[1] == 4) return compressIndicesImplementation(Containers::arrayCast<1, const UnsignedInt>(indices), atLeast, offset); @@ -122,7 +123,7 @@ std::pair, MeshIndexType> compressIndices(const Containe } } -std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, const Long offset) { +Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, const Long offset) { return compressIndices(indices, MeshIndexType::UnsignedShort, offset); } @@ -142,7 +143,7 @@ Trade::MeshData compressIndices(Trade::MeshData&& data, MeshIndexType atLeast) { /* Compress the indices */ UnsignedInt offset; - std::pair, MeshIndexType> result; + Containers::Pair, MeshIndexType> result; if(data.indexType() == MeshIndexType::UnsignedInt) { auto indices = data.indices(); offset = Math::min(indices); @@ -172,8 +173,8 @@ Trade::MeshData compressIndices(Trade::MeshData&& data, MeshIndexType atLeast) { data.attributeArraySize(i)}; } - Trade::MeshIndexData indices{result.second, result.first}; - return Trade::MeshData{data.primitive(), std::move(result.first), indices, + Trade::MeshIndexData indices{result.second(), result.first()}; + return Trade::MeshData{data.primitive(), std::move(result.first()), indices, std::move(vertexData), std::move(attributeData), newVertexCount}; } @@ -186,10 +187,8 @@ Trade::MeshData compressIndices(const Trade::MeshData& data, MeshIndexType atLea #ifdef MAGNUM_BUILD_DEPRECATED std::tuple, MeshIndexType, UnsignedInt, UnsignedInt> compressIndices(const std::vector& indices) { const auto minmax = Math::minmax(indices); - Containers::Array data; - MeshIndexType type; - std::tie(data, type) = compressIndices(indices, MeshIndexType::UnsignedByte); - return std::make_tuple(std::move(data), type, minmax.first, minmax.second); + Containers::Pair, MeshIndexType> dataType = compressIndices(indices, MeshIndexType::UnsignedByte); + return std::make_tuple(std::move(dataType.first()), dataType.second(), minmax.first, minmax.second); } template Containers::Array compressIndicesAs(const std::vector& indices) { diff --git a/src/Magnum/MeshTools/CompressIndices.h b/src/Magnum/MeshTools/CompressIndices.h index eb12a955c..a367d7e5c 100644 --- a/src/Magnum/MeshTools/CompressIndices.h +++ b/src/Magnum/MeshTools/CompressIndices.h @@ -29,7 +29,6 @@ * @brief Function @ref Magnum::MeshTools::compressIndices() */ -#include #include #include "Magnum/Mesh.h" @@ -40,6 +39,9 @@ #include #include #include + +/* The APIs used to return std::pair before */ +#include #endif namespace Magnum { namespace MeshTools { @@ -79,19 +81,19 @@ operation directly on a @ref Trade::MeshData instance. The @p atLeast parameter is expected to not be an implementation-specific type. @see @ref isMeshIndexTypeImplementationSpecific() */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); /** @overload @m_since{2020,06} */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); /** @overload @m_since{2020,06} */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); /** @overload @@ -100,7 +102,7 @@ MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compre Same as @ref compressIndices(const Containers::StridedArrayView1D&, MeshIndexType, Long) with @p atLeast set to @ref MeshIndexType::UnsignedShort. */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); /** @overload @@ -109,7 +111,7 @@ MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compre Same as @ref compressIndices(const Containers::StridedArrayView1D&, MeshIndexType, Long) with @p atLeast set to @ref MeshIndexType::UnsignedShort. */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); /** @overload @@ -118,7 +120,7 @@ MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compre Same as @ref compressIndices(const Containers::StridedArrayView1D&, MeshIndexType, Long) with @p atLeast set to @ref MeshIndexType::UnsignedShort. */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView1D& indices, Long offset); /** @brief Compress a type-erased index array @@ -132,7 +134,7 @@ etc. overloads. The @p atLeast parameter is expected to not be an implementation-specific type. @see @ref isMeshIndexTypeImplementationSpecific() */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, MeshIndexType atLeast = MeshIndexType::UnsignedShort, Long offset = 0); /** @overload @@ -141,7 +143,7 @@ MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compre Same as @ref compressIndices(const Containers::StridedArrayView2D&, MeshIndexType, Long) with @p atLeast set to @ref MeshIndexType::UnsignedShort. */ -MAGNUM_MESHTOOLS_EXPORT std::pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, Long offset); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, MeshIndexType> compressIndices(const Containers::StridedArrayView2D& indices, Long offset); /** @brief Compress mesh data indices diff --git a/src/Magnum/MeshTools/RemoveDuplicates.cpp b/src/Magnum/MeshTools/RemoveDuplicates.cpp index b59c4610f..28c85fdfd 100644 --- a/src/Magnum/MeshTools/RemoveDuplicates.cpp +++ b/src/Magnum/MeshTools/RemoveDuplicates.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -97,7 +98,7 @@ std::size_t removeDuplicatesInto(const Containers::StridedArrayView2D, std::size_t> removeDuplicates(const Containers::StridedArrayView2D& data) { +Containers::Pair, std::size_t> removeDuplicates(const Containers::StridedArrayView2D& data) { Containers::Array indices{NoInit, data.size()[0]}; const std::size_t size = removeDuplicatesInto(data, indices); return {std::move(indices), size}; @@ -155,7 +156,7 @@ std::size_t removeDuplicatesInPlaceInto(const Containers::StridedArrayView2D, std::size_t> removeDuplicatesInPlace(const Containers::StridedArrayView2D& data) { +Containers::Pair, std::size_t> removeDuplicatesInPlace(const Containers::StridedArrayView2D& data) { Containers::Array indices{NoInit, data.size()[0]}; const std::size_t size = removeDuplicatesInPlaceInto(data, indices); return {std::move(indices), size}; @@ -174,9 +175,9 @@ template std::size_t removeDuplicatesIndexedInPlaceImplementati original order, which is an useful property. The float version has this inverted (having the *Indexed() variant as the main implementation) because the remapping there has to be done once for every dimension. */ - std::pair, std::size_t> result = removeDuplicatesInPlace(data); - for(auto& i: indices) i = result.first[i]; - return result.second; + const Containers::Pair, std::size_t> result = removeDuplicatesInPlace(data); + for(auto& i: indices) i = result.first()[i]; + return result.second(); } } @@ -348,7 +349,7 @@ template std::size_t removeDuplicatesFuzzyInPlaceIntoImplementation(con return size; } -template std::pair, std::size_t> removeDuplicatesFuzzyInPlaceImplementation(const Containers::StridedArrayView2D& data, const T epsilon) { +template Containers::Pair, std::size_t> removeDuplicatesFuzzyInPlaceImplementation(const Containers::StridedArrayView2D& data, const T epsilon) { Containers::Array indices{NoInit, data.size()[0]}; const std::size_t size = removeDuplicatesFuzzyInPlaceIntoImplementation(data, indices, epsilon); return {std::move(indices), size}; @@ -356,11 +357,11 @@ template std::pair, std::size_t> removeD } -std::pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, const Float epsilon) { +Containers::Pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, const Float epsilon) { return removeDuplicatesFuzzyInPlaceImplementation(data, epsilon); } -std::pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, const Double epsilon) { +Containers::Pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, const Double epsilon) { return removeDuplicatesFuzzyInPlaceImplementation(data, epsilon); } diff --git a/src/Magnum/MeshTools/RemoveDuplicates.h b/src/Magnum/MeshTools/RemoveDuplicates.h index 7fd84e748..8766dc8ce 100644 --- a/src/Magnum/MeshTools/RemoveDuplicates.h +++ b/src/Magnum/MeshTools/RemoveDuplicates.h @@ -29,8 +29,6 @@ * @brief Function @ref Magnum::MeshTools::removeDuplicatesInPlace(), @ref Magnum::MeshTools::removeDuplicatesIndexedInPlace() */ -#include - #include "Magnum/Magnum.h" #include "Magnum/Math/TypeTraits.h" #include "Magnum/MeshTools/visibility.h" @@ -40,6 +38,9 @@ #include #include #include + +/* The function used to return a std::pair */ +#include #endif namespace Magnum { namespace MeshTools { @@ -68,7 +69,7 @@ an index array pointing to original data locations. @see @ref Corrade::Containers::StridedArrayView::isContiguous(), @ref removeDuplicatesInPlaceInto() */ -MAGNUM_MESHTOOLS_EXPORT std::pair, std::size_t> removeDuplicatesInPlace(const Containers::StridedArrayView2D& data); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, std::size_t> removeDuplicatesInPlace(const Containers::StridedArrayView2D& data); /** @brief Remove duplicate data from given array in-place into given output index array @@ -95,7 +96,7 @@ Compared to @ref removeDuplicatesInPlace(const Containers::StridedArrayView2D, std::size_t> removeDuplicates(const Containers::StridedArrayView2D& data); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, std::size_t> removeDuplicates(const Containers::StridedArrayView2D& data); /** @brief Remove duplicate data from given array into given output index array @@ -173,13 +174,13 @@ If you want to remove duplicates in multiple incidental arrays, first remove duplicates in each array separately and then combine the resulting index arrays back into a single one using @ref combineIndexedAttributes(). */ -MAGNUM_MESHTOOLS_EXPORT std::pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, Float epsilon = Math::TypeTraits::epsilon()); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, Float epsilon = Math::TypeTraits::epsilon()); /** * @overload * @m_since{2020,06} */ -MAGNUM_MESHTOOLS_EXPORT std::pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, Double epsilon = Math::TypeTraits::epsilon()); +MAGNUM_MESHTOOLS_EXPORT Containers::Pair, std::size_t> removeDuplicatesFuzzyInPlace(const Containers::StridedArrayView2D& data, Double epsilon = Math::TypeTraits::epsilon()); /** @brief Remove duplicate data from given array using fuzzy comparison in-place into given output index array diff --git a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp index 5334e0e8e..ff67f9924 100644 --- a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -105,19 +106,19 @@ template void CompressIndicesTest::compressUnsignedByte() { const T indices[]{1, 2, 3, 0, 4}; /* By default it has 16-byte type as minimum, override */ - std::pair, MeshIndexType> out = + Containers::Pair, MeshIndexType> out = compressIndices(indices, MeshIndexType::UnsignedByte); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedByte); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedByte); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 2, 3, 0, 4}), TestSuite::Compare::Container); /* Test the type-erased variant as well */ out = compressIndices(Containers::arrayCast<2, const char>(Containers::stridedArrayView(indices)), MeshIndexType::UnsignedByte); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedByte); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedByte); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 2, 3, 0, 4}), TestSuite::Compare::Container); } @@ -126,18 +127,18 @@ template void CompressIndicesTest::compressUnsignedShort() { setTestCaseTemplateName(Math::TypeTraits::name()); const T indices[]{1, 256, 0, 5}; - std::pair, MeshIndexType> out = compressIndices(indices); + Containers::Pair, MeshIndexType> out = compressIndices(indices); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedShort); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedShort); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 256, 0, 5}), TestSuite::Compare::Container); /* Test the type-erased variant as well */ out = compressIndices(Containers::arrayCast<2, const char>(Containers::stridedArrayView(indices))); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedShort); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedShort); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 256, 0, 5}), TestSuite::Compare::Container); } @@ -146,18 +147,18 @@ template void CompressIndicesTest::compressUnsignedInt() { setTestCaseTemplateName(Math::TypeTraits::name()); const T indices[]{65536, 3, 2}; - std::pair, MeshIndexType> out = compressIndices(indices); + Containers::Pair, MeshIndexType> out = compressIndices(indices); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedInt); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedInt); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({65536, 3, 2}), TestSuite::Compare::Container); /* Test the type-erased variant as well */ out = compressIndices(Containers::arrayCast<2, const char>(Containers::stridedArrayView(indices))); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedInt); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedInt); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({65536, 3, 2}), TestSuite::Compare::Container); } @@ -165,28 +166,28 @@ template void CompressIndicesTest::compressUnsignedInt() { void CompressIndicesTest::compressUnsignedByteInflateToShort() { const UnsignedByte indices[]{1, 2, 3, 0, 4}; /* That's the default */ - std::pair, MeshIndexType> out = compressIndices(indices); + Containers::Pair, MeshIndexType> out = compressIndices(indices); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedShort); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedShort); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 2, 3, 0, 4}), TestSuite::Compare::Container); } void CompressIndicesTest::compressOffset() { const UnsignedInt indices[]{75000 + 1, 75000 + 256, 75000 + 0, 75000 + 5}; - std::pair, MeshIndexType> out = compressIndices(indices, 75000); + Containers::Pair, MeshIndexType> out = compressIndices(indices, 75000); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedShort); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedShort); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 256, 0, 5}), TestSuite::Compare::Container); /* Test the type-erased variant as well */ out = compressIndices(Containers::arrayCast<2, const char>(Containers::stridedArrayView(indices)), 75000); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedShort); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedShort); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({1, 256, 0, 5}), TestSuite::Compare::Container); } @@ -195,18 +196,18 @@ template void CompressIndicesTest::compressOffsetNegative() { setTestCaseTemplateName(Math::TypeTraits::name()); const T indices[]{1, 255, 0, 5}; - std::pair, MeshIndexType> out = compressIndices(indices, -75000); + Containers::Pair, MeshIndexType> out = compressIndices(indices, -75000); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedInt); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedInt); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({75000 + 1, 75000 + 255, 75000 + 0, 75000 + 5}), TestSuite::Compare::Container); /* Test the type-erased variant as well */ out = compressIndices(Containers::arrayCast<2, const char>(Containers::stridedArrayView(indices)), -75000); - CORRADE_COMPARE(out.second, MeshIndexType::UnsignedInt); - CORRADE_COMPARE_AS(Containers::arrayCast(out.first), + CORRADE_COMPARE(out.second(), MeshIndexType::UnsignedInt); + CORRADE_COMPARE_AS(Containers::arrayCast(out.first()), Containers::arrayView({75000 + 1, 75000 + 255, 75000 + 0, 75000 + 5}), TestSuite::Compare::Container); } diff --git a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp index 7b216cd15..5cb1a2529 100644 --- a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp +++ b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp @@ -27,6 +27,7 @@ #include /* random device for std::shuffle() */ #include #include +#include #include #include #include @@ -266,18 +267,19 @@ RemoveDuplicatesTest::RemoveDuplicatesTest() { void RemoveDuplicatesTest::removeDuplicates() { Int data[]{-15, 32, 24, -15, 15, 7541, 24, 32}; - std::pair, std::size_t> result = + Containers::Pair, std::size_t> result = MeshTools::removeDuplicates(Containers::arrayCast<2, char>(Containers::arrayView(data))); - CORRADE_COMPARE_AS(Containers::arrayView(result.first), + CORRADE_COMPARE_AS(Containers::arrayView(result.first()), Containers::arrayView({0, 1, 2, 0, 4, 5, 2, 1}), TestSuite::Compare::Container); + CORRADE_COMPARE(result.second(), 5); - std::pair, std::size_t> resultInPlace = + Containers::Pair, std::size_t> resultInPlace = MeshTools::removeDuplicatesInPlace(Containers::arrayCast<2, char>(Containers::arrayView(data))); - CORRADE_COMPARE_AS(Containers::arrayView(resultInPlace.first), + CORRADE_COMPARE_AS(Containers::arrayView(resultInPlace.first()), Containers::arrayView({0, 1, 2, 0, 3, 4, 2, 1}), TestSuite::Compare::Container); - CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(resultInPlace.second), + CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(resultInPlace.second()), Containers::arrayView({-15, 32, 24, 15, 7541}), TestSuite::Compare::Container); } @@ -421,14 +423,14 @@ template void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceOneDime T(3.4) /* bucket 3 in 1st iteration, bucket 3 in 2nd */ }; - std::pair, std::size_t> result = + Containers::Pair, std::size_t> result = MeshTools::removeDuplicatesFuzzyInPlace( Containers::arrayCast<2, T>(Containers::stridedArrayView(data)), T(1.00001)); - CORRADE_COMPARE_AS(Containers::arrayView(result.first), + CORRADE_COMPARE_AS(Containers::arrayView(result.first()), Containers::arrayView({0, 1, 0, 1}), TestSuite::Compare::Container); - CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(result.second), + CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(result.second()), (Containers::arrayView({T(1.0), T(2.9)})), TestSuite::Compare::Container); } @@ -446,14 +448,14 @@ template void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceMoreDim {T(1.0), T(5.0)} }; - std::pair, std::size_t> result = + Containers::Pair, std::size_t> result = MeshTools::removeDuplicatesFuzzyInPlace( Containers::arrayCast<2, T>(Containers::stridedArrayView(data)), T(2.0)); - CORRADE_COMPARE_AS(Containers::arrayView(result.first), + CORRADE_COMPARE_AS(Containers::arrayView(result.first()), Containers::arrayView({0, 0, 1, 1}), TestSuite::Compare::Container); - CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(result.second), + CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(result.second()), Containers::arrayView>({{T(1.0), T(0.0)}, {T(0.0), T(4.0)}}), TestSuite::Compare::Container); } @@ -1215,7 +1217,7 @@ void RemoveDuplicatesTest::soakTest() { CORRADE_COMPARE(MeshTools::removeDuplicatesInPlace( Containers::StridedArrayView2D{ Containers::arrayCast(Containers::arrayView(data)), {1000, 4}} - ).second, 100); + ).second(), 100); } void RemoveDuplicatesTest::soakTestFuzzy() { @@ -1226,7 +1228,7 @@ void RemoveDuplicatesTest::soakTestFuzzy() { std::shuffle(std::begin(data), std::end(data), std::minstd_rand{std::random_device{}()}); CORRADE_COMPARE(MeshTools::removeDuplicatesFuzzyInPlace( - Containers::arrayCast<2, Float>(Containers::arrayView(data))).second, + Containers::arrayCast<2, Float>(Containers::arrayView(data))).second(), 100); }