feat(geometry): Add Bentley-Ottmann algorithm for line segment intersection#6871
Merged
DenizAltunkapan merged 9 commits intoTheAlgorithms:masterfrom Oct 25, 2025
Microindole:add-bentley-ottmann-algorithm
Merged
feat(geometry): Add Bentley-Ottmann algorithm for line segment intersection#6871DenizAltunkapan merged 9 commits intoTheAlgorithms:masterfrom Microindole:add-bentley-ottmann-algorithm
DenizAltunkapan merged 9 commits intoTheAlgorithms:masterfrom
Microindole:add-bentley-ottmann-algorithm
Conversation
- Implement sweep-line algorithm for finding all intersection points - Time complexity: O((n + k) log n) where n is segments, k is intersections - Uses event queue (PriorityQueue) and status structure (TreeSet) - Handles vertical/horizontal segments, collinear overlaps, and touching endpoints - Includes comprehensive Javadoc with examples and references
- 19 test cases covering typical, edge, and degenerate cases - Tests include: single/multiple intersections, parallel segments, grid patterns - Performance test with 100 random segments - All tests validate correctness of intersection detection
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6871 +/- ##
============================================
+ Coverage 78.18% 78.20% +0.01%
- Complexity 6509 6564 +55
============================================
Files 742 743 +1
Lines 21697 21886 +189
Branches 4237 4284 +47
============================================
+ Hits 16964 17116 +152
- Misses 4062 4087 +25
- Partials 671 683 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DenizAltunkapan
approved these changes
Oct 25, 2025
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.
Description
This PR implements the Bentley-Ottmann sweep-line algorithm for efficiently finding all intersection points among a set of line segments in a 2D plane.
Changes
BentleyOttmann.javawith complete implementationBentleyOttmannTest.javawith 19 comprehensive test casesAlgorithm Details
PriorityQueue<Event>TreeSet<Segment>(balanced BST)Test Coverage
Example Usage
Related Issue
Closes #6870
Checklist