Skip to content

Commit

Permalink
Merge pull request #1910 from Turfjs/mf/boolean-overlap-perf
Browse files Browse the repository at this point in the history
Improve @turf/boolean-overlap performance on MultiPoints
  • Loading branch information
rowanwins authored Jun 16, 2020
2 parents 3fa082c + 82eb8d9 commit 9f151a5
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit 9f151a5

Please sign in to comment.