-
-
Notifications
You must be signed in to change notification settings - Fork 190
Implemented the Line.project #3402
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
Open
XFajk
wants to merge
23
commits into
pygame-community:main
Choose a base branch
from
XFajk:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
22ccf84
implemented the Line.project method with all the tests and docs
XFajk e2001dd
added the doc string to the method in C
XFajk 193071a
optimized the Line.project method made it METH_FASTCALL and removed s…
XFajk ea76d39
made the docs more clear, improved the images
XFajk 44ab4fc
Update docs/reST/ref/geometry.rst
XFajk cd9c648
Update docs/reST/ref/geometry.rst
XFajk 896f7b2
Update docs/reST/ref/geometry.rst
XFajk ed8af87
added "/" to the stub file to indicate that the first arg is position…
XFajk bfe2698
added one more test case fixed the stub
XFajk a291329
made a small change to the stub
XFajk 317719e
fixed a bug in the Line.project method
XFajk e6c1f8c
remade the method to be VARARGS insted of FASTCALL
XFajk 383741f
added proper error handling and and reflected that in the docs and tests
XFajk f7178f6
removed one mistake made
XFajk e89deaa
Update line.c
XFajk d06b383
Update line.c
XFajk 81dc704
Delete .clangd unimportant file
XFajk 70dc960
Update buildconfig/stubs/pygame/geometry.pyi
XFajk 82c43c9
Update geometry.rst
XFajk 32ae369
Update src_c/line.c
XFajk 1a8d9f6
Update src_c/line.c
XFajk 2401414
Update src_c/line.c
XFajk 4194dce
Fix typo in variable name for squared line length in _line_project_he…
XFajk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -740,3 +740,27 @@ | |
.. versionadded:: 2.5.3 | ||
|
||
.. ## Line.flip_ab_ip ## | ||
|
||
.. method:: project | ||
|
||
| :sl:`projects the line onto the given line` | ||
| :sg:`project(point: tuple[float, float], clamp=False) -> tuple[float, float]` | ||
|
||
This method takes in a point and one boolean keyword argument clamp. It outputs an orthogonally projected point onto the line. | ||
If clamp is True it makes sure that the outputted point will be on the line segment. | ||
XFajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
.. figure:: code_examples/project.png | ||
:alt: project method image | ||
|
||
Example of how it projects the point on to the line purplish point is the point we want to project and the blue point is what you would get as a result | ||
XFajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
.. figure:: code_examples/project_clamp.png | ||
:alt: project do_clamp=True image | ||
|
||
Example of what the clamp argument changes if it is true it stays on the line segment | ||
XFajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. versionadded:: 2.5.4 | ||
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. this would need to be updated to 2.5.6 after we have consensus on this PR |
||
|
||
.. ## Line.project ## |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wasn't clear. Only the return type should be changed to
tuple[float, float]
; the argument should stayPoint
.The reason is that while the input argument should be as broad and abstract of a type as possible, the return type needs to be more concrete and narrow to allow easy usage.
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.
Now when talking about this, not related to this PR, but maybe we should rename the typing.(Int)Point to typing.(Int)PointLike, just to be the same as the rest of typing module, and a little bit more clear to avoid stuff like that in the future. On the other hand, it is hard to do that now since the typing module is exposed in pygame API, so maybe in pg3
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 would normally agree with increasing naming consistency.
However,
Point
is not necessarily like the other types in that it is not a union of similar, acceptable types. It is also not a raw protocol likeSequenceLike
.The main reason of course is verbosity; originally,
CoordinateLike
would be too long which might be the original reason, butPointLike
is still long too.