mirror of
https://github.com/Turfjs/turf.git
synced 2025-12-08 20:26:16 +00:00
Reverted self intersection behavior of boolean-intersect. update tests (#2773)
Co-authored-by: James Beard <james@smallsaucepan.com>
This commit is contained in:
parent
5a9d40d496
commit
d1a2c5857f
@ -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) => {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user