Browse Source

Math: use vector member slicing in batch packing tests.

And document that it's possible to do this, so users aren't confused.
pull/674/head
Vladimír Vondruš 1 year ago
parent
commit
7557c8ddb7
  1. 36
      doc/snippets/Math.cpp
  2. 63
      src/Magnum/Math/PackingBatch.h
  3. 329
      src/Magnum/Math/Test/PackingBatchTest.cpp

36
doc/snippets/Math.cpp

@ -24,6 +24,8 @@
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/Containers/StridedArrayView.h>
#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<void>(a);
static_cast<void>(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<const Color3ub> src = DOXYGEN_ELLIPSIS({});
Containers::StridedArrayView1D<Color3> dst = DOXYGEN_ELLIPSIS({});
Math::unpackInto(src.slice(&Color3ub::data),
dst.slice(&Color3::data));
/* [unpackInto-vector-slice] */
}
{
/* [unpackInto-slice-flatten] */
Containers::StridedArrayView2D<const Color4ub> src = DOXYGEN_ELLIPSIS({});
Containers::StridedArrayView2D<Color4> 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;

63
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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<const Double>&
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
for various examples of how to pass the arguments.
@see @ref castInto(const Containers::StridedArrayView2D<const Double>&, const Containers::StridedArrayView2D<Float>&),
@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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
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<const Double>&
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 UnsignedByte>&, const Containers::StridedArrayView2D<Float>&)
for various examples of how to pass the arguments.
*/
MAGNUM_EXPORT void castInto(const Containers::StridedArrayView2D<const UnsignedByte>& src, const Containers::StridedArrayView2D<UnsignedByte>& dst);

329
src/Magnum/Math/Test/PackingBatchTest.cpp

@ -177,11 +177,14 @@ void PackingBatchTest::unpackUnsignedByte() {
{0.0f, 1.0f}
};
Containers::StridedArrayView1D<Vector2ub> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2> 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<Vector2us> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2> 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<Vector2b> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2> 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<Vector2s> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2> 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<Vector2> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2ub> 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<Vector2> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2us> 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<Vector2> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2b> 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<Vector2> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Vector2s> 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<Vector2us> src{data, &data[0].src,
Containers::arraySize(data), sizeof(Data)};
Containers::StridedArrayView1D<Vector2> 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<Vector2> src{data, &data[0].src,
Containers::arraySize(data), sizeof(Data)};
Containers::StridedArrayView1D<Vector2us> 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<class FloatingPoint, class Integral> void PackingBatchTest::castUnsigne
{13, 255}
};
Containers::StridedArrayView1D<Math::Vector2<Integral>> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Math::Vector2<FloatingPoint>> 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<Integral>::data),
Containers::stridedArrayView(data).slice(&Data::dst)
.slice(&Math::Vector2<FloatingPoint>::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<FloatingPoint>::data),
Containers::stridedArrayView(data).slice(&Data::src)
.slice(&Math::Vector2<Integral>::data));
CORRADE_COMPARE_AS(
Containers::stridedArrayView(data).slice(&Data::src),
Containers::stridedArrayView(expectedIntegral),
TestSuite::Compare::Container);
}
@ -524,17 +558,25 @@ template<class FloatingPoint, class Integral> void PackingBatchTest::castSignedF
{13, 127}
};
Containers::StridedArrayView1D<Math::Vector2<Integral>> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Math::Vector2<FloatingPoint>> 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<Integral>::data),
Containers::stridedArrayView(data).slice(&Data::dst)
.slice(&Math::Vector2<FloatingPoint>::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<FloatingPoint>::data),
Containers::stridedArrayView(data).slice(&Data::src)
.slice(&Math::Vector2<Integral>::data));
CORRADE_COMPARE_AS(
Containers::stridedArrayView(data).slice(&Data::src),
Containers::stridedArrayView(expectedIntegral),
TestSuite::Compare::Container);
}
@ -562,17 +604,25 @@ template<class T, class U> void PackingBatchTest::castUnsignedInteger() {
{13, 255}
};
Containers::StridedArrayView1D<Math::Vector2<T>> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Math::Vector2<U>> 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<T>::data),
Containers::stridedArrayView(data).slice(&Data::dst)
.slice(&Math::Vector2<U>::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<U>::data),
Containers::stridedArrayView(data).slice(&Data::src)
.slice(&Math::Vector2<T>::data));
CORRADE_COMPARE_AS(
Containers::stridedArrayView(data).slice(&Data::src),
Containers::stridedArrayView(expectedOriginalType),
TestSuite::Compare::Container);
}
@ -600,17 +650,25 @@ template<class T, class U> void PackingBatchTest::castSignedInteger() {
{13, 127}
};
Containers::StridedArrayView1D<Math::Vector2<T>> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Math::Vector2<U>> 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<T>::data),
Containers::stridedArrayView(data).slice(&Data::dst)
.slice(&Math::Vector2<U>::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<U>::data),
Containers::stridedArrayView(data).slice(&Data::src)
.slice(&Math::Vector2<T>::data));
CORRADE_COMPARE_AS(
Containers::stridedArrayView(data).slice(&Data::src),
Containers::stridedArrayView(expectedOriginalType),
TestSuite::Compare::Container);
}
@ -635,18 +693,25 @@ template<class T, class U> void PackingBatchTest::castFloatDouble() {
{T(-119.0), T(22.75)},
{T(13.0), T(127.5)}
};
Containers::StridedArrayView1D<Math::Vector2<T>> src{data, &data[0].src, 3, sizeof(Data)};
Containers::StridedArrayView1D<Math::Vector2<U>> 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<T>::data),
Containers::stridedArrayView(data).slice(&Data::dst)
.slice(&Math::Vector2<U>::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<U>::data),
Containers::stridedArrayView(data).slice(&Data::src)
.slice(&Math::Vector2<T>::data));
CORRADE_COMPARE_AS(
Containers::stridedArrayView(data).slice(&Data::src),
Containers::stridedArrayView(expectedOriginalType),
TestSuite::Compare::Container);
}
@ -660,18 +725,22 @@ template<class T> 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<T>::data);
auto srcNonContiguous = Containers::StridedArrayView2D<T>{
Containers::stridedArrayView(dataNonContiguous)
.slice(&Math::Vector4<T>::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<Float>{
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<UnsignedShort>{
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<Float>{
Containers::stridedArrayView(resultNonContiguous)
.slice(&Vector4::data)
}.every({1, 2});
Containers::String out;
Error redirectError{&out};
@ -748,14 +821,16 @@ template<class U, class T> void PackingBatchTest::assertionsCast() {
Math::Vector3<U> resultWrongVectorSize[2]{};
Math::Vector4<U> 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<T>::data);
auto dstWrongCount = Containers::stridedArrayView(resultWrongCount)
.slice(&Math::Vector2<U>::data);
auto dstWrongVectorSize = Containers::stridedArrayView(resultWrongVectorSize)
.slice(&Math::Vector3<U>::data);
auto dstNotContiguous = Containers::StridedArrayView2D<U>{
Containers::stridedArrayView(resultNonContiguous)
.slice(&Math::Vector4<U>::data)
}.every({1, 2});
Containers::String out;
Error redirectError{&out};

Loading…
Cancel
Save