-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into transform-scale-#895
- Loading branch information
Showing
13 changed files
with
6,663 additions
and
269 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,45 @@ | ||
var concave = 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 concave = require('./'); | ||
|
||
const directory = path.join(__dirname, 'test', 'in') + path.sep; | ||
const fixtures = fs.readdirSync(directory).map(filename => { | ||
return { | ||
name: path.parse(filename).name, | ||
geojson: load.sync(directory + filename) | ||
}; | ||
}); | ||
|
||
/** | ||
* Single Process Benchmark | ||
* | ||
* issue-333: 651.884ms | ||
* pts1: 6.568ms | ||
* pts2: 476.032ms | ||
*/ | ||
for (const {name, geojson} of fixtures) { | ||
const {maxEdge, units} = geojson.properties || {maxEdge: 1}; | ||
console.time(name); | ||
concave(geojson, maxEdge, units); | ||
console.timeEnd(name); | ||
} | ||
|
||
/** | ||
* Benchmark Results | ||
* | ||
* issue-333 x 5.57 ops/sec ±10.65% (18 runs sampled) | ||
* pts1 x 315 ops/sec ±3.48% (70 runs sampled) | ||
* pts2 x 4.51 ops/sec ±2.28% (16 runs sampled) | ||
*/ | ||
const suite = new Benchmark.Suite('turf-transform-scale'); | ||
for (const {name, geojson} of fixtures) { | ||
const {maxEdge, units} = geojson.properties || {maxEdge: 1}; | ||
suite.add(name, () => concave(geojson, maxEdge, units)); | ||
} | ||
|
||
var pts1 = JSON.parse(fs.readFileSync(__dirname+'/test/in/pts1.geojson')); | ||
var pts2 = JSON.parse(fs.readFileSync(__dirname+'/test/in/pts2.geojson')); | ||
|
||
var suite = new Benchmark.Suite('turf-concave'); | ||
suite | ||
.add('turf-concave#simple',function () { | ||
concave(pts1, 2.5, 'miles'); | ||
}) | ||
.add('turf-concave#complex',function () { | ||
concave(pts2, 2.5, 'miles'); | ||
}) | ||
.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
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,56 +1,54 @@ | ||
var concave = require('./'); | ||
var test = require('tape'); | ||
var fs = require('fs'); | ||
var featureCollection = require('@turf/helpers').featureCollection; | ||
var point = require('@turf/helpers').point; | ||
|
||
var pts1 = JSON.parse(fs.readFileSync(__dirname+'/test/fixtures/in/pts1.geojson')); | ||
var pts2 = JSON.parse(fs.readFileSync(__dirname+'/test/fixtures/in/pts2.geojson')); | ||
|
||
test('concave', function(t){ | ||
|
||
var ptsOnePoint = featureCollection([point([0, 0])]); | ||
var ptsOnePointHull = null; | ||
t.throws(function(){ | ||
ptsOnePointHull = concave(ptsOnePoint, 5.5, 'miles'); | ||
}, Error, 'fails with too few points'); | ||
t.notOk(ptsOnePointHull, 'hull not computed with too few points'); | ||
|
||
var ptsNoPointHull = null; | ||
t.throws(function(){ | ||
ptsNoPointHull = concave(pts1, 0, 'miles'); | ||
}, Error, 'fails with small maxEdge'); | ||
t.notOk(ptsNoPointHull, 'hull not computed with small maxEdge'); | ||
|
||
t.end(); | ||
const fs = require('fs'); | ||
const test = require('tape'); | ||
const path = require('path'); | ||
const load = require('load-json-file'); | ||
const write = require('write-json-file'); | ||
const {point, featureCollection} = require('@turf/helpers'); | ||
const {featureEach} = require('@turf/meta'); | ||
const concave = require('./'); | ||
|
||
const directories = { | ||
in: path.join(__dirname, 'test', 'in') + path.sep, | ||
out: path.join(__dirname, 'test', 'out') + path.sep | ||
}; | ||
|
||
const fixtures = fs.readdirSync(directories.in).map(filename => { | ||
return { | ||
filename, | ||
name: path.parse(filename).name, | ||
geojson: load.sync(directories.in + filename) | ||
}; | ||
}); | ||
|
||
test('concave', function(t){ | ||
var pts1HullMiles = concave(pts1, 5.5, 'miles'); | ||
var pts1HullKilometers = concave(pts1, 5.5 * 1.60934, 'kilometers'); | ||
t.ok(pts1HullMiles, 'computes hull'); | ||
t.equal(pts1HullMiles.type, 'Feature'); | ||
t.deepEqual(pts1HullMiles, pts1HullKilometers, 'miles and km should return the same result'); | ||
|
||
var pts2HullMiles = concave(pts2, 2, 'miles'); | ||
var pts2HullKilometers = concave(pts2, 2 * 1.60934, 'kilometers'); | ||
t.ok(pts2HullMiles, 'computes hull'); | ||
t.equal(pts2HullMiles.type, 'Feature'); | ||
t.deepEqual(pts2HullMiles, pts2HullKilometers, 'miles and km should return the same result'); | ||
|
||
// output results | ||
pts1.features = pts1.features.map(stylePt); | ||
pts1.features.push(pts1HullMiles); | ||
pts2.features = pts2.features.map(stylePt); | ||
pts2.features.push(pts2HullMiles); | ||
fs.writeFileSync(__dirname+'/test/fixtures/out/pts1_out.geojson', JSON.stringify(pts1,null,2)); | ||
fs.writeFileSync(__dirname+'/test/fixtures/out/pts2_out.geojson', JSON.stringify(pts2,null,2)); | ||
|
||
t.end(); | ||
test('turf-line-split', t => { | ||
for(const {filename, name, geojson} of fixtures) { | ||
const {maxEdge, units} = geojson.properties || {maxEdge: 1}; | ||
const hull = concave(geojson, maxEdge, units); | ||
featureEach(geojson, stylePt); | ||
const results = featureCollection([...geojson.features, hull]); | ||
|
||
if (process.env.REGEN) write.sync(directories.out + filename, results); | ||
t.deepEquals(results, load.sync(directories.out + filename), name); | ||
} | ||
t.end(); | ||
}); | ||
|
||
|
||
const points = featureCollection([point([0, 0]), point([1, 1]), point([1, 0])]); | ||
const onePoint = featureCollection([point([0, 0])]); | ||
|
||
test('concave', t => { | ||
t.throws(() => concave(onePoint, 5.5, 'miles'), /too few polygons found to compute concave hull/, 'too few points'); | ||
t.throws(() => concave(onePoint, 0), /too few polygons found to compute concave hull/, 'maxEdge too small'); | ||
|
||
t.throws(() => concave(null, 0), /points is required/, 'no points'); | ||
t.throws(() => concave(points, null), /maxEdge is required/, 'no maxEdge'); | ||
t.throws(() => concave(points, 1, 'foo'), /units is invalid/, 'invalid units'); | ||
|
||
t.end(); | ||
}); | ||
|
||
function stylePt(pt){ | ||
pt.properties['marker-color'] = '#f0f'; | ||
pt.properties['marker-size'] = 'small'; | ||
return pt; | ||
pt.properties['marker-color'] = '#f0f'; | ||
pt.properties['marker-size'] = 'small'; | ||
} |
Oops, something went wrong.