New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/boolean-within

Package Overview
Dependencies
Maintainers
4
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/boolean-within - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

main.js

13

index.d.ts

@@ -1,10 +0,9 @@

/// <reference types="geojson" />
import { Feature, GeometryObject } from '@turf/helpers'
type Feature = GeoJSON.Feature<any> | GeoJSON.GeometryObject
/**
* http://turfjs.org/docs/#boolean-within
* http://turfjs.org/docs/#booleanwithin
*/
declare function within(feature1: Feature, feature2: Feature): boolean;
declare namespace within { }
export = within;
export default function (
feature1: Feature<any> | GeometryObject,
feature2: Feature<any> | GeometryObject
): boolean;

@@ -1,7 +0,5 @@

var inside = require('@turf/inside');
var calcBbox = require('@turf/bbox');
var invariant = require('@turf/invariant');
var isPointOnLine = require('@turf/boolean-point-on-line');
var getGeom = invariant.getGeom;
var getGeomType = invariant.getGeomType;
import calcBbox from '@turf/bbox';
import booleanPointOnLine from '@turf/boolean-point-on-line';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import { getGeom, getType } from '@turf/invariant';

@@ -19,4 +17,4 @@ /**

* @example
* const line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
* const point = turf.point([1, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
* var point = turf.point([1, 2]);
*

@@ -26,5 +24,5 @@ * turf.booleanWithin(point, line);

*/
module.exports = function (feature1, feature2) {
var type1 = getGeomType(feature1);
var type2 = getGeomType(feature2);
function booleanWithin(feature1, feature2) {
var type1 = getType(feature1);
var type2 = getType(feature2);
var geom1 = getGeom(feature1);

@@ -39,5 +37,5 @@ var geom2 = getGeom(feature2);

case 'LineString':
return isPointOnLine(geom1, geom2, true);
return booleanPointOnLine(geom1, geom2, {ignoreEndVertices: true});
case 'Polygon':
return inside(geom1, geom2, true);
return booleanPointInPolygon(geom1, geom2, {ignoreBoundary: true});
default:

@@ -76,3 +74,3 @@ throw new Error('feature2 ' + type2 + ' geometry not supported');

}
};
}

@@ -110,7 +108,7 @@ function isPointInMultiPoint(point, multiPoint) {

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

@@ -125,3 +123,3 @@ }

for (var i = 0; i < multiPoint.coordinates.length; i++) {
var isInside = inside(multiPoint.coordinates[1], polygon);
var isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon);
if (!isInside) {

@@ -132,3 +130,3 @@ output = false;

if (!oneInside) {
isInside = inside(multiPoint.coordinates[1], polygon, true);
isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon, {ignoreBoundary: true});
}

@@ -141,3 +139,3 @@ }

for (var i = 0; i < lineString1.coordinates.length; i++) {
if (!isPointOnLine(lineString1.coordinates[i], lineString2)) {
if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {
return false;

@@ -158,11 +156,11 @@ }

for (var i = 0; i < linestring.coordinates.length - 1; i++) {
if (!inside(linestring.coordinates[i], polygon)) {
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
return false;
}
if (!foundInsidePoint) {
foundInsidePoint = inside(linestring.coordinates[i], polygon, true);
foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, {ignoreBoundary: true});
}
if (!foundInsidePoint) {
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
foundInsidePoint = inside(midpoint, polygon, true);
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {ignoreBoundary: true});

@@ -190,3 +188,3 @@ }

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

@@ -210,4 +208,4 @@ }

* @private
* @param {[number, number]} pair1 point [x,y]
* @param {[number, number]} pair2 point [x,y]
* @param {Array<number>} pair1 point [x,y]
* @param {Array<number>} pair2 point [x,y]
* @returns {boolean} true/false if coord pairs match

@@ -223,5 +221,5 @@ */

* @private
* @param {[number, number]} pair1 point [x,y]
* @param {[number, number]} pair2 point [x,y]
* @returns {[number, number]} midpoint of pair1 and pair2
* @param {Array<number>} pair1 point [x,y]
* @param {Array<number>} pair2 point [x,y]
* @returns {Array<number>} midpoint of pair1 and pair2
*/

@@ -231,1 +229,3 @@ function getMidpoint(pair1, pair2) {

}
export default booleanWithin;
{
"name": "@turf/boolean-within",
"version": "4.7.3",
"version": "5.0.4",
"description": "turf boolean-within module",
"main": "index.js",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"main.js"
],
"scripts": {
"test": "node test.js",
"bench": "node bench.js"
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
},

@@ -37,16 +41,22 @@ "repository": {

"devDependencies": {
"@turf/helpers": "^4.7.3",
"benchmark": "2.1.4",
"boolean-jsts": "0.0.1",
"boolean-shapely": "0.1.2",
"glob": "7.1.2",
"load-json-file": "2.0.0",
"tape": "4.8.0"
"@std/esm": "*",
"benchmark": "*",
"boolean-jsts": "*",
"boolean-shapely": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*"
},
"dependencies": {
"@turf/bbox": "^4.7.3",
"@turf/boolean-point-on-line": "^4.7.3",
"@turf/inside": "^4.7.3",
"@turf/invariant": "^4.7.3"
"@turf/bbox": "^5.0.4",
"@turf/boolean-point-in-polygon": "^5.0.4",
"@turf/boolean-point-on-line": "^5.0.4",
"@turf/helpers": "^5.0.4",
"@turf/invariant": "^5.0.4"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}
# @turf/boolean-within
# booleanWithin
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## booleanWithin
Boolean-within returns true if the first geometry is completely within the second geometry.

@@ -18,4 +20,4 @@ The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)

```javascript
const line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
const point = turf.point([1, 2]);
var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
var point = turf.point([1, 2]);

@@ -22,0 +24,0 @@ turf.booleanWithin(point, line);

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