File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed
packages/turf-boolean-point-on-line Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,25 @@ function isPointOnLineSegment(
97
97
} else if ( cross !== 0 ) {
98
98
return false ;
99
99
}
100
+
101
+ // Special cases for zero length lines
102
+ // https://github.com/Turfjs/turf/issues/2750
103
+ if ( Math . abs ( dxl ) === Math . abs ( dyl ) && Math . abs ( dxl ) === 0 ) {
104
+ // Zero length line.
105
+ if ( excludeBoundary ) {
106
+ // To be on a zero length line pt has to be on the start (and end), BUT we
107
+ // are excluding start and end from possible matches.
108
+ return false ;
109
+ }
110
+ if ( pt [ 0 ] === lineSegmentStart [ 0 ] && pt [ 1 ] === lineSegmentStart [ 1 ] ) {
111
+ // If point is same as start (and end) it's on the line segment
112
+ return true ;
113
+ } else {
114
+ // Otherwise point is somewhere else
115
+ return false ;
116
+ }
117
+ }
118
+
100
119
if ( ! excludeBoundary ) {
101
120
if ( Math . abs ( dxl ) >= Math . abs ( dyl ) ) {
102
121
return dxl > 0 ? x1 <= x && x <= x2 : x2 <= x && x <= x1 ;
Original file line number Diff line number Diff line change @@ -3,7 +3,10 @@ import path from "path";
3
3
import { fileURLToPath } from "url" ;
4
4
import test from "tape" ;
5
5
import { loadJsonFileSync } from "load-json-file" ;
6
- import { booleanPointOnLine as pointOnLine } from "./index.js" ;
6
+ import { point , lineString } from "@turf/helpers" ;
7
+ import booleanPointOnLine , {
8
+ booleanPointOnLine as pointOnLine ,
9
+ } from "./index.js" ;
7
10
8
11
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
9
12
@@ -36,3 +39,33 @@ test("turf-boolean-point-on-line", (t) => {
36
39
} ) ;
37
40
t . end ( ) ;
38
41
} ) ;
42
+
43
+ test ( "turf-boolean-point-on-line - issue 2750" , ( t ) => {
44
+ // Issue 2750 was that in the first test below where point is on a different
45
+ // longitude to a zero length line booleanPointOnLine gave the correct result,
46
+ // while the second test where a point on the SAME longitude, but nowhere
47
+ // near, that zero length line incorrectly returned true.
48
+ t . false (
49
+ booleanPointOnLine (
50
+ point ( [ 2 , 13 ] ) ,
51
+ lineString ( [
52
+ [ 1 , 1 ] ,
53
+ [ 1 , 1 ] ,
54
+ ] )
55
+ ) ,
56
+ "#2750 different longitude point not on zero length line"
57
+ ) ;
58
+
59
+ t . false (
60
+ booleanPointOnLine (
61
+ point ( [ 1 , 13 ] ) ,
62
+ lineString ( [
63
+ [ 1 , 1 ] ,
64
+ [ 1 , 1 ] ,
65
+ ] )
66
+ ) ,
67
+ "#2750 same longitude point not on zero length line"
68
+ ) ;
69
+
70
+ t . end ( ) ;
71
+ } ) ;
You can’t perform that action at this time.
0 commit comments