Repository navigation
fix: stop convexHullRecursive returning interior points - #7784
Open
Aditya2375 wants to merge 2 commits into
Open
Aditya2375 wants to merge 2 commits into
Aditya2375 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7784 +/- ##
============================================
- Coverage 82.45% 82.42% -0.03%
+ Complexity 8512 8511 -1
============================================
Files 847 847
Lines 26291 26294 +3
Branches 5134 5135 +1
============================================
- Hits 21677 21674 -3
- Misses 3825 3830 +5
- Partials 789 790 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Aditya2375
marked this pull request as ready for review
November 25, 2026 01:21
Aditya2375
requested review from
DenizAltunkapan,
alxkm and
yanglbme
as code owners
November 25, 2026 01:21
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your change:
Fixed
ConvexHull.convexHullRecursivereturning points that lie strictly inside the convex hull.The quickhull step picks the "extreme" point (the farthest point from the current line segment, which is guaranteed to be a hull vertex) and recurses on it. But it compared values returned by
Point.orientation, which normalizes its result withInteger.compare(..., 0)and therefore only ever returns -1, 0 or 1. Every candidate point compared "equal", so the code simply recursed on the first candidate in list order. An arbitrary point beyond the segment is not guaranteed to be on the hull, so strictly interior points ended up in the result.Example with the current implementation:
The fix computes the actual cross product (as a
long, to avoid int overflow) when selecting the extreme point. I also deduplicated the input up front, since coincident input points previously made the< 3base case return duplicates (e.g.[P, P]->[P, P]).I verified the fixed implementation against an independent monotone-chain oracle on 5000 randomized point sets (including collinear and duplicate-heavy inputs): all match. Added regression tests for both cases; both fail on the current code and pass with the fix.
Checklist:
Fixes: #{$ISSUE_NO}.