Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/turf-boolean-contains/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import calcBbox from "@turf/bbox";
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
import isPointOnLine from "@turf/boolean-point-on-line";
import difference from '@turf/difference';
import { point } from "@turf/helpers";
import { BBox, Feature, Geometry, LineString, MultiPoint, Point, Polygon } from "@turf/helpers";
import { getCoords, getGeom, getType } from "@turf/invariant";
Expand Down Expand Up @@ -162,8 +163,7 @@ export function isLineInPoly(polygon: Polygon, linestring: LineString) {
}

/**
* Is Polygon2 in Polygon1
* Only takes into account outer rings
* Is Polygon2 in Polygon1?
*
* @private
* @param {Geometry|Feature<Polygon>} feature1 Polygon1
Expand All @@ -189,7 +189,12 @@ export function isPolyInPoly(feature1: Feature<Polygon>|Polygon, feature2: Featu
}
}
}
return true;

//If feature2 is completely contained within feature1
//then subtracting feature1 from feature2 will result in
//a null feature. Otherwise feature2 is not contained.
const diff = difference(feature2, feature1);
return diff === null;
}

export function doBBoxOverlap(bbox1: BBox, bbox2: BBox) {
Expand Down
1 change: 1 addition & 0 deletions packages/turf-boolean-contains/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@turf/bbox": "^6.2.0-alpha.1",
"@turf/boolean-point-in-polygon": "^6.2.0-alpha.1",
"@turf/boolean-point-on-line": "^6.2.0-alpha.1",
"@turf/difference": "^6.2.0-alpha.1",
"@turf/helpers": "^6.2.0-alpha.1",
"@turf/invariant": "^6.2.0-alpha.1"
}
Expand Down
Loading