This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| init(from list: [T] = []) { | |
| cursor = list.first | |
| rightList = list | |
| } | |
| /// Convert to a swift array | |
| func toList() -> [T] { | |
| if let c = cursor { | |
| return leftList + [c] + rightList.reversed() | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ListZipper<T> { | |
| private var leftList: [T] = [] | |
| private var rightList: [T] = [] | |
| /// Cursor to the selected Track | |
| var cursor: T? = nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def encode(points, precision = 1e5) | |
| result = "" | |
| last_lat = last_lng = last_timestamp = 0 | |
| # Convert each point (lat, lng, ts) to a string | |
| points.each do |point| | |
| # Convert to integer | |
| lat = (point[0] * precision).round | |
| lng = (point[1] * precision).round | |
| timestamp = point[2] | |
| # Compute the difference with the previous point |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| coordinates = [] | |
| word = "" | |
| polyline.each_byte do |b| | |
| # Add the character b to the current chunk | |
| word << b | |
| next unless b < 0x5f # While we are below the _ ascii code | |
| # Add the chunk to the list of coordinates represented by a string | |
| coordinates << word | |
| word = "" | |
| end |
NewerOlder