diff --git a/packages/turf-boolean-intersects/index.ts b/packages/turf-boolean-intersects/index.ts index 5ba9ba7a0..50b08925f 100644 --- a/packages/turf-boolean-intersects/index.ts +++ b/packages/turf-boolean-intersects/index.ts @@ -9,7 +9,7 @@ import { flattenEach } from "@turf/meta"; * @param {Geometry|Feature} feature1 GeoJSON Feature or Geometry * @param {Geometry|Feature} 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 | Geometry, feature2: Feature | Geometry, - options: { + { + ignoreSelfIntersections = true, + }: { ignoreSelfIntersections?: boolean; } = {} ) { - const ignoreSelfIntersections: boolean = - options.ignoreSelfIntersections ?? false; - let bool = false; flattenEach(feature1, (flatten1) => { flattenEach(feature2, (flatten2) => { diff --git a/packages/turf-boolean-intersects/test.ts b/packages/turf-boolean-intersects/test.ts index 0dc261338..f42de2774 100644 --- a/packages/turf-boolean-intersects/test.ts +++ b/packages/turf-boolean-intersects/test.ts @@ -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();