-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add Vector2.from_angle() method #48237
Conversation
af24c90
to
075fb36
Compare
075fb36
to
7eeb450
Compare
7eeb450
to
5c1bcf9
Compare
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.
Writing tests is not currently required (unlike documentation), but highly recommended. See also godotengine/godot-proposals#1586.
Are there any contribution guides in the documentation to make this happen? I understand that C# is officially supported language, but I'm not sure if it's required for contributors to implement those methods currently. This question also applies to VisualScript, GDNative etc... As for myself, I'm not using C# at all. Does that mean my own contribution to core would be blocked because of lack of C# knowledge? |
@Xrayez It's not necessarily a blocker, but if it's not done here, someone will have to do it later for consistency. It's easier to just do it everywhere at once. If you want to update the documentation, that would be great. As for VisualScript and GDNative, they get access to methods via |
5c1bcf9
to
5e82996
Compare
Most of the time (if not always), I'd like to test a feature myself before doing changes. If I don't know how to test something, I'd rather avoid doing those changes, unless someone else is willing to test those changes before merging, otherwise this could lead to broken code. So, IMO, it's better that someone else does those changes in a separate PR who know better. I'd just make it clear that you're willing to test the implementation if you do want to see them in any PR, not just "Missing C# version". I'm just providing my feedback on the review process, sorry. 🙂 |
5e82996
to
0e9e17e
Compare
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.
The idea makes sense, but what you are providing here is simply half of of what would be needed to allow building any vector from polar coordinates. Consequently, I think it would be more feature-complete to rename the function to |
The length argument wouldn't be very useful. It's a unit vector, so you can just multiply it. Also the function was never intended to have anything to do with polar coordinates (which very few people use). |
I mean, at least it looks like something that has a mathematical sense. The I think that, if we implement the possibility to create a vector from an angle, then that's basically equivalent to building a vector from it's polar coordinates (returned by the angle() and lenght() function the other way around). It makes the API more consistent and easier to search. |
We don't need 3 points. The origin and X axis are implied. When it comes to polar coordinates, this is just something that is super easy to do with existing methods (angle & length, and from_angle & multiply), while simultaneously being a very niche use case for games, so it doesn't make sense to have APIs for it. |
Yep, that's basically the issue here. As explicit naming is better than implicit naming, I think |
Compare: Vector2.from_angle(radians) * length
Vector2.from_polar(radians, length) I really do think it's not worth being explicit here. I'm for complementing @groud your opinion on this is basically the complete opposite of what you said in #43103 (comment):
The |
Alternative solution could be:
if really needed. Due to this, I've even considered to do the same thing in goostengine/goost#65, where using
Being feature-complete can mean anything to a user. For instance, are we going to implement other conversion methods such cylindrical coordinate system as well? That would certainly make those features complete, but I'm afraid those methods could bloat That's why I'm suggesting that we implement coordinate system conversion methods in classes such as |
Surprise! Looks like I've found existing methods which do polar to cartesian conversion and vice versa, I had no idea we have those functions already, and I'm not sure whether you were aware of them either... 054a2ac. The only problem is that That said, since we already have those functions, I humbly think that adding Again, quoting KoBeWi in this PR:
Cross-referencing those methods in the documentation should be worth it, still. |
0e9e17e
to
4ed79ad
Compare
ready to merge when passes CI. Do not forget to remove polar/cartesian functions from variant_utility in a subsequent PR, as they are redundant and a confusing API for Godot users compared to this one. |
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.
Works in my testing and looks good except for one style issue.
4ed79ad
to
3f3739c
Compare
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.
Looks good and works in my testing. I haven't tested the C# version but it looks good.
Thanks! |
Resolves 2D part of godotengine/godot-proposals#1719 (someone wanted Vector3 equivalent, but it probably requires some more math so meh)
With this you can do
and it will return
Vector2(0, 1)
(or at least it would if static functions weren't bugged, see #48238)