1
- import test from 'flug' ;
2
- import { serve } from 'srvd' ;
3
- import load from '../load' ;
4
- import utils from './utils.module' ;
5
- import getDepth from 'get-depth' ;
1
+ /** @format */
2
+
3
+ import test from "flug" ;
4
+ import { serve } from "srvd" ;
5
+ import load from "../load" ;
6
+ import utils from "./utils.module" ;
7
+ import getDepth from "get-depth" ;
6
8
7
9
serve ( { debug : true , max : 10 , port : 3000 } ) ;
8
10
9
11
const { fetchJson, fetchJsons } = utils ;
10
12
11
- const url = ' http://localhost:3000/data/RWA_MNH_ANC.tif' ;
12
- const urlToData = ' http://localhost:3000/data/' ;
13
- const urlToGeojsons = urlToData + ' gadm/geojsons/' ;
14
- const urlToGeojson = urlToGeojsons + ' Akrotiri and Dhekelia.geojson' ;
15
- const urlToArcgisJsons = urlToData + ' gadm/arcgis/' ;
13
+ const url = " http://localhost:3000/data/RWA_MNH_ANC.tif" ;
14
+ const urlToData = " http://localhost:3000/data/" ;
15
+ const urlToGeojsons = urlToData + " gadm/geojsons/" ;
16
+ const urlToGeojson = urlToGeojsons + " Akrotiri and Dhekelia.geojson" ;
17
+ const urlToArcgisJsons = urlToData + " gadm/arcgis/" ;
16
18
17
- test ( ' Get Bounding when Bounding Box when Bigger Than Raster and with Negative Values' , async ( { eq } ) => {
19
+ test ( " Get Bounding when Bounding Box when Bigger Than Raster and with Negative Values" , async ( { eq } ) => {
18
20
const georaster = await load ( url ) ;
19
21
const bboxWithBuffer = {
20
22
xmin : georaster . xmin - 1 ,
21
23
xmax : georaster . xmax + 1 ,
22
24
ymin : georaster . ymin - 1 ,
23
- ymax : georaster . ymax + 1 ,
25
+ ymax : georaster . ymax + 1
24
26
} ;
25
27
const actualBbox = utils . convertCrsBboxToImageBbox ( georaster , bboxWithBuffer ) ;
26
28
eq ( actualBbox . xmin < 0 , true ) ;
@@ -29,50 +31,59 @@ test('Get Bounding when Bounding Box when Bigger Than Raster and with Negative V
29
31
eq ( actualBbox . ymin < actualBbox . ymax , true ) ;
30
32
} ) ;
31
33
32
- test ( ' Get Bounding Box of GeoJSON that has MultiPolygon Geometry (i.e., multiple rings)' , async ( { eq } ) => {
34
+ test ( " Get Bounding Box of GeoJSON that has MultiPolygon Geometry (i.e., multiple rings)" , async ( { eq } ) => {
33
35
const country = await fetchJson ( urlToGeojson ) ;
34
36
const bbox = utils . getBoundingBox ( country . geometry . coordinates ) ;
35
- eq ( typeof bbox . xmin , ' number' ) ;
36
- eq ( typeof bbox . xmax , ' number' ) ;
37
- eq ( typeof bbox . ymin , ' number' ) ;
38
- eq ( typeof bbox . ymax , ' number' ) ;
37
+ eq ( typeof bbox . xmin , " number" ) ;
38
+ eq ( typeof bbox . xmax , " number" ) ;
39
+ eq ( typeof bbox . ymin , " number" ) ;
40
+ eq ( typeof bbox . ymax , " number" ) ;
39
41
eq ( bbox . xmin , 32.76010131835966 ) ;
40
42
eq ( bbox . xmax , 33.92147445678711 ) ;
41
43
eq ( bbox . ymin , 34.56208419799816 ) ;
42
44
eq ( bbox . ymax , 35.118995666503906 ) ;
43
45
} ) ;
44
46
45
-
46
- test ( 'Test Forcing Within' , ( { eq } ) => {
47
+ test ( "Test Forcing Within" , ( { eq } ) => {
47
48
eq ( utils . forceWithin ( 10 , 1 , 11 ) , 10 ) ;
48
49
eq ( utils . forceWithin ( - 10 , 1 , 11 ) , 1 ) ;
49
50
eq ( utils . forceWithin ( 990 , 1 , 11 ) , 11 ) ;
50
51
} ) ;
51
52
52
- test ( 'Test Merging of Index Ranges' , ( { eq } ) => {
53
- let original = [ [ 0 , 10 ] , [ 10 , 10 ] , [ 20 , 30 ] , [ 30 , 40 ] ] ;
53
+ test ( "Test Merging of Index Ranges" , ( { eq } ) => {
54
+ let original = [
55
+ [ 0 , 10 ] ,
56
+ [ 10 , 10 ] ,
57
+ [ 20 , 30 ] ,
58
+ [ 30 , 40 ]
59
+ ] ;
54
60
let merged = utils . mergeRanges ( original ) ;
55
- eq ( JSON . stringify ( merged ) , '[[0,10],[20,40]]' ) ;
56
-
57
- original = [ [ 0 , 10 ] , [ 10 , 10 ] , [ 21 , 31 ] , [ 30 , 40 ] ] ;
61
+ eq ( JSON . stringify ( merged ) , "[[0,10],[20,40]]" ) ;
62
+
63
+ original = [
64
+ [ 0 , 10 ] ,
65
+ [ 10 , 10 ] ,
66
+ [ 21 , 31 ] ,
67
+ [ 30 , 40 ]
68
+ ] ;
58
69
merged = utils . mergeRanges ( original ) ;
59
- eq ( JSON . stringify ( merged ) , ' [[0,10],[21,40]]' ) ;
70
+ eq ( JSON . stringify ( merged ) , " [[0,10],[21,40]]" ) ;
60
71
} ) ;
61
72
62
-
63
-
64
- test ( 'Get Depth For Multipolygon' , async ( { eq } ) => {
65
- const countryDepths = [ [ 'Afghanistan' , 3 ] , [ 'Akrotiri and Dhekelia' , 4 ] ] ;
73
+ test ( "Get Depth For Multipolygon" , async ( { eq } ) => {
74
+ const countryDepths = [
75
+ [ "Afghanistan" , 3 ] ,
76
+ [ "Akrotiri and Dhekelia" , 4 ]
77
+ ] ;
66
78
for ( let i = 0 ; i < countryDepths . length ; i ++ ) {
67
79
const [ name , depth ] = countryDepths [ i ] ;
68
- const country = await fetchJson ( urlToGeojsons + name + ' .geojson' ) ;
80
+ const country = await fetchJson ( urlToGeojsons + name + " .geojson" ) ;
69
81
const actualDepth = getDepth ( country . geometry . coordinates ) ;
70
82
eq ( actualDepth , depth ) ;
71
83
}
72
84
} ) ;
73
85
74
-
75
- test ( 'Clustering Of Line Segments: For array of objects holding information about intersections: Got Correct Split' , ( { eq } ) => {
86
+ test ( "Clustering Of Line Segments: For array of objects holding information about intersections: Got Correct Split" , ( { eq } ) => {
76
87
let segments , computed , computedNumberOfClusters ;
77
88
78
89
segments = [ { endsOffLine : true } , { endsOffLine : false } , { endsOffLine : false } , { endsOffLine : true } ] ;
@@ -96,7 +107,7 @@ test('Clustering Of Line Segments: For array of objects holding information abou
96
107
eq ( computed [ 0 ] . length , 4 ) ;
97
108
} ) ;
98
109
99
- test ( ' Test Coupling' , ( { eq } ) => {
110
+ test ( " Test Coupling" , ( { eq } ) => {
100
111
const items = [ 0 , 1 , 18 , 77 , 99 , 103 ] ;
101
112
const actual = utils . couple ( items ) ;
102
113
eq ( actual . length , items . length / 2 ) ;
@@ -105,11 +116,11 @@ test('Test Coupling', ({ eq }) => {
105
116
} ) ;
106
117
} ) ;
107
118
108
- test ( ' Test isPolygon' , async ( { eq } ) => {
109
- const countries = [ ' Afghanistan' , ' Ukraine' ] ;
119
+ test ( " Test isPolygon" , async ( { eq } ) => {
120
+ const countries = [ " Afghanistan" , " Ukraine" ] ;
110
121
for ( let i = 0 ; i < countries . length ; i ++ ) {
111
122
const name = countries [ i ] ;
112
- const jsons = await fetchJsons ( [ urlToGeojsons + name + ' .geojson' , urlToArcgisJsons + name + ' .json' ] ) ;
123
+ const jsons = await fetchJsons ( [ urlToGeojsons + name + " .geojson" , urlToArcgisJsons + name + " .json" ] ) ;
113
124
const [ geojson , arcgisjson ] = jsons ;
114
125
// console.log('geojson:', JSON.stringify(geojson).substring(0, 100) + '...');
115
126
// console.log('arcgisjson:', JSON.stringify(arcgisjson).substring(0, 100) + '...');
@@ -119,27 +130,38 @@ test('Test isPolygon', async ({ eq }) => {
119
130
}
120
131
} ) ;
121
132
122
- test ( 'Test Intersections' , ( { eq } ) => {
123
- const edge1 = [ [ 32.87069320678728 , 34.66652679443354 ] , [ 32.87069320678728 , 34.66680526733393 ] ] ; // vertical
124
- const edge2 = [ [ 30 , 34.70833333333334 ] , [ 40 , 34.70833333333334 ] ] ;
133
+ test ( "Test Intersections" , ( { eq } ) => {
134
+ const edge1 = [
135
+ [ 32.87069320678728 , 34.66652679443354 ] ,
136
+ [ 32.87069320678728 , 34.66680526733393 ]
137
+ ] ; // vertical
138
+ const edge2 = [
139
+ [ 30 , 34.70833333333334 ] ,
140
+ [ 40 , 34.70833333333334 ]
141
+ ] ;
125
142
const line1 = utils . getLineFromPoints ( edge1 [ 0 ] , edge1 [ 1 ] ) ;
126
143
const line2 = utils . getLineFromPoints ( edge2 [ 0 ] , edge2 [ 1 ] ) ;
127
144
let intersection = utils . getIntersectionOfTwoLines ( line1 , line2 ) ;
128
145
eq ( intersection . x , 32.87069320678728 ) ;
129
146
eq ( intersection . y , 34.70833333333334 ) ;
130
147
131
148
// this test fails because of floating point arithmetic
132
- const verticalEdge = [ [ 19.59097290039091 , 29.76190948486328 ] , [ 19.59097290039091 , 41.76180648803728 ] ] ;
133
- const horizontalEdge = [ [ 15 , 41.641892470257524 ] , [ 25 , 41.641892470257524 ] ] ;
149
+ const verticalEdge = [
150
+ [ 19.59097290039091 , 29.76190948486328 ] ,
151
+ [ 19.59097290039091 , 41.76180648803728 ]
152
+ ] ;
153
+ const horizontalEdge = [
154
+ [ 15 , 41.641892470257524 ] ,
155
+ [ 25 , 41.641892470257524 ]
156
+ ] ;
134
157
const verticalLine = utils . getLineFromPoints ( verticalEdge [ 0 ] , verticalEdge [ 1 ] ) ;
135
158
const horizontalLine = utils . getLineFromPoints ( horizontalEdge [ 0 ] , horizontalEdge [ 1 ] ) ;
136
159
intersection = utils . getIntersectionOfTwoLines ( verticalLine , horizontalLine ) ;
137
160
//eq(intersection.x, 19.59097290039091);
138
161
//eq(intersection.y, 41.641892470257524);
139
162
} ) ;
140
163
141
-
142
- test ( 'Test Categorization of Intersections' , ( { eq } ) => {
164
+ test ( "Test Categorization of Intersections" , ( { eq } ) => {
143
165
// through
144
166
let segments = [ { xmin : - 140 , xmax : - 140 , direction : 1 } ] ;
145
167
let actual = utils . categorizeIntersection ( segments ) ;
@@ -148,28 +170,42 @@ test('Test Categorization of Intersections', ({ eq }) => {
148
170
eq ( actual . xmax , - 140 ) ;
149
171
150
172
// rebound
151
- segments = [ { xmin : - 140 , xmax : - 140 , direction : 1 } , { xmin : - 140 , xmax : - 140 , direction : - 1 } ] ;
173
+ segments = [
174
+ { xmin : - 140 , xmax : - 140 , direction : 1 } ,
175
+ { xmin : - 140 , xmax : - 140 , direction : - 1 }
176
+ ] ;
152
177
actual = utils . categorizeIntersection ( segments ) ;
153
178
eq ( actual . through , false ) ;
154
179
eq ( actual . xmin , - 140 ) ;
155
180
eq ( actual . xmax , - 140 ) ;
156
181
157
182
// horizontal through
158
- segments = [ { xmin : - 140 , xmax : - 140 , direction : 1 } , { xmin : - 140 , xmax : - 130 , direction : 0 } , { xmin : - 130 , xmax : - 130 , direction : 1 } ] ;
183
+ segments = [
184
+ { xmin : - 140 , xmax : - 140 , direction : 1 } ,
185
+ { xmin : - 140 , xmax : - 130 , direction : 0 } ,
186
+ { xmin : - 130 , xmax : - 130 , direction : 1 }
187
+ ] ;
159
188
actual = utils . categorizeIntersection ( segments ) ;
160
189
eq ( actual . through , true ) ;
161
190
eq ( actual . xmin , - 140 ) ;
162
191
eq ( actual . xmax , - 130 ) ;
163
192
164
193
// horizontal rebound
165
- segments = [ { xmin : - 140 , xmax : - 140 , direction : 1 } , { xmin : - 140 , xmax : - 130 , direction : 0 } , { xmin : - 130 , xmax : - 130 , direction : - 1 } ] ;
194
+ segments = [
195
+ { xmin : - 140 , xmax : - 140 , direction : 1 } ,
196
+ { xmin : - 140 , xmax : - 130 , direction : 0 } ,
197
+ { xmin : - 130 , xmax : - 130 , direction : - 1 }
198
+ ] ;
166
199
actual = utils . categorizeIntersection ( segments ) ;
167
200
eq ( actual . through , false ) ;
168
201
eq ( actual . xmin , - 140 ) ;
169
202
eq ( actual . xmax , - 130 ) ;
170
203
171
204
// through with stop
172
- segments = [ { xmin : - 140 , xmax : - 140 , direction : 1 } , { xmin : - 140 , xmax : - 140 , direction : 1 } ] ;
205
+ segments = [
206
+ { xmin : - 140 , xmax : - 140 , direction : 1 } ,
207
+ { xmin : - 140 , xmax : - 140 , direction : 1 }
208
+ ] ;
173
209
actual = utils . categorizeIntersection ( segments ) ;
174
210
eq ( actual . through , true ) ;
175
211
eq ( actual . xmin , - 140 ) ;
@@ -178,4 +214,4 @@ test('Test Categorization of Intersections', ({ eq }) => {
178
214
179
215
test ( "get constructor names" , ( { eq } ) => {
180
216
eq ( utils . getConstructorName ( new ArrayBuffer ( ) ) , "ArrayBuffer" ) ;
181
- } )
217
+ } ) ;
0 commit comments