Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve @turf/boolean-overlap performance on MultiPoints #1910

Merged
merged 1 commit into from
Jun 16, 2020
Merged
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
22 changes: 12 additions & 10 deletions packages/turf-boolean-overlap/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { coordAll, segmentEach } from '@turf/meta';
import { segmentEach } from '@turf/meta';
import { getGeom } from '@turf/invariant';
import lineOverlap from '@turf/line-overlap';
import lineIntersect from '@turf/line-intersect';
import GeojsonEquality from 'geojson-equality';
import { Feature, LineString, MultiLineString, Polygon, MultiPolygon, Geometry } from '@turf/helpers';
import { Feature, Geometry, MultiPoint } from '@turf/helpers';

/**
* Compares two geometries of the same dimension and returns true if their intersection set results in a geometry
Expand Down Expand Up @@ -48,14 +48,16 @@ export default function booleanOverlap(

switch (type1) {
case 'MultiPoint':
const coords1 = coordAll(feature1);
const coords2 = coordAll(feature2);
coords1.forEach((coord1) => {
coords2.forEach((coord2) => {
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
});
});
break;
for (var i=0; i<(geom1 as MultiPoint).coordinates.length; i++) {
for (var j=0; j<(geom2 as MultiPoint).coordinates.length; j++) {
var coord1 = geom1.coordinates[i];
var coord2 = geom2.coordinates[j];
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) {
return true;
}
}
}
return false;

case 'LineString':
case 'MultiLineString':
Expand Down