forked from w8r/martinez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
featureTypes.test.js
56 lines (46 loc) · 2.46 KB
/
featureTypes.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import tap from 'tape';
import path from 'path';
import load from 'load-json-file';
import * as martinez from '../index';
const clipping = load.sync(path.join(__dirname, 'featureTypes', 'clippingPoly.geojson'));
const outDir = path.join(__dirname, 'featureTypes', 'out');
const testScenarios = [
{
testName: 'polyToClipping',
subjectPoly: 'poly',
},
{
testName: 'polyWithHoleToClipping',
subjectPoly: 'polyWithHole',
},
{
testName: 'multiPolyToClipping',
subjectPoly: 'multiPoly',
},
{
testName: 'multiPolyWithHoleToClipping',
subjectPoly: 'multiPolyWithHole',
}
];
testScenarios.forEach((ts) => {
const subject = load.sync(path.join(__dirname, 'featureTypes', ts.subjectPoly + '.geojson'));
tap.test(ts.testName, (t) => {
const expectedIntResult = load.sync(path.join(outDir, 'intersection', t.name + '.geojson'))
if (expectedIntResult.geometry.type === 'Polygon') expectedIntResult.geometry.coordinates = [expectedIntResult.geometry.coordinates]
const intResult = martinez.intersection(subject.geometry.coordinates, clipping.geometry.coordinates);
t.same(intResult, expectedIntResult.geometry.coordinates, ts.testName + ' - Intersect');
const expectedXorResult = load.sync(path.join(outDir, 'xor', t.name + '.geojson'))
if (expectedXorResult.geometry.type === 'Polygon') expectedXorResult.geometry.coordinates = [expectedXorResult.geometry.coordinates]
const xorResult = martinez.xor(subject.geometry.coordinates, clipping.geometry.coordinates);
t.same(xorResult, expectedXorResult.geometry.coordinates, ts.testName + ' - XOR');
const expectedDiffResult = load.sync(path.join(outDir, 'difference', t.name + '.geojson'))
if (expectedDiffResult.geometry.type === 'Polygon') expectedDiffResult.geometry.coordinates = [expectedDiffResult.geometry.coordinates]
const diffResult = martinez.diff(subject.geometry.coordinates, clipping.geometry.coordinates);
t.same(diffResult, expectedDiffResult.geometry.coordinates, ts.testName + ' - Difference');
const expectedUnionResult = load.sync(path.join(outDir, 'union', t.name + '.geojson'))
if (expectedUnionResult.geometry.type === 'Polygon') expectedUnionResult.geometry.coordinates = [expectedUnionResult.geometry.coordinates]
const unionResult = martinez.union(subject.geometry.coordinates, clipping.geometry.coordinates);
t.same(unionResult, expectedUnionResult.geometry.coordinates, ts.testName + ' - Union');
t.end();
});
});