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