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

Add more Line attributes #3268

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

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]>
@itzpr3d4t0r itzpr3d4t0r added New API This pull request may need extra debate as it adds a new class or function to pygame geometry pygame.geometry labels Dec 16, 2024
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner December 16, 2024 12:16
@itzpr3d4t0r itzpr3d4t0r mentioned this pull request Dec 16, 2024
89 tasks
@itzpr3d4t0r itzpr3d4t0r added this to the 2.5.3 milestone Dec 16, 2024
docs/reST/ref/geometry.rst Outdated Show resolved Hide resolved
docs/reST/ref/geometry.rst Outdated Show resolved Hide resolved
src_c/doc/geometry_doc.h Outdated Show resolved Hide resolved
Copy link
Member

@MyreMylar MyreMylar left a 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:

image

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?

@MyreMylar
Copy link
Member

How does everyone else feel about this difference?

I guess I should also ask - is there a line.rotate(angle, origin) function on the way? And what are the results of it with an origin of (0,0) compared to doing the same rotation on a Vector2?

The way we rotate stuff geometrically doesn't particularly matter - as long as we are internally consistent.

@MyreMylar MyreMylar closed this Dec 31, 2024
@MyreMylar MyreMylar reopened this Dec 31, 2024
@aatle
Copy link
Contributor

aatle commented Dec 31, 2024

@MyreMylar you are comparing rotating a line by a certain angle, with the inherent "angle" of a line.
The angle of a line corresponds with the proposed Vector2 angle and angle_rad properties in #3222, and should have similar behavior for special cases.

The angle of a line is similar to atan(line.slope) (quadrant incorrect), and is better described as the angle of a vector representing the line, where a is the origin.

The angle should be in degrees, for consistency. There should probably be both a degrees and a radians implementation for every angle method, also for circle too. This would be consistent with Vector2.

@aatle
Copy link
Contributor

aatle commented Dec 31, 2024

Perhaps the vector corresponding to a line may be a useful attribute. (bx - ax, by - ay).

@damusss damusss dismissed their stale review January 5, 2025 14:22

Changes have been addressed

{
double dem = self->line.bx - self->line.ax;
if (dem == 0) {
return PyFloat_FromDouble(0);
Copy link
Contributor

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)));
Copy link
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geometry pygame.geometry New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants