Skip to content

Add Rotating Calipers algorithm for convex polygon diameter - #15275

Open
Clear20-22 wants to merge 4 commits into
TheAlgorithms:masterfrom
Clear20-22:add-rotating-calipers
Open

Add Rotating Calipers algorithm for convex polygon diameter#15275
Clear20-22 wants to merge 4 commits into
TheAlgorithms:masterfrom
Clear20-22:add-rotating-calipers

Conversation

@Clear20-22

@Clear20-22 Clear20-22 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

This PR implements the Rotating Calipers algorithm in geometry/rotating_calipers.py. It computes the maximum Euclidean distance (polygon diameter) and the antipodal point pair of a set of 2D points in O(N log N) overall time (O(N) for the calipers sweep after monotone chain convex hull construction).

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 include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Copilot AI lite review requested due to automatic review settings September 11, 2026 05:32
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 11, 2026

@algorithms-keeper algorithms-keeper Bot 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 geometry/rotating_calipers.py Outdated

import math

Point = tuple[float, 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.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Point

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The remaining test-coverage feedback is a non-blocking nit.

Pull request overview

Adds a rotating-calipers algorithm for computing the diameter and antipodal pair of 2D point sets.

Changes:

  • Builds a monotone-chain convex hull.
  • Computes diameter using rotating calipers.
  • Handles degenerate inputs and includes doctests.
File summaries
File Summary Review finding
geometry/rotating_calipers.py Implements hull construction, geometry helpers, and diameter calculation. Nit (1 vote): add an asymmetric convex-polygon doctest to strengthen sweep validation.
Review details

Suppressed comments (1)

geometry/rotating_calipers.py:162

  • The end-to-end doctests exercise the sweep only on an axis-aligned rectangle (plus degenerate 1D cases). Because that input has strong symmetry and repeated antipodal-area ties, it can pass even if pointer advancement or antipodal selection is wrong for a general convex polygon. Add an asymmetric convex polygon, ideally with interior and/or unsorted points, and assert its known brute-force diameter and returned endpoints.
    >>> rotating_calipers([Point(1.0, 1.0)])
    Traceback (most recent call last):
        ...
    ValueError: At least 2 points are required to compute polygon diameter.
    """
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants