diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 1ef3f77ba..b1f5c9fe4 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -67,6 +67,7 @@ class Vector2Test: public Corrade::TestSuite::Tester { void axes(); void scales(); void perpendicular(); + void aspectRatio(); void debug(); void configuration(); @@ -90,6 +91,7 @@ Vector2Test::Vector2Test() { &Vector2Test::axes, &Vector2Test::scales, &Vector2Test::perpendicular, + &Vector2Test::aspectRatio, &Vector2Test::debug, &Vector2Test::configuration}); @@ -196,6 +198,11 @@ void Vector2Test::perpendicular() { CORRADE_COMPARE(Vector2::xAxis().perpendicular(), Vector2::yAxis()); } +void Vector2Test::aspectRatio() { + const Vector2 a(3.0f, 4.0f); + CORRADE_COMPARE(a.aspectRatio(), 0.75f); +} + void Vector2Test::debug() { std::ostringstream o; Debug(&o) << Vector2(0.5f, 15.0f); diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index f55483b7d..2fb887fd8 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -134,6 +134,15 @@ template class Vector2: public Vector<2, T> { */ Vector2 perpendicular() const { return {-y(), x()}; } + /** + * @brief Aspect ratio + * + * Returns quotient of the two elements. @f[ + * a = \frac{v_x}{v_y} + * @f] + */ + T aspectRatio() const { return x()/y(); } + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(2, Vector2) };