mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
haversine: cleanup union types, simplify LatLonTuple, add GeoJSON test
This commit is contained in:
@@ -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);
|
||||
|
||||
Vendored
+8
-15
@@ -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 {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user