-
Notifications
You must be signed in to change notification settings - Fork 353
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 utility to "normalize" numeric string values on a Document #1988
Conversation
- Use in Document new value normalization interface: Document.normalizeValueStrings() - Add in unit tests for each.
doc->normalizeValueStrings(); | ||
doc2->normalizeValueStrings(); | ||
|
||
// Note: do not check doc2 == doc as that is a pointer comparison |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is a way to allow pointer comparison to be a value comparison, but left a note here since I ran into it.
- Simplify logic. - Remove precision clamping. - Add JS wrapper.
- Add integer, matrix support - Move type into more generic method. - Update tests.
- Do not remove trailing 0s for scientific notation. This just checks for the 'e' character after stripping leading and trailing spaces and leading zeros. - Skip empty tokens, though this is invalid for MaterialX.
@kwokcb As a thought experiment, it seems worthwhile to consider the following line from the OpenPBR definition:
After the proposed normalization logic, would it become the following?
If so, then I wonder if this approach will really achieve our goal of normalizing numeric value strings across a document, allowing for more straightforward comparisons. In a sense, the transformation above would make the definition of OpenPBR less consistent rather than more so! |
If it's desired then a I don't think this utility should be used to enforce format consistency as it's intent was for comparison consistency and "normalization" semantics were added . That said, the above can be done but is basically preserving a 1 decimal place precision format when none is required. |
@kwokcb In this case, it's not the choice of formatting conventions that I'm thinking of, but rather that these conventions aren't being applied consistently across the document. As a user, it would seem very surprising that normalization would be applied to the I wonder if we may be pursuing the wrong approach here, and it may be worthwhile to go back to the initial motivation for this proposed feature. If the formatting of numeric strings is changing in a roundtrip of MaterialX documents through USD, is there potentially some way to preserve this formatting in the interchange steps, rather than attempting to apply a standardized string formatting after the fact? |
value = valueElemen.getValue()
valueToCompare = value.getValueString()
@ld-kerley and @jstone-lucasfilm let me know your thoughts. |
In general I'm less of a fan of having to mutate the document to perform a comparison on it. I like the idea of having explicit some sort of comparison function for all the MaterialX elements, and that comparison function accepting arguments to control the criteria for comparison. This could account for the difference between "these two documents are going to render the same" vs "these two documents are going to present the same UI", and potentially also allow us to provide "these two documents are within a specified floating point tolerance of each other" by providing an error threshold. |
Yeah, I was never expecting that the document would ever get changed. I thought this was strictly to be used as a way to check "are these two values the same" when values are expressed as strings without introducing potential floating point conversion errors. |
Earlier in this discussion, I recall a suggestion to add an If we took the MaterialX/source/MaterialXCore/Types.h Line 410 in 18c06ea
|
This sounds good as we've basically come full circle back :). I'd just suggest closing this PR and suggest
|
That approach sounds good to me, @kwokcb, and thanks for working through this tricky set of issues with us! :) |
A new PR is up ##2003. I will leave this for the time being if a comparison is needed for testing. |
Resolution
Fixes: #1981
Allow for a user to "normalize" numeric string values on a document. This allows for 2 documents which may have differing formatting for these values to be comparable for equivalency if both are "normalized" before the comparison.
Changes
normalizeValueString()
. This supports all numeric types. For integers only leading and trailing spaces are removed. All vector / matrix values are separated using this string: ", "Document.normalizeValueStrings()