Skip to content

Fixing line-overlap missing certain horizontal/vertical lines (#2582)#3071

Open
jonovotny wants to merge 4 commits into
Turfjs:masterfrom
jonovotny:line-overlap-fix-(#2582)
Open

Fixing line-overlap missing certain horizontal/vertical lines (#2582)#3071
jonovotny wants to merge 4 commits into
Turfjs:masterfrom
jonovotny:line-overlap-fix-(#2582)

Conversation

@jonovotny

@jonovotny jonovotny commented May 29, 2026

Copy link
Copy Markdown

Line-overlap now detects overlap in horizontal and vertical segments with a parallel offset within tolerance (fixing #2582). Previously bounding boxes in the rbush tree would not overlap in these edge cases. By expanding the bbox around matching segments by the tolerance this issue should be resolved.

Added a test case of two polygons with horizontal and vertical overlap. (#2580 remains a problem and may still lead to missing segments for a different reason.)

Fixes #2582

jonovotny added 4 commits May 29, 2026 12:54
line-overlap now detects overlap in horizontal and vertical sections with a parallel offset within tolerance. Previously bounding boxes in the rbush tree would not overlap in these edge cases. By expanding the bbox around matching segments by the tolerance this issue is fixed.
@mfedderly mfedderly added this to the v7.4 milestone Jun 26, 2026

@mfedderly mfedderly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for looking at this! I think tolerance is in the wrong units but everything else looks good.


// Expand segment bounding box by the tolerance to create overlap in horizontal/vertical segments
var bb = bbox(segment);
bb = [bb[0]-tolerance, bb[1]-tolerance, bb[2]+tolerance, bb[3]+tolerance];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The jsdoc above implies that tolerance is in kilometers not degrees, so this needs a conversion I think.

import { lengthToDegrees} from "@turf/helpers";
...
const toleranceDegrees = lengthToDegrees(tolerance, "kilometers");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh! One other thing. You may want to skip this bbox logic entirely if tolerance === 0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lineOverlap tolerance is not handled in every case

2 participants