-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Changes from all commits
1932b82
49dbee5
969cdce
1f69517
e0d7289
9eb4b61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2499,6 +2499,30 @@ vector2_from_polar(pgVector *self, PyObject *args) | |
|
||
Py_RETURN_NONE; | ||
} | ||
|
||
static PyObject * | ||
vector2_angle_rad(pgVector *self, PyObject *_null) | ||
{ | ||
double angle_rad; | ||
angle_rad = atan2(self->coords[1], self->coords[0]); | ||
return PyFloat_FromDouble(angle_rad); | ||
} | ||
|
||
static PyObject * | ||
vector2_angle(pgVector *self, PyObject *_null) | ||
{ | ||
double angle_rad = atan2(self->coords[1], self->coords[0]); | ||
double angle_deg = RAD2DEG(angle_rad); | ||
|
||
if (angle_deg > 180) { | ||
angle_deg -= 360; | ||
} | ||
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 commentThe 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 commentThe 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. |
||
} | ||
|
||
static PyObject * | ||
vector_getsafepickle(pgRectObject *self, void *_null) | ||
{ | ||
|
@@ -2566,6 +2590,9 @@ static PyMethodDef vector2_methods[] = { | |
DOC_MATH_VECTOR2_ASPOLAR}, | ||
{"from_polar", (PyCFunction)vector2_from_polar, METH_VARARGS, | ||
DOC_MATH_VECTOR2_FROMPOLAR}, | ||
{"angle_rad", (PyCFunction)vector2_angle_rad, METH_NOARGS, | ||
DOC_MATH_VECTOR2_ANGLERAD}, | ||
{"angle", (PyCFunction)vector2_angle, METH_NOARGS, DOC_MATH_VECTOR2_ANGLE}, | ||
{"project", (PyCFunction)vector2_project, METH_O, | ||
DOC_MATH_VECTOR2_PROJECT}, | ||
{"copy", (PyCFunction)vector_copy, METH_NOARGS, DOC_MATH_VECTOR2_COPY}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
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
(orpy -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
andangle_rad