Skip to content

Commit 24aa197

Browse files
authored
fixes booleanIntersects false positive (#196)
1 parent 44630f7 commit 24aa197

File tree

8 files changed

+57
-20
lines changed

8 files changed

+57
-20
lines changed

.github/workflows/dart-pub-publish-on-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

1313
- uses: dart-lang/setup-dart@v1
1414
with:

.github/workflows/dart-pub-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

1313
- uses: dart-lang/setup-dart@v1
1414
with:

.github/workflows/dart-unit-tests-on-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

1313
- uses: dart-lang/setup-dart@v1
1414
with:

.github/workflows/dart-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

1313
- uses: dart-lang/setup-dart@v1
1414
with:

.github/workflows/pr-code-coverage-reporting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
github.event.workflow_run.conclusion == 'success' }}
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515

1616
- uses: dart-lang/setup-dart@v1
1717
with:

lib/src/booleans/boolean_disjoint.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import '../polygon_to_line.dart';
1919
/// booleanDisjoint(line, point);
2020
/// //=true
2121
/// ```
22-
bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) {
22+
bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2, {bool ignoreSelfIntersections = false}) {
2323
var bool = true;
2424
flattenEach(
2525
feature1,
@@ -30,7 +30,7 @@ bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) {
3030
if (!bool) {
3131
return bool;
3232
}
33-
bool = _disjoint(flatten1.geometry!, flatten2.geometry!);
33+
bool = _disjoint(flatten1.geometry!, flatten2.geometry!, ignoreSelfIntersections);
3434
},
3535
);
3636
},
@@ -39,7 +39,7 @@ bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) {
3939
}
4040

4141
/// Disjoint operation for simple Geometries ([Point]/[LineString]/[Polygon])
42-
bool _disjoint(GeometryType geom1, GeometryType geom2) {
42+
bool _disjoint(GeometryType geom1, GeometryType geom2, bool ignoreSelfIntersections) {
4343
if (geom1 is Point) {
4444
if (geom2 is Point) {
4545
return geom1.coordinates != geom2.coordinates;
@@ -52,17 +52,17 @@ bool _disjoint(GeometryType geom1, GeometryType geom2) {
5252
if (geom2 is Point) {
5353
return !_isPointOnLine(geom1, geom2);
5454
} else if (geom2 is LineString) {
55-
return !_isLineOnLine(geom1, geom2);
55+
return !_isLineOnLine(geom1, geom2, ignoreSelfIntersections);
5656
} else if (geom2 is Polygon) {
57-
return !_isLineInPoly(geom2, geom1);
57+
return !_isLineInPoly(geom2, geom1, ignoreSelfIntersections);
5858
}
5959
} else if (geom1 is Polygon) {
6060
if (geom2 is Point) {
6161
return !booleanPointInPolygon((geom2).coordinates, geom1);
6262
} else if (geom2 is LineString) {
63-
return !_isLineInPoly(geom1, geom2);
63+
return !_isLineInPoly(geom1, geom2, ignoreSelfIntersections);
6464
} else if (geom2 is Polygon) {
65-
return !_isPolyInPoly(geom2, geom1);
65+
return !_isPolyInPoly(geom2, geom1, ignoreSelfIntersections);
6666
}
6767
}
6868
return false;
@@ -79,21 +79,21 @@ bool _isPointOnLine(LineString lineString, Point pt) {
7979
return false;
8080
}
8181

82-
bool _isLineOnLine(LineString lineString1, LineString lineString2) {
83-
var doLinesIntersect = lineIntersect(lineString1, lineString2);
82+
bool _isLineOnLine(LineString lineString1, LineString lineString2, bool ignoreSelfIntersections) {
83+
var doLinesIntersect = lineIntersect(lineString1, lineString2, ignoreSelfIntersections: ignoreSelfIntersections);
8484
if (doLinesIntersect.features.isNotEmpty) {
8585
return true;
8686
}
8787
return false;
8888
}
8989

90-
bool _isLineInPoly(Polygon polygon, LineString lineString) {
90+
bool _isLineInPoly(Polygon polygon, LineString lineString, bool ignoreSelfIntersections) {
9191
for (var coord in lineString.coordinates) {
9292
if (booleanPointInPolygon(coord, polygon)) {
9393
return true;
9494
}
9595
}
96-
var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
96+
var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), ignoreSelfIntersections: ignoreSelfIntersections);
9797
if (doLinesIntersect.features.isNotEmpty) {
9898
return true;
9999
}
@@ -103,7 +103,7 @@ bool _isLineInPoly(Polygon polygon, LineString lineString) {
103103
/// Is [Polygon] (geom1) in [Polygon] (geom2)
104104
/// Only takes into account outer rings
105105
/// See http://stackoverflow.com/a/4833823/1979085
106-
bool _isPolyInPoly(Polygon feature1, Polygon feature2) {
106+
bool _isPolyInPoly(Polygon feature1, Polygon feature2, bool ignoreSelfIntersections) {
107107
for (var coord1 in feature1.coordinates[0]) {
108108
if (booleanPointInPolygon(coord1, feature2)) {
109109
return true;
@@ -115,7 +115,7 @@ bool _isPolyInPoly(Polygon feature1, Polygon feature2) {
115115
}
116116
}
117117
var doLinesIntersect =
118-
lineIntersect(polygonToLine(feature1), polygonToLine(feature2));
118+
lineIntersect(polygonToLine(feature1), polygonToLine(feature2), ignoreSelfIntersections: ignoreSelfIntersections);
119119
if (doLinesIntersect.features.isNotEmpty) {
120120
return true;
121121
}

lib/src/booleans/boolean_intersects.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'boolean_disjoint.dart';
1111
/// booleanIntersects(line, point);
1212
/// //=true
1313
/// ```
14-
bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2) {
14+
bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2, {bool ignoreSelfIntersections = true}) {
1515
var result = false;
1616
flattenEach(
1717
feature1,
@@ -22,7 +22,7 @@ bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2) {
2222
if (result) {
2323
return true;
2424
}
25-
result = !booleanDisjoint(flatten1, flatten2);
25+
result = !booleanDisjoint(flatten1, flatten2, ignoreSelfIntersections: ignoreSelfIntersections);
2626
},
2727
);
2828
},
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "Polygon",
9+
"coordinates": [
10+
[
11+
[-11, -12],
12+
[-13, -12],
13+
[-13, -13],
14+
[-11, -13],
15+
[-11, -12]
16+
]
17+
]
18+
}
19+
},
20+
{
21+
"type": "Feature",
22+
"properties": {},
23+
"geometry": {
24+
"type": "Polygon",
25+
"coordinates": [
26+
[
27+
[0, 0],
28+
[2, 2],
29+
[0, 2],
30+
[2, 0],
31+
[0, 0]
32+
]
33+
]
34+
}
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)