-
-
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
Add more Line
attributes
#3268
base: main
Are you sure you want to change the base?
Add more Line
attributes
#3268
Conversation
- center - centerx/y - angle - slope Co-authored-by: Emc2356 <[email protected]> Co-authored-by: NovialRiptide <[email protected]> Co-authored-by: ScriptLineStudios <[email protected]> Co-authored-by: Avaxar <[email protected]> Co-authored-by: maqa41 <[email protected]>
Co-authored-by: Dan Lawrence <[email protected]>
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 angle attribute seems like it is a bit off from what I would expect in pygame. Not sure if this is because of the reversed y axis, or the difference in chosen calculations
I was expecting results something like this I guess:
If I apply rotations to a Vector2 of (0,-10)
then it lines up with the image above.
However a line of ((0,0),(0,-10))
currently has an angle of 90° and a line of ((0,0),(10,0))
has a reported angle of -0.0°.
How does everyone else feel about this difference?
I guess I should also ask - is there a The way we rotate stuff geometrically doesn't particularly matter - as long as we are internally consistent. |
@MyreMylar you are comparing rotating a line by a certain angle, with the inherent "angle" of a line. The angle of a line is similar to The |
Perhaps the vector corresponding to a line may be a useful attribute. |
{ | ||
double dem = self->line.bx - self->line.ax; | ||
if (dem == 0) { | ||
return PyFloat_FromDouble(0); |
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 think this is inaccurate. The result here should either be an exception or +-inf
.
If inf
, then I would think that for by - ay == 0
case it would be nan
instead.
In any case, the vertical line behavior needs to be documented.
double dy = self->line.by - self->line.ay; | ||
double gradient = dy / dx; | ||
|
||
return PyFloat_FromDouble(-RAD_TO_DEG(atan(gradient))); |
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 don't think the angle should be negated.
Also it should use some form of atan2
instead of atan
, to reach the full 360 deg range, as had been specified in the docs.
There's also special cases like a == b
, inf
, etc., where it maybe should emulate python math.atan2(line.by - line.ay, line.bx - line.ax)
(also see #3222).
Adds the following
Line
attributes:Credits
Geometry Project:
For code, docs and tests:
@novialriptide @Emc2356 @itzpr3d4t0r @ScriptLineStudios @avaxar @Matiiss @newpaxonian @maqa41 @blankRiot96
Also thanks to @Starbuck5 for kickstarting the idea and the occasional help!
Functionality added in this PR
geometry.pyi
https://github.com/pygame-community/pygame-geometry/blame/main/geometry.pyi
Credits to @Emc2356 @itzpr3d4t0r @novialriptide @ScriptLineStudios @avaxar
geometry.rst
https://github.com/pygame-community/pygame-geometry/blame/main/docs/line.rst
Credits to @Emc2356 @itzpr3d4t0r @ScriptLineStudios @avaxar
line.c
https://github.com/pygame-community/pygame-geometry/blame/main/src_c/line.c
Credits to @Emc2356 @itzpr3d4t0r @novialriptide @ScriptLineStudios @avaxar
geometry.h
https://github.com/pygame-community/pygame-geometry/blame/main/src_c/include/geometry.h
Credits to @Emc2356 @itzpr3d4t0r @maqa41
geometry_test.py
https://github.com/pygame-community/pygame-geometry/blame/main/test/test_line.py
Credits to @Emc2356 @itzpr3d4t0r @novialriptide @ScriptLineStudios @avaxar