-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added turf-rhumb-destination * added rhum-distance module; removed distance test in rhumb-destination (requires rhumb-distance) * update package and bench on rhumb-distance and rhumb-destination * added turf-rhumb-bearing * added validation tests to rhumb-distance and rhumb-destination * fixed linting errors * Update package.json module names * Compact test results @turf/rhumb-distance * Add more test cases in @turf/rhumb-destination * Update Benchmark to ES6 syntax * Remove entire switch statement @turf/rhumb-destination * Remove entire switch statement @turf/rhumb-distance * Update JSDocs * Update typescript definitions * Update JSDocs for other bearing/distance/destination modules * Remove JSDocs extra comment in example * added note on failing rhumb-distance test
- Loading branch information
1 parent
1764837
commit dc48afe
Showing
45 changed files
with
1,290 additions
and
19 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/// <reference types="geojson" /> | ||
|
||
type Point = GeoJSON.Feature<GeoJSON.Point>; | ||
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
|
||
/** | ||
* http://turfjs.org/docs/#bearing | ||
*/ | ||
declare function bearing(start: Point, end: Point): number; | ||
declare function bearing(start: Point, end: Point, final?: boolean): number; | ||
declare namespace bearing { } | ||
export = bearing; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
/// <reference types="geojson" /> | ||
|
||
import {Units} from '@turf/helpers' | ||
|
||
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
|
||
/** | ||
* http://turfjs.org/docs/#destination | ||
*/ | ||
declare function destination(from: Point, distance: number, bearing: number, units?: string): Point; | ||
declare function destination(origin: Point, distance: number, bearing: number, units?: Units): GeoJSON.Feature<GeoJSON.Point>; | ||
declare namespace destination { } | ||
export = destination; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
/// <reference types="geojson" /> | ||
|
||
type Point = GeoJSON.Feature<GeoJSON.Point>; | ||
import {Units} from '@turf/helpers' | ||
|
||
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
|
||
/** | ||
* http://turfjs.org/docs/#distance | ||
*/ | ||
declare function distance(from: Point, to: Point, units?: string): number; | ||
declare function distance(from: Point, to: Point, units?: Units): number; | ||
declare namespace distance { } | ||
export = distance; |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 TurfJS | ||
|
||
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,71 @@ | ||
# @turf/rhumb-bearing | ||
|
||
# rhumbBearing | ||
|
||
Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the bearing angle between them along a Rhumb line | ||
i.e. the angle measured in degrees start the north line (0 degrees) | ||
|
||
**Parameters** | ||
|
||
- `start` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** starting Point | ||
- `end` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** 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`) | ||
|
||
**Examples** | ||
|
||
```javascript | ||
var point1 = { | ||
"type": "Feature", | ||
"properties": { | ||
"marker-color": "#F00" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-75.343, 39.984] | ||
} | ||
}; | ||
var point2 = { | ||
"type": "Feature", | ||
"properties": { | ||
"marker-color": "#00F" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-75.534, 39.123] | ||
} | ||
}; | ||
|
||
var bearing = turf.rhumbBearing(point1, point2); | ||
|
||
//addToMap | ||
point1.properties.bearing = bearing | ||
point2.properties.bearing = bearing | ||
var addToMap = [point1, point2] | ||
``` | ||
|
||
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing from north 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 | ||
./scripts/generate-readmes in the turf project. --> | ||
|
||
--- | ||
|
||
This module is part of the [Turfjs project](http://turfjs.org/), an open source | ||
module collection dedicated to geographic algorithms. It is maintained in the | ||
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create | ||
PRs and issues. | ||
|
||
### Installation | ||
|
||
Install this module individually: | ||
|
||
```sh | ||
$ npm install @turf/rhumb-bearing | ||
``` | ||
|
||
Or install the Turf module that includes it as a function: | ||
|
||
```sh | ||
$ npm install @turf/turf | ||
``` |
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,20 @@ | ||
var {point} = require('@turf/helpers'); | ||
var Benchmark = require('benchmark'); | ||
var rhumbBearing = require('./'); | ||
|
||
var start = point([-75.4, 39.4]); | ||
var end = point([-75.534, 39.123]); | ||
|
||
/** | ||
* Benchmark Results | ||
* | ||
* initial bearing x 1,108,233 ops/sec ±3.22% (86 runs sampled) | ||
* final bearing x 1,144,822 ops/sec ±2.01% (88 runs sampled) | ||
*/ | ||
var suite = new Benchmark.Suite('turf-rhumb-bearing'); | ||
suite | ||
.add('initial bearing', () => rhumbBearing(start, end)) | ||
.add('final bearing', () => rhumbBearing(start, end, true)) | ||
.on('cycle', e => console.log(String(e.target))) | ||
.on('complete', () => {}) | ||
.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,10 @@ | ||
/// <reference types="geojson" /> | ||
|
||
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
|
||
/** | ||
* http://turfjs.org/docs/#rhumb-bearing | ||
*/ | ||
declare function rhumbBearing(start: Point, end: Point, final?: boolean): number; | ||
declare namespace rhumbBearing { } | ||
export = rhumbBearing; |
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,63 @@ | ||
// https://en.wikipedia.org/wiki/Rhumb_line | ||
// http://www.movable-type.co.uk/scripts/latlong.html#rhumblines | ||
var getCoord = require('@turf/invariant').getCoord; | ||
var GeodesyLatLon = require('geodesy').LatLonSpherical; | ||
|
||
/** | ||
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line | ||
* i.e. the angle measured in degrees start the north line (0 degrees) | ||
* | ||
* @name rhumbBearing | ||
* @param {Geometry|Feature<Point>|Array<number>} start starting Point | ||
* @param {Geometry|Feature<Point>|Array<number>} end ending Point | ||
* @param {boolean} [final=false] calculates the final bearing if true | ||
* @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise) | ||
* @example | ||
* var point1 = { | ||
* "type": "Feature", | ||
* "properties": { | ||
* "marker-color": "#F00" | ||
* }, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-75.343, 39.984] | ||
* } | ||
* }; | ||
* var point2 = { | ||
* "type": "Feature", | ||
* "properties": { | ||
* "marker-color": "#00F" | ||
* }, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-75.534, 39.123] | ||
* } | ||
* }; | ||
* | ||
* var bearing = turf.rhumbBearing(point1, point2); | ||
* | ||
* //addToMap | ||
* point1.properties.bearing = bearing | ||
* point2.properties.bearing = bearing | ||
* var addToMap = [point1, point2] | ||
*/ | ||
module.exports = function (start, end, final) { | ||
// validation | ||
if (!start) throw new Error('start point is required'); | ||
if (!end) throw new Error('end point is required'); | ||
|
||
var coordsStart = getCoord(start); | ||
var coordsEnd = getCoord(end); | ||
var origin = new GeodesyLatLon(coordsStart[1], coordsStart[0]); | ||
var destination = new GeodesyLatLon(coordsEnd[1], coordsEnd[0]); | ||
var bear360; | ||
if (final) { | ||
bear360 = destination.rhumbBearingTo(origin); | ||
} else { | ||
bear360 = origin.rhumbBearingTo(destination); | ||
} | ||
|
||
var bear180 = (bear360 > 180) ? -(360 - bear360) : bear360; | ||
|
||
return bear180; | ||
}; |
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,47 @@ | ||
{ | ||
"name": "@turf/rhumb-bearing", | ||
"version": "4.0.0", | ||
"description": "turf rhumb-bearing module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/Turfjs/turf.git" | ||
}, | ||
"keywords": [ | ||
"turf", | ||
"bearing", | ||
"loxodrome", | ||
"rhumb", | ||
"rhumb line" | ||
], | ||
"author": "Turf Authors", | ||
"contributors": [ | ||
"Stefano Borghi <@stebogit>", | ||
"Denis Carriere <@DenisCarriere>" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Turfjs/turf/issues" | ||
}, | ||
"homepage": "https://github.com/Turfjs/turf", | ||
"devDependencies": { | ||
"@turf/destination": "^4.2.0", | ||
"@turf/helpers": "^4.2.0", | ||
"benchmark": "^2.1.4", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
}, | ||
"dependencies": { | ||
"@turf/invariant": "^4.2.0", | ||
"geodesy": "1.1.1" | ||
} | ||
} |
Oops, something went wrong.