Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 32 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 12 | import * as turf from '@turf/turf'; |
|
2 | |||
3 | 12 | export function getDistance(lat1: number, lon1: number, lat2: number, lon2: number) { |
|
4 | 50 | const from = turf.point([lon1, lat1]); |
|
5 | 50 | const to = turf.point([lon2, lat2]); |
|
6 | 50 | return turf.distance(from, to) * 1000; |
|
7 | } |
||
8 | |||
9 | 12 | export function positionInsidePolygon( |
|
10 | lat: number, |
||
11 | lon: number, |
||
12 | polygon: { lat: number; lng: number }[], |
||
13 | ): boolean { |
||
14 | 486 | const point = { |
|
15 | type: 'Feature' as const, |
||
16 | properties: {}, |
||
17 | geometry: { |
||
18 | type: 'Point' as const, |
||
19 | coordinates: [lon, lat], |
||
20 | }, |
||
21 | }; |
||
22 | 486 | const poly = { |
|
23 | type: 'Feature' as const, |
||
24 | properties: {}, |
||
25 | geometry: { |
||
26 | type: 'Polygon' as const, |
||
27 | 2469 | coordinates: [polygon.map((p) => [p.lng, p.lat])], |
|
28 | }, |
||
29 | }; |
||
30 | 486 | return turf.booleanPointInPolygon(point, poly); |
|
31 | } |
||
32 |