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

Added component-wise min and max functions for vectors #72316

Merged
merged 1 commit into from
Feb 11, 2023

Conversation

0xafbf
Copy link
Contributor

@0xafbf 0xafbf commented Jan 29, 2023

Implements changes needed to solve this issue: #45320

EDIT:
This PR doesn't solve the issue mentioned above. This PR only implements the min/max functions for the vector classes in the cpp side, but doesn't change the way min/max works in GDScript. That change may come with another PR at a later time.

@0xafbf 0xafbf requested review from a team as code owners January 29, 2023 16:47
@MewPurPur
Copy link
Contributor

MewPurPur commented Jan 29, 2023

LGTM (just need to fix the static checks)

Not sure about the way it's done in variant though, I'll take a closer look later.

Would be good to add tests for the new methods

@0xafbf 0xafbf requested a review from a team as a code owner January 29, 2023 17:36
@0xafbf 0xafbf force-pushed the component-wise-minmax branch 2 times, most recently from a6dd4f6 to 7c73a92 Compare January 29, 2023 17:46
@Calinou Calinou added this to the 4.0 milestone Jan 29, 2023
@0xafbf
Copy link
Contributor Author

0xafbf commented Jan 29, 2023

I think that I got the changes right this time, let me know if you think I should make any change in the variant code.

@MewPurPur
Copy link
Contributor

MewPurPur commented Jan 29, 2023

Better but still needs work. Now they fail if you pass a combination of ints and floats. Not sure what the best way to fix this would be, maybe someone more experienced can help.

Variant::evaluate(Variant::OP_LESS, base, *p_args[i], ret, valid);
if (!valid) {
const Variant &x = *p_args[i];
if (x.get_type() != base_type) {
Copy link
Contributor

@MewPurPur MewPurPur Jan 29, 2023

Choose a reason for hiding this comment

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

A special case in this condition for ints and floats would be sufficient for now. (Likewise for min())

@groud
Copy link
Member

groud commented Jan 30, 2023

As you have seen on the issue you linked, the asked feature is controversial. Several users (including myself) are not happy with the fact max(A,B) would be able to return something different from A or B.

According to a discussion we had with other maintainers, we are more leaning towards removing this helper for values that are not basic types like int, float, bool (basically everywhere the current behavior can confuse users).

We however believe the component-wise max/min could be exposed, either as a method of Vector2/3 (like, v_A.max(v_B)) or as some static method Vector2.max(v_A, v_B). So I guess part of this PR could be kept. We might ask for a rename of the method though.

@MewPurPur
Copy link
Contributor

MewPurPur commented Jan 30, 2023

a method of Vector2/3 (like, v_A.max(v_B))

We got that already, but only for Vector2{i}, and not in Vector3/4. Though this PR implemented it for the remaining vector types.

I also want bring up that in GlobalScope methods like round(), sign(), snapped() and others, where the notion only holds for floats/ints, we just call the vector function with the same name. Only here, min and max are vararg, so there's a minor difference I guess.

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.

I think for now it's fine to implement the component-wise min/man methods for Vector3(i) and Vector4(i), but whether the global min/max functions should operate component-wise is still controversial (see comments in #45320). Could you strip the changes to the global functions from this PR?

@akien-mga akien-mga merged commit 8f46656 into godotengine:master Feb 11, 2023
@akien-mga
Copy link
Member

Thanks!

@Eclextic
Copy link

Eclextic commented Jun 3, 2024

This has yet to be implemented for the GDScript side... Any progress?

@AThousandShips
Copy link
Member

No it has been implemented for scripting a month ago:

@Eclextic
Copy link

Eclextic commented Jun 4, 2024

No it has been implemented for scripting a month ago:

After looking a bit further into it, it seems that it was only implemented for Godot Latest/4.3. Any plans to cherry-pick this change for Godot 4.2 and lower?

@MewPurPur
Copy link
Contributor

MewPurPur commented Jun 4, 2024

No, this is a feature and not a patch.

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