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

Proposal-1778: Updating Transform.rotated() docs and test cases. #43694

Closed

Conversation

AlexanderPruss
Copy link
Contributor

@AlexanderPruss AlexanderPruss commented Nov 19, 2020

For proposal 1778: godotengine/godot-proposals#1788

Following the discussion in #43601, it was decided to just adjust the documentation of Transform.rotated() instead of adding a new function.

If this is approved, we can probably close the previous PR and the linked proposal.

Comment on lines 60 to 65
Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));

// Make sure that the rotated transform isn't sharing references with the original transform.
REQUIRE(&rotated_transform.basis != &transform.basis);
REQUIRE(&rotated_transform.origin != &transform.origin);
Copy link
Contributor

@Xrayez Xrayez Nov 19, 2020

Choose a reason for hiding this comment

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

While the first REQUIRE is reasonable, the successive assertions depend on the previous one. Better do this:

Suggested change
Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));
// Make sure that the rotated transform isn't sharing references with the original transform.
REQUIRE(&rotated_transform.basis != &transform.basis);
REQUIRE(&rotated_transform.origin != &transform.origin);
Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));
// Make sure that the rotated transform isn't sharing references with the original transform.
CHECK(&rotated_transform.basis != &transform.basis);
CHECK(&rotated_transform.origin != &transform.origin);

This way, both "basis" and "origin" will be tested (without immediately exiting the test case if the first one fails).

Same for the test case below.

Also, not sure about referencing with &, is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reasonable, I'll change the latter REQUIREs to CHECKs.

As far as referencing with &, this may just be paranoia due to my lack of C++ experience. But technically the == operator can be overloaded, right?

Copy link
Contributor

@Xrayez Xrayez Nov 19, 2020

Choose a reason for hiding this comment

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

Looking more closely now, in this case & will take a pointer, so this will always "falsely" succeed because this compares pointers rather than values, because as far as I know rotated_transform is a modified copy of transform, so & is not suitable in this case.

So this should rather be:

Suggested change
Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));
// Make sure that the rotated transform isn't sharing references with the original transform.
REQUIRE(&rotated_transform.basis != &transform.basis);
REQUIRE(&rotated_transform.origin != &transform.origin);
Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));
// Make sure that the rotated transform isn't sharing references with the original transform.
CHECK(rotated_transform.basis != transform.basis);
CHECK(rotated_transform.origin != transform.origin);

But technically the == operator can be overloaded, right?

Yes, this is done for a lot of existing core types in Godot, so usually you don't have to worry about this and just do equality checks. If those fail due to floating point accumulation, is_equal_approx is also implemented for built-in types.

Copy link
Contributor Author

@AlexanderPruss AlexanderPruss Nov 22, 2020

Choose a reason for hiding this comment

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

I think the pointer memory addresses are what I wanted to check; I thought I could make sure that transform.rotated() returns an object that doesn't share important references with the old object. I.e. that the following is the case -

Transform transform = Transform();
Transform rotated = transform.rotated(...);
transform.origin.x += 1;
//rotated's origin should still be on the origin, not on (1,0,0)

But that's maybe not necessary, I think I'll just remove those assertions. Though in general, as a new Godot user, I'm not always clear on whether a function will modify the existing object or return a new object.

Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

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

This needs to be rebased because Transform was renamed to Transform3D.

@@ -168,7 +168,8 @@
<argument index="1" name="phi" type="float">
</argument>
<description>
Rotates the transform around the given axis by the given angle (in radians), using matrix multiplication. The axis must be a normalized vector.
Returns a new transform created by rotating around the given axis by the given angle (in radians). The axis must be a normalized vector.
The axis of rotation goes through (0, 0, 0) in local space, so the transform's origin will also rotate. If you want to change the transform's orientation while keeping it in place, consider calling [code]rotated[/code] on the transform's basis instead.
Copy link
Member

Choose a reason for hiding this comment

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

While technically this should be implied from the current text, for clarity's sake we should mention "relative to the parent" somewhere here.

expected.basis.set_axis(2, Vector3(0, 0, -1));

Transform rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
REQUIRE(rotated_transform.is_equal_approx(expected));
Copy link
Member

@aaronfranke aaronfranke Aug 29, 2021

Choose a reason for hiding this comment

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

Most of the code in the test cases is very nice. But two things:

  • These need to go in a test_transform_3d.h file.
  • Why are you using REQUIRE when the other tests use CHECK_MESSAGE?

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'll move the code over into a new file and make sure it compiles after the renamings, and change REQUIRE to CHECK_MESSAGE. I'll keep the assertion the same.

YeldhamDev and others added 22 commits September 23, 2021 21:32
`#pragma once` was used in a few files, yet we settled on using
traditional include guards instead.

The PooledList template comment was also moved to allow editors
such as Visual Studio Code to display the comment when hovering
PooledList.

`app.h` was renamed to `app_uwp.h` to be less generic for the
include guard.
Replace `#pragma once` by traditional include guards for consistency
New contributors added to AUTHORS:
@AnilBK, @Jummit

Thanks to all contributors and donors for making Godot possible!
Fix incorrect offsets of tooltip content in `CodeEdit`
@AlexanderPruss
Copy link
Contributor Author

After the rebase this PR's commit history has suddenly gotten a bit bigger. Oh dear. I'll have to see what has to happen to fix this, but I won't get to it tonight I'm afraid.

Don't rebase while on sick leave, lesson learned

@aaronfranke
Copy link
Member

It's because you didn't do a rebase, you did a merge. Here are instructions on how to rebase:

https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#the-interactive-rebase

@aaronfranke aaronfranke removed request for a team October 1, 2021 16:58
@Calinou
Copy link
Member

Calinou commented Dec 8, 2021

@AlexanderPruss Could you look into rebasing this pull request to make sure only 2a920a2 (#43694) is included? If this proves to be too difficult, you can recreate a new pull request.

@Calinou
Copy link
Member

Calinou commented May 13, 2022

Superseded by #61008 and #61013. Thanks for the contribution nonetheless!

@Calinou Calinou closed this May 13, 2022
@Calinou Calinou removed request for a team May 13, 2022 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.