Add graham scan algorithm · Pull Request #4205 · TheAlgorithms/Python · GitHub
Skip to content

Add graham scan algorithm - #4205

Merged
cclauss merged 7 commits into
masterfrom
unknown repository
Mar 2, 2021
Merged

cclauss merged 7 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Feb 13, 2021

Copy link
Copy Markdown

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required awaiting reviews This PR is ready to be reviewed labels Feb 13, 2021

@ghost ghost left a comment

Copy link
Copy Markdown

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.

Comment thread other/graham_scan.py Outdated

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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

Comment thread other/graham_scan.py Outdated
angle = degrees(atan2(y - miny, x - minx))
return angle

sorted_points = sorted(points, key=lambda p: angle_comparer(p))

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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

Comment thread other/graham_scan.py
straight = 2
right = 3

def check_direction(

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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

@ghost ghost added the tests are failing Do not merge until tests pass label Feb 13, 2021
@ghost ghost removed the require descriptive names This PR needs descriptive function and/or variable names label Feb 13, 2021

@ghost ghost left a comment

Copy link
Copy Markdown

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.

Comment thread 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:

Copy link
Copy Markdown

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

Comment thread other/graham_scan.py
straight = 2
right = 3

def check_direction(

Copy link
Copy Markdown

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

@ghost

ghost commented Feb 13, 2021

Copy link
Copy Markdown
Author

To reviewers:

The test is failed at pre-commit because CI executes black for whole files in this repository, and it changes 814 files.

I did black with its newest version, and so CI does. It should be updated, or ignore this fail.

@ghost ghost removed the require tests Tests [doctest/unittest/pytest] are required label Feb 22, 2021
@ghost ghost removed the tests are failing Do not merge until tests pass label Mar 2, 2021
@cclauss

cclauss commented Mar 2, 2021

Copy link
Copy Markdown
Member

Doesn't this algorithm belong in https://github.com/TheAlgorithms/Python/tree/master/sorts ? or graphs?

How does this algorithm compare with
https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/convex_hull.py

@ghost

ghost commented Mar 2, 2021

Copy link
Copy Markdown
Author

@cclauss
Hi. I'm not sure if this algorithm should belong to sorts, because this aims to find the convex hull of a finite set of points. It's kind of coordinate things rather than sorting.

@cclauss

cclauss commented Mar 2, 2021

Copy link
Copy Markdown
Member

Putting algorithms in other makes them very hard for visitors to find. Is there another category that makes sense?

@ghost ghost closed this Mar 2, 2021
@ghost ghost reopened this Mar 2, 2021
@cclauss cclauss closed this Mar 2, 2021
@cclauss cclauss reopened this Mar 2, 2021
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Mar 2, 2021
@cclauss
cclauss merged commit a796ccf into TheAlgorithms:master Mar 2, 2021
@ghost

ghost commented Mar 2, 2021

Copy link
Copy Markdown
Author

@cclauss

I see. searches must be fitting. I will move this.

How does this algorithm compare with master/divide_and_conquer/convex_hull.py

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.
We'll look for all points at same time and trace the periphery with checking if the angle is towards to inner or outer.

@ghost

ghost commented Mar 2, 2021

Copy link
Copy Markdown
Author

Oh. Thank you for merging.

I wonder if I should create other PR to move this to searches, or shouldn't....

@cclauss

cclauss commented Mar 2, 2021

Copy link
Copy Markdown
Member

peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
* 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>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* 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>
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant