vgavara / haversine-ts Goto Github PK
View Code? Open in Web Editor NEWTypescript library for calculations on a sphere surface with both decimal degrees (DD) or degrees minutes seconds (DMS) coordinates.
License: MIT License
Typescript library for calculations on a sphere surface with both decimal degrees (DD) or degrees minutes seconds (DMS) coordinates.
License: MIT License
Add Haversine
class a new method for calculating the coordinates of a destination point given a source point, a bearing and a distance.
Add suitable unit tests and update the documentation accordingly.
Sample:
/**
* Calculates the coordinates of a point given an start point, a distance and
* a bearing
*
* @param {DDPoint} startPoint - Start point, in decimal degrees coordinates.
* @param {number} distance - Distance from the start point to the targetted
* point, using as unit of measure that set in the class constructor
* (metres, kilometres or miles).
* @param {number} bearing Bearing to the targetted point, in degrees (0 to
* 360, clockwise from North).
*/
getPoint(startPoint: DDPoint, distance: number, bearing: number): DDPoint {
if (distance < 0)
throw new Error("Distance out of range: Must be equal of higher than 0");
if (bearing < 0 || bearing >= 360)
throw new Error("Bearing out of range: Must be between 0 and < 360");
const startLatitude = toRadians(startPoint.latitude);
const startLongitude = toRadians(startPoint.longitude);
const angularDistance = distance / this.sphereRadius;
const targetLatitude = Math.asin(
Math.sin(startLatitude) * Math.cos(angularDistance) +
Math.cos(startLatitude) * Math.sin(angularDistance) * Math.cos(bearing)
);
const targetLongitude =
startLongitude +
Math.atan2(
Math.sin(bearing) * Math.sin(angularDistance) * Math.cos(startLatitude),
Math.cos(angularDistance) -
Math.sin(startLatitude) * Math.sin(targetLatitude)
);
return new DDPoint(targetLatitude, targetLongitude);
}
Add Haversine
class a method to find the nearest/farthest point of a list of points to a given reference point:
havesine.getNearest(referencePoint: DDPoint, points: DDPoint[]) => DDPoint
havesine.getFarthest(referencePoint: DDPoint, points: DDPoint[]) => DDPoint
Create a Haversine static class supporting the calculation of the distance between two points.
Also create the Point class addressed to hold a sphere point latitude and longitude.
Create the file set needed for developing a typescript library able to be uploaded to NPM as package. The library must contain:
Coordinates range check must be fixed to validate that latitude ranges from -90 to 90 instead of -180 to 180.
This fix must be performed in both DD and DMS point classes
Create a GitHub workflow to be run when a PR to master/stable branches was created.
The workflow must build the project and run the tests
Add Haversine class a function for calculating the start and end bearings between two points in a sphere.
Add suitable unit tests and upgrade the documentation.
The step setting the npm version breaks, so it is necessary to remove it.
Perform these operations in README.md:
Add support to Degrees Minutes Seconds (DMS) coordinates
Set as readonly these class members:
latitude
and longitude
;degrees
, minutes
and seconds
uod
and sphereRadius
start
and end
Add required files, actions and secrets to allow an automatic deployment to NPM once a pull request was merged on branch stable and tagged.
Support @renovate in the repostiory
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
chai
, @types/chai
)mocha
, @types/mocha
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/pull-request.yml
actions/checkout v4
actions/setup-node v3
.github/workflows/release.yml
actions/checkout v4
actions/setup-node v3
package.json
@types/chai ^4.3.4
@types/mocha ^10.0.0
@types/sinon ^10.0.13
@typescript-eslint/eslint-plugin ^6.0.0
chai ^4.3.7
eslint ^8.28.0
eslint-config-prettier ^8.5.0
eslint-plugin-prettier ^5.0.0
husky ^8.0.2
lint-staged ^13.0.4
mocha ^10.1.0
prettier ^3.0.0
prettier-plugin-jsdoc ^1.0.0
sinon ^16.0.0
ts-node ^10.9.1
tsconfig-paths ^4.1.0
typescript ^4.9.3
Add Haversine
class a method (getInRange?) to find those points that are in a given distance range from a reference point:
havesine.getInRange(referencePoint: DDPoint, points: DDPoint[], distance: number) => DDPoint[]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.