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

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

17 Feb 2025 08:39PM UTC coverage: 40.419% (-58.3%) from 98.718%
#49

push

Mr Martian
setup a wasm build for experimentation; main rust didnt have no_std (bug)

18 of 18 new or added lines in 3 files covered. (100.0%)

2956 existing lines in 15 files now uncovered.

2082 of 5151 relevant lines covered (40.42%)

107.98 hits per line

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

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

7
use alloc::string::String;
8
use alloc::vec::Vec;
9

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

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

UNCOV
68
        self.features.push(feature);
×
UNCOV
69
    }
×
70

71
    /// Get the feature at the given index
UNCOV
72
    pub fn feature(&self, i: usize) -> &BaseVectorFeature {
×
UNCOV
73
        &self.features[i]
×
UNCOV
74
    }
×
75

76
    /// Get the number of features
UNCOV
77
    pub fn len(&self) -> usize {
×
UNCOV
78
        self.features.len()
×
UNCOV
79
    }
×
80

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

UNCOV
99
        for feature in mvt.features.values_mut() {
×
UNCOV
100
            bvt.add_feature(feature.into());
×
UNCOV
101
        }
×
102

UNCOV
103
        bvt
×
UNCOV
104
    }
×
105
}
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