@konfirm/geojson 1.0.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/.editorconfig +16 -0
- package/.github/workflows/release.yml +21 -0
- package/.github/workflows/tests.yml +56 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +260 -0
- package/dist/Domain/Constants.d.ts +5 -0
- package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +6 -0
- package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +11 -0
- package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/Position.d.ts +7 -0
- package/dist/Domain/GeoJSON/Feature.d.ts +12 -0
- package/dist/Domain/GeoJSON/FeatureCollection.d.ts +8 -0
- package/dist/Domain/GeoJSON/GeoJSON.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +8 -0
- package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/Point.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry.d.ts +9 -0
- package/dist/Domain/GeoJSON/GeometryCollection.d.ts +8 -0
- package/dist/Domain/GeoJSON/GeometryObject.d.ts +12 -0
- package/dist/Domain/Guards/Number.d.ts +3 -0
- package/dist/Domain/Guards/Tuple.d.ts +3 -0
- package/dist/Domain/Iterator/IterablePair.d.ts +32 -0
- package/dist/Domain/Iterator/SimpleGeometry.d.ts +90 -0
- package/dist/Domain/Utility/Calculate.d.ts +9 -0
- package/dist/Domain/Utility/Distance.d.ts +3 -0
- package/dist/Domain/Utility/Intersect.d.ts +2 -0
- package/dist/Domain/Utility/Segments.d.ts +2 -0
- package/dist/Domain/Utility/Winding.d.ts +3 -0
- package/dist/geojson.cjs.js +655 -0
- package/dist/geojson.cjs.min.js +1 -0
- package/dist/geojson.d.ts +198 -0
- package/dist/geojson.es.js +627 -0
- package/dist/geojson.es.min.js +1 -0
- package/dist/geojson.js +660 -0
- package/dist/geojson.min.js +1 -0
- package/dist/main.d.ts +15 -0
- package/package.json +63 -0
- package/rollup.config.mjs +43 -0
- package/source/Domain/Constants.ts +5 -0
- package/source/Domain/GeoJSON/Concept/Altitude.ts +9 -0
- package/source/Domain/GeoJSON/Concept/BoundingBox.ts +31 -0
- package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +12 -0
- package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +23 -0
- package/source/Domain/GeoJSON/Concept/InteriorRing.ts +12 -0
- package/source/Domain/GeoJSON/Concept/Latitude.ts +7 -0
- package/source/Domain/GeoJSON/Concept/LinearRing.ts +14 -0
- package/source/Domain/GeoJSON/Concept/Longitude.ts +7 -0
- package/source/Domain/GeoJSON/Concept/Position.ts +18 -0
- package/source/Domain/GeoJSON/Feature.ts +24 -0
- package/source/Domain/GeoJSON/FeatureCollection.ts +16 -0
- package/source/Domain/GeoJSON/GeoJSON.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/LineString.ts +12 -0
- package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +10 -0
- package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/Point.ts +12 -0
- package/source/Domain/GeoJSON/Geometry/Polygon.ts +20 -0
- package/source/Domain/GeoJSON/Geometry.ts +11 -0
- package/source/Domain/GeoJSON/GeometryCollection.ts +23 -0
- package/source/Domain/GeoJSON/GeometryObject.ts +20 -0
- package/source/Domain/Guards/Number.ts +13 -0
- package/source/Domain/Guards/Tuple.ts +6 -0
- package/source/Domain/Guards/Utility.ts +1 -0
- package/source/Domain/Iterator/IterablePair.ts +47 -0
- package/source/Domain/Iterator/SimpleGeometry.ts +137 -0
- package/source/Domain/Utility/Calculate.ts +143 -0
- package/source/Domain/Utility/Distance.ts +56 -0
- package/source/Domain/Utility/Intersect.ts +42 -0
- package/source/Domain/Utility/Numeric.ts +8 -0
- package/source/Domain/Utility/Segments.ts +5 -0
- package/source/Domain/Utility/Winding.ts +19 -0
- package/source/main.ts +20 -0
- package/test/Domain/GeoJSON/Concept/Altitude.ts +58 -0
- package/test/Domain/GeoJSON/Concept/BoundingBox.ts +77 -0
- package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +65 -0
- package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +56 -0
- package/test/Domain/GeoJSON/Concept/InteriorRing.ts +65 -0
- package/test/Domain/GeoJSON/Concept/Latitude.ts +56 -0
- package/test/Domain/GeoJSON/Concept/LinearRing.ts +63 -0
- package/test/Domain/GeoJSON/Concept/Longitude.ts +56 -0
- package/test/Domain/GeoJSON/Concept/Position.ts +56 -0
- package/test/Domain/GeoJSON/Feature.ts +9 -0
- package/test/Domain/GeoJSON/FeatureCollection.ts +9 -0
- package/test/Domain/GeoJSON/GeoJSON.ts +21 -0
- package/test/Domain/GeoJSON/Geometry/LineString.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/Point.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/Polygon.ts +11 -0
- package/test/Domain/GeoJSON/Geometry.ts +9 -0
- package/test/Domain/GeoJSON/GeometryCollection.ts +9 -0
- package/test/Domain/GeoJSON/GeometryObject.ts +4 -0
- package/test/Domain/Guards/Number.ts +49 -0
- package/test/Domain/Guards/Tuple.ts +27 -0
- package/test/Domain/Iterator/IterablePair.ts +203 -0
- package/test/Domain/Iterator/SimpleGeometry.ts +195 -0
- package/test/Domain/Utility/Calculate.ts +178 -0
- package/test/Domain/Utility/Distance.ts +19 -0
- package/test/Domain/Utility/Intersect.ts +54 -0
- package/test/Domain/Utility/Numeric.ts +30 -0
- package/test/Domain/Utility/Winding.ts +52 -0
- package/test/README.ts +123 -0
- package/test/data/Distance.ts +51 -0
- package/test/data/HolySee.ts +74 -0
- package/test/data/Intersect.ts +300 -0
- package/test/data/Italy.ts +2883 -0
- package/test/data/SanMarino.ts +83 -0
- package/test/data/Shapes.ts +107 -0
- package/test/helper/geometry.ts +76 -0
- package/test/helper/malform.ts +82 -0
- package/test/main.ts +4 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/GeoJSONObject';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/GeoJSON/Concept/GeoJSONObject', Export, 'isGeoJSONObject', 'isStrictGeoJSONObject');
|
|
7
|
+
|
|
8
|
+
const { isGeoJSONObject, isStrictGeoJSONObject } = Export;
|
|
9
|
+
|
|
10
|
+
test('Domain/GeoJSON/Concept/GeoJSONObject - isGeoJSONObject', (t) => {
|
|
11
|
+
each`
|
|
12
|
+
type | bbox | valid
|
|
13
|
+
-------------|-------------------------------|-------
|
|
14
|
+
Type | | yes
|
|
15
|
+
Type | ${[0, 0, 0, 0]} | yes
|
|
16
|
+
Type | ${[0, 0, 0, 0, 0, 0]} | yes
|
|
17
|
+
Type | ${[-181, -91, 0, 181, 91, 0]} | yes
|
|
18
|
+
${undefined} | | no
|
|
19
|
+
${null} | | no
|
|
20
|
+
${true} | | no
|
|
21
|
+
${false} | | no
|
|
22
|
+
${12345} | | no
|
|
23
|
+
`(({ type, bbox, valid }: any) => {
|
|
24
|
+
const validate = isGeoJSONObject(type);
|
|
25
|
+
const input = Object.assign({ type }, bbox ? { bbox } : {});
|
|
26
|
+
|
|
27
|
+
t.equal(typeof validate, 'function', `creates isGeoJSONObject validator for type ${JSON.stringify(type)}`);
|
|
28
|
+
t.equal(validate(input), valid === 'yes', `type ${JSON.stringify(type)} validates ${JSON.stringify(input)} ${valid}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
t.end();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Domain/GeoJSON/Concept/GeoJSONObject - isStrictGeoJSONObject', (t) => {
|
|
35
|
+
each`
|
|
36
|
+
type | bbox | valid
|
|
37
|
+
-------------|-------------------------------|-------
|
|
38
|
+
Type | | yes
|
|
39
|
+
Type | ${[0, 0, 0, 0]} | yes
|
|
40
|
+
Type | ${[0, 0, 0, 0, 0, 0]} | yes
|
|
41
|
+
Type | ${[-181, -91, 0, 181, 91, 0]} | no
|
|
42
|
+
${undefined} | | no
|
|
43
|
+
${null} | | no
|
|
44
|
+
${true} | | no
|
|
45
|
+
${false} | | no
|
|
46
|
+
${12345} | | no
|
|
47
|
+
`(({ type, bbox, valid }: any) => {
|
|
48
|
+
const validate = isStrictGeoJSONObject(type);
|
|
49
|
+
const input = Object.assign({ type }, bbox ? { bbox } : {});
|
|
50
|
+
|
|
51
|
+
t.equal(typeof validate, 'function', `creates isStrictGeoJSONObject validator for type ${JSON.stringify(type)}`);
|
|
52
|
+
t.equal(validate(input), valid === 'yes', `type ${JSON.stringify(type)} validates ${JSON.stringify(input)} ${valid}`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/InteriorRing';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
import { coordinates as Italy } from '../../../data/Italy';
|
|
6
|
+
import { coordinates as SanMarino, polygon } from '../../../data/SanMarino';
|
|
7
|
+
import { coordinates as HolySee } from '../../../data/HolySee';
|
|
8
|
+
|
|
9
|
+
exported('Domain/GeoJSON/Concept/InteriorRing', Export, 'isInteriorRing', 'isStrictInteriorRing');
|
|
10
|
+
|
|
11
|
+
const { isInteriorRing, isStrictInteriorRing } = Export;
|
|
12
|
+
|
|
13
|
+
test('Domain/GeoJSON/Concept/InteriorRing - isInteriorRing', (t) => {
|
|
14
|
+
each`
|
|
15
|
+
input | valid
|
|
16
|
+
-------------------------------------------------|----
|
|
17
|
+
${undefined} | no
|
|
18
|
+
${null} | no
|
|
19
|
+
${'[[1,0],[1,1],[0,1],[1,0]]'} | no
|
|
20
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
|
|
21
|
+
${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
|
|
22
|
+
${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
|
|
23
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
|
|
24
|
+
${[[1, 0], [1, 1], [1, 0]]} | no
|
|
25
|
+
${[[1, 0], [1, 0]]} | no
|
|
26
|
+
${[[1, 0]]} | no
|
|
27
|
+
${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | yes
|
|
28
|
+
`(({ input, valid }) => {
|
|
29
|
+
t.equal(isInteriorRing(input), valid === 'yes', `[${input}] isInteriorRing ${valid}`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
t.ok(Italy.every((polygon) => polygon.every(isInteriorRing)), 'coordinates for Italy polygon all match isInteriorRing');
|
|
33
|
+
t.notOk(SanMarino.every(isInteriorRing), 'coordinates for SanMarino does not match isInteriorRing');
|
|
34
|
+
t.notOk(HolySee.every(isInteriorRing), 'coordinates for HolySee does not match isInteriorRing');
|
|
35
|
+
|
|
36
|
+
t.end();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Domain/GeoJSON/Concept/InteriorRing - isStrictInteriorRing', (t) => {
|
|
40
|
+
each`
|
|
41
|
+
input | valid
|
|
42
|
+
-------------------------------------------------|----
|
|
43
|
+
${undefined} | no
|
|
44
|
+
${null} | no
|
|
45
|
+
${'[[1,0],[1,1],[0,1],[1,0]]'} | no
|
|
46
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
|
|
47
|
+
${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | no
|
|
48
|
+
${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
|
|
49
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
|
|
50
|
+
${[[1, 0], [1, 1], [1, 0]]} | no
|
|
51
|
+
${[[1, 0], [1, 0]]} | no
|
|
52
|
+
${[[1, 0]]} | no
|
|
53
|
+
${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | no
|
|
54
|
+
`(({ input, valid }) => {
|
|
55
|
+
t.equal(isStrictInteriorRing(input), valid === 'yes', `[${input}] isStrictInteriorRing ${valid}`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
t.notOk(Italy.every((polygon) => polygon.every(isStrictInteriorRing)), 'coordinates for Italy polygon do not match isStrictInteriorRing');
|
|
59
|
+
t.ok(Italy.every((polygon) => !isStrictInteriorRing(polygon[0])), 'first polygon coordinates for Italy none match isStrictInteriorRing');
|
|
60
|
+
t.ok(Italy.filter((polygon) => polygon.length > 1).every((polygon) => polygon.slice(1).every(isStrictInteriorRing)), 'second+ polygon coordinates for Italy none match isStrictInteriorRing')
|
|
61
|
+
t.notOk(SanMarino.every(isStrictInteriorRing), 'coordinates for SanMarino does not match isStrictInteriorRing');
|
|
62
|
+
t.notOk(HolySee.every(isStrictInteriorRing), 'coordinates for HolySee does not match isStrictInteriorRing');
|
|
63
|
+
|
|
64
|
+
t.end();
|
|
65
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/Latitude';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/GeoJSON/Concept/Latitude', Export, 'isLatitude', 'isStrictLatitude');
|
|
7
|
+
|
|
8
|
+
const { isLatitude, isStrictLatitude } = Export;
|
|
9
|
+
|
|
10
|
+
test('Domain/GeoJSON/Concept/Latitude - isLatitude', (t) => {
|
|
11
|
+
each`
|
|
12
|
+
input | valid
|
|
13
|
+
----------------|-------
|
|
14
|
+
${0} | yes
|
|
15
|
+
${0.0000000001} | yes
|
|
16
|
+
${51.9851034} | yes
|
|
17
|
+
${-90} | yes
|
|
18
|
+
${-90.1} | yes
|
|
19
|
+
${90} | yes
|
|
20
|
+
${90.1} | yes
|
|
21
|
+
${-Infinity} | no
|
|
22
|
+
${Infinity} | no
|
|
23
|
+
${NaN} | no
|
|
24
|
+
${'1234'} | no
|
|
25
|
+
${false} | no
|
|
26
|
+
${true} | no
|
|
27
|
+
`(({ input, valid }) => {
|
|
28
|
+
t.equal(isLatitude(input), valid === 'yes', `${input} ${valid}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
t.end();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Domain/GeoJSON/Concept/Latitude - isStrictLatitude', (t) => {
|
|
35
|
+
each`
|
|
36
|
+
input | valid
|
|
37
|
+
----------------|-------
|
|
38
|
+
${0} | yes
|
|
39
|
+
${0.0000000001} | yes
|
|
40
|
+
${51.9851034} | yes
|
|
41
|
+
${-90} | yes
|
|
42
|
+
${-90.1} | no
|
|
43
|
+
${90} | yes
|
|
44
|
+
${90.1} | no
|
|
45
|
+
${-Infinity} | no
|
|
46
|
+
${Infinity} | no
|
|
47
|
+
${NaN} | no
|
|
48
|
+
${'1234'} | no
|
|
49
|
+
${false} | no
|
|
50
|
+
${true} | no
|
|
51
|
+
`(({ input, valid }) => {
|
|
52
|
+
t.equal(isStrictLatitude(input), valid === 'yes', `${input} ${valid}`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/LinearRing';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
import { coordinates as Italy } from '../../../data/Italy';
|
|
6
|
+
import { coordinates as SanMarino } from '../../../data/SanMarino';
|
|
7
|
+
import { coordinates as HolySee } from '../../../data/HolySee';
|
|
8
|
+
|
|
9
|
+
exported('Domain/GeoJSON/Concept/LinearRing', Export, 'isLinearRing', 'isStrictLinearRing');
|
|
10
|
+
|
|
11
|
+
const { isLinearRing, isStrictLinearRing } = Export;
|
|
12
|
+
|
|
13
|
+
test('Domain/GeoJSON/Concept/LinearRing - isLinearRing', (t) => {
|
|
14
|
+
each`
|
|
15
|
+
input | valid
|
|
16
|
+
-------------------------------------------------|----
|
|
17
|
+
${undefined} | no
|
|
18
|
+
${null} | no
|
|
19
|
+
${'[[1,0],[1,1],[0,1],[1,0]]'} | no
|
|
20
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
|
|
21
|
+
${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
|
|
22
|
+
${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
|
|
23
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
|
|
24
|
+
${[[1, 0], [1, 1], [1, 0]]} | no
|
|
25
|
+
${[[1, 0], [1, 0]]} | no
|
|
26
|
+
${[[1, 0]]} | no
|
|
27
|
+
${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | yes
|
|
28
|
+
`(({ input, valid }) => {
|
|
29
|
+
t.equal(isLinearRing(input), valid === 'yes', `[${input}] isLinearRing ${valid}`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
t.ok(Italy.every((polygon) => polygon.every(isLinearRing)), 'coordinates for Italy polygon all match isLinearRing');
|
|
33
|
+
t.notOk(SanMarino.every(isLinearRing), 'coordinates for SanMarino does not match isLinearRing');
|
|
34
|
+
t.notOk(HolySee.every(isLinearRing), 'coordinates for HolySee does not match isLinearRing');
|
|
35
|
+
|
|
36
|
+
t.end();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Domain/GeoJSON/Concept/LinearRing - isStrictLinearRing', (t) => {
|
|
40
|
+
each`
|
|
41
|
+
input | valid
|
|
42
|
+
-------------------------------------------------|----
|
|
43
|
+
${undefined} | no
|
|
44
|
+
${null} | no
|
|
45
|
+
${'[[1,0],[1,1],[0,1],[1,0]]'} | no
|
|
46
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
|
|
47
|
+
${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
|
|
48
|
+
${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
|
|
49
|
+
${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
|
|
50
|
+
${[[1, 0], [1, 1], [1, 0]]} | no
|
|
51
|
+
${[[1, 0], [1, 0]]} | no
|
|
52
|
+
${[[1, 0]]} | no
|
|
53
|
+
${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | no
|
|
54
|
+
`(({ input, valid }) => {
|
|
55
|
+
t.equal(isStrictLinearRing(input), valid === 'yes', `[${input}] isStrictLinearRing ${valid}`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
t.ok(Italy.every((polygon) => polygon.every(isStrictLinearRing)), 'coordinates for Italy polygon all match isStrictLinearRing');
|
|
59
|
+
t.notOk(SanMarino.every(isStrictLinearRing), 'coordinates for SanMarino does not match isStrictLinearRing');
|
|
60
|
+
t.notOk(HolySee.every(isStrictLinearRing), 'coordinates for HolySee does not match isStrictLinearRing');
|
|
61
|
+
|
|
62
|
+
t.end();
|
|
63
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/Longitude';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/GeoJSON/Concept/Longitude', Export, 'isLongitude', 'isStrictLongitude');
|
|
7
|
+
|
|
8
|
+
const { isLongitude, isStrictLongitude } = Export;
|
|
9
|
+
|
|
10
|
+
test('Domain/GeoJSON/Concept/Longitude - isLongitude', (t) => {
|
|
11
|
+
each`
|
|
12
|
+
input | valid
|
|
13
|
+
----------------|-------
|
|
14
|
+
${0} | yes
|
|
15
|
+
${0.0000000001} | yes
|
|
16
|
+
${5.8987296} | yes
|
|
17
|
+
${-180} | yes
|
|
18
|
+
${-180.1} | yes
|
|
19
|
+
${180} | yes
|
|
20
|
+
${180.1} | yes
|
|
21
|
+
${-Infinity} | no
|
|
22
|
+
${Infinity} | no
|
|
23
|
+
${NaN} | no
|
|
24
|
+
${'1234'} | no
|
|
25
|
+
${false} | no
|
|
26
|
+
${true} | no
|
|
27
|
+
`(({ input, valid }) => {
|
|
28
|
+
t.equal(isLongitude(input), valid === 'yes', `${input} ${valid}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
t.end();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Domain/GeoJSON/Concept/Longitude - isStrictLongitude', (t) => {
|
|
35
|
+
each`
|
|
36
|
+
input | valid
|
|
37
|
+
----------------|-------
|
|
38
|
+
${0} | yes
|
|
39
|
+
${0.0000000001} | yes
|
|
40
|
+
${5.8987296} | yes
|
|
41
|
+
${-180} | yes
|
|
42
|
+
${-180.1} | no
|
|
43
|
+
${180} | yes
|
|
44
|
+
${180.1} | no
|
|
45
|
+
${-Infinity} | no
|
|
46
|
+
${Infinity} | no
|
|
47
|
+
${NaN} | no
|
|
48
|
+
${'1234'} | no
|
|
49
|
+
${false} | no
|
|
50
|
+
${true} | no
|
|
51
|
+
`(({ input, valid }) => {
|
|
52
|
+
t.equal(isStrictLongitude(input), valid === 'yes', `${input} ${valid}`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Concept/Position';
|
|
3
|
+
import { coordinates } from '../../../data/HolySee';
|
|
4
|
+
import { exported } from '../../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/GeoJSON/Concept/Position', Export, 'isPosition', 'isStrictPosition', 'isEquivalentPosition');
|
|
7
|
+
|
|
8
|
+
const { isPosition, isStrictPosition, isEquivalentPosition } = Export;
|
|
9
|
+
const altitude = coordinates.map(([lon, lat, alt = 1.23]) => [lon, lat, alt]);
|
|
10
|
+
|
|
11
|
+
test('Domain/GeoJSON/Concept/Position - isPosition', (t) => {
|
|
12
|
+
t.ok(coordinates.every(isPosition), 'all coordinates match isPosition');
|
|
13
|
+
t.ok(altitude.every(isPosition), 'all coordinates with altitude match isPosition');
|
|
14
|
+
|
|
15
|
+
t.notOk(isPosition([Infinity, 0, 0]), `[Infinity, 0, 0] is not a Position`);
|
|
16
|
+
t.notOk(isPosition([0, Infinity, 0]), `[0, Infinity, 0] is not a Position`);
|
|
17
|
+
t.notOk(isPosition([0, 0, Infinity]), `[0, 0, Infinity] is not a Position`);
|
|
18
|
+
t.ok(isPosition([0, 0, 0]), `[0, 0, 0] is Position`);
|
|
19
|
+
t.ok(isPosition([-181, 0, 0]), `[-181, 0, 0] is Position`);
|
|
20
|
+
t.ok(isPosition([0, -91, 0]), `[0, -91, 0] is Position`);
|
|
21
|
+
t.ok(isPosition([0, 0, -7000000]), `[0, 0, -7000000] is Position`);
|
|
22
|
+
t.ok(isPosition([-181, -91, 0]), `[-181, -91, 0] is Position`);
|
|
23
|
+
t.ok(isPosition([0, -91, -7000000]), `[0, -91, -7000000] is Position`);
|
|
24
|
+
t.ok(isPosition([-181, 0, -7000000]), `[-181, 0, -7000000] is Position`);
|
|
25
|
+
t.ok(isPosition([-181, -91, -7000000]), `[-181, -91, -7000000] is Position`);
|
|
26
|
+
|
|
27
|
+
t.end();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Domain/GeoJSON/Concept/Position - isStrictPosition', (t) => {
|
|
31
|
+
t.ok(coordinates.every(isStrictPosition), 'all coordinates match isStrictPosition');
|
|
32
|
+
t.ok(altitude.every(isStrictPosition), 'all coordinates with altitude match isStrictPosition');
|
|
33
|
+
|
|
34
|
+
t.notOk(isStrictPosition([Infinity, 0, 0]), `[Infinity, 0, 0] is not a strict Position`);
|
|
35
|
+
t.notOk(isStrictPosition([0, Infinity, 0]), `[0, Infinity, 0] is not a strict Position`);
|
|
36
|
+
t.notOk(isStrictPosition([0, 0, Infinity]), `[0, 0, Infinity] is not a strict Position`);
|
|
37
|
+
t.ok(isStrictPosition([0, 0, 0]), `[0, 0, 0] is strict Position`);
|
|
38
|
+
t.notOk(isStrictPosition([-181, 0, 0]), `[-181, 0, 0] is not a strict Position`);
|
|
39
|
+
t.notOk(isStrictPosition([0, -91, 0]), `[0, -91, 0] is not a strict Position`);
|
|
40
|
+
t.notOk(isStrictPosition([0, 0, -7000000]), `[0, 0, -7000000] is not a strict Position`);
|
|
41
|
+
t.notOk(isStrictPosition([-181, -91, 0]), `[-181, -91, 0] is not a strict Position`);
|
|
42
|
+
t.notOk(isStrictPosition([0, -91, -7000000]), `[0, -91, -7000000] is not a strict Position`);
|
|
43
|
+
t.notOk(isStrictPosition([-181, 0, -7000000]), `[-181, 0, -7000000] is not a strict Position`);
|
|
44
|
+
t.notOk(isStrictPosition([-181, -91, -7000000]), `[-181, -91, -7000000] is not a strict Position`);
|
|
45
|
+
|
|
46
|
+
t.end();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Domain/GeoJSON/Concept/Position - isEquivalentPosition', (t) => {
|
|
50
|
+
t.ok(isEquivalentPosition([1.23456789, 2.3456789], [1.23456789, 2.3456789]), `[1.23456789,2.3456789] and [1.23456789,2.3456789] are equivalent`);
|
|
51
|
+
t.ok(isEquivalentPosition([1.23456789, 2.3456789, 3.456789], [1.23456789, 2.3456789, 3.456789]), `[1.23456789,2.3456789,3.456789] and [1.23456789,2.3456789,3.456789] are equivalent`);
|
|
52
|
+
t.notOk(isEquivalentPosition([1.23456789, 2.3456789, 3.456789], [1.23456789, 2.3456789]), `[1.23456789,2.3456789,3.456789] and [1.23456789,2.3456789] are not equivalent`);
|
|
53
|
+
t.notOk(isEquivalentPosition([1.23456789, 2.3456789], [1.23456789, 2.3456789, , 3.456789]), `[1.23456789,2.3456789] and [1.23456789,2.3456789,,3.456789] are not equivalent`);
|
|
54
|
+
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as Export from '../../../source/Domain/GeoJSON/GeoJSON';
|
|
2
|
+
import { runner } from '../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
const types = [
|
|
5
|
+
'Point',
|
|
6
|
+
'MultiPoint',
|
|
7
|
+
'LineString',
|
|
8
|
+
'MultiLineString',
|
|
9
|
+
'Polygon',
|
|
10
|
+
'MultiPolygon',
|
|
11
|
+
'GeometryCollection',
|
|
12
|
+
'Feature',
|
|
13
|
+
'FeatureCollection',
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
runner(
|
|
17
|
+
'Domain/GeoJSON/GeoJSON',
|
|
18
|
+
Export,
|
|
19
|
+
['isGeoJSON', types],
|
|
20
|
+
['isStrictGeoJSON', types],
|
|
21
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/LineString';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/LineString',
|
|
6
|
+
Export,
|
|
7
|
+
['isLineStringCoordinates', ['MultiPoint']],
|
|
8
|
+
'isLineString',
|
|
9
|
+
['isStrictLineStringCoordinates', ['MultiPoint']],
|
|
10
|
+
'isStrictLineString',
|
|
11
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiLineString';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/MultiLineString',
|
|
6
|
+
Export,
|
|
7
|
+
['isMultiLineStringCoordinates', ['Polygon']],
|
|
8
|
+
'isMultiLineString',
|
|
9
|
+
['isStrictMultiLineStringCoordinates', ['Polygon']],
|
|
10
|
+
'isStrictMultiLineString',
|
|
11
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiPoint';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/MultiPoint',
|
|
6
|
+
Export,
|
|
7
|
+
['isMultiPointCoordinates', ['LineString']],
|
|
8
|
+
'isMultiPoint',
|
|
9
|
+
['isStrictMultiPointCoordinates', ['LineString']],
|
|
10
|
+
'isStrictMultiPoint',
|
|
11
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiPolygon';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/MultiPolygon',
|
|
6
|
+
Export,
|
|
7
|
+
'isMultiPolygonCoordinates',
|
|
8
|
+
'isMultiPolygon',
|
|
9
|
+
'isStrictMultiPolygonCoordinates',
|
|
10
|
+
'isStrictMultiPolygon',
|
|
11
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/Point';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/Point',
|
|
6
|
+
Export,
|
|
7
|
+
'isPointCoordinates',
|
|
8
|
+
'isPoint',
|
|
9
|
+
'isStrictPointCoordinates',
|
|
10
|
+
'isStrictPoint',
|
|
11
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Export from '../../../../source/Domain/GeoJSON/Geometry/Polygon';
|
|
2
|
+
import { runner } from '../../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry/Polygon',
|
|
6
|
+
Export,
|
|
7
|
+
'isPolygonCoordinates',
|
|
8
|
+
'isPolygon',
|
|
9
|
+
'isStrictPolygonCoordinates',
|
|
10
|
+
'isStrictPolygon',
|
|
11
|
+
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as Export from '../../../source/Domain/GeoJSON/Geometry';
|
|
2
|
+
import { runner } from '../../helper/geometry';
|
|
3
|
+
|
|
4
|
+
runner(
|
|
5
|
+
'Domain/GeoJSON/Geometry',
|
|
6
|
+
Export,
|
|
7
|
+
['isGeometry', ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']],
|
|
8
|
+
['isStrictGeometry', ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']],
|
|
9
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import { each } from 'template-literal-each';
|
|
3
|
+
import * as Export from '../../../source/Domain/Guards/Number';
|
|
4
|
+
import { exported } from '../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/Guards/Number - exports', Export, 'isNumberValue', 'isNumberBetween');
|
|
7
|
+
|
|
8
|
+
const { isNumberValue, isNumberBetween } = Export;
|
|
9
|
+
|
|
10
|
+
test('Domain/Guards/Number - isNumberValue', (t) => {
|
|
11
|
+
each`
|
|
12
|
+
input | valid
|
|
13
|
+
---------------------------|-------
|
|
14
|
+
${123} | yes
|
|
15
|
+
${Number.MAX_SAFE_INTEGER} | yes
|
|
16
|
+
${Number.MIN_SAFE_INTEGER} | yes
|
|
17
|
+
${Number.MAX_VALUE} | yes
|
|
18
|
+
${Number.MIN_VALUE} | yes
|
|
19
|
+
${Math.PI} | yes
|
|
20
|
+
${-Math.PI} | yes
|
|
21
|
+
${Infinity} | no
|
|
22
|
+
${-Infinity} | no
|
|
23
|
+
${NaN} | no
|
|
24
|
+
${'123'} | no
|
|
25
|
+
`(({ input, valid }) => {
|
|
26
|
+
t.equal(isNumberValue(input), valid === 'yes', `${input} isNumberValue ${valid}`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
t.end();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('Domain/Guards/Number - isNumberBetween', (t) => {
|
|
33
|
+
each`
|
|
34
|
+
input | min | max | valid
|
|
35
|
+
-------------|--------|--------------|-------
|
|
36
|
+
${1} | ${0} | ${2} | yes
|
|
37
|
+
${0} | ${0} | ${2} | yes
|
|
38
|
+
${-1} | ${0} | ${2} | no
|
|
39
|
+
${Infinity} | ${0} | ${undefined} | no
|
|
40
|
+
${Math.PI} | ${0} | ${undefined} | yes
|
|
41
|
+
${0} | ${-10} | ${10} | yes
|
|
42
|
+
`(({ input, min, max, valid }: any) => {
|
|
43
|
+
const between = isNumberBetween(min, max);
|
|
44
|
+
|
|
45
|
+
t.equal(between(input), valid === 'yes', `${input} is ${valid === 'no' ? 'not ' : ''}between ${min} and ${max}`);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
t.end();
|
|
49
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isBoolean, isNumber, isString } from '@konfirm/guard';
|
|
2
|
+
import test from 'tape';
|
|
3
|
+
import * as Export from '../../../source/Domain/Guards/Tuple';
|
|
4
|
+
import { exported } from '../../helper/geometry';
|
|
5
|
+
|
|
6
|
+
exported('Domain/Guards/Tuple - exports', Export, 'isTuple');
|
|
7
|
+
|
|
8
|
+
const { isTuple } = Export;
|
|
9
|
+
|
|
10
|
+
test('Domain/Guards/Tuple - isTuple', (t) => {
|
|
11
|
+
const snn = isTuple(isString, isNumber, isNumber);
|
|
12
|
+
const bsn = isTuple(isBoolean, isString, isNumber);
|
|
13
|
+
|
|
14
|
+
t.notOk(snn(['abc']), `['abc'] does not match isTuple(isString, isNumber, isNumber)`);
|
|
15
|
+
t.notOk(snn(['abc', 123]), `['abc', 123] does not match isTuple(isString, isNumber, isNumber)`);
|
|
16
|
+
t.ok(snn(['abc', 123, 456]), `['abc', 123, 456] matches isTuple(isString, isNumber, isNumber)`);
|
|
17
|
+
t.notOk(snn(['abc', 123, true]), `['abc', 123, true] does not match isTuple(isString, isNumber, isNumber)`);
|
|
18
|
+
t.notOk(snn(['abc', false, 123]), `['abc', false, 123] does not match isTuple(isString, isNumber, isNumber)`);
|
|
19
|
+
t.notOk(snn(['abc', 123, 456, 789]), `['abc', 456, 789, 123] does not match isTuple(isString, isNumber, isNumber)`);
|
|
20
|
+
|
|
21
|
+
t.notOk(bsn(['abc', 123]), `['abc', 123] does not match isTuple(isBoolean, isString, isNumber)`);
|
|
22
|
+
t.notOk(bsn(['abc', false, 123]), `['abc', false, 123] does not match isTuple(isBoolean, isString, isNumber)`);
|
|
23
|
+
t.ok(bsn([true, 'abc', 123]), `[true, 'abc', 123] matches isTuple(isBoolean, isString, isNumber)`);
|
|
24
|
+
t.ok(bsn([false, 'abc', 123]), `[false, 'abc', 123] matches isTuple(isBoolean, isString, isNumber)`);
|
|
25
|
+
|
|
26
|
+
t.end();
|
|
27
|
+
});
|