@osmix/shared 0.0.2 → 0.0.7
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/CHANGELOG.md +33 -0
- package/README.md +49 -19
- package/dist/assert.d.ts +24 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +28 -0
- package/dist/assert.js.map +1 -0
- package/dist/bbox-intersects.d.ts +15 -0
- package/dist/bbox-intersects.d.ts.map +1 -0
- package/dist/bbox-intersects.js +24 -0
- package/dist/bbox-intersects.js.map +1 -0
- package/dist/bytes-to-stream.d.ts +18 -0
- package/dist/bytes-to-stream.d.ts.map +1 -0
- package/dist/bytes-to-stream.js +25 -0
- package/dist/bytes-to-stream.js.map +1 -0
- package/dist/color.d.ts +4 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +33 -0
- package/dist/color.js.map +1 -0
- package/dist/concat-bytes.d.ts +5 -0
- package/dist/concat-bytes.d.ts.map +1 -0
- package/dist/concat-bytes.js +14 -0
- package/dist/concat-bytes.js.map +1 -0
- package/dist/coordinates.d.ts +28 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +38 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/haversine-distance.d.ts +16 -0
- package/dist/haversine-distance.d.ts.map +1 -0
- package/dist/haversine-distance.js +26 -0
- package/dist/haversine-distance.js.map +1 -0
- package/dist/lineclip.d.ts +2 -0
- package/dist/lineclip.d.ts.map +1 -0
- package/dist/lineclip.js +3 -0
- package/dist/lineclip.js.map +1 -0
- package/dist/progress.d.ts +42 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +53 -0
- package/dist/progress.js.map +1 -0
- package/dist/relation-kind.d.ts +69 -0
- package/dist/relation-kind.d.ts.map +1 -0
- package/dist/relation-kind.js +375 -0
- package/dist/relation-kind.js.map +1 -0
- package/dist/relation-multipolygon.d.ts +43 -0
- package/dist/relation-multipolygon.d.ts.map +1 -0
- package/dist/relation-multipolygon.js +195 -0
- package/dist/relation-multipolygon.js.map +1 -0
- package/dist/src/assert.d.ts +20 -1
- package/dist/src/assert.d.ts.map +1 -1
- package/dist/src/assert.js +20 -1
- package/dist/src/assert.js.map +1 -1
- package/dist/src/bbox-intersects.d.ts +15 -0
- package/dist/src/bbox-intersects.d.ts.map +1 -0
- package/dist/src/bbox-intersects.js +24 -0
- package/dist/src/bbox-intersects.js.map +1 -0
- package/dist/src/bytes-to-stream.d.ts +17 -1
- package/dist/src/bytes-to-stream.d.ts.map +1 -1
- package/dist/src/bytes-to-stream.js +16 -0
- package/dist/src/bytes-to-stream.js.map +1 -1
- package/dist/src/color.d.ts +4 -0
- package/dist/src/color.d.ts.map +1 -0
- package/dist/src/color.js +33 -0
- package/dist/src/color.js.map +1 -0
- package/dist/src/coordinates.d.ts +28 -0
- package/dist/src/coordinates.d.ts.map +1 -0
- package/dist/src/coordinates.js +38 -0
- package/dist/src/coordinates.js.map +1 -0
- package/dist/src/haversine-distance.d.ts +9 -1
- package/dist/src/haversine-distance.d.ts.map +1 -1
- package/dist/src/haversine-distance.js +9 -1
- package/dist/src/haversine-distance.js.map +1 -1
- package/dist/src/progress.d.ts +42 -0
- package/dist/src/progress.d.ts.map +1 -0
- package/dist/src/progress.js +53 -0
- package/dist/src/progress.js.map +1 -0
- package/dist/src/relation-kind.d.ts +69 -0
- package/dist/src/relation-kind.d.ts.map +1 -0
- package/dist/src/relation-kind.js +375 -0
- package/dist/src/relation-kind.js.map +1 -0
- package/dist/src/relation-multipolygon.d.ts +43 -0
- package/dist/src/relation-multipolygon.d.ts.map +1 -0
- package/dist/src/relation-multipolygon.js +195 -0
- package/dist/src/relation-multipolygon.js.map +1 -0
- package/dist/src/stream-to-bytes.d.ts +16 -0
- package/dist/src/stream-to-bytes.d.ts.map +1 -1
- package/dist/src/stream-to-bytes.js +16 -0
- package/dist/src/stream-to-bytes.js.map +1 -1
- package/dist/src/test/fixtures.d.ts +1 -1
- package/dist/src/test/fixtures.d.ts.map +1 -1
- package/dist/src/test/fixtures.js +16 -8
- package/dist/src/test/fixtures.js.map +1 -1
- package/dist/src/throttle.d.ts +25 -0
- package/dist/src/throttle.d.ts.map +1 -0
- package/dist/src/throttle.js +34 -0
- package/dist/src/throttle.js.map +1 -0
- package/dist/src/tile.d.ts +34 -0
- package/dist/src/tile.d.ts.map +1 -0
- package/dist/src/tile.js +72 -0
- package/dist/src/tile.js.map +1 -0
- package/dist/src/transform-bytes.d.ts +22 -0
- package/dist/src/transform-bytes.d.ts.map +1 -1
- package/dist/src/transform-bytes.js +22 -0
- package/dist/src/transform-bytes.js.map +1 -1
- package/dist/src/types.d.ts +76 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +70 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/way-is-area.d.ts +24 -0
- package/dist/src/way-is-area.d.ts.map +1 -0
- package/dist/src/way-is-area.js +104 -0
- package/dist/src/way-is-area.js.map +1 -0
- package/dist/src/zigzag.d.ts +33 -0
- package/dist/src/zigzag.d.ts.map +1 -0
- package/dist/src/zigzag.js +40 -0
- package/dist/src/zigzag.js.map +1 -0
- package/dist/stream-to-bytes.d.ts +18 -0
- package/dist/stream-to-bytes.d.ts.map +1 -0
- package/dist/stream-to-bytes.js +30 -0
- package/dist/stream-to-bytes.js.map +1 -0
- package/dist/test/fixtures.d.ts +36 -0
- package/dist/test/fixtures.d.ts.map +1 -0
- package/dist/test/fixtures.js +175 -0
- package/dist/test/fixtures.js.map +1 -0
- package/dist/test/haversine-distance.test.js +2 -2
- package/dist/test/haversine-distance.test.js.map +1 -1
- package/dist/test/relation-kind.test.d.ts +2 -0
- package/dist/test/relation-kind.test.d.ts.map +1 -0
- package/dist/test/relation-kind.test.js +367 -0
- package/dist/test/relation-kind.test.js.map +1 -0
- package/dist/test/relation-multipolygon.test.d.ts +2 -0
- package/dist/test/relation-multipolygon.test.d.ts.map +1 -0
- package/dist/test/relation-multipolygon.test.js +237 -0
- package/dist/test/relation-multipolygon.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +76 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/way-is-area.test.d.ts +2 -0
- package/dist/test/way-is-area.test.d.ts.map +1 -0
- package/dist/test/way-is-area.test.js +31 -0
- package/dist/test/way-is-area.test.js.map +1 -0
- package/dist/throttle.d.ts +25 -0
- package/dist/throttle.d.ts.map +1 -0
- package/dist/throttle.js +34 -0
- package/dist/throttle.js.map +1 -0
- package/dist/tile.d.ts +34 -0
- package/dist/tile.d.ts.map +1 -0
- package/dist/tile.js +72 -0
- package/dist/tile.js.map +1 -0
- package/dist/transform-bytes.d.ts +24 -0
- package/dist/transform-bytes.d.ts.map +1 -0
- package/dist/transform-bytes.js +28 -0
- package/dist/transform-bytes.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/utils.js.map +1 -0
- package/dist/way-is-area.d.ts +24 -0
- package/dist/way-is-area.d.ts.map +1 -0
- package/dist/way-is-area.js +104 -0
- package/dist/way-is-area.js.map +1 -0
- package/dist/zigzag.d.ts +33 -0
- package/dist/zigzag.d.ts.map +1 -0
- package/dist/zigzag.js +40 -0
- package/dist/zigzag.js.map +1 -0
- package/package.json +11 -10
- package/src/assert.ts +21 -1
- package/src/bbox-intersects.ts +30 -0
- package/src/bytes-to-stream.ts +17 -0
- package/src/color.ts +37 -0
- package/src/coordinates.ts +45 -0
- package/src/haversine-distance.ts +10 -1
- package/src/progress.ts +74 -0
- package/src/relation-kind.ts +446 -0
- package/src/relation-multipolygon.ts +225 -0
- package/src/stream-to-bytes.ts +17 -0
- package/src/test/fixtures.ts +16 -12
- package/src/throttle.ts +37 -0
- package/src/tile.ts +89 -0
- package/src/transform-bytes.ts +23 -0
- package/src/types.ts +93 -1
- package/src/utils.ts +79 -0
- package/src/way-is-area.ts +107 -0
- package/src/zigzag.ts +42 -0
- package/test/haversine-distance.test.ts +2 -2
- package/test/relation-kind.test.ts +426 -0
- package/test/relation-multipolygon.test.ts +265 -0
- package/test/utils.test.ts +103 -0
- package/test/way-is-area.test.ts +42 -0
- package/tsconfig/test.json +1 -0
- package/tsconfig.build.json +5 -0
- package/dist/src/spherical-mercator.d.ts +0 -15
- package/dist/src/spherical-mercator.d.ts.map +0 -1
- package/dist/src/spherical-mercator.js +0 -35
- package/dist/src/spherical-mercator.js.map +0 -1
- package/dist/src/spherical-mercator.test.d.ts +0 -2
- package/dist/src/spherical-mercator.test.d.ts.map +0 -1
- package/dist/src/spherical-mercator.test.js +0 -25
- package/dist/src/spherical-mercator.test.js.map +0 -1
- package/src/spherical-mercator.test.ts +0 -42
- package/src/spherical-mercator.ts +0 -42
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions used across all Osmix packages.
|
|
3
|
+
*
|
|
4
|
+
* Includes geographic primitives (LonLat, Bbox), tile coordinates,
|
|
5
|
+
* and core OSM entity types (Node, Way, Relation).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Geographic coordinate as [longitude, latitude] tuple. */
|
|
10
|
+
export type LonLat = [lon: number, lat: number];
|
|
11
|
+
/** 2D pixel or cartesian coordinate as [x, y] tuple. */
|
|
12
|
+
export type XY = [x: number, y: number];
|
|
13
|
+
/** Geographic coordinate as object with lon/lat properties. */
|
|
14
|
+
export interface ILonLat {
|
|
15
|
+
lon: number;
|
|
16
|
+
lat: number;
|
|
17
|
+
}
|
|
18
|
+
/** XYZ tile coordinate as [x, y, z] tuple. */
|
|
19
|
+
export type Tile = [x: number, y: number, z: number];
|
|
20
|
+
/**
|
|
21
|
+
* Project LonLat to pixels
|
|
22
|
+
*/
|
|
23
|
+
export type LonLatToPixel = (ll: LonLat, zoom: number) => XY;
|
|
24
|
+
export type LonLatToTilePixel = (ll: LonLat, z: number, extent: number) => XY;
|
|
25
|
+
export type Rgba = [r: number, g: number, b: number, a: number] | Uint8ClampedArray;
|
|
26
|
+
/**
|
|
27
|
+
* A bounding box in the format [minLon, minLat, maxLon, maxLat].
|
|
28
|
+
* GeoJSON.BBox allows for 3D bounding boxes, but we use tools that expect 2D bounding boxes.
|
|
29
|
+
*/
|
|
30
|
+
export type GeoBbox2D = [
|
|
31
|
+
minLon: number,
|
|
32
|
+
minLat: number,
|
|
33
|
+
maxLon: number,
|
|
34
|
+
maxLat: number
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* A pixel bounding box in the format [minX, minY, maxX, maxY]. Note: minY is north. maxY is south.
|
|
38
|
+
*/
|
|
39
|
+
export type TilePxBbox = [
|
|
40
|
+
minX: number,
|
|
41
|
+
minY: number,
|
|
42
|
+
maxX: number,
|
|
43
|
+
maxY: number
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Shared OSM Types
|
|
47
|
+
*/
|
|
48
|
+
export type OsmEntityType = "node" | "way" | "relation";
|
|
49
|
+
export interface OsmInfoParsed {
|
|
50
|
+
version?: number;
|
|
51
|
+
timestamp?: number;
|
|
52
|
+
changeset?: number;
|
|
53
|
+
uid?: number;
|
|
54
|
+
user_sid?: number;
|
|
55
|
+
visible?: boolean;
|
|
56
|
+
user?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface OsmTags {
|
|
59
|
+
[key: string]: string | number;
|
|
60
|
+
}
|
|
61
|
+
interface IOsmEntity {
|
|
62
|
+
id: number;
|
|
63
|
+
info?: OsmInfoParsed;
|
|
64
|
+
tags?: OsmTags;
|
|
65
|
+
}
|
|
66
|
+
export interface OsmNode extends IOsmEntity, ILonLat {
|
|
67
|
+
}
|
|
68
|
+
export interface OsmWay extends IOsmEntity {
|
|
69
|
+
refs: number[];
|
|
70
|
+
}
|
|
71
|
+
export interface OsmRelationMember {
|
|
72
|
+
type: OsmEntityType;
|
|
73
|
+
ref: number;
|
|
74
|
+
role?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface OsmRelation extends IOsmEntity {
|
|
77
|
+
members: OsmRelationMember[];
|
|
78
|
+
}
|
|
79
|
+
export type OsmEntity = OsmNode | OsmWay | OsmRelation;
|
|
80
|
+
export interface OsmEntityTypeMap extends Record<OsmEntityType, IOsmEntity> {
|
|
81
|
+
node: OsmNode;
|
|
82
|
+
way: OsmWay;
|
|
83
|
+
relation: OsmRelation;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Semantic kinds of OSM relations based on their type tag and structure.
|
|
87
|
+
*/
|
|
88
|
+
export type RelationKind = "area" | "line" | "point" | "logic" | "super";
|
|
89
|
+
/**
|
|
90
|
+
* Metadata about a relation kind, including expected roles and whether member order matters.
|
|
91
|
+
*/
|
|
92
|
+
export interface RelationKindMetadata {
|
|
93
|
+
kind: RelationKind;
|
|
94
|
+
expectedRoles?: string[];
|
|
95
|
+
orderMatters: boolean;
|
|
96
|
+
description: string;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAC/C,wDAAwD;AACxD,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AAEvC,+DAA+D;AAC/D,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General OSM entity utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides type guards, equality checks, and type detection for OSM entities.
|
|
5
|
+
* Uses deep equality checking for tags, info, and entity-specific properties.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { OsmEntity, OsmEntityType, OsmNode, OsmRelation, OsmWay } from "./types";
|
|
10
|
+
/** Type guard: check if entity is a Node. */
|
|
11
|
+
export declare function isNode(entity: OsmEntity): entity is OsmNode;
|
|
12
|
+
/** Check if two nodes are equal (position, tags, and info). */
|
|
13
|
+
export declare function isNodeEqual(a: OsmNode, b: OsmNode): boolean;
|
|
14
|
+
/** Type guard: check if entity is a Way. */
|
|
15
|
+
export declare function isWay(entity: OsmEntity): entity is OsmWay;
|
|
16
|
+
/** Type guard: check if entity is a Relation. */
|
|
17
|
+
export declare function isRelation(entity: OsmEntity): entity is OsmRelation;
|
|
18
|
+
/** Check if two ways are equal (refs, tags, and info). */
|
|
19
|
+
export declare function isWayEqual(a: OsmWay, b: OsmWay): boolean;
|
|
20
|
+
/** Check if two relations are equal (members, tags, and info). */
|
|
21
|
+
export declare function isRelationEqual(a: OsmRelation, b: OsmRelation): boolean;
|
|
22
|
+
/** Check if two entities have equal properties (type-aware comparison). */
|
|
23
|
+
export declare function entityPropertiesEqual(a: OsmEntity, b: OsmEntity): boolean;
|
|
24
|
+
/** Get the entity type ("node", "way", or "relation") for an entity. */
|
|
25
|
+
export declare function getEntityType(entity: OsmEntity): OsmEntityType;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a relation is a multipolygon relation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isMultipolygonRelation(relation: OsmRelation): boolean;
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,WAAW,EACX,MAAM,EACN,MAAM,SAAS,CAAA;AAShB,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,OAAO,CAE3D;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAEjD;AAED,4CAA4C;AAC5C,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,MAAM,CAEzD;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,WAAW,CAEnE;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,WAE9C;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,WAE7D;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,WAO/D;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAK9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAErE"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General OSM entity utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides type guards, equality checks, and type detection for OSM entities.
|
|
5
|
+
* Uses deep equality checking for tags, info, and entity-specific properties.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { dequal } from "dequal/lite";
|
|
10
|
+
/**
|
|
11
|
+
* Check if two entities have equal tags and info.
|
|
12
|
+
*/
|
|
13
|
+
function isTagsAndInfoEqual(a, b) {
|
|
14
|
+
return dequal(a.tags, b.tags) && dequal(a.info, b.info);
|
|
15
|
+
}
|
|
16
|
+
/** Type guard: check if entity is a Node. */
|
|
17
|
+
export function isNode(entity) {
|
|
18
|
+
return "lon" in entity && "lat" in entity;
|
|
19
|
+
}
|
|
20
|
+
/** Check if two nodes are equal (position, tags, and info). */
|
|
21
|
+
export function isNodeEqual(a, b) {
|
|
22
|
+
return a.lat === b.lat && a.lon === b.lon && isTagsAndInfoEqual(a, b);
|
|
23
|
+
}
|
|
24
|
+
/** Type guard: check if entity is a Way. */
|
|
25
|
+
export function isWay(entity) {
|
|
26
|
+
return "refs" in entity;
|
|
27
|
+
}
|
|
28
|
+
/** Type guard: check if entity is a Relation. */
|
|
29
|
+
export function isRelation(entity) {
|
|
30
|
+
return "members" in entity;
|
|
31
|
+
}
|
|
32
|
+
/** Check if two ways are equal (refs, tags, and info). */
|
|
33
|
+
export function isWayEqual(a, b) {
|
|
34
|
+
return dequal(a.refs, b.refs) && isTagsAndInfoEqual(a, b);
|
|
35
|
+
}
|
|
36
|
+
/** Check if two relations are equal (members, tags, and info). */
|
|
37
|
+
export function isRelationEqual(a, b) {
|
|
38
|
+
return dequal(a.members, b.members) && isTagsAndInfoEqual(a, b);
|
|
39
|
+
}
|
|
40
|
+
/** Check if two entities have equal properties (type-aware comparison). */
|
|
41
|
+
export function entityPropertiesEqual(a, b) {
|
|
42
|
+
if (!dequal(a.tags, b.tags))
|
|
43
|
+
return false;
|
|
44
|
+
if (!dequal(a.info, b.info))
|
|
45
|
+
return false;
|
|
46
|
+
if (isNode(a) && isNode(b))
|
|
47
|
+
return isNodeEqual(a, b);
|
|
48
|
+
if (isWay(a) && isWay(b))
|
|
49
|
+
return isWayEqual(a, b);
|
|
50
|
+
if (isRelation(a) && isRelation(b))
|
|
51
|
+
return isRelationEqual(a, b);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/** Get the entity type ("node", "way", or "relation") for an entity. */
|
|
55
|
+
export function getEntityType(entity) {
|
|
56
|
+
if (isNode(entity))
|
|
57
|
+
return "node";
|
|
58
|
+
if (isWay(entity))
|
|
59
|
+
return "way";
|
|
60
|
+
if (isRelation(entity))
|
|
61
|
+
return "relation";
|
|
62
|
+
throw Error("Unknown entity type");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if a relation is a multipolygon relation.
|
|
66
|
+
*/
|
|
67
|
+
export function isMultipolygonRelation(relation) {
|
|
68
|
+
return relation.tags?.["type"] === "multipolygon";
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AASpC;;GAEG;AACH,SAAS,kBAAkB,CAAC,CAAY,EAAE,CAAY;IACrD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,MAAM,CAAC,MAAiB;IACvC,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAA;AAC1C,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,CAAU,EAAE,CAAU;IACjD,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACtE,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,KAAK,CAAC,MAAiB;IACtC,OAAO,MAAM,IAAI,MAAM,CAAA;AACxB,CAAC;AAED,iDAAiD;AACjD,MA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AAE,OAAO,MAAM,CAAA;IACjC,IAAI,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,UAAU,CAAA;IACzC,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAqB;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,cAAc,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Area detection for OSM ways.
|
|
3
|
+
*
|
|
4
|
+
* Implements the OSM wiki heuristics for determining whether a closed way
|
|
5
|
+
* should be rendered as an area (polygon) or a closed linear feature.
|
|
6
|
+
*
|
|
7
|
+
* @see https://wiki.openstreetmap.org/wiki/Key:area
|
|
8
|
+
* @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { OsmWay } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Determine if a way is an area based on its tags and nodes.
|
|
15
|
+
*
|
|
16
|
+
* This function implements the logic described in the OSM wiki:
|
|
17
|
+
* https://wiki.openstreetmap.org/wiki/Key:area
|
|
18
|
+
* https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
19
|
+
*
|
|
20
|
+
* @param way - The way to check.
|
|
21
|
+
* @returns `true` if the way is an area, `false` otherwise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function wayIsArea(way?: OsmWay): boolean;
|
|
24
|
+
//# sourceMappingURL=way-is-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"way-is-area.d.ts","sourceRoot":"","sources":["../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAqDrC;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CA+B/C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Area detection for OSM ways.
|
|
3
|
+
*
|
|
4
|
+
* Implements the OSM wiki heuristics for determining whether a closed way
|
|
5
|
+
* should be rendered as an area (polygon) or a closed linear feature.
|
|
6
|
+
*
|
|
7
|
+
* @see https://wiki.openstreetmap.org/wiki/Key:area
|
|
8
|
+
* @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Tags that imply an area unless their value is exactly "no"
|
|
14
|
+
*/
|
|
15
|
+
const IMPLIED_ANY_VALUE_BUT_NO = new Set([
|
|
16
|
+
"amenity",
|
|
17
|
+
"boundary",
|
|
18
|
+
"building",
|
|
19
|
+
"building:part",
|
|
20
|
+
"craft",
|
|
21
|
+
// "golf", Seeing a lot of golf=cartpath which is not an area
|
|
22
|
+
"historic",
|
|
23
|
+
"indoor",
|
|
24
|
+
"landuse",
|
|
25
|
+
"leisure",
|
|
26
|
+
"military",
|
|
27
|
+
"office",
|
|
28
|
+
"place",
|
|
29
|
+
"public_transport",
|
|
30
|
+
"ruins",
|
|
31
|
+
"shop",
|
|
32
|
+
"tourism",
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* Tags that imply an area only for these specific values
|
|
36
|
+
*/
|
|
37
|
+
const INCLUDED_VALUE_TAGS = {
|
|
38
|
+
barrier: new Set([
|
|
39
|
+
"city_wall",
|
|
40
|
+
"ditch",
|
|
41
|
+
"hedge",
|
|
42
|
+
"retaining_wall",
|
|
43
|
+
"wall",
|
|
44
|
+
"spikes",
|
|
45
|
+
]),
|
|
46
|
+
highway: new Set(["services", "rest_area", "escape", "elevator"]),
|
|
47
|
+
power: new Set(["plant", "substation", "generator", "transformer"]),
|
|
48
|
+
railway: new Set(["station", "turntable", "roundhouse", "platform"]),
|
|
49
|
+
waterway: new Set(["riverbank", "dock", "boatyard", "dam"]),
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Tags that imply an area unless the value is in this exclusion list
|
|
53
|
+
*/
|
|
54
|
+
const EXCLUDED_VALUE_TAGS = {
|
|
55
|
+
aeroway: new Set(["no", "taxiway"]),
|
|
56
|
+
"area:highway": new Set(["no"]),
|
|
57
|
+
man_made: new Set(["no", "cutline", "embankment", "pipeline"]),
|
|
58
|
+
natural: new Set(["no", "coastline", "cliff", "ridge", "arete", "tree_row"]),
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Determine if a way is an area based on its tags and nodes.
|
|
62
|
+
*
|
|
63
|
+
* This function implements the logic described in the OSM wiki:
|
|
64
|
+
* https://wiki.openstreetmap.org/wiki/Key:area
|
|
65
|
+
* https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
66
|
+
*
|
|
67
|
+
* @param way - The way to check.
|
|
68
|
+
* @returns `true` if the way is an area, `false` otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export function wayIsArea(way) {
|
|
71
|
+
if (!way)
|
|
72
|
+
return false;
|
|
73
|
+
const { refs, tags } = way;
|
|
74
|
+
if (refs.length < 3)
|
|
75
|
+
return false;
|
|
76
|
+
if (refs[0] !== refs[refs.length - 1])
|
|
77
|
+
return false;
|
|
78
|
+
// End refs are equal, no tags, assume it is an area.
|
|
79
|
+
if (!tags || Object.keys(tags).length === 0)
|
|
80
|
+
return true;
|
|
81
|
+
// Explicit override
|
|
82
|
+
if ("area" in tags)
|
|
83
|
+
return tags["area"] !== "no";
|
|
84
|
+
// Tags that count if value is NOT "no"
|
|
85
|
+
for (const key of IMPLIED_ANY_VALUE_BUT_NO) {
|
|
86
|
+
const v = tags[key];
|
|
87
|
+
if (v && v !== "no")
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
// Tags that are area only for INCLUDED values
|
|
91
|
+
for (const [key, included] of Object.entries(INCLUDED_VALUE_TAGS)) {
|
|
92
|
+
const v = tags[key];
|
|
93
|
+
if (v && included.has(`${v}`))
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
// Tags that are area unless value is excluded
|
|
97
|
+
for (const [key, excluded] of Object.entries(EXCLUDED_VALUE_TAGS)) {
|
|
98
|
+
const v = tags[key];
|
|
99
|
+
if (v && !excluded.has(`${v}`))
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=way-is-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"way-is-area.js","sourceRoot":"","sources":["../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACxC,SAAS;IACT,UAAU;IACV,UAAU;IACV,eAAe;IACf,OAAO;IACP,8DAA8D;IAC9D,UAAU;IACV,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,kBAAkB;IAClB,OAAO;IACP,MAAM;IACN,SAAS;CACT,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC3B,OAAO,EAAE,IAAI,GAAG,CAAC;QAChB,WAAW;QACX,OAAO;QACP,OAAO;QACP,gBAAgB;QAChB,MAAM;QACN,QAAQ;KACR,CAAC;IACF,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACjE,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACnE,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,SAAS,EA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AAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;IACjC,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC3C,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC"}
|
package/dist/zigzag.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zigzag encoding/decoding for protobuf-style varints.
|
|
3
|
+
*
|
|
4
|
+
* Zigzag encoding converts signed integers to unsigned by interleaving
|
|
5
|
+
* negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
|
|
6
|
+
* varint encoding of small negative numbers.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Zigzag encode a number using arithmetic operations.
|
|
12
|
+
* This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
|
|
13
|
+
* Formula: n < 0 ? -2*n - 1 : 2*n
|
|
14
|
+
*
|
|
15
|
+
* Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
|
|
16
|
+
* for unsigned varint encoding.
|
|
17
|
+
*/
|
|
18
|
+
export declare function zigzag(num: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Zigzag encode using bitwise operations (for geometry deltas only).
|
|
21
|
+
* This is faster but limited to 32-bit signed integers.
|
|
22
|
+
* Used for small coordinate deltas in geometry encoding.
|
|
23
|
+
*/
|
|
24
|
+
export declare function zigzag32(num: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Decode zigzag-encoded number back to original value.
|
|
27
|
+
* Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
|
|
28
|
+
* encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
|
|
29
|
+
*
|
|
30
|
+
* Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeZigzag(encoded: number): number;
|
|
33
|
+
//# sourceMappingURL=zigzag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zigzag.d.ts","sourceRoot":"","sources":["../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD"}
|
package/dist/zigzag.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zigzag encoding/decoding for protobuf-style varints.
|
|
3
|
+
*
|
|
4
|
+
* Zigzag encoding converts signed integers to unsigned by interleaving
|
|
5
|
+
* negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
|
|
6
|
+
* varint encoding of small negative numbers.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Zigzag encode a number using arithmetic operations.
|
|
12
|
+
* This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
|
|
13
|
+
* Formula: n < 0 ? -2*n - 1 : 2*n
|
|
14
|
+
*
|
|
15
|
+
* Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
|
|
16
|
+
* for unsigned varint encoding.
|
|
17
|
+
*/
|
|
18
|
+
export function zigzag(num) {
|
|
19
|
+
return num < 0 ? -2 * num - 1 : 2 * num;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Zigzag encode using bitwise operations (for geometry deltas only).
|
|
23
|
+
* This is faster but limited to 32-bit signed integers.
|
|
24
|
+
* Used for small coordinate deltas in geometry encoding.
|
|
25
|
+
*/
|
|
26
|
+
export function zigzag32(num) {
|
|
27
|
+
return (num << 1) ^ (num >> 31);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decode zigzag-encoded number back to original value.
|
|
31
|
+
* Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
|
|
32
|
+
* encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
|
|
33
|
+
*
|
|
34
|
+
* Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
|
|
35
|
+
*/
|
|
36
|
+
export function decodeZigzag(encoded) {
|
|
37
|
+
// Check if encoded is odd (negative) using bitwise, then use arithmetic
|
|
38
|
+
return (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=zigzag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zigzag.js","sourceRoot":"","sources":["../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IACnC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC3C,wEAAwE;IACxE,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAA;AAC9D,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@osmix/shared",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.7",
|
|
6
6
|
"description": "Shared utilities for Osmix",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./*": "./src/*.ts",
|
|
@@ -36,19 +36,20 @@
|
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsc",
|
|
40
|
-
"bench": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
39
|
+
"build": "tsc -p tsconfig.build.json",
|
|
40
|
+
"bench": "bun test --bench",
|
|
41
|
+
"prepare": "bun run build",
|
|
42
|
+
"release": "bun publish",
|
|
43
|
+
"test": "bun test",
|
|
44
|
+
"typecheck": "tsgo --noEmit"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@types/
|
|
47
|
-
"typescript": "
|
|
48
|
-
"vitest": "catalog:"
|
|
47
|
+
"@types/bun": "^1.3.3",
|
|
48
|
+
"typescript": "^5.9.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@mapbox/
|
|
51
|
+
"@mapbox/tilebelt": "^2.0.3",
|
|
52
|
+
"dequal": "^2.0.3",
|
|
52
53
|
"lineclip": "^2.0.0"
|
|
53
54
|
}
|
|
54
55
|
}
|
package/src/assert.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Assertion utilities for defensive programming.
|
|
3
|
+
*
|
|
4
|
+
* Provides typed assertion helpers that throw errors when conditions are not met,
|
|
5
|
+
* commonly used for index bounds checking and null/undefined guards.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Assert that a value is neither null nor undefined.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The value to check.
|
|
14
|
+
* @param message - Optional error message if assertion fails.
|
|
15
|
+
* @throws Error if value is null or undefined.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const item = array[index]
|
|
20
|
+
* assertValue(item, `No item at index ${index}`)
|
|
21
|
+
* // TypeScript now knows item is non-nullable
|
|
22
|
+
* ```
|
|
3
23
|
*/
|
|
4
24
|
export function assertValue<T>(
|
|
5
25
|
value?: T,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounding box intersection and containment utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for checking spatial relationships between
|
|
5
|
+
* geographic bounding boxes (west, south, east, north format).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { GeoBbox2D } from "./types"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if two bounding boxes intersect or contain each other.
|
|
14
|
+
* Handles both partial overlaps and complete containment.
|
|
15
|
+
*/
|
|
16
|
+
export function bboxContainsOrIntersects(bb1: GeoBbox2D, bb2: GeoBbox2D) {
|
|
17
|
+
const westIn =
|
|
18
|
+
(bb1[0] >= bb2[0] && bb1[0] <= bb2[2]) ||
|
|
19
|
+
(bb2[0] >= bb1[0] && bb2[0] <= bb1[2])
|
|
20
|
+
const eastIn =
|
|
21
|
+
(bb1[2] >= bb2[0] && bb1[2] <= bb2[2]) ||
|
|
22
|
+
(bb2[2] >= bb1[0] && bb2[2] <= bb1[2])
|
|
23
|
+
const northIn =
|
|
24
|
+
(bb1[1] >= bb2[1] && bb1[1] <= bb2[3]) ||
|
|
25
|
+
(bb2[1] >= bb1[1] && bb2[1] <= bb1[3])
|
|
26
|
+
const southIn =
|
|
27
|
+
(bb1[3] >= bb2[1] && bb1[3] <= bb2[3]) ||
|
|
28
|
+
(bb2[3] >= bb1[1] && bb2[3] <= bb1[3])
|
|
29
|
+
return (westIn || eastIn) && (northIn || southIn)
|
|
30
|
+
}
|
package/src/bytes-to-stream.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte array to stream conversion.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a Uint8Array in a ReadableStream for use with streaming APIs.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a ReadableStream from a Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* The stream will emit the entire byte array as a single chunk,
|
|
13
|
+
* then close immediately.
|
|
14
|
+
*
|
|
15
|
+
* @param bytes - The byte array to wrap.
|
|
16
|
+
* @returns A ReadableStream that emits the bytes.
|
|
17
|
+
*/
|
|
1
18
|
export function bytesToStream(bytes: Uint8Array<ArrayBuffer>) {
|
|
2
19
|
return new ReadableStream<Uint8Array<ArrayBuffer>>({
|
|
3
20
|
start(controller) {
|
package/src/color.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Rgba } from "./types"
|
|
2
|
+
|
|
3
|
+
const hexPattern = /^[0-9a-fA-F]+$/
|
|
4
|
+
|
|
5
|
+
export function normalizeHexColor(
|
|
6
|
+
value: string | number | null | undefined,
|
|
7
|
+
): string | undefined {
|
|
8
|
+
if (value === null || value === undefined) return
|
|
9
|
+
const raw = String(value).trim()
|
|
10
|
+
if (!raw) return
|
|
11
|
+
let hex = raw.startsWith("#") ? raw.slice(1) : raw
|
|
12
|
+
if (!hexPattern.test(hex)) return
|
|
13
|
+
|
|
14
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
15
|
+
hex = hex
|
|
16
|
+
.split("")
|
|
17
|
+
.map((char) => `${char}${char}`)
|
|
18
|
+
.join("")
|
|
19
|
+
} else if (hex.length !== 6 && hex.length !== 8) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return `#${hex.toUpperCase()}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function hexColorToRgba(
|
|
27
|
+
value: string | number | null | undefined,
|
|
28
|
+
): Rgba | undefined {
|
|
29
|
+
const normalized = normalizeHexColor(value)
|
|
30
|
+
if (!normalized) return
|
|
31
|
+
const hex = normalized.slice(1)
|
|
32
|
+
const r = Number.parseInt(hex.slice(0, 2), 16)
|
|
33
|
+
const g = Number.parseInt(hex.slice(2, 4), 16)
|
|
34
|
+
const b = Number.parseInt(hex.slice(4, 6), 16)
|
|
35
|
+
const a = hex.length === 8 ? Number.parseInt(hex.slice(6, 8), 16) : 255
|
|
36
|
+
return [r, g, b, a]
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate precision utilities for OSM data.
|
|
3
|
+
*
|
|
4
|
+
* OSM stores coordinates as integer microdegrees (7 decimal places) for
|
|
5
|
+
* compact storage and consistent precision. This module provides conversions
|
|
6
|
+
* between floating-point degrees and integer microdegrees.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { GeoBbox2D } from "./types"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* OSM coordinate scale: coordinates are stored as integer microdegrees.
|
|
15
|
+
* 1 microdegree = 1e-7 degrees = 0.0000001 degrees
|
|
16
|
+
*/
|
|
17
|
+
export const OSM_COORD_SCALE = 1e7
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Convert degrees to microdegrees (integer).
|
|
21
|
+
*/
|
|
22
|
+
export function toMicroDegrees(degrees: number): number {
|
|
23
|
+
return Math.round(degrees * OSM_COORD_SCALE)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Convert microdegrees (integer) to degrees (float).
|
|
28
|
+
*/
|
|
29
|
+
export function microToDegrees(microdegrees: number): number {
|
|
30
|
+
return microdegrees / OSM_COORD_SCALE
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Convert a bounding box from degrees to microdegrees.
|
|
35
|
+
*/
|
|
36
|
+
export function bboxToMicroDegrees(
|
|
37
|
+
bbox: GeoBbox2D,
|
|
38
|
+
): [minLon: number, minLat: number, maxLon: number, maxLat: number] {
|
|
39
|
+
return [
|
|
40
|
+
toMicroDegrees(bbox[0]),
|
|
41
|
+
toMicroDegrees(bbox[1]),
|
|
42
|
+
toMicroDegrees(bbox[2]),
|
|
43
|
+
toMicroDegrees(bbox[3]),
|
|
44
|
+
]
|
|
45
|
+
}
|