Browse Source

Math: no need to include <tuple> just for std::tie() in tests.

Unpack the pairs manually instead.
pull/331/head
Vladimír Vondruš 7 years ago
parent
commit
3a1713d549
  1. 17
      src/Magnum/Math/Algorithms/Test/QrTest.cpp
  2. 8
      src/Magnum/Math/Test/FunctionsTest.cpp
  3. 33
      src/Magnum/Math/Test/IntersectionBenchmark.cpp

17
src/Magnum/Math/Algorithms/Test/QrTest.cpp

@ -23,7 +23,6 @@
DEALINGS IN THE SOFTWARE.
*/
#include <tuple>
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Math/Matrix3.h"
@ -55,29 +54,27 @@ void QrTest::test() {
Vector3{-20.0f, 27.0f, 11.0f},
Vector3{-14.0f, -4.0f, -2.0f}};
Matrix3x3 q, r;
std::tie(q, r) = Algorithms::qr(a);
std::pair<Matrix3x3, Matrix3x3> qr = Algorithms::qr(a);
auto qExpected = Matrix3x3{Vector3{ 0.0f, 15.0f, 20.0f},
Vector3{-20.0f, 12.0f, -9.0f},
Vector3{-15.0f, -16.0f, 12.0f}}/25.0f;
CORRADE_COMPARE(q, qExpected);
CORRADE_COMPARE(qr.first, qExpected);
Matrix3x3 rExpected{Vector3{ 5.0f, 0.0f, 0.0f},
Vector3{25.0f, 25.0f, 0.0f},
Vector3{-4.0f, 10.0f, 10.0f}};
CORRADE_COMPARE(r, rExpected);
CORRADE_COMPARE(qr.second, rExpected);
}
void QrTest::decomposeRotationShear() {
Matrix4 a = Matrix4::scaling({1.5f, 2.0f, 1.0f})*Matrix4::rotationZ(35.0_degf);
Matrix3x3 q, r;
std::tie(q, r) = Algorithms::qr(a.rotationScaling());
CORRADE_COMPARE(q*r, a.rotationScaling());
std::pair<Matrix3x3, Matrix3x3> qr = Algorithms::qr(a.rotationScaling());
CORRADE_COMPARE(qr.first*qr.second, a.rotationScaling());
auto q4 = Matrix4::from(q, {});
auto r4 = Matrix4::from(r, {});
auto q4 = Matrix4::from(qr.first, {});
auto r4 = Matrix4::from(qr.second, {});
CORRADE_COMPARE(q4, Matrix4::rotationZ(43.03357_degf));
CORRADE_COMPARE(r4.scaling(), (Vector3{1.68099f, 1.85048f, 1.0f}));

8
src/Magnum/Math/Test/FunctionsTest.cpp

@ -23,7 +23,6 @@
DEALINGS IN THE SOFTWARE.
*/
#include <tuple>
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Math/Functions.h"
@ -325,10 +324,9 @@ void FunctionsTest::exp() {
}
void FunctionsTest::div() {
Int quotient, remainder;
std::tie(quotient, remainder) = Math::div(57, 6);
CORRADE_COMPARE(quotient, 9);
CORRADE_COMPARE(remainder, 3);
std::pair<Int, Int> div = Math::div(57, 6);
CORRADE_COMPARE(div.first, 9);
CORRADE_COMPARE(div.second, 3);
}
void FunctionsTest::isInf() {

33
src/Magnum/Math/Test/IntersectionBenchmark.cpp

@ -25,7 +25,6 @@
*/
#include <random>
#include <tuple>
#include <utility>
#include <Corrade/TestSuite/Tester.h>
@ -113,7 +112,11 @@ struct IntersectionBenchmark: Corrade::TestSuite::Tester {
void sphereConeView();
Frustum _frustum;
std::tuple<Vector3, Vector3, Rad> _cone;
struct {
Vector3 origin;
Vector3 normal;
Rad angle;
} _cone;
Matrix4 _coneView;
std::vector<Range3D> _boxes;
@ -140,11 +143,11 @@ IntersectionBenchmark::IntersectionBenchmark() {
/* Cone angle distribution */
std::uniform_real_distribution<float> ad(1.0f, 179.0f);
_cone = std::make_tuple(Vector3{pd(g), pd(g), pd(g)},
Vector3{pd(g), pd(g), pd(g)}.normalized(),
Rad(Deg(ad(g))));
_coneView = coneViewFromCone(std::get<0>(_cone), std::get<1>(_cone));
_frustum = Frustum::fromMatrix(_coneView*Matrix4::perspectiveProjection(std::get<2>(_cone), 1.0f, 0.001f, 100.0f));
_cone.origin = Vector3{pd(g), pd(g), pd(g)};
_cone.normal = Vector3{pd(g), pd(g), pd(g)}.normalized();
_cone.angle = Deg(ad(g));
_coneView = coneViewFromCone(_cone.origin, _cone.normal);
_frustum = Frustum::fromMatrix(_coneView*Matrix4::perspectiveProjection(_cone.angle, 1.0f, 0.001f, 100.0f));
_boxes.reserve(512);
_spheres.reserve(512);
@ -173,10 +176,10 @@ void IntersectionBenchmark::rangeFrustum() {
void IntersectionBenchmark::rangeCone() {
volatile bool b = false;
CORRADE_BENCHMARK(50) {
const Float tanAngle = Math::tan(std::get<2>(_cone));
const Float tanAngle = Math::tan(_cone.angle);
const Float tanAngleSqPlusOne = tanAngle*tanAngle + 1.0f;
for(auto& box: _boxes) {
b = b ^ Intersection::rangeCone(box, std::get<0>(_cone), std::get<1>(_cone), tanAngleSqPlusOne);
b = b ^ Intersection::rangeCone(box, _cone.origin, _cone.normal, tanAngleSqPlusOne);
}
}
}
@ -191,18 +194,18 @@ void IntersectionBenchmark::sphereFrustum() {
void IntersectionBenchmark::sphereConeNaive() {
volatile bool b = false;
CORRADE_BENCHMARK(50) for(auto& sphere: _spheres) {
b = b ^ sphereConeGT<Float>(sphere.xyz(), sphere.w(), std::get<0>(_cone), std::get<1>(_cone), std::get<2>(_cone));
b = b ^ sphereConeGT<Float>(sphere.xyz(), sphere.w(), _cone.origin, _cone.normal, _cone.angle);
}
}
void IntersectionBenchmark::sphereCone() {
volatile bool b = false;
CORRADE_BENCHMARK(50) {
const Float sinAngle = Math::sin(std::get<2>(_cone));
const Float tanAngle = Math::tan(std::get<2>(_cone));
const Float sinAngle = Math::sin(_cone.angle);
const Float tanAngle = Math::tan(_cone.angle);
const Float tanAngleSqPlusOne = tanAngle*tanAngle + 1.0f;
for(auto& sphere: _spheres) {
b = b ^ Intersection::sphereCone(sphere.xyz(), sphere.w(), std::get<0>(_cone), std::get<1>(_cone), sinAngle, tanAngleSqPlusOne);
b = b ^ Intersection::sphereCone(sphere.xyz(), sphere.w(), _cone.origin, _cone.normal, sinAngle, tanAngleSqPlusOne);
}
}
}
@ -210,8 +213,8 @@ void IntersectionBenchmark::sphereCone() {
void IntersectionBenchmark::sphereConeView() {
volatile bool b = false;
CORRADE_BENCHMARK(50) {
const Float sinAngle = Math::sin(std::get<2>(_cone));
const Float tanAngle = Math::tan(std::get<2>(_cone));
const Float sinAngle = Math::sin(_cone.angle);
const Float tanAngle = Math::tan(_cone.angle);
for(auto& sphere: _spheres) {
b = b ^ Intersection::sphereConeView(sphere.xyz(), sphere.w(), _coneView, sinAngle, tanAngle);
}

Loading…
Cancel
Save