1 #include "math/Quat.h"
2 #include "catch.hpp"
3 #include "tests/Approx.h"
4 
5 using namespace Sph;
6 
7 TEST_CASE("Quaternion rotation", "[quat]") {
8     Quat q1(Vector(1._f, 0._f, 0._f), 0.35_f);
9     REQUIRE(q1.convert() == approx(AffineMatrix::rotateX(0.35_f)));
10 
11     Vector axis = getNormalized(Vector(3._f, -2._f, 1._f));
12     Quat q2(axis, 0.2_f);
13     REQUIRE(q2.convert() == approx(AffineMatrix::rotateAxis(axis, 0.2_f)));
14 }
15 
16 TEST_CASE("Quaternion roundtrip", "[quat]") {
17     AffineMatrix m = AffineMatrix::rotateAxis(getNormalized(Vector(-4._f, 3._f, 2._f)), 0.5_f);
18     REQUIRE(Quat(m).convert() == approx(m));
19 }
20 
21 TEST_CASE("Quaternion axis and angle", "[quat]") {
22     const Vector axis = getNormalized(Vector(3._f, -1._f, 2._f));
23     const Float angle = 0.25_f;
24     Quat q(axis, angle);
25     REQUIRE(q.angle() == approx(angle));
26     REQUIRE(q.axis() == approx(axis));
27 }
28