Changeset View
Changeset View
Standalone View
Standalone View
source/maths/tests/test_Matrix3d.h
/* Copyright (C) 2011 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | |||||||||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | |||||||||||
* | * | |||||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | |||||||||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | |||||||||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | |||||||||||
* (at your option) any later version. | * (at your option) any later version. | |||||||||||
* | * | |||||||||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | |||||||||||
Show All 35 Lines | for (int i = 0; i < 4; ++i) | |||||||||||
{ | { | |||||||||||
const float expected = (x==y)? 1.0f : 0.0f; | const float expected = (x==y)? 1.0f : 0.0f; | |||||||||||
TS_ASSERT_DELTA(m(x,y), expected, 0.0002f); | TS_ASSERT_DELTA(m(x,y), expected, 0.0002f); | |||||||||||
} | } | |||||||||||
} | } | |||||||||||
} | } | |||||||||||
} | } | |||||||||||
void test_compoundMultiplication() | ||||||||||||
vladislavbelov: It doesn't check multiplication explicitly. | ||||||||||||
Done Inline Actions
Maybe ? Stan: Maybe ? | ||||||||||||
Not Done Inline ActionsMaybe. vladislavbelov: Maybe. | ||||||||||||
{ | ||||||||||||
const float EPS = 2e-4f; | ||||||||||||
float invertibleData[16] = { | ||||||||||||
2.f, -3.f, 0.f, 1.f, | ||||||||||||
-2.f, 3.f, 0.f, 0.f, | ||||||||||||
1.f, -2.f, 1.f, 0.f, | ||||||||||||
1.f, -1.f, 0.f, 0.f | ||||||||||||
}; | ||||||||||||
// Invertible matrix. | ||||||||||||
CMatrix3D a(invertibleData); | ||||||||||||
CMatrix3D n; | ||||||||||||
a.GetInverse(n); | ||||||||||||
a *= n; | ||||||||||||
CMatrix3D a2(invertibleData); | ||||||||||||
n *= a2; | ||||||||||||
Not Done Inline ActionsEpsilon should be a named constant. vladislavbelov: Epsilon should be a named constant. | ||||||||||||
Done Inline Actionsok. Stan: ok. | ||||||||||||
for (int j = 0; j < 16; ++j) | ||||||||||||
TS_ASSERT_DELTA(a._data[j], n._data[j], EPS); | ||||||||||||
// Non invertible matrix. | ||||||||||||
float nonInvertibleData[16] = { | ||||||||||||
2.f, -3.f, 0.f, 1.f, | ||||||||||||
-2.f, 3.f, 0.f, 0.f, | ||||||||||||
1.f, -2.f, 1.f, 0.f, | ||||||||||||
0.f, 0.f, 0.f, 0.f | ||||||||||||
}; | ||||||||||||
CMatrix3D b(nonInvertibleData); | ||||||||||||
b.GetInverse(n); | ||||||||||||
b *= n; | ||||||||||||
CMatrix3D b2(nonInvertibleData); | ||||||||||||
n *= b2; | ||||||||||||
bool different = false; | ||||||||||||
for (int j = 0; j < 16; ++j) | ||||||||||||
{ | ||||||||||||
if (!feq(b._data[j], n._data[j], EPS)) | ||||||||||||
{ | ||||||||||||
different = true; | ||||||||||||
break; | ||||||||||||
} | ||||||||||||
Not Done Inline ActionsThe same meaning as above but a different implementation. vladislavbelov: The same meaning as above but a different implementation. | ||||||||||||
Done Inline ActionsDo have a better implementation to check for at least one difference? Stan: Do have a better implementation to check for at least one difference? | ||||||||||||
Not Done Inline ActionsAs you had above: TS_ASSERT_DELTA. vladislavbelov: As you had above: `TS_ASSERT_DELTA`. | ||||||||||||
} | ||||||||||||
TS_ASSERT(different); | ||||||||||||
} | ||||||||||||
void test_quats() | void test_quats() | |||||||||||
{ | { | |||||||||||
srand(0); | srand(0); | |||||||||||
for (int i = 0; i < 4; ++i) | for (int i = 0; i < 4; ++i) | |||||||||||
{ | { | |||||||||||
CQuaternion q; | CQuaternion q; | |||||||||||
q.FromEulerAngles( | q.FromEulerAngles( | |||||||||||
-6.28f + 12.56f*(rand()/(float)RAND_MAX), | -6.28f + 12.56f*(rand()/(float)RAND_MAX), | |||||||||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
It doesn't check multiplication explicitly.