Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jun 2, 2016
2 parents df155d2 + 66cbc32 commit aa466fc
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ var values = features.map(function(feature) {
});
```

**If you were using turf-extent**

turf-extent's name was changed to turf-bbox. It is functionally the same.

```js
turf.bbox(poly) // [minx, miny, maxx, maxy]
```

# 2.0.0

* turf-grid renamed turf-point-grid (turf.grid => turf.pointGrid)
Expand Down
2 changes: 2 additions & 0 deletions packages/turf-circle/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test
coverage
21 changes: 21 additions & 0 deletions packages/turf-circle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2016 Mustafa Dokumacı

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.
65 changes: 65 additions & 0 deletions packages/turf-circle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# turf-circle

[![build status](https://secure.travis-ci.org/Turfjs/turf-circle.png)](http://travis-ci.org/Turfjs/turf-circle)

turf circle module


### `turf.circle(center, radius, steps, units)`

Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.


### Parameters

| parameter | type | description |
| ---------- | ------------------ | -------------------------------------- |
| `center` | Feature\.\<Point\> | center point |
| `radius` | Number | radius of the circle |
| `steps` | Number | number of steps |
| `units` | String | miles, kilometers, degrees, or radians |


### Example

```js
var center = {
"type": "Feature",
"properties": {
"marker-color": "#0f0"
},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
};
var radius = 5;
var steps = 10;
var units = 'kilometers';

var circle = turf.circle(center, radius, steps, units);

var result = {
"type": "FeatureCollection",
"features": [center, circle]
};

//=result
```


**Returns** `Feature.<Polygon>`, circle polygon

## Installation

Requires [nodejs](http://nodejs.org/).

```sh
$ npm install turf-circle
```

## Tests

```sh
$ npm test
```
21 changes: 21 additions & 0 deletions packages/turf-circle/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var circle = require('./');
var Benchmark = require('benchmark');

var center = {
type: "Feature",
geometry: {type: "Point", coordinates: [-75.0, 39.0]}
};
var radius = 5;
var steps = 10;

var suite = new Benchmark.Suite('turf-circle');

suite
.add('turf-circle',function () {
circle(center, radius, steps, 'kilometers');
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {})
.run();
50 changes: 50 additions & 0 deletions packages/turf-circle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var destination = require('turf-destination');
var helpers = require('turf-helpers');
var polygon = helpers.polygon;


/**
* Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
*
* @name circle
* @param {Feature<Point>} center center point
* @param {number} radius radius of the circle
* @param {number} steps number of steps
* @param {String} [units=kilometers] miles, kilometers, degrees, or radians
* @returns {Feature<Polygon>} circle polygon
* @example
* var center = {
* "type": "Feature",
* "properties": {
* "marker-color": "#0f0"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-75.343, 39.984]
* }
* };
* var radius = 5;
* var steps = 10;
* var units = 'kilometers';
*
* var circle = turf.circle(center, radius, steps, units);
*
* var result = {
* "type": "FeatureCollection",
* "features": [center, circle]
* };
*
* //=result
*/
module.exports = function (center, radius, steps, units) {
steps = steps || 64;
var coordinates = [];

for (var i = 0; i < steps; i++) {
coordinates.push(destination(center, radius, i * 360 / steps, units).geometry.coordinates);
}

coordinates.push(coordinates[0]);

return polygon([coordinates]);
};
41 changes: 41 additions & 0 deletions packages/turf-circle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "turf-circle",
"version": "3.0.5",
"description": "turf circle module",
"main": "index.js",
"scripts": {
"test": "tape test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/Turfjs/turf-circle.git"
},
"keywords": [
"turf",
"circle",
"radius",
"polygon",
"miles",
"km"
],
"author": {
"name": "Mustafa Dokumacı",
"email": "[email protected]",
"url": "http://mustafadokumaci.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/Turfjs/turf-circle/issues"
},
"homepage": "https://github.com/Turfjs/turf-circle",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^3.5.0",
"turf-distance": "^3.0.5",
"turf-inside": "^3.0.5"
},
"dependencies": {
"turf-destination": "^3.0.5",
"turf-helpers": "^3.0.5"
}
}
21 changes: 21 additions & 0 deletions packages/turf-circle/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var test = require('tape');
var destination = require('turf-destination');
var inside = require('turf-inside');
var circle = require('./');

test('circle', function(t){
var center = {
type: "Feature",
geometry: {type: "Point", coordinates: [-75.343, 39.984]}
};
var radius = 5;
var steps = 10;

var polygon = circle(center, radius, steps, 'kilometers');
var point1 = destination(center, radius - 1, 45, 'kilometers');
var point2 = destination(center, radius + 1, 135, 'kilometers');

t.equal(inside(point1, polygon), true, 'point is inside the polygon');
t.equal(inside(point2, polygon), false, 'point is outside the polygon');
t.end();
});
24 changes: 10 additions & 14 deletions packages/turf-midpoint/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ var Benchmark = require('benchmark');
var fs = require('fs');
var point = require('turf-helpers').point;

var pt1 = point(0,0);
var pt2 = point(10,0);
var pt1 = point([0,0]);
var pt2 = point([10,0]);

var suite = new Benchmark.Suite('turf-midpoint');
suite
.add('turf-midpoint',function () {
midpoint(pt1, pt2);
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {

})
.run();
new Benchmark.Suite('turf-midpoint')
.add('turf-midpoint',function () {
midpoint(pt1, pt2);
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.run();
24 changes: 9 additions & 15 deletions packages/turf-midpoint/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// http://cs.selu.edu/~rbyrd/math/midpoint/
// ((x1+x2)/2), ((y1+y2)/2)
var invariant = require('turf-invariant');
var bearing = require('turf-bearing');
var destination = require('turf-destination');
var distance = require('turf-distance');

/**
* Takes two {@link Point|points} and returns a point midway between them.
* This gives the middle point in terms of latitude and longitude averaging,
* so the midpoint is guaranteed to fall on the line on an equirectangular
* projection, but may not be halfway between the points on the globe.
* The midpoint is calculated geodesically, meaning the curvature of the earth is taken into account.
*
* @name midpoint
* @param {Feature<Point>} pt1 first point
Expand Down Expand Up @@ -42,13 +40,9 @@ var invariant = require('turf-invariant');
* //=result
*/
module.exports = function (point1, point2) {
var coords1 = invariant.getCoord(point1);
var coords2 = invariant.getCoord(point2);
return {
type: 'Point',
coordinates: [
(coords1[0] + coords2[0]) / 2,
(coords1[1] + coords2[1]) / 2
]
};
var dist = distance(point1, point2, 'miles');
var heading = bearing(point1, point2);
var midpoint = destination(point1, dist / 2, heading, 'miles');

return midpoint;
};
3 changes: 3 additions & 0 deletions packages/turf-midpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"tape": "^3.5.0"
},
"dependencies": {
"turf-bearing": "^3.0.1",
"turf-destination": "^3.0.5",
"turf-distance": "^3.0.5",
"turf-invariant": "^3.0.1"
}
}
Loading

0 comments on commit aa466fc

Please sign in to comment.