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

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

15 Aug 2024 12:39AM UTC coverage: 34.908% (+7.3%) from 27.612%
#18

push

Mr Martian
mistakes were made (writeTile was correct prior)

1 of 1 new or added line in 1 file covered. (100.0%)

59 existing lines in 5 files now uncovered.

14761 of 42285 relevant lines covered (34.91%)

110.8 hits per line

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

98.28
/rust/base/vector_layer.rs
1
use crate::base::BaseVectorFeature;
2
use crate::mapbox::MapboxVectorLayer;
3
use crate::open::{Extent, Shape};
4

5
use alloc::string::String;
6
use alloc::vec::Vec;
7

8
/// Base Vector Layer
9
/// This is an intermediary for storing layer data in the Open Vector Tile format.
10
#[derive(Debug)]
11
pub struct BaseVectorLayer {
12
    /// the version of the vector tile. This is a number that tracks the OVT specification. and shouldn't be tampered with
13
    pub version: u8,
14
    /// the name of the layer
15
    pub name: String,
16
    /// the extent of the vector tile (only **512**, **1_024**, **2_048**, **4_096**, and **8_192** are supported)
17
    pub extent: Extent,
18
    /// if the shape was already passed in to the constructor
19
    pub shape_defined: bool,
20
    /// if the M-Shape was already passed in to the constructor
21
    pub m_shape_defined: bool,
22
    /// The shape used to describe the features properties in the layer
23
    pub shape: Shape,
24
    /// the shape of each feature's M-Values
25
    pub m_shape: Option<Shape>,
26
    /// the features in the layer
27
    pub features: Vec<BaseVectorFeature>,
28
}
29
impl BaseVectorLayer {
30
    /// Create a new BaseVectorLayer
31
    pub fn new(
33✔
32
        name: String,
33✔
33
        extent: Extent,
33✔
34
        features: Vec<BaseVectorFeature>,
33✔
35
        shape: Option<Shape>,
33✔
36
        m_shape: Option<Shape>,
33✔
37
    ) -> Self {
33✔
38
        Self {
33✔
39
            version: 1,
33✔
40
            name,
33✔
41
            extent,
33✔
42
            shape_defined: shape.is_some(),
33✔
43
            m_shape_defined: m_shape.is_some(),
33✔
44
            shape: shape.unwrap_or_default(),
33✔
45
            m_shape,
33✔
46
            features,
33✔
47
        }
33✔
48
    }
33✔
49

50
    /// Add a new feature to the layer
51
    pub fn add_feature(&mut self, feature: BaseVectorFeature) {
72✔
52
        if !self.shape_defined {
72✔
53
            let prop_shape = (feature.properties()).clone().into();
72✔
54
            self.shape.merge(&prop_shape);
72✔
55
        }
72✔
56
        if !self.m_shape_defined {
72✔
57
            if let Some(m_values) = feature.m_values() {
72✔
58
                let feature_shape: Shape = (&m_values[..]).into();
66✔
59
                match self.m_shape {
66✔
60
                    Some(ref mut m_shape) => m_shape.merge(&feature_shape),
33✔
61
                    None => self.m_shape = Some(feature_shape),
33✔
62
                }
63
            }
6✔
UNCOV
64
        }
×
65

66
        self.features.push(feature);
72✔
67
    }
72✔
68

69
    /// Get the feature at the given index
70
    pub fn feature(&self, i: usize) -> &BaseVectorFeature {
9✔
71
        &self.features[i]
9✔
72
    }
9✔
73

74
    /// Get the number of features
75
    pub fn len(&self) -> usize {
15✔
76
        self.features.len()
15✔
77
    }
15✔
78

79
    /// Check if the layer is empty
80
    pub fn is_empty(&self) -> bool {
6✔
81
        self.features.is_empty()
6✔
82
    }
6✔
83
}
84
impl From<&mut MapboxVectorLayer> for BaseVectorLayer {
85
    fn from(mvt: &mut MapboxVectorLayer) -> Self {
6✔
86
        let mut bvt = Self {
6✔
87
            version: 1,
6✔
88
            name: mvt.name.clone(),
6✔
89
            extent: mvt.extent.into(),
6✔
90
            shape_defined: false,
6✔
91
            m_shape_defined: false,
6✔
92
            shape: Shape::default(),
6✔
93
            m_shape: None,
6✔
94
            features: Vec::new(),
6✔
95
        };
6✔
96

97
        for feature in mvt.features.values_mut() {
6✔
98
            bvt.add_feature(feature.into());
6✔
99
        }
6✔
100

101
        bvt
6✔
102
    }
6✔
103
}
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