-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Prevent floats from being represented in scientific notation in expression animation strings #4189
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
Prevent floats from being represented in scientific notation in expression animation strings #4189
Conversation
Thanks arcadiogarcia for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
Asked @tannergooding about formatting options, he mentioned there's @michael-hawker These expression extensions are from before my time in the Toolkit so I don't know the story behind then, do you know whether that API wasn't being used on purpose, maybe to work around some other limitation or something, or whether it might simply have been an oversight? Anyway I think it might be worth exploring using this other approach, as it could likely be more reliable, precise and definitely more efficient 😄 |
You can also just use
|
@Sergio0694 these APIs were created to create a better code-based way to create the composition expression animation strings required for composition animations which are connected to other properties of object. Our Toolkit docs on the existing feature: https://docs.microsoft.com/en-us/windows/communitytoolkit/animations/expressions |
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.
This extension method solves an immediate need. An alternate approach can be implemented at a later date.
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.
As per previous discussion, we agreed that this fix is fine given that the scenario was just broken before this PR anyway, and we might always rework/optimize this in the future. I like that the happy path of the new extension is just the previous ToString()
with an extra IndexOf
(negligible), but without any additional noteworthy work there. The fallback path is not ideal as Tanner mentioned too, but then again it does unblock folks using this today and is definitely better than the current situation. Looks good! 😄
Ugh, we didn't notice that this PR had duplicate commits with #4183 here: c4f6009 with a removal here: 7c205fe That's messed with the history and screwed up the other PR now. FYI @arcadiogarcia @RosarioPulella @XAML-Knight in these cases if you've accidently crossed the streams, don't make a revert commit (they're evil). Instead, create the new branch for the 2nd feature and interactive rebase on top of it instead to separate out the commits of the two features, or with the copied branch reset it back to the main common starting point, clean-up the code and make a new independent commit. |
@michael-hawker Oops my bad, I'm too used to squash on merge. Will fix the other PR's branch. |
@arcadiogarcia yeah we normally don't squash PRs to maintain history and commit records; we also changed recently to streamline not having to constantly update from the |
Fixes
PR Type
What kind of change does this PR introduce?
Bugfix
What is the current behavior?
Currently we use the default ToString() representation of floats to serialize the values in expression nodes into the expression animation string. When the values are too small or too large, .net uses scientific notation, which is not recognized by the composition API. E.g.
will throw
What is the new behavior?
I did some research and couldn't find any format parameter that would prevent ToString from sometimes using scientific notation (which I find very surprising, if someone knows of a built in way to accomplish this please leave a comment). A new extension method that always returns non-scientific notation representation of floats, and is used in the relevant GetValue() calls.
PR Checklist
Please check if your PR fulfills the following requirements:
Other information