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

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

15 Aug 2024 12:44AM UTC coverage: 43.923% (+9.0%) from 34.908%
#19

push

Mr Martian
fix coveralls

2349 of 5348 relevant lines covered (43.92%)

46.88 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::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(
×
32
        name: String,
×
33
        extent: Extent,
×
34
        features: Vec<BaseVectorFeature>,
×
35
        shape: Option<Shape>,
×
36
        m_shape: Option<Shape>,
×
37
    ) -> Self {
×
38
        Self {
×
39
            version: 1,
×
40
            name,
×
41
            extent,
×
42
            shape_defined: shape.is_some(),
×
43
            m_shape_defined: m_shape.is_some(),
×
44
            shape: shape.unwrap_or_default(),
×
45
            m_shape,
×
46
            features,
×
47
        }
×
48
    }
×
49

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

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

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

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

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

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

101
        bvt
×
102
    }
×
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