diff --git a/doc/changelog.dox b/doc/changelog.dox index d15e6957f..c978b6909 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -648,6 +648,8 @@ See also: return a reference to a fixed-size array instead of a pointer (i.e., @cpp T(&)[size] @ce instead of @cpp T* @ce) for more convenient usage in APIs that take sized views. +- Added @ref Math::Range::scaled() and @ref Math::Range::scaledFromCenter() + overloads taking a scalar @subsubsection changelog-latest-changes-meshtools MeshTools library diff --git a/src/Magnum/Math/Range.h b/src/Magnum/Math/Range.h index e112f886e..65e9ed4b3 100644 --- a/src/Magnum/Math/Range.h +++ b/src/Magnum/Math/Range.h @@ -287,23 +287,47 @@ template class Range { * Multiplies the minimal and maximal coordinates by given amount. * Center *doesn't* remain the same, use @ref scaledFromCenter() for * that operation. - * @see @ref padded() + * @see @ref padded(), @ref scaled(T) const */ Range scaled(const VectorType& scaling) const { return {_min*scaling, _max*scaling}; } + /** + * @overload + * @m_since_latest + */ + #ifndef DOXYGEN_GENERATING_OUTPUT + template::type> + #endif + Range scaled(T scaling) const { + return {_min*scaling, _max*scaling}; + } + /** * @brief Range scaled from the center * * Scales the size, while center remains the same. - * @see @ref scaled(), @ref padded(), @ref fromCenter() + * @see @ref scaled(), @ref padded(), @ref fromCenter(), + * @ref scaledFromCenter(T) const */ Range scaledFromCenter(const VectorType& scaling) const { /* Can't use *T(0.5) because that won't work for integers */ return fromCenter(center(), size()*scaling/T(2)); } + /** + * @overload + * @m_since_latest + */ + #ifndef DOXYGEN_GENERATING_OUTPUT + template::type> + #endif + Range scaledFromCenter(T scaling) const { + /* Can't use *T(0.5) because that won't work for integers */ + return fromCenter(center(), size()*scaling/T(2)); + } + /** * @brief Whether given point is contained inside the range * @@ -375,8 +399,14 @@ template class Range { Type scaled(const VectorType& scaling) const { \ return Range::scaled(scaling); \ } \ + Type scaled(T scaling) const { \ + return Range::scaled(scaling); \ + } \ Type scaledFromCenter(const VectorType& scaling) const { \ return Range::scaledFromCenter(scaling); \ + } \ + Type scaledFromCenter(T scaling) const { \ + return Range::scaledFromCenter(scaling); \ } #endif diff --git a/src/Magnum/Math/Test/RangeTest.cpp b/src/Magnum/Math/Test/RangeTest.cpp index d970a29e1..5c71ca05d 100644 --- a/src/Magnum/Math/Test/RangeTest.cpp +++ b/src/Magnum/Math/Test/RangeTest.cpp @@ -666,9 +666,12 @@ void RangeTest::padded1D() { void RangeTest::scaled() { Range2Di a({34, 23}, {47, 30}); Range2Di b({68, -69}, {94, -90}); + Range2Di c({68, 46}, {94, 60}); CORRADE_COMPARE(a.scaled({2, -3}), b); + CORRADE_COMPARE(a.scaled(2), c); CORRADE_COMPARE((a.size()*Vector2i{2, -3}), b.size()); + CORRADE_COMPARE(a.size()*2, c.size()); } void RangeTest::scaled1D() { @@ -682,10 +685,14 @@ void RangeTest::scaled1D() { void RangeTest::scaledFromCenter() { Range2Di a{{34, 22}, {48, 30}}; Range2Di b{{27, 38}, {55, 14}}; + Range2Di c{{27, 18}, {55, 34}}; CORRADE_COMPARE(a.scaledFromCenter({2, -3}), b); + CORRADE_COMPARE(a.scaledFromCenter(2), c); CORRADE_COMPARE(a.center(), b.center()); + CORRADE_COMPARE(a.center(), c.center()); CORRADE_COMPARE((a.size()*Vector2i{2, -3}), b.size()); + CORRADE_COMPARE(a.size()*2, c.size()); } void RangeTest::scaledFromCenter1D() { @@ -943,7 +950,9 @@ void RangeTest::subclassTypes() { CORRADE_VERIFY(std::is_same::value); CORRADE_VERIFY(std::is_same::value); CORRADE_VERIFY(std::is_same::value); + CORRADE_VERIFY(std::is_same::value); CORRADE_VERIFY(std::is_same::value); + CORRADE_VERIFY(std::is_same::value); } void RangeTest::subclass() { @@ -960,8 +969,12 @@ void RangeTest::subclass() { Recti(Vector2i{31, 28}, Vector2i{50, 25})); CORRADE_COMPARE(Recti(Vector2i{34, 23}, Vector2i{47, 30}).scaled({2, -3}), Recti(Vector2i{68, -69}, Vector2i{94, -90})); + CORRADE_COMPARE(Recti(Vector2i{34, 23}, Vector2i{47, 30}).scaled(2), + Recti(Vector2i{68, 46}, Vector2i{94, 60})); CORRADE_COMPARE(Recti(Vector2i{34, 22}, Vector2i{48, 30}).scaledFromCenter({2, -3}), Recti(Vector2i{27, 38}, Vector2i{55, 14})); + CORRADE_COMPARE(Recti(Vector2i{34, 22}, Vector2i{48, 30}).scaledFromCenter(2), + Recti(Vector2i{27, 18}, Vector2i{55, 34})); } void RangeTest::debug() {