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 PathFollow tests, Add PathFollow3D forward test #51372

Merged

Conversation

raulsntos
Copy link
Member

@raulsntos raulsntos commented Aug 7, 2021


NOTE: I've marked this PR ready for review since the CI passes but I'd like to know what to do with the remove point test and if the custom is_equal_approx is acceptable, then I'll squash the commits.

@Paulb23
Copy link
Member

Paulb23 commented Aug 8, 2021

For the SceneTree and RenderingSever, take a look at #50375.

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch 3 times, most recently from 56a8a10 to c7aa737 Compare September 14, 2021 18:23
@raulsntos
Copy link
Member Author

raulsntos commented Sep 14, 2021

The tests are failing because I get Vector3(99.93983, 0.050718, 0) instead of Vector3(100, 0, 0) probably because of float precision or the curve bake quality.

I tried to reduce the bake_interval and even though it gets closer to Vector3(100, 0, 0) it's still not enough. If I reduce it too much the tests crash probably because it runs out of memory.

@akien-mga
Copy link
Member

You can use approx_equal if it's close enough, or compare manually to a big enough epsilon that takes precision into account.

@raulsntos
Copy link
Member Author

I'm using Vector3::is_equal_approx which, unlike Math::is_equal_approx, does not have an overload with a tolerance parameter and therefore uses CMP_EPSILON.

The difference between Vector3(99.93983, 0.050718, 0) and Vector3(100, 0, 0) is not huge but it's not tiny either, so I'm not sure if modifying the tests' precision to pass would be acceptable. Maybe the difference is caused by an underlying issue and we'd be masking it, no?

@akien-mga
Copy link
Member

The difference between Vector3(99.93983, 0.050718, 0) and Vector3(100, 0, 0) is not huge but it's not tiny either, so I'm not sure if modifying the tests' precision to pass would be acceptable. Maybe the difference is caused by an underlying issue and we'd be masking it, no?

Yes, that should be investigated.

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch 2 times, most recently from c2890be to 77c5543 Compare September 17, 2021 11:08
@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch 2 times, most recently from dc92f64 to 7cd48c3 Compare October 7, 2021 14:20
@raulsntos
Copy link
Member Author

raulsntos commented Oct 7, 2021

Yes, that should be investigated.

After investigating I reached the conclusion that the _bake method is at fault here.

The points that are added to the curve are not baked so the cached points go from Vector2(100, 99.9516) to Vector2(95.00677, 100) and when trying to retrieve the point it interpolates between the two which never returns the original point Vector(100, 100).

I've modified the _bake methods for both Curve2D and Curve3D and now retrieving those corner points is more accurate, before the tests failed with an error of ±1 and now they still fail but in fewer asserts and with an error of ±0.0001 which I think is much more acceptable (but it's still not enough for the is_equal_approx method to return true.

@@ -122,15 +128,16 @@ TEST_CASE("[PathFollow2D] Sampling with offset") {
memdelete(path);
}

TEST_CASE("[PathFollow2D] Removal of a point in curve") {
const Ref<Curve2D> &curve = memnew(Curve2D());
TEST_CASE("[SceneTree][PathFollow2D] Removal of a point in curve") {
Copy link
Member Author

@raulsntos raulsntos Oct 7, 2021

Choose a reason for hiding this comment

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

This test won't pass because PathFollow currently does not listen to changes in the curve and AFAIK the PathFollow nodes never had this behavior.

Also, this test uses the unit offset but the PathFollow actually stores the offset. This test assumes that removing the middle point will update the transform to be at the interpolated point between the start and end points because that'd be the new 0.5. However, since PathFollow stored the offset it won't be equivalent to 0.5 anymore.

Same thing in the 3D version.


EDIT: I've commented these tests for now

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from 7cd48c3 to 4ddda01 Compare October 7, 2021 20:57
@raulsntos raulsntos marked this pull request as ready for review October 7, 2021 23:02
@raulsntos raulsntos requested a review from a team as a code owner October 7, 2021 23:02
@raulsntos raulsntos mentioned this pull request Oct 8, 2021
5 tasks
@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch 3 times, most recently from 1628ed6 to f1c1678 Compare December 6, 2021 16:42
@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from f1c1678 to 176052b Compare February 15, 2022 17:52
@reduz
Copy link
Member

reduz commented Jul 30, 2022

Whats the status of this?

@raulsntos
Copy link
Member Author

raulsntos commented Jul 30, 2022

It's done but not sure what to do about the last 2 commits:

When those questions are resolved I have to squash the commits and rebase.

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch 2 times, most recently from 3a980d7 to e5fdd84 Compare September 26, 2022 10:08
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 10, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 14, 2023
@YuriSizov
Copy link
Contributor

This probably needs at least some changes after the recent PathFollow changes regarding forward direction.

@raulsntos
Copy link
Member Author

  • While rebasing I found a bug in PathFollow3D, I opened Clamp PathFollow3D progress when not looping #78280 to fix it. I will rebase this PR after the other one is merged.
  • It seems the tests regarding forward direction fail unless I increase the tolerance even more, but at this point I feel like this might be a bug in PathFollow3D or Curve3D.

@AThousandShips AThousandShips modified the milestones: 4.2, 4.3 Oct 27, 2023
@Geometror
Copy link
Member

Could you do a quick rebase?

path->set_curve(curve);
const PathFollow2D *path_follow_2d = memnew(PathFollow2D);
path->add_child(path_follow_2d);
// TEST_CASE("[SceneTree][PathFollow2D] Removal of a point in curve") {
Copy link
Member

@AThousandShips AThousandShips Jul 12, 2024

Choose a reason for hiding this comment

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

Suggested change
// TEST_CASE("[SceneTree][PathFollow2D] Removal of a point in curve") {
//TEST_CASE("[SceneTree][PathFollow2D] Removal of a point in curve") {

No space before commented out code, for all

I'd suggest using a block comment though and explaining why the test is inactive

Copy link
Member Author

Choose a reason for hiding this comment

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

I've commented these tests because of #51372 (comment). I don't think the behavior these tests intended to test was ever implemented in PathFollow{2D,3D} so we may want to remove these tests instead.

Copy link
Member

@Geometror Geometror Jul 14, 2024

Choose a reason for hiding this comment

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

With the following adjustments it passes. We need to do the same immediate update as for the other test cases, and after the curve length has changed, the absolute progress value is outdated (and doesn't represent the ratio of 0.5 anymore).

	path_follow_3d->set_progress_ratio(0.5);
	path_follow_3d->update_transform(true);
	CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin()));

	curve->remove_point(1);

	path_follow_3d->set_progress_ratio(0.5);
	path_follow_3d->update_transform(true);
	CHECK_MESSAGE(
			is_equal_approx(Vector3(50, 50, 0), path_follow_3d->get_transform().get_origin()),
			"Path follow's position should be updated after removing a point from the curve");

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from e5fdd84 to 22d0086 Compare July 12, 2024 18:41
@raulsntos
Copy link
Member Author

Rebased.

Also added path_follow_3d->update_transform(true) because #80233 made the transform update deferred.

It seems #80233 also broke the forward vector test and I'm not sure if the new behavior is correct. I also get a bunch of ERROR: The target vector and up vector can't be parallel to each other.

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from 22d0086 to 40ecac6 Compare July 14, 2024 19:03
Copy link
Member

@Geometror Geometror left a comment

Choose a reason for hiding this comment

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

Looks good to me!
We could refactor the checks to use doctest::Approx, but I'm working on a better way to integrate Godot's types with doctest, so I guess it's fine to merge this now.

@akien-mga
Copy link
Member

Seems good to me too. Let's squash and merge, and fine tune things in follow up PRs.

@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from 40ecac6 to 871a451 Compare July 20, 2024 17:06
@raulsntos raulsntos force-pushed the path-follow-3d-forward-tests branch from 871a451 to c3a054f Compare July 20, 2024 17:09
@akien-mga akien-mga merged commit ab5ae8a into godotengine:master Jul 20, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

@raulsntos raulsntos deleted the path-follow-3d-forward-tests branch July 21, 2024 02:28
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.

8 participants