haversine: cleanup union types, simplify LatLonTuple, add GeoJSON test

This commit is contained in:
Daniel Hritzkiv
2017-11-15 11:36:28 -05:00
parent 5564fca4c4
commit fec98c71f8
2 changed files with 34 additions and 23 deletions
+26 -8
View File
@@ -1,11 +1,11 @@
import haversine = require('haversine');
const start: haversine.CoordinateLongNames = {
const start = {
longitude: 48.1548256,
latitude: 11.4017529
};
const end: haversine.CoordinateLongNames = {
const end = {
longitude: 52.5065133,
latitude: 13.1445551
};
@@ -17,19 +17,17 @@ const options: haversine.Options = {
haversine(start, end, options);
const startShort: haversine.CoordinateShortNames = {
const startShort = {
lon: 48.1548256,
lat: 11.4017529
};
const endShort: haversine.CoordinateShortNames = {
const endShort = {
lon: 52.5065133,
lat: 13.1445551
};
const optionsShort: haversine.Options = {
unit: 'km',
threshold: 1,
format: '{lon,lat}'
};
@@ -40,9 +38,29 @@ const startLatLon: haversine.LatLonTuple = [11.4017529, 48.1548256];
const endLatLon: haversine.LatLonTuple = [13.1445551, 52.5065133];
const optionsLatLon: haversine.Options = {
unit: 'km',
threshold: 1,
format: '[lat,lon]'
};
haversine(startLatLon, endLatLon, optionsLatLon);
const startGeoJSON = {
type: "Feature",
geometry: {
type: "LineString",
coordinates: startLatLon
}
};
const endGeoJSON = {
type: "Feature",
geometry: {
type: "LineString",
coordinates: endLatLon
}
};
const optionsGeoJSON: haversine.Options = {
format: 'geojson'
};
haversine(startGeoJSON, endGeoJSON, optionsGeoJSON);
+8 -15
View File
@@ -4,20 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace haversine {
interface CoordinateLongNames {
longitude: number;
latitude: number;
}
interface CoordinateShortNames {
lat: number;
lon: number;
}
interface LatLonTuple extends Array<number> {
0: number;
1: number;
}
type LatLonTuple = [number, number];
interface GeoJSON {
geometry: {
@@ -25,7 +12,13 @@ declare namespace haversine {
};
}
type Coordinate = (CoordinateLongNames | CoordinateShortNames | LatLonTuple | GeoJSON);
type Coordinate = ({
longitude: number;
latitude: number;
} | {
lat: number;
lon: number;
} | LatLonTuple | GeoJSON);
interface Options {
/**