Repository navigation
fix: stop convexHullRecursive returning interior points #7784
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,4 +135,47 @@ void testRecursiveHullForCoverage() { | |
| assertEquals(expectedCollinear, resultCollinear, "Should correctly handle collinear points on the hull edge"); | ||
| assertTrue(isCounterClockwise(resultCollinear), "The result of the collinear test should be in counter-clockwise order"); | ||
| } | ||
| @Test | ||
| void testConvexHullRecursiveExcludesInteriorPoints() { | ||
|
Member
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. Please add a regression with large positive and negative coordinates. I compiled this revision and checked the triangle |
||
| // (1,8) is strictly inside the hull of the other four points. | ||
| List<Point> points = new ArrayList<>(List.of(new Point(1, 5), new Point(1, 8), new Point(2, 9), new Point(0, 10), new Point(4, 19))); | ||
| List<Point> expected = List.of(new Point(1, 5), new Point(2, 9), new Point(4, 19), new Point(0, 10)); | ||
| assertEquals(expected, ConvexHull.convexHullRecursive(points)); | ||
|
|
||
| // (7,2) and (8,3) are strictly inside the triangle (4,0), (11,3), (3,10). | ||
| List<Point> points2 = new ArrayList<>(List.of(new Point(4, 0), new Point(7, 2), new Point(8, 3), new Point(11, 3), new Point(3, 10))); | ||
| List<Point> expected2 = List.of(new Point(4, 0), new Point(11, 3), new Point(3, 10)); | ||
| assertEquals(expected2, ConvexHull.convexHullRecursive(points2)); | ||
| } | ||
|
|
||
| @Test | ||
| void testConvexHullRecursiveDuplicatePoints() { | ||
| List<Point> points = new ArrayList<>(List.of(new Point(5, 5), new Point(5, 5))); | ||
| List<Point> expected = List.of(new Point(5, 5)); | ||
| assertEquals(expected, ConvexHull.convexHullRecursive(points)); | ||
| } | ||
|
|
||
| @Test | ||
| void testConvexHullRecursiveLargeCoordinates() { | ||
| // Differences between these coordinates overflow int when multiplied. | ||
| List<Point> points = new ArrayList<>(List.of(new Point(-32768, -32768), new Point(32768, -32768), new Point(-32768, 32768))); | ||
| List<Point> expected = List.of(new Point(-32768, -32768), new Point(32768, -32768), new Point(-32768, 32768)); | ||
| assertEquals(expected, ConvexHull.convexHullRecursive(points)); | ||
| } | ||
|
|
||
| @Test | ||
| void testConvexHullRecursiveFullIntRange() { | ||
| int min = Integer.MIN_VALUE; | ||
| int max = Integer.MAX_VALUE; | ||
| // Square corners, one point on a corner-to-corner diagonal and one inside. | ||
| List<Point> points = new ArrayList<>(List.of(new Point(min, min), new Point(max, min), new Point(max, max), new Point(min, max), new Point(0, 0), new Point(min, 0), new Point(max, 0), new Point(0, max))); | ||
| List<Point> expected = List.of(new Point(min, min), new Point(max, min), new Point(max, max), new Point(min, max)); | ||
| assertEquals(expected, ConvexHull.convexHullRecursive(points)); | ||
| } | ||
|
|
||
| @Test | ||
| void testConvexHullBruteForceLargeCoordinates() { | ||
| List<Point> points = new ArrayList<>(List.of(new Point(-32768, -32768), new Point(32768, -32768), new Point(-32768, 32768))); | ||
| assertEquals(3, ConvexHull.convexHullBruteForce(points).size()); | ||
| } | ||
| } | ||
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.
The initial upper/lower split and the final angle sort and collinearity filter still call
Point.orientation(), which computes the cross product entirely inint. Please use the same overflow-safe orientation throughout the recursive hull. The squared-distance tie-breaker in the angle sort also needs to respect the supported coordinate range.