-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Add graham scan algorithm #4205
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
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
other/graham_scan.py
Outdated
# remove the lowest and the most left point from points for preparing for sort | ||
points.pop(minidx) | ||
|
||
def angle_comparer(p: list[int, int]) -> float: |
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.
As there is no test file in this pull request nor any test function or class in the file other/graham_scan.py
, please provide doctest for the function angle_comparer
Please provide descriptive name for the parameter: p
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.
To reviewers:
This is an inner function.
argument name is fixed here fdaacde
other/graham_scan.py
Outdated
angle = degrees(atan2(y - miny, x - minx)) | ||
return angle | ||
|
||
sorted_points = sorted(points, key=lambda p: angle_comparer(p)) |
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.
Please provide descriptive name for the parameter: p
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.
argument name is fixed here fdaacde
straight = 2 | ||
right = 3 | ||
|
||
def check_direction( |
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.
As there is no test file in this pull request nor any test function or class in the file other/graham_scan.py
, please provide doctest for the function check_direction
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.
To reviewers:
This is an inner function
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
other/graham_scan.py
Outdated
# remove the lowest and the most left point from points for preparing for sort | ||
points.pop(minidx) | ||
|
||
def angle_comparer(point: list[int, int]) -> float: |
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.
As there is no test file in this pull request nor any test function or class in the file other/graham_scan.py
, please provide doctest for the function angle_comparer
straight = 2 | ||
right = 3 | ||
|
||
def check_direction( |
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.
As there is no test file in this pull request nor any test function or class in the file other/graham_scan.py
, please provide doctest for the function check_direction
To reviewers: The test is failed at pre-commit because CI executes I did |
Doesn't this algorithm belong in https://github.com/TheAlgorithms/Python/tree/master/sorts ? or graphs? How does this algorithm compare with |
@cclauss |
Putting algorithms in |
I see.
divide_and_conquer algorithm is also known well to solve convex hull problem only by O(n * logn) time complexity. However, it's approach is totally different from graham scan. Graham scan doesn't use divide_and_conquer approach, but it focuses on sorting points by angle. |
Oh. Thank you for merging. I wonder if I should create other PR to move this to |
https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/convex_hull.py has three different convex_hull algorithms and your file has a fourth. What would be really cool would be to benchmark the four algorithms on one or more common datasets to see the relative performance. |
* Add graham scan algorithm * Fix argument name p with point * Add tests in inner function * updating DIRECTORY.md * Fix graham scan for isort --profile=black Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Add graham scan algorithm * Fix argument name p with point * Add tests in inner function * updating DIRECTORY.md * Fix graham scan for isort --profile=black Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Add graham scan algorithm * Fix argument name p with point * Add tests in inner function * updating DIRECTORY.md * Fix graham scan for isort --profile=black Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.