Skip to content

Commit

Permalink
fix self intersection behavior of boolean-intersect. update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pm0u committed Dec 17, 2024
1 parent 0da7ada commit 87805b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
9 changes: 4 additions & 5 deletions packages/turf-boolean-intersects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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) => {
Expand Down
40 changes: 20 additions & 20 deletions packages/turf-boolean-intersects/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 87805b9

Please sign in to comment.