forked from Turfjs/turf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
327 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test | ||
coverage |
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 |
---|---|---|
@@ -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. |
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 |
---|---|---|
@@ -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 | ||
``` |
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 |
---|---|---|
@@ -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(); |
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 |
---|---|---|
@@ -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]); | ||
}; |
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 |
---|---|---|
@@ -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" | ||
} | ||
} |
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 |
---|---|---|
@@ -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(); | ||
}); |
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
Oops, something went wrong.