Skip to content

Commit 5a9d40d

Browse files
pm0usmallsaucepan
andauthored
Reverted self intersection behavior for boolean-disjoint (#2772)
Reverted default ignoreSelfIntersections to true, to bring it back in line with Turf 6.5.0 --------- Co-authored-by: James Beard <[email protected]>
1 parent 3bbd759 commit 5a9d40d

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

packages/turf-boolean-disjoint/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an
1212
* `feature2` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
1313
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
1414

15-
* `options.ignoreSelfIntersections` **[boolean][4]** ignores self-intersections on input features (optional, default `false`)
15+
* `options.ignoreSelfIntersections` **[boolean][4]** ignore self-intersections on input features (optional, default `true`)
1616

1717
### Examples
1818

packages/turf-boolean-disjoint/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { polygonToLine } from "@turf/polygon-to-line";
1818
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
1919
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
2020
* @param {Object} [options={}] Optional parameters
21-
* @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
21+
* @param {boolean} [options.ignoreSelfIntersections=true] ignore self-intersections on input features
2222
* @returns {boolean} true if the intersection is an empty set, false otherwise
2323
* @example
2424
* var point = turf.point([2, 2]);
@@ -30,13 +30,12 @@ import { polygonToLine } from "@turf/polygon-to-line";
3030
function booleanDisjoint(
3131
feature1: Feature<any> | Geometry,
3232
feature2: Feature<any> | Geometry,
33-
options: {
33+
{
34+
ignoreSelfIntersections = true,
35+
}: {
3436
ignoreSelfIntersections?: boolean;
35-
} = {}
37+
} = { ignoreSelfIntersections: true }
3638
): boolean {
37-
const ignoreSelfIntersections: boolean =
38-
options.ignoreSelfIntersections ?? false;
39-
4039
let bool = true;
4140
flattenEach(feature1, (flatten1) => {
4241
flattenEach(feature2, (flatten2) => {

packages/turf-boolean-disjoint/test.ts

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test("turf-boolean-disjoint", (t) => {
1414
.sync(path.join(__dirname, "test", "true", "**", "*.geojson"))
1515
.forEach((filepath) => {
1616
const name = path.parse(filepath).name;
17-
const geojson = loadJsonFileSync(filepath);
17+
const geojson: GeoJSON.FeatureCollection = loadJsonFileSync(filepath);
1818
const feature1 = geojson.features[0];
1919
const feature2 = geojson.features[1];
2020
const result = disjoint(feature1, feature2);
@@ -30,7 +30,7 @@ test("turf-boolean-disjoint", (t) => {
3030
.sync(path.join(__dirname, "test", "false", "**", "*.geojson"))
3131
.forEach((filepath) => {
3232
const name = path.parse(filepath).name;
33-
const geojson = loadJsonFileSync(filepath);
33+
const geojson: GeoJSON.FeatureCollection = loadJsonFileSync(filepath);
3434
const feature1 = geojson.features[0];
3535
const feature2 = geojson.features[1];
3636
const result = disjoint(feature1, feature2);
@@ -117,64 +117,95 @@ test("turf-boolean-disjoin with ignoreSelfIntersections option", (t) => {
117117
},
118118
};
119119

120-
// Test without ignoringSelfIntersections option (default behavior)
120+
const selfIntersectingPolygon: GeoJSON.Feature<GeoJSON.Polygon> = {
121+
type: "Feature",
122+
properties: {},
123+
geometry: {
124+
type: "Polygon",
125+
coordinates: [
126+
[
127+
[1.5, 1],
128+
[2, 1.5],
129+
130+
[3, 0.5],
131+
[-1, 3],
132+
[1.5, 1],
133+
],
134+
],
135+
},
136+
};
137+
138+
// Test with ignoringSelfIntersections = true (default behavior)
121139
let result = disjoint(selfIntersectingLineString, nonIntersectingLineString);
122-
t.false(
140+
t.true(
123141
result,
124-
"[false] " +
125-
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
142+
"[true] " +
143+
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
126144
);
127145
result = disjoint(selfIntersectingLineString, intersectingLineString);
128146
t.false(
129147
result,
130148
"[false] " +
131-
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
149+
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
132150
);
133151
result = disjoint(selfIntersectingLineString, intersectingPolygon);
134152
t.false(
135153
result,
136154
"[false] " +
137-
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
155+
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
138156
);
139157
result = disjoint(selfIntersectingLineString, nonIntersectingPolygon);
140-
t.false(
158+
t.true(
141159
result,
142-
"[false] " +
143-
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
160+
"[true] " +
161+
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
162+
);
163+
result = disjoint(selfIntersectingPolygon, nonIntersectingPolygon);
164+
t.true(
165+
result,
166+
"[true] " + "selfIntersectingPolygon-Polygon (ignoreSelfIntersections=true)"
144167
);
145168

146-
// Test with ignoringSelfIntersections option
169+
// Test with ignoringSelfIntersections option set to false
147170
result = disjoint(selfIntersectingLineString, nonIntersectingLineString, {
148-
ignoreSelfIntersections: true,
171+
ignoreSelfIntersections: false,
149172
});
150-
t.true(
173+
t.false(
151174
result,
152-
"[true] " +
153-
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
175+
"[false] " +
176+
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
154177
);
155178
result = disjoint(selfIntersectingLineString, intersectingLineString, {
156-
ignoreSelfIntersections: true,
179+
ignoreSelfIntersections: false,
157180
});
158181
t.false(
159182
result,
160183
"[false] " +
161-
"selfIntersectingLineString-LineString (ignoreSelfIntersections=true)"
184+
"selfIntersectingLineString-LineString (ignoreSelfIntersections=false)"
162185
);
163186
result = disjoint(selfIntersectingLineString, intersectingPolygon, {
164-
ignoreSelfIntersections: true,
187+
ignoreSelfIntersections: false,
165188
});
166189
t.false(
167190
result,
168191
"[false] " +
169-
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
192+
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
170193
);
171194
result = disjoint(selfIntersectingLineString, nonIntersectingPolygon, {
172-
ignoreSelfIntersections: true,
195+
ignoreSelfIntersections: false,
173196
});
174-
t.true(
197+
t.false(
175198
result,
176-
"[true] " +
177-
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=true)"
199+
"[false] " +
200+
"selfIntersectingLineString-Polygon (ignoreSelfIntersections=false)"
201+
);
202+
result = disjoint(selfIntersectingPolygon, nonIntersectingPolygon, {
203+
ignoreSelfIntersections: false,
204+
});
205+
t.false(
206+
result,
207+
"[false] " +
208+
"selfIntersectingPolygon-Polygon (ignoreSelfIntersections=false)"
178209
);
179210

180211
t.end();

0 commit comments

Comments
 (0)