@konfirm/geojson 1.0.0 → 1.0.1-beta.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.
- package/README.md +7 -7
- package/dist/{geojson.d.ts → main.d.mts} +18 -79
- package/dist/main.d.ts +137 -15
- package/dist/main.global.js +853 -0
- package/dist/main.global.js.map +1 -0
- package/dist/main.js +824 -0
- package/dist/main.js.map +1 -0
- package/dist/main.mjs +772 -0
- package/dist/main.mjs.map +1 -0
- package/package.json +101 -63
- package/.editorconfig +0 -16
- package/.github/workflows/release.yml +0 -21
- package/.github/workflows/tests.yml +0 -56
- package/CHANGELOG.md +0 -21
- package/dist/Domain/Constants.d.ts +0 -5
- package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +0 -3
- package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +0 -6
- package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +0 -4
- package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +0 -11
- package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +0 -4
- package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +0 -3
- package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +0 -4
- package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +0 -3
- package/dist/Domain/GeoJSON/Concept/Position.d.ts +0 -7
- package/dist/Domain/GeoJSON/Feature.d.ts +0 -12
- package/dist/Domain/GeoJSON/FeatureCollection.d.ts +0 -8
- package/dist/Domain/GeoJSON/GeoJSON.d.ts +0 -7
- package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +0 -11
- package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +0 -7
- package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +0 -8
- package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +0 -7
- package/dist/Domain/GeoJSON/Geometry/Point.d.ts +0 -11
- package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +0 -11
- package/dist/Domain/GeoJSON/Geometry.d.ts +0 -9
- package/dist/Domain/GeoJSON/GeometryCollection.d.ts +0 -8
- package/dist/Domain/GeoJSON/GeometryObject.d.ts +0 -12
- package/dist/Domain/Guards/Number.d.ts +0 -3
- package/dist/Domain/Guards/Tuple.d.ts +0 -3
- package/dist/Domain/Iterator/IterablePair.d.ts +0 -32
- package/dist/Domain/Iterator/SimpleGeometry.d.ts +0 -90
- package/dist/Domain/Utility/Calculate.d.ts +0 -9
- package/dist/Domain/Utility/Distance.d.ts +0 -3
- package/dist/Domain/Utility/Intersect.d.ts +0 -2
- package/dist/Domain/Utility/Segments.d.ts +0 -2
- package/dist/Domain/Utility/Winding.d.ts +0 -3
- package/dist/geojson.cjs.js +0 -655
- package/dist/geojson.cjs.min.js +0 -1
- package/dist/geojson.es.js +0 -627
- package/dist/geojson.es.min.js +0 -1
- package/dist/geojson.js +0 -660
- package/dist/geojson.min.js +0 -1
- package/rollup.config.mjs +0 -43
- package/source/Domain/Constants.ts +0 -5
- package/source/Domain/GeoJSON/Concept/Altitude.ts +0 -9
- package/source/Domain/GeoJSON/Concept/BoundingBox.ts +0 -31
- package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +0 -12
- package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +0 -23
- package/source/Domain/GeoJSON/Concept/InteriorRing.ts +0 -12
- package/source/Domain/GeoJSON/Concept/Latitude.ts +0 -7
- package/source/Domain/GeoJSON/Concept/LinearRing.ts +0 -14
- package/source/Domain/GeoJSON/Concept/Longitude.ts +0 -7
- package/source/Domain/GeoJSON/Concept/Position.ts +0 -18
- package/source/Domain/GeoJSON/Feature.ts +0 -24
- package/source/Domain/GeoJSON/FeatureCollection.ts +0 -16
- package/source/Domain/GeoJSON/GeoJSON.ts +0 -9
- package/source/Domain/GeoJSON/Geometry/LineString.ts +0 -12
- package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +0 -9
- package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +0 -10
- package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +0 -9
- package/source/Domain/GeoJSON/Geometry/Point.ts +0 -12
- package/source/Domain/GeoJSON/Geometry/Polygon.ts +0 -20
- package/source/Domain/GeoJSON/Geometry.ts +0 -11
- package/source/Domain/GeoJSON/GeometryCollection.ts +0 -23
- package/source/Domain/GeoJSON/GeometryObject.ts +0 -20
- package/source/Domain/Guards/Number.ts +0 -13
- package/source/Domain/Guards/Tuple.ts +0 -6
- package/source/Domain/Guards/Utility.ts +0 -1
- package/source/Domain/Iterator/IterablePair.ts +0 -47
- package/source/Domain/Iterator/SimpleGeometry.ts +0 -137
- package/source/Domain/Utility/Calculate.ts +0 -143
- package/source/Domain/Utility/Distance.ts +0 -56
- package/source/Domain/Utility/Intersect.ts +0 -42
- package/source/Domain/Utility/Numeric.ts +0 -8
- package/source/Domain/Utility/Segments.ts +0 -5
- package/source/Domain/Utility/Winding.ts +0 -19
- package/source/main.ts +0 -20
- package/test/Domain/GeoJSON/Concept/Altitude.ts +0 -58
- package/test/Domain/GeoJSON/Concept/BoundingBox.ts +0 -77
- package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +0 -65
- package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +0 -56
- package/test/Domain/GeoJSON/Concept/InteriorRing.ts +0 -65
- package/test/Domain/GeoJSON/Concept/Latitude.ts +0 -56
- package/test/Domain/GeoJSON/Concept/LinearRing.ts +0 -63
- package/test/Domain/GeoJSON/Concept/Longitude.ts +0 -56
- package/test/Domain/GeoJSON/Concept/Position.ts +0 -56
- package/test/Domain/GeoJSON/Feature.ts +0 -9
- package/test/Domain/GeoJSON/FeatureCollection.ts +0 -9
- package/test/Domain/GeoJSON/GeoJSON.ts +0 -21
- package/test/Domain/GeoJSON/Geometry/LineString.ts +0 -11
- package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +0 -11
- package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +0 -11
- package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +0 -11
- package/test/Domain/GeoJSON/Geometry/Point.ts +0 -11
- package/test/Domain/GeoJSON/Geometry/Polygon.ts +0 -11
- package/test/Domain/GeoJSON/Geometry.ts +0 -9
- package/test/Domain/GeoJSON/GeometryCollection.ts +0 -9
- package/test/Domain/GeoJSON/GeometryObject.ts +0 -4
- package/test/Domain/Guards/Number.ts +0 -49
- package/test/Domain/Guards/Tuple.ts +0 -27
- package/test/Domain/Iterator/IterablePair.ts +0 -203
- package/test/Domain/Iterator/SimpleGeometry.ts +0 -195
- package/test/Domain/Utility/Calculate.ts +0 -178
- package/test/Domain/Utility/Distance.ts +0 -19
- package/test/Domain/Utility/Intersect.ts +0 -54
- package/test/Domain/Utility/Numeric.ts +0 -30
- package/test/Domain/Utility/Winding.ts +0 -52
- package/test/README.ts +0 -123
- package/test/data/Distance.ts +0 -51
- package/test/data/HolySee.ts +0 -74
- package/test/data/Intersect.ts +0 -300
- package/test/data/Italy.ts +0 -2883
- package/test/data/SanMarino.ts +0 -83
- package/test/data/Shapes.ts +0 -107
- package/test/helper/geometry.ts +0 -76
- package/test/helper/malform.ts +0 -82
- package/test/main.ts +0 -4
- package/tsconfig.json +0 -12
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
// source/Domain/GeoJSON/Concept/Position.ts
|
|
2
|
+
import { any } from "@konfirm/guard";
|
|
3
|
+
|
|
4
|
+
// source/Domain/Guards/Tuple.ts
|
|
5
|
+
import { isArray } from "@konfirm/guard";
|
|
6
|
+
function isTuple(...rules) {
|
|
7
|
+
return (value) => isArray(value) && value.length === rules.length && rules.every((rule, index) => rule(value[index]));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// source/Domain/Constants.ts
|
|
11
|
+
var EARTH_RADIUS = 63710087714e-4;
|
|
12
|
+
var EARTH_RADIUS_MAJOR = 6378137;
|
|
13
|
+
var EARTH_RADIUS_MINOR = 6356752314245e-6;
|
|
14
|
+
var EARTH_FLATTENING = 298.257223563;
|
|
15
|
+
var GPS_SATELLITE_ORBIT = 2018e4;
|
|
16
|
+
|
|
17
|
+
// source/Domain/Guards/Number.ts
|
|
18
|
+
import { isNumber } from "@konfirm/guard";
|
|
19
|
+
function isNumberValue(value) {
|
|
20
|
+
return isNumber(value) && Number.isFinite(value);
|
|
21
|
+
}
|
|
22
|
+
function isNumberBetween(a, b = Infinity) {
|
|
23
|
+
const min = Math.min(a, b);
|
|
24
|
+
const max = Math.max(a, b);
|
|
25
|
+
return (value) => isNumberValue(value) && value >= min && value <= max;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// source/Domain/GeoJSON/Concept/Altitude.ts
|
|
29
|
+
function isAltitude(value) {
|
|
30
|
+
return isNumberValue(value);
|
|
31
|
+
}
|
|
32
|
+
var isStrictAltitude = isNumberBetween(
|
|
33
|
+
-EARTH_RADIUS,
|
|
34
|
+
GPS_SATELLITE_ORBIT
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// source/Domain/GeoJSON/Concept/Latitude.ts
|
|
38
|
+
function isLatitude(value) {
|
|
39
|
+
return isNumberValue(value);
|
|
40
|
+
}
|
|
41
|
+
var isStrictLatitude = isNumberBetween(-90, 90);
|
|
42
|
+
|
|
43
|
+
// source/Domain/GeoJSON/Concept/Longitude.ts
|
|
44
|
+
function isLongitude(value) {
|
|
45
|
+
return isNumberValue(value);
|
|
46
|
+
}
|
|
47
|
+
var isStrictLongitude = isNumberBetween(-180, 180);
|
|
48
|
+
|
|
49
|
+
// source/Domain/GeoJSON/Concept/Position.ts
|
|
50
|
+
var isPosition = any(
|
|
51
|
+
isTuple(isLongitude, isLatitude),
|
|
52
|
+
isTuple(isLongitude, isLatitude, isAltitude)
|
|
53
|
+
);
|
|
54
|
+
var isStrictPosition = any(
|
|
55
|
+
isTuple(isStrictLongitude, isStrictLatitude),
|
|
56
|
+
isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude)
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// source/Domain/GeoJSON/Feature.ts
|
|
60
|
+
import { all as all9, any as any5, isNULL, isObject, isStructure as isStructure2 } from "@konfirm/guard";
|
|
61
|
+
|
|
62
|
+
// source/Domain/GeoJSON/Concept/GeoJSONObject.ts
|
|
63
|
+
import { all as all2, isString, isStructure } from "@konfirm/guard";
|
|
64
|
+
|
|
65
|
+
// source/Domain/GeoJSON/Concept/BoundingBox.ts
|
|
66
|
+
import { all, any as any2 } from "@konfirm/guard";
|
|
67
|
+
var isBoundingBoxWithAltitude = all(
|
|
68
|
+
isTuple(
|
|
69
|
+
isLongitude,
|
|
70
|
+
isLatitude,
|
|
71
|
+
isAltitude,
|
|
72
|
+
isLongitude,
|
|
73
|
+
isLatitude,
|
|
74
|
+
isAltitude
|
|
75
|
+
),
|
|
76
|
+
([, s, , , n]) => s <= n
|
|
77
|
+
);
|
|
78
|
+
var isBoundingBoxWithoutAltitude = all(
|
|
79
|
+
isTuple(isLongitude, isLatitude, isLongitude, isLatitude),
|
|
80
|
+
([, s, , n]) => s <= n
|
|
81
|
+
);
|
|
82
|
+
var isBoundingBox = any2(
|
|
83
|
+
isBoundingBoxWithAltitude,
|
|
84
|
+
isBoundingBoxWithoutAltitude
|
|
85
|
+
);
|
|
86
|
+
var isStrictBoundingBox = any2(
|
|
87
|
+
all(
|
|
88
|
+
isTuple(
|
|
89
|
+
isStrictLongitude,
|
|
90
|
+
isStrictLatitude,
|
|
91
|
+
isStrictAltitude,
|
|
92
|
+
isStrictLongitude,
|
|
93
|
+
isStrictLatitude,
|
|
94
|
+
isStrictAltitude
|
|
95
|
+
),
|
|
96
|
+
isBoundingBoxWithAltitude
|
|
97
|
+
),
|
|
98
|
+
all(
|
|
99
|
+
isTuple(
|
|
100
|
+
isStrictLongitude,
|
|
101
|
+
isStrictLatitude,
|
|
102
|
+
isStrictLongitude,
|
|
103
|
+
isStrictLatitude
|
|
104
|
+
),
|
|
105
|
+
isBoundingBoxWithoutAltitude
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// source/Domain/GeoJSON/Concept/GeoJSONObject.ts
|
|
110
|
+
function isGeoJSONObject(type) {
|
|
111
|
+
return isStructure(
|
|
112
|
+
{
|
|
113
|
+
type: all2(isString, (value) => value === type),
|
|
114
|
+
bbox: isBoundingBox
|
|
115
|
+
},
|
|
116
|
+
"bbox"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// source/Domain/GeoJSON/Geometry.ts
|
|
121
|
+
import { any as any3 } from "@konfirm/guard";
|
|
122
|
+
|
|
123
|
+
// source/Domain/GeoJSON/GeometryObject.ts
|
|
124
|
+
import { all as all3, isKeyOfType } from "@konfirm/guard";
|
|
125
|
+
function isGeometryObject(type, isCoordinates) {
|
|
126
|
+
return all3(
|
|
127
|
+
isGeoJSONObject(type),
|
|
128
|
+
isKeyOfType("coordinates", isCoordinates)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// source/Domain/GeoJSON/Geometry/MultiPoint.ts
|
|
133
|
+
import { isArrayOfType } from "@konfirm/guard";
|
|
134
|
+
|
|
135
|
+
// source/Domain/GeoJSON/Geometry/Point.ts
|
|
136
|
+
var isPointCoordinates = isPosition;
|
|
137
|
+
var isPoint = isGeometryObject(
|
|
138
|
+
"Point",
|
|
139
|
+
isPointCoordinates
|
|
140
|
+
);
|
|
141
|
+
var isStrictPointCoordinates = isStrictPosition;
|
|
142
|
+
var isStrictPoint = isGeometryObject(
|
|
143
|
+
"Point",
|
|
144
|
+
isStrictPointCoordinates
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// source/Domain/GeoJSON/Geometry/MultiPoint.ts
|
|
148
|
+
var isMultiPointCoordinates = isArrayOfType(isPointCoordinates);
|
|
149
|
+
var isMultiPoint = isGeometryObject(
|
|
150
|
+
"MultiPoint",
|
|
151
|
+
isMultiPointCoordinates
|
|
152
|
+
);
|
|
153
|
+
var isStrictMultiPointCoordinates = isArrayOfType(isStrictPointCoordinates);
|
|
154
|
+
var isStrictMultiPoint = isGeometryObject(
|
|
155
|
+
"MultiPoint",
|
|
156
|
+
isStrictMultiPointCoordinates
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// source/Domain/GeoJSON/Geometry/LineString.ts
|
|
160
|
+
var isLineStringCoordinates = isMultiPointCoordinates;
|
|
161
|
+
var isLineString = isGeometryObject(
|
|
162
|
+
"LineString",
|
|
163
|
+
isLineStringCoordinates
|
|
164
|
+
);
|
|
165
|
+
var isStrictLineStringCoordinates = isStrictMultiPointCoordinates;
|
|
166
|
+
var isStrictLineString = isGeometryObject("LineString", isStrictLineStringCoordinates);
|
|
167
|
+
|
|
168
|
+
// source/Domain/GeoJSON/Geometry/MultiLineString.ts
|
|
169
|
+
import { isArrayOfType as isArrayOfType2 } from "@konfirm/guard";
|
|
170
|
+
var isMultiLineStringCoordinates = isArrayOfType2(
|
|
171
|
+
isLineStringCoordinates
|
|
172
|
+
);
|
|
173
|
+
var isMultiLineString = isGeometryObject(
|
|
174
|
+
"MultiLineString",
|
|
175
|
+
isMultiLineStringCoordinates
|
|
176
|
+
);
|
|
177
|
+
var isStrictMultiLineStringCoordinates = isArrayOfType2(
|
|
178
|
+
isStrictLineStringCoordinates
|
|
179
|
+
);
|
|
180
|
+
var isStrictMultiLineString = isGeometryObject(
|
|
181
|
+
"MultiLineString",
|
|
182
|
+
isStrictMultiLineStringCoordinates
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// source/Domain/GeoJSON/Geometry/MultiPolygon.ts
|
|
186
|
+
import { isArrayOfType as isArrayOfType6 } from "@konfirm/guard";
|
|
187
|
+
|
|
188
|
+
// source/Domain/GeoJSON/Geometry/Polygon.ts
|
|
189
|
+
import { all as all7, isArrayOfType as isArrayOfType5 } from "@konfirm/guard";
|
|
190
|
+
|
|
191
|
+
// source/Domain/GeoJSON/Concept/ExteriorRing.ts
|
|
192
|
+
import { all as all5 } from "@konfirm/guard";
|
|
193
|
+
|
|
194
|
+
// source/Domain/Utility/Winding.ts
|
|
195
|
+
import { isArrayOfType as isArrayOfType3 } from "@konfirm/guard";
|
|
196
|
+
function winding(positions2) {
|
|
197
|
+
return positions2.reduce((carry, [x, y], i, a) => {
|
|
198
|
+
const [nx, ny] = a[(i + 1) % a.length];
|
|
199
|
+
return carry + (nx - x) * (ny + y);
|
|
200
|
+
}, 0);
|
|
201
|
+
}
|
|
202
|
+
var isPositionArray = isArrayOfType3(isPosition);
|
|
203
|
+
function isClockwiseWinding(value) {
|
|
204
|
+
return isPositionArray(value) && winding(value) <= 0;
|
|
205
|
+
}
|
|
206
|
+
function isCounterClockwiseWinding(value) {
|
|
207
|
+
return isPositionArray(value) && winding(value) >= 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// source/Domain/GeoJSON/Concept/LinearRing.ts
|
|
211
|
+
import { all as all4, isArrayOfSize, isArrayOfType as isArrayOfType4 } from "@konfirm/guard";
|
|
212
|
+
var isLinearRing = all4(
|
|
213
|
+
isArrayOfType4(isPosition),
|
|
214
|
+
isArrayOfSize(4),
|
|
215
|
+
(value) => value[value.length - 1].every((v, i) => v === value[0][i])
|
|
216
|
+
);
|
|
217
|
+
var isStrictLinearRing = all4(
|
|
218
|
+
isArrayOfType4(isStrictPosition),
|
|
219
|
+
isArrayOfSize(4),
|
|
220
|
+
(value) => value[value.length - 1].every((v, i) => v === value[0][i])
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// source/Domain/GeoJSON/Concept/ExteriorRing.ts
|
|
224
|
+
var isExteriorRing = all5(isLinearRing);
|
|
225
|
+
var isStrictExteriorRing = all5(
|
|
226
|
+
isStrictLinearRing,
|
|
227
|
+
isCounterClockwiseWinding
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
// source/Domain/GeoJSON/Concept/InteriorRing.ts
|
|
231
|
+
import { all as all6 } from "@konfirm/guard";
|
|
232
|
+
var isInteriorRing = all6(isLinearRing);
|
|
233
|
+
var isStrictInteriorRing = all6(
|
|
234
|
+
isStrictLinearRing,
|
|
235
|
+
isClockwiseWinding
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// source/Domain/GeoJSON/Geometry/Polygon.ts
|
|
239
|
+
var isPolygonCoordinates = all7(isArrayOfType5(isLinearRing));
|
|
240
|
+
var isPolygon = isGeometryObject(
|
|
241
|
+
"Polygon",
|
|
242
|
+
isPolygonCoordinates
|
|
243
|
+
);
|
|
244
|
+
var isStrictPolygonCoordinates = all7(
|
|
245
|
+
isArrayOfType5(isStrictLinearRing),
|
|
246
|
+
(value) => isExteriorRing(value[0]),
|
|
247
|
+
(value) => value.slice(1).every(isInteriorRing)
|
|
248
|
+
);
|
|
249
|
+
var isStrictPolygon = isGeometryObject(
|
|
250
|
+
"Polygon",
|
|
251
|
+
isStrictPolygonCoordinates
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
// source/Domain/GeoJSON/Geometry/MultiPolygon.ts
|
|
255
|
+
var isMultiPolygonCoordinates = isArrayOfType6(isPolygonCoordinates);
|
|
256
|
+
var isMultiPolygon = isGeometryObject(
|
|
257
|
+
"MultiPolygon",
|
|
258
|
+
isMultiPolygonCoordinates
|
|
259
|
+
);
|
|
260
|
+
var isStrictMultiPolygonCoordinates = isArrayOfType6(
|
|
261
|
+
isStrictPolygonCoordinates
|
|
262
|
+
);
|
|
263
|
+
var isStrictMultiPolygon = isGeometryObject(
|
|
264
|
+
"MultiPolygon",
|
|
265
|
+
isStrictMultiPolygonCoordinates
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// source/Domain/GeoJSON/Geometry.ts
|
|
269
|
+
var isGeometry = any3(
|
|
270
|
+
isPoint,
|
|
271
|
+
isMultiPoint,
|
|
272
|
+
isLineString,
|
|
273
|
+
isMultiLineString,
|
|
274
|
+
isPolygon,
|
|
275
|
+
isMultiPolygon
|
|
276
|
+
);
|
|
277
|
+
var isStrictGeometry = any3(
|
|
278
|
+
isStrictPoint,
|
|
279
|
+
isStrictMultiPoint,
|
|
280
|
+
isStrictLineString,
|
|
281
|
+
isStrictMultiLineString,
|
|
282
|
+
isStrictPolygon,
|
|
283
|
+
isStrictMultiPolygon
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// source/Domain/GeoJSON/GeometryCollection.ts
|
|
287
|
+
import { all as all8, any as any4, isArrayOfType as isArrayOfType7, isKeyOfType as isKeyOfType2 } from "@konfirm/guard";
|
|
288
|
+
var isGeometryCollectionObject = all8(
|
|
289
|
+
isGeoJSONObject("GeometryCollection"),
|
|
290
|
+
isKeyOfType2(
|
|
291
|
+
"geometries",
|
|
292
|
+
isArrayOfType7(any4(isGeometry, isGeometryCollection))
|
|
293
|
+
)
|
|
294
|
+
);
|
|
295
|
+
var isStrictGeometryCollectionObject = all8(
|
|
296
|
+
isGeoJSONObject("GeometryCollection"),
|
|
297
|
+
isKeyOfType2(
|
|
298
|
+
"geometries",
|
|
299
|
+
isArrayOfType7(any4(isStrictGeometry, isStrictGeometryCollection))
|
|
300
|
+
)
|
|
301
|
+
);
|
|
302
|
+
function isGeometryCollection(value) {
|
|
303
|
+
return isGeometryCollectionObject(value);
|
|
304
|
+
}
|
|
305
|
+
function isStrictGeometryCollection(value) {
|
|
306
|
+
return isStrictGeometryCollectionObject(value);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// source/Domain/GeoJSON/Feature.ts
|
|
310
|
+
var isFeature = all9(
|
|
311
|
+
isGeoJSONObject("Feature"),
|
|
312
|
+
isStructure2({
|
|
313
|
+
geometry: any5(isGeometry, isGeometryCollection),
|
|
314
|
+
properties: any5(isNULL, isObject)
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
var isStrictFeature = all9(
|
|
318
|
+
isGeoJSONObject("Feature"),
|
|
319
|
+
isStructure2({
|
|
320
|
+
geometry: any5(isStrictGeometry, isStrictGeometryCollection),
|
|
321
|
+
properties: any5(isNULL, isObject)
|
|
322
|
+
})
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
// source/Domain/GeoJSON/FeatureCollection.ts
|
|
326
|
+
import { all as all10, isArrayOfType as isArrayOfType8, isKeyOfType as isKeyOfType3 } from "@konfirm/guard";
|
|
327
|
+
var isFeatureCollection = all10(
|
|
328
|
+
isGeoJSONObject("FeatureCollection"),
|
|
329
|
+
isKeyOfType3("features", isArrayOfType8(isFeature))
|
|
330
|
+
);
|
|
331
|
+
var isStrictFeatureCollection = all10(
|
|
332
|
+
isGeoJSONObject("FeatureCollection"),
|
|
333
|
+
isKeyOfType3("features", isArrayOfType8(isStrictFeature))
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// source/Domain/GeoJSON/GeoJSON.ts
|
|
337
|
+
import { any as any6 } from "@konfirm/guard";
|
|
338
|
+
var isGeoJSON = any6(
|
|
339
|
+
isGeometry,
|
|
340
|
+
isGeometryCollection,
|
|
341
|
+
isFeature,
|
|
342
|
+
isFeatureCollection
|
|
343
|
+
);
|
|
344
|
+
var isStrictGeoJSON = any6(
|
|
345
|
+
isStrictGeometry,
|
|
346
|
+
isStrictGeometryCollection,
|
|
347
|
+
isStrictFeature,
|
|
348
|
+
isStrictFeatureCollection
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
// source/Domain/Iterator/SimpleGeometry.ts
|
|
352
|
+
var reducers = {
|
|
353
|
+
*MultiPoint({ coordinates, ...rest }, unwrap) {
|
|
354
|
+
for (const pair of coordinates) {
|
|
355
|
+
yield* unwrap({
|
|
356
|
+
coordinates: pair,
|
|
357
|
+
...rest,
|
|
358
|
+
type: "Point"
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
*MultiLineString({ coordinates, ...rest }, unwrap) {
|
|
363
|
+
for (const pair of coordinates) {
|
|
364
|
+
yield* unwrap({
|
|
365
|
+
coordinates: pair,
|
|
366
|
+
...rest,
|
|
367
|
+
type: "LineString"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
*MultiPolygon({ coordinates, ...rest }, unwrap) {
|
|
372
|
+
for (const pair of coordinates) {
|
|
373
|
+
yield* unwrap({
|
|
374
|
+
coordinates: pair,
|
|
375
|
+
...rest,
|
|
376
|
+
type: "Polygon"
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
*GeometryCollection({ geometries: geometries3 }, unwrap) {
|
|
381
|
+
for (const geometry of geometries3) {
|
|
382
|
+
yield* unwrap(geometry);
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
*Feature({ geometry }, unwrap) {
|
|
386
|
+
yield* unwrap(geometry);
|
|
387
|
+
},
|
|
388
|
+
*FeatureCollection({ features }, unwrap) {
|
|
389
|
+
for (const { geometry } of features) {
|
|
390
|
+
yield* unwrap(geometry);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var SimpleGeometryIterator = class {
|
|
395
|
+
constructor(...inputs) {
|
|
396
|
+
this.inputs = [];
|
|
397
|
+
this.inputs = inputs;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Generator yielding all SimpleGeometry objects from the provided GeoJSON structure(s)
|
|
401
|
+
*
|
|
402
|
+
* @return {*} {Iterator<SimpleGeometry>}
|
|
403
|
+
* @memberof SimpleGeometryIterator
|
|
404
|
+
*/
|
|
405
|
+
*[Symbol.iterator]() {
|
|
406
|
+
for (const input of this.inputs) {
|
|
407
|
+
for (const simple of this.unwrap(input)) {
|
|
408
|
+
yield simple;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* unwrap any GeoJSON object into one or more SimpleGeometry object
|
|
414
|
+
*
|
|
415
|
+
* @private
|
|
416
|
+
* @param {GeoJSON} geo
|
|
417
|
+
* @return {*} {Iterable<SimpleGeometry>}
|
|
418
|
+
* @memberof SimpleGeometryIterator
|
|
419
|
+
*/
|
|
420
|
+
*unwrap(geo) {
|
|
421
|
+
geo.type in reducers ? yield* reducers[geo.type](
|
|
422
|
+
geo,
|
|
423
|
+
(g) => this.unwrap(g)
|
|
424
|
+
) : yield geo;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// source/Domain/Iterator/IterablePair.ts
|
|
429
|
+
var IterablePairIterator = class {
|
|
430
|
+
/**
|
|
431
|
+
* Constructs a new instance of IterablePairIterator
|
|
432
|
+
*
|
|
433
|
+
* @param iterators
|
|
434
|
+
*/
|
|
435
|
+
constructor(...iterators) {
|
|
436
|
+
this.iterators = [];
|
|
437
|
+
this.iterators = iterators;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Generator yielding all value pairs from the provided iterators
|
|
441
|
+
*
|
|
442
|
+
* @return {*} {Iterator<[T, T]>}
|
|
443
|
+
* @memberof IterablePairIterator
|
|
444
|
+
*/
|
|
445
|
+
*[Symbol.iterator]() {
|
|
446
|
+
for (const [a, b] of this.pairs(this.iterators)) {
|
|
447
|
+
for (const one of a) {
|
|
448
|
+
for (const two of b) {
|
|
449
|
+
yield [one, two];
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Create unique Iterator<T> combinations to traverse over
|
|
456
|
+
*
|
|
457
|
+
* @private
|
|
458
|
+
* @param {Array<Iterable<T>>} source
|
|
459
|
+
* @return {*} {Array<[Iterable<T>, Iterable<T>]>}
|
|
460
|
+
* @memberof IterablePairIterator
|
|
461
|
+
*/
|
|
462
|
+
pairs(source) {
|
|
463
|
+
return source.flatMap(
|
|
464
|
+
(a, i) => source.slice(i + 1).map((b) => [a, b])
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// source/Domain/Utility/Box.ts
|
|
470
|
+
function* positions(coordinates) {
|
|
471
|
+
if (typeof coordinates[0] === "number") {
|
|
472
|
+
yield coordinates;
|
|
473
|
+
} else {
|
|
474
|
+
for (const child of coordinates) {
|
|
475
|
+
yield* positions(child);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function boxFromPositions(source) {
|
|
480
|
+
let minLon = Infinity, minLat = Infinity, maxLon = -Infinity, maxLat = -Infinity;
|
|
481
|
+
for (const [lon, lat] of source) {
|
|
482
|
+
if (lon < minLon) minLon = lon;
|
|
483
|
+
if (lat < minLat) minLat = lat;
|
|
484
|
+
if (lon > maxLon) maxLon = lon;
|
|
485
|
+
if (lat > maxLat) maxLat = lat;
|
|
486
|
+
}
|
|
487
|
+
return [minLon, minLat, maxLon, maxLat];
|
|
488
|
+
}
|
|
489
|
+
function createBoxFromCoordinates(coordinates) {
|
|
490
|
+
return boxFromPositions(positions(coordinates));
|
|
491
|
+
}
|
|
492
|
+
function isWithinBox([lon, lat], [minLon, minLat, maxLon, maxLat]) {
|
|
493
|
+
return lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// source/Domain/Utility/Calculate.ts
|
|
497
|
+
var D2R = Math.PI / 180;
|
|
498
|
+
var \u03C0 = Math.PI;
|
|
499
|
+
function constrain(value, min, max) {
|
|
500
|
+
return Math.max(Math.min(value, max), min);
|
|
501
|
+
}
|
|
502
|
+
function squared(n) {
|
|
503
|
+
return n * n;
|
|
504
|
+
}
|
|
505
|
+
function rad(n) {
|
|
506
|
+
return n * D2R;
|
|
507
|
+
}
|
|
508
|
+
var EARTH_RADIUS_MAJOR_SQUARED = squared(EARTH_RADIUS_MAJOR);
|
|
509
|
+
var EARTH_RADIUS_MINOR_SQUARED = squared(EARTH_RADIUS_MINOR);
|
|
510
|
+
var EARTH_RADIUS_FACTOR = (EARTH_RADIUS_MAJOR_SQUARED - EARTH_RADIUS_MINOR_SQUARED) / EARTH_RADIUS_MINOR_SQUARED;
|
|
511
|
+
var EARTH_INVERSE_FLATTENING = 1 / EARTH_FLATTENING;
|
|
512
|
+
var PointToPoint = {
|
|
513
|
+
cartesian([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
|
|
514
|
+
return EARTH_RADIUS * rad(Math.sqrt(squared(\u03BBb - \u03BBa) + squared(\u03C6b - \u03C6a)));
|
|
515
|
+
},
|
|
516
|
+
haversine([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
|
|
517
|
+
const \u0394 = squared(Math.sin(rad(\u03C6b - \u03C6a) / 2)) + Math.cos(rad(\u03C6a)) * Math.cos(rad(\u03C6b)) * squared(Math.sin(rad(\u03BBb - \u03BBa) / 2));
|
|
518
|
+
return EARTH_RADIUS * Math.atan2(Math.sqrt(\u0394), Math.sqrt(1 - \u0394)) * 2;
|
|
519
|
+
},
|
|
520
|
+
vincenty(...points) {
|
|
521
|
+
const [[\u03BB1, \u03C61], [\u03BB2, \u03C62]] = points.map(
|
|
522
|
+
(p) => p.map(rad)
|
|
523
|
+
);
|
|
524
|
+
const L = \u03BB2 - \u03BB1;
|
|
525
|
+
const tanU1 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C61), cosU1 = 1 / Math.sqrt(1 + tanU1 * tanU1), sinU1 = tanU1 * cosU1;
|
|
526
|
+
const tanU2 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C62), cosU2 = 1 / Math.sqrt(1 + tanU2 * tanU2), sinU2 = tanU2 * cosU2;
|
|
527
|
+
const antipodal = Math.abs(L) > \u03C0 / 2 || Math.abs(\u03C62 - \u03C61) > \u03C0 / 2;
|
|
528
|
+
let \u03BB = L;
|
|
529
|
+
let sin\u03BB = null;
|
|
530
|
+
let cos\u03BB = null;
|
|
531
|
+
let \u03C3 = antipodal ? \u03C0 : 0;
|
|
532
|
+
let sin\u03C3 = 0;
|
|
533
|
+
let cos\u03C3 = antipodal ? -1 : 1;
|
|
534
|
+
let sinSq\u03C3 = null;
|
|
535
|
+
let cos2\u03C3\u2098 = 1;
|
|
536
|
+
let cosSq\u03B1 = 1;
|
|
537
|
+
let \u03BB\u02B9 = null;
|
|
538
|
+
let iterations = 0;
|
|
539
|
+
do {
|
|
540
|
+
sin\u03BB = Math.sin(\u03BB);
|
|
541
|
+
cos\u03BB = Math.cos(\u03BB);
|
|
542
|
+
sinSq\u03C3 = (cosU2 * sin\u03BB) ** 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cos\u03BB) ** 2;
|
|
543
|
+
if (Math.abs(sinSq\u03C3) < 1e-24) break;
|
|
544
|
+
sin\u03C3 = Math.sqrt(sinSq\u03C3);
|
|
545
|
+
cos\u03C3 = sinU1 * sinU2 + cosU1 * cosU2 * cos\u03BB;
|
|
546
|
+
\u03C3 = Math.atan2(sin\u03C3, cos\u03C3);
|
|
547
|
+
const sin\u03B1 = cosU1 * cosU2 * sin\u03BB / sin\u03C3;
|
|
548
|
+
cosSq\u03B1 = 1 - sin\u03B1 * sin\u03B1;
|
|
549
|
+
cos2\u03C3\u2098 = cosSq\u03B1 !== 0 ? cos\u03C3 - 2 * sinU1 * sinU2 / cosSq\u03B1 : 0;
|
|
550
|
+
const C = EARTH_INVERSE_FLATTENING / 16 * cosSq\u03B1 * (4 + EARTH_INVERSE_FLATTENING * (4 - 3 * cosSq\u03B1));
|
|
551
|
+
\u03BB\u02B9 = \u03BB;
|
|
552
|
+
\u03BB = L + (1 - C) * EARTH_INVERSE_FLATTENING * sin\u03B1 * (\u03C3 + C * sin\u03C3 * (cos2\u03C3\u2098 + C * cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
|
|
553
|
+
} while (Math.abs(\u03BB - \u03BB\u02B9) > 1e-12 && ++iterations < 1e3);
|
|
554
|
+
const uSq = cosSq\u03B1 * EARTH_RADIUS_FACTOR;
|
|
555
|
+
const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
|
|
556
|
+
const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
|
|
557
|
+
const \u0394\u03C3 = B * sin\u03C3 * (cos2\u03C3\u2098 + B / 4 * (cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098) - B / 6 * cos2\u03C3\u2098 * (-3 + 4 * sin\u03C3 * sin\u03C3) * (-3 + 4 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
|
|
558
|
+
return EARTH_RADIUS_MINOR * A * (\u03C3 - \u0394\u03C3);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
function getClosestPointOnLineByPoint(point, line) {
|
|
562
|
+
const [[px, py], [ax, ay], [bx, by]] = [point, ...line];
|
|
563
|
+
const [abx, aby] = [bx - ax, by - ay];
|
|
564
|
+
const [apx, apy] = [px - ax, py - ay];
|
|
565
|
+
const t = constrain(
|
|
566
|
+
(apx * abx + apy * aby) / (abx * abx + aby * aby),
|
|
567
|
+
0,
|
|
568
|
+
1
|
|
569
|
+
);
|
|
570
|
+
return t === 0 || t === 1 ? line[t] : [ax + abx * t, ay + aby * t];
|
|
571
|
+
}
|
|
572
|
+
function getDistanceOfPointToPoint(a, b, calculation) {
|
|
573
|
+
const calc = typeof calculation === "function" ? calculation : PointToPoint[calculation];
|
|
574
|
+
if (typeof calc === "function") {
|
|
575
|
+
return calc(a, b);
|
|
576
|
+
}
|
|
577
|
+
throw new Error(`Not a PointToPoint calculation function ${calculation}`);
|
|
578
|
+
}
|
|
579
|
+
function getDistanceOfPointToLine(point, line, calculation) {
|
|
580
|
+
return getDistanceOfPointToPoint(
|
|
581
|
+
point,
|
|
582
|
+
getClosestPointOnLineByPoint(point, line),
|
|
583
|
+
calculation
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
function getDistanceOfLineToLine(a, b, calculation) {
|
|
587
|
+
return isLinesCrossing(a, b) ? 0 : Math.min(
|
|
588
|
+
...a.map((a2) => getDistanceOfPointToLine(a2, b, calculation)),
|
|
589
|
+
...b.map((b2) => getDistanceOfPointToLine(b2, a, calculation))
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
function isLinesCrossing(a, b) {
|
|
593
|
+
const [[a1x, a1y], [a2x, a2y]] = a;
|
|
594
|
+
const [[b1x, b1y], [b2x, b2y]] = b;
|
|
595
|
+
const [s1x, s1y, s2x, s2y] = [a2x - a1x, a2y - a1y, b2x - b1x, b2y - b1y];
|
|
596
|
+
const s = (-s1y * (a1x - b1x) + s1x * (a1y - b1y)) / (-s2x * s1y + s1x * s2y);
|
|
597
|
+
const t = (s2x * (a1y - b1y) - s2y * (a1x - b1x)) / (-s2x * s1y + s1x * s2y);
|
|
598
|
+
return s >= 0 && s <= 1 && t >= 0 && t <= 1;
|
|
599
|
+
}
|
|
600
|
+
function isPointOnLine(point, line, threshold = 1e-14) {
|
|
601
|
+
return getDistanceOfPointToLine(point, line, "cartesian") < threshold;
|
|
602
|
+
}
|
|
603
|
+
function isPointInRing(p, ring) {
|
|
604
|
+
if (!isWithinBox(p, createBoxFromCoordinates(ring))) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
const { length } = ring;
|
|
608
|
+
const odd = ring.reduce((odd2, a, i) => {
|
|
609
|
+
const b = ring[(length + i - 1) % length];
|
|
610
|
+
return (a[1] < p[1] && b[1] >= p[1] || b[1] < p[1] && a[1] >= p[1]) && (a[0] <= p[0] || b[0] <= p[0]) ? odd2 ^ Number(
|
|
611
|
+
a[0] + (p[1] - a[1]) / (b[1] - a[1]) * (b[0] - a[0]) < p[0]
|
|
612
|
+
) : odd2;
|
|
613
|
+
}, 0);
|
|
614
|
+
return odd !== 0 || ring.slice(1).some((a, index) => isPointOnLine(p, [ring[index], a]));
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// source/Domain/Utility/Segments.ts
|
|
618
|
+
function segments(line) {
|
|
619
|
+
return line.slice(1).map((point, index) => [line[index], point]);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// source/Domain/Utility/Distance.ts
|
|
623
|
+
var geometries = {
|
|
624
|
+
PointPoint(a, b, calculation) {
|
|
625
|
+
return getDistanceOfPointToPoint(a, b, calculation);
|
|
626
|
+
},
|
|
627
|
+
LineStringPoint(a, b, calculation) {
|
|
628
|
+
return Math.min(
|
|
629
|
+
...segments(a).map(
|
|
630
|
+
(line) => getDistanceOfPointToLine(b, line, calculation)
|
|
631
|
+
)
|
|
632
|
+
);
|
|
633
|
+
},
|
|
634
|
+
LineStringLineString(a, b, calculation) {
|
|
635
|
+
const sa = segments(a);
|
|
636
|
+
const sb = segments(b);
|
|
637
|
+
return sa.reduce(
|
|
638
|
+
(carry, a2) => sb.reduce(
|
|
639
|
+
(carry2, b2) => carry2 > 0 ? Math.min(
|
|
640
|
+
carry2,
|
|
641
|
+
getDistanceOfLineToLine(a2, b2, calculation)
|
|
642
|
+
) : carry2,
|
|
643
|
+
carry
|
|
644
|
+
),
|
|
645
|
+
Infinity
|
|
646
|
+
);
|
|
647
|
+
},
|
|
648
|
+
PolygonPoint([exterior, ...interior], b, calculation) {
|
|
649
|
+
if (isPointInRing(b, exterior)) {
|
|
650
|
+
const [excluded] = interior.filter(
|
|
651
|
+
(ring) => isPointInRing(b, ring)
|
|
652
|
+
);
|
|
653
|
+
return excluded ? this.LineStringPoint(excluded, b, calculation) : 0;
|
|
654
|
+
}
|
|
655
|
+
return this.LineStringPoint(exterior, b, calculation);
|
|
656
|
+
},
|
|
657
|
+
PolygonLineString(a, b, calculation) {
|
|
658
|
+
const [exterior, ...interior] = a;
|
|
659
|
+
const line = segments(b);
|
|
660
|
+
const ring = b.some((b2) => isPointInRing(b2, exterior)) ? interior.find((a2) => b.every((b2) => isPointInRing(b2, a2))) : exterior;
|
|
661
|
+
return ring ? Math.min(
|
|
662
|
+
...segments(ring).map(
|
|
663
|
+
(a2) => Math.min(
|
|
664
|
+
...line.map(
|
|
665
|
+
(b2) => getDistanceOfLineToLine(a2, b2, calculation)
|
|
666
|
+
)
|
|
667
|
+
)
|
|
668
|
+
)
|
|
669
|
+
) : 0;
|
|
670
|
+
},
|
|
671
|
+
PolygonPolygon(a, b, calculation) {
|
|
672
|
+
return Math.min(
|
|
673
|
+
this.PolygonLineString(a, b[0], calculation),
|
|
674
|
+
this.PolygonLineString(b, a[0], calculation)
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
function distance(a, b, calculation = "cartesian") {
|
|
679
|
+
const lookup = geometries;
|
|
680
|
+
return Math.min(
|
|
681
|
+
...[
|
|
682
|
+
...new IterablePairIterator(
|
|
683
|
+
new SimpleGeometryIterator(a),
|
|
684
|
+
new SimpleGeometryIterator(b)
|
|
685
|
+
)
|
|
686
|
+
].map(([a2, b2]) => {
|
|
687
|
+
return a2.type + b2.type in lookup ? lookup[a2.type + b2.type](
|
|
688
|
+
a2.coordinates,
|
|
689
|
+
b2.coordinates,
|
|
690
|
+
calculation
|
|
691
|
+
) : b2.type + a2.type in lookup ? lookup[b2.type + a2.type](
|
|
692
|
+
b2.coordinates,
|
|
693
|
+
a2.coordinates,
|
|
694
|
+
calculation
|
|
695
|
+
) : Infinity;
|
|
696
|
+
})
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// source/Domain/Utility/Intersect.ts
|
|
701
|
+
var geometries2 = {
|
|
702
|
+
PointPoint(a, b) {
|
|
703
|
+
return a.length >= 2 && b.length >= 2 && a.slice(0, 2).every((v, i) => v === b[i]);
|
|
704
|
+
},
|
|
705
|
+
LineStringPoint(a, b) {
|
|
706
|
+
return a.some((a2) => this.PointPoint(a2, b)) || segments(a).some((line) => isPointOnLine(b, line));
|
|
707
|
+
},
|
|
708
|
+
LineStringLineString(a, b) {
|
|
709
|
+
const lines = segments(b);
|
|
710
|
+
return segments(a).some(
|
|
711
|
+
(a2) => lines.some((b2) => isLinesCrossing(a2, b2))
|
|
712
|
+
);
|
|
713
|
+
},
|
|
714
|
+
PolygonPoint([exterior, ...interior], b) {
|
|
715
|
+
return (this.LineStringPoint(exterior, b) || isPointInRing(b, exterior)) && (!interior.length || interior.every((ring) => !isPointInRing(b, ring)));
|
|
716
|
+
},
|
|
717
|
+
PolygonLineString(a, b) {
|
|
718
|
+
return a.some((ring) => this.LineStringLineString(ring, b)) || b.some((point) => this.PolygonPoint(a, point));
|
|
719
|
+
},
|
|
720
|
+
PolygonPolygon(a, b) {
|
|
721
|
+
return b.some(
|
|
722
|
+
(b1) => this.PolygonLineString(a, b1) || b1.some((b2) => this.PolygonPoint(a, b2))
|
|
723
|
+
) || a.some(
|
|
724
|
+
(a1) => this.PolygonLineString(b, a1) || a1.some((a2) => this.PolygonPoint(b, a2))
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
function intersect(a, b) {
|
|
729
|
+
const lookup = geometries2;
|
|
730
|
+
for (const [itA, itB] of new IterablePairIterator(
|
|
731
|
+
new SimpleGeometryIterator(a),
|
|
732
|
+
new SimpleGeometryIterator(b)
|
|
733
|
+
)) {
|
|
734
|
+
if (itA.type + itB.type in lookup && lookup[itA.type + itB.type](
|
|
735
|
+
itA.coordinates,
|
|
736
|
+
itB.coordinates
|
|
737
|
+
) || itB.type + itA.type in lookup && lookup[itB.type + itA.type](itB.coordinates, itA.coordinates)) {
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
export {
|
|
744
|
+
SimpleGeometryIterator,
|
|
745
|
+
distance,
|
|
746
|
+
intersect,
|
|
747
|
+
isFeature,
|
|
748
|
+
isFeatureCollection,
|
|
749
|
+
isGeoJSON,
|
|
750
|
+
isGeometry,
|
|
751
|
+
isGeometryCollection,
|
|
752
|
+
isLineString,
|
|
753
|
+
isMultiLineString,
|
|
754
|
+
isMultiPoint,
|
|
755
|
+
isMultiPolygon,
|
|
756
|
+
isPoint,
|
|
757
|
+
isPolygon,
|
|
758
|
+
isPosition,
|
|
759
|
+
isStrictFeature,
|
|
760
|
+
isStrictFeatureCollection,
|
|
761
|
+
isStrictGeoJSON,
|
|
762
|
+
isStrictGeometry,
|
|
763
|
+
isStrictGeometryCollection,
|
|
764
|
+
isStrictLineString,
|
|
765
|
+
isStrictMultiLineString,
|
|
766
|
+
isStrictMultiPoint,
|
|
767
|
+
isStrictMultiPolygon,
|
|
768
|
+
isStrictPoint,
|
|
769
|
+
isStrictPolygon,
|
|
770
|
+
isStrictPosition
|
|
771
|
+
};
|
|
772
|
+
//# sourceMappingURL=main.mjs.map
|