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

@turf/intersect

Package Overview
Dependencies
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/intersect - npm Package Compare versions

Comparing version 5.1.6 to 6.0.1

index.ts

58

index.js

@@ -1,8 +0,6 @@

// depend on jsts for now http://bjornharrtell.github.io/jsts/
import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'turf-jsts';
import truncate from '@turf/truncate';
import { getGeom } from '@turf/invariant';
import { feature } from '@turf/helpers';
import cleanCoords from '@turf/clean-coords';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var martinez = require("martinez-polygon-clipping");
var invariant_1 = require("@turf/invariant");
var helpers_1 = require("@turf/helpers");
/**

@@ -14,2 +12,4 @@ * Takes two {@link Polygon|polygons} and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.

* @param {Feature<Polygon>} poly2 the second polygon
* @param {Object} [options={}] Optional Parameters
* @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
* @returns {Feature|null} returns a feature representing the point(s) they share (in case of a {@link Point} or {@link MultiPoint}), the borders they share (in case of a {@link LineString} or a {@link MultiLineString}), the area they share (in case of {@link Polygon} or {@link MultiPolygon}). If they do not share any point, returns `null`.

@@ -41,26 +41,22 @@ * @example

*/
function intersect(poly1, poly2) {
var geom1 = getGeom(poly1);
var geom2 = getGeom(poly2);
// Return null if geometry is too narrow in coordinate precision
// fixes topology errors with JSTS
// https://github.com/Turfjs/turf/issues/463
// https://github.com/Turfjs/turf/pull/1004
if (cleanCoords(truncate(geom2, {precision: 4})).coordinates[0].length < 4) return null;
if (cleanCoords(truncate(geom1, {precision: 4})).coordinates[0].length < 4) return null;
var reader = new GeoJSONReader();
var a = reader.read(truncate(geom1));
var b = reader.read(truncate(geom2));
var intersection = OverlayOp.intersection(a, b);
// https://github.com/Turfjs/turf/issues/951
if (intersection.isEmpty()) return null;
var writer = new GeoJSONWriter();
var geom = writer.write(intersection);
return feature(geom);
function intersect(poly1, poly2, options) {
if (options === void 0) { options = {}; }
var geom1 = invariant_1.getGeom(poly1);
var geom2 = invariant_1.getGeom(poly2);
if (geom1.type !== 'Polygon')
throw new Error('poly1 must be a Polygon');
if (geom2.type !== 'Polygon')
throw new Error('poly2 must be a Polygon');
var intersection = martinez.intersection(geom1.coordinates, geom2.coordinates);
if (intersection === null || intersection.length === 0)
return null;
if (intersection.length === 1) {
var start = intersection[0][0][0];
var end = intersection[0][0][intersection[0][0].length - 1];
if (start[0] === end[0] && start[1] === end[1])
return helpers_1.polygon(intersection[0], options.properties);
return null;
}
return helpers_1.multiPolygon(intersection, options.properties);
}
export default intersect;
exports.default = intersect;
{
"name": "@turf/intersect",
"version": "5.1.6",
"version": "6.0.1",
"description": "turf intersect 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",
"prepare": "tsc",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"

@@ -37,4 +33,4 @@ },

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",

@@ -46,12 +42,6 @@ "rollup": "*",

"dependencies": {
"@turf/clean-coords": "^5.1.5",
"@turf/helpers": "^5.1.5",
"@turf/invariant": "^5.1.5",
"@turf/truncate": "^5.1.5",
"turf-jsts": "*"
},
"@std/esm": {
"esm": "js",
"cjs": true
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"martinez-polygon-clipping": "*"
}
}
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