-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix jsts empty (Multi)Polygon error @turf/difference (#725)
* Update fixtures from #644 * Fix jsts empty (Multi)Polygon error - Major refactoring to `index.js` & `test.js` - Update JSDocs & Typescript definition to support MultiPolygon #721
- Loading branch information
1 parent
862ae21
commit 60b2ee0
Showing
31 changed files
with
2,673 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
var difference = require('./'); | ||
var Benchmark = require('benchmark'); | ||
var fs = require('fs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const load = require('load-json-file'); | ||
const Benchmark = require('benchmark'); | ||
const difference = require('./'); | ||
|
||
var clip = JSON.parse(fs.readFileSync(__dirname+'/test/fixtures/in/differencedHole.geojson')); | ||
var hole = JSON.parse(fs.readFileSync(__dirname+'/test/fixtures/in/differencedFC.geojson')); | ||
const directory = path.join(__dirname, 'test', 'in') + path.sep; | ||
let fixtures = fs.readdirSync(directory).map(filename => { | ||
return { | ||
filename, | ||
name: path.parse(filename).name, | ||
geojson: load.sync(directory + filename) | ||
}; | ||
}); | ||
// fixtures = fixtures.filter(({name}) => name === 'issue-#721'); | ||
|
||
/** | ||
* Benchmark Results | ||
* | ||
* ==using jsts== | ||
* clip-polygons x 2,512 ops/sec ±30.29% (71 runs sampled) | ||
* completely-overlapped x 6,777 ops/sec ±4.08% (78 runs sampled) | ||
* create-hole x 5,451 ops/sec ±9.92% (75 runs sampled) | ||
* issue-#721-inverse x 434,372 ops/sec ±3.40% (85 runs sampled) | ||
* issue-#721 x 421,194 ops/sec ±4.35% (80 runs sampled) | ||
* multi-polygon-input x 1,904 ops/sec ±5.16% (79 runs sampled) | ||
* multi-polygon-target x 1,240 ops/sec ±5.44% (79 runs sampled) | ||
* split-polygon x 2,468 ops/sec ±4.75% (82 runs sampled) | ||
*/ | ||
const suite = new Benchmark.Suite('turf-difference'); | ||
for (const {name, geojson} of fixtures) { | ||
suite.add(name, () => difference(geojson.features[0], geojson.features[1])); | ||
} | ||
|
||
var suite = new Benchmark.Suite('turf-difference'); | ||
suite | ||
.add('turf-difference#clip',function () { | ||
difference(clip[0], clip[1]); | ||
}) | ||
.add('turf-difference#hole',function () { | ||
difference(hole[0], hole[1]); | ||
}) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function () { | ||
|
||
}) | ||
.run(); | ||
.on('cycle', e => console.log(String(e.target))) | ||
.on('complete', () => {}) | ||
.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/// <reference types="geojson" /> | ||
|
||
type Polygon = GeoJSON.Feature<GeoJSON.Polygon>; | ||
type MultiPolygon = GeoJSON.Feature<GeoJSON.MultiPolygon>; | ||
import {Polygon, MultiPolygon, Feature} from '@turf/meta' | ||
|
||
type Input = Feature<Polygon|MultiPolygon> | Polygon | MultiPolygon; | ||
type Output = Feature<Polygon|MultiPolygon> | undefined; | ||
|
||
/** | ||
* http://turfjs.org/docs/#difference | ||
*/ | ||
declare function difference(poly1: Polygon, poly2: Polygon): Polygon|MultiPolygon; | ||
declare function difference(polygon1: Input, polygon2: Input): Output; | ||
declare namespace difference { } | ||
export = difference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.