Browse Source

DebugTools: fuzzy-compare floats in CompareMaterial.

As it should be. It would be silly to compare vectors this way (because
that's what the operator== does by default), but not scalars.
pull/610/head
Vladimír Vondruš 4 years ago
parent
commit
515a77e31c
  1. 4
      src/Magnum/DebugTools/CompareMaterial.cpp
  2. 12
      src/Magnum/DebugTools/Test/CompareMaterialTest.cpp

4
src/Magnum/DebugTools/CompareMaterial.cpp

@ -91,9 +91,9 @@ bool attributesEqual(const Trade::MaterialAttributeData& a, const Trade::Materia
CORRADE_INTERNAL_ASSERT(a.type() == b.type());
switch(a.type()) {
#define _c(type) case Trade::MaterialAttributeType::type: \
return a.value<type>() == b.value<type>();
return Math::TypeTraits<type>::equals(a.value<type>(), b.value<type>());
#define _ct(name, type) case Trade::MaterialAttributeType::name: \
return a.value<type>() == b.value<type>();
return Math::TypeTraits<type>::equals(a.value<type>(), b.value<type>());
_ct(Bool, bool)
/* LCOV_EXCL_START */
_c(Float)

12
src/Magnum/DebugTools/Test/CompareMaterialTest.cpp

@ -80,6 +80,18 @@ const struct {
{Trade::MaterialLayer::ClearCoat},
{"name", "hello"_s},
}, {1, 3, 4}}},
{"fuzzy compare",
Trade::MaterialData{Trade::MaterialType::Phong, {
{Trade::MaterialAttribute::Shininess, 2000.0f},
{Trade::MaterialAttribute::AlphaMask, 0.5f},
{Trade::MaterialAttribute::DiffuseTexture, 3u},
}},
Trade::MaterialData{Trade::MaterialType::Phong, {
{Trade::MaterialAttribute::Shininess, 2000.0f + 0.01f},
{Trade::MaterialAttribute::AlphaMask, 0.5f - 1.0e-6f},
{Trade::MaterialAttribute::DiffuseTexture, 3u},
}},
},
};
const struct {

Loading…
Cancel
Save