diff --git a/src/Array.h b/src/Array.h index 703c63df3..622c48709 100644 --- a/src/Array.h +++ b/src/Array.h @@ -191,6 +191,13 @@ template class Array3D: public Array<3, T> { constexpr T y() const { return (*this)[1]; } /**< @overload */ T& z() { return (*this)[2]; } /**< @brief Z component */ constexpr T z() const { return (*this)[2]; } /**< @overload */ + + /** + * @brief XY part of the array + * @return First two components of the array + */ + Array2D& xy() { return reinterpret_cast&>(*this); } + constexpr Array2D xy() const { return {(*this)[0], (*this)[1]}; } /**< @overload */ }; /** @debugoperator{Magnum::Array} */ diff --git a/src/Test/ArrayTest.cpp b/src/Test/ArrayTest.cpp index 62b4cb7bc..69ade4dfe 100644 --- a/src/Test/ArrayTest.cpp +++ b/src/Test/ArrayTest.cpp @@ -104,6 +104,9 @@ void ArrayTest::access() { CORRADE_COMPARE(cc.x(), -5); CORRADE_COMPARE(cc.y(), 6); CORRADE_COMPARE(cc.z(), 7); + + CORRADE_COMPARE(c.xy(), Array2D(-5, 6)); + CORRADE_COMPARE(cc.xy(), Array2D(-5, 6)); } }}