Skip to content

Commit

Permalink
GlmIntegration: work around crazy init list apocalypse in 0.9.5.1.
Browse files Browse the repository at this point in the history
Read the comment for a good horror story and the following issue for a
good laugh. Everything would be good if 0.9.5.1 was long forgotten in
the years past, but for some reason it is *the* version included in
Ubuntu 14.04 LTS that has EOL in April *next year*.

This gave me cancer.

g-truc/glm#159
  • Loading branch information
mosra committed May 31, 2018
1 parent cd769e9 commit 75086ab
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Magnum/GlmIntegration/GtcIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ q> struct QuaternionConverter<T, glm::tquat<T, q>> {
}

static glm::tquat<T, q> to(const Quaternion<T>& other) {
#if GLM_VERSION*10 + GLM_VERSION_REVISION < 952
/* Due to initializer list fiasco in 0.9.5.1, using {} gives a totally
different result. https://github.com/g-truc/glm/issues/159 */
return glm::tquat<T, q>(other.scalar(), other.vector().x(), other.vector().y(), other.vector().z());
#else
return {other.scalar(), other.vector().x(), other.vector().y(), other.vector().z()};
#endif
}
};

Expand Down
30 changes: 26 additions & 4 deletions src/Magnum/GlmIntegration/Test/GtcIntegrationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,54 @@ GtcIntegrationTest::GtcIntegrationTest() {

void GtcIntegrationTest::quat() {
Quaternion a{{1.0f, 2.0f, 3.0f}, 4.0f};
#if GLM_VERSION*10 + GLM_VERSION_REVISION < 952
/* Due to initializer list fiasco in < 0.9.5.2, using {} gives a totally
different result. https://github.com/g-truc/glm/issues/159 */
glm::quat b(4.0f, 1.0f, 2.0f, 3.0f);
#else
glm::quat b{4.0f, 1.0f, 2.0f, 3.0f};
#endif

CORRADE_COMPARE(Quaternion{b}, a);
#if GLM_VERSION < 97
CORRADE_VERIFY(glm::quat{a} == b);
/* Can't use {} in < 0.9.5.2 because it matches *anything*. Too bad this
version is in 14.04 LTS. https://github.com/g-truc/glm/issues/159. Also,
glm::to_string() for quat is since O.9.7. */
CORRADE_VERIFY(glm::quat(a) == b);
#else
CORRADE_COMPARE(glm::quat{a}, b);
#endif

CORRADE_COMPARE(Quaternion{b}.vector().z(), b.z);
CORRADE_COMPARE(glm::quat{a}.z, a.vector().z());
/* Can't use {} in < 0.9.5.2 because it matches *anything*. Too bad this
version is in 14.04 LTS. https://github.com/g-truc/glm/issues/159 */
CORRADE_COMPARE(glm::quat(a).z, a.vector().z());
}

void GtcIntegrationTest::dquat() {
Quaterniond a{{1.0, 2.0, 3.0}, 4.0};
#if GLM_VERSION*10 + GLM_VERSION_REVISION < 952
/* Due to initializer list fiasco in < 0.9.5.2, using {} gives a totally
different result. https://github.com/g-truc/glm/issues/159 */
glm::dquat b(4.0, 1.0, 2.0, 3.0);
#else
glm::dquat b{4.0, 1.0, 2.0, 3.0};
#endif

CORRADE_COMPARE(Quaterniond{b}, a);
#if GLM_VERSION < 97
CORRADE_VERIFY(glm::dquat{a} == b);
/* Can't use {} in < 0.9.5.2 because it matches *anything*. Too bad this
version is in 14.04 LTS. https://github.com/g-truc/glm/issues/159. Also,
glm::to_string() for quat is since O.9.7. */
CORRADE_VERIFY(glm::dquat(a) == b);
#else
CORRADE_COMPARE(glm::dquat{a}, b);
#endif

CORRADE_COMPARE(Quaterniond{b}.vector().z(), b.z);
CORRADE_COMPARE(glm::dquat{a}.z, a.vector().z());
/* Can't use {} in < 0.9.5.2 because it matches *anything*. Too bad this
version is in 14.04 LTS. https://github.com/g-truc/glm/issues/159 */
CORRADE_COMPARE(glm::dquat(a).z, a.vector().z());
}

void GtcIntegrationTest::debugQuat() {
Expand Down
20 changes: 20 additions & 0 deletions src/Magnum/GlmIntegration/Test/GtxIntegrationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ GtxIntegrationTest::GtxIntegrationTest() {
void GtxIntegrationTest::dualquat() {
DualQuaternion a{{{1.0f, 2.0f, 3.0f}, 4.0f},
{{5.0f, 6.0f, 7.0f}, 8.0f}};
#if GLM_VERSION*10 + GLM_VERSION_REVISION < 952
/* In < 0.9.5.2 it is ambiguous (vec3 vs quat as second parameter) due
to initializer list fiasco: https://github.com/g-truc/glm/issues/159.
Also, due to the same thing, using {} gives a totally different result
compared to (). */
glm::dualquat b{glm::quat(4.0f, 1.0f, 2.0f, 3.0f),
glm::quat(8.0f, 5.0f, 6.0f, 7.0f)};
#else
glm::dualquat b{{4.0f, 1.0f, 2.0f, 3.0f},
{8.0f, 5.0f, 6.0f, 7.0f}};
#endif

CORRADE_COMPARE(DualQuaternion{b}, a);
#if GLM_VERSION < 97
/* glm::to_string() for quat is since O.9.7 */
CORRADE_VERIFY(glm::dualquat{a} == b);
#else
CORRADE_COMPARE(glm::dualquat{a}, b);
Expand All @@ -75,11 +85,21 @@ void GtxIntegrationTest::dualquat() {
void GtxIntegrationTest::ddualquat() {
DualQuaterniond a{{{1.0, 2.0, 3.0}, 4.0},
{{5.0, 6.0, 7.0}, 8.0}};
#if GLM_VERSION*10 + GLM_VERSION_REVISION < 952
/* In < 0.9.5.2 it is ambiguous (vec3 vs quat as second parameter) due
to initializer list fiasco: https://github.com/g-truc/glm/issues/159.
Also, due to the same thing, using {} gives a totally different result
compared to (). */
glm::ddualquat b{glm::dquat(4.0, 1.0, 2.0, 3.0),
glm::dquat(8.0, 5.0, 6.0, 7.0)};
#else
glm::ddualquat b{{4.0, 1.0, 2.0, 3.0},
{8.0, 5.0, 6.0, 7.0}};
#endif

CORRADE_COMPARE(DualQuaterniond{b}, a);
#if GLM_VERSION < 97
/* glm::to_string() for quat is since O.9.7 */
CORRADE_VERIFY(glm::ddualquat{a} == b);
#else
CORRADE_COMPARE(glm::ddualquat{a}, b);
Expand Down

0 comments on commit 75086ab

Please # to comment.