Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Element Equivalence Interfaces #2003

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Sep 4, 2024

Issue

Addresses issues: #1988 and #1981 dealing with comparison of element values by adding in a new "functionally" equivalent interface, such that functional equivalence means that the 2 elements perform the same computation. This differs from the existing operator== interface which checks for syntactical equivalence.

The key points for functional equivalence include:

  • The order of attributes specified on an Element does not matter.
  • The order of children Elements does not matter as long as these are immediate children of a Document or a Compound NodeGraph.
  • Equivalence can be performed based on runtime values as opposed to the string value used for text storage. For floating point numeric values equivalence can be performed within a given precision tolerance and/or numeric format.
  • Non-functional attributes may be explicitly skipped, such as UI formatting. UI numeric meta-data follows the same equivalence criteria as for input/output values (e.g. uimax or uimin). Name and Category equivalence cannot be skipped.

Changes

  • Adds a new isEquivalent method to Element.
  • Adds a new isAttributeEquivalent method for Element and override for ValueElement to allow for value vs string comparisons on the latter.
  • Adds equivalence options class: ElementEquivalanceOptions which can be passed in as an argument to isEquivalent
  • Adds an optional results / feedback class: ElementEquivalenceResult which can be passed in as an argument to isEquivalent and isAttributeEquivalent.

The following equivalence options are available:

  • Floating point format and precision for a float ValueElement. This is the same precision mechanism used for all value<->string conversions including values for code generation and file I/O.
  • The ability to skip a user provided list of attributes. e.g. skipping { xpos, ypos }.
  • Perform raw string compares for values (as operator==) currently does instead of value comparisons for a ValueElement.

Implementation Notes

  • Note that value comparisons convert from string to a concrete runtime type which will remove any
    extraneous string formatting such as leading and trailing spaces, 0 and leading + sign.
  • The the Value's string representation is used to perform the actual comparison allow for support of precision options.

Tests

A new unit test has been added with various numeric variations to test values, ordering, and precision.
The document pair used for testing looks like this:

<materialx version="1.39">
  <input name="input0" type="boolean" value="false">
  <input name="input1" type="color3" value="  1.0,   +2.0,  3.0   ">
  <input name="input2" type="color4" value="1.0,   2.00, 0.3000, -4">
  <input name="input3" type="filename" value="filename1">
  <input name="input4" type="float" uimin="  0.0100 " uimax="  01.0100 " value="  1.2e-10  ">
  <input name="input5" type="float" uimin="  0.0100 " uimax="  01.0100 " value="  00.1000  ">
  <input name="input6" type="integer" value="  12 ">
  <input name="input7" type="matrix33" value="01.0,         2.0,  0000.2310,    01.0,         2.0,  0000.2310, 01.0,         2.0,  0000.2310       ">
  <input name="input8" type="matrix44" value="01.0,         2.0,  0000.2310, 0.100, 01.0,         2.0,  0000.2310, 0.100, 01.0,         2.0,  0000.2310, 0.100, 01.0,         2.0,  0000.2310, 0.100">
  <input name="input9" type="string" value="mystring">
  <input name="input10" type="vector2" value="1.0,   0.012345608">
  <input name="input11" type="vector3" value="  1.0,   +2.0,  3.0   ">
  <input name="input12" type="vector4" value="1.0,   2.00, 0.3000, -4">
</materialx>

and

<materialx version="1.39">
  <input name="input0" type="boolean" value="false">
  <input name="input1" type="color3" value="1, 2, 3">
  <input name="input2" type="color4" value="1, 2, 0.3, -4">
  <input name="input3" type="filename" value="filename1">
  <input name="input4" type="float" value="1.2e-10" uimin="  0.01" uimax="  1.01">
  <input name="input5" type="float" value="0.1" uimin="  0.01" uimax="  1.01">
  <input name="input6" type="integer" value="12">
  <input name="input7" type="matrix33" value="1, 2, 0.231,  1, 2, 0.231,  1, 2, 0.231,  1, 2, 0.231">
  <input name="input8" type="matrix44" value="1, 2, 0.231, 0.1, 1, 2, 0.231, 0.1, 1, 2, 0.231, 0.1, 1, 2, 0.231, 0.1">
  <input name="input9" type="string" value="mystring">
  <input name="input10" type="vector2" value="1, 0.012345611">
  <input name="input11" type="vector3" value="1, 2, 3">
</materialx>

source/MaterialXCore/Element.h Outdated Show resolved Hide resolved
source/MaterialXCore/Element.cpp Outdated Show resolved Hide resolved
source/MaterialXCore/Element.cpp Outdated Show resolved Hide resolved
- Separate out results into option results class argument.
- Add isAttributeEquivalent() to avoid duplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants