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

Reimplement slerp on Vector3 #316

Merged
merged 1 commit into from
Jun 28, 2023
Merged

Conversation

T4rmyn
Copy link
Contributor

@T4rmyn T4rmyn commented Jun 19, 2023

Reimplemented the slerp method on Vector3 with the addition of documentation and several tests on it. Addresses part of #310 to (possibly?) complete Vector3 methods (leaving the lacking documentations aside).

A notable change from the original Godot calculations is just directly using .normalized() on axis for unit_axis than manually doing it by axis / axis_length_sq.sqrt() on line 314.

@Bromeon Bromeon added feature Adds functionality to the library c: core Core components labels Jun 19, 2023
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-316

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Thanks a lot! Just minor comments.

Here's the link to your method documentation, by the way 🙂

Comment on lines 300 to 302
/// Length is also interpolated in the case that the input vectors have different lengths. If both
/// input vectors have zero length or are collinear to each other, the method instead behaves like
/// and directly calls [`Vector3::lerp`].
Copy link
Member

Choose a reason for hiding this comment

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

The "directly calls" is an implementation detail (and makes the sentence more complicated to read), no need to mention that.

Instead, it would be nice if you added such comments in the code itself, e.g. in each if branch, to explain why this is equivalent to lerp.

godot-core/src/builtin/vectors/vector3.rs Outdated Show resolved Hide resolved
godot-core/src/builtin/vectors/vector3.rs Outdated Show resolved Hide resolved
@T4rmyn
Copy link
Contributor Author

T4rmyn commented Jun 19, 2023

This update was an attempt at explaining the if statements (and the other fixes) and I hope it was sufficient.

I wonder though, could the line 315 if check be moved one statement before to instead check directly for a zero Vector3 since only that can produce a length of zero (right?), saving the length_squared() operation for after the check. Also that would make axis_length_sq obsolete I think?

@T4rmyn T4rmyn requested a review from Bromeon June 19, 2023 18:04
@Bromeon
Copy link
Member

Bromeon commented Jun 19, 2023

That's correct, you could do

if axis == Vector3::ZERO {

Thanks for the comments!

@Bromeon
Copy link
Member

Bromeon commented Jun 19, 2023

Regarding the test cases, are they from Godot?

Otherwise, one thing we could do is see if Vector3::slerp and InnerVector3::slerp yield approximately the same results. This would need #[itest] though.

@T4rmyn
Copy link
Contributor Author

T4rmyn commented Jun 19, 2023

No, it's not. I will replace it with the Godot ones then. It's also getting really late so expect it tomorrow.

@Bromeon
Copy link
Member

Bromeon commented Jun 19, 2023

No rush here! 😊

I also think the tests are fine as-is. We might automate some integration-testing against Godot in the future, so it can still be good to have some unit tests. Those also make ensure that the engine is not required to run.

@T4rmyn
Copy link
Contributor Author

T4rmyn commented Jun 20, 2023

Uh oh, I think I found a difference in the checks by the repo's clippy and the local ./check.sh clippy. When I ran ./check.sh clippy it showed the previous force push as without flaws, but the repo one found the float has excessive precision.

When I ran the repo clippy command locally however, it also found the excessive precision issue.

For reference, the repo clippy command is:
cargo clippy --all-targets $GDEXT_FEATURES -- \ -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \ -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings.

While the ./check.sh one is:
cargo clippy --no-default-features -- -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings.

If this is a real issue I could open an issue about it (pun not intended).

@T4rmyn
Copy link
Contributor Author

T4rmyn commented Jun 20, 2023

On another note, I ported the Godot tests :D.

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Thanks for the note about clippy, I can adjust the local check.sh to match CI. In case of doubt, CI is always the source of truth.

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 28, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit fe1f1df into godot-rust:master Jun 28, 2023
@T4rmyn T4rmyn deleted the slerp_vector3 branch June 28, 2023 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Core components feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants