Skip to content

Commit

Permalink
Merge branch 'master' into updated-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere authored Apr 12, 2017
2 parents 3cf9ee8 + a8fcfb3 commit 45f966b
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 33 deletions.
5 changes: 3 additions & 2 deletions packages/turf-bearing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# bearing

Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the geographic bearing between them.
Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the geographic bearing between them,
i.e. the angle measured in degrees from the north line (0 degrees)

**Parameters**

Expand Down Expand Up @@ -39,7 +40,7 @@ point1.properties.bearing = bearing
//=bearing
```

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing in decimal degrees
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)

<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
Expand Down
5 changes: 3 additions & 2 deletions packages/turf-bearing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var getCoord = require('@turf/invariant').getCoord;
//http://www.movable-type.co.uk/scripts/latlong.html

/**
* Takes two {@link Point|points} and finds the geographic bearing between them.
* Takes two {@link Point|points} and finds the geographic bearing between them,
* i.e. the angle measured in degrees from the north line (0 degrees)
*
* @name bearing
* @param {Feature<Point>} start starting Point
* @param {Feature<Point>} end ending Point
* @param {boolean} [final=false] calculates the final bearing if true
* @returns {number} bearing in decimal degrees
* @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
* @example
* var point1 = {
* "type": "Feature",
Expand Down
15 changes: 11 additions & 4 deletions packages/turf-circle/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var destination = require('@turf/destination');
var helpers = require('@turf/helpers');
var polygon = helpers.polygon;
var polygon = require('@turf/helpers').polygon;

/**
* Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
Expand All @@ -19,10 +18,18 @@ var polygon = helpers.polygon;
*
* var circle = turf.circle(center, radius, steps, units);
*
* //=circle
* //addToMap
* var addToMap = [center, circle]
*/
module.exports = function (center, radius, steps, units) {
// validation
if (!center) throw new Error('center is required');
if (!radius) throw new Error('radius is required');

// default params
steps = steps || 64;

var properties = center.properties;
var coordinates = [];

for (var i = 0; i < steps; i++) {
Expand All @@ -31,5 +38,5 @@ module.exports = function (center, radius, steps, units) {

coordinates.push(coordinates[0]);

return polygon([coordinates]);
return polygon([coordinates], properties);
};
9 changes: 5 additions & 4 deletions packages/turf-circle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^3.5.0",
"@turf/distance": "^4.1.0",
"@turf/inside": "^4.1.0"
"@turf/truncate": "^4.1.0",
"benchmark": "^2.1.4",
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.0.0"
},
"dependencies": {
"@turf/destination": "^4.1.0",
Expand Down
42 changes: 27 additions & 15 deletions packages/turf-circle/test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
var test = require('tape');
var destination = require('@turf/destination');
var inside = require('@turf/inside');
var circle = require('./');
const test = require('tape');
const fs = require('fs');
const path = require('path');
const load = require('load-json-file');
const write = require('write-json-file');
const truncate = require('@turf/truncate');
const featureCollection = require('@turf/helpers').featureCollection;
const circle = require('./');

test('circle', function(t){
var center = {
type: "Feature",
geometry: {type: "Point", coordinates: [-75.343, 39.984]}
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)
};
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');
test('turf-circle', t => {
for (const {filename, name, geojson} of fixtures) {
const {radius, steps, units} = geojson.properties;
const C = truncate(circle(geojson, radius, steps, units));
const results = featureCollection([geojson, C]);

t.equal(inside(point1, polygon), true, 'point is inside the polygon');
t.equal(inside(point2, polygon), false, 'point is outside the polygon');
if (process.env.REGEN) write.sync(directories.out + filename, results);
t.deepEquals(results, load.sync(directories.out + filename), name);
}
t.end();
});
13 changes: 13 additions & 0 deletions packages/turf-circle/test/in/circle1.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "Feature",
"properties": {
"radius": 5
},
"geometry": {
"type": "Point",
"coordinates": [
-75.343,
39.984
]
}
}
Loading

2 comments on commit 45f966b

@stebogit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DenisCarriere @rowanwins since you are dealing with updating docs, I just noticed in CONTRIBUTING.md shouldn't the test.js file be in the main folder?

@DenisCarriere
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Indeed, I don't think anyone has touched the CONTRIBUTING.md doc.

Ex: Module Folder Structure

turf-<module>
│   index.js
│   index.d.ts
│   bench.js
│   test.js
│   package.json
│   README.md
│
└───tests
    │   types.ts
    │
    ├───in
    │   points.geojson
    │
    └───out
        points.geojson

Please sign in to comment.