-
Notifications
You must be signed in to change notification settings - Fork 67
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 Vector(2|3|4)<T>::NaN to easily create invalid vectors #222
Conversation
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
Codecov Report
@@ Coverage Diff @@
## ign-math6 #222 +/- ##
=============================================
+ Coverage 99.22% 99.39% +0.17%
=============================================
Files 66 66
Lines 6162 6162
=============================================
+ Hits 6114 6125 +11
+ Misses 48 37 -11
Continue to review full report at Codecov.
|
@chapulina , do you want to try adding the |
Signed-off-by: Louise Poubel <[email protected]>
Done in 1233218 |
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.
Looks good. Although I'd argue std::optional
is more convenient than this for representing uninitialized values. For one, when checking if a variable is nan, you can't compare it against Vector::NaN
directly. You'd have to use IsFinite
, which I don't think would be immediately apparent to users. Also, IsFinite
returns false if any of the members are nan
, or inf
, so it could potentially lead to bugs if Vector::NaN
is used to represent uninitialized vectors.
Signed-off-by: Louise Poubel <[email protected]>
Thanks for the review, @azeey, I addressed your comments in 564de1c. I also appreciate the feedback on the motivation for this PR. The specific use case that motivated this was a vector whose value keeps changing, and at times I actually needed to fill it with NaNs. But at other times I've also needed to "flag" that a vector's value was invalid temporarily, and I think it could be useful there as well, but I agree that there are multiple ways of going about this. |
Signed-off-by: Louise Poubel <[email protected]> Signed-off-by: Arjo Chakravarty <[email protected]>
🎉 New feature
Summary
I often need to create invalid vectors to indicate that something isn't initialized or became invalid. There are ways of expressing this with null pointers or
std::nullopt
, but using NaNs makes it convenient to do without involving the creation and destruction of new vectors.This also plays well with the existing
IsFinite
andCorrect
functions. Note that none of this applies to integer types.Test it
Take a look at the added tests.
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge
🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸