From eee8456710a93e6180b0e79dfc9caf2823450095 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Tue, 20 Jun 2017 22:45:44 +1000 Subject: [PATCH 1/8] Initial commit od boolean-disjoint --- packages/turf-boolean-disjoint/LICENSE | 20 ++ packages/turf-boolean-disjoint/README.md | 60 +++++ packages/turf-boolean-disjoint/bench.js | 43 ++++ packages/turf-boolean-disjoint/index.d.ts | 10 + packages/turf-boolean-disjoint/index.js | 207 +++++++++++++++++ packages/turf-boolean-disjoint/package.json | 48 ++++ packages/turf-boolean-disjoint/test.js | 30 +++ .../false/LineIsNotDisjointFromLine.geojson | 21 ++ .../LineIsNotDisjointFromPolygon.geojson | 21 ++ .../MultiPointNotDisjointFromLine.geojson | 21 ++ ...ultiPointNotDisjointFromMultipoint.geojson | 21 ++ .../MultiPointNotDisjointFromPoly.geojson | 21 ++ .../PointIsNotDisjointFromLineString.geojson | 21 ++ .../PointNotDisjointFromInternalPoly.geojson | 21 ++ .../PointNotDisjointFromMultipoint.geojson | 21 ++ .../false/PointNotDisjointFromPoint.geojson | 21 ++ .../false/PointNotDisjointFromPoly.geojson | 21 ++ .../false/PolyIsNotDisjointFromPoly.geojson | 21 ++ .../test/true/LineIsDisjointFromLine.geojson | 21 ++ .../true/LineIsDisjointFromPolygon.geojson | 21 ++ .../true/MultiPointDisjointFromLine.geojson | 21 ++ .../MultiPointDisjointFromMultipoint.geojson | 21 ++ .../true/MultiPointIsDisjointFromPoly.geojson | 21 ++ .../true/PointDisjointFromMultipoint.geojson | 21 ++ .../test/true/PointDisjointFromPoint.geojson | 21 ++ .../PointIsDisjointFromLinestring.geojson | 21 ++ .../test/true/PointIsDisjointFromPoly.geojson | 21 ++ .../test/true/PolyIsDisjointFromPoly.geojson | 21 ++ packages/turf-boolean-disjoint/yarn.lock | 219 ++++++++++++++++++ 29 files changed, 1078 insertions(+) create mode 100644 packages/turf-boolean-disjoint/LICENSE create mode 100644 packages/turf-boolean-disjoint/README.md create mode 100644 packages/turf-boolean-disjoint/bench.js create mode 100644 packages/turf-boolean-disjoint/index.d.ts create mode 100644 packages/turf-boolean-disjoint/index.js create mode 100644 packages/turf-boolean-disjoint/package.json create mode 100644 packages/turf-boolean-disjoint/test.js create mode 100644 packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson create mode 100644 packages/turf-boolean-disjoint/yarn.lock diff --git a/packages/turf-boolean-disjoint/LICENSE b/packages/turf-boolean-disjoint/LICENSE new file mode 100644 index 0000000000..96ce51b76f --- /dev/null +++ b/packages/turf-boolean-disjoint/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 TurfJS + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/turf-boolean-disjoint/README.md b/packages/turf-boolean-disjoint/README.md new file mode 100644 index 0000000000..06492271f6 --- /dev/null +++ b/packages/turf-boolean-disjoint/README.md @@ -0,0 +1,60 @@ +# @turf/boolean-disjoint + +# booleanDisjoint + +Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. + +**Parameters** + +- `feature1` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** GeoJSON Feature or Geometry +- `feature2` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** GeoJSON Feature or Geometry + +**Examples** + +```javascript +const point = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [2, 2] + } +} +const line = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } +} +turf.booleanDisjoint(line, point); +//=true +``` + +Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true/false + + + +--- + +This module is part of the [Turfjs project](http://turfjs.org/), an open source +module collection dedicated to geographic algorithms. It is maintained in the +[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create +PRs and issues. + +### Installation + +Install this module individually: + +```sh +$ npm install @turf/boolean-disjoint +``` + +Or install the Turf module that includes it as a function: + +```sh +$ npm install @turf/turf +``` diff --git a/packages/turf-boolean-disjoint/bench.js b/packages/turf-boolean-disjoint/bench.js new file mode 100644 index 0000000000..3560b30a44 --- /dev/null +++ b/packages/turf-boolean-disjoint/bench.js @@ -0,0 +1,43 @@ +const path = require('path'); +const glob = require('glob'); +const Benchmark = require('benchmark'); +const load = require('load-json-file'); +const disjoint = require('./'); + +/** + * Benchmark Results + * + * LineIsNotDisjointFromLine x 50,655 ops/sec ±3.66% (63 runs sampled) + * LineIsNotDisjointFromPolygon x 49,947 ops/sec ±2.79% (42 runs sampled) + * MultiPointNotDisjointFromLine x 7,431,677 ops/sec ±1.24% (85 runs sampled) + * MultiPointNotDisjointFromMultipoint x 7,399,444 ops/sec ±0.99% (87 runs sampled) + * MultiPointNotDisjointFromPoly x 2,298,298 ops/sec ±1.02% (88 runs sampled) + * PointIsNotDisjointFromLineString x 10,068,082 ops/sec ±1.02% (89 runs sampled) + * PointNotDisjointFromInternalPoly x 2,136,512 ops/sec ±1.24% (87 runs sampled) + * PointNotDisjointFromMultipoint x 10,712,566 ops/sec ±0.98% (88 runs sampled) + * PointNotDisjointFromPoint x 16,663,034 ops/sec ±0.98% (88 runs sampled) + * PointNotDisjointFromPoly x 2,509,098 ops/sec ±1.06% (87 runs sampled) + * PolyIsNotDisjointFromPoly x 2,078,010 ops/sec ±1.60% (85 runs sampled) + * LineIsDisjointFromLine x 62,985 ops/sec ±4.13% (64 runs sampled) + * LineIsDisjointFromPolygon x 58,937 ops/sec ±2.84% (62 runs sampled) + * MultiPointDisjointFromLine x 4,634,718 ops/sec ±1.94% (85 runs sampled) + * MultiPointDisjointFromMultipoint x 6,602,132 ops/sec ±3.76% (81 runs sampled) + * MultiPointIsDisjointFromPoly x 1,203,406 ops/sec ±1.01% (87 runs sampled) + * PointDisjointFromMultipoint x 11,373,917 ops/sec ±1.33% (87 runs sampled) + * PointDisjointFromPoint x 18,149,666 ops/sec ±1.10% (85 runs sampled) + * PointIsDisjointFromLinestring x 7,572,815 ops/sec ±0.97% (89 runs sampled) + * PointIsDisjointFromPoly x 2,217,658 ops/sec ±1.04% (83 runs sampled) + * PolyIsDisjointFromPoly x 551,254 ops/sec ±1.18% (90 runs sampled) + */ +const suite = new Benchmark.Suite('turf-boolean-disjoint'); +glob.sync(path.join(__dirname, 'test', '**', '*.geojson')).forEach(filepath => { + const {name} = path.parse(filepath); + const geojson = load.sync(filepath); + const [feature1, feature2] = geojson.features; + suite.add(name, () => disjoint(feature1, feature2)); +}); + +suite + .on('cycle', e => console.log(String(e.target))) + .on('complete', () => {}) + .run(); diff --git a/packages/turf-boolean-disjoint/index.d.ts b/packages/turf-boolean-disjoint/index.d.ts new file mode 100644 index 0000000000..c84b6cf520 --- /dev/null +++ b/packages/turf-boolean-disjoint/index.d.ts @@ -0,0 +1,10 @@ +/// + +type Feature = GeoJSON.Feature | GeoJSON.GeometryObject; + +/** + * http://turfjs.org/docs/#boolean-disjoint + */ +declare function booleanDisjoint(feature1: Feature, feature2: Feature): boolean; +declare namespace booleanDisjoint { } +export = booleanDisjoint; diff --git a/packages/turf-boolean-disjoint/index.js b/packages/turf-boolean-disjoint/index.js new file mode 100644 index 0000000000..d0b5a7dad3 --- /dev/null +++ b/packages/turf-boolean-disjoint/index.js @@ -0,0 +1,207 @@ +var inside = require('@turf/inside'); +var lineIntersect = require('@turf/line-intersect'); +var polyToLinestring = require('@turf/polygon-to-linestring'); +var invariant = require('@turf/invariant'); +var getGeom = invariant.getGeom; +var getGeomType = invariant.getGeomType; +var getCoords = invariant.getCoords; + +/** + * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. + * + * @name booleanDisjoint + * @param {Geometry|Feature} feature1 GeoJSON Feature or Geometry + * @param {Geometry|Feature} feature2 GeoJSON Feature or Geometry + * @returns {Boolean} true/false + * @example + * const point = { + * "type": "Feature", + * "properties": {}, + * "geometry": { + * "type": "Point", + * "coordinates": [2, 2] + * } + * } + * const line = { + * "type": "Feature", + * "properties": {}, + * "geometry": { + * "type": "LineString", + * "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + * } + * } + * turf.booleanDisjoint(line, point); + * //=true + */ +module.exports = function (feature1, feature2) { + var type1 = getGeomType(feature1); + var type2 = getGeomType(feature2); + var geom1 = getGeom(feature1); + var geom2 = getGeom(feature2); + var coords1 = getCoords(feature1); + var coords2 = getCoords(feature2); + + switch (type1) { + case 'Point': + switch (type2) { + case 'Point': + return !compareCoords(coords1, coords2) || false; + case 'MultiPoint': + return !isPointInMultiPoint(geom2, geom1) || false; + case 'LineString': + return !isPointOnLine(geom2, geom1) || false; + case 'Polygon': + return !inside(geom1, geom2) || false; + } + break; + case 'MultiPoint': + switch (type2) { + case 'Point': + return !isPointInMultiPoint(coords1, coords2) || false; + case 'MultiPoint': + return !isMultiPointInMultiPoint(geom1, geom2) || false; + case 'LineString': + return !isMultiPointOnLine(geom2, geom1) || false; + case 'Polygon': + return !isMultiPointInPoly(geom2, geom1) || false; + } + break; + case 'LineString': + switch (type2) { + case 'Point': + return !isPointOnLine(geom1, geom2) || false; + case 'MultiPoint': + return !isMultiPointOnLine(geom1, geom2) || false; + case 'LineString': + return !isLineOnLine(geom1, geom2) || false; + case 'Polygon': + return !isLineInPoly(geom2, geom1) || false; + } + break; + case 'Polygon': + switch (type2) { + case 'Point': + return !inside(geom2, geom1) || false; + case 'MultiPoint': + return !isMultiPointInPoly(geom1, geom2) || false; + case 'LineString': + return !isLineInPoly(geom1, geom2) || false; + case 'Polygon': + return !isPolyInPoly(geom2, geom1) || false; + } + break; + } +}; + +function isPointInMultiPoint(multiPoint, point) { + for (var i = 0; i < multiPoint.coordinates.length; i++) { + if (compareCoords(multiPoint.coordinates[i], point.coordinates)) { + return true; + } + } + return false; +} + +function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { + for (var i = 0; i < multiPoint2.coordinates.length; i++) { + for (var i2 = 0; i2 < multiPoint1.coordinates.length; i2++) { + if (compareCoords(multiPoint2.coordinates[i], multiPoint1.coordinates[i2])) { + return true; + } + } + } + return false; +} + +// http://stackoverflow.com/a/11908158/1979085 +function isPointOnLine(lineString, point) { + for (var i = 0; i < lineString.coordinates.length - 1; i++) { + if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], point.coordinates)) { + return true; + } + } + return false; +} + +function isMultiPointOnLine(lineString, multiPoint) { + for (var i = 0; i < multiPoint.coordinates.length; i++) { + for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) { + if (isPointOnLineSegment(lineString.coordinates[i2], lineString.coordinates[i2 + 1], multiPoint.coordinates[i])) { + return true; + } + } + } + return false; +} + +function isMultiPointInPoly(polygon, multiPoint) { + for (var i = 0; i < multiPoint.coordinates.length; i++) { + if (inside(multiPoint.coordinates[i], polygon)) { + return true; + } + } + return false; +} + +function isLineOnLine(lineString1, lineString2) { + var doLinesIntersect = lineIntersect(lineString1, lineString2); + if (doLinesIntersect.features.length > 0) { + return true; + } + return false; +} + +function isLineInPoly(polygon, lineString) { + var doLinesIntersect = lineIntersect(lineString, polyToLinestring(polygon)); + if (doLinesIntersect.features.length > 0) { + return true; + } + return false; +} + +// /** +// * Is Polygon (geom1) in Polygon (geom2) +// * Only takes into account outer rings +// * See http://stackoverflow.com/a/4833823/1979085 +// * +// * @private +// * @param {Geometry|Feature} feature1 Polygon1 +// * @param {Geometry|Feature} feature2 Polygon2 +// * @returns {Boolean} true/false +// */ +function isPolyInPoly(feature1, feature2) { + for (var i = 0; i < feature1.coordinates[0].length; i++) { + if (inside(feature1.coordinates[0][i], feature2)) { + return true; + } + } + return false; +} + +function isPointOnLineSegment(LineSegmentStart, LineSegmentEnd, Point) { + var dxc = Point[0] - LineSegmentStart[0]; + var dyc = Point[1] - LineSegmentStart[1]; + var dxl = LineSegmentEnd[0] - LineSegmentStart[0]; + var dyl = LineSegmentEnd[1] - LineSegmentStart[1]; + var cross = dxc * dyl - dyc * dxl; + if (cross !== 0) { + return false; + } + if (Math.abs(dxl) >= Math.abs(dyl)) { + return dxl > 0 ? LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0] : LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; + } else { + return dyl > 0 ? LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1] : LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1]; + } +} + +/** + * compareCoords + * + * @private + * @param {[number, number]} pair1 point [x,y] + * @param {[number, number]} pair2 point [x,y] + * @returns {boolean} true/false if coord pairs match + */ +function compareCoords(pair1, pair2) { + return pair1[0] === pair2[0] && pair1[1] === pair2[1]; +} diff --git a/packages/turf-boolean-disjoint/package.json b/packages/turf-boolean-disjoint/package.json new file mode 100644 index 0000000000..2ffbb4542c --- /dev/null +++ b/packages/turf-boolean-disjoint/package.json @@ -0,0 +1,48 @@ +{ + "name": "@turf/boolean-disjoint", + "version": "4.0.0", + "description": "turf boolean-disjoint module", + "main": "index.js", + "types": "index.d.ts", + "files": [ + "index.js", + "index.d.ts" + ], + "scripts": { + "test": "node test.js", + "bench": "node bench.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/Turfjs/turf.git" + }, + "keywords": [ + "turf", + "disjoint", + "boolean", + "de-9im" + ], + "author": "Turf Authors", + "contributors": [ + "Rowan Winsemius <@rowanwins>", + "Denis Carriere <@DenisCarriere>" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/Turfjs/turf/issues" + }, + "homepage": "https://github.com/Turfjs/turf", + "devDependencies": { + "@turf/helpers": "^4.3.0", + "benchmark": "^2.1.4", + "boolean-shapely": "^0.1.2", + "load-json-file": "^2.0.0", + "tape": "^4.6.3" + }, + "dependencies": { + "@turf/inside": "^4.4.0", + "@turf/invariant": "^4.3.0", + "@turf/line-intersect": "^4.4.0", + "@turf/polygon-to-linestring": "^4.4.0" + } +} diff --git a/packages/turf-boolean-disjoint/test.js b/packages/turf-boolean-disjoint/test.js new file mode 100644 index 0000000000..12993767b2 --- /dev/null +++ b/packages/turf-boolean-disjoint/test.js @@ -0,0 +1,30 @@ +const glob = require('glob'); +const path = require('path'); +const test = require('tape'); +const load = require('load-json-file'); +const shapely = require('boolean-shapely'); +const disjoint = require('./'); + +test('turf-boolean-disjoint', t => { + // True Fixtures + glob.sync(path.join(__dirname, 'test', 'true', '*.geojson')).forEach(filepath => { + const {name} = path.parse(filepath); + const geojson = load.sync(filepath); + const [feature1, feature2] = geojson.features; + const result = disjoint(feature1, feature2); + + if (process.env.SHAPELY) shapely.disjoint(feature1, feature2).then(result => t.true(result, '[true] shapely - ' + name)); + t.true(result, '[true] ' + name); + }); + // False Fixtures + glob.sync(path.join(__dirname, 'test', 'false', '*.geojson')).forEach(filepath => { + const {name} = path.parse(filepath); + const geojson = load.sync(filepath); + const [feature1, feature2] = geojson.features; + const result = disjoint(feature1, feature2); + + if (process.env.SHAPELY) shapely.disjoint(feature1, feature2).then(result => t.false(result, '[false] shapely - ' + name)); + t.false(result, '[false] ' + name); + }); + t.end(); +}); diff --git a/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson new file mode 100644 index 0000000000..01ba117caf --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 2], [12, 2], [12, 3], [12, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson b/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson new file mode 100644 index 0000000000..f0c7049cc8 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 2], [12, 2], [12, 3], [12, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson new file mode 100644 index 0000000000..f753cc5a82 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [0, 0]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson new file mode 100644 index 0000000000..913aac0816 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[0, 0], [12, 12]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [12, 12]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson new file mode 100644 index 0000000000..e076953538 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[-1, 2], [-2, -2]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson b/packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson new file mode 100644 index 0000000000..d4d803a59f --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson new file mode 100644 index 0000000000..50ebfc7dfe --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 2.5] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson new file mode 100644 index 0000000000..466b100c0e --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [12, 12]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson new file mode 100644 index 0000000000..82d30f2b40 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson new file mode 100644 index 0000000000..db92015c7d --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [-1, 2] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson new file mode 100644 index 0000000000..56ffd84279 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [-13, -12], [-13, -13], [-11, -13], [-1, 2]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson new file mode 100644 index 0000000000..e908d9ffd1 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 0], [12, 2], [12, 3], [12, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson b/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson new file mode 100644 index 0000000000..5e17fddff9 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 0], [12, 2], [12, 3], [12, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson new file mode 100644 index 0000000000..1d01a11c0f --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[2, 2], [0, 0]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson new file mode 100644 index 0000000000..a73c473c4e --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[0, 0], [13, 13]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [12, 12]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson new file mode 100644 index 0000000000..fb002538d3 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[-3, -3], [-2, -2]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson new file mode 100644 index 0000000000..2c0beca26c --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [12, 12]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson b/packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson new file mode 100644 index 0000000000..48bb68a8d7 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 1] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson b/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson new file mode 100644 index 0000000000..331ecb6cb1 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson new file mode 100644 index 0000000000..a4ea587a2a --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson new file mode 100644 index 0000000000..23faeb9a4b --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-11, -12], [-13, -12], [-13, -13], [-11, -13], [-11, -12]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/yarn.lock b/packages/turf-boolean-disjoint/yarn.lock new file mode 100644 index 0000000000..18f6925131 --- /dev/null +++ b/packages/turf-boolean-disjoint/yarn.lock @@ -0,0 +1,219 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@turf/helpers@^4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.3.0.tgz#7b2f733aa0eb3ea1f07d467ac02ede00cc6cde0d" + +"@turf/inside@^4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@turf/inside/-/inside-4.3.0.tgz#ba06be5966a5ab31c1cabb9819241e0802422c45" + dependencies: + "@turf/invariant" "^4.3.0" + +"@turf/invariant@^4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.3.0.tgz#5bd1ce6ae51b1229dc0dc7d09d973fabae49af89" + +balanced-match@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" + +benchmark@^2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629" + dependencies: + lodash "^4.17.4" + platform "^1.3.3" + +brace-expansion@^1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" + dependencies: + balanced-match "^0.4.1" + concat-map "0.0.1" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +deep-equal@^1.0.1, deep-equal@~1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" + +define-properties@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94" + dependencies: + foreach "^2.0.5" + object-keys "^1.0.8" + +defined@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" + +es-abstract@^1.5.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.7.0.tgz#dfade774e01bfcd97f96180298c449c8623fb94c" + dependencies: + es-to-primitive "^1.1.1" + function-bind "^1.1.0" + is-callable "^1.1.3" + is-regex "^1.0.3" + +es-to-primitive@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d" + dependencies: + is-callable "^1.1.1" + is-date-object "^1.0.1" + is-symbol "^1.0.1" + +for-each@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.2.tgz#2c40450b9348e97f281322593ba96704b9abd4d4" + dependencies: + is-function "~1.0.0" + +foreach@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +function-bind@^1.0.2, function-bind@^1.1.0, function-bind@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" + +glob@~7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + +has@^1.0.1, has@~1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28" + dependencies: + function-bind "^1.0.2" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +is-callable@^1.1.1, is-callable@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2" + +is-date-object@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16" + +is-function@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-function/-/is-function-1.0.1.tgz#12cfb98b65b57dd3d193a3121f5f6e2f437602b5" + +is-regex@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" + dependencies: + has "^1.0.1" + +is-symbol@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572" + +lodash@^4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + +minimatch@^3.0.2: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + dependencies: + brace-expansion "^1.1.7" + +minimist@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + +object-inspect@~1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.2.2.tgz#c82115e4fcc888aea14d64c22e4f17f6a70d5e5a" + +object-keys@^1.0.8: + version "1.0.11" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +platform@^1.3.3: + version "1.3.4" + resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.4.tgz#6f0fb17edaaa48f21442b3a975c063130f1c3ebd" + +resolve@~1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" + +resumer@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/resumer/-/resumer-0.0.0.tgz#f1e8f461e4064ba39e82af3cdc2a8c893d076759" + dependencies: + through "~2.3.4" + +string.prototype.trim@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz#d04de2c89e137f4d7d206f086b5ed2fae6be8cea" + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.0" + function-bind "^1.0.2" + +tape@^4.6.3: + version "4.6.3" + resolved "https://registry.yarnpkg.com/tape/-/tape-4.6.3.tgz#637e77581e9ab2ce17577e9bd4ce4f575806d8b6" + dependencies: + deep-equal "~1.0.1" + defined "~1.0.0" + for-each "~0.3.2" + function-bind "~1.1.0" + glob "~7.1.1" + has "~1.0.1" + inherits "~2.0.3" + minimist "~1.2.0" + object-inspect "~1.2.1" + resolve "~1.1.7" + resumer "~0.0.0" + string.prototype.trim "~1.1.2" + through "~2.3.8" + +through@~2.3.4, through@~2.3.8: + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From 504c3c15ff4a2f72a96e0aa49b893d178efd10ff Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 10:14:13 -0400 Subject: [PATCH 2/8] Update boolean-disjoint - Drop `|| false` from `index.js` - Remove extra comments - Add single process benchmark --- packages/turf-boolean-disjoint/bench.js | 24 ++++ packages/turf-boolean-disjoint/index.js | 56 +++++----- packages/turf-boolean-disjoint/yarn.lock | 134 ++++++++++++++++++++++- 3 files changed, 181 insertions(+), 33 deletions(-) diff --git a/packages/turf-boolean-disjoint/bench.js b/packages/turf-boolean-disjoint/bench.js index 3560b30a44..0f5c687797 100644 --- a/packages/turf-boolean-disjoint/bench.js +++ b/packages/turf-boolean-disjoint/bench.js @@ -7,6 +7,27 @@ const disjoint = require('./'); /** * Benchmark Results * + * LineIsNotDisjointFromLine: 3.464ms + * LineIsNotDisjointFromPolygon: 1.199ms + * MultiPointNotDisjointFromLine: 0.213ms + * MultiPointNotDisjointFromMultipoint: 0.193ms + * MultiPointNotDisjointFromPoly: 1.468ms + * PointIsNotDisjointFromLineString: 0.184ms + * PointNotDisjointFromInternalPoly: 0.651ms + * PointNotDisjointFromMultipoint: 0.165ms + * PointNotDisjointFromPoint: 0.020ms + * PointNotDisjointFromPoly: 0.025ms + * PolyIsNotDisjointFromPoly: 0.209ms + * LineIsDisjointFromLine: 0.280ms + * LineIsDisjointFromPolygon: 0.230ms + * MultiPointDisjointFromLine: 0.046ms + * MultiPointDisjointFromMultipoint: 0.015ms + * MultiPointIsDisjointFromPoly: 0.034ms + * PointDisjointFromMultipoint: 0.155ms + * PointDisjointFromPoint: 0.021ms + * PointIsDisjointFromLinestring: 0.962ms + * PointIsDisjointFromPoly: 0.131ms + * PolyIsDisjointFromPoly: 0.080ms * LineIsNotDisjointFromLine x 50,655 ops/sec ±3.66% (63 runs sampled) * LineIsNotDisjointFromPolygon x 49,947 ops/sec ±2.79% (42 runs sampled) * MultiPointNotDisjointFromLine x 7,431,677 ops/sec ±1.24% (85 runs sampled) @@ -34,6 +55,9 @@ glob.sync(path.join(__dirname, 'test', '**', '*.geojson')).forEach(filepath => { const {name} = path.parse(filepath); const geojson = load.sync(filepath); const [feature1, feature2] = geojson.features; + console.time(name); + disjoint(feature1, feature2); + console.timeEnd(name); suite.add(name, () => disjoint(feature1, feature2)); }); diff --git a/packages/turf-boolean-disjoint/index.js b/packages/turf-boolean-disjoint/index.js index d0b5a7dad3..fe41ea570c 100644 --- a/packages/turf-boolean-disjoint/index.js +++ b/packages/turf-boolean-disjoint/index.js @@ -1,10 +1,10 @@ var inside = require('@turf/inside'); +var invariant = require('@turf/invariant'); var lineIntersect = require('@turf/line-intersect'); var polyToLinestring = require('@turf/polygon-to-linestring'); -var invariant = require('@turf/invariant'); var getGeom = invariant.getGeom; -var getGeomType = invariant.getGeomType; var getCoords = invariant.getCoords; +var getGeomType = invariant.getGeomType; /** * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. @@ -45,49 +45,49 @@ module.exports = function (feature1, feature2) { case 'Point': switch (type2) { case 'Point': - return !compareCoords(coords1, coords2) || false; + return !compareCoords(coords1, coords2); case 'MultiPoint': - return !isPointInMultiPoint(geom2, geom1) || false; + return !isPointInMultiPoint(geom2, geom1); case 'LineString': - return !isPointOnLine(geom2, geom1) || false; + return !isPointOnLine(geom2, geom1); case 'Polygon': - return !inside(geom1, geom2) || false; + return !inside(geom1, geom2); } break; case 'MultiPoint': switch (type2) { case 'Point': - return !isPointInMultiPoint(coords1, coords2) || false; + return !isPointInMultiPoint(coords1, coords2); case 'MultiPoint': - return !isMultiPointInMultiPoint(geom1, geom2) || false; + return !isMultiPointInMultiPoint(geom1, geom2); case 'LineString': - return !isMultiPointOnLine(geom2, geom1) || false; + return !isMultiPointOnLine(geom2, geom1); case 'Polygon': - return !isMultiPointInPoly(geom2, geom1) || false; + return !isMultiPointInPoly(geom2, geom1); } break; case 'LineString': switch (type2) { case 'Point': - return !isPointOnLine(geom1, geom2) || false; + return !isPointOnLine(geom1, geom2); case 'MultiPoint': - return !isMultiPointOnLine(geom1, geom2) || false; + return !isMultiPointOnLine(geom1, geom2); case 'LineString': - return !isLineOnLine(geom1, geom2) || false; + return !isLineOnLine(geom1, geom2); case 'Polygon': - return !isLineInPoly(geom2, geom1) || false; + return !isLineInPoly(geom2, geom1); } break; case 'Polygon': switch (type2) { case 'Point': - return !inside(geom2, geom1) || false; + return !inside(geom2, geom1); case 'MultiPoint': - return !isMultiPointInPoly(geom1, geom2) || false; + return !isMultiPointInPoly(geom1, geom2); case 'LineString': - return !isLineInPoly(geom1, geom2) || false; + return !isLineInPoly(geom1, geom2); case 'Polygon': - return !isPolyInPoly(geom2, geom1) || false; + return !isPolyInPoly(geom2, geom1); } break; } @@ -159,16 +159,16 @@ function isLineInPoly(polygon, lineString) { return false; } -// /** -// * Is Polygon (geom1) in Polygon (geom2) -// * Only takes into account outer rings -// * See http://stackoverflow.com/a/4833823/1979085 -// * -// * @private -// * @param {Geometry|Feature} feature1 Polygon1 -// * @param {Geometry|Feature} feature2 Polygon2 -// * @returns {Boolean} true/false -// */ +/** + * Is Polygon (geom1) in Polygon (geom2) + * Only takes into account outer rings + * See http://stackoverflow.com/a/4833823/1979085 + * + * @private + * @param {Geometry|Feature} feature1 Polygon1 + * @param {Geometry|Feature} feature2 Polygon2 + * @returns {Boolean} true/false + */ function isPolyInPoly(feature1, feature2) { for (var i = 0; i < feature1.coordinates[0].length; i++) { if (inside(feature1.coordinates[0][i], feature2)) { diff --git a/packages/turf-boolean-disjoint/yarn.lock b/packages/turf-boolean-disjoint/yarn.lock index 18f6925131..ab1ed5da4b 100644 --- a/packages/turf-boolean-disjoint/yarn.lock +++ b/packages/turf-boolean-disjoint/yarn.lock @@ -2,20 +2,77 @@ # yarn lockfile v1 +"@turf/bbox-polygon@^4.3.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/bbox-polygon/-/bbox-polygon-4.4.0.tgz#40b17ed063f0722e7407dcd6fad03bfce57b5a15" + dependencies: + "@turf/helpers" "^4.4.0" + +"@turf/bbox@^3.10.5": + version "3.14.0" + resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-3.14.0.tgz#cee5f396dde78aca9cede05e1122db18bc504635" + dependencies: + "@turf/meta" "^3.14.0" + +"@turf/helpers@^3.10.5": + version "3.13.0" + resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-3.13.0.tgz#d06078a1464cf56cdb7ea624ea1e13a71b88b806" + "@turf/helpers@^4.3.0": version "4.3.0" resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.3.0.tgz#7b2f733aa0eb3ea1f07d467ac02ede00cc6cde0d" -"@turf/inside@^4.3.0": - version "4.3.0" - resolved "https://registry.yarnpkg.com/@turf/inside/-/inside-4.3.0.tgz#ba06be5966a5ab31c1cabb9819241e0802422c45" +"@turf/helpers@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.4.0.tgz#c83112f7fbe6ed183c7c0c2f776481b94d1cbd01" + +"@turf/inside@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/inside/-/inside-4.4.0.tgz#5a78de2c0ed9a68b494508f53ae2f4b73dd770ef" dependencies: - "@turf/invariant" "^4.3.0" + "@turf/invariant" "^4.4.0" "@turf/invariant@^4.3.0": version "4.3.0" resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.3.0.tgz#5bd1ce6ae51b1229dc0dc7d09d973fabae49af89" +"@turf/invariant@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.4.0.tgz#aac0afb840ae40908f9c80393f416222dcf79c32" + +"@turf/line-intersect@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/line-intersect/-/line-intersect-4.4.0.tgz#aa6040a456737a3a5098d538b4bb20d051845195" + dependencies: + "@turf/helpers" "^4.4.0" + "@turf/invariant" "^4.4.0" + "@turf/line-segment" "^4.4.0" + "@turf/meta" "^4.4.0" + geojson-rbush "^1.0.1" + +"@turf/line-segment@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/line-segment/-/line-segment-4.4.0.tgz#660fc0bdced64334c38d55c5a562800c67ffa3ec" + dependencies: + "@turf/helpers" "^4.4.0" + "@turf/invariant" "^4.4.0" + "@turf/meta" "^4.4.0" + +"@turf/meta@^3.10.5", "@turf/meta@^3.14.0": + version "3.14.0" + resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-3.14.0.tgz#8d3050c1a0f44bf406a633b6bd28c510f7bcee27" + +"@turf/meta@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.4.0.tgz#4fa25d4cc0525bd4cdbaf4ff68a6f8ae81f1975f" + +"@turf/polygon-to-linestring@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@turf/polygon-to-linestring/-/polygon-to-linestring-4.4.0.tgz#c6fdbb75fec42d9aad9b9dd0eb1cf07e8c121403" + dependencies: + "@turf/helpers" "^4.4.0" + "@turf/invariant" "^4.4.0" + balanced-match@^0.4.1: version "0.4.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" @@ -27,6 +84,12 @@ benchmark@^2.1.4: lodash "^4.17.4" platform "^1.3.3" +boolean-shapely@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/boolean-shapely/-/boolean-shapely-0.1.2.tgz#465fe962c99c35d4c7a6a4978da0d1df95b81b7b" + dependencies: + python-shell "^0.4.0" + brace-expansion@^1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" @@ -38,7 +101,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -deep-equal@^1.0.1, deep-equal@~1.0.1: +deep-equal@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" @@ -53,6 +116,12 @@ defined@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" +error-ex@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" + dependencies: + is-arrayish "^0.2.1" + es-abstract@^1.5.0: version "1.7.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.7.0.tgz#dfade774e01bfcd97f96180298c449c8623fb94c" @@ -88,6 +157,16 @@ function-bind@^1.0.2, function-bind@^1.1.0, function-bind@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" +geojson-rbush@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/geojson-rbush/-/geojson-rbush-1.1.0.tgz#f6c1ac12f8030c890d410b6b0fdeb92a0b3ac318" + dependencies: + "@turf/bbox" "^3.10.5" + "@turf/bbox-polygon" "^4.3.0" + "@turf/helpers" "^3.10.5" + "@turf/meta" "^3.10.5" + rbush "^2.0.1" + glob@~7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" @@ -99,6 +178,10 @@ glob@~7.1.1: once "^1.3.0" path-is-absolute "^1.0.0" +graceful-fs@^4.1.2: + version "4.1.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" + has@^1.0.1, has@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28" @@ -116,6 +199,10 @@ inherits@2, inherits@~2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + is-callable@^1.1.1, is-callable@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2" @@ -138,6 +225,15 @@ is-symbol@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572" +load-json-file@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8" + dependencies: + graceful-fs "^4.1.2" + parse-json "^2.2.0" + pify "^2.0.0" + strip-bom "^3.0.0" + lodash@^4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -166,14 +262,38 @@ once@^1.3.0: dependencies: wrappy "1" +parse-json@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" + dependencies: + error-ex "^1.2.0" + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" +pify@^2.0.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" + platform@^1.3.3: version "1.3.4" resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.4.tgz#6f0fb17edaaa48f21442b3a975c063130f1c3ebd" +python-shell@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/python-shell/-/python-shell-0.4.0.tgz#259c5470d885292b22e906a57b085f651752f956" + +quickselect@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/quickselect/-/quickselect-1.0.0.tgz#02630818f9aae4ecab26f0103f98d061c17c58f3" + +rbush@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/rbush/-/rbush-2.0.1.tgz#4cfaca28c3064bc0ee75431a1b79990e875eefa9" + dependencies: + quickselect "^1.0.0" + resolve@~1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" @@ -192,6 +312,10 @@ string.prototype.trim@~1.1.2: es-abstract "^1.5.0" function-bind "^1.0.2" +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + tape@^4.6.3: version "4.6.3" resolved "https://registry.yarnpkg.com/tape/-/tape-4.6.3.tgz#637e77581e9ab2ce17577e9bd4ce4f575806d8b6" From e4cf64c2e3ffd78923cb8d440d7efd8b3c6b9181 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 12:06:34 -0400 Subject: [PATCH 3/8] Add MultiPolygon to test fixtures --- packages/turf-boolean-disjoint/test.js | 4 +- .../Polygon/MultiPolygon-Polygon.geojson | 97 +++++++++++++++++++ .../MultiPolygon/Polygon-MultiPolygon.geojson | 97 +++++++++++++++++++ .../Polygon/MultiPolygon-Polygon.geojson | 97 +++++++++++++++++++ .../MultiPolygon/Polygon-MultiPolygon.geojson | 97 +++++++++++++++++++ 5 files changed, 390 insertions(+), 2 deletions(-) create mode 100644 packages/turf-boolean-disjoint/test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson diff --git a/packages/turf-boolean-disjoint/test.js b/packages/turf-boolean-disjoint/test.js index 12993767b2..ea202ec84d 100644 --- a/packages/turf-boolean-disjoint/test.js +++ b/packages/turf-boolean-disjoint/test.js @@ -7,7 +7,7 @@ const disjoint = require('./'); test('turf-boolean-disjoint', t => { // True Fixtures - glob.sync(path.join(__dirname, 'test', 'true', '*.geojson')).forEach(filepath => { + glob.sync(path.join(__dirname, 'test', 'true', '**', '*.geojson')).forEach(filepath => { const {name} = path.parse(filepath); const geojson = load.sync(filepath); const [feature1, feature2] = geojson.features; @@ -17,7 +17,7 @@ test('turf-boolean-disjoint', t => { t.true(result, '[true] ' + name); }); // False Fixtures - glob.sync(path.join(__dirname, 'test', 'false', '*.geojson')).forEach(filepath => { + glob.sync(path.join(__dirname, 'test', 'false', '**', '*.geojson')).forEach(filepath => { const {name} = path.parse(filepath); const geojson = load.sync(filepath); const [feature1, feature2] = geojson.features; diff --git a/packages/turf-boolean-disjoint/test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson b/packages/turf-boolean-disjoint/test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson new file mode 100644 index 0000000000..f06f293f40 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson @@ -0,0 +1,97 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "fill": "#ff0000" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + 122.6953125, + -19.186677697957833 + ], + [ + 128.759765625, + -19.186677697957833 + ], + [ + 128.759765625, + -15.28418511407642 + ], + [ + 122.6953125, + -15.28418511407642 + ], + [ + 122.6953125, + -19.186677697957833 + ] + ] + ], + [ + [ + [ + 123.74999999999999, + -25.918526162075153 + ], + [ + 130.25390625, + -25.918526162075153 + ], + [ + 130.25390625, + -20.715015145512087 + ], + [ + 123.74999999999999, + -20.715015145512087 + ], + [ + 123.74999999999999, + -25.918526162075153 + ] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "fill": "#0000ff" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 119.20166015624999, + -22.776181505086495 + ], + [ + 125.09033203124999, + -22.776181505086495 + ], + [ + 125.09033203124999, + -18.417078658661257 + ], + [ + 119.20166015624999, + -18.417078658661257 + ], + [ + 119.20166015624999, + -22.776181505086495 + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson b/packages/turf-boolean-disjoint/test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson new file mode 100644 index 0000000000..be3c9da3d9 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson @@ -0,0 +1,97 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "fill": "#0000ff" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 119.20166015624999, + -22.776181505086495 + ], + [ + 125.09033203124999, + -22.776181505086495 + ], + [ + 125.09033203124999, + -18.417078658661257 + ], + [ + 119.20166015624999, + -18.417078658661257 + ], + [ + 119.20166015624999, + -22.776181505086495 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "fill": "#ff0000" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + 122.6953125, + -19.186677697957833 + ], + [ + 128.759765625, + -19.186677697957833 + ], + [ + 128.759765625, + -15.28418511407642 + ], + [ + 122.6953125, + -15.28418511407642 + ], + [ + 122.6953125, + -19.186677697957833 + ] + ] + ], + [ + [ + [ + 123.74999999999999, + -25.918526162075153 + ], + [ + 130.25390625, + -25.918526162075153 + ], + [ + 130.25390625, + -20.715015145512087 + ], + [ + 123.74999999999999, + -20.715015145512087 + ], + [ + 123.74999999999999, + -25.918526162075153 + ] + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson b/packages/turf-boolean-disjoint/test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson new file mode 100644 index 0000000000..91783ce157 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson @@ -0,0 +1,97 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "fill": "#ff0000" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + 122.6953125, + -19.186677697957833 + ], + [ + 128.759765625, + -19.186677697957833 + ], + [ + 128.759765625, + -15.28418511407642 + ], + [ + 122.6953125, + -15.28418511407642 + ], + [ + 122.6953125, + -19.186677697957833 + ] + ] + ], + [ + [ + [ + 123.74999999999999, + -25.918526162075153 + ], + [ + 130.25390625, + -25.918526162075153 + ], + [ + 130.25390625, + -20.715015145512087 + ], + [ + 123.74999999999999, + -20.715015145512087 + ], + [ + 123.74999999999999, + -25.918526162075153 + ] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "fill": "#0000ff" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 116.98242187499999, + -24.647017162630352 + ], + [ + 122.87109375, + -24.647017162630352 + ], + [ + 122.87109375, + -20.34462694382967 + ], + [ + 116.98242187499999, + -20.34462694382967 + ], + [ + 116.98242187499999, + -24.647017162630352 + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson b/packages/turf-boolean-disjoint/test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson new file mode 100644 index 0000000000..480686cbbc --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson @@ -0,0 +1,97 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "fill": "#0000ff" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 116.98242187499999, + -24.647017162630352 + ], + [ + 122.87109375, + -24.647017162630352 + ], + [ + 122.87109375, + -20.34462694382967 + ], + [ + 116.98242187499999, + -20.34462694382967 + ], + [ + 116.98242187499999, + -24.647017162630352 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "fill": "#ff0000" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + 122.6953125, + -19.186677697957833 + ], + [ + 128.759765625, + -19.186677697957833 + ], + [ + 128.759765625, + -15.28418511407642 + ], + [ + 122.6953125, + -15.28418511407642 + ], + [ + 122.6953125, + -19.186677697957833 + ] + ] + ], + [ + [ + [ + 123.74999999999999, + -25.918526162075153 + ], + [ + 130.25390625, + -25.918526162075153 + ], + [ + 130.25390625, + -20.715015145512087 + ], + [ + 123.74999999999999, + -20.715015145512087 + ], + [ + 123.74999999999999, + -25.918526162075153 + ] + ] + ] + ] + } + } + ] +} \ No newline at end of file From 24d978400436749040a0f29fdeaa06090322004f Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 12:19:40 -0400 Subject: [PATCH 4/8] Organize Test fixtures to folders --- .../test/false/{ => LineString}/LineIsNotDisjointFromLine.geojson | 0 .../false/{ => LineString}/LineIsNotDisjointFromPolygon.geojson | 0 .../false/{ => MultiPoint}/MultiPointNotDisjointFromLine.geojson | 0 .../{ => MultiPoint}/MultiPointNotDisjointFromMultipoint.geojson | 0 .../false/{ => MultiPoint}/MultiPointNotDisjointFromPoly.geojson | 0 .../LineString/Point-LineString.geojson} | 0 .../MultiPoint/Point-MultiPoint.geojson} | 0 .../Point/Point-Point.geojson} | 0 .../Polygon/Point-Polygon-1.geojson} | 0 .../Polygon/Point-Polygon-2.geojson} | 0 .../Polygon/Polygon-Polygon.geojson} | 0 .../LineString/LineString-LineString.geojson} | 0 .../Polygon/LineString-Polygon.geojson} | 0 .../LineString/MultiPoint-LineString.geojson} | 0 .../MultiPoint/MultiPoint-MultiPoint.geojson} | 0 .../Polygon/MultiPoint-Polygon.geojson} | 0 .../LineString/Point-LineString.geojson} | 0 .../MultiPoint/Point-Multipoint.geojson} | 0 .../Point/Point-Point.geojson} | 0 .../Polygon/Point-Polygon.geojson} | 0 .../Polygon/Polygon-Polygon.geojson} | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename packages/turf-boolean-disjoint/test/false/{ => LineString}/LineIsNotDisjointFromLine.geojson (100%) rename packages/turf-boolean-disjoint/test/false/{ => LineString}/LineIsNotDisjointFromPolygon.geojson (100%) rename packages/turf-boolean-disjoint/test/false/{ => MultiPoint}/MultiPointNotDisjointFromLine.geojson (100%) rename packages/turf-boolean-disjoint/test/false/{ => MultiPoint}/MultiPointNotDisjointFromMultipoint.geojson (100%) rename packages/turf-boolean-disjoint/test/false/{ => MultiPoint}/MultiPointNotDisjointFromPoly.geojson (100%) rename packages/turf-boolean-disjoint/test/false/{PointIsNotDisjointFromLineString.geojson => Point/LineString/Point-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/{PointNotDisjointFromMultipoint.geojson => Point/MultiPoint/Point-MultiPoint.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/{PointNotDisjointFromPoint.geojson => Point/Point/Point-Point.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/{PointNotDisjointFromInternalPoly.geojson => Point/Polygon/Point-Polygon-1.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/{PointNotDisjointFromPoly.geojson => Point/Polygon/Point-Polygon-2.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/{PolyIsNotDisjointFromPoly.geojson => Polygon/Polygon/Polygon-Polygon.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{LineIsDisjointFromLine.geojson => LineString/LineString/LineString-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{LineIsDisjointFromPolygon.geojson => LineString/Polygon/LineString-Polygon.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{MultiPointDisjointFromLine.geojson => MultiPoint/LineString/MultiPoint-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{MultiPointDisjointFromMultipoint.geojson => MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{MultiPointIsDisjointFromPoly.geojson => MultiPoint/Polygon/MultiPoint-Polygon.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{PointIsDisjointFromLinestring.geojson => Point/LineString/Point-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{PointDisjointFromMultipoint.geojson => Point/MultiPoint/Point-Multipoint.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{PointDisjointFromPoint.geojson => Point/Point/Point-Point.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{PointIsDisjointFromPoly.geojson => Point/Polygon/Point-Polygon.geojson} (100%) rename packages/turf-boolean-disjoint/test/true/{PolyIsDisjointFromPoly.geojson => Polygon/Polygon/Polygon-Polygon.geojson} (100%) diff --git a/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromLine.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromLine.geojson diff --git a/packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson b/packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromPolygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/LineIsNotDisjointFromPolygon.geojson rename to packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromPolygon.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromLine.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromLine.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromMultipoint.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromMultipoint.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromMultipoint.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromPoly.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPointNotDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromPoly.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PointIsNotDisjointFromLineString.geojson rename to packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/false/Point/MultiPoint/Point-MultiPoint.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PointNotDisjointFromMultipoint.geojson rename to packages/turf-boolean-disjoint/test/false/Point/MultiPoint/Point-MultiPoint.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson b/packages/turf-boolean-disjoint/test/false/Point/Point/Point-Point.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoint.geojson rename to packages/turf-boolean-disjoint/test/false/Point/Point/Point-Point.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson b/packages/turf-boolean-disjoint/test/false/Point/Polygon/Point-Polygon-1.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PointNotDisjointFromInternalPoly.geojson rename to packages/turf-boolean-disjoint/test/false/Point/Polygon/Point-Polygon-1.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/Point/Polygon/Point-Polygon-2.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PointNotDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/false/Point/Polygon/Point-Polygon-2.geojson diff --git a/packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/Polygon/Polygon/Polygon-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/PolyIsNotDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/false/Polygon/Polygon/Polygon-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/true/LineString/LineString/LineString-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/LineIsDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/true/LineString/LineString/LineString-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson b/packages/turf-boolean-disjoint/test/true/LineString/Polygon/LineString-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/LineIsDisjointFromPolygon.geojson rename to packages/turf-boolean-disjoint/test/true/LineString/Polygon/LineString-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/true/MultiPoint/LineString/MultiPoint-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/true/MultiPoint/LineString/MultiPoint-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/true/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/MultiPointDisjointFromMultipoint.geojson rename to packages/turf-boolean-disjoint/test/true/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson diff --git a/packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/MultiPoint/Polygon/MultiPoint-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/MultiPointIsDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/true/MultiPoint/Polygon/MultiPoint-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson b/packages/turf-boolean-disjoint/test/true/Point/LineString/Point-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/PointIsDisjointFromLinestring.geojson rename to packages/turf-boolean-disjoint/test/true/Point/LineString/Point-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/true/Point/MultiPoint/Point-Multipoint.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/PointDisjointFromMultipoint.geojson rename to packages/turf-boolean-disjoint/test/true/Point/MultiPoint/Point-Multipoint.geojson diff --git a/packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson b/packages/turf-boolean-disjoint/test/true/Point/Point/Point-Point.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/PointDisjointFromPoint.geojson rename to packages/turf-boolean-disjoint/test/true/Point/Point/Point-Point.geojson diff --git a/packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/Point/Polygon/Point-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/PointIsDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/true/Point/Polygon/Point-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/true/Polygon/Polygon/Polygon-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/true/PolyIsDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/true/Polygon/Polygon/Polygon-Polygon.geojson From 0b8b1721fefbe83c2f29b0874519aa0528e33fcf Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 13:03:51 -0400 Subject: [PATCH 5/8] Update test fixtures --- .../LineString-LineString.geojson} | 0 .../LineString-Polygon.geojson} | 0 .../MultiPoint-LineString.geojson} | 0 .../MultiPoint-MultiPoint.geojson} | 0 .../MultiPoint-Polygon.geojson} | 0 .../MultiPoint/Point/MultiPoint-Point.geojson | 21 +++++++++++++++++++ 6 files changed, 21 insertions(+) rename packages/turf-boolean-disjoint/test/false/LineString/{LineIsNotDisjointFromLine.geojson => LineString/LineString-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/LineString/{LineIsNotDisjointFromPolygon.geojson => Polygon/LineString-Polygon.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/MultiPoint/{MultiPointNotDisjointFromLine.geojson => LineString/MultiPoint-LineString.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/MultiPoint/{MultiPointNotDisjointFromMultipoint.geojson => MultiPoint/MultiPoint-MultiPoint.geojson} (100%) rename packages/turf-boolean-disjoint/test/false/MultiPoint/{MultiPointNotDisjointFromPoly.geojson => Polygon/MultiPoint-Polygon.geojson} (100%) create mode 100644 packages/turf-boolean-disjoint/test/true/MultiPoint/Point/MultiPoint-Point.geojson diff --git a/packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/false/LineString/LineString/LineString-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromPolygon.geojson b/packages/turf-boolean-disjoint/test/false/LineString/Polygon/LineString-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/LineString/LineIsNotDisjointFromPolygon.geojson rename to packages/turf-boolean-disjoint/test/false/LineString/Polygon/LineString-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromLine.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/LineString/MultiPoint-LineString.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromLine.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/LineString/MultiPoint-LineString.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromMultipoint.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromMultipoint.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson diff --git a/packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromPoly.geojson b/packages/turf-boolean-disjoint/test/false/MultiPoint/Polygon/MultiPoint-Polygon.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/MultiPoint/MultiPointNotDisjointFromPoly.geojson rename to packages/turf-boolean-disjoint/test/false/MultiPoint/Polygon/MultiPoint-Polygon.geojson diff --git a/packages/turf-boolean-disjoint/test/true/MultiPoint/Point/MultiPoint-Point.geojson b/packages/turf-boolean-disjoint/test/true/MultiPoint/Point/MultiPoint-Point.geojson new file mode 100644 index 0000000000..13d0bcbb15 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/MultiPoint/Point/MultiPoint-Point.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 1], [12, 12]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + } + ] +} \ No newline at end of file From 2f35d0896ab9b37ea24f8ff72a53ef1b13411014 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 13:23:26 -0400 Subject: [PATCH 6/8] Support MultiGeometries disjoint --- packages/turf-boolean-disjoint/bench.js | 2 +- packages/turf-boolean-disjoint/index.js | 97 +++++---------------- packages/turf-boolean-disjoint/package.json | 2 +- 3 files changed, 26 insertions(+), 75 deletions(-) diff --git a/packages/turf-boolean-disjoint/bench.js b/packages/turf-boolean-disjoint/bench.js index 0f5c687797..e8758a5c64 100644 --- a/packages/turf-boolean-disjoint/bench.js +++ b/packages/turf-boolean-disjoint/bench.js @@ -1,7 +1,7 @@ const path = require('path'); const glob = require('glob'); -const Benchmark = require('benchmark'); const load = require('load-json-file'); +const Benchmark = require('benchmark'); const disjoint = require('./'); /** diff --git a/packages/turf-boolean-disjoint/index.js b/packages/turf-boolean-disjoint/index.js index fe41ea570c..a99a6f9cef 100644 --- a/packages/turf-boolean-disjoint/index.js +++ b/packages/turf-boolean-disjoint/index.js @@ -1,10 +1,7 @@ var inside = require('@turf/inside'); -var invariant = require('@turf/invariant'); +var flattenEach = require('@turf/meta').flattenEach; var lineIntersect = require('@turf/line-intersect'); var polyToLinestring = require('@turf/polygon-to-linestring'); -var getGeom = invariant.getGeom; -var getCoords = invariant.getCoords; -var getGeomType = invariant.getGeomType; /** * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. @@ -34,44 +31,40 @@ var getGeomType = invariant.getGeomType; * //=true */ module.exports = function (feature1, feature2) { - var type1 = getGeomType(feature1); - var type2 = getGeomType(feature2); - var geom1 = getGeom(feature1); - var geom2 = getGeom(feature2); - var coords1 = getCoords(feature1); - var coords2 = getCoords(feature2); + var boolean; + flattenEach(feature1, function (flatten1) { + flattenEach(feature2, function (flatten2) { + if (boolean === false) return false; + boolean = disjoint(flatten1.geometry, flatten2.geometry); + }); + }); + return boolean; +}; - switch (type1) { +/** + * Disjoint operation for simple Geometries (Point/LineString/Polygon) + * + * @private + * @param {Geometry} geom1 GeoJSON Geometry + * @param {Geometry} geom2 GeoJSON Geometry + * @returns {Boolean} true/false + */ +function disjoint(geom1, geom2) { + switch (geom1.type) { case 'Point': - switch (type2) { + switch (geom2.type) { case 'Point': - return !compareCoords(coords1, coords2); - case 'MultiPoint': - return !isPointInMultiPoint(geom2, geom1); + return !compareCoords(geom1.coordinates, geom2.coordinates); case 'LineString': return !isPointOnLine(geom2, geom1); case 'Polygon': return !inside(geom1, geom2); } break; - case 'MultiPoint': - switch (type2) { - case 'Point': - return !isPointInMultiPoint(coords1, coords2); - case 'MultiPoint': - return !isMultiPointInMultiPoint(geom1, geom2); - case 'LineString': - return !isMultiPointOnLine(geom2, geom1); - case 'Polygon': - return !isMultiPointInPoly(geom2, geom1); - } - break; case 'LineString': - switch (type2) { + switch (geom2.type) { case 'Point': return !isPointOnLine(geom1, geom2); - case 'MultiPoint': - return !isMultiPointOnLine(geom1, geom2); case 'LineString': return !isLineOnLine(geom1, geom2); case 'Polygon': @@ -79,11 +72,9 @@ module.exports = function (feature1, feature2) { } break; case 'Polygon': - switch (type2) { + switch (geom2.type) { case 'Point': return !inside(geom2, geom1); - case 'MultiPoint': - return !isMultiPointInPoly(geom1, geom2); case 'LineString': return !isLineInPoly(geom1, geom2); case 'Polygon': @@ -91,26 +82,6 @@ module.exports = function (feature1, feature2) { } break; } -}; - -function isPointInMultiPoint(multiPoint, point) { - for (var i = 0; i < multiPoint.coordinates.length; i++) { - if (compareCoords(multiPoint.coordinates[i], point.coordinates)) { - return true; - } - } - return false; -} - -function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { - for (var i = 0; i < multiPoint2.coordinates.length; i++) { - for (var i2 = 0; i2 < multiPoint1.coordinates.length; i2++) { - if (compareCoords(multiPoint2.coordinates[i], multiPoint1.coordinates[i2])) { - return true; - } - } - } - return false; } // http://stackoverflow.com/a/11908158/1979085 @@ -123,26 +94,6 @@ function isPointOnLine(lineString, point) { return false; } -function isMultiPointOnLine(lineString, multiPoint) { - for (var i = 0; i < multiPoint.coordinates.length; i++) { - for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) { - if (isPointOnLineSegment(lineString.coordinates[i2], lineString.coordinates[i2 + 1], multiPoint.coordinates[i])) { - return true; - } - } - } - return false; -} - -function isMultiPointInPoly(polygon, multiPoint) { - for (var i = 0; i < multiPoint.coordinates.length; i++) { - if (inside(multiPoint.coordinates[i], polygon)) { - return true; - } - } - return false; -} - function isLineOnLine(lineString1, lineString2) { var doLinesIntersect = lineIntersect(lineString1, lineString2); if (doLinesIntersect.features.length > 0) { diff --git a/packages/turf-boolean-disjoint/package.json b/packages/turf-boolean-disjoint/package.json index 2ffbb4542c..4aab2560fb 100644 --- a/packages/turf-boolean-disjoint/package.json +++ b/packages/turf-boolean-disjoint/package.json @@ -41,8 +41,8 @@ }, "dependencies": { "@turf/inside": "^4.4.0", - "@turf/invariant": "^4.3.0", "@turf/line-intersect": "^4.4.0", + "@turf/meta": "^4.4.0", "@turf/polygon-to-linestring": "^4.4.0" } } From 275c995153d66a740ff8cb665962a1575ff714cd Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 13:55:32 -0400 Subject: [PATCH 7/8] Add more test fixtures --- packages/turf-boolean-disjoint/index.js | 3 ++- .../Point/LineString-Point-1.geojson | 21 +++++++++++++++++++ .../Point/LineString-Point-2.geojson | 21 +++++++++++++++++++ .../LineString/Polygon-LineString.geojson | 21 +++++++++++++++++++ .../false/Polygon/Point/Polygon-Point.geojson | 21 +++++++++++++++++++ .../LineString/Point/LineString-Point.geojson | 21 +++++++++++++++++++ .../LineString/Polygon-LineString.geojson | 21 +++++++++++++++++++ .../true/Polygon/Point/Polygon-Point.geojson | 21 +++++++++++++++++++ 8 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-1.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-2.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/Polygon/LineString/Polygon-LineString.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/Polygon/Point/Polygon-Point.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/LineString/Point/LineString-Point.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/Polygon/LineString/Polygon-LineString.geojson create mode 100644 packages/turf-boolean-disjoint/test/true/Polygon/Point/Polygon-Point.geojson diff --git a/packages/turf-boolean-disjoint/index.js b/packages/turf-boolean-disjoint/index.js index a99a6f9cef..0ced3d8c3d 100644 --- a/packages/turf-boolean-disjoint/index.js +++ b/packages/turf-boolean-disjoint/index.js @@ -60,6 +60,7 @@ function disjoint(geom1, geom2) { case 'Polygon': return !inside(geom1, geom2); } + /* istanbul ignore next */ break; case 'LineString': switch (geom2.type) { @@ -70,6 +71,7 @@ function disjoint(geom1, geom2) { case 'Polygon': return !isLineInPoly(geom2, geom1); } + /* istanbul ignore next */ break; case 'Polygon': switch (geom2.type) { @@ -80,7 +82,6 @@ function disjoint(geom1, geom2) { case 'Polygon': return !isPolyInPoly(geom2, geom1); } - break; } } diff --git a/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-1.geojson b/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-1.geojson new file mode 100644 index 0000000000..ee52d798b9 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-1.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-2.geojson b/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-2.geojson new file mode 100644 index 0000000000..fec3c616a9 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/LineString/Point/LineString-Point-2.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1.5] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/Polygon/LineString/Polygon-LineString.geojson b/packages/turf-boolean-disjoint/test/false/Polygon/LineString/Polygon-LineString.geojson new file mode 100644 index 0000000000..958851c0c8 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Polygon/LineString/Polygon-LineString.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 2], [12, 2], [12, 3], [12, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/Polygon/Point/Polygon-Point.geojson b/packages/turf-boolean-disjoint/test/false/Polygon/Point/Polygon-Point.geojson new file mode 100644 index 0000000000..98abecf78c --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Polygon/Point/Polygon-Point.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 2.5] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/LineString/Point/LineString-Point.geojson b/packages/turf-boolean-disjoint/test/true/LineString/Point/LineString-Point.geojson new file mode 100644 index 0000000000..9cbccfa1b8 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/LineString/Point/LineString-Point.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/Polygon/LineString/Polygon-LineString.geojson b/packages/turf-boolean-disjoint/test/true/Polygon/LineString/Polygon-LineString.geojson new file mode 100644 index 0000000000..29d591babb --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/Polygon/LineString/Polygon-LineString.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[0, 0], [12, 2], [12, 3], [12, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/true/Polygon/Point/Polygon-Point.geojson b/packages/turf-boolean-disjoint/test/true/Polygon/Point/Polygon-Point.geojson new file mode 100644 index 0000000000..5f1b0513df --- /dev/null +++ b/packages/turf-boolean-disjoint/test/true/Polygon/Point/Polygon-Point.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1] + } + } + ] +} \ No newline at end of file From 8e01ce582d6b9497affa30a2e82b41b0e7f1eb47 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 20 Jun 2017 14:09:10 -0400 Subject: [PATCH 8/8] Add more test fixtures --- packages/turf-boolean-disjoint/index.js | 10 +++++++-- ...ing.geojson => Point-LineString-1.geojson} | 0 .../LineString/Point-LineString-2.geojson | 21 +++++++++++++++++++ .../LineString/Point-LineString-3.geojson | 21 +++++++++++++++++++ .../LineString/Point-LineString-4.geojson | 21 +++++++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) rename packages/turf-boolean-disjoint/test/false/Point/LineString/{Point-LineString.geojson => Point-LineString-1.geojson} (100%) create mode 100644 packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-2.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-3.geojson create mode 100644 packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-4.geojson diff --git a/packages/turf-boolean-disjoint/index.js b/packages/turf-boolean-disjoint/index.js index 0ced3d8c3d..5290ec2201 100644 --- a/packages/turf-boolean-disjoint/index.js +++ b/packages/turf-boolean-disjoint/index.js @@ -140,9 +140,15 @@ function isPointOnLineSegment(LineSegmentStart, LineSegmentEnd, Point) { return false; } if (Math.abs(dxl) >= Math.abs(dyl)) { - return dxl > 0 ? LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0] : LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; + if (dxl > 0) { + return LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0]; + } else { + return LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; + } + } else if (dyl > 0) { + return LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1]; } else { - return dyl > 0 ? LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1] : LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1]; + return LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1]; } } diff --git a/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString.geojson b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-1.geojson similarity index 100% rename from packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString.geojson rename to packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-1.geojson diff --git a/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-2.geojson b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-2.geojson new file mode 100644 index 0000000000..b40c55038d --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-2.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [1, 1.5] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-3.geojson b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-3.geojson new file mode 100644 index 0000000000..568b5b3b00 --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-3.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [2.5, 1] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [2, 1], [3, 1], [4, 1]] + } + } + ] +} \ No newline at end of file diff --git a/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-4.geojson b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-4.geojson new file mode 100644 index 0000000000..fa4b40311c --- /dev/null +++ b/packages/turf-boolean-disjoint/test/false/Point/LineString/Point-LineString-4.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [2.5, 2.5] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[1, 1], [2, 2], [3, 3], [4, 4]] + } + } + ] +} \ No newline at end of file