Skip to content

Commit

Permalink
change default steps to 8, pass steps to JTS (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenchanin authored Nov 16, 2020
1 parent 321991c commit 4024376
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/turf-buffer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the input, or even be empty.
- `radius` **[number][4]** distance to draw the buffer (negative values are allowed)
- `options` **[Object][5]** Optional parameters (optional, default `{}`)
- `options.units` **[string][6]** any of the options supported by turf units (optional, default `"kilometers"`)
- `options.steps` **[number][4]** number of steps (optional, default `64`)
- `options.steps` **[number][4]** number of steps (optional, default `8`)

**Examples**

Expand Down
16 changes: 7 additions & 9 deletions packages/turf-buffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { feature, featureCollection, radiansToLength, lengthToRadians, earthRadi
* @param {number} radius distance to draw the buffer (negative values are allowed)
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units="kilometers"] any of the options supported by turf units
* @param {number} [options.steps=64] number of steps
* @param {number} [options.steps=8] number of steps
* @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features
* @example
* var point = turf.point([-90.548630, 14.616599]);
Expand All @@ -32,8 +32,10 @@ import { feature, featureCollection, radiansToLength, lengthToRadians, earthRadi
function buffer(geojson, radius, options) {
// Optional params
options = options || {};
var units = options.units;
var steps = options.steps || 64;

// use user supplied options or default values
var units = options.units || 'kilometers';
var steps = options.steps || 8;

// validation
if (!geojson) throw new Error('geojson is required');
Expand All @@ -44,10 +46,6 @@ function buffer(geojson, radius, options) {
if (radius === undefined) throw new Error('radius is required');
if (steps <= 0) throw new Error('steps must be greater than 0');

// default params
steps = steps || 64;
units = units || 'kilometers';

var results = [];
switch (geojson.type) {
case 'GeometryCollection':
Expand Down Expand Up @@ -77,7 +75,7 @@ function buffer(geojson, radius, options) {
* @param {Feature<any>} geojson input to be buffered
* @param {number} radius distance to draw the buffer
* @param {string} [units='kilometers'] any of the options supported by turf units
* @param {number} [steps=64] number of steps
* @param {number} [steps=8] number of steps
* @returns {Feature<Polygon|MultiPolygon>} buffered feature
*/
function bufferFeature(geojson, radius, units, steps) {
Expand Down Expand Up @@ -112,7 +110,7 @@ function bufferFeature(geojson, radius, units, steps) {
var reader = new GeoJSONReader();
var geom = reader.read(projected);
var distance = radiansToLength(lengthToRadians(radius, units), 'meters');
var buffered = BufferOp.bufferOp(geom, distance);
var buffered = BufferOp.bufferOp(geom, distance, steps);
var writer = new GeoJSONWriter();
buffered = writer.write(buffered);

Expand Down

0 comments on commit 4024376

Please sign in to comment.