Fix numerical problems with polyline
This commit is contained in:
		
							parent
							
								
									4e9709d038
								
							
						
					
					
						commit
						70afe209d5
					
				| @ -68,16 +68,16 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter | |||||||
|     std::vector<int> delta_numbers; |     std::vector<int> delta_numbers; | ||||||
|     BOOST_ASSERT(size > 0); |     BOOST_ASSERT(size > 0); | ||||||
|     delta_numbers.reserve((size - 1) * 2); |     delta_numbers.reserve((size - 1) * 2); | ||||||
|     util::Coordinate previous_coordinate{util::FixedLongitude(0), util::FixedLatitude(0)}; |     int current_lat = 0; | ||||||
|     std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const util::Coordinate loc) |     int current_lon = 0; | ||||||
|  |     std::for_each(begin, end, [&delta_numbers, ¤t_lat, ¤t_lon](const util::Coordinate loc) | ||||||
|                   { |                   { | ||||||
|                       const int lat_diff = static_cast<int>(loc.lat - previous_coordinate.lat) * |                       const int lat_diff = std::round(static_cast<int>(loc.lat) * detail::COORDINATE_TO_POLYLINE) - current_lat; | ||||||
|                                            detail::COORDINATE_TO_POLYLINE; |                       const int lon_diff = std::round(static_cast<int>(loc.lon) * detail::COORDINATE_TO_POLYLINE) - current_lon; | ||||||
|                       const int lon_diff = static_cast<int>(loc.lon - previous_coordinate.lon) * |  | ||||||
|                                            detail::COORDINATE_TO_POLYLINE; |  | ||||||
|                       delta_numbers.emplace_back(lat_diff); |                       delta_numbers.emplace_back(lat_diff); | ||||||
|                       delta_numbers.emplace_back(lon_diff); |                       delta_numbers.emplace_back(lon_diff); | ||||||
|                       previous_coordinate = loc; |                       current_lat += lat_diff; | ||||||
|  |                       current_lon += lon_diff; | ||||||
|                   }); |                   }); | ||||||
|     return encode(delta_numbers); |     return encode(delta_numbers); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user