-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Proposal-1778: Updating Transform.rotated() docs and test cases. #43694
Conversation
tests/test_math.h
Outdated
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); |
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.
While the first REQUIRE
is reasonable, the successive assertions depend on the previous one. Better do this:
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?
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.
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?
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.
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:
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.
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.
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.
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.
This needs to be rebased because Transform was renamed to Transform3D.
doc/classes/Transform.xml
Outdated
@@ -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. |
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.
While technically this should be implied from the current text, for clarity's sake we should mention "relative to the parent" somewhere here.
tests/test_math.h
Outdated
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)); |
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.
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 useCHECK_MESSAGE
?
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.
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.
`#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
Fix incorrect offsets of tooltip content in `CodeEdit`
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 |
It's because you didn't do a rebase, you did a merge. Here are instructions on how to rebase: |
@AlexanderPruss Could you look into rebasing this pull request to make sure only |
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.