pub type IDType = u32;
pub type LType = i64; pub type CoordType = f64;
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Tup {
pub lat: LType,
pub lon: LType,
}
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct Coord {
pub lat: CoordType,
pub lon: CoordType,
}
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct Node {
pub coord: Coord,
pub tags: Tags,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Way {
pub nodes: Vec<IDType>,
pub tags: Tags,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub enum RelationMemeberType {
Node,
Way,
Relation,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct RelationMemeber {
pub member_id: IDType,
pub member_type: RelationMemeberType,
pub role_id: IDType,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Relation {
pub tags: Tags,
pub members: Vec<RelationMemeber>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Strings {
pub strings: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Tag {
pub key: IDType,
pub val: IDType,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Tags {
pub string_table_id: IDType,
pub tags: Vec<Tag>,
}
impl Tags {
pub fn get_keys_vals<'a>(&'a self, string_table: &'a Strings) -> Vec<(&'a String, &'a String)> {
let mut kvls = Vec::with_capacity(self.tags.len());
for tag in &self.tags {
assert!(tag.key != 0);
assert!(tag.val != 0);
match string_table.strings.get(tag.key as usize) {
Some(key) => match string_table.strings.get(tag.val as usize) {
Some(value) => {
kvls.push((key, value));
}
None => println!("WARNING: failed to map tags key."),
},
None => println!("WARNING: failed to map tags value."),
}
}
kvls
}
}
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct LBox {
pub top_left: Coord,
pub bottom_right: Coord,
}
#[macro_export]
macro_rules! pbf_min {
($x:expr, $y:expr) => ( if $x < $y { $x } else { $y } );
}
#[macro_export]
macro_rules! pbf_max {
($x:expr, $y:expr) => ( if $x > $y { $x } else { $y } );
}
impl LBox {
pub fn union_with_box<'a>(mut self, other: &LBox) -> LBox {
if self.top_left.lat > other.top_left.lat {
self.top_left.lat = other.top_left.lat;
}
if self.top_left.lon > other.top_left.lon {
self.top_left.lon = other.top_left.lon;
}
if self.bottom_right.lat < other.bottom_right.lat {
self.bottom_right.lat = other.bottom_right.lat;
}
if self.bottom_right.lon < other.bottom_right.lon {
self.bottom_right.lon = other.bottom_right.lon;
}
self
}
pub fn union_with_coord<'a>(&'a mut self, other: &Coord) {
if self.top_left.lat > other.lat {
self.top_left.lat = other.lat;
}
if self.top_left.lon > other.lon {
self.top_left.lon = other.lon;
}
if self.bottom_right.lat < other.lat {
self.bottom_right.lat = other.lat;
}
if self.bottom_right.lon < other.lon {
self.bottom_right.lon = other.lon;
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct BlobPosition {
pub start: usize,
pub size: usize,
}
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct PbfInfo {
pub bbox: LBox,
pub position: BlobPosition,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PBFData {
NodesSet(Vec<(IDType, Node)>),
WaysSet(Vec<(IDType, Way)>),
RelationsSet(Vec<(IDType, Relation)>),
Strings(IDType, Strings),
PbfInfo(PbfInfo),
ParseEnd,
}