• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-S2 / open-vector-tile / #27

06 Dec 2024 02:32PM UTC coverage: 98.708% (+1.3%) from 97.451%
#27

push

Mr Martian
fix coveralls

8783 of 8898 relevant lines covered (98.71%)

58.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.71
/tests/mapbox/vector_tile.rs
1
#[cfg(test)]
2
mod tests {
3
    extern crate alloc;
4
    use ovtile::{
5
        base::{
6
            BaseVectorFeature, BaseVectorLayer, BaseVectorLinesFeature, BaseVectorPointsFeature,
7
            BaseVectorPolysFeature, BaseVectorTile, VectorFeature,
8
        },
9
        mapbox::vector_tile::{write_tile, MapboxVectorTile},
10
        open::{Extent, FeatureType, Value},
11
        Point, VectorGeometry, VectorLayerMethods, VectorLineWithOffset, VectorTile,
12
    };
13

14
    use std::{
15
        fs,
16
        panic::{self, AssertUnwindSafe},
17
    };
18

19
    #[test]
20
    fn test_mapbox_vector_tile() {
1✔
21
        let mut tile = BaseVectorTile::default();
1✔
22

1✔
23
        let example_value_str = r#"{
1✔
24
            "a": 3,
1✔
25
            "b": 1,
1✔
26
            "c": 2.2
1✔
27
        }"#;
1✔
28
        let example_value = serde_json::from_str::<Value>(example_value_str).unwrap();
1✔
29
        let example_value_str_2 = r#"{
1✔
30
            "a": -2,
1✔
31
            "b": 1,
1✔
32
            "c": 2.2
1✔
33
        }"#;
1✔
34
        let example_value2 = serde_json::from_str::<Value>(example_value_str_2).unwrap();
1✔
35

1✔
36
        // POINTS //-//-//-//-//-//-//-//-//-//-//
1✔
37

1✔
38
        let mut points_layer =
1✔
39
            BaseVectorLayer::new("points".to_string(), 4096.into(), vec![], None, None);
1✔
40

1✔
41
        let feature = BaseVectorPointsFeature::new(
1✔
42
            None,
1✔
43
            vec![Point::new_with_m(0, 0, example_value2.clone())],
1✔
44
            example_value.clone(),
1✔
45
            None,
1✔
46
        );
1✔
47
        let feature2 = BaseVectorPointsFeature::new(
1✔
48
            Some(1),
1✔
49
            vec![Point::new_with_m(0, 0, example_value.clone()), Point::new(1, 1)],
1✔
50
            example_value2.clone(),
1✔
51
            None,
1✔
52
        );
1✔
53

1✔
54
        // add_features
1✔
55
        points_layer.add_feature(BaseVectorFeature::BaseVectorPointsFeature(feature));
1✔
56
        points_layer.add_feature(BaseVectorFeature::BaseVectorPointsFeature(feature2));
1✔
57

1✔
58
        tile.add_layer(points_layer);
1✔
59

1✔
60
        // LINES //-//-//-//-//-//-//-//-//-//-//
1✔
61

1✔
62
        let mut lines_layer =
1✔
63
            BaseVectorLayer::new("lines".to_string(), 2_048.into(), vec![], None, None);
1✔
64

1✔
65
        let feature3 = BaseVectorLinesFeature::new(
1✔
66
            None,
1✔
67
            vec![VectorLineWithOffset::new(
1✔
68
                0.0,
1✔
69
                vec![Point::new_with_m(0, 0, example_value2.clone())],
1✔
70
            )],
1✔
71
            example_value.clone(),
1✔
72
            None,
1✔
73
        );
1✔
74
        let feature4 = BaseVectorLinesFeature::new(
1✔
75
            Some(1),
1✔
76
            vec![
1✔
77
                VectorLineWithOffset::new(
1✔
78
                    0.0,
1✔
79
                    vec![Point::new_with_m(0, 0, example_value2.clone())],
1✔
80
                ),
1✔
81
                VectorLineWithOffset::new(0.0, vec![Point::new(2, 2), Point::new(3, 3)]),
1✔
82
            ],
1✔
83
            example_value2.clone(),
1✔
84
            None,
1✔
85
        );
1✔
86

1✔
87
        lines_layer.add_feature(BaseVectorFeature::BaseVectorLinesFeature(feature3));
1✔
88
        lines_layer.add_feature(BaseVectorFeature::BaseVectorLinesFeature(feature4));
1✔
89

1✔
90
        tile.add_layer(lines_layer);
1✔
91

1✔
92
        // POLYS //-//-//-//-//-//-//-//-//-//-//
1✔
93

1✔
94
        let mut polys_layer =
1✔
95
            BaseVectorLayer::new("polys".to_string(), 8_192.into(), vec![], None, None);
1✔
96

1✔
97
        let feature5 = BaseVectorPolysFeature::new(
1✔
98
            None,
1✔
99
            vec![vec![VectorLineWithOffset::new(
1✔
100
                0.0,
1✔
101
                vec![
1✔
102
                    Point::new_with_m(0, 0, example_value2.clone()),
1✔
103
                    Point::new(1, 1),
1✔
104
                    Point::new(2, 2),
1✔
105
                    Point::new(3, 3),
1✔
106
                    Point::new(0, 0),
1✔
107
                ],
1✔
108
            )]],
1✔
109
            example_value.clone(),
1✔
110
            None,
1✔
111
            vec![],
1✔
112
            vec![],
1✔
113
        );
1✔
114

1✔
115
        let feature6 = BaseVectorPolysFeature::new(
1✔
116
            Some(1),
1✔
117
            vec![
1✔
118
                vec![VectorLineWithOffset::new(
1✔
119
                    0.0,
1✔
120
                    vec![
1✔
121
                        Point::new_with_m(0, 0, example_value2.clone()),
1✔
122
                        Point::new(1, 1),
1✔
123
                        Point::new(2, 2),
1✔
124
                        Point::new(3, 3),
1✔
125
                        Point::new(0, 0),
1✔
126
                    ],
1✔
127
                )],
1✔
128
                vec![
1✔
129
                    VectorLineWithOffset::new(
1✔
130
                        0.0,
1✔
131
                        vec![
1✔
132
                            Point::new_with_m(0, 0, example_value2.clone()),
1✔
133
                            Point::new(1, 1),
1✔
134
                            Point::new(2, 2),
1✔
135
                            Point::new(3, 3),
1✔
136
                            Point::new(0, 0),
1✔
137
                        ],
1✔
138
                    ),
1✔
139
                    VectorLineWithOffset::new(
1✔
140
                        0.0,
1✔
141
                        vec![
1✔
142
                            Point::new(2, 2),
1✔
143
                            Point::new(3, 3),
1✔
144
                            Point::new(4, 4),
1✔
145
                            Point::new(5, 5),
1✔
146
                            Point::new(2, 2),
1✔
147
                        ],
1✔
148
                    ),
1✔
149
                ],
1✔
150
            ],
1✔
151
            example_value2.clone(),
1✔
152
            None,
1✔
153
            vec![0, 1, 2, 1, 5],
1✔
154
            vec![Point::new(10, 4), Point::new(11, 5), Point::new(12, 6)],
1✔
155
        );
1✔
156

1✔
157
        polys_layer.add_feature(BaseVectorFeature::BaseVectorPolysFeature(feature5));
1✔
158
        polys_layer.add_feature(BaseVectorFeature::BaseVectorPolysFeature(feature6));
1✔
159

1✔
160
        tile.add_layer(polys_layer);
1✔
161

1✔
162
        // convert BaseVectorLayer into MapboxVectorTile
1✔
163
        let mapbox_tile_bytes = write_tile(&mut tile);
1✔
164

1✔
165
        let mut mapbox_tile = MapboxVectorTile::new(mapbox_tile_bytes, None);
1✔
166

1✔
167
        assert_eq!(mapbox_tile.layers.len(), 3);
1✔
168

169
        // POINTS
170

171
        let m_points_layer = mapbox_tile.layer("points").unwrap();
1✔
172

1✔
173
        assert_eq!(m_points_layer.version(), 1);
1✔
174
        assert_eq!(m_points_layer.name(), "points");
1✔
175
        assert_eq!(m_points_layer.extent(), 4_096);
1✔
176

177
        assert_eq!(m_points_layer.len(), 2);
1✔
178

179
        {
180
            let m_feature = m_points_layer.feature(0).unwrap();
1✔
181
            // id
1✔
182
            assert_eq!(m_feature.id(), None);
1✔
183
            // properties
184
            assert_eq!(m_feature.properties(), example_value);
1✔
185
            // version
186
            assert_eq!(m_feature.version(), 1);
1✔
187
            // extent
188
            assert_eq!(m_feature.extent(), 4_096);
1✔
189
            // get_type
190
            assert_eq!(m_feature.get_type(), FeatureType::Points);
1✔
191
            // bbox
192
            assert_eq!(m_feature.bbox(), None);
1✔
193
            // has_m_values
194
            assert!(!m_feature.has_m_values());
1✔
195
            // is points
196
            assert!(m_feature.is_points());
1✔
197
            // is lines
198
            assert!(!m_feature.is_lines());
1✔
199
            // is polys
200
            assert!(!m_feature.is_polygons());
1✔
201
            // is points3d
202
            assert!(!m_feature.is_points_3d());
1✔
203
            // is lines3d
204
            assert!(!m_feature.is_lines_3d());
1✔
205
            // is polys3d
206
            assert!(!m_feature.is_polygons_3d());
1✔
207
            // load_points
208
            let points = m_feature.load_points();
1✔
209
            assert_eq!(points.len(), 1);
1✔
210
            assert_eq!(points, vec![Point::new(0, 0)]);
1✔
211
            // load_geometry
212
            let geometry = m_feature.load_geometry();
1✔
213
            assert_eq!(geometry, VectorGeometry::VectorPoints(vec![Point::new(0, 0)]));
1✔
214
            // load indices
215
            assert_eq!(m_feature.read_indices(), Vec::<u32>::new());
1✔
216

217
            // Test that a function panics
218
            let load_points_3d_test =
1✔
219
                panic::catch_unwind(AssertUnwindSafe(|| m_feature.load_points_3d()));
1✔
220
            assert!(load_points_3d_test.is_err());
1✔
221

222
            // load_lines
223
            let load_lines_test = panic::catch_unwind(AssertUnwindSafe(|| m_feature.load_lines()));
1✔
224
            assert!(load_lines_test.is_err());
1✔
225

226
            // load_lines_3d
227
            let load_lines_3d_test =
1✔
228
                panic::catch_unwind(AssertUnwindSafe(|| m_feature.load_lines_3d()));
1✔
229
            assert!(load_lines_3d_test.is_err());
1✔
230

231
            // load_geometry_flat
232
            let load_geometry_flat_test =
1✔
233
                panic::catch_unwind(AssertUnwindSafe(|| m_feature.load_geometry_flat()));
1✔
234
            assert!(load_geometry_flat_test.is_err());
1✔
235

236
            // add_tesselation_3d
237
            let add_tesselation_3d_test = panic::catch_unwind(AssertUnwindSafe(|| {
1✔
238
                let mut tmp_vec = vec![];
1✔
239
                m_feature.add_tesselation_3d(&mut tmp_vec, 1.);
1✔
240
            }));
1✔
241
            assert!(add_tesselation_3d_test.is_err());
1✔
242
        }
243

244
        {
245
            let m_feature = m_points_layer.feature(1).unwrap();
1✔
246
            // id
1✔
247
            assert_eq!(m_feature.id(), Some(1));
1✔
248
            // properties
249
            assert_eq!(m_feature.properties(), example_value2);
1✔
250
            // version
251
            assert_eq!(m_feature.version(), 1);
1✔
252
            // extent
253
            assert_eq!(m_feature.extent(), 4_096);
1✔
254
            // get_type
255
            assert_eq!(m_feature.get_type(), FeatureType::Points);
1✔
256
            // bbox
257
            assert_eq!(m_feature.bbox(), None);
1✔
258
            // has_m_values
259
            assert!(!m_feature.has_m_values());
1✔
260
            // is points
261
            assert!(m_feature.is_points());
1✔
262
            // is lines
263
            assert!(!m_feature.is_lines());
1✔
264
            // is polys
265
            assert!(!m_feature.is_polygons());
1✔
266
            // is points3d
267
            assert!(!m_feature.is_points_3d());
1✔
268
            // is lines3d
269
            assert!(!m_feature.is_lines_3d());
1✔
270
            // is polys3d
271
            assert!(!m_feature.is_polygons_3d());
1✔
272
            // load_points
273
            let points = m_feature.load_points();
1✔
274
            assert_eq!(points.len(), 2);
1✔
275
            assert_eq!(points, vec![Point::new(0, 0), Point::new(1, 1)]);
1✔
276
            // load_geometry
277
            let geometry = m_feature.load_geometry();
1✔
278
            assert_eq!(
1✔
279
                geometry,
1✔
280
                VectorGeometry::VectorPoints(vec![Point::new(0, 0), Point::new(1, 1)])
1✔
281
            );
1✔
282
            // load indices
283
            assert_eq!(m_feature.read_indices(), Vec::<u32>::new());
1✔
284
        }
285

286
        // LINES
287

288
        let m_lines_layer = mapbox_tile.layer("lines").unwrap();
1✔
289

1✔
290
        assert_eq!(m_lines_layer.version(), 1);
1✔
291
        assert_eq!(m_lines_layer.name(), "lines");
1✔
292
        assert_eq!(m_lines_layer.extent(), 2_048);
1✔
293

294
        assert_eq!(m_lines_layer.len(), 2);
1✔
295

296
        {
297
            let m_feature = m_lines_layer.feature(0).unwrap();
1✔
298
            // id
1✔
299
            assert_eq!(m_feature.id(), None);
1✔
300
            // properties
301
            assert_eq!(m_feature.properties(), example_value);
1✔
302
            // version
303
            assert_eq!(m_feature.version(), 1);
1✔
304
            // extent
305
            assert_eq!(m_feature.extent(), 2_048);
1✔
306
            // get_type
307
            assert_eq!(m_feature.get_type(), FeatureType::Lines);
1✔
308
            // bbox
309
            assert_eq!(m_feature.bbox(), None);
1✔
310
            // has_m_values
311
            assert!(!m_feature.has_m_values());
1✔
312
            // is points
313
            assert!(!m_feature.is_points());
1✔
314
            // is lines
315
            assert!(m_feature.is_lines());
1✔
316
            // is polys
317
            assert!(!m_feature.is_polygons());
1✔
318
            // is points3d
319
            assert!(!m_feature.is_points_3d());
1✔
320
            // is lines3d
321
            assert!(!m_feature.is_lines_3d());
1✔
322
            // is polys3d
323
            assert!(!m_feature.is_polygons_3d());
1✔
324
            // load_points
325
            let points = m_feature.load_points();
1✔
326
            assert_eq!(points.len(), 1);
1✔
327
            assert_eq!(points, vec![Point::new(0, 0)]);
1✔
328
            // load_geometry
329
            let geometry = m_feature.load_geometry();
1✔
330
            assert_eq!(
1✔
331
                geometry,
1✔
332
                VectorGeometry::VectorLines(vec![VectorLineWithOffset::new(
1✔
333
                    0.0,
1✔
334
                    vec![Point::new(0, 0)],
1✔
335
                )]),
1✔
336
            );
1✔
337
            // load lines
338
            let lines = m_feature.load_lines();
1✔
339
            assert_eq!(lines.len(), 1);
1✔
340
            assert_eq!(lines, vec![VectorLineWithOffset::new(0.0, vec![Point::new(0, 0)])],);
1✔
341
            // load indices
342
            assert_eq!(m_feature.read_indices(), Vec::<u32>::new());
1✔
343
        }
344
        {
345
            let m_feature = m_lines_layer.feature(1).unwrap();
1✔
346
            // id
1✔
347
            assert_eq!(m_feature.id(), Some(1));
1✔
348
            // properties
349
            assert_eq!(m_feature.properties(), example_value2);
1✔
350
            // version
351
            assert_eq!(m_feature.version(), 1);
1✔
352
            // extent
353
            assert_eq!(m_feature.extent(), 2_048);
1✔
354
            // get_type
355
            assert_eq!(m_feature.get_type(), FeatureType::Lines);
1✔
356
            // bbox
357
            assert_eq!(m_feature.bbox(), None);
1✔
358
            // has_m_values
359
            assert!(!m_feature.has_m_values());
1✔
360
            // is points
361
            assert!(!m_feature.is_points());
1✔
362
            // is lines
363
            assert!(m_feature.is_lines());
1✔
364
            // is polys
365
            assert!(!m_feature.is_polygons());
1✔
366
            // is points3d
367
            assert!(!m_feature.is_points_3d());
1✔
368
            // is lines3d
369
            assert!(!m_feature.is_lines_3d());
1✔
370
            // is polys3d
371
            assert!(!m_feature.is_polygons_3d());
1✔
372
            // load_points
373
            let points = m_feature.load_points();
1✔
374
            assert_eq!(points.len(), 3);
1✔
375
            assert_eq!(points, vec![Point::new(0, 0), Point::new(2, 2), Point::new(3, 3)]);
1✔
376
            // load_geometry
377
            let geometry = m_feature.load_geometry();
1✔
378
            assert_eq!(
1✔
379
                geometry,
1✔
380
                VectorGeometry::VectorLines(vec![
1✔
381
                    VectorLineWithOffset::new(0.0, vec![Point::new(0, 0)]),
1✔
382
                    VectorLineWithOffset::new(0.0, vec![Point::new(2, 2), Point::new(3, 3)]),
1✔
383
                ]),
1✔
384
            );
1✔
385
            // load lines
386
            let lines = m_feature.load_lines();
1✔
387
            assert_eq!(lines.len(), 2);
1✔
388
            assert_eq!(
1✔
389
                lines,
1✔
390
                vec![
1✔
391
                    VectorLineWithOffset::new(0.0, vec![Point::new(0, 0)],),
1✔
392
                    VectorLineWithOffset::new(0.0, vec![Point::new(2, 2), Point::new(3, 3)]),
1✔
393
                ],
1✔
394
            );
1✔
395
            // load indices
396
            assert_eq!(m_feature.read_indices(), Vec::<u32>::new());
1✔
397
        }
398

399
        // POLYGONS
400

401
        let m_polygons_layer = mapbox_tile.layer("polys").unwrap();
1✔
402

1✔
403
        assert_eq!(m_polygons_layer.version(), 1);
1✔
404
        assert_eq!(m_polygons_layer.name(), "polys");
1✔
405
        assert_eq!(m_polygons_layer.extent(), 8_192);
1✔
406

407
        assert_eq!(m_polygons_layer.len(), 2);
1✔
408

409
        {
410
            let m_feature = m_polygons_layer.feature(0).unwrap();
1✔
411
            // id
1✔
412
            assert_eq!(m_feature.id(), None);
1✔
413
            // properties
414
            assert_eq!(m_feature.properties(), example_value);
1✔
415
            // version
416
            assert_eq!(m_feature.version(), 1);
1✔
417
            // extent
418
            assert_eq!(m_feature.extent(), 8_192);
1✔
419
            // get_type
420
            assert_eq!(m_feature.get_type(), FeatureType::Polygons);
1✔
421
            // bbox
422
            assert_eq!(m_feature.bbox(), None);
1✔
423
            // has_m_values
424
            assert!(!m_feature.has_m_values());
1✔
425
            // is points
426
            assert!(!m_feature.is_points());
1✔
427
            // is lines
428
            assert!(!m_feature.is_lines());
1✔
429
            // is polys
430
            assert!(m_feature.is_polygons());
1✔
431
            // is points3d
432
            assert!(!m_feature.is_points_3d());
1✔
433
            // is lines3d
434
            assert!(!m_feature.is_lines_3d());
1✔
435
            // is polys3d
436
            assert!(!m_feature.is_polygons_3d());
1✔
437
            // load_points
438
            let points = m_feature.load_points();
1✔
439
            assert_eq!(points.len(), 4);
1✔
440
            assert_eq!(
1✔
441
                points,
1✔
442
                vec![Point::new(0, 0), Point::new(1, 1), Point::new(2, 2), Point::new(3, 3),]
1✔
443
            );
1✔
444
            // load_geometry
445
            let geometry = m_feature.load_geometry();
1✔
446
            assert_eq!(
1✔
447
                geometry,
1✔
448
                VectorGeometry::VectorPolys(vec![vec![VectorLineWithOffset::new(
1✔
449
                    0.0,
1✔
450
                    vec![
1✔
451
                        Point::new(0, 0),
1✔
452
                        Point::new(1, 1),
1✔
453
                        Point::new(2, 2),
1✔
454
                        Point::new(3, 3),
1✔
455
                        Point::new(0, 0),
1✔
456
                    ],
1✔
457
                )]]),
1✔
458
            );
1✔
459
            // load lines
460
            let lines = m_feature.load_lines();
1✔
461
            assert_eq!(lines.len(), 1);
1✔
462
            assert_eq!(
1✔
463
                lines,
1✔
464
                vec![VectorLineWithOffset::new(
1✔
465
                    0.0,
1✔
466
                    vec![
1✔
467
                        Point::new(0, 0),
1✔
468
                        Point::new(1, 1),
1✔
469
                        Point::new(2, 2),
1✔
470
                        Point::new(3, 3),
1✔
471
                        Point::new(0, 0)
1✔
472
                    ]
1✔
473
                )],
1✔
474
            );
1✔
475
            // load indices
476
            assert_eq!(m_feature.read_indices(), Vec::<u32>::new());
1✔
477
            // load tessellations
478
            let mut tess = vec![];
1✔
479
            m_feature.add_tesselation(&mut tess, 1.0 / 8_192.0);
1✔
480
            assert_eq!(tess, Vec::<f64>::new());
1✔
481

482
            // load_geometry_flat
483
            let (geometry_flat, indices) = m_feature.load_geometry_flat();
1✔
484
            assert_eq!(indices, Vec::<u32>::new());
1✔
485
            assert_eq!(
1✔
486
                geometry_flat,
1✔
487
                vec![
1✔
488
                    0.0,
1✔
489
                    0.0,
1✔
490
                    0.0001220703125,
1✔
491
                    0.0001220703125,
1✔
492
                    0.000244140625,
1✔
493
                    0.000244140625,
1✔
494
                    0.0003662109375,
1✔
495
                    0.0003662109375,
1✔
496
                    0.0,
1✔
497
                    0.0
1✔
498
                ]
1✔
499
            );
1✔
500
        }
501
        {
502
            let m_feature = m_polygons_layer.feature(1).unwrap();
1✔
503
            // id
1✔
504
            assert_eq!(m_feature.id(), Some(1));
1✔
505
            // properties
506
            assert_eq!(m_feature.properties(), example_value2);
1✔
507
            // version
508
            assert_eq!(m_feature.version(), 1);
1✔
509
            // extent
510
            assert_eq!(m_feature.extent(), 8_192);
1✔
511
            // get_type
512
            assert_eq!(m_feature.get_type(), FeatureType::Polygons);
1✔
513
            // bbox
514
            assert_eq!(m_feature.bbox(), None);
1✔
515
            // has_m_values
516
            assert!(!m_feature.has_m_values());
1✔
517
            // is points
518
            assert!(!m_feature.is_points());
1✔
519
            // is lines
520
            assert!(!m_feature.is_lines());
1✔
521
            // is polys
522
            assert!(m_feature.is_polygons());
1✔
523
            // is points3d
524
            assert!(!m_feature.is_points_3d());
1✔
525
            // is lines3d
526
            assert!(!m_feature.is_lines_3d());
1✔
527
            // is polys3d
528
            assert!(!m_feature.is_polygons_3d());
1✔
529
            // load_points
530
            let points = m_feature.load_points();
1✔
531
            assert_eq!(points.len(), 12);
1✔
532
            assert_eq!(
1✔
533
                points,
1✔
534
                vec![
1✔
535
                    Point::new(0, 0),
1✔
536
                    Point::new(1, 1),
1✔
537
                    Point::new(2, 2),
1✔
538
                    Point::new(3, 3),
1✔
539
                    Point::new(0, 0),
1✔
540
                    Point::new(1, 1),
1✔
541
                    Point::new(2, 2),
1✔
542
                    Point::new(3, 3),
1✔
543
                    Point::new(2, 2),
1✔
544
                    Point::new(3, 3),
1✔
545
                    Point::new(4, 4),
1✔
546
                    Point::new(5, 5),
1✔
547
                ]
1✔
548
            );
1✔
549
            // load_geometry
550
            let geometry = m_feature.load_geometry();
1✔
551
            assert_eq!(
1✔
552
                geometry,
1✔
553
                VectorGeometry::VectorPolys(vec![
1✔
554
                    vec![VectorLineWithOffset::new(
1✔
555
                        0.0,
1✔
556
                        vec![
1✔
557
                            Point::new(0, 0),
1✔
558
                            Point::new(1, 1),
1✔
559
                            Point::new(2, 2),
1✔
560
                            Point::new(3, 3),
1✔
561
                            Point::new(0, 0),
1✔
562
                        ],
1✔
563
                    )],
1✔
564
                    vec![
1✔
565
                        VectorLineWithOffset::new(
1✔
566
                            0.0,
1✔
567
                            vec![
1✔
568
                                Point::new(0, 0),
1✔
569
                                Point::new(1, 1),
1✔
570
                                Point::new(2, 2),
1✔
571
                                Point::new(3, 3),
1✔
572
                                Point::new(0, 0),
1✔
573
                            ],
1✔
574
                        ),
1✔
575
                        VectorLineWithOffset::new(
1✔
576
                            0.0,
1✔
577
                            vec![
1✔
578
                                Point::new(2, 2),
1✔
579
                                Point::new(3, 3),
1✔
580
                                Point::new(4, 4),
1✔
581
                                Point::new(5, 5),
1✔
582
                                Point::new(2, 2),
1✔
583
                            ],
1✔
584
                        ),
1✔
585
                    ],
1✔
586
                ]),
1✔
587
            );
1✔
588
            // load lines
589
            let lines = m_feature.load_lines();
1✔
590
            assert_eq!(lines.len(), 3);
1✔
591
            assert_eq!(
1✔
592
                lines,
1✔
593
                vec![
1✔
594
                    VectorLineWithOffset::new(
1✔
595
                        0.0,
1✔
596
                        vec![
1✔
597
                            Point::new(0, 0),
1✔
598
                            Point::new(1, 1),
1✔
599
                            Point::new(2, 2),
1✔
600
                            Point::new(3, 3),
1✔
601
                            Point::new(0, 0),
1✔
602
                        ]
1✔
603
                    ),
1✔
604
                    VectorLineWithOffset::new(
1✔
605
                        0.0,
1✔
606
                        vec![
1✔
607
                            Point::new(0, 0),
1✔
608
                            Point::new(1, 1),
1✔
609
                            Point::new(2, 2),
1✔
610
                            Point::new(3, 3),
1✔
611
                            Point::new(0, 0),
1✔
612
                        ]
1✔
613
                    ),
1✔
614
                    VectorLineWithOffset::new(
1✔
615
                        0.0,
1✔
616
                        vec![
1✔
617
                            Point::new(2, 2),
1✔
618
                            Point::new(3, 3),
1✔
619
                            Point::new(4, 4),
1✔
620
                            Point::new(5, 5),
1✔
621
                            Point::new(2, 2),
1✔
622
                        ]
1✔
623
                    ),
1✔
624
                ],
1✔
625
            );
1✔
626
            // load indices
627
            assert_eq!(m_feature.read_indices(), vec![0, 1, 2, 1, 5]);
1✔
628
            // load tessellations
629
            let mut tess = vec![];
1✔
630
            m_feature.add_tesselation(&mut tess, 1.0);
1✔
631
            assert_eq!(tess, vec![10.0, 4.0, 11.0, 5.0, 12.0, 6.0]);
1✔
632

633
            // load_geometry_flat
634
            let (geometry_flat, indices) = m_feature.load_geometry_flat();
1✔
635
            assert_eq!(indices, vec![0, 1, 2, 1, 5]);
1✔
636
            assert_eq!(
1✔
637
                geometry_flat,
1✔
638
                vec![
1✔
639
                    0.0,
1✔
640
                    0.0,
1✔
641
                    0.0001220703125,
1✔
642
                    0.0001220703125,
1✔
643
                    0.000244140625,
1✔
644
                    0.000244140625,
1✔
645
                    0.0003662109375,
1✔
646
                    0.0003662109375,
1✔
647
                    0.0,
1✔
648
                    0.0,
1✔
649
                    0.0,
1✔
650
                    0.0,
1✔
651
                    0.0001220703125,
1✔
652
                    0.0001220703125,
1✔
653
                    0.000244140625,
1✔
654
                    0.000244140625,
1✔
655
                    0.0003662109375,
1✔
656
                    0.0003662109375,
1✔
657
                    0.0,
1✔
658
                    0.0,
1✔
659
                    0.000244140625,
1✔
660
                    0.000244140625,
1✔
661
                    0.0003662109375,
1✔
662
                    0.0003662109375,
1✔
663
                    0.00048828125,
1✔
664
                    0.00048828125,
1✔
665
                    0.0006103515625,
1✔
666
                    0.0006103515625,
1✔
667
                    0.000244140625,
1✔
668
                    0.000244140625,
1✔
669
                    0.001220703125,
1✔
670
                    0.00048828125,
1✔
671
                    0.0013427734375,
1✔
672
                    0.0006103515625,
1✔
673
                    0.00146484375,
1✔
674
                    0.000732421875
1✔
675
                ]
1✔
676
            );
1✔
677
        }
678
    }
1✔
679

680
    #[test]
681
    fn test_parse_file() {
1✔
682
        let data = fs::read("./tests/fixtures/multi-point.pbf").unwrap();
1✔
683
        let mut tile = MapboxVectorTile::new(data, None);
1✔
684
        assert_eq!(tile.layers.len(), 1);
1✔
685

686
        let geojson_layer = tile.layer("geojson").unwrap();
1✔
687
        assert_eq!(geojson_layer.version(), 2);
1✔
688
        assert_eq!(geojson_layer.name(), "geojson");
1✔
689
        assert_eq!(geojson_layer.extent(), 4_096);
1✔
690
        assert_eq!(geojson_layer.len(), 1);
1✔
691
        assert!(!geojson_layer.is_empty());
1✔
692

693
        let geojson_feature = geojson_layer.feature(0).unwrap();
1✔
694
        let geojson_geometry = geojson_feature.load_geometry();
1✔
695
        assert_eq!(
1✔
696
            geojson_geometry,
1✔
697
            VectorGeometry::VectorPoints(vec![Point::new(2059, 2025), Point::new(2082, 2002)])
1✔
698
        );
1✔
699
    }
1✔
700

701
    #[test]
702
    fn test_parse_file_vector_tile() {
1✔
703
        let data = fs::read("./tests/fixtures/multi-point.pbf").unwrap();
1✔
704
        let mut tile = VectorTile::new(data, None);
1✔
705
        assert_eq!(tile.layers.len(), 1);
1✔
706

707
        let geojson_layer = tile.layer("geojson").unwrap();
1✔
708
        assert_eq!(geojson_layer.version(), 2);
1✔
709
        assert_eq!(geojson_layer.name(), "geojson");
1✔
710
        assert_eq!(geojson_layer.extent(), 4_096);
1✔
711
        assert_eq!(geojson_layer.len(), 1);
1✔
712
        assert!(!geojson_layer.is_empty());
1✔
713

714
        let geojson_feature = geojson_layer.feature(0).unwrap();
1✔
715
        let geojson_geometry = geojson_feature.load_geometry();
1✔
716
        assert_eq!(
1✔
717
            geojson_geometry,
1✔
718
            VectorGeometry::VectorPoints(vec![Point::new(2059, 2025), Point::new(2082, 2002)])
1✔
719
        );
1✔
720
    }
1✔
721

722
    #[test]
723
    fn test_issue_60_file() {
1✔
724
        // https://github.com/mapbox/vector-tile-js/issues/60
1✔
725
        let data = fs::read("./tests/fixtures/multipolygon-with-closepath.pbf").unwrap();
1✔
726
        let mut tile = MapboxVectorTile::new(data, None);
1✔
727
        assert_eq!(tile.layers.len(), 1);
1✔
728

729
        let layer = tile.layer("geojsonLayer").unwrap();
1✔
730

1✔
731
        let len = layer.len();
1✔
732
        for i in 0..len {
1✔
733
            let feature = layer.feature(i).unwrap();
1✔
734
            feature.load_geometry();
1✔
735
        }
1✔
736
    }
1✔
737

738
    #[test]
739
    fn test_issue_60_file_vector_tile() {
1✔
740
        // https://github.com/mapbox/vector-tile-js/issues/60
1✔
741
        let data = fs::read("./tests/fixtures/multipolygon-with-closepath.pbf").unwrap();
1✔
742
        let mut tile = VectorTile::new(data, None);
1✔
743
        assert_eq!(tile.layers.len(), 1);
1✔
744

745
        let layer = tile.layer("geojsonLayer").unwrap();
1✔
746

1✔
747
        let len = layer.len();
1✔
748
        for i in 0..len {
1✔
749
            let feature = layer.feature(i).unwrap();
1✔
750
            feature.load_geometry();
1✔
751
        }
1✔
752
    }
1✔
753

754
    #[test]
755
    fn test_parse_file_multi_polygon() {
1✔
756
        let data = fs::read("./tests/fixtures/multipolygon-with-closepath.pbf").unwrap();
1✔
757
        let mut tile = MapboxVectorTile::new(data, None);
1✔
758
        assert_eq!(tile.layers.len(), 1);
1✔
759

760
        let geojson_layer = tile.layer("geojsonLayer").unwrap();
1✔
761
        assert_eq!(geojson_layer.version(), 1);
1✔
762
        assert_eq!(geojson_layer.name(), "geojsonLayer");
1✔
763
        assert_eq!(geojson_layer.extent(), 4_096);
1✔
764
        assert_eq!(geojson_layer.len(), 1);
1✔
765

766
        let geojson_feature = geojson_layer.feature(0).unwrap();
1✔
767
        let geojson_geometry = geojson_feature.load_geometry();
1✔
768
        assert_eq!(
1✔
769
            geojson_geometry,
1✔
770
            VectorGeometry::VectorPolys(vec![
1✔
771
                vec![VectorLineWithOffset {
1✔
772
                    offset: 0.0,
1✔
773
                    geometry: vec![
1✔
774
                        Point::new(1707, 1690),
1✔
775
                        Point::new(2390, 1690),
1✔
776
                        Point::new(2390, 2406),
1✔
777
                        Point::new(1707, 2406),
1✔
778
                        Point::new(1707, 1690),
1✔
779
                    ],
1✔
780
                },],
1✔
781
                vec![VectorLineWithOffset {
1✔
782
                    offset: 0.0,
1✔
783
                    geometry: vec![
1✔
784
                        Point::new(1878, 1876),
1✔
785
                        Point::new(2219, 1876),
1✔
786
                        Point::new(2219, 2221),
1✔
787
                        Point::new(1878, 2221),
1✔
788
                        Point::new(1878, 1876),
1✔
789
                    ],
1✔
790
                },],
1✔
791
            ])
1✔
792
        );
1✔
793

794
        let base_tile = BaseVectorTile::from(&mut tile);
1✔
795
        assert_eq!(base_tile.layers.len(), 1);
1✔
796
        assert_eq!(base_tile.layers.get("geojsonLayer").unwrap().len(), 1);
1✔
797

798
        let geojson_layer = base_tile.layers.get("geojsonLayer").unwrap();
1✔
799
        assert_eq!(geojson_layer.version, 1);
1✔
800
        assert_eq!(geojson_layer.name, "geojsonLayer");
1✔
801
        assert_eq!(geojson_layer.extent, Extent::Extent4096);
1✔
802
        assert_eq!(geojson_layer.len(), 1);
1✔
803

804
        let geojson_feature = geojson_layer.feature(0);
1✔
805
        // extract BaseVectorPolysFeature
1✔
806
        match geojson_feature {
1✔
807
            BaseVectorFeature::BaseVectorPolysFeature(feature) => {
1✔
808
                assert_eq!(feature.load_geometry(), geojson_geometry);
1✔
809
            }
810
            _ => panic!("expected BaseVectorPolysFeature"),
×
811
        }
812
    }
1✔
813

814
    #[test]
815
    fn test_parse_file_multi_polygon_vector_tile() {
1✔
816
        let data = fs::read("./tests/fixtures/multipolygon-with-closepath.pbf").unwrap();
1✔
817
        let mut tile = VectorTile::new(data, None);
1✔
818
        assert_eq!(tile.layers.len(), 1);
1✔
819

820
        let geojson_layer = tile.layer("geojsonLayer").unwrap();
1✔
821
        assert_eq!(geojson_layer.version(), 1);
1✔
822
        assert_eq!(geojson_layer.name(), "geojsonLayer");
1✔
823
        assert_eq!(geojson_layer.extent(), 4_096);
1✔
824
        assert_eq!(geojson_layer.len(), 1);
1✔
825

826
        let geojson_feature = geojson_layer.feature(0).unwrap();
1✔
827
        let geojson_geometry = geojson_feature.load_geometry();
1✔
828
        assert_eq!(
1✔
829
            geojson_geometry,
1✔
830
            VectorGeometry::VectorPolys(vec![
1✔
831
                vec![VectorLineWithOffset {
1✔
832
                    offset: 0.0,
1✔
833
                    geometry: vec![
1✔
834
                        Point::new(1707, 1690),
1✔
835
                        Point::new(2390, 1690),
1✔
836
                        Point::new(2390, 2406),
1✔
837
                        Point::new(1707, 2406),
1✔
838
                        Point::new(1707, 1690),
1✔
839
                    ],
1✔
840
                },],
1✔
841
                vec![VectorLineWithOffset {
1✔
842
                    offset: 0.0,
1✔
843
                    geometry: vec![
1✔
844
                        Point::new(1878, 1876),
1✔
845
                        Point::new(2219, 1876),
1✔
846
                        Point::new(2219, 2221),
1✔
847
                        Point::new(1878, 2221),
1✔
848
                        Point::new(1878, 1876),
1✔
849
                    ],
1✔
850
                },],
1✔
851
            ])
1✔
852
        );
1✔
853

854
        let base_tile = BaseVectorTile::from(&mut tile);
1✔
855
        assert_eq!(base_tile.layers.len(), 1);
1✔
856
        assert_eq!(base_tile.layers.get("geojsonLayer").unwrap().len(), 1);
1✔
857

858
        let geojson_layer = base_tile.layers.get("geojsonLayer").unwrap();
1✔
859
        assert_eq!(geojson_layer.version, 1);
1✔
860
        assert_eq!(geojson_layer.name, "geojsonLayer");
1✔
861
        assert_eq!(geojson_layer.extent, Extent::Extent4096);
1✔
862
        assert_eq!(geojson_layer.len(), 1);
1✔
863

864
        let geojson_feature = geojson_layer.feature(0);
1✔
865
        // extract BaseVectorPolysFeature
1✔
866
        match geojson_feature {
1✔
867
            BaseVectorFeature::BaseVectorPolysFeature(feature) => {
1✔
868
                assert_eq!(feature.load_geometry(), geojson_geometry);
1✔
869
            }
870
            _ => panic!("expected BaseVectorPolysFeature"),
×
871
        }
872
    }
1✔
873
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc