Socket
Socket
Sign inDemoInstall

@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 6.0.0 to 6.0.1

index.d.ts

120

index.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
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 bbox_1 = __importDefault(require("@turf/bbox"));
var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon"));
var boolean_point_on_line_1 = __importDefault(require("@turf/boolean-point-on-line"));
var invariant_1 = require("@turf/invariant");

@@ -32,52 +35,52 @@ /**

switch (type1) {
case 'Point':
case "Point":
switch (type2) {
case 'Point':
case "Point":
return compareCoords(coords1, coords2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
throw new Error("feature2 " + type2 + " geometry not supported");
}
case 'MultiPoint':
case "MultiPoint":
switch (type2) {
case 'Point':
case "Point":
return isPointInMultiPoint(geom1, geom2);
case 'MultiPoint':
case "MultiPoint":
return isMultiPointInMultiPoint(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
throw new Error("feature2 " + type2 + " geometry not supported");
}
case 'LineString':
case "LineString":
switch (type2) {
case 'Point':
case "Point":
return boolean_point_on_line_1.default(geom2, geom1, { ignoreEndVertices: true });
case 'LineString':
case "LineString":
return isLineOnLine(geom1, geom2);
case 'MultiPoint':
case "MultiPoint":
return isMultiPointOnLine(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
throw new Error("feature2 " + type2 + " geometry not supported");
}
case 'Polygon':
case "Polygon":
switch (type2) {
case 'Point':
case "Point":
return boolean_point_in_polygon_1.default(geom2, geom1, { ignoreBoundary: true });
case 'LineString':
case "LineString":
return isLineInPoly(geom1, geom2);
case 'Polygon':
case "Polygon":
return isPolyInPoly(geom1, geom2);
case 'MultiPoint':
case "MultiPoint":
return isMultiPointInPoly(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
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) {
function isPointInMultiPoint(multiPoint, pt) {
var i;
var output = false;
for (i = 0; i < multiPoint.coordinates.length; i++) {
if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
if (compareCoords(multiPoint.coordinates[i], pt.coordinates)) {
output = true;

@@ -89,7 +92,10 @@ break;

}
exports.isPointInMultiPoint = isPointInMultiPoint;
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
for (var i = 0; i < multiPoint2.coordinates.length; i++) {
for (var _i = 0, _a = multiPoint2.coordinates; _i < _a.length; _i++) {
var coord2 = _a[_i];
var matchFound = false;
for (var i2 = 0; i2 < multiPoint1.coordinates.length; i2++) {
if (compareCoords(multiPoint2.coordinates[i], multiPoint1.coordinates[i2])) {
for (var _b = 0, _c = multiPoint1.coordinates; _b < _c.length; _b++) {
var coord1 = _c[_b];
if (compareCoords(coord2, coord1)) {
matchFound = true;

@@ -105,9 +111,11 @@ break;

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

@@ -121,5 +129,7 @@ }

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

@@ -130,9 +140,11 @@ }

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

@@ -143,2 +155,3 @@ }

}
exports.isLineOnLine = isLineOnLine;
function isLineInPoly(polygon, linestring) {

@@ -154,3 +167,3 @@ var output = false;

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

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

}
exports.isLineInPoly = isLineInPoly;
/**

@@ -173,2 +187,9 @@ * Is Polygon2 in Polygon1

function isPolyInPoly(feature1, feature2) {
// Handle Nulls
if (feature1.type === "Feature" && feature1.geometry === null) {
return false;
}
if (feature2.type === "Feature" && feature2.geometry === null) {
return false;
}
var poly1Bbox = bbox_1.default(feature1);

@@ -179,5 +200,10 @@ var poly2Bbox = bbox_1.default(feature2);

}
for (var i = 0; i < feature2.coordinates[0].length; i++) {
if (!boolean_point_in_polygon_1.default(feature2.coordinates[0][i], feature1)) {
return false;
var coords = invariant_1.getGeom(feature2).coordinates;
for (var _i = 0, coords_1 = coords; _i < coords_1.length; _i++) {
var ring = coords_1[_i];
for (var _a = 0, ring_1 = ring; _a < ring_1.length; _a++) {
var coord = ring_1[_a];
if (!boolean_point_in_polygon_1.default(coord, feature1)) {
return false;
}
}

@@ -187,13 +213,19 @@ }

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

@@ -210,4 +242,6 @@ * compareCoords

}
exports.compareCoords = compareCoords;
function getMidpoint(pair1, pair2) {
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
}
exports.getMidpoint = getMidpoint;
{
"name": "@turf/boolean-contains",
"version": "6.0.0",
"version": "6.0.1",
"description": "turf boolean-contains module",
"main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.ts"
"index.d.ts"
],
"scripts": {
"prepare": "tsc",
"pretest": "tsc",

@@ -43,3 +45,5 @@ "test": "node test.js",

"typescript": "*",
"tape": "*"
"tape": "*",
"tslint": "*",
"@types/tape": "*"
},

@@ -46,0 +50,0 @@ "dependencies": {

@@ -14,4 +14,4 @@ # @turf/boolean-contains

- `feature1` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;any>)** GeoJSON Feature or Geometry
- `feature2` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;any>)** GeoJSON Feature or Geometry
- `feature1` **([Geometry][1] \| [Feature][2]&lt;any>)** GeoJSON Feature or Geometry
- `feature2` **([Geometry][1] \| [Feature][2]&lt;any>)** GeoJSON Feature or Geometry

@@ -28,4 +28,10 @@ **Examples**

Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true/false
Returns **[boolean][3]** true/false
[1]: https://tools.ietf.org/html/rfc7946#section-3.1
[2]: https://tools.ietf.org/html/rfc7946#section-3.2
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
<!-- This file is automatically generated. Please don't edit it directly:

@@ -32,0 +38,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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