@osmix/core 0.1.10 → 0.2.0

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +86 -69
  4. package/dist/contracts.d.ts +26 -0
  5. package/dist/contracts.d.ts.map +1 -0
  6. package/dist/contracts.js +1 -0
  7. package/dist/contracts.js.map +1 -0
  8. package/dist/entities.d.ts +1 -1
  9. package/dist/entities.d.ts.map +1 -1
  10. package/dist/entities.js +2 -7
  11. package/dist/entities.js.map +1 -1
  12. package/dist/ids.d.ts +2 -0
  13. package/dist/ids.d.ts.map +1 -1
  14. package/dist/ids.js +23 -15
  15. package/dist/ids.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +0 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/mocks.d.ts.map +1 -1
  21. package/dist/mocks.js.map +1 -1
  22. package/dist/nodes.d.ts +9 -3
  23. package/dist/nodes.d.ts.map +1 -1
  24. package/dist/nodes.js +6 -13
  25. package/dist/nodes.js.map +1 -1
  26. package/dist/osm.d.ts +1 -1
  27. package/dist/osm.d.ts.map +1 -1
  28. package/dist/osm.js +1 -4
  29. package/dist/osm.js.map +1 -1
  30. package/dist/relations.d.ts +3 -2
  31. package/dist/relations.d.ts.map +1 -1
  32. package/dist/relations.js +15 -9
  33. package/dist/relations.js.map +1 -1
  34. package/dist/stringtable.d.ts.map +1 -1
  35. package/dist/stringtable.js +4 -13
  36. package/dist/stringtable.js.map +1 -1
  37. package/dist/tags.d.ts +1 -1
  38. package/dist/tags.d.ts.map +1 -1
  39. package/dist/tags.js.map +1 -1
  40. package/dist/typed-arrays.d.ts.map +1 -1
  41. package/dist/typed-arrays.js.map +1 -1
  42. package/dist/ways.d.ts +2 -1
  43. package/dist/ways.d.ts.map +1 -1
  44. package/dist/ways.js +18 -18
  45. package/dist/ways.js.map +1 -1
  46. package/package.json +46 -31
  47. package/src/contracts.ts +28 -0
  48. package/src/entities.ts +179 -194
  49. package/src/ids.ts +228 -235
  50. package/src/index.ts +12 -9
  51. package/src/mocks.ts +114 -113
  52. package/src/nodes.ts +364 -397
  53. package/src/osm.ts +196 -207
  54. package/src/relations.ts +530 -558
  55. package/src/stringtable.ts +174 -183
  56. package/src/tags.ts +263 -271
  57. package/src/typed-arrays.ts +184 -194
  58. package/src/types/geoflatbush.d.ts +28 -33
  59. package/src/types/geokdbush.d.ts +28 -33
  60. package/src/types/kdbush.d.ts +34 -34
  61. package/src/ways.ts +381 -405
  62. package/test/ids.bench.ts +29 -0
  63. package/test/ids.test.ts +84 -0
  64. package/test/memory.test.ts +29 -30
  65. package/test/relations.bench.ts +27 -0
  66. package/test/relations.test.ts +101 -0
  67. package/test/tags-search.test.ts +76 -56
  68. package/test/typed-arrays.test.ts +100 -99
  69. package/tsconfig.build.json +6 -6
  70. package/tsconfig.json +7 -7
package/src/mocks.ts CHANGED
@@ -1,49 +1,50 @@
1
- import type { OsmNode } from "@osmix/shared/types"
2
- import { Osm } from "./osm.ts"
1
+ import type { OsmNode } from "@osmix/types";
3
2
 
4
- const YAKIM_LAT = 46.60207
5
- const YAKIM_LON = -120.505898
3
+ import { Osm } from "./osm.ts";
6
4
 
7
- const ONE_KM_LON = 0.0131 // approximately
8
- const ONE_KM_LAT = 0.009
5
+ const YAKIM_LAT = 46.60207;
6
+ const YAKIM_LON = -120.505898;
7
+
8
+ const ONE_KM_LON = 0.0131; // approximately
9
+ const ONE_KM_LAT = 0.009;
9
10
 
10
11
  const node0: OsmNode = {
11
- id: 0,
12
- lat: YAKIM_LAT,
13
- lon: YAKIM_LON,
14
- }
12
+ id: 0,
13
+ lat: YAKIM_LAT,
14
+ lon: YAKIM_LON,
15
+ };
15
16
 
16
17
  const node1: OsmNode = {
17
- id: 1,
18
- lat: YAKIM_LAT,
19
- lon: YAKIM_LON - ONE_KM_LON, // approximately 1km west
20
- }
18
+ id: 1,
19
+ lat: YAKIM_LAT,
20
+ lon: YAKIM_LON - ONE_KM_LON, // approximately 1km west
21
+ };
21
22
 
22
23
  function addBaseNodes(osm: Osm) {
23
- osm.nodes.addNode(node0)
24
- osm.nodes.addNode(node1)
24
+ osm.nodes.addNode(node0);
25
+ osm.nodes.addNode(node1);
25
26
  }
26
27
 
27
28
  function addBaseWays(osm: Osm) {
28
- osm.ways.addWay({
29
- id: 1,
30
- refs: [0, 1],
31
- tags: {
32
- highway: "primary",
33
- },
34
- })
29
+ osm.ways.addWay({
30
+ id: 1,
31
+ refs: [0, 1],
32
+ tags: {
33
+ highway: "primary",
34
+ },
35
+ });
35
36
  }
36
37
 
37
38
  /**
38
39
  * Create a base OSM with one way and two nodes.
39
40
  */
40
41
  export function createMockBaseOsm(): Osm {
41
- const base = new Osm()
42
- addBaseNodes(base)
43
- base.nodes.buildIndex()
44
- addBaseWays(base)
45
- base.buildIndexes()
46
- return base
42
+ const base = new Osm();
43
+ addBaseNodes(base);
44
+ base.nodes.buildIndex();
45
+ addBaseWays(base);
46
+ base.buildIndexes();
47
+ return base;
47
48
  }
48
49
 
49
50
  /**
@@ -53,88 +54,88 @@ export function createMockBaseOsm(): Osm {
53
54
  * - A way that crosses over the first way, but does not share a node and so starts disconnected
54
55
  */
55
56
  export function createMockPatchOsm(): Osm {
56
- const osm = new Osm()
57
-
58
- addBaseNodes(osm)
59
-
60
- // Add way the connects with base way node 0 (will replace it)
61
- osm.nodes.addNode({
62
- ...node0,
63
- id: 2,
64
- tags: {
65
- crossing: "yes",
66
- },
67
- })
68
- osm.nodes.addNode({
69
- ...node1,
70
- id: 3,
71
- lon: YAKIM_LON + ONE_KM_LON, // ends 1km east of the center point
72
- })
73
-
74
- // Add nodes for disconnected way
75
- osm.nodes.addNode({
76
- id: 4,
77
- lat: YAKIM_LAT - ONE_KM_LAT, // 1km south
78
- lon: YAKIM_LON + ONE_KM_LON / 4, // 250m east
79
- })
80
- osm.nodes.addNode({
81
- id: 5,
82
- lat: YAKIM_LAT + ONE_KM_LAT, // 1km north
83
- lon: YAKIM_LON + ONE_KM_LON / 4, // 250m east
84
- })
85
-
86
- // Add nodes for crossing way
87
- osm.nodes.addNode({
88
- id: 6,
89
- lat: YAKIM_LAT - ONE_KM_LAT, // 1km south
90
- lon: YAKIM_LON + ONE_KM_LON / 2, // 500m east
91
- })
92
- osm.nodes.addNode({
93
- id: 7,
94
- lat: YAKIM_LAT + ONE_KM_LAT, // 1km north
95
- lon: YAKIM_LON + ONE_KM_LON / 2, // 500m east
96
- })
97
-
98
- osm.nodes.buildIndex()
99
-
100
- // Add same base way with new tags
101
- osm.ways.addWay({
102
- id: 1,
103
- refs: [0, 1],
104
- tags: {
105
- highway: "primary",
106
- version: "2",
107
- },
108
- })
109
-
110
- // Add way that overlaps with base way node 1. Node should be de-duplicated.
111
- osm.ways.addWay({
112
- id: 2,
113
- refs: [2, 3],
114
- tags: {
115
- highway: "secondary",
116
- },
117
- })
118
-
119
- // Add way that crosses way 2, and should generate 1 intersection.
120
- osm.ways.addWay({
121
- id: 3,
122
- refs: [4, 5],
123
- tags: {
124
- highway: "primary",
125
- },
126
- })
127
-
128
- // Add a way that crosses way 2, but has a tag indicating it is an underpass and should be left alone
129
- osm.ways.addWay({
130
- id: 4,
131
- refs: [6, 7],
132
- tags: {
133
- highway: "underpass",
134
- tunnel: "yes",
135
- },
136
- })
137
-
138
- osm.buildIndexes()
139
- return osm
57
+ const osm = new Osm();
58
+
59
+ addBaseNodes(osm);
60
+
61
+ // Add way the connects with base way node 0 (will replace it)
62
+ osm.nodes.addNode({
63
+ ...node0,
64
+ id: 2,
65
+ tags: {
66
+ crossing: "yes",
67
+ },
68
+ });
69
+ osm.nodes.addNode({
70
+ ...node1,
71
+ id: 3,
72
+ lon: YAKIM_LON + ONE_KM_LON, // ends 1km east of the center point
73
+ });
74
+
75
+ // Add nodes for disconnected way
76
+ osm.nodes.addNode({
77
+ id: 4,
78
+ lat: YAKIM_LAT - ONE_KM_LAT, // 1km south
79
+ lon: YAKIM_LON + ONE_KM_LON / 4, // 250m east
80
+ });
81
+ osm.nodes.addNode({
82
+ id: 5,
83
+ lat: YAKIM_LAT + ONE_KM_LAT, // 1km north
84
+ lon: YAKIM_LON + ONE_KM_LON / 4, // 250m east
85
+ });
86
+
87
+ // Add nodes for crossing way
88
+ osm.nodes.addNode({
89
+ id: 6,
90
+ lat: YAKIM_LAT - ONE_KM_LAT, // 1km south
91
+ lon: YAKIM_LON + ONE_KM_LON / 2, // 500m east
92
+ });
93
+ osm.nodes.addNode({
94
+ id: 7,
95
+ lat: YAKIM_LAT + ONE_KM_LAT, // 1km north
96
+ lon: YAKIM_LON + ONE_KM_LON / 2, // 500m east
97
+ });
98
+
99
+ osm.nodes.buildIndex();
100
+
101
+ // Add same base way with new tags
102
+ osm.ways.addWay({
103
+ id: 1,
104
+ refs: [0, 1],
105
+ tags: {
106
+ highway: "primary",
107
+ version: "2",
108
+ },
109
+ });
110
+
111
+ // Add way that overlaps with base way node 1. Node should be de-duplicated.
112
+ osm.ways.addWay({
113
+ id: 2,
114
+ refs: [2, 3],
115
+ tags: {
116
+ highway: "secondary",
117
+ },
118
+ });
119
+
120
+ // Add way that crosses way 2, and should generate 1 intersection.
121
+ osm.ways.addWay({
122
+ id: 3,
123
+ refs: [4, 5],
124
+ tags: {
125
+ highway: "primary",
126
+ },
127
+ });
128
+
129
+ // Add a way that crosses way 2, but has a tag indicating it is an underpass and should be left alone
130
+ osm.ways.addWay({
131
+ id: 4,
132
+ refs: [6, 7],
133
+ tags: {
134
+ highway: "underpass",
135
+ tunnel: "yes",
136
+ },
137
+ });
138
+
139
+ osm.buildIndexes();
140
+ return osm;
140
141
  }