| 10 | { |
| 11 | |
| 12 | void encode(int number_to_encode, std::string &output) |
| 13 | { |
| 14 | if (number_to_encode < 0) |
| 15 | { |
| 16 | const unsigned binary = std::llabs(number_to_encode); |
| 17 | const unsigned twos = (~binary) + 1u; |
| 18 | const unsigned shl = twos << 1u; |
| 19 | number_to_encode = static_cast<int>(~shl); |
| 20 | } |
| 21 | else |
| 22 | { |
| 23 | number_to_encode <<= 1u; |
| 24 | } |
| 25 | while (number_to_encode >= 0x20) |
| 26 | { |
| 27 | const int next_value = (0x20 | (number_to_encode & 0x1f)) + 63; |
| 28 | output += static_cast<char>(next_value); |
| 29 | number_to_encode >>= 5; |
| 30 | } |
| 31 | |
| 32 | number_to_encode += 63; |
| 33 | output += static_cast<char>(number_to_encode); |
| 34 | } |
| 35 | |
| 36 | // https://developers.google.com/maps/documentation/utilities/polylinealgorithm |
| 37 | std::int32_t decode_polyline_integer(std::string::const_iterator &first, |