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

Fix what appears to be a copy/paste redundant code problem. Issue #5733 #5734

Merged
merged 3 commits into from
Feb 6, 2020
Merged

Conversation

JTrantow
Copy link
Contributor

#5733 Change second conditional to test values_ir.size().

    if ((values_rtd.size() == 0) || (values_ir.size() == 0))

Also correct some casting and replace auto with the exact types where appropriate. Why use auto's when the exact type is known at this level?
The coding distinctions between float and double don't seem very tight. Looks like floats would work for most of this.

Fix some casting issues. Looks like quite a bit of double vs float slop in this file.
@dorodnic
Copy link
Contributor

Hi @JTrantow
Thank you for the pull-requests!

@@ -103,7 +103,7 @@ namespace librealsense
return val == 0;
}), values_ir.end());

if (values_rtd.size() == 0 || values_rtd.size() == 0)
if ((values_rtd.size() == 0) || (values_ir.size() == 0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra ()?
Using .empty() instead of the comparison to 0 would be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on using .empty() instead and dropping the "extra ()".

I updated my forked branch. What else do I need to do to update the PR?

z2rtd(vertices, rtd.data(), intrinsics, options.baseline);
double rtd_zo_value;
z2rtd(vertices, rtd.data(), intrinsics, int(options.baseline));
double rtd_zo_value; // \\todo Not sure why try_get_zo_rtd_ir_point_values() returns a double and detect_zero_order() uses a float. Which is best representation?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably change the zo_value argument (line 118) to double. It should resolve all the warnings about conversions, and make the explicit conversion in line 155 unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in my forked branch. What's the next step to closing this out?
I'll use the github web page as email replies don't appear to keep the message chain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked your changes and everything's fine, just please remove this todo comment and we're good :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed todo comment and an unnecessary float cast. Also changed values.reserve((patch_r + 2ULL) (patch_r + 2ULL)) so the '+' and '' don't give precision warning messages.
Final changes are pushed. So if these are accepted this PR and Issue#5733 can be closed.

@JTrantow
Copy link
Contributor Author

JTrantow commented Jan 29, 2020 via email

@JTrantow
Copy link
Contributor Author

JTrantow commented Jan 29, 2020 via email

@neilyoung
Copy link
Contributor

Might be unrelated, but since I lately stumbled across the same question "float" or "double" and just used "float" in the hope, it would be more precise - I was wrong. It turned out, that "float" (especially in C++ realsense environment) renders a 4 byte value. It took me a while to find this as a major difference to my well working python script: C was not precise. I changed all float to double and it worked.

@JTrantow
Copy link
Contributor Author

JTrantow commented Jan 29, 2020 via email

Use value_rtd.empty() suggestion instead of (values_rtd.size() == 0).
Declare zo_value as double. Use doubles throughout detect_zero_order().
Added intialializers for resolutions_depth and read_baseline.
@maloel
Copy link
Collaborator

maloel commented Jan 30, 2020

The "extra ()" come from my background in embedded systems. See https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/general-rules/parentheses

I agree with the reasoning there but only up to a point. "When in doubt" is the key, and so I prefer readability when it's fairly obvious. If you mix && and ||, I can maybe see the point but otherwise, KISS works best.

Removed an unnecssary float cast.
Use +2ULL in the values.reserve((patch_r + 2UL) *(patch_r + 2UL)) line. This promotes each operand to a unsigned long long which matches the size_t used by reserved() and avoids compiler warnings.
Copy link
Collaborator

@maloel maloel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @JTrantow

@JTrantow JTrantow closed this Jan 30, 2020
@maloel
Copy link
Collaborator

maloel commented Feb 3, 2020

@JTrantow I think you closed this by mistake...

@maloel maloel reopened this Feb 3, 2020
@dorodnic dorodnic merged commit 1681e6d into IntelRealSense:development Feb 6, 2020
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.

4 participants