From 515a77e31c78b01610182b076678905f69d21fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 9 Nov 2022 23:41:09 +0100 Subject: [PATCH] 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. --- src/Magnum/DebugTools/CompareMaterial.cpp | 4 ++-- src/Magnum/DebugTools/Test/CompareMaterialTest.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Magnum/DebugTools/CompareMaterial.cpp b/src/Magnum/DebugTools/CompareMaterial.cpp index 1d32b2c80..86b9c578c 100644 --- a/src/Magnum/DebugTools/CompareMaterial.cpp +++ b/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() == b.value(); + return Math::TypeTraits::equals(a.value(), b.value()); #define _ct(name, type) case Trade::MaterialAttributeType::name: \ - return a.value() == b.value(); + return Math::TypeTraits::equals(a.value(), b.value()); _ct(Bool, bool) /* LCOV_EXCL_START */ _c(Float) diff --git a/src/Magnum/DebugTools/Test/CompareMaterialTest.cpp b/src/Magnum/DebugTools/Test/CompareMaterialTest.cpp index 680035d7d..01f77b42f 100644 --- a/src/Magnum/DebugTools/Test/CompareMaterialTest.cpp +++ b/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 {