Skip to content

Commit 8f5a852

Browse files
committed
Remove unnecessary int -> double -> int conversion in PBF output
1 parent e970573 commit 8f5a852

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

include/osmium/io/detail/pbf_output_format.hpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ namespace osmium {
129129
max_entities_per_block = 8000
130130
};
131131

132-
enum {
133-
location_granularity = 100
134-
};
135-
136-
/**
137-
* convert a double lat or lon value to an int, respecting the granularity
138-
*/
139-
inline int64_t lonlat2int(double lonlat) {
140-
return static_cast<int64_t>(std::round(lonlat * lonlat_resolution / location_granularity));
141-
}
142-
143132
enum class pbf_blob_type {
144133
header = 0,
145134
data = 1
@@ -232,8 +221,8 @@ namespace osmium {
232221
m_visibles.push_back(node.visible());
233222
}
234223

235-
m_lats.push_back(m_delta_lat.update(lonlat2int(node.location().lat_without_check())));
236-
m_lons.push_back(m_delta_lon.update(lonlat2int(node.location().lon_without_check())));
224+
m_lats.push_back(m_delta_lat.update(node.location().y()));
225+
m_lons.push_back(m_delta_lon.update(node.location().x()));
237226

238227
for (const auto& tag : node.tags()) {
239228
m_tags.push_back(m_stringtable->add(tag.key()));
@@ -700,8 +689,8 @@ namespace osmium {
700689
pbf_node.add_sint64(OSMFormat::Node::required_sint64_id, node.id());
701690
add_meta(node, pbf_node);
702691

703-
pbf_node.add_sint64(OSMFormat::Node::required_sint64_lat, lonlat2int(node.location().lat_without_check()));
704-
pbf_node.add_sint64(OSMFormat::Node::required_sint64_lon, lonlat2int(node.location().lon_without_check()));
692+
pbf_node.add_sint64(OSMFormat::Node::required_sint64_lat, node.location().y());
693+
pbf_node.add_sint64(OSMFormat::Node::required_sint64_lon, node.location().x());
705694
}
706695

707696
void way(const osmium::Way& way) {
@@ -724,14 +713,14 @@ namespace osmium {
724713
osmium::DeltaEncode<int64_t, int64_t> delta_id;
725714
protozero::packed_field_sint64 field{pbf_way, protozero::pbf_tag_type(OSMFormat::Way::packed_sint64_lon)};
726715
for (const auto& node_ref : way.nodes()) {
727-
field.add_element(delta_id.update(lonlat2int(node_ref.location().lon_without_check())));
716+
field.add_element(delta_id.update(node_ref.location().x()));
728717
}
729718
}
730719
{
731720
osmium::DeltaEncode<int64_t, int64_t> delta_id;
732721
protozero::packed_field_sint64 field{pbf_way, protozero::pbf_tag_type(OSMFormat::Way::packed_sint64_lat)};
733722
for (const auto& node_ref : way.nodes()) {
734-
field.add_element(delta_id.update(lonlat2int(node_ref.location().lat_without_check())));
723+
field.add_element(delta_id.update(node_ref.location().y()));
735724
}
736725
}
737726
}

0 commit comments

Comments
 (0)