Skip to content

Commit a368aac

Browse files
authored
Cleanup options for equivalence testing (#2115)
User facing naming changes for the functional equivalence API. There are no logic changes.
1 parent 65dbd39 commit a368aac

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

source/MaterialXCore/Element.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,14 @@ bool Element::isEquivalent(ConstElementPtr rhs, const ElementEquivalenceOptions&
396396
StringVec rhsAttributeNames = rhs->getAttributeNames();
397397

398398
// Filter out any attributes specified in the options.
399-
const StringSet& skipAttributes = options.skipAttributes;
400-
if (!skipAttributes.empty())
399+
const StringSet& attributeExclusionList = options.attributeExclusionList;
400+
if (!attributeExclusionList.empty())
401401
{
402402
attributeNames.erase(std::remove_if(attributeNames.begin(), attributeNames.end(),
403-
[&skipAttributes](const string& attr) { return skipAttributes.find(attr) != skipAttributes.end(); }),
403+
[&attributeExclusionList](const string& attr) { return attributeExclusionList.find(attr) != attributeExclusionList.end(); }),
404404
attributeNames.end());
405405
rhsAttributeNames.erase(std::remove_if(rhsAttributeNames.begin(), rhsAttributeNames.end(),
406-
[&skipAttributes](const string& attr) { return skipAttributes.find(attr) != skipAttributes.end(); }),
406+
[&attributeExclusionList](const string& attr) { return attributeExclusionList.find(attr) != attributeExclusionList.end(); }),
407407
rhsAttributeNames.end());
408408
}
409409

@@ -714,7 +714,7 @@ bool ValueElement::isAttributeEquivalent(ConstElementPtr rhs, const string& attr
714714
{
715715
// Perform value comparisons
716716
bool performedValueComparison = false;
717-
if (!options.skipValueComparisons)
717+
if (options.performValueComparisons)
718718
{
719719
const StringSet uiAttributes =
720720
{
@@ -724,7 +724,7 @@ bool ValueElement::isAttributeEquivalent(ConstElementPtr rhs, const string& attr
724724
};
725725

726726
// Get precision and format options
727-
ScopedFloatFormatting fmt(options.format, options.precision);
727+
ScopedFloatFormatting fmt(options.floatFormat, options.floatPrecision);
728728

729729
ConstValueElementPtr rhsValueElement = rhs->asA<ValueElement>();
730730

source/MaterialXCore/Element.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,34 +1389,33 @@ class MX_CORE_API ElementEquivalenceOptions
13891389
public:
13901390
ElementEquivalenceOptions()
13911391
{
1392-
format = Value::getFloatFormat();
1393-
precision = Value::getFloatPrecision();
1394-
skipAttributes = {};
1395-
skipValueComparisons = false;
1392+
performValueComparisons = true;
1393+
floatFormat = Value::getFloatFormat();
1394+
floatPrecision = Value::getFloatPrecision();
1395+
attributeExclusionList = {};
13961396
};
13971397
~ElementEquivalenceOptions() { }
13981398

1399-
/// Floating point format option for floating point value comparisons
1400-
Value::FloatFormat format;
1399+
/// Perform value comparisons as opposed to literal string comparisons.
1400+
/// Default is true.
1401+
bool performValueComparisons;
14011402

1402-
/// Floating point precision option for floating point value comparisons
1403-
int precision;
1403+
/// Floating point format to use for floating point value comparisons
1404+
Value::FloatFormat floatFormat;
14041405

1405-
/// Attribute filtering options. By default all attributes are considered.
1406-
/// Name, category attributes cannot be skipped.
1406+
/// Floating point precision to use for floating point value comparisons
1407+
int floatPrecision;
1408+
1409+
/// Specifies the set of attributes that should be excluded when performing a comparison.
1410+
/// By default all attributes are considered. Name and category attributes cannot be excluded.
14071411
///
1408-
/// For example UI attribute comparision be skipped by setting:
1409-
/// skipAttributes = {
1412+
/// For example, to exclude UI and documentation attributes from consideration the follow may be set:
1413+
/// attributeExclusionList = {
14101414
/// ValueElement::UI_MIN_ATTRIBUTE, ValueElement::UI_MAX_ATTRIBUTE,
14111415
/// ValueElement::UI_SOFT_MIN_ATTRIBUTE, ValueElement::UI_SOFT_MAX_ATTRIBUTE,
14121416
/// ValueElement::UI_STEP_ATTRIBUTE, Element::XPOS_ATTRIBUTE,
1413-
/// Element::YPOS_ATTRIBUTE };
1414-
StringSet skipAttributes;
1415-
1416-
/// Do not perform any value comparisions. Instead perform exact string comparisons for attributes
1417-
/// Default is false. The operator==() method can be used instead as it always performs
1418-
/// a strict comparison. Default is false.
1419-
bool skipValueComparisons;
1417+
/// Element::YPOS_ATTRIBUTE, Element::DOC_ATTRIBUTE };
1418+
StringSet attributeExclusionList;
14201419
};
14211420

14221421
/// @class ExceptionOrphanedElement

source/MaterialXTest/MaterialXCore/Document.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,27 @@ TEST_CASE("Document equivalence", "[document]")
217217
mx::ElementEquivalenceOptions options;
218218
mx::ElementEquivalenceResultVec results;
219219

220-
// Check skipping all value compares
221-
options.skipValueComparisons = true;
220+
// Check that this fails when not performing value comparisons
221+
options.performValueComparisons = false;
222222
bool equivalent = doc->isEquivalent(doc2, options, &results);
223223
REQUIRE(!equivalent);
224224

225225
// Check attibute values
226-
options.skipValueComparisons = false;
226+
options.performValueComparisons = true;
227227
results.clear();
228228
equivalent = doc->isEquivalent(doc2, options, &results);
229229
REQUIRE(equivalent);
230230

231231
unsigned int currentPrecision = mx::Value::getFloatPrecision();
232232
// This will compare 0.012345608 versus: 1, 0.012345611 for input10
233-
options.precision = 8;
233+
options.floatPrecision = 8;
234234
equivalent = doc->isEquivalent(doc2, options);
235235
REQUIRE(!equivalent);
236-
options.precision = currentPrecision;
236+
options.floatPrecision = currentPrecision;
237237

238238
// Check attribute filtering of inputs
239239
results.clear();
240-
options.skipAttributes = { mx::ValueElement::UI_MIN_ATTRIBUTE, mx::ValueElement::UI_MAX_ATTRIBUTE };
240+
options.attributeExclusionList = { mx::ValueElement::UI_MIN_ATTRIBUTE, mx::ValueElement::UI_MAX_ATTRIBUTE };
241241
for (mx::InputPtr floatInput : floatInputs)
242242
{
243243
floatInput->setAttribute(mx::ValueElement::UI_MIN_ATTRIBUTE, "0.9");

source/PyMaterialX/PyMaterialXCore/PyElement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ void bindPyElement(py::module& mod)
224224
.def_readwrite("attributeName", &mx::ElementEquivalenceResult::attributeName);
225225

226226
py::class_<mx::ElementEquivalenceOptions>(mod, "ElementEquivalenceOptions")
227-
.def_readwrite("format", &mx::ElementEquivalenceOptions::format)
228-
.def_readwrite("precision", &mx::ElementEquivalenceOptions::precision)
229-
.def_readwrite("skipAttributes", &mx::ElementEquivalenceOptions::skipAttributes)
230-
.def_readwrite("skipValueComparisons", &mx::ElementEquivalenceOptions::skipValueComparisons)
227+
.def_readwrite("performValueComparisons", &mx::ElementEquivalenceOptions::performValueComparisons)
228+
.def_readwrite("floatFormat", &mx::ElementEquivalenceOptions::floatFormat)
229+
.def_readwrite("floatPrecision", &mx::ElementEquivalenceOptions::floatPrecision)
230+
.def_readwrite("attributeExclusionList", &mx::ElementEquivalenceOptions::attributeExclusionList)
231231
.def(py::init<>());
232232

233233
py::class_<mx::StringResolver, mx::StringResolverPtr>(mod, "StringResolver")

0 commit comments

Comments
 (0)