Check if Vector_3 is assigned #6045
Replies: 7 comments 4 replies
-
You cannot check. We had a discussion (or even github issue?) about initializing with NaN to make debugging easier, but didnt conclude. |
Beta Was this translation helpful? Give feedback.
-
There is nothing general, in C++, that can tell you if a variable was initialized or not. If that is important for you, then use special class templates |
Beta Was this translation helpful? Give feedback.
-
Thank you @afabri and @lrineau I will use a sum of coordinates as a check, it works fine for my current case, as they are initial all zeros. Thank you for your response. |
Beta Was this translation helpful? Give feedback.
-
@lrineau Thank you for pointing this out, now I understand why I had plenty of random errors that I did not understood. Another question I have is also a beginner level. |
Beta Was this translation helpful? Give feedback.
-
I checked again this:
And this produces true; |
Beta Was this translation helpful? Give feedback.
-
There is nothing that guarantees that an non-initialized CGAL object will have its coordinates zeroed, and that is for efficiency reasons: the default-constructor leaves the coordinates uninitialized. As I said, if it really matters for you to detect when a variable is left uninitialized, then you need to:
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a simple question.
How can I check if a
CGAL_Kernel::Vector_3
is assigned?For example I declare variable (first case)
CGAL_Kernel::Vector_3 v;
and like this (second case):
CGAL_Kernel::Vector_3 v(0,0,1);
Is there any way to know if a user initialized the object or not?
In the first case the return value would be false, in the second true.
Is there a shorter way that doing this?
bool isValid = ((v.x()+v.y()+v.z())<0.0001);
Beta Was this translation helpful? Give feedback.
All reactions