Browse Source

Math: Non-const overloads for Frustum::(left|right|top|bottom|near|far|[])

Signed-off-by: Squareys <squareys@googlemail.com>
pull/371/head
Squareys 6 years ago committed by Vladimír Vondruš
parent
commit
a0e6ac1ed0
  1. 56
      src/Magnum/Math/Frustum.h
  2. 39
      src/Magnum/Math/Test/FrustumTest.cpp

56
src/Magnum/Math/Frustum.h

@ -146,9 +146,17 @@ template<class T> class Frustum {
/**
* @brief Plane at given index
* @m_since_latest
*
* Expects that @p i is less than @cpp 6 @ce.
*/
Vector4<T>& operator[](std::size_t i) {
CORRADE_ASSERT(i < 6, "Math::Frustum::operator[](): index" << i << "out of range",
_data[i]);
return _data[i];
}
/** @overload */
/* returns const& so [][] operations are also constexpr */
constexpr const Vector4<T>& operator[](std::size_t i) const {
return CORRADE_CONSTEXPR_ASSERT(i < 6, "Math::Frustum::operator[](): index" << i << "out of range"), _data[i];
@ -196,23 +204,47 @@ template<class T> class Frustum {
*/
constexpr const Vector4<T>* cend() const { return _data + 6; }
/** @brief Left plane */
constexpr Vector4<T> left() const { return _data[0]; }
/**
* @brief Left plane
* @m_since_latest
*/
Vector4<T>& left() { return _data[0]; }
constexpr Vector4<T> left() const { return _data[0]; } /**< @overload */
/** @brief Right plane */
constexpr Vector4<T> right() const { return _data[1]; }
/**
* @brief Right plane
* @m_since_latest
*/
Vector4<T>& right() { return _data[1]; }
constexpr Vector4<T> right() const { return _data[1]; } /**< @overload */
/** @brief Bottom plane */
constexpr Vector4<T> bottom() const { return _data[2]; }
/**
* @brief Bottom plane
* @m_since_latest
*/
Vector4<T>& bottom() { return _data[2]; }
constexpr Vector4<T> bottom() const { return _data[2]; } /**< @overload */
/** @brief Top plane */
constexpr Vector4<T> top() const { return _data[3]; }
/**
* @brief Top plane
* @m_since_latest
*/
Vector4<T>& top() { return _data[3]; }
constexpr Vector4<T> top() const { return _data[3]; } /**< @overload */
/** @brief Near plane */
constexpr Vector4<T> near() const { return _data[4]; }
/**
* @brief Near plane
* @m_since_latest
*/
Vector4<T>& near() { return _data[4]; }
constexpr Vector4<T> near() const { return _data[4]; } /**< @overload */
/** @brief Far plane */
constexpr Vector4<T> far() const { return _data[5]; }
/**
* @brief Far plane
* @m_since_latest
*/
Vector4<T>& far() { return _data[5]; }
constexpr Vector4<T> far() const { return _data[5]; } /**< @overload */
private:
Vector4<T> _data[6];

39
src/Magnum/Math/Test/FrustumTest.cpp

@ -119,17 +119,42 @@ void FrustumTest::construct() {
{-7.0f, 8.0f, -9.0f, 0.5f},
{ 7.0f, 8.0f, 9.0f, 0.6f}};
constexpr Frustum frustum = {
Frustum a = {
planes[0], planes[1],
planes[2], planes[3],
planes[4], planes[5]};
constexpr Frustum ca = {
planes[0], planes[1],
planes[2], planes[3],
planes[4], planes[5]};
constexpr Vector4 c3 = ca[3];
CORRADE_COMPARE(c3, planes[3]);
CORRADE_COMPARE(a[3], planes[3]);
constexpr Vector4 cleft = ca.left();
CORRADE_COMPARE(a.left(), planes[0]);
CORRADE_COMPARE(cleft, planes[0]);
constexpr Vector4 cright = ca.right();
CORRADE_COMPARE(a.right(), planes[1]);
CORRADE_COMPARE(cright, planes[1]);
constexpr Vector4 cbottom = ca.bottom();
CORRADE_COMPARE(a.bottom(), planes[2]);
CORRADE_COMPARE(cbottom, planes[2]);
constexpr Vector4 ctop = ca.top();
CORRADE_COMPARE(a.top(), planes[3]);
CORRADE_COMPARE(ctop, planes[3]);
constexpr Vector4 cnear = ca.near();
CORRADE_COMPARE(a.near(), planes[4]);
CORRADE_COMPARE(cnear, planes[4]);
CORRADE_COMPARE(frustum[0], planes[0]);
CORRADE_COMPARE(frustum[1], planes[1]);
CORRADE_COMPARE(frustum[2], planes[2]);
CORRADE_COMPARE(frustum[3], planes[3]);
CORRADE_COMPARE(frustum[4], planes[4]);
CORRADE_COMPARE(frustum[5], planes[5]);
constexpr Vector4 cfar = ca.far();
CORRADE_COMPARE(cfar, planes[5]);
CORRADE_COMPARE(a.far(), planes[5]);
CORRADE_VERIFY((std::is_nothrow_constructible<Frustum, Vector4, Vector4, Vector4, Vector4, Vector4, Vector4>::value));
}

Loading…
Cancel
Save