From faa33d4156dcdafdb1c536b5bc5e7dd6b36b6fca Mon Sep 17 00:00:00 2001 From: Sebastian Cao Date: Sun, 5 Jul 2026 21:26:48 +0800 Subject: [PATCH] Fix boolean-disjoint missing overlapping collinear lines --- packages/turf-boolean-disjoint/index.ts | 13 +++++++++ .../LineString/LineString-Overlap.geojson | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-Overlap.geojson diff --git a/packages/turf-boolean-disjoint/index.ts b/packages/turf-boolean-disjoint/index.ts index 0b8158eb1b..ea3de597d3 100644 --- a/packages/turf-boolean-disjoint/index.ts +++ b/packages/turf-boolean-disjoint/index.ts @@ -125,6 +125,19 @@ function isLineOnLine( if (doLinesIntersect.features.length > 0) { return true; } + // lineIntersect() only reports points where segments cross, so collinear + // (partially) overlapping lines are missed. Check whether a vertex of either + // line lies on the other line to also catch those overlapping cases. + for (const coords of lineString1.coordinates) { + if (isPointOnLine(lineString2, { type: "Point", coordinates: coords })) { + return true; + } + } + for (const coords of lineString2.coordinates) { + if (isPointOnLine(lineString1, { type: "Point", coordinates: coords })) { + return true; + } + } return false; } diff --git a/packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-Overlap.geojson b/packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-Overlap.geojson new file mode 100644 index 0000000000..c591f5ef3e --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-Overlap.geojson @@ -0,0 +1,27 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [4, 1], + [5, 4] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [4, 1], + [6, 7] + ] + } + } + ] +}