Reverted self intersection behavior of boolean-intersect. update tests (#2773)

Co-authored-by: James Beard <james@smallsaucepan.com>
This commit is contained in:
Paul Mourer 2024-12-23 21:03:15 -07:00 committed by GitHub
parent 5a9d40d496
commit d1a2c5857f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 25 deletions

View File

@ -9,7 +9,7 @@ import { flattenEach } from "@turf/meta";
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
* @param {boolean} [options.ignoreSelfIntersections=true] ignore self-intersections on input features
* @returns {boolean} true if geometries intersect, false otherwise
* @example
* var point1 = turf.point([2, 2]);
@ -30,13 +30,12 @@ import { flattenEach } from "@turf/meta";
function booleanIntersects(
feature1: Feature<any> | Geometry,
feature2: Feature<any> | Geometry,
options: {
{
ignoreSelfIntersections = true,
}: {
ignoreSelfIntersections?: boolean;
} = {}
) {
const ignoreSelfIntersections: boolean =
options.ignoreSelfIntersections ?? false;
let bool = false;
flattenEach(feature1, (flatten1) => {
flattenEach(feature2, (flatten2) => {

View File

@ -122,62 +122,62 @@ test("turf-boolean-intersects with ignoreSelfIntersections option", (t) => {
selfIntersectingLineString,
nonIntersectingLineString
);
t.true(
t.false(
result,
"[true] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
"[false] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
);
result = intersects(selfIntersectingLineString, intersectingLineString);
t.true(
result,
"[true] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
);
result = intersects(selfIntersectingLineString, intersectingPolygon);
t.true(
result,
"[true] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
);
result = intersects(selfIntersectingLineString, nonIntersectingPolygon);
t.true(
t.false(
result,
"[true] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
"[false] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
);
// Test with ignoringSelfIntersections option
result = intersects(selfIntersectingLineString, nonIntersectingLineString, {
ignoreSelfIntersections: true,
ignoreSelfIntersections: false,
});
t.false(
t.true(
result,
"[false] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
"[true] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
);
result = intersects(selfIntersectingLineString, intersectingLineString, {
ignoreSelfIntersections: true,
ignoreSelfIntersections: false,
});
t.true(
result,
"[true] " +
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
);
result = intersects(selfIntersectingLineString, intersectingPolygon, {
ignoreSelfIntersections: true,
ignoreSelfIntersections: false,
});
t.true(
result,
"[true] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
);
result = intersects(selfIntersectingLineString, nonIntersectingPolygon, {
ignoreSelfIntersections: true,
ignoreSelfIntersections: false,
});
t.false(
t.true(
result,
"[false] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
"[true] " +
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
);
t.end();