77 MultiPolygon ,
88 Point ,
99 Polygon ,
10+ Position ,
1011} from "geojson" ;
1112import { bbox as calcBbox } from "@turf/bbox" ;
1213import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon" ;
@@ -176,7 +177,9 @@ function isMultiPointInPoly(polygon: Polygon, multiPoint: MultiPoint) {
176177
177178function isLineOnLine ( lineString1 : LineString , lineString2 : LineString ) {
178179 let haveFoundInteriorPoint = false ;
179- for ( const coords of lineString2 . coordinates ) {
180+ const coordinates = lineString2 . coordinates ;
181+ for ( let i = 0 ; i < coordinates . length ; i ++ ) {
182+ const coords = coordinates [ i ] ;
180183 if (
181184 isPointOnLine ( { type : "Point" , coordinates : coords } , lineString1 , {
182185 ignoreEndVertices : true ,
@@ -191,6 +194,23 @@ function isLineOnLine(lineString1: LineString, lineString2: LineString) {
191194 ) {
192195 return false ;
193196 }
197+ // A segment whose endpoints are both on lineString1 (e.g. lineString2's
198+ // vertices coincide with lineString1's boundary) still shares interior with
199+ // lineString1. Probe the segment midpoint so an interior overlap is detected
200+ // even when no vertex of lineString2 is strictly interior.
201+ if ( ! haveFoundInteriorPoint && i > 0 ) {
202+ const midpoint : Position = [
203+ ( coordinates [ i - 1 ] [ 0 ] + coords [ 0 ] ) / 2 ,
204+ ( coordinates [ i - 1 ] [ 1 ] + coords [ 1 ] ) / 2 ,
205+ ] ;
206+ if (
207+ isPointOnLine ( { type : "Point" , coordinates : midpoint } , lineString1 , {
208+ ignoreEndVertices : true ,
209+ } )
210+ ) {
211+ haveFoundInteriorPoint = true ;
212+ }
213+ }
194214 }
195215 return haveFoundInteriorPoint ;
196216}
0 commit comments