@turf/bearing
Advanced tools
Comparing version 3.10.0 to 3.13.0
35
index.js
@@ -11,2 +11,3 @@ var getCoord = require('@turf/invariant').getCoord; | ||
* @param {Feature<Point>} end ending Point | ||
* @param {boolean} [final=false] calculates the final bearing if true | ||
* @returns {number} bearing in decimal degrees | ||
@@ -35,14 +36,8 @@ * @example | ||
* | ||
* var points = { | ||
* "type": "FeatureCollection", | ||
* "features": [point1, point2] | ||
* }; | ||
* | ||
* //=points | ||
* | ||
* var bearing = turf.bearing(point1, point2); | ||
* | ||
* //=bearing | ||
*/ | ||
module.exports = function (start, end) { | ||
function bearing(start, end, final) { | ||
if (final === true) return calculateFinalBearing(start, end); | ||
var degrees2radians = Math.PI / 180; | ||
@@ -61,5 +56,21 @@ var radians2degrees = 180 / Math.PI; | ||
var bearing = radians2degrees * Math.atan2(a, b); | ||
var bear = radians2degrees * Math.atan2(a, b); | ||
return bearing; | ||
}; | ||
return bear; | ||
} | ||
/** | ||
* Calculates Final Bearing | ||
* | ||
* @param {Feature<Point>} start starting Point | ||
* @param {Feature<Point>} end ending Point | ||
* @returns {number} bearing | ||
*/ | ||
function calculateFinalBearing(start, end) { | ||
// Swap start & end | ||
var bear = bearing(end, start); | ||
bear = (bear + 180) % 360; | ||
return bear; | ||
} | ||
module.exports = bearing; |
{ | ||
"name": "@turf/bearing", | ||
"version": "3.10.0", | ||
"version": "3.13.0", | ||
"description": "turf bearing module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
}, | ||
@@ -23,10 +29,12 @@ "repository": { | ||
"homepage": "https://github.com/Turfjs/turf", | ||
"dependencies": { | ||
"@turf/invariant": "^3.10.0" | ||
}, | ||
"devDependencies": { | ||
"@turf/destination": "^3.13.0", | ||
"@turf/helpers": "^3.13.0", | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.5.0" | ||
"tape": "^3.5.0", | ||
"write-json-file": "^2.0.0" | ||
}, | ||
"types": "index.d.ts" | ||
"dependencies": { | ||
"@turf/invariant": "^3.13.0" | ||
} | ||
} |
@@ -11,2 +11,3 @@ # @turf/bearing | ||
- `end` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** ending Point | ||
- `final` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** calculates the final bearing if true (optional, default `false`) | ||
@@ -37,11 +38,3 @@ **Examples** | ||
var points = { | ||
"type": "FeatureCollection", | ||
"features": [point1, point2] | ||
}; | ||
//=points | ||
var bearing = turf.bearing(point1, point2); | ||
//=bearing | ||
@@ -52,2 +45,13 @@ ``` | ||
# calculateFinalBearing | ||
Calculates Final Bearing | ||
**Parameters** | ||
- `start` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** starting Point | ||
- `end` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** ending Point | ||
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
@@ -54,0 +58,0 @@ if you find an error, edit the source file (likely index.js), and re-run |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6426
78
0
5
5
74
Updated@turf/invariant@^3.13.0