Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Initial commit turf buffer no jsts #876

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions packages/turf-buffer/README.md

This file was deleted.

35 changes: 5 additions & 30 deletions packages/turf-buffer/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const fs = require('fs');
const path = require('path');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const buffer = require('./');
const lineOffset = require('./');

const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {
let fixtures = fs.readdirSync(directory).map(filename => {
return {
filename,
name: path.parse(filename).name,
Expand All @@ -15,37 +15,12 @@ const fixtures = fs.readdirSync(directory).map(filename => {

/**
* Benchmark Results
*
* feature-collection-points: 139.101ms
* geometry-collection-points: 20.334ms
* issue-#783: 33.209ms
* linestring: 6.371ms
* multi-linestring: 48.786ms
* multi-point: 7.627ms
* multi-polygon: 38.921ms
* negative-buffer: 5.621ms
* north-latitude-points: 71.144ms
* northern-polygon: 2.644ms
* point: 8.155ms
* polygon-with-holes: 6.965ms
* feature-collection-points x 722 ops/sec ±14.28% (65 runs sampled)
* geometry-collection-points x 1,314 ops/sec ±7.87% (66 runs sampled)
* issue-#783 x 1,404 ops/sec ±6.81% (64 runs sampled)
* linestring x 2,936 ops/sec ±6.94% (72 runs sampled)
* multi-linestring x 623 ops/sec ±4.35% (79 runs sampled)
* multi-point x 1,735 ops/sec ±8.60% (65 runs sampled)
* multi-polygon x 1,125 ops/sec ±3.93% (80 runs sampled)
* north-latitude-points x 1,649 ops/sec ±2.09% (86 runs sampled)
* northern-polygon x 4,658 ops/sec ±3.08% (78 runs sampled)
* point x 65,020 ops/sec ±1.29% (85 runs sampled)
* polygon-with-holes x 2,795 ops/sec ±2.98% (81 runs sampled)
* complex x 17,634 ops/sec ±1.63% (88 runs sampled)
* rectangle x 33,735 ops/sec ±2.27% (92 runs sampled)
*/
const suite = new Benchmark.Suite('turf-buffer');
for (const {name, geojson} of fixtures) {
console.time(name);
buffer(geojson, 50, 'miles');
console.timeEnd(name);
suite.add(name, () => buffer(geojson, 50, 'miles'));
suite.add(name, () => lineOffset(geojson, 100, 'meters'));
}

suite
Expand Down
30 changes: 7 additions & 23 deletions packages/turf-buffer/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
/// <reference types="geojson" />

import {Units, FeatureGeometryCollection} from '@turf/helpers';
import {Units} from '@turf/helpers';

type Point = GeoJSON.Point;
type LineString = GeoJSON.LineString;
type Polygon = GeoJSON.Polygon;
type MultiPoint = GeoJSON.MultiPoint;
type MultiLineString = GeoJSON.MultiLineString;
type MultiPolygon = GeoJSON.MultiPolygon;
type GeometryObject = GeoJSON.GeometryObject;
type GeometryCollection = GeoJSON.GeometryCollection;
type Feature<Geom extends GeometryObject> = GeoJSON.Feature<Geom>;
type FeatureCollection<Geom extends GeometryObject> = GeoJSON.FeatureCollection<Geom>;
type Geoms = Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon;
type Geoms = GeoJSON.LineString | GeoJSON.MultiLineString;

interface Buffer {
/**
* http://turfjs.org/docs/#buffer
*/
<Geom extends Point|LineString|Polygon>(feature: Feature<Geom>|Geom, radius?: number, unit?: Units, steps?: number): Feature<Polygon> | undefined;
<Geom extends MultiPoint|MultiLineString|MultiPolygon>(feature: Feature<Geom>|Geom, radius?: number, unit?: Units, steps?: number): Feature<MultiPolygon> | undefined;
<Geom extends Point|LineString|Polygon>(feature: FeatureCollection<Geom>, radius?: number, unit?: Units, steps?: number): FeatureCollection<Polygon>;
<Geom extends MultiPoint|MultiLineString|MultiPolygon>(feature: FeatureCollection<Geom>, radius?: number, unit?: Units, steps?: number): FeatureCollection<MultiPolygon>;
(feature: FeatureCollection<any>|FeatureGeometryCollection|GeometryCollection, radius?: number, unit?: Units, steps?: number): FeatureCollection<Polygon|MultiPolygon>;
(feature: Feature<any>|GeometryObject, radius?: number, unit?: Units, steps?: number): Feature<Polygon|MultiPolygon> | undefined;
}
declare const buffer: Buffer;
declare namespace buffer {}
/**
* http://turfjs.org/docs/#buffer
*/
declare function buffer<Geom extends Geoms>(line: Feature<Geom> | Geom, distance: number, units?: Units): Feature<Geom>;
declare namespace buffer { }
export = buffer;
Loading