@@ -4,17 +4,27 @@ const {
44 unwrapLonRange,
55 doesCrossAntiMeridian
66} = require ( '../../../src/lib/geo_location_utils' ) ;
7+ const loggers = require ( '../../../src/lib/loggers' ) ;
8+
9+ function extractSingleFeature ( geometry ) {
10+ const trace = {
11+ _length : 1 ,
12+ geojson : { type : 'Feature' , id : 'Omicron Persei 8' , geometry }
13+ } ;
14+
15+ return extractTraceFeature ( [ { loc : 'Omicron Persei 8' , trace } ] ) [ 0 ] ;
16+ }
717
818describe ( 'Test geo_location_utils.extractTraceFeature' , ( ) => {
9- it ( 'keeps degenerate MultiPolygons without affecting valid features' , ( ) => {
19+ it ( 'keeps MultiPolygons with no positive-area polygon without affecting valid features' , ( ) => {
1020 const trace = {
1121 _length : 2 ,
1222 geojson : {
1323 type : 'FeatureCollection' ,
1424 features : [
1525 {
1626 type : 'Feature' ,
17- id : 'degenerate ' ,
27+ id : 'zero-area ' ,
1828 geometry : {
1929 type : 'MultiPolygon' ,
2030 coordinates : [
@@ -49,18 +59,71 @@ describe('Test geo_location_utils.extractTraceFeature', () => {
4959 }
5060 } ;
5161 const calcTrace = [
52- { loc : 'degenerate ' , trace } ,
62+ { loc : 'zero-area ' , trace } ,
5363 { loc : 'valid' , trace }
5464 ] ;
5565
5666 const features = extractTraceFeature ( calcTrace ) ;
5767
5868 expect ( features . length ) . toBe ( 2 ) ;
59- expect ( features [ 0 ] . id ) . toBe ( 'degenerate ' ) ;
69+ expect ( features [ 0 ] . id ) . toBe ( 'zero-area ' ) ;
6070 expect ( features [ 0 ] . properties . ct . every ( Number . isNaN ) ) . toBe ( true ) ;
6171 expect ( features [ 1 ] . id ) . toBe ( 'valid' ) ;
6272 expect ( features [ 1 ] . properties . ct . every ( Number . isFinite ) ) . toBe ( true ) ;
6373 } ) ;
74+
75+ it ( 'keeps Polygons and MultiPolygons whose rings hold no points' , ( ) => {
76+ const polygon = extractSingleFeature ( { type : 'Polygon' , coordinates : [ [ ] ] } ) ;
77+ const multiPolygon = extractSingleFeature ( { type : 'MultiPolygon' , coordinates : [ [ [ ] ] ] } ) ;
78+
79+ expect ( polygon . properties . ct . every ( Number . isNaN ) ) . toBe ( true ) ;
80+ expect ( multiPolygon . properties . ct . every ( Number . isNaN ) ) . toBe ( true ) ;
81+ } ) ;
82+
83+ it ( 'logs the locations whose centroid could not be computed' , ( ) => {
84+ spyOn ( loggers , 'log' ) ;
85+
86+ extractSingleFeature ( {
87+ type : 'MultiPolygon' ,
88+ coordinates : [
89+ [
90+ [
91+ [ 0 , 0 ] ,
92+ [ 1 , 1 ] ,
93+ [ 0 , 0 ] ,
94+ [ 0 , 0 ]
95+ ]
96+ ]
97+ ]
98+ } ) ;
99+
100+ expect ( loggers . log ) . toHaveBeenCalledWith (
101+ [
102+ 'Location Omicron Persei 8 has no polygon with positive area.' ,
103+ 'Its centroid could not be computed,' ,
104+ 'so hover and selection will not work for it.'
105+ ] . join ( ' ' )
106+ ) ;
107+ } ) ;
108+
109+ it ( 'does not log for features with a computable centroid' , ( ) => {
110+ spyOn ( loggers , 'log' ) ;
111+
112+ extractSingleFeature ( {
113+ type : 'Polygon' ,
114+ coordinates : [
115+ [
116+ [ 0 , 0 ] ,
117+ [ 0 , 1 ] ,
118+ [ 1 , 1 ] ,
119+ [ 1 , 0 ] ,
120+ [ 0 , 0 ]
121+ ]
122+ ]
123+ } ) ;
124+
125+ expect ( loggers . log ) . not . toHaveBeenCalled ( ) ;
126+ } ) ;
64127} ) ;
65128
66129describe ( 'Test geo_location_utils.getFitboundsLonRange' , ( ) => {
0 commit comments