-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathfilter-utils.spec.ts
More file actions
77 lines (65 loc) · 2.05 KB
/
filter-utils.spec.ts
File metadata and controls
77 lines (65 loc) · 2.05 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
/** @jest-environment node */
// loaders.gl expects fetch globals (Response, etc). Node < 18 / Jest may not provide them.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const nodeFetch = require('node-fetch');
(global as any).fetch = (global as any).fetch || nodeFetch;
(global as any).Response = (global as any).Response || nodeFetch.Response;
(global as any).Headers = (global as any).Headers || nodeFetch.Headers;
(global as any).Request = (global as any).Request || nodeFetch.Request;
import {getPolygonFilterFunctor} from './filter-utils';
import {getGeojsonPointPositionFromRaw} from '../../layers/src/geojson-layer/geojson-position-utils';
describe('filterUtils - polygon filter', () => {
const squarePolygon = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[
[-1, -1],
[1, -1],
[1, 1],
[-1, 1],
[-1, -1]
]
]
}
};
test('WKT POINT string can be used for polygon filter', () => {
const layer = {
type: 'point',
getPositionAccessor: () => (d: {raw: unknown}) => getGeojsonPointPositionFromRaw(d.raw)
};
const filter = {value: squarePolygon};
const fn = getPolygonFilterFunctor(layer, filter, null);
expect(getGeojsonPointPositionFromRaw('POINT (0.5 0.5)')).toEqual([0.5, 0.5]);
expect(fn({raw: 'POINT (0.5 0.5)'})).toBe(true);
expect(fn({raw: 'POINT (10 10)'})).toBe(false);
});
test('MultiPoint keeps row if any point is inside polygon', () => {
const layer = {
type: 'point',
getPositionAccessor: () => (d: {pos: any}) => d.pos
};
const filter = {value: squarePolygon};
const fn = getPolygonFilterFunctor(layer, filter, null);
expect(
fn({
pos: [
[10, 10],
[0.2, 0.2]
]
})
).toBe(true);
expect(
fn({
pos: [
[10, 10],
[20, 20]
]
})
).toBe(false);
});
});