@squawk/airspace 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/resolver.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAW,MAAM,SAAS,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAC;AAIlF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,8DAA8D;IAC9D,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,eAAe,EAAE,CAAC;AAmD3E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAgCzF"}
|
package/dist/resolver.js
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { polygon } from '@squawk/geo';
|
|
2
2
|
import { altitudeMatches } from './vertical-filter.js';
|
|
3
|
-
/**
|
|
4
|
-
* Computes an axis-aligned bounding box from a polygon exterior ring.
|
|
5
|
-
*/
|
|
6
|
-
function computeBoundingBox(ring) {
|
|
7
|
-
let minLon = Infinity;
|
|
8
|
-
let maxLon = -Infinity;
|
|
9
|
-
let minLat = Infinity;
|
|
10
|
-
let maxLat = -Infinity;
|
|
11
|
-
for (const coord of ring) {
|
|
12
|
-
const lon = coord[0];
|
|
13
|
-
const lat = coord[1];
|
|
14
|
-
if (lon < minLon) {
|
|
15
|
-
minLon = lon;
|
|
16
|
-
}
|
|
17
|
-
if (lon > maxLon) {
|
|
18
|
-
maxLon = lon;
|
|
19
|
-
}
|
|
20
|
-
if (lat < minLat) {
|
|
21
|
-
minLat = lat;
|
|
22
|
-
}
|
|
23
|
-
if (lat > maxLat) {
|
|
24
|
-
maxLat = lat;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return { minLon, maxLon, minLat, maxLat };
|
|
28
|
-
}
|
|
29
3
|
/**
|
|
30
4
|
* Parses a GeoJSON Feature into an IndexedFeature, extracting the
|
|
31
5
|
* AirspaceFeature properties and polygon ring. Returns null if the
|
|
@@ -36,8 +10,7 @@ function parseFeature(geoFeature) {
|
|
|
36
10
|
if (!geom || geom.type !== 'Polygon') {
|
|
37
11
|
return null;
|
|
38
12
|
}
|
|
39
|
-
const
|
|
40
|
-
const ring = polygon.coordinates[0];
|
|
13
|
+
const ring = geom.coordinates[0];
|
|
41
14
|
if (!ring || ring.length < 4) {
|
|
42
15
|
return null;
|
|
43
16
|
}
|
|
@@ -51,12 +24,12 @@ function parseFeature(geoFeature) {
|
|
|
51
24
|
identifier: props.identifier ?? '',
|
|
52
25
|
floor: props.floor,
|
|
53
26
|
ceiling: props.ceiling,
|
|
54
|
-
boundary:
|
|
27
|
+
boundary: geom,
|
|
55
28
|
state: props.state ?? null,
|
|
56
29
|
controllingFacility: props.controllingFacility ?? null,
|
|
57
30
|
scheduleDescription: props.scheduleDescription ?? null,
|
|
58
31
|
};
|
|
59
|
-
return { feature, ring, boundingBox:
|
|
32
|
+
return { feature, ring, boundingBox: polygon.boundingBox(ring) };
|
|
60
33
|
}
|
|
61
34
|
/**
|
|
62
35
|
* Creates a stateless airspace resolver function. The resolver accepts a
|
|
@@ -98,13 +71,10 @@ export function createAirspaceResolver(options) {
|
|
|
98
71
|
if (types && !types.has(feature.type)) {
|
|
99
72
|
continue;
|
|
100
73
|
}
|
|
101
|
-
if (lon
|
|
102
|
-
lon > boundingBox.maxLon ||
|
|
103
|
-
lat < boundingBox.minLat ||
|
|
104
|
-
lat > boundingBox.maxLat) {
|
|
74
|
+
if (!polygon.pointInBoundingBox(lon, lat, boundingBox)) {
|
|
105
75
|
continue;
|
|
106
76
|
}
|
|
107
|
-
if (!pointInPolygon(lon, lat, ring)) {
|
|
77
|
+
if (!polygon.pointInPolygon(lon, lat, ring)) {
|
|
108
78
|
continue;
|
|
109
79
|
}
|
|
110
80
|
if (!altitudeMatches(altitudeFt, feature.floor, feature.ceiling)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squawk/airspace",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pure logic library for querying US airspace geometry by position and altitude",
|
|
6
6
|
"author": "Neil Cochran",
|
|
@@ -33,11 +33,12 @@
|
|
|
33
33
|
"lint": "tsc --noEmit && eslint src"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@squawk/geo": "*",
|
|
36
37
|
"@squawk/types": "*"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@squawk/airspace-data": "*",
|
|
40
|
-
"@types/node": "^25.
|
|
41
|
+
"@types/node": "^25.6.0"
|
|
41
42
|
},
|
|
42
43
|
"keywords": [
|
|
43
44
|
"aviation",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests whether a point is inside a polygon using the ray casting algorithm.
|
|
3
|
-
* The polygon is represented as an array of [lon, lat] coordinate pairs
|
|
4
|
-
* forming a closed ring (first and last points are identical).
|
|
5
|
-
*
|
|
6
|
-
* Returns true if the point is inside or on the boundary of the polygon.
|
|
7
|
-
*/
|
|
8
|
-
export declare function pointInPolygon(
|
|
9
|
-
/** Longitude of the test point in decimal degrees. */
|
|
10
|
-
x: number,
|
|
11
|
-
/** Latitude of the test point in decimal degrees. */
|
|
12
|
-
y: number,
|
|
13
|
-
/** Polygon exterior ring as [lon, lat] coordinate pairs. */
|
|
14
|
-
ring: number[][]): boolean;
|
|
15
|
-
//# sourceMappingURL=point-in-polygon.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"point-in-polygon.d.ts","sourceRoot":"","sources":["../src/point-in-polygon.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,cAAc;AAC5B,sDAAsD;AACtD,CAAC,EAAE,MAAM;AACT,qDAAqD;AACrD,CAAC,EAAE,MAAM;AACT,4DAA4D;AAC5D,IAAI,EAAE,MAAM,EAAE,EAAE,GACf,OAAO,CAgBT"}
|
package/dist/point-in-polygon.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests whether a point is inside a polygon using the ray casting algorithm.
|
|
3
|
-
* The polygon is represented as an array of [lon, lat] coordinate pairs
|
|
4
|
-
* forming a closed ring (first and last points are identical).
|
|
5
|
-
*
|
|
6
|
-
* Returns true if the point is inside or on the boundary of the polygon.
|
|
7
|
-
*/
|
|
8
|
-
export function pointInPolygon(
|
|
9
|
-
/** Longitude of the test point in decimal degrees. */
|
|
10
|
-
x,
|
|
11
|
-
/** Latitude of the test point in decimal degrees. */
|
|
12
|
-
y,
|
|
13
|
-
/** Polygon exterior ring as [lon, lat] coordinate pairs. */
|
|
14
|
-
ring) {
|
|
15
|
-
let inside = false;
|
|
16
|
-
const len = ring.length;
|
|
17
|
-
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
18
|
-
const xi = ring[i][0];
|
|
19
|
-
const yi = ring[i][1];
|
|
20
|
-
const xj = ring[j][0];
|
|
21
|
-
const yj = ring[j][1];
|
|
22
|
-
if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) {
|
|
23
|
-
inside = !inside;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return inside;
|
|
27
|
-
}
|