-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
New functions : Vector2.angle and Vector2.angle_rad and the tests and documentation needed #3216
Conversation
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’d rather see these implemented as read-only attributes vs methods. There’s also a discussion to be had about how it should work for Vector3
because we should have parity in features between the two as much as possible
Ok, I'll try to modify my code and create attributes and not methods and wait for how the Vector3 features should work. |
@@ -34,6 +34,8 @@ | |||
#define DOC_MATH_VECTOR2_ANGLETO "angle_to(Vector2, /) -> float\ncalculates the angle to a given vector in degrees." | |||
#define DOC_MATH_VECTOR2_ASPOLAR "as_polar() -> (r, phi)\nreturns a tuple with radial distance and azimuthal angle." | |||
#define DOC_MATH_VECTOR2_FROMPOLAR "from_polar((r, phi), /) -> None\nSets x and y from a polar coordinates tuple." | |||
#define DOC_MATH_VECTOR2_ANGLERAD "angle_rad() -> float\nreturns the angle of the vector in radians relative to the positive X-axis." |
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 see that this macros have been created, but the doc RST file has not been edited, making me believe you added them manually. To add a new feature you should edit the math.rst found somewhere under the docs folder and when you added proper documentation run the command py dev.py docs
(or py -m buildconfig docs
) that will generate them automatically.
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.
Sorry, I'm new so I didn't know that. I'm going to fix that. But I don't understand what this macros is doing if it's not to create a doc.
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.
However, with @oddbookworm comment. Do you think I should update my code and make a new PR for this issue or not ?
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.
@AntoineMamou for the docs header, did you not read the first line of the file? Where it says it's autogenerated from the actual docs?
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.
Which part of my comment do you want to push off to another PR?
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.
Sorry, I didn't see it when I make the PR
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 was just thinking about the attributes angle
and angle_rad
else if (angle_deg <= -180) { | ||
angle_deg += 360; | ||
} | ||
return Py_BuildValue("d", angle_deg); |
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.
Why have you used Py_BuildValue here and PyFloat_FromDouble in the other function? I feel like they should both use the latter. also, I feel like there are a few unnecessary declarations that could be avoided reducing a bit the lines, if that doesn't decrease readability too much (but formatting the code might bring it back)
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.
Yes you are right. Because I begin in this project, I saw that there is these two function and I try it both. Since it works, I didn't see the problem but if both should use PyFloat_FromDouble, it's ok.
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.
Are these changes relevant to this pr?
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.
Hello,
No, not at all. This was a mistake I made because I was working on an other issue at that time. By the way, this PR should be close I think because it's this PR that is link to the issue of .angle
and .angle_rad
: #3222
Closing this PR in favour of the newer PR #3222 made by OP |
As explains in this issue : #3195, I added the two functions
angle
andangle_rad
in the module Vector2.angle_rad
: Returns the vector’s angle in radians relative to the positive x-axis.angle
: Returns the angle in degrees, normalized to (180,180].I also created tests and documentation for these two functions