diff --git a/doc/snippets/Math.cpp b/doc/snippets/Math.cpp index 738c9bee7..3e4cadd2f 100644 --- a/doc/snippets/Math.cpp +++ b/doc/snippets/Math.cpp @@ -24,6 +24,8 @@ DEALINGS IN THE SOFTWARE. */ +#include + #include "Magnum/Magnum.h" #include "Magnum/Math/Color.h" #include "Magnum/Math/FunctionsBatch.h" @@ -34,6 +36,7 @@ #include "Magnum/Math/DualQuaternion.h" #include "Magnum/Math/Frustum.h" #include "Magnum/Math/Half.h" +#include "Magnum/Math/PackingBatch.h" #include "Magnum/Math/Range.h" #include "Magnum/Math/Swizzle.h" #include "Magnum/Math/Time.h" @@ -1270,6 +1273,39 @@ static_cast(a); static_cast(b); } +{ +/* [unpackInto] */ +const UnsignedByte src[]{DOXYGEN_ELLIPSIS(0)}; +Float dst[Containers::arraySize(src)]; +Math::unpackInto(Containers::stridedArrayView(src), + Containers::stridedArrayView(dst)); +/* [unpackInto] */ +} + +{ +/* [unpackInto-vector-slice] */ +Containers::StridedArrayView1D src = DOXYGEN_ELLIPSIS({}); +Containers::StridedArrayView1D dst = DOXYGEN_ELLIPSIS({}); +Math::unpackInto(src.slice(&Color3ub::data), + dst.slice(&Color3::data)); +/* [unpackInto-vector-slice] */ +} + +{ +/* [unpackInto-slice-flatten] */ +Containers::StridedArrayView2D src = DOXYGEN_ELLIPSIS({}); +Containers::StridedArrayView2D dst = DOXYGEN_ELLIPSIS({}); +Math::unpackInto(src.asContiguous<0>().slice(&Color4ub::data), + dst.asContiguous<0>().slice(&Color4::data)); +/* [unpackInto-slice-flatten] */ + +/* [unpackInto-slice-loop] */ +for(std::size_t i = 0; i != src.size()[0]; ++i) + Math::unpackInto(src[i].slice(&Color4ub::data), + dst[i].slice(&Color4::data)); +/* [unpackInto-slice-loop] */ +} + { Range1D range, a, b; constexpr UnsignedInt dimensions = 1; diff --git a/src/Magnum/Math/PackingBatch.h b/src/Magnum/Math/PackingBatch.h index e670868b5..a11a6e3ab 100644 --- a/src/Magnum/Math/PackingBatch.h +++ b/src/Magnum/Math/PackingBatch.h @@ -56,6 +56,28 @@ floating-point values in range @f$ [0, 1] @f$. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that the second dimension in both is contiguous. + +The function can be called directly with an one-dimensional strided view as +it's implicitly convertible to a @link Containers::StridedArrayView2D @endlink: + +@snippet Math.cpp unpackInto + +Overloads for vector, matrix and other math types are not provided because +there would be too many variants. Instead you can slice to @ref Vector::data(), +@ref RectangularMatrix::data() etc., which is then convertible to a 2D view: + +@snippet Math.cpp unpackInto-vector-slice + +For higher dimension count you can flatten the extra dimensions using +@relativeref{Corrade,Containers::StridedArrayView::asContiguous()} if they're +contiguous: + +@snippet Math.cpp unpackInto-slice-flatten + +Or call the function on the nested dimensions in a loop if not: + +@snippet Math.cpp unpackInto-slice-loop + @see @ref packInto(), @ref castInto(), @relativeref{Corrade,Containers::StridedArrayView::isContiguous()} */ @@ -77,7 +99,8 @@ Converts integral values from full range of given *signed* integral type to floating-point values in range @f$ [-1, 1] @f$. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See the @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +overload for various examples of how to pass the arguments. @see @ref packInto(), @ref castInto(), @relativeref{Corrade,Containers::StridedArrayView::isContiguous()} */ @@ -100,7 +123,8 @@ given *unsigned* integral type or range @f$ [-1, 1] @f$ to full range of given *signed* integral type. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Conversion result for floating-point numbers outside the normalized range is undefined. @@ -139,7 +163,8 @@ for more information about half floats. Unlike @ref packHalf() this function is a faster table-based implementation at the expense of using more memory, thus more suitable for batch conversions of large data amounts. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. Algorithm used: *Jeroen van der Zijp -- Fast Half Float Conversions, 2008, ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf* @@ -158,7 +183,8 @@ for more information about half floats. Unlike @ref unpackHalf() this function is a faster table-based implementation at the expense of using more memory, thus more suitable for batch conversions of large data amounts. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. Algorithm used: *Jeroen van der Zijp -- Fast Half Float Conversions, 2008, ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf* @@ -176,7 +202,9 @@ Unlike @ref packInto(), this function performs only an equivalent of @cpp Float(a) @ce over the range, so e.g. @cpp 135 @ce becomes @cpp 135.0f @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that -the second dimension in both is contiguous. +the second dimension in both is contiguous. See +@ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Numbers with more than 23 bits of precision will not be represented accurately when cast into a @relativeref{Magnum,Float}. @@ -226,7 +254,9 @@ Unlike @ref packInto(), this function performs only an equivalent of @cpp Double(a) @ce over the range, so e.g. @cpp 135 @ce becomes @cpp 135.0 @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that -the second dimension in both is contiguous. +the second dimension in both is contiguous. See +@ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Numbers with more than 52 bits of precision will not be represented accurately when cast into a @relativeref{Magnum,Double}. @@ -276,7 +306,9 @@ Unlike @ref packInto(), this function performs only an equivalent of @cpp T(a) @ce over the range, so e.g. @cpp 135.0f @ce becomes @cpp 135 @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that -the second dimension in both is contiguous. +the second dimension in both is contiguous. See +@ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Fractional part of the @relativeref{Magnum,Float} input will be silently discarded when cast into an integer type. @@ -326,7 +358,9 @@ Unlike @ref packInto(), this function performs only an equivalent of @cpp T(a) @ce over the range, so e.g. @cpp 135.0 @ce becomes @cpp 135 @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that -the second dimension in both is contiguous. +the second dimension in both is contiguous. See +@ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Fractional part of the @relativeref{Magnum,Double} input will be silently discarded when cast into an integer type. @@ -374,7 +408,9 @@ MAGNUM_EXPORT void castInto(const Containers::StridedArrayView2D& Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that -the second dimension in both is contiguous. +the second dimension in both is contiguous. See +@ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Values that don't fit into the resulting type will have undefined values. @@ -531,7 +567,8 @@ This function performs an equivalent of @cpp Double(a) @ce over the range, so e.g. @cpp 135.0f @ce becomes @cpp 135.0 @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @see @ref castInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&), @relativeref{Corrade,Containers::StridedArrayView::isContiguous()} @@ -548,7 +585,8 @@ This function performs an equivalent of @cpp Float(a) @ce over the range, so e.g. @cpp 135.0 @ce becomes @cpp 135.0f @ce. Second dimension is meant to contain vector/matrix components, or have a size of 1 for scalars. Expects that @p src and @p dst have the same size and that the second dimension in both is -contiguous. +contiguous. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. @attention Numbers with more than 23 bits of precision will not be represented accurately when cast into a @ref Magnum::Float "Float". @@ -567,7 +605,8 @@ MAGNUM_EXPORT void castInto(const Containers::StridedArrayView2D& Provided for convenience when writing generic code, delegates to @relativeref{Corrade,Utility::copy()}. Expects that @p src and @p dst have the same size, for consistency with other @ref castInto() expects also that the second dimension in both is contiguous even though it's not required by -@relativeref{Corrade,Utility::copy()}. +@relativeref{Corrade,Utility::copy()}. See @ref unpackInto(const Containers::StridedArrayView2D&, const Containers::StridedArrayView2D&) +for various examples of how to pass the arguments. */ MAGNUM_EXPORT void castInto(const Containers::StridedArrayView2D& src, const Containers::StridedArrayView2D& dst); diff --git a/src/Magnum/Math/Test/PackingBatchTest.cpp b/src/Magnum/Math/Test/PackingBatchTest.cpp index 901399238..01da1df9c 100644 --- a/src/Magnum/Math/Test/PackingBatchTest.cpp +++ b/src/Magnum/Math/Test/PackingBatchTest.cpp @@ -177,11 +177,14 @@ void PackingBatchTest::unpackUnsignedByte() { {0.0f, 1.0f} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - unpackInto(Containers::arrayCast<2, UnsignedByte>(src), - Containers::arrayCast<2, Float>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + unpackInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2ub::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -206,11 +209,14 @@ void PackingBatchTest::unpackUnsignedShort() { {0.0f, 1.0f} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - unpackInto(Containers::arrayCast<2, UnsignedShort>(src), - Containers::arrayCast<2, Float>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + unpackInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2us::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -235,11 +241,14 @@ void PackingBatchTest::unpackSignedByte() { {-1.0f, -1.0f} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - unpackInto(Containers::arrayCast<2, Byte>(src), - Containers::arrayCast<2, Float>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + unpackInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2b::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -264,11 +273,14 @@ void PackingBatchTest::unpackSignedShort() { {-1.0f, -1.0f} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - unpackInto(Containers::arrayCast<2, Short>(src), - Containers::arrayCast<2, Float>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + unpackInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2s::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -293,11 +305,14 @@ void PackingBatchTest::packUnsignedByte() { {255, 255} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - packInto(Containers::arrayCast<2, Float>(src), - Containers::arrayCast<2, UnsignedByte>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + packInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2ub::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -322,11 +337,14 @@ void PackingBatchTest::packUnsignedShort() { {65535, 65535} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - packInto(Containers::arrayCast<2, Float>(src), - Containers::arrayCast<2, UnsignedShort>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + packInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2us::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -351,11 +369,14 @@ void PackingBatchTest::packSignedByte() { {127, 127} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - packInto(Containers::arrayCast<2, Float>(src), - Containers::arrayCast<2, Byte>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + packInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2b::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -380,11 +401,14 @@ void PackingBatchTest::packSignedShort() { {32767, 32767} }; - Containers::StridedArrayView1D src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, 3, sizeof(Data)}; - packInto(Containers::arrayCast<2, Float>(src), - Containers::arrayCast<2, Short>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + packInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2s::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -411,13 +435,14 @@ void PackingBatchTest::unpackHalf() { {-Constants::inf(), +Constants::inf()} }; - Containers::StridedArrayView1D src{data, &data[0].src, - Containers::arraySize(data), sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, - Containers::arraySize(data), sizeof(Data)}; - unpackHalfInto(Containers::arrayCast<2, UnsignedShort>(src), - Containers::arrayCast<2, Float>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + unpackHalfInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2us::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -444,13 +469,14 @@ void PackingBatchTest::packHalf() { {0xfc00, 0x7c00} }; - Containers::StridedArrayView1D src{data, &data[0].src, - Containers::arraySize(data), sizeof(Data)}; - Containers::StridedArrayView1D dst{data, &data[0].dst, - Containers::arraySize(data), sizeof(Data)}; - packHalfInto(Containers::arrayCast<2, Float>(src), - Containers::arrayCast<2, UnsignedShort>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expected), + packHalfInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Vector2us::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expected), TestSuite::Compare::Container); /* Ensure the results are consistent with non-batch APIs */ @@ -484,17 +510,25 @@ template void PackingBatchTest::castUnsigne {13, 255} }; - Containers::StridedArrayView1D> src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D> dst{data, &data[0].dst, 3, sizeof(Data)}; - castInto(Containers::arrayCast<2, Integral>(src), - Containers::arrayCast<2, FloatingPoint>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expectedFloatingPoint), + castInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expectedFloatingPoint), TestSuite::Compare::Container); /* Test the other way around as well */ - castInto(Containers::arrayCast<2, FloatingPoint>(dst), - Containers::arrayCast<2, Integral>(src)); - CORRADE_COMPARE_AS(src, Containers::stridedArrayView(expectedIntegral), + castInto( + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::src), + Containers::stridedArrayView(expectedIntegral), TestSuite::Compare::Container); } @@ -524,17 +558,25 @@ template void PackingBatchTest::castSignedF {13, 127} }; - Containers::StridedArrayView1D> src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D> dst{data, &data[0].dst, 3, sizeof(Data)}; - castInto(Containers::arrayCast<2, Integral>(src), - Containers::arrayCast<2, FloatingPoint>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expectedFloatingPoint), + castInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expectedFloatingPoint), TestSuite::Compare::Container); /* Test the other way around as well */ - castInto(Containers::arrayCast<2, FloatingPoint>(dst), - Containers::arrayCast<2, Integral>(src)); - CORRADE_COMPARE_AS(src, Containers::stridedArrayView(expectedIntegral), + castInto( + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::src), + Containers::stridedArrayView(expectedIntegral), TestSuite::Compare::Container); } @@ -562,17 +604,25 @@ template void PackingBatchTest::castUnsignedInteger() { {13, 255} }; - Containers::StridedArrayView1D> src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D> dst{data, &data[0].dst, 3, sizeof(Data)}; - castInto(Containers::arrayCast<2, T>(src), - Containers::arrayCast<2, U>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expectedTargetType), + castInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expectedTargetType), TestSuite::Compare::Container); /* Test the other way around as well */ - castInto(Containers::arrayCast<2, U>(dst), - Containers::arrayCast<2, T>(src)); - CORRADE_COMPARE_AS(src, Containers::stridedArrayView(expectedOriginalType), + castInto( + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::src), + Containers::stridedArrayView(expectedOriginalType), TestSuite::Compare::Container); } @@ -600,17 +650,25 @@ template void PackingBatchTest::castSignedInteger() { {13, 127} }; - Containers::StridedArrayView1D> src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D> dst{data, &data[0].dst, 3, sizeof(Data)}; - castInto(Containers::arrayCast<2, T>(src), - Containers::arrayCast<2, U>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expectedTargetType), + castInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expectedTargetType), TestSuite::Compare::Container); /* Test the other way around as well */ - castInto(Containers::arrayCast<2, U>(dst), - Containers::arrayCast<2, T>(src)); - CORRADE_COMPARE_AS(src, Containers::stridedArrayView(expectedOriginalType), + castInto( + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::src), + Containers::stridedArrayView(expectedOriginalType), TestSuite::Compare::Container); } @@ -635,18 +693,25 @@ template void PackingBatchTest::castFloatDouble() { {T(-119.0), T(22.75)}, {T(13.0), T(127.5)} }; - - Containers::StridedArrayView1D> src{data, &data[0].src, 3, sizeof(Data)}; - Containers::StridedArrayView1D> dst{data, &data[0].dst, 3, sizeof(Data)}; - castInto(Containers::arrayCast<2, T>(src), - Containers::arrayCast<2, U>(dst)); - CORRADE_COMPARE_AS(dst, Containers::stridedArrayView(expectedTargetType), + castInto( + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::dst), + Containers::stridedArrayView(expectedTargetType), TestSuite::Compare::Container); /* Test the other way around as well */ - castInto(Containers::arrayCast<2, U>(dst), - Containers::arrayCast<2, T>(src)); - CORRADE_COMPARE_AS(src, Containers::stridedArrayView(expectedOriginalType), + castInto( + Containers::stridedArrayView(data).slice(&Data::dst) + .slice(&Math::Vector2::data), + Containers::stridedArrayView(data).slice(&Data::src) + .slice(&Math::Vector2::data)); + CORRADE_COMPARE_AS( + Containers::stridedArrayView(data).slice(&Data::src), + Containers::stridedArrayView(expectedOriginalType), TestSuite::Compare::Container); } @@ -660,18 +725,22 @@ template void PackingBatchTest::assertionsPackUnpack() { Vector3 resultWrongVectorSize[2]{}; Vector4 resultNonContiguous[2]{}; - auto src = Containers::arrayCast<2, T>( - Containers::arrayView(data)); - auto srcNonContiguous = Containers::arrayCast<2, T>( - Containers::arrayView(dataNonContiguous)).every({1, 2}); - auto dst = Containers::arrayCast<2, Float>( - Containers::arrayView(result)); - auto dstWrongCount = Containers::arrayCast<2, Float>( - Containers::arrayView(resultWrongCount)); - auto dstWrongVectorSize = Containers::arrayCast<2, Float>( - Containers::arrayView(resultWrongVectorSize)); - auto dstNotContiguous = Containers::arrayCast<2, Float>( - Containers::arrayView(resultNonContiguous)).every({1, 2}); + auto src = Containers::stridedArrayView(data) + .slice(&Math::Vector2::data); + auto srcNonContiguous = Containers::StridedArrayView2D{ + Containers::stridedArrayView(dataNonContiguous) + .slice(&Math::Vector4::data) + }.every({1, 2}); + auto dst = Containers::stridedArrayView(result) + .slice(&Vector2::data); + auto dstWrongCount = Containers::stridedArrayView(resultWrongCount) + .slice(&Vector2::data); + auto dstWrongVectorSize = Containers::stridedArrayView(resultWrongVectorSize) + .slice(&Vector3::data); + auto dstNotContiguous = Containers::StridedArrayView2D{ + Containers::stridedArrayView(resultNonContiguous) + .slice(&Vector4::data) + }.every({1, 2}); Containers::String out; Error redirectError{&out}; @@ -704,18 +773,22 @@ void PackingBatchTest::assertionsPackUnpackHalf() { Vector3 resultWrongVectorSize[2]{}; Vector4 resultNonContiguous[2]{}; - auto src = Containers::arrayCast<2, UnsignedShort>( - Containers::arrayView(data)); - auto srcNonContiguous = Containers::arrayCast<2, UnsignedShort>( - Containers::arrayView(dataNonContiguous)).every({1, 2}); - auto dst = Containers::arrayCast<2, Float>( - Containers::arrayView(result)); - auto dstWrongCount = Containers::arrayCast<2, Float>( - Containers::arrayView(resultWrongCount)); - auto dstWrongVectorSize = Containers::arrayCast<2, Float>( - Containers::arrayView(resultWrongVectorSize)); - auto dstNotContiguous = Containers::arrayCast<2, Float>( - Containers::arrayView(resultNonContiguous)).every({1, 2}); + auto src = Containers::stridedArrayView(data) + .slice(&Vector2us::data); + auto srcNonContiguous = Containers::StridedArrayView2D{ + Containers::stridedArrayView(dataNonContiguous) + .slice(&Vector4us::data) + }.every({1, 2}); + auto dst = Containers::stridedArrayView(result) + .slice(&Vector2::data); + auto dstWrongCount = Containers::stridedArrayView(resultWrongCount) + .slice(&Vector2::data); + auto dstWrongVectorSize = Containers::stridedArrayView(resultWrongVectorSize) + .slice(&Vector3::data); + auto dstNotContiguous = Containers::StridedArrayView2D{ + Containers::stridedArrayView(resultNonContiguous) + .slice(&Vector4::data) + }.every({1, 2}); Containers::String out; Error redirectError{&out}; @@ -748,14 +821,16 @@ template void PackingBatchTest::assertionsCast() { Math::Vector3 resultWrongVectorSize[2]{}; Math::Vector4 resultNonContiguous[2]{}; - auto src = Containers::arrayCast<2, T>( - Containers::arrayView(data)); - auto dstWrongCount = Containers::arrayCast<2, U>( - Containers::arrayView(resultWrongCount)); - auto dstWrongVectorSize = Containers::arrayCast<2, U>( - Containers::arrayView(resultWrongVectorSize)); - auto dstNotContiguous = Containers::arrayCast<2, U>( - Containers::arrayView(resultNonContiguous)).every({1, 2}); + auto src = Containers::stridedArrayView(data) + .slice(&Math::Vector2::data); + auto dstWrongCount = Containers::stridedArrayView(resultWrongCount) + .slice(&Math::Vector2::data); + auto dstWrongVectorSize = Containers::stridedArrayView(resultWrongVectorSize) + .slice(&Math::Vector3::data); + auto dstNotContiguous = Containers::StridedArrayView2D{ + Containers::stridedArrayView(resultNonContiguous) + .slice(&Math::Vector4::data) + }.every({1, 2}); Containers::String out; Error redirectError{&out};