diff --git a/.github/workflows/dart-pub-publish-on-pr.yml b/.github/workflows/dart-pub-publish-on-pr.yml index dbce0b12..b77e9700 100644 --- a/.github/workflows/dart-pub-publish-on-pr.yml +++ b/.github/workflows/dart-pub-publish-on-pr.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: diff --git a/.github/workflows/dart-pub-publish.yml b/.github/workflows/dart-pub-publish.yml index 77a70b78..c635d2de 100644 --- a/.github/workflows/dart-pub-publish.yml +++ b/.github/workflows/dart-pub-publish.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: diff --git a/.github/workflows/dart-unit-tests-on-pr.yml b/.github/workflows/dart-unit-tests-on-pr.yml index b6ca9dd0..d0806f02 100644 --- a/.github/workflows/dart-unit-tests-on-pr.yml +++ b/.github/workflows/dart-unit-tests-on-pr.yml @@ -8,7 +8,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: diff --git a/.github/workflows/dart-unit-tests.yml b/.github/workflows/dart-unit-tests.yml index 1206f668..db190ca1 100644 --- a/.github/workflows/dart-unit-tests.yml +++ b/.github/workflows/dart-unit-tests.yml @@ -8,7 +8,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: diff --git a/.github/workflows/pr-code-coverage-reporting.yml b/.github/workflows/pr-code-coverage-reporting.yml index a632247b..89835330 100644 --- a/.github/workflows/pr-code-coverage-reporting.yml +++ b/.github/workflows/pr-code-coverage-reporting.yml @@ -11,7 +11,7 @@ jobs: github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: diff --git a/lib/src/booleans/boolean_disjoint.dart b/lib/src/booleans/boolean_disjoint.dart index 0920f448..625f7cd3 100644 --- a/lib/src/booleans/boolean_disjoint.dart +++ b/lib/src/booleans/boolean_disjoint.dart @@ -19,7 +19,7 @@ import '../polygon_to_line.dart'; /// booleanDisjoint(line, point); /// //=true /// ``` -bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) { +bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2, {bool ignoreSelfIntersections = false}) { var bool = true; flattenEach( feature1, @@ -30,7 +30,7 @@ bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) { if (!bool) { return bool; } - bool = _disjoint(flatten1.geometry!, flatten2.geometry!); + bool = _disjoint(flatten1.geometry!, flatten2.geometry!, ignoreSelfIntersections); }, ); }, @@ -39,7 +39,7 @@ bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) { } /// Disjoint operation for simple Geometries ([Point]/[LineString]/[Polygon]) -bool _disjoint(GeometryType geom1, GeometryType geom2) { +bool _disjoint(GeometryType geom1, GeometryType geom2, bool ignoreSelfIntersections) { if (geom1 is Point) { if (geom2 is Point) { return geom1.coordinates != geom2.coordinates; @@ -52,17 +52,17 @@ bool _disjoint(GeometryType geom1, GeometryType geom2) { if (geom2 is Point) { return !_isPointOnLine(geom1, geom2); } else if (geom2 is LineString) { - return !_isLineOnLine(geom1, geom2); + return !_isLineOnLine(geom1, geom2, ignoreSelfIntersections); } else if (geom2 is Polygon) { - return !_isLineInPoly(geom2, geom1); + return !_isLineInPoly(geom2, geom1, ignoreSelfIntersections); } } else if (geom1 is Polygon) { if (geom2 is Point) { return !booleanPointInPolygon((geom2).coordinates, geom1); } else if (geom2 is LineString) { - return !_isLineInPoly(geom1, geom2); + return !_isLineInPoly(geom1, geom2, ignoreSelfIntersections); } else if (geom2 is Polygon) { - return !_isPolyInPoly(geom2, geom1); + return !_isPolyInPoly(geom2, geom1, ignoreSelfIntersections); } } return false; @@ -79,21 +79,21 @@ bool _isPointOnLine(LineString lineString, Point pt) { return false; } -bool _isLineOnLine(LineString lineString1, LineString lineString2) { - var doLinesIntersect = lineIntersect(lineString1, lineString2); +bool _isLineOnLine(LineString lineString1, LineString lineString2, bool ignoreSelfIntersections) { + var doLinesIntersect = lineIntersect(lineString1, lineString2, ignoreSelfIntersections: ignoreSelfIntersections); if (doLinesIntersect.features.isNotEmpty) { return true; } return false; } -bool _isLineInPoly(Polygon polygon, LineString lineString) { +bool _isLineInPoly(Polygon polygon, LineString lineString, bool ignoreSelfIntersections) { for (var coord in lineString.coordinates) { if (booleanPointInPolygon(coord, polygon)) { return true; } } - var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon)); + var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), ignoreSelfIntersections: ignoreSelfIntersections); if (doLinesIntersect.features.isNotEmpty) { return true; } @@ -103,7 +103,7 @@ bool _isLineInPoly(Polygon polygon, LineString lineString) { /// Is [Polygon] (geom1) in [Polygon] (geom2) /// Only takes into account outer rings /// See http://stackoverflow.com/a/4833823/1979085 -bool _isPolyInPoly(Polygon feature1, Polygon feature2) { +bool _isPolyInPoly(Polygon feature1, Polygon feature2, bool ignoreSelfIntersections) { for (var coord1 in feature1.coordinates[0]) { if (booleanPointInPolygon(coord1, feature2)) { return true; @@ -115,7 +115,7 @@ bool _isPolyInPoly(Polygon feature1, Polygon feature2) { } } var doLinesIntersect = - lineIntersect(polygonToLine(feature1), polygonToLine(feature2)); + lineIntersect(polygonToLine(feature1), polygonToLine(feature2), ignoreSelfIntersections: ignoreSelfIntersections); if (doLinesIntersect.features.isNotEmpty) { return true; } diff --git a/lib/src/booleans/boolean_intersects.dart b/lib/src/booleans/boolean_intersects.dart index 695452a7..b572a2a1 100644 --- a/lib/src/booleans/boolean_intersects.dart +++ b/lib/src/booleans/boolean_intersects.dart @@ -11,7 +11,7 @@ import 'boolean_disjoint.dart'; /// booleanIntersects(line, point); /// //=true /// ``` -bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2) { +bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2, {bool ignoreSelfIntersections = true}) { var result = false; flattenEach( feature1, @@ -22,7 +22,7 @@ bool booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2) { if (result) { return true; } - result = !booleanDisjoint(flatten1, flatten2); + result = !booleanDisjoint(flatten1, flatten2, ignoreSelfIntersections: ignoreSelfIntersections); }, ); }, diff --git a/test/examples/booleans/intersects/false/Polygon/Polygon/Polygon-SelfintersectingPolygon.geojson b/test/examples/booleans/intersects/false/Polygon/Polygon/Polygon-SelfintersectingPolygon.geojson new file mode 100644 index 00000000..e6584195 --- /dev/null +++ b/test/examples/booleans/intersects/false/Polygon/Polygon/Polygon-SelfintersectingPolygon.geojson @@ -0,0 +1,37 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-11, -12], + [-13, -12], + [-13, -13], + [-11, -13], + [-11, -12] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [0, 0], + [2, 2], + [0, 2], + [2, 0], + [0, 0] + ] + ] + } + } + ] +}