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

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

10 Sep 2024 04:56AM UTC coverage: 98.024% (-0.6%) from 98.575%
#21

push

Mr Martian
support conversion from s2json-spec; 3D-Terrain storage added

127 of 179 new or added lines in 19 files covered. (70.95%)

1 existing line in 1 file now uncovered.

8929 of 9109 relevant lines covered (98.02%)

61.56 hits per line

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

0.0
/rust/open/elevation_data.rs
1
use alloc::vec::Vec;
2

3
use crate::{delta_decode_array, delta_encode_array, open::Extent};
4

5
use libm::round;
6
use pbf::{ProtoRead, ProtoWrite, Protobuf};
7

8
/// Elevation object to read from
9
#[derive(Default, Debug)]
10
pub struct ElevationData {
11
    data: Vec<f64>,
12
    extent: Extent,
13
    size: f64,
14
    min: f64,
15
    max: f64,
16
}
17
impl ProtoRead for ElevationData {
NEW
18
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
×
NEW
19
        match tag {
×
NEW
20
            0 => self.extent = pb.read_varint(),
×
NEW
21
            1 => self.size = pb.read_varint(),
×
NEW
22
            2 => self.min = pb.read_varint(),
×
NEW
23
            3 => self.max = pb.read_varint(),
×
24
            4 => {
NEW
25
                self.data = delta_decode_array(&pb.read_packed())
×
NEW
26
                    .into_iter()
×
NEW
27
                    .map(|v| unmap_value(v as f64, self.min, self.max, self.extent.into()))
×
NEW
28
                    .collect()
×
29
            }
NEW
30
            _ => panic!("unknown tag: {}", tag),
×
31
        }
NEW
32
    }
×
33
}
34
impl ProtoWrite for ElevationData {
NEW
35
    fn write(&self, pb: &mut Protobuf) {
×
NEW
36
        let max = self.data.iter().fold(0.0, |a, b| f64::max(a, *b));
×
NEW
37
        let min = self.data.iter().fold(0.0, |a, b| f64::min(a, *b));
×
NEW
38
        let re_mapped: Vec<u32> = self
×
NEW
39
            .data
×
NEW
40
            .iter()
×
NEW
41
            .map(|v| remap_value(*v, min, max, self.extent.into()))
×
NEW
42
            .collect();
×
NEW
43
        let d_coded = delta_encode_array(&re_mapped);
×
NEW
44

×
NEW
45
        pb.write_varint_field(0, self.extent);
×
NEW
46
        pb.write_varint_field(1, self.size);
×
NEW
47
        pb.write_varint_field(2, min);
×
NEW
48
        pb.write_varint_field(3, max);
×
NEW
49
        pb.write_packed_varint(4, &d_coded);
×
NEW
50
    }
×
51
}
52

53
/// map the value to the range 0->extent
NEW
54
fn remap_value(value: f64, min: f64, max: f64, extent: f64) -> u32 {
×
NEW
55
    round(((value - min) * extent) / (max - min)) as u32
×
NEW
56
}
×
57

58
/// map the value back to floats
NEW
59
fn unmap_value(value: f64, min: f64, max: f64, extent: f64) -> f64 {
×
NEW
60
    (value * (max - min)) / extent + min
×
NEW
61
}
×
62

63
/// convert rgb to elevation using terrarium formula
NEW
64
pub fn convert_terrarium_elevation_data(r: u8, g: u8, b: u8) -> f64 {
×
NEW
65
    r as f64 * 256. + g as f64 + b as f64 / 256. - 32768.
×
NEW
66
}
×
67

68
/// convert rgb to elevation using mapbox formula
NEW
69
pub fn convert_mapbox_elevation_data(r: u8, g: u8, b: u8) -> f64 {
×
NEW
70
    -10000. + (r as f64 * 256. * 256. + g as f64 * 256. + b as f64) * 0.1
×
NEW
71
}
×
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