Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/boolean-contains

Package Overview
Dependencies
Maintainers
4
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/boolean-contains - npm Package Compare versions

Comparing version 5.1.5 to 6.0.0

index.ts

147

index.js

@@ -1,6 +0,7 @@

import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import calcBbox from '@turf/bbox';
import isPointOnLine from '@turf/boolean-point-on-line';
import { getGeom, getCoords, getType } from '@turf/invariant';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var boolean_point_in_polygon_1 = require("@turf/boolean-point-in-polygon");
var bbox_1 = require("@turf/bbox");
var boolean_point_on_line_1 = require("@turf/boolean-point-on-line");
var invariant_1 = require("@turf/invariant");
/**

@@ -24,55 +25,54 @@ * Boolean-contains returns True if the second geometry is completely contained by the first geometry.

function booleanContains(feature1, feature2) {
var type1 = getType(feature1);
var type2 = getType(feature2);
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
var coords1 = getCoords(feature1);
var coords2 = getCoords(feature2);
var geom1 = invariant_1.getGeom(feature1);
var geom2 = invariant_1.getGeom(feature2);
var type1 = invariant_1.getType(feature1);
var type2 = invariant_1.getType(feature2);
var coords1 = invariant_1.getCoords(feature1);
var coords2 = invariant_1.getCoords(feature2);
switch (type1) {
case 'Point':
switch (type2) {
case 'Point':
return compareCoords(coords1, coords2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'MultiPoint':
switch (type2) {
case 'Point':
return isPointInMultiPoint(geom1, geom2);
switch (type2) {
case 'Point':
return compareCoords(coords1, coords2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'MultiPoint':
return isMultiPointInMultiPoint(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'LineString':
switch (type2) {
case 'Point':
return isPointOnLine(geom2, geom1, {ignoreEndVertices: true});
switch (type2) {
case 'Point':
return isPointInMultiPoint(geom1, geom2);
case 'MultiPoint':
return isMultiPointInMultiPoint(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'LineString':
return isLineOnLine(geom1, geom2);
case 'MultiPoint':
return isMultiPointOnLine(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'Polygon':
switch (type2) {
case 'Point':
return booleanPointInPolygon(geom2, geom1, {ignoreBoundary: true});
case 'LineString':
return isLineInPoly(geom1, geom2);
switch (type2) {
case 'Point':
return boolean_point_on_line_1.default(geom2, geom1, { ignoreEndVertices: true });
case 'LineString':
return isLineOnLine(geom1, geom2);
case 'MultiPoint':
return isMultiPointOnLine(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'Polygon':
return isPolyInPoly(geom1, geom2);
case 'MultiPoint':
return isMultiPointInPoly(geom1, geom2);
switch (type2) {
case 'Point':
return boolean_point_in_polygon_1.default(geom2, geom1, { ignoreBoundary: true });
case 'LineString':
return isLineInPoly(geom1, geom2);
case 'Polygon':
return isPolyInPoly(geom1, geom2);
case 'MultiPoint':
return isMultiPointInPoly(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
default:
throw new Error('feature1 ' + type1 + ' geometry not supported');
throw new Error('feature1 ' + type1 + ' geometry not supported');
}
}
exports.default = booleanContains;
function isPointInMultiPoint(multiPoint, point) {

@@ -89,3 +89,2 @@ var i;

}
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {

@@ -106,11 +105,9 @@ for (var i = 0; i < multiPoint2.coordinates.length; i++) {

}
function isMultiPointOnLine(lineString, multiPoint) {
var haveFoundInteriorPoint = false;
for (var i = 0; i < multiPoint.coordinates.length; i++) {
if (isPointOnLine(multiPoint.coordinates[i], lineString, {ignoreEndVertices: true})) {
if (boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString, { ignoreEndVertices: true })) {
haveFoundInteriorPoint = true;
}
if (!isPointOnLine(multiPoint.coordinates[i], lineString)) {
if (!boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString)) {
return false;

@@ -124,6 +121,5 @@ }

}
function isMultiPointInPoly(polygon, multiPoint) {
for (var i = 0; i < multiPoint.coordinates.length; i++) {
if (!booleanPointInPolygon(multiPoint.coordinates[i], polygon, {ignoreBoundary: true})) {
if (!boolean_point_in_polygon_1.default(multiPoint.coordinates[i], polygon, { ignoreBoundary: true })) {
return false;

@@ -134,10 +130,9 @@ }

}
function isLineOnLine(lineString1, lineString2) {
var haveFoundInteriorPoint = false;
for (var i = 0; i < lineString2.coordinates.length; i++) {
if (isPointOnLine({type: 'Point', coordinates: lineString2.coordinates[i]}, lineString1, { ignoreEndVertices: true })) {
if (boolean_point_on_line_1.default({ type: 'Point', coordinates: lineString2.coordinates[i] }, lineString1, { ignoreEndVertices: true })) {
haveFoundInteriorPoint = true;
}
if (!isPointOnLine({type: 'Point', coordinates: lineString2.coordinates[i]}, lineString1, {ignoreEndVertices: false })) {
if (!boolean_point_on_line_1.default({ type: 'Point', coordinates: lineString2.coordinates[i] }, lineString1, { ignoreEndVertices: false })) {
return false;

@@ -148,9 +143,7 @@ }

}
function isLineInPoly(polygon, linestring) {
var output = false;
var i = 0;
var polyBbox = calcBbox(polygon);
var lineBbox = calcBbox(linestring);
var polyBbox = bbox_1.default(polygon);
var lineBbox = bbox_1.default(linestring);
if (!doBBoxOverlap(polyBbox, lineBbox)) {

@@ -161,3 +154,3 @@ return false;

var midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
if (booleanPointInPolygon({type: 'Point', coordinates: midPoint}, polygon, { ignoreBoundary: true })) {
if (boolean_point_in_polygon_1.default({ type: 'Point', coordinates: midPoint }, polygon, { ignoreBoundary: true })) {
output = true;

@@ -169,3 +162,2 @@ break;

}
/**

@@ -181,4 +173,4 @@ * Is Polygon2 in Polygon1

function isPolyInPoly(feature1, feature2) {
var poly1Bbox = calcBbox(feature1);
var poly2Bbox = calcBbox(feature2);
var poly1Bbox = bbox_1.default(feature1);
var poly2Bbox = bbox_1.default(feature2);
if (!doBBoxOverlap(poly1Bbox, poly2Bbox)) {

@@ -188,3 +180,3 @@ return false;

for (var i = 0; i < feature2.coordinates[0].length; i++) {
if (!booleanPointInPolygon(feature2.coordinates[0][i], feature1)) {
if (!boolean_point_in_polygon_1.default(feature2.coordinates[0][i], feature1)) {
return false;

@@ -195,11 +187,13 @@ }

}
function doBBoxOverlap(bbox1, bbox2) {
if (bbox1[0] > bbox2[0]) return false;
if (bbox1[2] < bbox2[2]) return false;
if (bbox1[1] > bbox2[1]) return false;
if (bbox1[3] < bbox2[3]) return false;
if (bbox1[0] > bbox2[0])
return false;
if (bbox1[2] < bbox2[2])
return false;
if (bbox1[1] > bbox2[1])
return false;
if (bbox1[3] < bbox2[3])
return false;
return true;
}
/**

@@ -216,7 +210,4 @@ * compareCoords

}
function getMidpoint(pair1, pair2) {
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
}
export default booleanContains;
{
"name": "@turf/boolean-contains",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-contains module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"

@@ -42,3 +37,2 @@ },

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",

@@ -49,16 +43,12 @@ "boolean-jsts": "*",

"load-json-file": "*",
"rollup": "*",
"typescript": "*",
"tape": "*"
},
"dependencies": {
"@turf/bbox": "^5.1.5",
"@turf/boolean-point-in-polygon": "^5.1.5",
"@turf/boolean-point-on-line": "^5.1.5",
"@turf/helpers": "^5.1.5",
"@turf/invariant": "^5.1.5"
},
"@std/esm": {
"esm": "js",
"cjs": true
"@turf/bbox": "6.x",
"@turf/boolean-point-in-polygon": "6.x",
"@turf/boolean-point-on-line": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}
}

@@ -53,1 +53,6 @@ # @turf/boolean-contains

```
### Diagrams
![esri-contains](diagrams/esri-contains.gif)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc